Whamcloud - gitweb
cf62a37de33b4de6bc2c00dadbf7847725e6bf2c
[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 LU-11058
12 ALWAYS_EXCEPT="$SANITY_EXCEPT  42a     42b     42c     77k"
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 OSC=${OSC:-"osc"}
26
27 CC=${CC:-cc}
28 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
29 CREATETEST=${CREATETEST:-createtest}
30 LFS=${LFS:-lfs}
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 DEF_STRIPE_COUNT=-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 if [[ $MDSCOUNT -gt 1 ]]; then
63         # bug number:    LU-11161
64         ALWAYS_EXCEPT+=" 160g"
65 fi
66
67 #                                  5          12          (min)"
68 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
69
70 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
71         # bug number for skipped test: LU-1957
72         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  180"
73         #                                               13    (min)"
74         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
75 fi
76
77 # Get the SLES distro version
78 #
79 # Returns a version string that should only be used in comparing
80 # strings returned by version_code()
81 sles_version_code()
82 {
83         local version=$(grep VERSION_ID /etc/os-release | cut -d'"' -f2)
84
85         # All SuSE Linux versions have one decimal. version_code expects two
86         local sles_version=$version.0
87         version_code $sles_version
88 }
89
90 # Check if we are running on Ubuntu or SLES so we can make decisions on
91 # what tests to run
92 if [ -r /etc/SuSE-release ]; then
93         sles_version=$(sles_version_code)
94         [ $sles_version -lt $(version_code 11.4.0) ] &&
95                 # bug number for skipped test: LU-4341
96                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT  170"
97         [ $sles_version -lt $(version_code 12.0.0) ] &&
98                 # bug number for skipped test: LU-3703
99                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT  234"
100 elif [ -r /etc/os-release ]; then
101         if grep -qi ubuntu /etc/os-release; then
102                 ubuntu_version=$(version_code $(sed -n -e 's/"//g' \
103                                                 -e 's/^VERSION=//p' \
104                                                 /etc/os-release |
105                                                 awk '{ print $1 }'))
106
107                 if [[ $ubuntu_version -gt $(version_code 16.0.0) ]]; then
108                         # bug number for skipped test:
109                         #                LU-10334 LU-10335 LU-10335 LU-10335
110                         ALWAYS_EXCEPT+=" 103a     130a     130b     130c"
111                         #                LU-10335 LU-10335 LU-10365 LU-10366
112                         ALWAYS_EXCEPT+=" 130d     130e     400a     410"
113                 fi
114         fi
115 fi
116
117 FAIL_ON_ERROR=false
118
119 cleanup() {
120         echo -n "cln.."
121         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
122         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
123 }
124 setup() {
125         echo -n "mnt.."
126         load_modules
127         setupall || exit 10
128         echo "done"
129 }
130
131 check_swap_layouts_support()
132 {
133         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
134                 skip "Does not support layout lock."
135 }
136
137 check_and_setup_lustre
138 DIR=${DIR:-$MOUNT}
139 assert_DIR
140
141 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
142
143 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
144 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
145 rm -rf $DIR/[Rdfs][0-9]*
146
147 # $RUNAS_ID may get set incorrectly somewhere else
148 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
149
150 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
151
152 build_test_filter
153
154 if [ "${ONLY}" = "MOUNT" ] ; then
155         echo "Lustre is up, please go on"
156         exit
157 fi
158
159 echo "preparing for tests involving mounts"
160 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
161 touch $EXT2_DEV
162 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
163 echo # add a newline after mke2fs.
164
165 umask 077
166
167 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
168 lctl set_param debug=-1 2> /dev/null || true
169 test_0a() {
170         touch $DIR/$tfile
171         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
172         rm $DIR/$tfile
173         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
174 }
175 run_test 0a "touch; rm ====================="
176
177 test_0b() {
178         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
179         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
180 }
181 run_test 0b "chmod 0755 $DIR ============================="
182
183 test_0c() {
184         $LCTL get_param mdc.*.import | grep "state: FULL" ||
185                 error "import not FULL"
186         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
187                 error "bad target"
188 }
189 run_test 0c "check import proc"
190
191 test_0d() { # LU-3397
192         [ $(lustre_version_code mgs) -lt $(version_code 2.10.57) ] &&
193                 skip "proc exports not supported before 2.10.57"
194
195         local mgs_exp="mgs.MGS.exports"
196         local client_uuid=$($LCTL get_param -n mgc.*.uuid)
197         local exp_client_nid
198         local exp_client_version
199         local exp_val
200         local imp_val
201         local temp_imp=$DIR/$tfile.import
202         local temp_exp=$DIR/$tfile.export
203
204         # save mgc import file to $temp_imp
205         $LCTL get_param mgc.*.import | tee $temp_imp
206         # Check if client uuid is found in MGS export
207         for exp_client_nid in $(do_facet mgs $LCTL get_param -N $mgs_exp.*); do
208                 [ $(do_facet mgs $LCTL get_param -n $exp_client_nid.uuid) == \
209                         $client_uuid ] &&
210                         break;
211         done
212         # save mgs export file to $temp_exp
213         do_facet mgs $LCTL get_param $exp_client_nid.export | tee $temp_exp
214
215         # Compare the value of field "connect_flags"
216         imp_val=$(grep "connect_flags" $temp_imp)
217         exp_val=$(grep "connect_flags" $temp_exp)
218         [ "$exp_val" == "$imp_val" ] ||
219                 error "export flags '$exp_val' != import flags '$imp_val'"
220
221         # Compare the value of client version
222         exp_client_version=$(awk '/target_version:/ { print $2 }' $temp_exp)
223         exp_val=$(version_code $exp_client_version)
224         imp_val=$(lustre_version_code client)
225         [ "$exp_val" == "$imp_val" ] ||
226                 error "export client version '$exp_val' != '$imp_val'"
227 }
228 run_test 0d "check export proc ============================="
229
230 test_1() {
231         test_mkdir $DIR/$tdir
232         test_mkdir $DIR/$tdir/d2
233         mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
234         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
235         rmdir $DIR/$tdir/d2
236         rmdir $DIR/$tdir
237         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
238 }
239 run_test 1 "mkdir; remkdir; rmdir"
240
241 test_2() {
242         test_mkdir $DIR/$tdir
243         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
244         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
245         rm -r $DIR/$tdir
246         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
247 }
248 run_test 2 "mkdir; touch; rmdir; check file"
249
250 test_3() {
251         test_mkdir $DIR/$tdir
252         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
253         touch $DIR/$tdir/$tfile
254         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
255         rm -r $DIR/$tdir
256         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
257 }
258 run_test 3 "mkdir; touch; rmdir; check dir"
259
260 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
261 test_4() {
262         test_mkdir -i 1 $DIR/$tdir
263
264         touch $DIR/$tdir/$tfile ||
265                 error "Create file under remote directory failed"
266
267         rmdir $DIR/$tdir &&
268                 error "Expect error removing in-use dir $DIR/$tdir"
269
270         test -d $DIR/$tdir || error "Remote directory disappeared"
271
272         rm -rf $DIR/$tdir || error "remove remote dir error"
273 }
274 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
275
276 test_5() {
277         test_mkdir $DIR/$tdir
278         test_mkdir $DIR/$tdir/d2
279         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
280         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
281         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
282 }
283 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2"
284
285 test_6a() {
286         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
287         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
288         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
289                 error "$tfile does not have perm 0666 or UID $UID"
290         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
291         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
292                 error "$tfile should be 0666 and owned by UID $UID"
293 }
294 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
295
296 test_6c() {
297         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
298
299         touch $DIR/$tfile
300         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
301         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
302                 error "$tfile should be owned by UID $RUNAS_ID"
303         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
304         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
305                 error "$tfile should be owned by UID $RUNAS_ID"
306 }
307 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
308
309 test_6e() {
310         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
311
312         touch $DIR/$tfile
313         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
314         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
315                 error "$tfile should be owned by GID $UID"
316         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
317         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
318                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
319 }
320 run_test 6e "touch+chgrp $tfile; $RUNAS chgrp $tfile (should return error)"
321
322 test_6g() {
323         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
324
325         test_mkdir $DIR/$tdir
326         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
327         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
328         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
329         test_mkdir $DIR/$tdir/d/subdir
330         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
331                 error "$tdir/d/subdir should be GID $RUNAS_GID"
332         if [[ $MDSCOUNT -gt 1 ]]; then
333                 # check remote dir sgid inherite
334                 $LFS mkdir -i 0 $DIR/$tdir.local ||
335                         error "mkdir $tdir.local failed"
336                 chmod g+s $DIR/$tdir.local ||
337                         error "chmod $tdir.local failed"
338                 chgrp $RUNAS_GID $DIR/$tdir.local ||
339                         error "chgrp $tdir.local failed"
340                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
341                         error "mkdir $tdir.remote failed"
342                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
343                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
344                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
345                         error "$tdir.remote should be mode 02755"
346         fi
347 }
348 run_test 6g "verify new dir in sgid dir inherits group"
349
350 test_6h() { # bug 7331
351         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
352
353         touch $DIR/$tfile || error "touch failed"
354         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
355         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
356                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
357         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
358                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
359 }
360 run_test 6h "$RUNAS chown RUNAS_ID.0 .../$tfile (should return error)"
361
362 test_7a() {
363         test_mkdir $DIR/$tdir
364         $MCREATE $DIR/$tdir/$tfile
365         chmod 0666 $DIR/$tdir/$tfile
366         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
367                 error "$tdir/$tfile should be mode 0666"
368 }
369 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
370
371 test_7b() {
372         if [ ! -d $DIR/$tdir ]; then
373                 test_mkdir $DIR/$tdir
374         fi
375         $MCREATE $DIR/$tdir/$tfile
376         echo -n foo > $DIR/$tdir/$tfile
377         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
378         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
379 }
380 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
381
382 test_8() {
383         test_mkdir $DIR/$tdir
384         touch $DIR/$tdir/$tfile
385         chmod 0666 $DIR/$tdir/$tfile
386         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
387                 error "$tfile mode not 0666"
388 }
389 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
390
391 test_9() {
392         test_mkdir $DIR/$tdir
393         test_mkdir $DIR/$tdir/d2
394         test_mkdir $DIR/$tdir/d2/d3
395         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
396 }
397 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
398
399 test_10() {
400         test_mkdir $DIR/$tdir
401         test_mkdir $DIR/$tdir/d2
402         touch $DIR/$tdir/d2/$tfile
403         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
404                 error "$tdir/d2/$tfile not a file"
405 }
406 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
407
408 test_11() {
409         test_mkdir $DIR/$tdir
410         test_mkdir $DIR/$tdir/d2
411         chmod 0666 $DIR/$tdir/d2
412         chmod 0705 $DIR/$tdir/d2
413         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
414                 error "$tdir/d2 mode not 0705"
415 }
416 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
417
418 test_12() {
419         test_mkdir $DIR/$tdir
420         touch $DIR/$tdir/$tfile
421         chmod 0666 $DIR/$tdir/$tfile
422         chmod 0654 $DIR/$tdir/$tfile
423         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
424                 error "$tdir/d2 mode not 0654"
425 }
426 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
427
428 test_13() {
429         test_mkdir $DIR/$tdir
430         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
431         >  $DIR/$tdir/$tfile
432         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
433                 error "$tdir/$tfile size not 0 after truncate"
434 }
435 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
436
437 test_14() {
438         test_mkdir $DIR/$tdir
439         touch $DIR/$tdir/$tfile
440         rm $DIR/$tdir/$tfile
441         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
442 }
443 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
444
445 test_15() {
446         test_mkdir $DIR/$tdir
447         touch $DIR/$tdir/$tfile
448         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
449         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
450                 error "$tdir/${tfile_2} not a file after rename"
451         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
452 }
453 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
454
455 test_16() {
456         test_mkdir $DIR/$tdir
457         touch $DIR/$tdir/$tfile
458         rm -rf $DIR/$tdir/$tfile
459         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
460 }
461 run_test 16 "touch .../d16/f; rm -rf .../d16/f"
462
463 test_17a() {
464         test_mkdir $DIR/$tdir
465         touch $DIR/$tdir/$tfile
466         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
467         ls -l $DIR/$tdir
468         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
469                 error "$tdir/l-exist not a symlink"
470         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
471                 error "$tdir/l-exist not referencing a file"
472         rm -f $DIR/$tdir/l-exist
473         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
474 }
475 run_test 17a "symlinks: create, remove (real)"
476
477 test_17b() {
478         test_mkdir $DIR/$tdir
479         ln -s no-such-file $DIR/$tdir/l-dangle
480         ls -l $DIR/$tdir
481         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
482                 error "$tdir/l-dangle not referencing no-such-file"
483         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
484                 error "$tdir/l-dangle not referencing non-existent file"
485         rm -f $DIR/$tdir/l-dangle
486         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
487 }
488 run_test 17b "symlinks: create, remove (dangling)"
489
490 test_17c() { # bug 3440 - don't save failed open RPC for replay
491         test_mkdir $DIR/$tdir
492         ln -s foo $DIR/$tdir/$tfile
493         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
494 }
495 run_test 17c "symlinks: open dangling (should return error)"
496
497 test_17d() {
498         test_mkdir $DIR/$tdir
499         ln -s foo $DIR/$tdir/$tfile
500         touch $DIR/$tdir/$tfile || error "creating to new symlink"
501 }
502 run_test 17d "symlinks: create dangling"
503
504 test_17e() {
505         test_mkdir $DIR/$tdir
506         local foo=$DIR/$tdir/$tfile
507         ln -s $foo $foo || error "create symlink failed"
508         ls -l $foo || error "ls -l failed"
509         ls $foo && error "ls not failed" || true
510 }
511 run_test 17e "symlinks: create recursive symlink (should return error)"
512
513 test_17f() {
514         test_mkdir $DIR/$tdir
515         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
516         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
517         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
518         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
519         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
520         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
521         ls -l  $DIR/$tdir
522 }
523 run_test 17f "symlinks: long and very long symlink name"
524
525 # str_repeat(S, N) generate a string that is string S repeated N times
526 str_repeat() {
527         local s=$1
528         local n=$2
529         local ret=''
530         while [ $((n -= 1)) -ge 0 ]; do
531                 ret=$ret$s
532         done
533         echo $ret
534 }
535
536 # Long symlinks and LU-2241
537 test_17g() {
538         test_mkdir $DIR/$tdir
539         local TESTS="59 60 61 4094 4095"
540
541         # Fix for inode size boundary in 2.1.4
542         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
543                 TESTS="4094 4095"
544
545         # Patch not applied to 2.2 or 2.3 branches
546         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
547         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
548                 TESTS="4094 4095"
549
550         # skip long symlink name for rhel6.5.
551         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
552         grep -q '6.5' /etc/redhat-release &>/dev/null &&
553                 TESTS="59 60 61 4062 4063"
554
555         for i in $TESTS; do
556                 local SYMNAME=$(str_repeat 'x' $i)
557                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
558                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
559         done
560 }
561 run_test 17g "symlinks: really long symlink name and inode boundaries"
562
563 test_17h() { #bug 17378
564         [ $PARALLEL == "yes" ] && skip "skip parallel run"
565         remote_mds_nodsh && skip "remote MDS with nodsh"
566
567         local mdt_idx
568
569         test_mkdir $DIR/$tdir
570         mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
571         $LFS setstripe -c -1 $DIR/$tdir
572         #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
573         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
574         touch $DIR/$tdir/$tfile || true
575 }
576 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
577
578 test_17i() { #bug 20018
579         [ $PARALLEL == "yes" ] && skip "skip parallel run"
580         remote_mds_nodsh && skip "remote MDS with nodsh"
581
582         local foo=$DIR/$tdir/$tfile
583         local mdt_idx
584
585         test_mkdir -c1 $DIR/$tdir
586         mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
587         ln -s $foo $foo || error "create symlink failed"
588 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
589         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
590         ls -l $foo && error "error not detected"
591         return 0
592 }
593 run_test 17i "don't panic on short symlink (should return error)"
594
595 test_17k() { #bug 22301
596         [ $PARALLEL == "yes" ] && skip "skip parallel run"
597         [[ -z "$(which rsync 2>/dev/null)" ]] &&
598                 skip "no rsync command"
599         rsync --help | grep -q xattr ||
600                 skip_env "$(rsync --version | head -n1) does not support xattrs"
601         test_mkdir $DIR/$tdir
602         test_mkdir $DIR/$tdir.new
603         touch $DIR/$tdir/$tfile
604         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
605         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
606                 error "rsync failed with xattrs enabled"
607 }
608 run_test 17k "symlinks: rsync with xattrs enabled"
609
610 test_17l() { # LU-279
611         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
612                 skip "no getfattr command"
613
614         test_mkdir $DIR/$tdir
615         touch $DIR/$tdir/$tfile
616         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
617         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
618                 # -h to not follow symlinks. -m '' to list all the xattrs.
619                 # grep to remove first line: '# file: $path'.
620                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
621                 do
622                         lgetxattr_size_check $path $xattr ||
623                                 error "lgetxattr_size_check $path $xattr failed"
624                 done
625         done
626 }
627 run_test 17l "Ensure lgetxattr's returned xattr size is consistent"
628
629 # LU-1540
630 test_17m() {
631         [ $PARALLEL == "yes" ] && skip "skip parallel run"
632         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
633                 skip_env "ldiskfs only test"
634         remote_mds_nodsh && skip "remote MDS with nodsh"
635         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
636         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
637                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks"
638
639         local short_sym="0123456789"
640         local wdir=$DIR/$tdir
641         local i
642
643         test_mkdir $wdir
644         long_sym=$short_sym
645         # create a long symlink file
646         for ((i = 0; i < 4; ++i)); do
647                 long_sym=${long_sym}${long_sym}
648         done
649
650         echo "create 512 short and long symlink files under $wdir"
651         for ((i = 0; i < 256; ++i)); do
652                 ln -sf ${long_sym}"a5a5" $wdir/long-$i
653                 ln -sf ${short_sym}"a5a5" $wdir/short-$i
654         done
655
656         echo "erase them"
657         rm -f $wdir/*
658         sync
659         wait_delete_completed
660
661         echo "recreate the 512 symlink files with a shorter string"
662         for ((i = 0; i < 512; ++i)); do
663                 # rewrite the symlink file with a shorter string
664                 ln -sf ${long_sym} $wdir/long-$i || error "long_sym failed"
665                 ln -sf ${short_sym} $wdir/short-$i || error "short_sym failed"
666         done
667
668         local mds_index=$(($($LFS getstripe -m $wdir) + 1))
669         local devname=$(mdsdevname $mds_index)
670
671         echo "stop and checking mds${mds_index}:"
672         # e2fsck should not return error
673         stop mds${mds_index}
674         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
675         rc=$?
676
677         start mds${mds_index} $devname $MDS_MOUNT_OPTS ||
678                 error "start mds${mds_index} failed"
679         df $MOUNT > /dev/null 2>&1
680         [ $rc -eq 0 ] ||
681                 error "e2fsck detected error for short/long symlink: rc=$rc"
682         rm -f $wdir/*
683 }
684 run_test 17m "run e2fsck against MDT which contains short/long symlink"
685
686 check_fs_consistency_17n() {
687         local mdt_index
688         local rc=0
689
690         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
691         # so it only check MDT1/MDT2 instead of all of MDTs.
692         for mdt_index in 1 2; do
693                 local devname=$(mdsdevname $mdt_index)
694                 # e2fsck should not return error
695                 stop mds${mdt_index}
696                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
697                         rc=$((rc + $?))
698
699                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
700                         error "mount mds$mdt_index failed"
701                 df $MOUNT > /dev/null 2>&1
702         done
703         return $rc
704 }
705
706 test_17n() {
707         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
708         [ $PARALLEL == "yes" ] && skip "skip parallel run"
709         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
710                 skip_env "ldiskfs only test"
711         remote_mds_nodsh && skip "remote MDS with nodsh"
712         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
713         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
714                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks"
715
716         local i
717
718         test_mkdir $DIR/$tdir
719         for ((i=0; i<10; i++)); do
720                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
721                         error "create remote dir error $i"
722                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
723                         error "create files under remote dir failed $i"
724         done
725
726         check_fs_consistency_17n ||
727                 error "e2fsck report error after create files under remote dir"
728
729         for ((i = 0; i < 10; i++)); do
730                 rm -rf $DIR/$tdir/remote_dir_${i} ||
731                         error "destroy remote dir error $i"
732         done
733
734         check_fs_consistency_17n ||
735                 error "e2fsck report error after unlink files under remote dir"
736
737         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
738                 skip "lustre < 2.4.50 does not support migrate mv"
739
740         for ((i = 0; i < 10; i++)); do
741                 mkdir -p $DIR/$tdir/remote_dir_${i}
742                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
743                         error "create files under remote dir failed $i"
744                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
745                         error "migrate remote dir error $i"
746         done
747         check_fs_consistency_17n || error "e2fsck report error after migration"
748
749         for ((i = 0; i < 10; i++)); do
750                 rm -rf $DIR/$tdir/remote_dir_${i} ||
751                         error "destroy remote dir error $i"
752         done
753
754         check_fs_consistency_17n || error "e2fsck report error after unlink"
755 }
756 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
757
758 test_17o() {
759         remote_mds_nodsh && skip "remote MDS with nodsh"
760         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
761                 skip "Need MDS version at least 2.3.64"
762
763         local wdir=$DIR/${tdir}o
764         local mdt_index
765         local rc=0
766
767         test_mkdir $wdir
768         touch $wdir/$tfile
769         mdt_index=$($LFS getstripe -m $wdir/$tfile)
770         mdt_index=$((mdt_index + 1))
771
772         cancel_lru_locks mdc
773         #fail mds will wait the failover finish then set
774         #following fail_loc to avoid interfer the recovery process.
775         fail mds${mdt_index}
776
777         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
778         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
779         ls -l $wdir/$tfile && rc=1
780         do_facet mds${mdt_index} lctl set_param fail_loc=0
781         [[ $rc -eq 0 ]] || error "stat file should fail"
782 }
783 run_test 17o "stat file with incompat LMA feature"
784
785 test_18() {
786         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
787         ls $DIR || error "Failed to ls $DIR: $?"
788 }
789 run_test 18 "touch .../f ; ls ... =============================="
790
791 test_19a() {
792         touch $DIR/$tfile
793         ls -l $DIR
794         rm $DIR/$tfile
795         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
796 }
797 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
798
799 test_19b() {
800         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
801 }
802 run_test 19b "ls -l .../f19 (should return error) =============="
803
804 test_19c() {
805         [ $RUNAS_ID -eq $UID ] &&
806                 skip_env "RUNAS_ID = UID = $UID -- skipping"
807
808         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
809 }
810 run_test 19c "$RUNAS touch .../f19 (should return error) =="
811
812 test_19d() {
813         cat $DIR/f19 && error || true
814 }
815 run_test 19d "cat .../f19 (should return error) =============="
816
817 test_20() {
818         touch $DIR/$tfile
819         rm $DIR/$tfile
820         touch $DIR/$tfile
821         rm $DIR/$tfile
822         touch $DIR/$tfile
823         rm $DIR/$tfile
824         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
825 }
826 run_test 20 "touch .../f ; ls -l ..."
827
828 test_21() {
829         test_mkdir $DIR/$tdir
830         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
831         ln -s dangle $DIR/$tdir/link
832         echo foo >> $DIR/$tdir/link
833         cat $DIR/$tdir/dangle
834         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
835         $CHECKSTAT -f -t file $DIR/$tdir/link ||
836                 error "$tdir/link not linked to a file"
837 }
838 run_test 21 "write to dangling link"
839
840 test_22() {
841         local wdir=$DIR/$tdir
842         test_mkdir $wdir
843         chown $RUNAS_ID:$RUNAS_GID $wdir
844         (cd $wdir || error "cd $wdir failed";
845                 $RUNAS tar cf - /etc/hosts /etc/sysconfig/network |
846                 $RUNAS tar xf -)
847         ls -lR $wdir/etc || error "ls -lR $wdir/etc failed"
848         $CHECKSTAT -t dir $wdir/etc || error "checkstat -t dir failed"
849         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $wdir/etc ||
850                 error "checkstat -u failed"
851 }
852 run_test 22 "unpack tar archive as non-root user"
853
854 # was test_23
855 test_23a() {
856         test_mkdir $DIR/$tdir
857         local file=$DIR/$tdir/$tfile
858
859         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
860         openfile -f O_CREAT:O_EXCL $file &&
861                 error "$file recreate succeeded" || true
862 }
863 run_test 23a "O_CREAT|O_EXCL in subdir"
864
865 test_23b() { # bug 18988
866         test_mkdir $DIR/$tdir
867         local file=$DIR/$tdir/$tfile
868
869         rm -f $file
870         echo foo > $file || error "write filed"
871         echo bar >> $file || error "append filed"
872         $CHECKSTAT -s 8 $file || error "wrong size"
873         rm $file
874 }
875 run_test 23b "O_APPEND check"
876
877 # LU-9409, size with O_APPEND and tiny writes
878 test_23c() {
879         local file=$DIR/$tfile
880
881         # single dd
882         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800
883         $CHECKSTAT -s 6400 $file || error "wrong size, expected 6400"
884         rm -f $file
885
886         # racing tiny writes
887         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
888         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
889         wait
890         $CHECKSTAT -s 12800 $file || error "wrong size, expected 12800"
891         rm -f $file
892
893         #racing tiny & normal writes
894         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4096 count=4 &
895         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=100 &
896         wait
897         $CHECKSTAT -s 17184 $file || error "wrong size, expected 17184"
898         rm -f $file
899
900         #racing tiny & normal writes 2, ugly numbers
901         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4099 count=11 &
902         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=17 count=173 &
903         wait
904         $CHECKSTAT -s 48030 $file || error "wrong size, expected 48030"
905         rm -f $file
906 }
907 run_test 23c "O_APPEND size checks for tiny writes"
908
909 # LU-11069 file offset is correct after appending writes
910 test_23d() {
911         local file=$DIR/$tfile
912         local offset
913
914         echo CentaurHauls > $file
915         offset=$($MULTIOP $file oO_WRONLY:O_APPEND:w13Zp)
916         if ((offset != 26)); then
917                 error "wrong offset, expected 26, got '$offset'"
918         fi
919 }
920 run_test 23d "file offset is correct after appending writes"
921
922 # rename sanity
923 test_24a() {
924         echo '-- same directory rename'
925         test_mkdir $DIR/$tdir
926         touch $DIR/$tdir/$tfile.1
927         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
928         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
929 }
930 run_test 24a "rename file to non-existent target"
931
932 test_24b() {
933         test_mkdir $DIR/$tdir
934         touch $DIR/$tdir/$tfile.{1,2}
935         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
936         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
937         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
938 }
939 run_test 24b "rename file to existing target"
940
941 test_24c() {
942         test_mkdir $DIR/$tdir
943         test_mkdir $DIR/$tdir/d$testnum.1
944         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
945         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
946         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
947 }
948 run_test 24c "rename directory to non-existent target"
949
950 test_24d() {
951         test_mkdir -c1 $DIR/$tdir
952         test_mkdir -c1 $DIR/$tdir/d$testnum.1
953         test_mkdir -c1 $DIR/$tdir/d$testnum.2
954         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
955         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
956         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
957 }
958 run_test 24d "rename directory to existing target"
959
960 test_24e() {
961         echo '-- cross directory renames --'
962         test_mkdir $DIR/R5a
963         test_mkdir $DIR/R5b
964         touch $DIR/R5a/f
965         mv $DIR/R5a/f $DIR/R5b/g
966         $CHECKSTAT -a $DIR/R5a/f || error "$DIR/R5a/f exists"
967         $CHECKSTAT -t file $DIR/R5b/g || error "$DIR/R5b/g not file type"
968 }
969 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
970
971 test_24f() {
972         test_mkdir $DIR/R6a
973         test_mkdir $DIR/R6b
974         touch $DIR/R6a/f $DIR/R6b/g
975         mv $DIR/R6a/f $DIR/R6b/g
976         $CHECKSTAT -a $DIR/R6a/f || error "$DIR/R6a/f exists"
977         $CHECKSTAT -t file $DIR/R6b/g || error "$DIR/R6b/g not file type"
978 }
979 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
980
981 test_24g() {
982         test_mkdir $DIR/R7a
983         test_mkdir $DIR/R7b
984         test_mkdir $DIR/R7a/d
985         mv $DIR/R7a/d $DIR/R7b/e
986         $CHECKSTAT -a $DIR/R7a/d || error "$DIR/R7a/d exists"
987         $CHECKSTAT -t dir $DIR/R7b/e || error "$DIR/R7b/e not dir type"
988 }
989 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
990
991 test_24h() {
992         test_mkdir -c1 $DIR/R8a
993         test_mkdir -c1 $DIR/R8b
994         test_mkdir -c1 $DIR/R8a/d
995         test_mkdir -c1 $DIR/R8b/e
996         mrename $DIR/R8a/d $DIR/R8b/e
997         $CHECKSTAT -a $DIR/R8a/d || error "$DIR/R8a/d exists"
998         $CHECKSTAT -t dir $DIR/R8b/e || error "$DIR/R8b/e not dir type"
999 }
1000 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
1001
1002 test_24i() {
1003         echo "-- rename error cases"
1004         test_mkdir $DIR/R9
1005         test_mkdir $DIR/R9/a
1006         touch $DIR/R9/f
1007         mrename $DIR/R9/f $DIR/R9/a
1008         $CHECKSTAT -t file $DIR/R9/f || error "$DIR/R9/f not file type"
1009         $CHECKSTAT -t dir  $DIR/R9/a || error "$DIR/R9/a not dir type"
1010         $CHECKSTAT -a $DIR/R9/a/f || error "$DIR/R9/a/f exists"
1011 }
1012 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
1013
1014 test_24j() {
1015         test_mkdir $DIR/R10
1016         mrename $DIR/R10/f $DIR/R10/g
1017         $CHECKSTAT -t dir $DIR/R10 || error "$DIR/R10 not dir type"
1018         $CHECKSTAT -a $DIR/R10/f || error "$DIR/R10/f exists"
1019         $CHECKSTAT -a $DIR/R10/g || error "$DIR/R10/g exists"
1020 }
1021 run_test 24j "source does not exist ============================"
1022
1023 test_24k() {
1024         test_mkdir $DIR/R11a
1025         test_mkdir $DIR/R11a/d
1026         touch $DIR/R11a/f
1027         mv $DIR/R11a/f $DIR/R11a/d
1028         $CHECKSTAT -a $DIR/R11a/f || error "$DIR/R11a/f exists"
1029         $CHECKSTAT -t file $DIR/R11a/d/f || error "$DIR/R11a/d/f not file type"
1030 }
1031 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
1032
1033 # bug 2429 - rename foo foo foo creates invalid file
1034 test_24l() {
1035         f="$DIR/f24l"
1036         $MULTIOP $f OcNs || error "rename of ${f} to itself failed"
1037 }
1038 run_test 24l "Renaming a file to itself ========================"
1039
1040 test_24m() {
1041         f="$DIR/f24m"
1042         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
1043         # on ext3 this does not remove either the source or target files
1044         # though the "expected" operation would be to remove the source
1045         $CHECKSTAT -t file ${f} || error "${f} missing"
1046         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
1047 }
1048 run_test 24m "Renaming a file to a hard link to itself ========="
1049
1050 test_24n() {
1051     f="$DIR/f24n"
1052     # this stats the old file after it was renamed, so it should fail
1053     touch ${f}
1054     $CHECKSTAT ${f} || error "${f} missing"
1055     mv ${f} ${f}.rename
1056     $CHECKSTAT ${f}.rename || error "${f}.rename missing"
1057     $CHECKSTAT -a ${f} || error "${f} exists"
1058 }
1059 run_test 24n "Statting the old file after renaming (Posix rename 2)"
1060
1061 test_24o() {
1062         test_mkdir $DIR/$tdir
1063         rename_many -s random -v -n 10 $DIR/$tdir
1064 }
1065 run_test 24o "rename of files during htree split"
1066
1067 test_24p() {
1068         test_mkdir $DIR/R12a
1069         test_mkdir $DIR/R12b
1070         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
1071         mrename $DIR/R12a $DIR/R12b
1072         $CHECKSTAT -a $DIR/R12a || error "$DIR/R12a exists"
1073         $CHECKSTAT -t dir $DIR/R12b || error "$DIR/R12b not dir type"
1074         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
1075         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
1076 }
1077 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
1078
1079 cleanup_multiop_pause() {
1080         trap 0
1081         kill -USR1 $MULTIPID
1082 }
1083
1084 test_24q() {
1085         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1086
1087         test_mkdir $DIR/R13a
1088         test_mkdir $DIR/R13b
1089         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
1090         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
1091         MULTIPID=$!
1092
1093         trap cleanup_multiop_pause EXIT
1094         mrename $DIR/R13a $DIR/R13b
1095         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1096         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1097         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1098         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1099         cleanup_multiop_pause
1100         wait $MULTIPID || error "multiop close failed"
1101 }
1102 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1103
1104 test_24r() { #bug 3789
1105         test_mkdir $DIR/R14a
1106         test_mkdir $DIR/R14a/b
1107         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1108         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1109         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1110 }
1111 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1112
1113 test_24s() {
1114         test_mkdir $DIR/R15a
1115         test_mkdir $DIR/R15a/b
1116         test_mkdir $DIR/R15a/b/c
1117         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1118         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1119         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1120 }
1121 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1122 test_24t() {
1123         test_mkdir $DIR/R16a
1124         test_mkdir $DIR/R16a/b
1125         test_mkdir $DIR/R16a/b/c
1126         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1127         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1128         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1129 }
1130 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1131
1132 test_24u() { # bug12192
1133         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error "multiop failed"
1134         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1135 }
1136 run_test 24u "create stripe file"
1137
1138 page_size() {
1139         local size
1140         size=$(getconf PAGE_SIZE 2>/dev/null)
1141         echo -n ${size:-4096}
1142 }
1143
1144 simple_cleanup_common() {
1145         local rc=0
1146         trap 0
1147         [ -z "$DIR" -o -z "$tdir" ] && return 0
1148
1149         local start=$SECONDS
1150         rm -rf $DIR/$tdir
1151         rc=$?
1152         wait_delete_completed
1153         echo "cleanup time $((SECONDS - start))"
1154         return $rc
1155 }
1156
1157 max_pages_per_rpc() {
1158         local mdtname="$(printf "MDT%04x" ${1:-0})"
1159         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1160 }
1161
1162 test_24v() {
1163         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1164
1165         local nrfiles=${COUNT:-100000}
1166         local fname="$DIR/$tdir/$tfile"
1167
1168         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1169         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
1170
1171         test_mkdir "$(dirname $fname)"
1172         # assume MDT0000 has the fewest inodes
1173         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1174         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1175         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1176
1177         trap simple_cleanup_common EXIT
1178
1179         createmany -m "$fname" $nrfiles
1180
1181         cancel_lru_locks mdc
1182         lctl set_param mdc.*.stats clear
1183
1184         # was previously test_24D: LU-6101
1185         # readdir() returns correct number of entries after cursor reload
1186         local num_ls=$(ls $DIR/$tdir | wc -l)
1187         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1188         local num_all=$(ls -a $DIR/$tdir | wc -l)
1189         if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
1190              $num_all -ne $((nrfiles + 2)) ]; then
1191                 error "Expected $nrfiles files, got $num_ls " \
1192                         "($num_uniq unique $num_all .&..)"
1193         fi
1194         # LU-5 large readdir
1195         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1196         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1197         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1198         # take into account of overhead in lu_dirpage header and end mark in
1199         # each page, plus one in rpc_num calculation.
1200         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1201         local page_entries=$((($(page_size) - 24) / dirent_size))
1202         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1203         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1204         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1205         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1206         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1207         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1208                 error "large readdir doesn't take effect: " \
1209                       "$mds_readpage should be about $rpc_max"
1210
1211         simple_cleanup_common
1212 }
1213 run_test 24v "list large directory (test hash collision, b=17560)"
1214
1215 test_24w() { # bug21506
1216         SZ1=234852
1217         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1218         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1219         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1220         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1221         [[ "$SZ1" -eq "$SZ2" ]] ||
1222                 error "Error reading at the end of the file $tfile"
1223 }
1224 run_test 24w "Reading a file larger than 4Gb"
1225
1226 test_24x() {
1227         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1228         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1229         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1230                 skip "Need MDS version at least 2.7.56"
1231
1232         local MDTIDX=1
1233         local remote_dir=$DIR/$tdir/remote_dir
1234
1235         test_mkdir $DIR/$tdir
1236         $LFS mkdir -i $MDTIDX $remote_dir ||
1237                 error "create remote directory failed"
1238
1239         test_mkdir $DIR/$tdir/src_dir
1240         touch $DIR/$tdir/src_file
1241         test_mkdir $remote_dir/tgt_dir
1242         touch $remote_dir/tgt_file
1243
1244         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1245                 error "rename dir cross MDT failed!"
1246
1247         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1248                 error "rename file cross MDT failed!"
1249
1250         touch $DIR/$tdir/ln_file
1251         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1252                 error "ln file cross MDT failed"
1253
1254         rm -rf $DIR/$tdir || error "Can not delete directories"
1255 }
1256 run_test 24x "cross MDT rename/link"
1257
1258 test_24y() {
1259         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1260         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1261
1262         local remote_dir=$DIR/$tdir/remote_dir
1263         local mdtidx=1
1264
1265         test_mkdir $DIR/$tdir
1266         $LFS mkdir -i $mdtidx $remote_dir ||
1267                 error "create remote directory failed"
1268
1269         test_mkdir $remote_dir/src_dir
1270         touch $remote_dir/src_file
1271         test_mkdir $remote_dir/tgt_dir
1272         touch $remote_dir/tgt_file
1273
1274         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1275                 error "rename subdir in the same remote dir failed!"
1276
1277         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1278                 error "rename files in the same remote dir failed!"
1279
1280         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1281                 error "link files in the same remote dir failed!"
1282
1283         rm -rf $DIR/$tdir || error "Can not delete directories"
1284 }
1285 run_test 24y "rename/link on the same dir should succeed"
1286
1287 test_24A() { # LU-3182
1288         local NFILES=5000
1289
1290         rm -rf $DIR/$tdir
1291         test_mkdir $DIR/$tdir
1292         trap simple_cleanup_common EXIT
1293         createmany -m $DIR/$tdir/$tfile $NFILES
1294         local t=$(ls $DIR/$tdir | wc -l)
1295         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1296         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1297         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1298                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1299         fi
1300
1301         simple_cleanup_common || error "Can not delete directories"
1302 }
1303 run_test 24A "readdir() returns correct number of entries."
1304
1305 test_24B() { # LU-4805
1306         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
1307
1308         local count
1309
1310         test_mkdir $DIR/$tdir
1311         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1312                 error "create striped dir failed"
1313
1314         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1315         [ $count -eq 2 ] || error "Expected 2, got $count"
1316
1317         touch $DIR/$tdir/striped_dir/a
1318
1319         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1320         [ $count -eq 3 ] || error "Expected 3, got $count"
1321
1322         touch $DIR/$tdir/striped_dir/.f
1323
1324         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1325         [ $count -eq 4 ] || error "Expected 4, got $count"
1326
1327         rm -rf $DIR/$tdir || error "Can not delete directories"
1328 }
1329 run_test 24B "readdir for striped dir return correct number of entries"
1330
1331 test_24C() {
1332         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
1333
1334         mkdir $DIR/$tdir
1335         mkdir $DIR/$tdir/d0
1336         mkdir $DIR/$tdir/d1
1337
1338         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1339                 error "create striped dir failed"
1340
1341         cd $DIR/$tdir/d0/striped_dir
1342
1343         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1344         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1345         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1346
1347         [ "$d0_ino" = "$parent_ino" ] ||
1348                 error ".. wrong, expect $d0_ino, get $parent_ino"
1349
1350         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1351                 error "mv striped dir failed"
1352
1353         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1354
1355         [ "$d1_ino" = "$parent_ino" ] ||
1356                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1357 }
1358 run_test 24C "check .. in striped dir"
1359
1360 test_24E() {
1361         [[ $MDSCOUNT -lt 4 ]] && skip_env "needs >= 4 MDTs"
1362         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1363
1364         mkdir -p $DIR/$tdir
1365         mkdir $DIR/$tdir/src_dir
1366         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1367                 error "create remote source failed"
1368
1369         touch $DIR/$tdir/src_dir/src_child/a
1370
1371         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1372                 error "create remote target dir failed"
1373
1374         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1375                 error "create remote target child failed"
1376
1377         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1378                 error "rename dir cross MDT failed!"
1379
1380         find $DIR/$tdir
1381
1382         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1383                 error "src_child still exists after rename"
1384
1385         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1386                 error "missing file(a) after rename"
1387
1388         rm -rf $DIR/$tdir || error "Can not delete directories"
1389 }
1390 run_test 24E "cross MDT rename/link"
1391
1392 test_25a() {
1393         echo '== symlink sanity ============================================='
1394
1395         test_mkdir $DIR/d25
1396         ln -s d25 $DIR/s25
1397         touch $DIR/s25/foo ||
1398                 error "File creation in symlinked directory failed"
1399 }
1400 run_test 25a "create file in symlinked directory ==============="
1401
1402 test_25b() {
1403         [ ! -d $DIR/d25 ] && test_25a
1404         $CHECKSTAT -t file $DIR/s25/foo || error "$DIR/s25/foo not file type"
1405 }
1406 run_test 25b "lookup file in symlinked directory ==============="
1407
1408 test_26a() {
1409         test_mkdir $DIR/d26
1410         test_mkdir $DIR/d26/d26-2
1411         ln -s d26/d26-2 $DIR/s26
1412         touch $DIR/s26/foo || error "File creation failed"
1413 }
1414 run_test 26a "multiple component symlink ======================="
1415
1416 test_26b() {
1417         test_mkdir -p $DIR/$tdir/d26-2
1418         ln -s $tdir/d26-2/foo $DIR/s26-2
1419         touch $DIR/s26-2 || error "File creation failed"
1420 }
1421 run_test 26b "multiple component symlink at end of lookup ======"
1422
1423 test_26c() {
1424         test_mkdir $DIR/d26.2
1425         touch $DIR/d26.2/foo
1426         ln -s d26.2 $DIR/s26.2-1
1427         ln -s s26.2-1 $DIR/s26.2-2
1428         ln -s s26.2-2 $DIR/s26.2-3
1429         chmod 0666 $DIR/s26.2-3/foo
1430 }
1431 run_test 26c "chain of symlinks"
1432
1433 # recursive symlinks (bug 439)
1434 test_26d() {
1435         ln -s d26-3/foo $DIR/d26-3
1436 }
1437 run_test 26d "create multiple component recursive symlink"
1438
1439 test_26e() {
1440         [ ! -h $DIR/d26-3 ] && test_26d
1441         rm $DIR/d26-3
1442 }
1443 run_test 26e "unlink multiple component recursive symlink"
1444
1445 # recursive symlinks (bug 7022)
1446 test_26f() {
1447         test_mkdir $DIR/$tdir
1448         test_mkdir $DIR/$tdir/$tfile
1449         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1450         test_mkdir -p lndir/bar1
1451         test_mkdir $DIR/$tdir/$tfile/$tfile
1452         cd $tfile                || error "cd $tfile failed"
1453         ln -s .. dotdot          || error "ln dotdot failed"
1454         ln -s dotdot/lndir lndir || error "ln lndir failed"
1455         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1456         output=`ls $tfile/$tfile/lndir/bar1`
1457         [ "$output" = bar1 ] && error "unexpected output"
1458         rm -r $tfile             || error "rm $tfile failed"
1459         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1460 }
1461 run_test 26f "rm -r of a directory which has recursive symlink"
1462
1463 test_27a() {
1464         test_mkdir $DIR/$tdir
1465         $LFS getstripe $DIR/$tdir
1466         $LFS setstripe -c 1 $DIR/$tdir/$tfile || error "setstripe failed"
1467         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1468         cp /etc/hosts $DIR/$tdir/$tfile || error "Can't copy to one stripe file"
1469 }
1470 run_test 27a "one stripe file"
1471
1472 test_27b() {
1473         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1474
1475         test_mkdir $DIR/$tdir
1476         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1477         $LFS getstripe -c $DIR/$tdir/$tfile
1478         [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
1479                 error "two-stripe file doesn't have two stripes"
1480
1481         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1482 }
1483 run_test 27b "create and write to two stripe file"
1484
1485 test_27d() {
1486         test_mkdir $DIR/$tdir
1487         $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile ||
1488                 error "setstripe failed"
1489         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1490         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1491 }
1492 run_test 27d "create file with default settings"
1493
1494 test_27e() {
1495         # LU-5839 adds check for existed layout before setting it
1496         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1497                 skip "Need MDS version at least 2.7.56"
1498
1499         test_mkdir $DIR/$tdir
1500         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1501         $LFS setstripe -c 2 $DIR/$tdir/$tfile && error "setstripe worked twice"
1502         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1503 }
1504 run_test 27e "setstripe existing file (should return error)"
1505
1506 test_27f() {
1507         test_mkdir $DIR/$tdir
1508         $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1509                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1510         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1511                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1512         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1513         $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1514 }
1515 run_test 27f "setstripe with bad stripe size (should return error)"
1516
1517 test_27g() {
1518         test_mkdir $DIR/$tdir
1519         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1520         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "no stripe info" ||
1521                 error "$DIR/$tdir/$tfile has object"
1522 }
1523 run_test 27g "$LFS getstripe with no objects"
1524
1525 test_27i() {
1526         test_mkdir $DIR/$tdir
1527         touch $DIR/$tdir/$tfile || error "touch failed"
1528         [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1529                 error "missing objects"
1530 }
1531 run_test 27i "$LFS getstripe with some objects"
1532
1533 test_27j() {
1534         test_mkdir $DIR/$tdir
1535         $LFS setstripe -i $OSTCOUNT $DIR/$tdir/$tfile &&
1536                 error "setstripe failed" || true
1537 }
1538 run_test 27j "setstripe with bad stripe offset (should return error)"
1539
1540 test_27k() { # bug 2844
1541         test_mkdir $DIR/$tdir
1542         local file=$DIR/$tdir/$tfile
1543         local ll_max_blksize=$((4 * 1024 * 1024))
1544         $LFS setstripe -S 67108864 $file || error "setstripe failed"
1545         local blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1546         [ $blksize -le $ll_max_blksize ] || error "1:$blksize > $ll_max_blksize"
1547         dd if=/dev/zero of=$file bs=4k count=1
1548         blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1549         [ $blksize -le $ll_max_blksize ] || error "2:$blksize > $ll_max_blksize"
1550 }
1551 run_test 27k "limit i_blksize for broken user apps"
1552
1553 test_27l() {
1554         mcreate $DIR/$tfile || error "creating file"
1555         $RUNAS $LFS setstripe -c 1 $DIR/$tfile &&
1556                 error "setstripe should have failed" || true
1557 }
1558 run_test 27l "check setstripe permissions (should return error)"
1559
1560 test_27m() {
1561         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1562
1563         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1564                    head -n1)
1565         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1566                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1567         fi
1568         trap simple_cleanup_common EXIT
1569         test_mkdir $DIR/$tdir
1570         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.1
1571         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
1572                 error "dd should fill OST0"
1573         i=2
1574         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.$i; do
1575                 i=$((i + 1))
1576                 [ $i -gt 256 ] && break
1577         done
1578         i=$((i + 1))
1579         touch $DIR/$tdir/$tfile.$i
1580         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1581             awk '{print $1}'| grep -w "0") ] &&
1582                 error "OST0 was full but new created file still use it"
1583         i=$((i + 1))
1584         touch $DIR/$tdir/$tfile.$i
1585         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1586             awk '{print $1}'| grep -w "0") ] &&
1587                 error "OST0 was full but new created file still use it"
1588         simple_cleanup_common
1589 }
1590 run_test 27m "create file while OST0 was full"
1591
1592 sleep_maxage() {
1593         local delay=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1594                       awk '{ print $1 * 2; exit; }')
1595         sleep $delay
1596 }
1597
1598 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1599 # if the OST isn't full anymore.
1600 reset_enospc() {
1601         local OSTIDX=${1:-""}
1602
1603         local list=$(comma_list $(osts_nodes))
1604         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1605
1606         do_nodes $list lctl set_param fail_loc=0
1607         sync    # initiate all OST_DESTROYs from MDS to OST
1608         sleep_maxage
1609 }
1610
1611 exhaust_precreations() {
1612         local OSTIDX=$1
1613         local FAILLOC=$2
1614         local FAILIDX=${3:-$OSTIDX}
1615         local ofacet=ost$((OSTIDX + 1))
1616
1617         test_mkdir -p -c1 $DIR/$tdir
1618         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
1619         local mfacet=mds$((mdtidx + 1))
1620         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1621
1622         local OST=$(ostname_from_index $OSTIDX)
1623
1624         # on the mdt's osc
1625         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1626         local last_id=$(do_facet $mfacet lctl get_param -n \
1627                         osc.$mdtosc_proc1.prealloc_last_id)
1628         local next_id=$(do_facet $mfacet lctl get_param -n \
1629                         osc.$mdtosc_proc1.prealloc_next_id)
1630
1631         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1632         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1633
1634         test_mkdir -p $DIR/$tdir/${OST}
1635         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1636 #define OBD_FAIL_OST_ENOSPC              0x215
1637         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1638         echo "Creating to objid $last_id on ost $OST..."
1639         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1640         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1641         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1642         sleep_maxage
1643 }
1644
1645 exhaust_all_precreations() {
1646         local i
1647         for (( i=0; i < OSTCOUNT; i++ )) ; do
1648                 exhaust_precreations $i $1 -1
1649         done
1650 }
1651
1652 test_27n() {
1653         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1654         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1655         remote_mds_nodsh && skip "remote MDS with nodsh"
1656         remote_ost_nodsh && skip "remote OST with nodsh"
1657
1658         reset_enospc
1659         rm -f $DIR/$tdir/$tfile
1660         exhaust_precreations 0 0x80000215
1661         $LFS setstripe -c -1 $DIR/$tdir || error "setstripe failed"
1662         touch $DIR/$tdir/$tfile || error "touch failed"
1663         $LFS getstripe $DIR/$tdir/$tfile
1664         reset_enospc
1665 }
1666 run_test 27n "create file with some full OSTs"
1667
1668 test_27o() {
1669         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1670         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1671         remote_mds_nodsh && skip "remote MDS with nodsh"
1672         remote_ost_nodsh && skip "remote OST with nodsh"
1673
1674         reset_enospc
1675         rm -f $DIR/$tdir/$tfile
1676         exhaust_all_precreations 0x215
1677
1678         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1679
1680         reset_enospc
1681         rm -rf $DIR/$tdir/*
1682 }
1683 run_test 27o "create file with all full OSTs (should error)"
1684
1685 test_27p() {
1686         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1687         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1688         remote_mds_nodsh && skip "remote MDS with nodsh"
1689         remote_ost_nodsh && skip "remote OST with nodsh"
1690
1691         reset_enospc
1692         rm -f $DIR/$tdir/$tfile
1693         test_mkdir $DIR/$tdir
1694
1695         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1696         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1697         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1698
1699         exhaust_precreations 0 0x80000215
1700         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1701         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1702         $LFS getstripe $DIR/$tdir/$tfile
1703
1704         reset_enospc
1705 }
1706 run_test 27p "append to a truncated file with some full OSTs"
1707
1708 test_27q() {
1709         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1710         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1711         remote_mds_nodsh && skip "remote MDS with nodsh"
1712         remote_ost_nodsh && skip "remote OST with nodsh"
1713
1714         reset_enospc
1715         rm -f $DIR/$tdir/$tfile
1716
1717         test_mkdir $DIR/$tdir
1718         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1719         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1720                 error "truncate $DIR/$tdir/$tfile failed"
1721         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1722
1723         exhaust_all_precreations 0x215
1724
1725         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1726         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1727
1728         reset_enospc
1729 }
1730 run_test 27q "append to truncated file with all OSTs full (should error)"
1731
1732 test_27r() {
1733         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1734         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1735         remote_mds_nodsh && skip "remote MDS with nodsh"
1736         remote_ost_nodsh && skip "remote OST with nodsh"
1737
1738         reset_enospc
1739         rm -f $DIR/$tdir/$tfile
1740         exhaust_precreations 0 0x80000215
1741
1742         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1743
1744         reset_enospc
1745 }
1746 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1747
1748 test_27s() { # bug 10725
1749         test_mkdir $DIR/$tdir
1750         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1751         local stripe_count=0
1752         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1753         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1754                 error "stripe width >= 2^32 succeeded" || true
1755
1756 }
1757 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1758
1759 test_27t() { # bug 10864
1760         WDIR=$(pwd)
1761         WLFS=$(which lfs)
1762         cd $DIR
1763         touch $tfile
1764         $WLFS getstripe $tfile
1765         cd $WDIR
1766 }
1767 run_test 27t "check that utils parse path correctly"
1768
1769 test_27u() { # bug 4900
1770         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1771         remote_mds_nodsh && skip "remote MDS with nodsh"
1772
1773         local index
1774         local list=$(comma_list $(mdts_nodes))
1775
1776 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1777         do_nodes $list $LCTL set_param fail_loc=0x139
1778         test_mkdir -p $DIR/$tdir
1779         trap simple_cleanup_common EXIT
1780         createmany -o $DIR/$tdir/t- 1000
1781         do_nodes $list $LCTL set_param fail_loc=0
1782
1783         TLOG=$TMP/$tfile.getstripe
1784         $LFS getstripe $DIR/$tdir > $TLOG
1785         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1786         unlinkmany $DIR/$tdir/t- 1000
1787         trap 0
1788         [[ $OBJS -gt 0 ]] &&
1789                 error "$OBJS objects created on OST-0. See $TLOG" ||
1790                 rm -f $TLOG
1791 }
1792 run_test 27u "skip object creation on OSC w/o objects"
1793
1794 test_27v() { # bug 4900
1795         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1796         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1797         remote_mds_nodsh && skip "remote MDS with nodsh"
1798         remote_ost_nodsh && skip "remote OST with nodsh"
1799
1800         exhaust_all_precreations 0x215
1801         reset_enospc
1802
1803         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
1804
1805         touch $DIR/$tdir/$tfile
1806         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1807         # all except ost1
1808         for (( i=1; i < OSTCOUNT; i++ )); do
1809                 do_facet ost$i lctl set_param fail_loc=0x705
1810         done
1811         local START=`date +%s`
1812         createmany -o $DIR/$tdir/$tfile 32
1813
1814         local FINISH=`date +%s`
1815         local TIMEOUT=`lctl get_param -n timeout`
1816         local PROCESS=$((FINISH - START))
1817         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1818                error "$FINISH - $START >= $TIMEOUT / 2"
1819         sleep $((TIMEOUT / 2 - PROCESS))
1820         reset_enospc
1821 }
1822 run_test 27v "skip object creation on slow OST"
1823
1824 test_27w() { # bug 10997
1825         test_mkdir $DIR/$tdir
1826         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1827         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
1828                 error "stripe size $size != 65536" || true
1829         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
1830                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
1831 }
1832 run_test 27w "check $LFS setstripe -S and getstrip -d options"
1833
1834 test_27wa() {
1835         [[ $OSTCOUNT -lt 2 ]] &&
1836                 skip_env "skipping multiple stripe count/offset test"
1837
1838         test_mkdir $DIR/$tdir
1839         for i in $(seq 1 $OSTCOUNT); do
1840                 offset=$((i - 1))
1841                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
1842                         error "setstripe -c $i -i $offset failed"
1843                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
1844                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
1845                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1846                 [ $index -ne $offset ] &&
1847                         error "stripe offset $index != $offset" || true
1848         done
1849 }
1850 run_test 27wa "check $LFS setstripe -c -i options"
1851
1852 test_27x() {
1853         remote_ost_nodsh && skip "remote OST with nodsh"
1854         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1855         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1856
1857         OFFSET=$(($OSTCOUNT - 1))
1858         OSTIDX=0
1859         local OST=$(ostname_from_index $OSTIDX)
1860
1861         test_mkdir $DIR/$tdir
1862         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
1863         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1864         sleep_maxage
1865         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1866         for i in $(seq 0 $OFFSET); do
1867                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
1868                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
1869                 error "OST0 was degraded but new created file still use it"
1870         done
1871         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1872 }
1873 run_test 27x "create files while OST0 is degraded"
1874
1875 test_27y() {
1876         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1877         remote_mds_nodsh && skip "remote MDS with nodsh"
1878         remote_ost_nodsh && skip "remote OST with nodsh"
1879         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1880
1881         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1882         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1883                 osc.$mdtosc.prealloc_last_id)
1884         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1885                 osc.$mdtosc.prealloc_next_id)
1886         local fcount=$((last_id - next_id))
1887         [[ $fcount -eq 0 ]] && skip "not enough space on OST0"
1888         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1889
1890         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1891                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1892         local OST_DEACTIVE_IDX=-1
1893         local OSC
1894         local OSTIDX
1895         local OST
1896
1897         for OSC in $MDS_OSCS; do
1898                 OST=$(osc_to_ost $OSC)
1899                 OSTIDX=$(index_from_ostuuid $OST)
1900                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1901                         OST_DEACTIVE_IDX=$OSTIDX
1902                 fi
1903                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1904                         echo $OSC "is Deactivated:"
1905                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1906                 fi
1907         done
1908
1909         OSTIDX=$(index_from_ostuuid $OST)
1910         test_mkdir $DIR/$tdir
1911         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
1912
1913         for OSC in $MDS_OSCS; do
1914                 OST=$(osc_to_ost $OSC)
1915                 OSTIDX=$(index_from_ostuuid $OST)
1916                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1917                         echo $OST "is degraded:"
1918                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1919                                                 obdfilter.$OST.degraded=1
1920                 fi
1921         done
1922
1923         sleep_maxage
1924         createmany -o $DIR/$tdir/$tfile $fcount
1925
1926         for OSC in $MDS_OSCS; do
1927                 OST=$(osc_to_ost $OSC)
1928                 OSTIDX=$(index_from_ostuuid $OST)
1929                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1930                         echo $OST "is recovered from degraded:"
1931                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1932                                                 obdfilter.$OST.degraded=0
1933                 else
1934                         do_facet $SINGLEMDS lctl --device %$OSC activate
1935                 fi
1936         done
1937
1938         # all osp devices get activated, hence -1 stripe count restored
1939         local stripe_count=0
1940
1941         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1942         # devices get activated.
1943         sleep_maxage
1944         $LFS setstripe -c -1 $DIR/$tfile
1945         stripe_count=$($LFS getstripe -c $DIR/$tfile)
1946         rm -f $DIR/$tfile
1947         [ $stripe_count -ne $OSTCOUNT ] &&
1948                 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
1949         return 0
1950 }
1951 run_test 27y "create files while OST0 is degraded and the rest inactive"
1952
1953 check_seq_oid()
1954 {
1955         log "check file $1"
1956
1957         lmm_count=$($GETSTRIPE -c $1)
1958         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1959         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1960
1961         local old_ifs="$IFS"
1962         IFS=$'[:]'
1963         fid=($($LFS path2fid $1))
1964         IFS="$old_ifs"
1965
1966         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1967         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1968
1969         # compare lmm_seq and lu_fid->f_seq
1970         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1971         # compare lmm_object_id and lu_fid->oid
1972         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1973
1974         # check the trusted.fid attribute of the OST objects of the file
1975         local have_obdidx=false
1976         local stripe_nr=0
1977         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1978                 # skip lines up to and including "obdidx"
1979                 [ -z "$obdidx" ] && break
1980                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1981                 $have_obdidx || continue
1982
1983                 local ost=$((obdidx + 1))
1984                 local dev=$(ostdevname $ost)
1985                 local oid_hex
1986
1987                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1988
1989                 seq=$(echo $seq | sed -e "s/^0x//g")
1990                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1991                         oid_hex=$(echo $oid)
1992                 else
1993                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1994                 fi
1995                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1996
1997                 local ff=""
1998                 #
1999                 # Don't unmount/remount the OSTs if we don't need to do that.
2000                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
2001                 # update too, until that use mount/ll_decode_filter_fid/mount.
2002                 # Re-enable when debugfs will understand new filter_fid.
2003                 #
2004                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
2005                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
2006                                 $dev 2>/dev/null" | grep "parent=")
2007                 fi
2008                 if [ -z "$ff" ]; then
2009                         stop ost$ost
2010                         mount_fstype ost$ost
2011                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
2012                                 $(facet_mntpt ost$ost)/$obj_file)
2013                         unmount_fstype ost$ost
2014                         start ost$ost $dev $OST_MOUNT_OPTS
2015                         clients_up
2016                 fi
2017
2018                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
2019
2020                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
2021
2022                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
2023                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
2024                 #
2025                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
2026                 #       stripe_size=1048576 component_id=1 component_start=0 \
2027                 #       component_end=33554432
2028                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
2029                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
2030                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
2031                 local ff_pstripe
2032                 if grep -q 'stripe=' <<<$ff; then
2033                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
2034                 else
2035                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
2036                         # into f_ver in this case.  See comment on ff_parent.
2037                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
2038                 fi
2039
2040                 # compare lmm_seq and filter_fid->ff_parent.f_seq
2041                 [ $ff_pseq = $lmm_seq ] ||
2042                         error "FF parent SEQ $ff_pseq != $lmm_seq"
2043                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
2044                 [ $ff_poid = $lmm_oid ] ||
2045                         error "FF parent OID $ff_poid != $lmm_oid"
2046                 (($ff_pstripe == $stripe_nr)) ||
2047                         error "FF stripe $ff_pstripe != $stripe_nr"
2048
2049                 stripe_nr=$((stripe_nr + 1))
2050                 [ $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2051                         continue
2052                 if grep -q 'stripe_count=' <<<$ff; then
2053                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
2054                                             -e 's/ .*//' <<<$ff)
2055                         [ $lmm_count = $ff_scnt ] ||
2056                                 error "FF stripe count $lmm_count != $ff_scnt"
2057                 fi
2058         done
2059 }
2060
2061 test_27z() {
2062         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2063         remote_ost_nodsh && skip "remote OST with nodsh"
2064
2065         test_mkdir $DIR/$tdir
2066         $LFS setstripe -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
2067                 { error "setstripe -c -1 failed"; return 1; }
2068         # We need to send a write to every object to get parent FID info set.
2069         # This _should_ also work for setattr, but does not currently.
2070         # touch $DIR/$tdir/$tfile-1 ||
2071         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
2072                 { error "dd $tfile-1 failed"; return 2; }
2073         $LFS setstripe -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
2074                 { error "setstripe -c -1 failed"; return 3; }
2075         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
2076                 { error "dd $tfile-2 failed"; return 4; }
2077
2078         # make sure write RPCs have been sent to OSTs
2079         sync; sleep 5; sync
2080
2081         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
2082         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
2083 }
2084 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
2085
2086 test_27A() { # b=19102
2087         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2088
2089         save_layout_restore_at_exit $MOUNT
2090         $LFS setstripe -c 0 -i -1 -S 0 $MOUNT
2091         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
2092                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
2093         local default_size=$($GETSTRIPE -S $MOUNT)
2094         local default_offset=$($GETSTRIPE -i $MOUNT)
2095         local dsize=$(do_facet $SINGLEMDS \
2096                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
2097         [ $default_size -eq $dsize ] ||
2098                 error "stripe size $default_size != $dsize"
2099         [ $default_offset -eq -1 ] ||
2100                 error "stripe offset $default_offset != -1"
2101 }
2102 run_test 27A "check filesystem-wide default LOV EA values"
2103
2104 test_27B() { # LU-2523
2105         test_mkdir $DIR/$tdir
2106         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
2107         touch $DIR/$tdir/f0
2108         # open f1 with O_LOV_DELAY_CREATE
2109         # rename f0 onto f1
2110         # call setstripe ioctl on open file descriptor for f1
2111         # close
2112         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
2113                 $DIR/$tdir/f0
2114
2115         rm -f $DIR/$tdir/f1
2116         # open f1 with O_LOV_DELAY_CREATE
2117         # unlink f1
2118         # call setstripe ioctl on open file descriptor for f1
2119         # close
2120         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2121
2122         # Allow multiop to fail in imitation of NFS's busted semantics.
2123         true
2124 }
2125 run_test 27B "call setstripe on open unlinked file/rename victim"
2126
2127 test_27C() { #LU-2871
2128         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2129
2130         declare -a ost_idx
2131         local index
2132         local found
2133         local i
2134         local j
2135
2136         test_mkdir $DIR/$tdir
2137         cd $DIR/$tdir
2138         for i in $(seq 0 $((OSTCOUNT - 1))); do
2139                 # set stripe across all OSTs starting from OST$i
2140                 $SETSTRIPE -i $i -c -1 $tfile$i
2141                 # get striping information
2142                 ost_idx=($($GETSTRIPE $tfile$i |
2143                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2144                 echo ${ost_idx[@]}
2145
2146                 # check the layout
2147                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2148                         error "${#ost_idx[@]} != $OSTCOUNT"
2149
2150                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2151                         found=0
2152                         for j in $(echo ${ost_idx[@]}); do
2153                                 if [ $index -eq $j ]; then
2154                                         found=1
2155                                         break
2156                                 fi
2157                         done
2158                         [ $found = 1 ] ||
2159                                 error "Can not find $index in ${ost_idx[@]}"
2160                 done
2161         done
2162 }
2163 run_test 27C "check full striping across all OSTs"
2164
2165 test_27D() {
2166         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2167         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
2168         remote_mds_nodsh && skip "remote MDS with nodsh"
2169
2170         local POOL=${POOL:-testpool}
2171         local first_ost=0
2172         local last_ost=$(($OSTCOUNT - 1))
2173         local ost_step=1
2174         local ost_list=$(seq $first_ost $ost_step $last_ost)
2175         local ost_range="$first_ost $last_ost $ost_step"
2176
2177         if ! combined_mgs_mds ; then
2178                 mount_mgs_client
2179         fi
2180
2181         test_mkdir $DIR/$tdir
2182         pool_add $POOL || error "pool_add failed"
2183         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2184
2185         local skip27D
2186         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
2187                 skip27D+="-s 29"
2188         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) -o \
2189           $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2190                 skip27D+=" -s 30,31"
2191         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2192                 error "llapi_layout_test failed"
2193
2194         destroy_test_pools || error "destroy test pools failed"
2195
2196         if ! combined_mgs_mds ; then
2197                 umount_mgs_client
2198         fi
2199 }
2200 run_test 27D "validate llapi_layout API"
2201
2202 # Verify that default_easize is increased from its initial value after
2203 # accessing a widely striped file.
2204 test_27E() {
2205         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2206         [ $(lustre_version_code client) -lt $(version_code 2.5.57) ] &&
2207                 skip "client does not have LU-3338 fix"
2208
2209         # 72 bytes is the minimum space required to store striping
2210         # information for a file striped across one OST:
2211         # (sizeof(struct lov_user_md_v3) +
2212         #  sizeof(struct lov_user_ost_data_v1))
2213         local min_easize=72
2214         $LCTL set_param -n llite.*.default_easize $min_easize ||
2215                 error "lctl set_param failed"
2216         local easize=$($LCTL get_param -n llite.*.default_easize)
2217
2218         [ $easize -eq $min_easize ] ||
2219                 error "failed to set default_easize"
2220
2221         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2222                 error "setstripe failed"
2223         cat $DIR/$tfile
2224         rm $DIR/$tfile
2225
2226         easize=$($LCTL get_param -n llite.*.default_easize)
2227
2228         [ $easize -gt $min_easize ] ||
2229                 error "default_easize not updated"
2230 }
2231 run_test 27E "check that default extended attribute size properly increases"
2232
2233 test_27F() { # LU-5346/LU-7975
2234         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2235         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs"
2236         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
2237                 skip "Need MDS version at least 2.8.51"
2238         remote_ost_nodsh && skip "remote OST with nodsh"
2239
2240         test_mkdir $DIR/$tdir
2241         rm -f $DIR/$tdir/f0
2242         $SETSTRIPE -c 2 $DIR/$tdir
2243
2244         # stop all OSTs to reproduce situation for LU-7975 ticket
2245         for num in $(seq $OSTCOUNT); do
2246                 stop ost$num
2247         done
2248
2249         # open/create f0 with O_LOV_DELAY_CREATE
2250         # truncate f0 to a non-0 size
2251         # close
2252         multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2253
2254         $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2255         # open/write it again to force delayed layout creation
2256         cat /etc/hosts > $DIR/$tdir/f0 &
2257         catpid=$!
2258
2259         # restart OSTs
2260         for num in $(seq $OSTCOUNT); do
2261                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2262                         error "ost$num failed to start"
2263         done
2264
2265         wait $catpid || error "cat failed"
2266
2267         cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2268         [[ $($GETSTRIPE -c $DIR/$tdir/f0) == 2 ]] || error "wrong stripecount"
2269
2270 }
2271 run_test 27F "Client resend delayed layout creation with non-zero size"
2272
2273 test_27G() { #LU-10629
2274         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2275         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2276         local POOL=${POOL:-testpool}
2277         local ostrange="0 0 1"
2278
2279         test_mkdir $DIR/$tdir
2280         pool_add $POOL || error "pool_add failed"
2281         pool_add_targets $POOL $ostrange || error "pool_add_targets failed"
2282         $LFS setstripe -p $POOL $DIR/$tdir
2283
2284         local pool=$($LFS getstripe -p $DIR/$tdir)
2285
2286         [ "$pool" = "$POOL" ] || error "Striping failed got '$pool' not '$POOL'"
2287
2288         $LFS setstripe -d $DIR/$tdir
2289
2290         pool=$($LFS getstripe -p $DIR/$tdir)
2291
2292         rmdir $DIR/$tdir
2293
2294         [ -z "$pool" ] || error "'$pool' is not empty"
2295 }
2296 run_test 27G "Clear OST pool from stripe"
2297
2298 # createtest also checks that device nodes are created and
2299 # then visible correctly (#2091)
2300 test_28() { # bug 2091
2301         test_mkdir $DIR/d28
2302         $CREATETEST $DIR/d28/ct || error "createtest failed"
2303 }
2304 run_test 28 "create/mknod/mkdir with bad file types ============"
2305
2306 test_29() {
2307         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2308
2309         sync; sleep 1; sync # flush out any dirty pages from previous tests
2310         cancel_lru_locks
2311         test_mkdir $DIR/d29
2312         touch $DIR/d29/foo
2313         log 'first d29'
2314         ls -l $DIR/d29
2315
2316         declare -i LOCKCOUNTORIG=0
2317         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2318                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2319         done
2320         [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
2321
2322         declare -i LOCKUNUSEDCOUNTORIG=0
2323         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2324                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2325         done
2326
2327         log 'second d29'
2328         ls -l $DIR/d29
2329         log 'done'
2330
2331         declare -i LOCKCOUNTCURRENT=0
2332         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2333                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2334         done
2335
2336         declare -i LOCKUNUSEDCOUNTCURRENT=0
2337         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2338                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2339         done
2340
2341         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2342                 $LCTL set_param -n ldlm.dump_namespaces ""
2343                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2344                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2345                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2346                 return 2
2347         fi
2348         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2349                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2350                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2351                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2352                 return 3
2353         fi
2354 }
2355 run_test 29 "IT_GETATTR regression  ============================"
2356
2357 test_30a() { # was test_30
2358         cp $(which ls) $DIR || cp /bin/ls $DIR
2359         $DIR/ls / || error "Can't execute binary from lustre"
2360         rm $DIR/ls
2361 }
2362 run_test 30a "execute binary from Lustre (execve) =============="
2363
2364 test_30b() {
2365         cp `which ls` $DIR || cp /bin/ls $DIR
2366         chmod go+rx $DIR/ls
2367         $RUNAS $DIR/ls / || error "Can't execute binary from lustre as non-root"
2368         rm $DIR/ls
2369 }
2370 run_test 30b "execute binary from Lustre as non-root ==========="
2371
2372 test_30c() { # b=22376
2373         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2374
2375         cp `which ls` $DIR || cp /bin/ls $DIR
2376         chmod a-rw $DIR/ls
2377         cancel_lru_locks mdc
2378         cancel_lru_locks osc
2379         $RUNAS $DIR/ls / || error "Can't execute binary from lustre"
2380         rm -f $DIR/ls
2381 }
2382 run_test 30c "execute binary from Lustre without read perms ===="
2383
2384 test_31a() {
2385         $OPENUNLINK $DIR/f31 $DIR/f31 || error "openunlink failed"
2386         $CHECKSTAT -a $DIR/f31 || error "$DIR/f31 exists"
2387 }
2388 run_test 31a "open-unlink file =================================="
2389
2390 test_31b() {
2391         touch $DIR/f31 || error "touch $DIR/f31 failed"
2392         ln $DIR/f31 $DIR/f31b || error "ln failed"
2393         $MULTIOP $DIR/f31b Ouc || error "multiop failed"
2394         $CHECKSTAT -t file $DIR/f31 || error "$DIR/f31 not file type"
2395 }
2396 run_test 31b "unlink file with multiple links while open ======="
2397
2398 test_31c() {
2399         touch $DIR/f31 || error "touch $DIR/f31 failed"
2400         ln $DIR/f31 $DIR/f31c || error "ln failed"
2401         multiop_bg_pause $DIR/f31 O_uc ||
2402                 error "multiop_bg_pause for $DIR/f31 failed"
2403         MULTIPID=$!
2404         $MULTIOP $DIR/f31c Ouc
2405         kill -USR1 $MULTIPID
2406         wait $MULTIPID
2407 }
2408 run_test 31c "open-unlink file with multiple links ============="
2409
2410 test_31d() {
2411         opendirunlink $DIR/d31d $DIR/d31d || error "opendirunlink failed"
2412         $CHECKSTAT -a $DIR/d31d || error "$DIR/d31d exists"
2413 }
2414 run_test 31d "remove of open directory ========================="
2415
2416 test_31e() { # bug 2904
2417         openfilleddirunlink $DIR/d31e || error "openfilleddirunlink failed"
2418 }
2419 run_test 31e "remove of open non-empty directory ==============="
2420
2421 test_31f() { # bug 4554
2422         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2423
2424         set -vx
2425         test_mkdir $DIR/d31f
2426         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2427         cp /etc/hosts $DIR/d31f
2428         ls -l $DIR/d31f
2429         $GETSTRIPE $DIR/d31f/hosts
2430         multiop_bg_pause $DIR/d31f D_c || return 1
2431         MULTIPID=$!
2432
2433         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2434         test_mkdir $DIR/d31f
2435         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2436         cp /etc/hosts $DIR/d31f
2437         ls -l $DIR/d31f
2438         $GETSTRIPE $DIR/d31f/hosts
2439         multiop_bg_pause $DIR/d31f D_c || return 1
2440         MULTIPID2=$!
2441
2442         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2443         wait $MULTIPID || error "first opendir $MULTIPID failed"
2444
2445         sleep 6
2446
2447         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2448         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2449         set +vx
2450 }
2451 run_test 31f "remove of open directory with open-unlink file ==="
2452
2453 test_31g() {
2454         echo "-- cross directory link --"
2455         test_mkdir -c1 $DIR/${tdir}ga
2456         test_mkdir -c1 $DIR/${tdir}gb
2457         touch $DIR/${tdir}ga/f
2458         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2459         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2460         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2461         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2462         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2463 }
2464 run_test 31g "cross directory link==============="
2465
2466 test_31h() {
2467         echo "-- cross directory link --"
2468         test_mkdir -c1 $DIR/${tdir}
2469         test_mkdir -c1 $DIR/${tdir}/dir
2470         touch $DIR/${tdir}/f
2471         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2472         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2473         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2474         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2475         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2476 }
2477 run_test 31h "cross directory link under child==============="
2478
2479 test_31i() {
2480         echo "-- cross directory link --"
2481         test_mkdir -c1 $DIR/$tdir
2482         test_mkdir -c1 $DIR/$tdir/dir
2483         touch $DIR/$tdir/dir/f
2484         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2485         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2486         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2487         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2488         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2489 }
2490 run_test 31i "cross directory link under parent==============="
2491
2492 test_31j() {
2493         test_mkdir -c1 -p $DIR/$tdir
2494         test_mkdir -c1 -p $DIR/$tdir/dir1
2495         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2496         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2497         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2498         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2499         return 0
2500 }
2501 run_test 31j "link for directory==============="
2502
2503 test_31k() {
2504         test_mkdir -c1 -p $DIR/$tdir
2505         touch $DIR/$tdir/s
2506         touch $DIR/$tdir/exist
2507         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2508         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2509         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2510         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2511         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2512         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2513         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2514         return 0
2515 }
2516 run_test 31k "link to file: the same, non-existing, dir==============="
2517
2518 test_31m() {
2519         mkdir $DIR/d31m
2520         touch $DIR/d31m/s
2521         mkdir $DIR/d31m2
2522         touch $DIR/d31m2/exist
2523         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2524         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2525         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2526         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2527         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2528         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2529         return 0
2530 }
2531 run_test 31m "link to file: the same, non-existing, dir==============="
2532
2533 test_31n() {
2534         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2535         nlink=$(stat --format=%h $DIR/$tfile)
2536         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2537         local fd=$(free_fd)
2538         local cmd="exec $fd<$DIR/$tfile"
2539         eval $cmd
2540         cmd="exec $fd<&-"
2541         trap "eval $cmd" EXIT
2542         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2543         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2544         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2545         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2546         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2547         eval $cmd
2548 }
2549 run_test 31n "check link count of unlinked file"
2550
2551 link_one() {
2552         local TEMPNAME=$(mktemp $1_XXXXXX)
2553         mlink $TEMPNAME $1 2> /dev/null &&
2554                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2555         munlink $TEMPNAME
2556 }
2557
2558 test_31o() { # LU-2901
2559         test_mkdir $DIR/$tdir
2560         for LOOP in $(seq 100); do
2561                 rm -f $DIR/$tdir/$tfile*
2562                 for THREAD in $(seq 8); do
2563                         link_one $DIR/$tdir/$tfile.$LOOP &
2564                 done
2565                 wait
2566                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2567                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2568                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2569                         break || true
2570         done
2571 }
2572 run_test 31o "duplicate hard links with same filename"
2573
2574 test_31p() {
2575         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
2576
2577         test_mkdir $DIR/$tdir
2578         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2579         $LFS setdirstripe -D -c2 -H all_char $DIR/$tdir/striped_dir
2580
2581         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2582                 error "open unlink test1 failed"
2583         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2584                 error "open unlink test2 failed"
2585
2586         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2587                 error "test1 still exists"
2588         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2589                 error "test2 still exists"
2590 }
2591 run_test 31p "remove of open striped directory"
2592
2593 cleanup_test32_mount() {
2594         local rc=0
2595         trap 0
2596         local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
2597         $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
2598         losetup -d $loopdev || true
2599         rm -rf $DIR/$tdir
2600         return $rc
2601 }
2602
2603 test_32a() {
2604         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2605
2606         echo "== more mountpoints and symlinks ================="
2607         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2608         trap cleanup_test32_mount EXIT
2609         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2610         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2611                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2612         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. ||
2613                 error "$DIR/$tdir/ext2-mountpoint/.. not dir type"
2614         cleanup_test32_mount
2615 }
2616 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2617
2618 test_32b() {
2619         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2620
2621         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2622         trap cleanup_test32_mount EXIT
2623         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2624         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2625                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2626         ls -al $DIR/$tdir/ext2-mountpoint/.. ||
2627                 error "Can't list $DIR/$tdir/ext2-mountpoint/.."
2628         cleanup_test32_mount
2629 }
2630 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2631
2632 test_32c() {
2633         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2634
2635         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2636         trap cleanup_test32_mount EXIT
2637         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2638         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2639                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2640         test_mkdir -p $DIR/$tdir/d2/test_dir
2641         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
2642                 error "$DIR/$tdir/ext2-mountpoint/../d2/test_dir not dir type"
2643         cleanup_test32_mount
2644 }
2645 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2646
2647 test_32d() {
2648         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2649
2650         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2651         trap cleanup_test32_mount EXIT
2652         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2653         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2654                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2655         test_mkdir -p $DIR/$tdir/d2/test_dir
2656         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
2657                 error "Can't list $DIR/$tdir/ext2-mountpoint/../d2/test_dir"
2658         cleanup_test32_mount
2659 }
2660 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir"
2661
2662 test_32e() {
2663         rm -fr $DIR/$tdir
2664         test_mkdir -p $DIR/$tdir/tmp
2665         local tmp_dir=$DIR/$tdir/tmp
2666         ln -s $DIR/$tdir $tmp_dir/symlink11
2667         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2668         $CHECKSTAT -t link $DIR/$tdir/tmp/symlink11 || error "symlink11 bad"
2669         $CHECKSTAT -t link $DIR/$tdir/symlink01 || error "symlink01 bad"
2670 }
2671 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir"
2672
2673 test_32f() {
2674         rm -fr $DIR/$tdir
2675         test_mkdir -p $DIR/$tdir/tmp
2676         local tmp_dir=$DIR/$tdir/tmp
2677         ln -s $DIR/$tdir $tmp_dir/symlink11
2678         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2679         ls $DIR/$tdir/tmp/symlink11  || error "symlink11 bad"
2680         ls $DIR/$tdir/symlink01 || error "symlink01 bad"
2681 }
2682 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir"
2683
2684 test_32g() {
2685         local tmp_dir=$DIR/$tdir/tmp
2686         test_mkdir -p $tmp_dir
2687         test_mkdir $DIR/${tdir}2
2688         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
2689         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
2690         $CHECKSTAT -t link $tmp_dir/symlink12 || error "symlink12 not a link"
2691         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error "symlink02 not a link"
2692         $CHECKSTAT -t dir -f $tmp_dir/symlink12 || error "symlink12 not a dir"
2693         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error "symlink12 not a dir"
2694 }
2695 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2696
2697 test_32h() {
2698         rm -fr $DIR/$tdir $DIR/${tdir}2
2699         tmp_dir=$DIR/$tdir/tmp
2700         test_mkdir -p $tmp_dir
2701         test_mkdir $DIR/${tdir}2
2702         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
2703         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
2704         ls $tmp_dir/symlink12 || error "listing symlink12"
2705         ls $DIR/$tdir/symlink02  || error "listing symlink02"
2706 }
2707 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2708
2709 test_32i() {
2710         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2711
2712         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2713         trap cleanup_test32_mount EXIT
2714         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2715         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2716                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2717         touch $DIR/$tdir/test_file
2718         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file ||
2719                 error "$DIR/$tdir/ext2-mountpoint/../test_file not file type"
2720         cleanup_test32_mount
2721 }
2722 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2723
2724 test_32j() {
2725         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2726
2727         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2728         trap cleanup_test32_mount EXIT
2729         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2730         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2731                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2732         touch $DIR/$tdir/test_file
2733         cat $DIR/$tdir/ext2-mountpoint/../test_file ||
2734                 error "Can't open $DIR/$tdir/ext2-mountpoint/../test_file"
2735         cleanup_test32_mount
2736 }
2737 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2738
2739 test_32k() {
2740         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2741
2742         rm -fr $DIR/$tdir
2743         trap cleanup_test32_mount EXIT
2744         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2745         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2746                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2747         test_mkdir -p $DIR/$tdir/d2
2748         touch $DIR/$tdir/d2/test_file || error "touch failed"
2749         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
2750                 error "$DIR/$tdir/ext2-mountpoint/../d2/test_file not file type"
2751         cleanup_test32_mount
2752 }
2753 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2754
2755 test_32l() {
2756         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2757
2758         rm -fr $DIR/$tdir
2759         trap cleanup_test32_mount EXIT
2760         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2761         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2762                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2763         test_mkdir -p $DIR/$tdir/d2
2764         touch $DIR/$tdir/d2/test_file || error "touch failed"
2765         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
2766                 error "Can't open $DIR/$tdir/ext2-mountpoint/../d2/test_file"
2767         cleanup_test32_mount
2768 }
2769 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2770
2771 test_32m() {
2772         rm -fr $DIR/d32m
2773         test_mkdir -p $DIR/d32m/tmp
2774         TMP_DIR=$DIR/d32m/tmp
2775         ln -s $DIR $TMP_DIR/symlink11
2776         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2777         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 ||
2778                 error "symlink11 not a link"
2779         $CHECKSTAT -t link $DIR/d32m/symlink01 ||
2780                 error "symlink01 not a link"
2781 }
2782 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2783
2784 test_32n() {
2785         rm -fr $DIR/d32n
2786         test_mkdir -p $DIR/d32n/tmp
2787         TMP_DIR=$DIR/d32n/tmp
2788         ln -s $DIR $TMP_DIR/symlink11
2789         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2790         ls -l $DIR/d32n/tmp/symlink11  || error "listing symlink11"
2791         ls -l $DIR/d32n/symlink01 || error "listing symlink01"
2792 }
2793 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2794
2795 test_32o() {
2796         touch $DIR/$tfile
2797         test_mkdir -p $DIR/d32o/tmp
2798         TMP_DIR=$DIR/d32o/tmp
2799         ln -s $DIR/$tfile $TMP_DIR/symlink12
2800         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2801         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 ||
2802                 error "symlink12 not a link"
2803         $CHECKSTAT -t link $DIR/d32o/symlink02 || error "symlink02 not a link"
2804         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 ||
2805                 error "$DIR/d32o/tmp/symlink12 not file type"
2806         $CHECKSTAT -t file -f $DIR/d32o/symlink02 ||
2807                 error "$DIR/d32o/symlink02 not file type"
2808 }
2809 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2810
2811 test_32p() {
2812         log 32p_1
2813         rm -fr $DIR/d32p
2814         log 32p_2
2815         rm -f $DIR/$tfile
2816         log 32p_3
2817         touch $DIR/$tfile
2818         log 32p_4
2819         test_mkdir -p $DIR/d32p/tmp
2820         log 32p_5
2821         TMP_DIR=$DIR/d32p/tmp
2822         log 32p_6
2823         ln -s $DIR/$tfile $TMP_DIR/symlink12
2824         log 32p_7
2825         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2826         log 32p_8
2827         cat $DIR/d32p/tmp/symlink12 ||
2828                 error "Can't open $DIR/d32p/tmp/symlink12"
2829         log 32p_9
2830         cat $DIR/d32p/symlink02 || error "Can't open $DIR/d32p/symlink02"
2831         log 32p_10
2832 }
2833 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2834
2835 test_32q() {
2836         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2837
2838         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2839         trap cleanup_test32_mount EXIT
2840         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2841         touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
2842         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2843                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2844         ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
2845         cleanup_test32_mount
2846 }
2847 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2848
2849 test_32r() {
2850         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2851
2852         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2853         trap cleanup_test32_mount EXIT
2854         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2855         touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
2856         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2857                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2858         ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
2859         cleanup_test32_mount
2860 }
2861 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2862
2863 test_33aa() {
2864         rm -f $DIR/$tfile
2865         touch $DIR/$tfile
2866         chmod 444 $DIR/$tfile
2867         chown $RUNAS_ID $DIR/$tfile
2868         log 33_1
2869         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2870         log 33_2
2871 }
2872 run_test 33aa "write file with mode 444 (should return error)"
2873
2874 test_33a() {
2875         rm -fr $DIR/$tdir
2876         test_mkdir $DIR/$tdir
2877         chown $RUNAS_ID $DIR/$tdir
2878         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile ||
2879                 error "$RUNAS create $tdir/$tfile failed"
2880         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile &&
2881                 error "open RDWR" || true
2882 }
2883 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2884
2885 test_33b() {
2886         rm -fr $DIR/$tdir
2887         test_mkdir $DIR/$tdir
2888         chown $RUNAS_ID $DIR/$tdir
2889         $RUNAS $OPENFILE -f 1286739555 $DIR/$tdir/$tfile || true
2890 }
2891 run_test 33b "test open file with malformed flags (No panic)"
2892
2893 test_33c() {
2894         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2895         remote_ost_nodsh && skip "remote OST with nodsh"
2896
2897         local ostnum
2898         local ostname
2899         local write_bytes
2900         local all_zeros
2901
2902         all_zeros=:
2903         rm -fr $DIR/$tdir
2904         test_mkdir $DIR/$tdir
2905         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2906
2907         sync
2908         for ostnum in $(seq $OSTCOUNT); do
2909                 # test-framework's OST numbering is one-based, while Lustre's
2910                 # is zero-based
2911                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2912                 # Parsing llobdstat's output sucks; we could grep the /proc
2913                 # path, but that's likely to not be as portable as using the
2914                 # llobdstat utility.  So we parse lctl output instead.
2915                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2916                         obdfilter/$ostname/stats |
2917                         awk '/^write_bytes/ {print $7}' )
2918                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2919                 if (( ${write_bytes:-0} > 0 ))
2920                 then
2921                         all_zeros=false
2922                         break;
2923                 fi
2924         done
2925
2926         $all_zeros || return 0
2927
2928         # Write four bytes
2929         echo foo > $DIR/$tdir/bar
2930         # Really write them
2931         sync
2932
2933         # Total up write_bytes after writing.  We'd better find non-zeros.
2934         for ostnum in $(seq $OSTCOUNT); do
2935                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2936                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2937                         obdfilter/$ostname/stats |
2938                         awk '/^write_bytes/ {print $7}' )
2939                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2940                 if (( ${write_bytes:-0} > 0 ))
2941                 then
2942                         all_zeros=false
2943                         break;
2944                 fi
2945         done
2946
2947         if $all_zeros
2948         then
2949                 for ostnum in $(seq $OSTCOUNT); do
2950                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2951                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2952                         do_facet ost$ostnum lctl get_param -n \
2953                                 obdfilter/$ostname/stats
2954                 done
2955                 error "OST not keeping write_bytes stats (b22312)"
2956         fi
2957 }
2958 run_test 33c "test llobdstat and write_bytes"
2959
2960 test_33d() {
2961         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
2962         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2963
2964         local MDTIDX=1
2965         local remote_dir=$DIR/$tdir/remote_dir
2966
2967         test_mkdir $DIR/$tdir
2968         $LFS mkdir -i $MDTIDX $remote_dir ||
2969                 error "create remote directory failed"
2970
2971         touch $remote_dir/$tfile
2972         chmod 444 $remote_dir/$tfile
2973         chown $RUNAS_ID $remote_dir/$tfile
2974
2975         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2976
2977         chown $RUNAS_ID $remote_dir
2978         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2979                                         error "create" || true
2980         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2981                                     error "open RDWR" || true
2982         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2983 }
2984 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2985
2986 test_33e() {
2987         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
2988
2989         mkdir $DIR/$tdir
2990
2991         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2992         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2993         mkdir $DIR/$tdir/local_dir
2994
2995         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2996         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2997         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2998
2999         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3000                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
3001
3002         rmdir $DIR/$tdir/* || error "rmdir failed"
3003
3004         umask 777
3005         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3006         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
3007         mkdir $DIR/$tdir/local_dir
3008
3009         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
3010         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
3011         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
3012
3013         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3014                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
3015
3016         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
3017
3018         umask 000
3019         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3020         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
3021         mkdir $DIR/$tdir/local_dir
3022
3023         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
3024         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
3025         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
3026
3027         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3028                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
3029 }
3030 run_test 33e "mkdir and striped directory should have same mode"
3031
3032 cleanup_33f() {
3033         trap 0
3034         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
3035 }
3036
3037 test_33f() {
3038         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3039         remote_mds_nodsh && skip "remote MDS with nodsh"
3040
3041         mkdir $DIR/$tdir
3042         chmod go+rwx $DIR/$tdir
3043         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
3044         trap cleanup_33f EXIT
3045
3046         $RUNAS lfs mkdir -i 0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
3047                 error "cannot create striped directory"
3048
3049         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
3050                 error "cannot create files in striped directory"
3051
3052         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
3053                 error "cannot remove files in striped directory"
3054
3055         $RUNAS rmdir $DIR/$tdir/striped_dir ||
3056                 error "cannot remove striped directory"
3057
3058         cleanup_33f
3059 }
3060 run_test 33f "nonroot user can create, access, and remove a striped directory"
3061
3062 test_33g() {
3063         mkdir -p $DIR/$tdir/dir2
3064
3065         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
3066         echo $err
3067         [[ $err =~ "exists" ]] || error "Not exists error"
3068 }
3069 run_test 33g "nonroot user create already existing root created file"
3070
3071 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
3072 test_34a() {
3073         rm -f $DIR/f34
3074         $MCREATE $DIR/f34 || error "mcreate failed"
3075         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
3076                 error "getstripe failed"
3077         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error "truncate failed"
3078         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
3079                 error "getstripe failed"
3080         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3081                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3082 }
3083 run_test 34a "truncate file that has not been opened ==========="
3084
3085 test_34b() {
3086         [ ! -f $DIR/f34 ] && test_34a
3087         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3088                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3089         $OPENFILE -f O_RDONLY $DIR/f34
3090         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
3091                 error "getstripe failed"
3092         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3093                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3094 }
3095 run_test 34b "O_RDONLY opening file doesn't create objects ====="
3096
3097 test_34c() {
3098         [ ! -f $DIR/f34 ] && test_34a
3099         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3100                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3101         $OPENFILE -f O_RDWR $DIR/f34
3102         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
3103         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3104                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3105 }
3106 run_test 34c "O_RDWR opening file-with-size works =============="
3107
3108 test_34d() {
3109         [ ! -f $DIR/f34 ] && test_34a
3110         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 ||
3111                 error "dd failed"
3112         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3113                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3114         rm $DIR/f34
3115 }
3116 run_test 34d "write to sparse file ============================="
3117
3118 test_34e() {
3119         rm -f $DIR/f34e
3120         $MCREATE $DIR/f34e || error "mcreate failed"
3121         $TRUNCATE $DIR/f34e 1000 || error "truncate failed"
3122         $CHECKSTAT -s 1000 $DIR/f34e ||
3123                 error "Size of $DIR/f34e not equal to 1000 bytes"
3124         $OPENFILE -f O_RDWR $DIR/f34e
3125         $CHECKSTAT -s 1000 $DIR/f34e ||
3126                 error "Size of $DIR/f34e not equal to 1000 bytes"
3127 }
3128 run_test 34e "create objects, some with size and some without =="
3129
3130 test_34f() { # bug 6242, 6243
3131         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3132
3133         SIZE34F=48000
3134         rm -f $DIR/f34f
3135         $MCREATE $DIR/f34f || error "mcreate failed"
3136         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
3137         dd if=$DIR/f34f of=$TMP/f34f
3138         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
3139         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
3140         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
3141         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
3142         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
3143 }
3144 run_test 34f "read from a file with no objects until EOF ======="
3145
3146 test_34g() {
3147         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3148
3149         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE ||
3150                 error "dd failed"
3151         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error "truncate failed"
3152         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3153                 error "Size of $DIR/$tfile not equal to $((TEST_34_SIZE / 2))"
3154         cancel_lru_locks osc
3155         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3156                 error "wrong size after lock cancel"
3157
3158         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error "truncate failed"
3159         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3160                 error "expanding truncate failed"
3161         cancel_lru_locks osc
3162         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3163                 error "wrong expanded size after lock cancel"
3164 }
3165 run_test 34g "truncate long file ==============================="
3166
3167 test_34h() {
3168         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3169
3170         local gid=10
3171         local sz=1000
3172
3173         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error "dd failed"
3174         sync # Flush the cache so that multiop below does not block on cache
3175              # flush when getting the group lock
3176         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
3177         MULTIPID=$!
3178
3179         # Since just timed wait is not good enough, let's do a sync write
3180         # that way we are sure enough time for a roundtrip + processing
3181         # passed + 2 seconds of extra margin.
3182         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
3183         rm $DIR/${tfile}-1
3184         sleep 2
3185
3186         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
3187                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
3188                 kill -9 $MULTIPID
3189         fi
3190         wait $MULTIPID
3191         local nsz=`stat -c %s $DIR/$tfile`
3192         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
3193 }
3194 run_test 34h "ftruncate file under grouplock should not block"
3195
3196 test_35a() {
3197         cp /bin/sh $DIR/f35a
3198         chmod 444 $DIR/f35a
3199         chown $RUNAS_ID $DIR/f35a
3200         $RUNAS $DIR/f35a && error || true
3201         rm $DIR/f35a
3202 }
3203 run_test 35a "exec file with mode 444 (should return and not leak)"
3204
3205 test_36a() {
3206         rm -f $DIR/f36
3207         utime $DIR/f36 || error "utime failed for MDS"
3208 }
3209 run_test 36a "MDS utime check (mknod, utime)"
3210
3211 test_36b() {
3212         echo "" > $DIR/f36
3213         utime $DIR/f36 || error "utime failed for OST"
3214 }
3215 run_test 36b "OST utime check (open, utime)"
3216
3217 test_36c() {
3218         rm -f $DIR/d36/f36
3219         test_mkdir $DIR/d36
3220         chown $RUNAS_ID $DIR/d36
3221         $RUNAS utime $DIR/d36/f36 || error "utime failed for MDS as non-root"
3222 }
3223 run_test 36c "non-root MDS utime check (mknod, utime)"
3224
3225 test_36d() {
3226         [ ! -d $DIR/d36 ] && test_36c
3227         echo "" > $DIR/d36/f36
3228         $RUNAS utime $DIR/d36/f36 || error "utime failed for OST as non-root"
3229 }
3230 run_test 36d "non-root OST utime check (open, utime)"
3231
3232 test_36e() {
3233         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping"
3234
3235         test_mkdir $DIR/$tdir
3236         touch $DIR/$tdir/$tfile
3237         $RUNAS utime $DIR/$tdir/$tfile &&
3238                 error "utime worked, expected failure" || true
3239 }
3240 run_test 36e "utime on non-owned file (should return error)"
3241
3242 subr_36fh() {
3243         local fl="$1"
3244         local LANG_SAVE=$LANG
3245         local LC_LANG_SAVE=$LC_LANG
3246         export LANG=C LC_LANG=C # for date language
3247
3248         DATESTR="Dec 20  2000"
3249         test_mkdir $DIR/$tdir
3250         lctl set_param fail_loc=$fl
3251         date; date +%s
3252         cp /etc/hosts $DIR/$tdir/$tfile
3253         sync & # write RPC generated with "current" inode timestamp, but delayed
3254         sleep 1
3255         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
3256         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
3257         cancel_lru_locks osc
3258         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
3259         date; date +%s
3260         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
3261                 echo "BEFORE: $LS_BEFORE" && \
3262                 echo "AFTER : $LS_AFTER" && \
3263                 echo "WANT  : $DATESTR" && \
3264                 error "$DIR/$tdir/$tfile timestamps changed" || true
3265
3266         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
3267 }
3268
3269 test_36f() {
3270         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3271
3272         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3273         subr_36fh "0x80000214"
3274 }
3275 run_test 36f "utime on file racing with OST BRW write =========="
3276
3277 test_36g() {
3278         remote_ost_nodsh && skip "remote OST with nodsh"
3279         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3280
3281         local fmd_max_age
3282         local fmd_before
3283         local fmd_after
3284
3285         test_mkdir $DIR/$tdir
3286         fmd_max_age=$(do_facet ost1 \
3287                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
3288                 head -n 1")
3289
3290         fmd_before=$(do_facet ost1 \
3291                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3292         touch $DIR/$tdir/$tfile
3293         sleep $((fmd_max_age + 12))
3294         fmd_after=$(do_facet ost1 \
3295                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3296
3297         echo "fmd_before: $fmd_before"
3298         echo "fmd_after: $fmd_after"
3299         [[ $fmd_after -gt $fmd_before ]] &&
3300                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3301                 error "fmd didn't expire after ping" || true
3302 }
3303 run_test 36g "filter mod data cache expiry ====================="
3304
3305 test_36h() {
3306         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3307
3308         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3309         subr_36fh "0x80000227"
3310 }
3311 run_test 36h "utime on file racing with OST BRW write =========="
3312
3313 test_36i() {
3314         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3315
3316         test_mkdir $DIR/$tdir
3317         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3318
3319         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3320         local new_mtime=$((mtime + 200))
3321
3322         #change Modify time of striped dir
3323         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3324                         error "change mtime failed"
3325
3326         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3327
3328         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3329 }
3330 run_test 36i "change mtime on striped directory"
3331
3332 # test_37 - duplicate with tests 32q 32r
3333
3334 test_38() {
3335         local file=$DIR/$tfile
3336         touch $file
3337         openfile -f O_DIRECTORY $file
3338         local RC=$?
3339         local ENOTDIR=20
3340         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3341         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3342 }
3343 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3344
3345 test_39a() { # was test_39
3346         touch $DIR/$tfile
3347         touch $DIR/${tfile}2
3348 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3349 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3350 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3351         sleep 2
3352         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3353         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3354                 echo "mtime"
3355                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3356                 echo "atime"
3357                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3358                 echo "ctime"
3359                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3360                 error "O_TRUNC didn't change timestamps"
3361         fi
3362 }
3363 run_test 39a "mtime changed on create"
3364
3365 test_39b() {
3366         test_mkdir -c1 $DIR/$tdir
3367         cp -p /etc/passwd $DIR/$tdir/fopen
3368         cp -p /etc/passwd $DIR/$tdir/flink
3369         cp -p /etc/passwd $DIR/$tdir/funlink
3370         cp -p /etc/passwd $DIR/$tdir/frename
3371         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3372
3373         sleep 1
3374         echo "aaaaaa" >> $DIR/$tdir/fopen
3375         echo "aaaaaa" >> $DIR/$tdir/flink
3376         echo "aaaaaa" >> $DIR/$tdir/funlink
3377         echo "aaaaaa" >> $DIR/$tdir/frename
3378
3379         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3380         local link_new=`stat -c %Y $DIR/$tdir/flink`
3381         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3382         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3383
3384         cat $DIR/$tdir/fopen > /dev/null
3385         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3386         rm -f $DIR/$tdir/funlink2
3387         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3388
3389         for (( i=0; i < 2; i++ )) ; do
3390                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3391                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3392                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3393                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3394
3395                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3396                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3397                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3398                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3399
3400                 cancel_lru_locks osc
3401                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3402         done
3403 }
3404 run_test 39b "mtime change on open, link, unlink, rename  ======"
3405
3406 # this should be set to past
3407 TEST_39_MTIME=`date -d "1 year ago" +%s`
3408
3409 # bug 11063
3410 test_39c() {
3411         touch $DIR1/$tfile
3412         sleep 2
3413         local mtime0=`stat -c %Y $DIR1/$tfile`
3414
3415         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3416         local mtime1=`stat -c %Y $DIR1/$tfile`
3417         [ "$mtime1" = $TEST_39_MTIME ] || \
3418                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3419
3420         local d1=`date +%s`
3421         echo hello >> $DIR1/$tfile
3422         local d2=`date +%s`
3423         local mtime2=`stat -c %Y $DIR1/$tfile`
3424         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3425                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3426
3427         mv $DIR1/$tfile $DIR1/$tfile-1
3428
3429         for (( i=0; i < 2; i++ )) ; do
3430                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3431                 [ "$mtime2" = "$mtime3" ] || \
3432                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3433
3434                 cancel_lru_locks osc
3435                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3436         done
3437 }
3438 run_test 39c "mtime change on rename ==========================="
3439
3440 # bug 21114
3441 test_39d() {
3442         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3443
3444         touch $DIR1/$tfile
3445         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3446
3447         for (( i=0; i < 2; i++ )) ; do
3448                 local mtime=`stat -c %Y $DIR1/$tfile`
3449                 [ $mtime = $TEST_39_MTIME ] || \
3450                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3451
3452                 cancel_lru_locks osc
3453                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3454         done
3455 }
3456 run_test 39d "create, utime, stat =============================="
3457
3458 # bug 21114
3459 test_39e() {
3460         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3461
3462         touch $DIR1/$tfile
3463         local mtime1=`stat -c %Y $DIR1/$tfile`
3464
3465         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3466
3467         for (( i=0; i < 2; i++ )) ; do
3468                 local mtime2=`stat -c %Y $DIR1/$tfile`
3469                 [ $mtime2 = $TEST_39_MTIME ] || \
3470                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3471
3472                 cancel_lru_locks osc
3473                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3474         done
3475 }
3476 run_test 39e "create, stat, utime, stat ========================"
3477
3478 # bug 21114
3479 test_39f() {
3480         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3481
3482         touch $DIR1/$tfile
3483         mtime1=`stat -c %Y $DIR1/$tfile`
3484
3485         sleep 2
3486         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3487
3488         for (( i=0; i < 2; i++ )) ; do
3489                 local mtime2=`stat -c %Y $DIR1/$tfile`
3490                 [ $mtime2 = $TEST_39_MTIME ] || \
3491                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3492
3493                 cancel_lru_locks osc
3494                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3495         done
3496 }
3497 run_test 39f "create, stat, sleep, utime, stat ================="
3498
3499 # bug 11063
3500 test_39g() {
3501         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3502
3503         echo hello >> $DIR1/$tfile
3504         local mtime1=`stat -c %Y $DIR1/$tfile`
3505
3506         sleep 2
3507         chmod o+r $DIR1/$tfile
3508
3509         for (( i=0; i < 2; i++ )) ; do
3510                 local mtime2=`stat -c %Y $DIR1/$tfile`
3511                 [ "$mtime1" = "$mtime2" ] || \
3512                         error "lost mtime: $mtime2, should be $mtime1"
3513
3514                 cancel_lru_locks osc
3515                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3516         done
3517 }
3518 run_test 39g "write, chmod, stat ==============================="
3519
3520 # bug 11063
3521 test_39h() {
3522         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3523
3524         touch $DIR1/$tfile
3525         sleep 1
3526
3527         local d1=`date`
3528         echo hello >> $DIR1/$tfile
3529         local mtime1=`stat -c %Y $DIR1/$tfile`
3530
3531         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3532         local d2=`date`
3533         if [ "$d1" != "$d2" ]; then
3534                 echo "write and touch not within one second"
3535         else
3536                 for (( i=0; i < 2; i++ )) ; do
3537                         local mtime2=`stat -c %Y $DIR1/$tfile`
3538                         [ "$mtime2" = $TEST_39_MTIME ] || \
3539                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3540
3541                         cancel_lru_locks osc
3542                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3543                 done
3544         fi
3545 }
3546 run_test 39h "write, utime within one second, stat ============="
3547
3548 test_39i() {
3549         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3550
3551         touch $DIR1/$tfile
3552         sleep 1
3553
3554         echo hello >> $DIR1/$tfile
3555         local mtime1=`stat -c %Y $DIR1/$tfile`
3556
3557         mv $DIR1/$tfile $DIR1/$tfile-1
3558
3559         for (( i=0; i < 2; i++ )) ; do
3560                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3561
3562                 [ "$mtime1" = "$mtime2" ] || \
3563                         error "lost mtime: $mtime2, should be $mtime1"
3564
3565                 cancel_lru_locks osc
3566                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3567         done
3568 }
3569 run_test 39i "write, rename, stat =============================="
3570
3571 test_39j() {
3572         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3573
3574         start_full_debug_logging
3575         touch $DIR1/$tfile
3576         sleep 1
3577
3578         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3579         lctl set_param fail_loc=0x80000412
3580         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3581                 error "multiop failed"
3582         local multipid=$!
3583         local mtime1=`stat -c %Y $DIR1/$tfile`
3584
3585         mv $DIR1/$tfile $DIR1/$tfile-1
3586
3587         kill -USR1 $multipid
3588         wait $multipid || error "multiop close failed"
3589
3590         for (( i=0; i < 2; i++ )) ; do
3591                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3592                 [ "$mtime1" = "$mtime2" ] ||
3593                         error "mtime is lost on close: $mtime2, " \
3594                               "should be $mtime1"
3595
3596                 cancel_lru_locks osc
3597                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3598         done
3599         lctl set_param fail_loc=0
3600         stop_full_debug_logging
3601 }
3602 run_test 39j "write, rename, close, stat ======================="
3603
3604 test_39k() {
3605         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3606
3607         touch $DIR1/$tfile
3608         sleep 1
3609
3610         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3611         local multipid=$!
3612         local mtime1=`stat -c %Y $DIR1/$tfile`
3613
3614         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3615
3616         kill -USR1 $multipid
3617         wait $multipid || error "multiop close failed"
3618
3619         for (( i=0; i < 2; i++ )) ; do
3620                 local mtime2=`stat -c %Y $DIR1/$tfile`
3621
3622                 [ "$mtime2" = $TEST_39_MTIME ] || \
3623                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3624
3625                 cancel_lru_locks osc
3626                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3627         done
3628 }
3629 run_test 39k "write, utime, close, stat ========================"
3630
3631 # this should be set to future
3632 TEST_39_ATIME=`date -d "1 year" +%s`
3633
3634 test_39l() {
3635         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3636         remote_mds_nodsh && skip "remote MDS with nodsh"
3637
3638         local atime_diff=$(do_facet $SINGLEMDS \
3639                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3640         rm -rf $DIR/$tdir
3641         mkdir -p $DIR/$tdir
3642
3643         # test setting directory atime to future
3644         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3645         local atime=$(stat -c %X $DIR/$tdir)
3646         [ "$atime" = $TEST_39_ATIME ] ||
3647                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3648
3649         # test setting directory atime from future to now
3650         local now=$(date +%s)
3651         touch -a -d @$now $DIR/$tdir
3652
3653         atime=$(stat -c %X $DIR/$tdir)
3654         [ "$atime" -eq "$now"  ] ||
3655                 error "atime is not updated from future: $atime, $now"
3656
3657         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3658         sleep 3
3659
3660         # test setting directory atime when now > dir atime + atime_diff
3661         local d1=$(date +%s)
3662         ls $DIR/$tdir
3663         local d2=$(date +%s)
3664         cancel_lru_locks mdc
3665         atime=$(stat -c %X $DIR/$tdir)
3666         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3667                 error "atime is not updated  : $atime, should be $d2"
3668
3669         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3670         sleep 3
3671
3672         # test not setting directory atime when now < dir atime + atime_diff
3673         ls $DIR/$tdir
3674         cancel_lru_locks mdc
3675         atime=$(stat -c %X $DIR/$tdir)
3676         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3677                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3678
3679         do_facet $SINGLEMDS \
3680                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3681 }
3682 run_test 39l "directory atime update ==========================="
3683
3684 test_39m() {
3685         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3686
3687         touch $DIR1/$tfile
3688         sleep 2
3689         local far_past_mtime=$(date -d "May 29 1953" +%s)
3690         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3691
3692         touch -m -d @$far_past_mtime $DIR1/$tfile
3693         touch -a -d @$far_past_atime $DIR1/$tfile
3694
3695         for (( i=0; i < 2; i++ )) ; do
3696                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3697                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3698                         error "atime or mtime set incorrectly"
3699
3700                 cancel_lru_locks osc
3701                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3702         done
3703 }
3704 run_test 39m "test atime and mtime before 1970"
3705
3706 test_39n() { # LU-3832
3707         remote_mds_nodsh && skip "remote MDS with nodsh"
3708
3709         local atime_diff=$(do_facet $SINGLEMDS \
3710                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3711         local atime0
3712         local atime1
3713         local atime2
3714
3715         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3716
3717         rm -rf $DIR/$tfile
3718         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3719         atime0=$(stat -c %X $DIR/$tfile)
3720
3721         sleep 5
3722         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3723         atime1=$(stat -c %X $DIR/$tfile)
3724
3725         sleep 5
3726         cancel_lru_locks mdc
3727         cancel_lru_locks osc
3728         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3729         atime2=$(stat -c %X $DIR/$tfile)
3730
3731         do_facet $SINGLEMDS \
3732                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3733
3734         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3735         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3736 }
3737 run_test 39n "check that O_NOATIME is honored"
3738
3739 test_39o() {
3740         TESTDIR=$DIR/$tdir/$tfile
3741         [ -e $TESTDIR ] && rm -rf $TESTDIR
3742         mkdir -p $TESTDIR
3743         cd $TESTDIR
3744         links1=2
3745         ls
3746         mkdir a b
3747         ls
3748         links2=$(stat -c %h .)
3749         [ $(($links1 + 2)) != $links2 ] &&
3750                 error "wrong links count $(($links1 + 2)) != $links2"
3751         rmdir b
3752         links3=$(stat -c %h .)
3753         [ $(($links1 + 1)) != $links3 ] &&
3754                 error "wrong links count $links1 != $links3"
3755         return 0
3756 }
3757 run_test 39o "directory cached attributes updated after create"
3758
3759 test_39p() {
3760         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
3761
3762         local MDTIDX=1
3763         TESTDIR=$DIR/$tdir/$tdir
3764         [ -e $TESTDIR ] && rm -rf $TESTDIR
3765         test_mkdir -p $TESTDIR
3766         cd $TESTDIR
3767         links1=2
3768         ls
3769         test_mkdir -i $MDTIDX $TESTDIR/remote_dir1
3770         test_mkdir -i $MDTIDX $TESTDIR/remote_dir2
3771         ls
3772         links2=$(stat -c %h .)
3773         [ $(($links1 + 2)) != $links2 ] &&
3774                 error "wrong links count $(($links1 + 2)) != $links2"
3775         rmdir remote_dir2
3776         links3=$(stat -c %h .)
3777         [ $(($links1 + 1)) != $links3 ] &&
3778                 error "wrong links count $links1 != $links3"
3779         return 0
3780 }
3781 run_test 39p "remote directory cached attributes updated after create ========"
3782
3783
3784 test_39q() { # LU-8041
3785         local testdir=$DIR/$tdir
3786         mkdir -p $testdir
3787         multiop_bg_pause $testdir D_c || error "multiop failed"
3788         local multipid=$!
3789         cancel_lru_locks mdc
3790         kill -USR1 $multipid
3791         local atime=$(stat -c %X $testdir)
3792         [ "$atime" -ne 0 ] || error "atime is zero"
3793 }
3794 run_test 39q "close won't zero out atime"
3795
3796 test_40() {
3797         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3798         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3799                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3800         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3801                 error "$tfile is not 4096 bytes in size"
3802 }
3803 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3804
3805 test_41() {
3806         # bug 1553
3807         small_write $DIR/f41 18
3808 }
3809 run_test 41 "test small file write + fstat ====================="
3810
3811 count_ost_writes() {
3812         lctl get_param -n ${OSC}.*.stats |
3813                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3814                         END { printf("%0.0f", writes) }'
3815 }
3816
3817 # decent default
3818 WRITEBACK_SAVE=500
3819 DIRTY_RATIO_SAVE=40
3820 MAX_DIRTY_RATIO=50
3821 BG_DIRTY_RATIO_SAVE=10
3822 MAX_BG_DIRTY_RATIO=25
3823
3824 start_writeback() {
3825         trap 0
3826         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3827         # dirty_ratio, dirty_background_ratio
3828         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3829                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3830                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3831                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3832         else
3833                 # if file not here, we are a 2.4 kernel
3834                 kill -CONT `pidof kupdated`
3835         fi
3836 }
3837
3838 stop_writeback() {
3839         # setup the trap first, so someone cannot exit the test at the
3840         # exact wrong time and mess up a machine
3841         trap start_writeback EXIT
3842         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3843         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3844                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3845                 sysctl -w vm.dirty_writeback_centisecs=0
3846                 sysctl -w vm.dirty_writeback_centisecs=0
3847                 # save and increase /proc/sys/vm/dirty_ratio
3848                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3849                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3850                 # save and increase /proc/sys/vm/dirty_background_ratio
3851                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3852                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3853         else
3854                 # if file not here, we are a 2.4 kernel
3855                 kill -STOP `pidof kupdated`
3856         fi
3857 }
3858
3859 # ensure that all stripes have some grant before we test client-side cache
3860 setup_test42() {
3861         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3862                 dd if=/dev/zero of=$i bs=4k count=1
3863                 rm $i
3864         done
3865 }
3866
3867 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3868 # file truncation, and file removal.
3869 test_42a() {
3870         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3871
3872         setup_test42
3873         cancel_lru_locks $OSC
3874         stop_writeback
3875         sync; sleep 1; sync # just to be safe
3876         BEFOREWRITES=`count_ost_writes`
3877         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3878         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3879         AFTERWRITES=`count_ost_writes`
3880         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3881                 error "$BEFOREWRITES < $AFTERWRITES"
3882         start_writeback
3883 }
3884 run_test 42a "ensure that we don't flush on close"
3885
3886 test_42b() {
3887         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3888
3889         setup_test42
3890         cancel_lru_locks $OSC
3891         stop_writeback
3892         sync
3893         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3894         BEFOREWRITES=$(count_ost_writes)
3895         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3896         AFTERWRITES=$(count_ost_writes)
3897         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3898                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3899         fi
3900         BEFOREWRITES=$(count_ost_writes)
3901         sync || error "sync: $?"
3902         AFTERWRITES=$(count_ost_writes)
3903         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3904                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3905         fi
3906         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3907         start_writeback
3908         return 0
3909 }
3910 run_test 42b "test destroy of file with cached dirty data ======"
3911
3912 # if these tests just want to test the effect of truncation,
3913 # they have to be very careful.  consider:
3914 # - the first open gets a {0,EOF}PR lock
3915 # - the first write conflicts and gets a {0, count-1}PW
3916 # - the rest of the writes are under {count,EOF}PW
3917 # - the open for truncate tries to match a {0,EOF}PR
3918 #   for the filesize and cancels the PWs.
3919 # any number of fixes (don't get {0,EOF} on open, match
3920 # composite locks, do smarter file size management) fix
3921 # this, but for now we want these tests to verify that
3922 # the cancellation with truncate intent works, so we
3923 # start the file with a full-file pw lock to match against
3924 # until the truncate.
3925 trunc_test() {
3926         test=$1
3927         file=$DIR/$test
3928         offset=$2
3929         cancel_lru_locks $OSC
3930         stop_writeback
3931         # prime the file with 0,EOF PW to match
3932         touch $file
3933         $TRUNCATE $file 0
3934         sync; sync
3935         # now the real test..
3936         dd if=/dev/zero of=$file bs=1024 count=100
3937         BEFOREWRITES=`count_ost_writes`
3938         $TRUNCATE $file $offset
3939         cancel_lru_locks $OSC
3940         AFTERWRITES=`count_ost_writes`
3941         start_writeback
3942 }
3943
3944 test_42c() {
3945         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3946
3947         trunc_test 42c 1024
3948         [ $BEFOREWRITES -eq $AFTERWRITES ] &&
3949                 error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3950         rm $file
3951 }
3952 run_test 42c "test partial truncate of file with cached dirty data"
3953
3954 test_42d() {
3955         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3956
3957         trunc_test 42d 0
3958         [ $BEFOREWRITES -eq $AFTERWRITES ] ||
3959                 error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3960         rm $file
3961 }
3962 run_test 42d "test complete truncate of file with cached dirty data"
3963
3964 test_42e() { # bug22074
3965         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3966
3967         local TDIR=$DIR/${tdir}e
3968         local pagesz=$(page_size)
3969         local pages=16 # hardcoded 16 pages, don't change it.
3970         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3971         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3972         local max_dirty_mb
3973         local warmup_files
3974
3975         test_mkdir $DIR/${tdir}e
3976         $SETSTRIPE -c 1 $TDIR
3977         createmany -o $TDIR/f $files
3978
3979         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3980
3981         # we assume that with $OSTCOUNT files, at least one of them will
3982         # be allocated on OST0.
3983         warmup_files=$((OSTCOUNT * max_dirty_mb))
3984         createmany -o $TDIR/w $warmup_files
3985
3986         # write a large amount of data into one file and sync, to get good
3987         # avail_grant number from OST.
3988         for ((i=0; i<$warmup_files; i++)); do
3989                 idx=$($GETSTRIPE -i $TDIR/w$i)
3990                 [ $idx -ne 0 ] && continue
3991                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3992                 break
3993         done
3994         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3995         sync
3996         $LCTL get_param $proc_osc0/cur_dirty_bytes
3997         $LCTL get_param $proc_osc0/cur_grant_bytes
3998
3999         # create as much dirty pages as we can while not to trigger the actual
4000         # RPCs directly. but depends on the env, VFS may trigger flush during this
4001         # period, hopefully we are good.
4002         for ((i=0; i<$warmup_files; i++)); do
4003                 idx=$($GETSTRIPE -i $TDIR/w$i)
4004                 [ $idx -ne 0 ] && continue
4005                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
4006         done
4007         $LCTL get_param $proc_osc0/cur_dirty_bytes
4008         $LCTL get_param $proc_osc0/cur_grant_bytes
4009
4010         # perform the real test
4011         $LCTL set_param $proc_osc0/rpc_stats 0
4012         for ((;i<$files; i++)); do
4013                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
4014                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
4015         done
4016         sync
4017         $LCTL get_param $proc_osc0/rpc_stats
4018
4019         local percent=0
4020         local have_ppr=false
4021         $LCTL get_param $proc_osc0/rpc_stats |
4022                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
4023                         # skip lines until we are at the RPC histogram data
4024                         [ "$PPR" == "pages" ] && have_ppr=true && continue
4025                         $have_ppr || continue
4026
4027                         # we only want the percent stat for < 16 pages
4028                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
4029
4030                         percent=$((percent + WPCT))
4031                         if [[ $percent -gt 15 ]]; then
4032                                 error "less than 16-pages write RPCs" \
4033                                       "$percent% > 15%"
4034                                 break
4035                         fi
4036                 done
4037         rm -rf $TDIR
4038 }
4039 run_test 42e "verify sub-RPC writes are not done synchronously"
4040
4041 test_43A() { # was test_43
4042         test_mkdir $DIR/$tdir
4043         cp -p /bin/ls $DIR/$tdir/$tfile
4044         $MULTIOP $DIR/$tdir/$tfile Ow_c &
4045         pid=$!
4046         # give multiop a chance to open
4047         sleep 1
4048
4049         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
4050         kill -USR1 $pid
4051 }
4052 run_test 43A "execution of file opened for write should return -ETXTBSY"
4053
4054 test_43a() {
4055         test_mkdir $DIR/$tdir
4056         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
4057                 cp -p multiop $DIR/$tdir/multiop
4058         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
4059                 error "multiop open $TMP/$tfile.junk failed"
4060         rm $TMP/$tfile.junk     # delete junk file on close (not part of test)
4061         MULTIOP_PID=$!
4062         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
4063         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
4064         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
4065 }
4066 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
4067
4068 test_43b() {
4069         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4070
4071         test_mkdir $DIR/$tdir
4072         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
4073                 cp -p multiop $DIR/$tdir/multiop
4074         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
4075                 error "multiop open $TMP/$tfile.junk failed"
4076         rm $TMP/$tfile.junk     # delete junk file on close (not part of test)
4077         MULTIOP_PID=$!
4078         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
4079         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
4080         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
4081 }
4082 run_test 43b "truncate of file being executed should return -ETXTBSY"
4083
4084 test_43c() {
4085         local testdir="$DIR/$tdir"
4086         test_mkdir $testdir
4087         cp $SHELL $testdir/
4088         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
4089                 ( cd $testdir && md5sum -c )
4090 }
4091 run_test 43c "md5sum of copy into lustre"
4092
4093 test_44A() { # was test_44
4094         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4095
4096         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
4097         dd if=$DIR/f1 bs=4k count=1 > /dev/null
4098 }
4099 run_test 44A "zero length read from a sparse stripe"
4100
4101 test_44a() {
4102         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
4103                 awk '{ print $2 }')
4104         [ -z "$nstripe" ] && skip "can't get stripe info"
4105         [[ $nstripe -gt $OSTCOUNT ]] &&
4106                 skip "Wrong default_stripe_count: $nstripe OSTCOUNT: $OSTCOUNT"
4107
4108         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
4109                 awk '{ print $2 }')
4110         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
4111                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
4112                         awk '{ print $2 }')
4113         fi
4114
4115         OFFSETS="0 $((stride/2)) $((stride-1))"
4116         for offset in $OFFSETS; do
4117                 for i in $(seq 0 $((nstripe-1))); do
4118                         local GLOBALOFFSETS=""
4119                         # size in Bytes
4120                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
4121                         local myfn=$DIR/d44a-$size
4122                         echo "--------writing $myfn at $size"
4123                         ll_sparseness_write $myfn $size ||
4124                                 error "ll_sparseness_write"
4125                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
4126                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
4127                                 error "ll_sparseness_verify $GLOBALOFFSETS"
4128
4129                         for j in $(seq 0 $((nstripe-1))); do
4130                                 # size in Bytes
4131                                 size=$((((j + $nstripe )*$stride + $offset)))
4132                                 ll_sparseness_write $myfn $size ||
4133                                         error "ll_sparseness_write"
4134                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
4135                         done
4136                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
4137                                 error "ll_sparseness_verify $GLOBALOFFSETS"
4138                         rm -f $myfn
4139                 done
4140         done
4141 }
4142 run_test 44a "test sparse pwrite ==============================="
4143
4144 dirty_osc_total() {
4145         tot=0
4146         for d in `lctl get_param -n ${OSC}.*.cur_dirty_bytes`; do
4147                 tot=$(($tot + $d))
4148         done
4149         echo $tot
4150 }
4151 do_dirty_record() {
4152         before=`dirty_osc_total`
4153         echo executing "\"$*\""
4154         eval $*
4155         after=`dirty_osc_total`
4156         echo before $before, after $after
4157 }
4158 test_45() {
4159         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4160
4161         f="$DIR/f45"
4162         # Obtain grants from OST if it supports it
4163         echo blah > ${f}_grant
4164         stop_writeback
4165         sync
4166         do_dirty_record "echo blah > $f"
4167         [[ $before -eq $after ]] && error "write wasn't cached"
4168         do_dirty_record "> $f"
4169         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
4170         do_dirty_record "echo blah > $f"
4171         [[ $before -eq $after ]] && error "write wasn't cached"
4172         do_dirty_record "sync"
4173         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
4174         do_dirty_record "echo blah > $f"
4175         [[ $before -eq $after ]] && error "write wasn't cached"
4176         do_dirty_record "cancel_lru_locks osc"
4177         [[ $before -gt $after ]] ||
4178                 error "lock cancellation didn't lower dirty count"
4179         start_writeback
4180 }
4181 run_test 45 "osc io page accounting ============================"
4182
4183 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
4184 # test tickles a bug where re-dirtying a page was failing to be mapped to the
4185 # objects offset and an assert hit when an rpc was built with 1023's mapped
4186 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
4187 test_46() {
4188         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4189
4190         f="$DIR/f46"
4191         stop_writeback
4192         sync
4193         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
4194         sync
4195         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
4196         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
4197         sync
4198         start_writeback
4199 }
4200 run_test 46 "dirtying a previously written page ================"
4201
4202 # test_47 is removed "Device nodes check" is moved to test_28
4203
4204 test_48a() { # bug 2399
4205         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
4206         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
4207                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly"
4208
4209         test_mkdir $DIR/$tdir
4210         cd $DIR/$tdir
4211         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
4212         test_mkdir $DIR/$tdir
4213         touch foo || error "'touch foo' failed after recreating cwd"
4214         test_mkdir bar
4215         touch .foo || error "'touch .foo' failed after recreating cwd"
4216         test_mkdir .bar
4217         ls . > /dev/null || error "'ls .' failed after recreating cwd"
4218         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4219         cd . || error "'cd .' failed after recreating cwd"
4220         mkdir . && error "'mkdir .' worked after recreating cwd"
4221         rmdir . && error "'rmdir .' worked after recreating cwd"
4222         ln -s . baz || error "'ln -s .' failed after recreating cwd"
4223         cd .. || error "'cd ..' failed after recreating cwd"
4224 }
4225 run_test 48a "Access renamed working dir (should return errors)="
4226
4227 test_48b() { # bug 2399
4228         rm -rf $DIR/$tdir
4229         test_mkdir $DIR/$tdir
4230         cd $DIR/$tdir
4231         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
4232         touch foo && error "'touch foo' worked after removing cwd"
4233         mkdir foo && error "'mkdir foo' worked after removing cwd"
4234         touch .foo && error "'touch .foo' worked after removing cwd"
4235         mkdir .foo && error "'mkdir .foo' worked after removing cwd"
4236         ls . > /dev/null && error "'ls .' worked after removing cwd"
4237         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4238         mkdir . && error "'mkdir .' worked after removing cwd"
4239         rmdir . && error "'rmdir .' worked after removing cwd"
4240         ln -s . foo && error "'ln -s .' worked after removing cwd"
4241         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
4242 }
4243 run_test 48b "Access removed working dir (should return errors)="
4244
4245 test_48c() { # bug 2350
4246         #lctl set_param debug=-1
4247         #set -vx
4248         rm -rf $DIR/$tdir
4249         test_mkdir -p $DIR/$tdir/dir
4250         cd $DIR/$tdir/dir
4251         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4252         $TRACE touch foo && error "touch foo worked after removing cwd"
4253         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
4254         touch .foo && error "touch .foo worked after removing cwd"
4255         mkdir .foo && error "mkdir .foo worked after removing cwd"
4256         $TRACE ls . && error "'ls .' worked after removing cwd"
4257         $TRACE ls .. || error "'ls ..' failed after removing cwd"
4258         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
4259         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
4260         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
4261         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
4262 }
4263 run_test 48c "Access removed working subdir (should return errors)"
4264
4265 test_48d() { # bug 2350
4266         #lctl set_param debug=-1
4267         #set -vx
4268         rm -rf $DIR/$tdir
4269         test_mkdir -p $DIR/$tdir/dir
4270         cd $DIR/$tdir/dir
4271         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4272         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4273         $TRACE touch foo && error "'touch foo' worked after removing parent"
4274         $TRACE mkdir foo && error "mkdir foo worked after removing parent"
4275         touch .foo && error "'touch .foo' worked after removing parent"
4276         mkdir .foo && error "mkdir .foo worked after removing parent"
4277         $TRACE ls . && error "'ls .' worked after removing parent"
4278         $TRACE ls .. && error "'ls ..' worked after removing parent"
4279         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
4280         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
4281         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
4282         true
4283 }
4284 run_test 48d "Access removed parent subdir (should return errors)"
4285
4286 test_48e() { # bug 4134
4287         #lctl set_param debug=-1
4288         #set -vx
4289         rm -rf $DIR/$tdir
4290         test_mkdir -p $DIR/$tdir/dir
4291         cd $DIR/$tdir/dir
4292         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4293         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4294         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
4295         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
4296         # On a buggy kernel addition of "touch foo" after cd .. will
4297         # produce kernel oops in lookup_hash_it
4298         touch ../foo && error "'cd ..' worked after recreate parent"
4299         cd $DIR
4300         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
4301 }
4302 run_test 48e "Access to recreated parent subdir (should return errors)"
4303
4304 test_49() { # LU-1030
4305         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4306         remote_ost_nodsh && skip "remote OST with nodsh"
4307
4308         # get ost1 size - lustre-OST0000
4309         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
4310                 awk '{ print $4 }')
4311         # write 800M at maximum
4312         [[ $ost1_size -lt 2 ]] && ost1_size=2
4313         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
4314
4315         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
4316         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
4317         local dd_pid=$!
4318
4319         # change max_pages_per_rpc while writing the file
4320         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
4321         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
4322         # loop until dd process exits
4323         while ps ax -opid | grep -wq $dd_pid; do
4324                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4325                 sleep $((RANDOM % 5 + 1))
4326         done
4327         # restore original max_pages_per_rpc
4328         $LCTL set_param $osc1_mppc=$orig_mppc
4329         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4330 }
4331 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4332
4333 test_50() {
4334         # bug 1485
4335         test_mkdir $DIR/$tdir
4336         cd $DIR/$tdir
4337         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4338 }
4339 run_test 50 "special situations: /proc symlinks  ==============="
4340
4341 test_51a() {    # was test_51
4342         # bug 1516 - create an empty entry right after ".." then split dir
4343         test_mkdir -c1 $DIR/$tdir
4344         touch $DIR/$tdir/foo
4345         $MCREATE $DIR/$tdir/bar
4346         rm $DIR/$tdir/foo
4347         createmany -m $DIR/$tdir/longfile 201
4348         FNUM=202
4349         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4350                 $MCREATE $DIR/$tdir/longfile$FNUM
4351                 FNUM=$(($FNUM + 1))
4352                 echo -n "+"
4353         done
4354         echo
4355         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4356 }
4357 run_test 51a "special situations: split htree with empty entry =="
4358
4359 cleanup_print_lfs_df () {
4360         trap 0
4361         $LFS df
4362         $LFS df -i
4363 }
4364
4365 test_51b() {
4366         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4367
4368         local dir=$DIR/$tdir
4369         local nrdirs=$((65536 + 100))
4370
4371         # cleanup the directory
4372         rm -fr $dir
4373
4374         test_mkdir -c1 $dir
4375
4376         $LFS df
4377         $LFS df -i
4378         local mdtidx=$(printf "%04x" $($LFS getstripe -m $dir))
4379         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4380         [[ $numfree -lt $nrdirs ]] &&
4381                 skip "not enough free inodes ($numfree) on MDT$mdtidx"
4382
4383         # need to check free space for the directories as well
4384         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4385         numfree=$(( blkfree / $(fs_inode_ksize) ))
4386         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)"
4387
4388         trap cleanup_print_lfs_df EXIT
4389
4390         # create files
4391         createmany -d $dir/d $nrdirs || {
4392                 unlinkmany $dir/d $nrdirs
4393                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
4394         }
4395
4396         # really created :
4397         nrdirs=$(ls -U $dir | wc -l)
4398
4399         # unlink all but 100 subdirectories, then check it still works
4400         local left=100
4401         local delete=$((nrdirs - left))
4402
4403         $LFS df
4404         $LFS df -i
4405
4406         # for ldiskfs the nlink count should be 1, but this is OSD specific
4407         # and so this is listed for informational purposes only
4408         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
4409         unlinkmany -d $dir/d $delete ||
4410                 error "unlink of first $delete subdirs failed"
4411
4412         echo "nlink between: $(stat -c %h $dir)"
4413         local found=$(ls -U $dir | wc -l)
4414         [ $found -ne $left ] &&
4415                 error "can't find subdirs: found only $found, expected $left"
4416
4417         unlinkmany -d $dir/d $delete $left ||
4418                 error "unlink of second $left subdirs failed"
4419         # regardless of whether the backing filesystem tracks nlink accurately
4420         # or not, the nlink count shouldn't be more than "." and ".." here
4421         local after=$(stat -c %h $dir)
4422         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
4423                 echo "nlink after: $after"
4424
4425         cleanup_print_lfs_df
4426 }
4427 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
4428
4429 test_51d() {
4430         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4431         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs"
4432
4433         test_mkdir $DIR/$tdir
4434         createmany -o $DIR/$tdir/t- 1000
4435         $LFS getstripe $DIR/$tdir > $TMP/$tfile
4436         for N in $(seq 0 $((OSTCOUNT - 1))); do
4437                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4438                         END { printf("%0.0f", objs) }' $TMP/$tfile)
4439                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
4440                         '($1 == '$N') { objs += 1 } \
4441                         END { printf("%0.0f", objs) }')
4442                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4443         done
4444         unlinkmany $DIR/$tdir/t- 1000
4445
4446         NLAST=0
4447         for N in $(seq 1 $((OSTCOUNT - 1))); do
4448                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4449                         error "OST $N has less objects vs OST $NLAST" \
4450                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4451                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4452                         error "OST $N has less objects vs OST $NLAST" \
4453                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4454
4455                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4456                         error "OST $N has less #0 objects vs OST $NLAST" \
4457                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4458                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4459                         error "OST $N has less #0 objects vs OST $NLAST" \
4460                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4461                 NLAST=$N
4462         done
4463         rm -f $TMP/$tfile
4464 }
4465 run_test 51d "check object distribution"
4466
4467 test_51e() {
4468         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4469                 skip_env "ldiskfs only test"
4470         fi
4471
4472         test_mkdir -c1 $DIR/$tdir
4473         test_mkdir -c1 $DIR/$tdir/d0
4474
4475         touch $DIR/$tdir/d0/foo
4476         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4477                 error "file exceed 65000 nlink limit!"
4478         unlinkmany $DIR/$tdir/d0/f- 65001
4479         return 0
4480 }
4481 run_test 51e "check file nlink limit"
4482
4483 test_51f() {
4484         test_mkdir $DIR/$tdir
4485
4486         local max=100000
4487         local ulimit_old=$(ulimit -n)
4488         local spare=20 # number of spare fd's for scripts/libraries, etc.
4489         local mdt=$($LFS getstripe -m $DIR/$tdir)
4490         local numfree=$($LFS df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
4491
4492         echo "MDT$mdt numfree=$numfree, max=$max"
4493         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
4494         if [ $((numfree + spare)) -gt $ulimit_old ]; then
4495                 while ! ulimit -n $((numfree + spare)); do
4496                         numfree=$((numfree * 3 / 4))
4497                 done
4498                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
4499         else
4500                 echo "left ulimit at $ulimit_old"
4501         fi
4502
4503         createmany -o -k -t 120 $DIR/$tdir/f $numfree || {
4504                 unlinkmany $DIR/$tdir/f $numfree
4505                 error "create+open $numfree files in $DIR/$tdir failed"
4506         }
4507         ulimit -n $ulimit_old
4508
4509         # if createmany exits at 120s there will be fewer than $numfree files
4510         unlinkmany $DIR/$tdir/f $numfree || true
4511 }
4512 run_test 51f "check many open files limit"
4513
4514 test_52a() {
4515         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4516         test_mkdir $DIR/$tdir
4517         touch $DIR/$tdir/foo
4518         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4519         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4520         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4521         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4522         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4523                                         error "link worked"
4524         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4525         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4526         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4527                                                      error "lsattr"
4528         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4529         cp -r $DIR/$tdir $TMP/
4530         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
4531 }
4532 run_test 52a "append-only flag test (should return errors)"
4533
4534 test_52b() {
4535         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4536         test_mkdir $DIR/$tdir
4537         touch $DIR/$tdir/foo
4538         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4539         cat test > $DIR/$tdir/foo && error "cat test worked"
4540         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4541         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4542         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4543                                         error "link worked"
4544         echo foo >> $DIR/$tdir/foo && error "echo worked"
4545         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4546         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4547         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4548         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4549                                                         error "lsattr"
4550         chattr -i $DIR/$tdir/foo || error "chattr failed"
4551
4552         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4553 }
4554 run_test 52b "immutable flag test (should return errors) ======="
4555
4556 test_53() {
4557         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4558         remote_mds_nodsh && skip "remote MDS with nodsh"
4559         remote_ost_nodsh && skip "remote OST with nodsh"
4560
4561         local param
4562         local param_seq
4563         local ostname
4564         local mds_last
4565         local mds_last_seq
4566         local ost_last
4567         local ost_last_seq
4568         local ost_last_id
4569         local ostnum
4570         local node
4571         local found=false
4572         local support_last_seq=true
4573
4574         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4575                 support_last_seq=false
4576
4577         # only test MDT0000
4578         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4579         local value
4580         for value in $(do_facet $SINGLEMDS \
4581                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4582                 param=$(echo ${value[0]} | cut -d "=" -f1)
4583                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4584
4585                 if $support_last_seq; then
4586                         param_seq=$(echo $param |
4587                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4588                         mds_last_seq=$(do_facet $SINGLEMDS \
4589                                        $LCTL get_param -n $param_seq)
4590                 fi
4591                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4592
4593                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4594                 node=$(facet_active_host ost$((ostnum+1)))
4595                 param="obdfilter.$ostname.last_id"
4596                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4597                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4598                         ost_last_id=$ost_last
4599
4600                         if $support_last_seq; then
4601                                 ost_last_id=$(echo $ost_last |
4602                                               awk -F':' '{print $2}' |
4603                                               sed -e "s/^0x//g")
4604                                 ost_last_seq=$(echo $ost_last |
4605                                                awk -F':' '{print $1}')
4606                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4607                         fi
4608
4609                         if [[ $ost_last_id != $mds_last ]]; then
4610                                 error "$ost_last_id != $mds_last"
4611                         else
4612                                 found=true
4613                                 break
4614                         fi
4615                 done
4616         done
4617         $found || error "can not match last_seq/last_id for $mdtosc"
4618         return 0
4619 }
4620 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4621
4622 test_54a() {
4623         perl -MSocket -e ';' || skip "no Socket perl module installed"
4624
4625         $SOCKETSERVER $DIR/socket ||
4626                 error "$SOCKETSERVER $DIR/socket failed: $?"
4627         $SOCKETCLIENT $DIR/socket ||
4628                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4629         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4630 }
4631 run_test 54a "unix domain socket test =========================="
4632
4633 test_54b() {
4634         f="$DIR/f54b"
4635         mknod $f c 1 3
4636         chmod 0666 $f
4637         dd if=/dev/zero of=$f bs=$(page_size) count=1
4638 }
4639 run_test 54b "char device works in lustre ======================"
4640
4641 find_loop_dev() {
4642         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4643         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4644         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4645
4646         for i in $(seq 3 7); do
4647                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4648                 LOOPDEV=$LOOPBASE$i
4649                 LOOPNUM=$i
4650                 break
4651         done
4652 }
4653
4654 cleanup_54c() {
4655         local rc=0
4656         loopdev="$DIR/loop54c"
4657
4658         trap 0
4659         $UMOUNT $DIR/$tdir || rc=$?
4660         losetup -d $loopdev || true
4661         losetup -d $LOOPDEV || true
4662         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4663         return $rc
4664 }
4665
4666 test_54c() {
4667         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4668
4669         loopdev="$DIR/loop54c"
4670
4671         find_loop_dev
4672         [ -z "$LOOPNUM" ] && skip_env "couldn't find empty loop device"
4673         trap cleanup_54c EXIT
4674         mknod $loopdev b 7 $LOOPNUM
4675         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4676         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4677         losetup $loopdev $DIR/$tfile ||
4678                 error "can't set up $loopdev for $DIR/$tfile"
4679         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4680         test_mkdir $DIR/$tdir
4681         mount -t ext2 $loopdev $DIR/$tdir ||
4682                 error "error mounting $loopdev on $DIR/$tdir"
4683         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4684                 error "dd write"
4685         df $DIR/$tdir
4686         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4687                 error "dd read"
4688         cleanup_54c
4689 }
4690 run_test 54c "block device works in lustre ====================="
4691
4692 test_54d() {
4693         f="$DIR/f54d"
4694         string="aaaaaa"
4695         mknod $f p
4696         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4697 }
4698 run_test 54d "fifo device works in lustre ======================"
4699
4700 test_54e() {
4701         f="$DIR/f54e"
4702         string="aaaaaa"
4703         cp -aL /dev/console $f
4704         echo $string > $f || error "echo $string to $f failed"
4705 }
4706 run_test 54e "console/tty device works in lustre ======================"
4707
4708 test_56a() {
4709         local numfiles=3
4710         local dir=$DIR/$tdir
4711
4712         rm -rf $dir
4713         test_mkdir -p $dir/dir
4714         for i in $(seq $numfiles); do
4715                 touch $dir/file$i
4716                 touch $dir/dir/file$i
4717         done
4718
4719         local numcomp=$($LFS getstripe --component-count $dir)
4720
4721         [[ $numcomp == 0 ]] && numcomp=1
4722
4723         # test lfs getstripe with --recursive
4724         local filenum=$($LFS getstripe -r $dir | egrep -c "obdidx|l_ost_idx")
4725
4726         [[ $filenum -eq $((numfiles * 2)) ]] ||
4727                 error "$LFS getstripe -r: found $filenum != $((numfiles * 2))"
4728         filenum=$($LFS getstripe $dir | egrep -c "obdidx|l_ost_idx")
4729         [[ $filenum -eq $numfiles ]] ||
4730                 error "$LFS getstripe $dir: found $filenum, not $numfiles"
4731         echo "$LFS getstripe showed obdidx or l_ost_idx"
4732
4733         # test lfs getstripe with file instead of dir
4734         filenum=$($LFS getstripe $dir/file1 | egrep -c "obdidx|l_ost_idx")
4735         [[ $filenum -eq 1 ]] ||
4736                 error "$LFS getstripe $dir/file1: found $filenum, not 1"
4737         echo "$LFS getstripe file1 passed"
4738
4739         #test lfs getstripe with --verbose
4740         filenum=$($LFS getstripe --verbose $dir | grep -c lmm_magic)
4741         [[ $filenum -eq $((numfiles * numcomp)) ]] ||
4742                 error "$LFS getstripe --verbose $dir: "\
4743                       "got $filenum want $((numfiles * numcomp)) lmm_magic"
4744         [[ $($LFS getstripe $dir | grep -c lmm_magic) -eq 0 ]] ||
4745                 error "$LFS getstripe $dir: showed lmm_magic"
4746
4747         #test lfs getstripe with -v prints lmm_fid
4748         filenum=$($LFS getstripe -v $dir | grep -c lmm_fid)
4749         [[ $filenum -eq $((numfiles * numcomp)) ]] ||
4750                 error "$LFS getstripe -v $dir: "\
4751                       "got $filenum want $((numfiles * numcomp)) lmm_fid"
4752         [[ $($LFS getstripe $dir | grep -c lmm_fid) -eq 0 ]] ||
4753                 error "$LFS getstripe $dir: showed lmm_fid by default"
4754         echo "$LFS getstripe --verbose passed"
4755
4756         #check for FID information
4757         local fid1=$($LFS getstripe --fid $dir/file1)
4758         local fid2=$($LFS getstripe --verbose $dir/file1 |
4759                      awk '/lmm_fid: / { print $2; exit; }')
4760         local fid3=$($LFS path2fid $dir/file1)
4761
4762         [ "$fid1" != "$fid2" ] &&
4763                 error "getstripe --fid '$fid1' != getstripe --verbose '$fid2'"
4764         [ "$fid1" != "$fid3" ] &&
4765                 error "getstripe --fid '$fid1' != lfs path2fid '$fid3'"
4766         echo "$LFS getstripe --fid passed"
4767
4768         #test lfs getstripe with --obd
4769         $LFS getstripe --obd wrong_uuid $dir 2>&1 | grep -q "unknown obduuid" ||
4770                 error "$LFS getstripe --obd wrong_uuid: should return error"
4771
4772         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4773
4774         local ostidx=1
4775         local obduuid=$(ostuuid_from_index $ostidx)
4776         local found=$($LFS getstripe -r --obd $obduuid $dir |
4777                 grep 'lmm_stripe_offset:' | grep -c " $ostidx\$")
4778
4779         filenum=$($LFS getstripe -ir $dir | grep -c "^$ostidx\$")
4780         [[ $($LFS getstripe -id $dir) -ne $ostidx ]] ||
4781                 ((filenum--))
4782         [[ $($LFS getstripe -id $dir/dir) -ne $ostidx ]] ||
4783                 ((filenum--))
4784
4785         [[ $found -eq $filenum ]] ||
4786                 error "$LFS getstripe --obd: found $found expect $filenum"
4787         [[ $($LFS getstripe -r -v --obd $obduuid $dir |
4788                 sed '/^[         ]*'${ostidx}'[  ]/d' |
4789                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4790                 error "$LFS getstripe --obd: should not show file on other obd"
4791         echo "$LFS getstripe --obd passed"
4792 }
4793 run_test 56a "check $LFS getstripe"
4794
4795 test_56b() {
4796         local dir=$DIR/$tdir
4797         local numdirs=3
4798
4799         test_mkdir $dir
4800         for i in $(seq $numdirs); do
4801                 test_mkdir $dir/dir$i
4802         done
4803
4804         # test lfs getdirstripe default mode is non-recursion, which is
4805         # different from lfs getstripe
4806         local dircnt=$($LFS getdirstripe $dir | grep -c lmv_stripe_count)
4807
4808         [[ $dircnt -eq 1 ]] ||
4809                 error "$LFS getdirstripe: found $dircnt, not 1"
4810         dircnt=$($LFS getdirstripe --recursive $dir |
4811                 grep -c lmv_stripe_count)
4812         [[ $dircnt -eq $((numdirs + 1)) ]] ||
4813                 error "$LFS getdirstripe -r: $dircnt, != $((numdirs + 1))"
4814 }
4815 run_test 56b "check $LFS getdirstripe"
4816
4817 test_56c() {
4818         remote_ost_nodsh && skip "remote OST with nodsh"
4819
4820         local ost_idx=0
4821         local ost_name=$(ostname_from_index $ost_idx)
4822         local old_status=$(ost_dev_status $ost_idx)
4823
4824         [[ -z "$old_status" ]] ||
4825                 skip_env "OST $ost_name is in $old_status status"
4826
4827         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
4828         sleep_maxage
4829
4830         local new_status=$(ost_dev_status $ost_idx)
4831
4832         [[ "$new_status" = "D" ]] ||
4833                 error "OST $ost_name is in status of '$new_status', not 'D'"
4834
4835         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
4836         sleep_maxage
4837
4838         new_status=$(ost_dev_status $ost_idx)
4839         [[ -z "$new_status" ]] ||
4840                 error "OST $ost_name is in status of '$new_status', not ''"
4841 }
4842 run_test 56c "check 'lfs df' showing device status"
4843
4844 NUMFILES=3
4845 NUMDIRS=3
4846 setup_56() {
4847         local local_tdir="$1"
4848         local local_numfiles="$2"
4849         local local_numdirs="$3"
4850         local dir_params="$4"
4851         local dir_stripe_params="$5"
4852
4853         if [ ! -d "$local_tdir" ] ; then
4854                 test_mkdir -p $dir_stripe_params $local_tdir
4855                 [ "$dir_params" ] && $LFS setstripe $dir_params $local_tdir
4856                 for i in $(seq $local_numfiles) ; do
4857                         touch $local_tdir/file$i
4858                 done
4859                 for i in $(seq $local_numdirs) ; do
4860                         test_mkdir $dir_stripe_params $local_tdir/dir$i
4861                         for j in $(seq $local_numfiles) ; do
4862                                 touch $local_tdir/dir$i/file$j
4863                         done
4864                 done
4865         fi
4866 }
4867
4868 setup_56_special() {
4869         local local_tdir=$1
4870         local local_numfiles=$2
4871         local local_numdirs=$3
4872
4873         setup_56 $local_tdir $local_numfiles $local_numdirs
4874
4875         if [ ! -e "$local_tdir/loop${local_numfiles}b" ] ; then
4876                 for i in $(seq $local_numfiles) ; do
4877                         mknod $local_tdir/loop${i}b b 7 $i
4878                         mknod $local_tdir/null${i}c c 1 3
4879                         ln -s $local_tdir/file1 $local_tdir/link${i}
4880                 done
4881                 for i in $(seq $local_numdirs) ; do
4882                         mknod $local_tdir/dir$i/loop${i}b b 7 $i
4883                         mknod $local_tdir/dir$i/null${i}c c 1 3
4884                         ln -s $local_tdir/dir$i/file1 $local_tdir/dir$i/link${i}
4885                 done
4886         fi
4887 }
4888
4889 test_56g() {
4890         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4891         local expected=$(($NUMDIRS + 2))
4892
4893         setup_56 $dir $NUMFILES $NUMDIRS
4894
4895         # test lfs find with -name
4896         for i in $(seq $NUMFILES) ; do
4897                 local nums=$($LFS find -name "*$i" $dir | wc -l)
4898
4899                 [ $nums -eq $expected ] ||
4900                         error "lfs find -name '*$i' $dir wrong: "\
4901                               "found $nums, expected $expected"
4902         done
4903 }
4904 run_test 56g "check lfs find -name"
4905
4906 test_56h() {
4907         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4908         local expected=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4909
4910         setup_56 $dir $NUMFILES $NUMDIRS
4911
4912         # test lfs find with ! -name
4913         for i in $(seq $NUMFILES) ; do
4914                 local nums=$($LFS find ! -name "*$i" $dir | wc -l)
4915
4916                 [ $nums -eq $expected ] ||
4917                         error "lfs find ! -name '*$i' $dir wrong: "\
4918                               "found $nums, expected $expected"
4919         done
4920 }
4921 run_test 56h "check lfs find ! -name"
4922
4923 test_56i() {
4924         local dir=$DIR/$tdir
4925
4926         test_mkdir $dir
4927
4928         local cmd="$LFS find -ost $(ostuuid_from_index 0 $dir) $dir"
4929         local out=$($cmd)
4930
4931         [ -z "$out" ] || error "'$cmd' returned directory '$out'"
4932 }
4933 run_test 56i "check 'lfs find -ost UUID' skips directories"
4934
4935 test_56j() {
4936         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4937
4938         setup_56_special $dir $NUMFILES $NUMDIRS
4939
4940         local expected=$((NUMDIRS + 1))
4941         local cmd="$LFS find -type d $dir"
4942         local nums=$($cmd | wc -l)
4943
4944         [ $nums -eq $expected ] ||
4945                 error "'$cmd' wrong: found $nums, expected $expected"
4946 }
4947 run_test 56j "check lfs find -type d"
4948
4949 test_56k() {
4950         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4951
4952         setup_56_special $dir $NUMFILES $NUMDIRS
4953
4954         local expected=$(((NUMDIRS + 1) * NUMFILES))
4955         local cmd="$LFS find -type f $dir"
4956         local nums=$($cmd | wc -l)
4957
4958         [ $nums -eq $expected ] ||
4959                 error "'$cmd' wrong: found $nums, expected $expected"
4960 }
4961 run_test 56k "check lfs find -type f"
4962
4963 test_56l() {
4964         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4965
4966         setup_56_special $dir $NUMFILES $NUMDIRS
4967
4968         local expected=$((NUMDIRS + NUMFILES))
4969         local cmd="$LFS find -type b $dir"
4970         local nums=$($cmd | wc -l)
4971
4972         [ $nums -eq $expected ] ||
4973                 error "'$cmd' wrong: found $nums, expected $expected"
4974 }
4975 run_test 56l "check lfs find -type b"
4976
4977 test_56m() {
4978         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4979
4980         setup_56_special $dir $NUMFILES $NUMDIRS
4981
4982         local expected=$((NUMDIRS + NUMFILES))
4983         local cmd="$LFS find -type c $dir"
4984         local nums=$($cmd | wc -l)
4985         [ $nums -eq $expected ] ||
4986                 error "'$cmd' wrong: found $nums, expected $expected"
4987 }
4988 run_test 56m "check lfs find -type c"
4989
4990 test_56n() {
4991         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4992         setup_56_special $dir $NUMFILES $NUMDIRS
4993
4994         local expected=$((NUMDIRS + NUMFILES))
4995         local cmd="$LFS find -type l $dir"
4996         local nums=$($cmd | wc -l)
4997
4998         [ $nums -eq $expected ] ||
4999                 error "'$cmd' wrong: found $nums, expected $expected"
5000 }
5001 run_test 56n "check lfs find -type l"
5002
5003 test_56o() {
5004         local dir=$DIR/$tdir
5005
5006         setup_56 $dir $NUMFILES $NUMDIRS
5007         utime $dir/file1 > /dev/null || error "utime (1)"
5008         utime $dir/file2 > /dev/null || error "utime (2)"
5009         utime $dir/dir1 > /dev/null || error "utime (3)"
5010         utime $dir/dir2 > /dev/null || error "utime (4)"
5011         utime $dir/dir1/file1 > /dev/null || error "utime (5)"
5012         dd if=/dev/zero count=1 >> $dir/dir1/file1 && sync
5013
5014         local expected=4
5015         local nums=$($LFS find -mtime +0 $dir | wc -l)
5016
5017         [ $nums -eq $expected ] ||
5018                 error "lfs find -mtime +0 $dir: found $nums expect $expected"
5019
5020         expected=12
5021         cmd="$LFS find -mtime 0 $dir"
5022         nums=$($cmd | wc -l)
5023         [ $nums -eq $expected ] ||
5024                 error "'$cmd' wrong: found $nums, expected $expected"
5025 }
5026 run_test 56o "check lfs find -mtime for old files"
5027
5028 test_56p() {
5029         [ $RUNAS_ID -eq $UID ] &&
5030                 skip_env "RUNAS_ID = UID = $UID -- skipping"
5031
5032         local dir=$DIR/$tdir
5033
5034         setup_56 $dir $NUMFILES $NUMDIRS
5035         chown $RUNAS_ID $dir/file* || error "chown $DIR/${tdir}g/file$i failed"
5036
5037         local expected=$NUMFILES
5038         local cmd="$LFS find -uid $RUNAS_ID $dir"
5039         local nums=$($cmd | wc -l)
5040
5041         [ $nums -eq $expected ] ||
5042                 error "'$cmd' wrong: found $nums, expected $expected"
5043
5044         expected=$(((NUMFILES + 1) * NUMDIRS + 1))
5045         cmd="$LFS find ! -uid $RUNAS_ID $dir"
5046         nums=$($cmd | wc -l)
5047         [ $nums -eq $expected ] ||
5048                 error "'$cmd' wrong: found $nums, expected $expected"
5049 }
5050 run_test 56p "check lfs find -uid and ! -uid"
5051
5052 test_56q() {
5053         [ $RUNAS_ID -eq $UID ] &&
5054                 skip_env "RUNAS_ID = UID = $UID -- skipping"
5055
5056         local dir=$DIR/$tdir
5057
5058         setup_56 $dir $NUMFILES $NUMDIRS
5059         chgrp $RUNAS_GID $dir/file* || error "chown $dir/file$i failed"
5060
5061         local expected=$NUMFILES
5062         local cmd="$LFS find -gid $RUNAS_GID $dir"
5063         local nums=$($cmd | wc -l)
5064
5065         [ $nums -eq $expected ] ||
5066                 error "'$cmd' wrong: found $nums, expected $expected"
5067
5068         expected=$(( ($NUMFILES+1) * $NUMDIRS + 1))
5069         cmd="$LFS find ! -gid $RUNAS_GID $dir"
5070         nums=$($cmd | wc -l)
5071         [ $nums -eq $expected ] ||
5072                 error "'$cmd' wrong: found $nums, expected $expected"
5073 }
5074 run_test 56q "check lfs find -gid and ! -gid"
5075
5076 test_56r() {
5077         local dir=$DIR/$tdir
5078
5079         setup_56 $dir $NUMFILES $NUMDIRS
5080
5081         local expected=12
5082         local cmd="$LFS find -size 0 -type f $dir"
5083         local nums=$($cmd | wc -l)
5084
5085         [ $nums -eq $expected ] ||
5086                 error "'$cmd' wrong: found $nums, expected $expected"
5087         expected=0
5088         cmd="$LFS find ! -size 0 -type f $dir"
5089         nums=$($cmd | wc -l)
5090         [ $nums -eq $expected ] ||
5091                 error "'$cmd' wrong: found $nums, expected $expected"
5092         echo "test" > $dir/$tfile
5093         echo "test2" > $dir/$tfile.2 && sync
5094         expected=1
5095         cmd="$LFS find -size 5 -type f $dir"
5096         nums=$($cmd | wc -l)
5097         [ $nums -eq $expected ] ||
5098                 error "'$cmd' wrong: found $nums, expected $expected"
5099         expected=1
5100         cmd="$LFS find -size +5 -type f $dir"
5101         nums=$($cmd | wc -l)
5102         [ $nums -eq $expected ] ||
5103                 error "'$cmd' wrong: found $nums, expected $expected"
5104         expected=2
5105         cmd="$LFS find -size +0 -type f $dir"
5106         nums=$($cmd | wc -l)
5107         [ $nums -eq $expected ] ||
5108                 error "'$cmd' wrong: found $nums, expected $expected"
5109         expected=2
5110         cmd="$LFS find ! -size -5 -type f $dir"
5111         nums=$($cmd | wc -l)
5112         [ $nums -eq $expected ] ||
5113                 error "'$cmd' wrong: found $nums, expected $expected"
5114         expected=12
5115         cmd="$LFS find -size -5 -type f $dir"
5116         nums=$($cmd | wc -l)
5117         [ $nums -eq $expected ] ||
5118                 error "'$cmd' wrong: found $nums, expected $expected"
5119 }
5120 run_test 56r "check lfs find -size works"
5121
5122 test_56s() { # LU-611 #LU-9369
5123         [[ $OSTCOUNT -lt 2 ]] && skip_env "need at least 2 OSTs"
5124
5125         local dir=$DIR/$tdir
5126         local onestripe=$(((NUMDIRS + 1) * NUMFILES))
5127
5128         setup_56 $dir $NUMFILES $NUMDIRS "-c 1"
5129         for i in $(seq $NUMDIRS); do
5130                 $LFS setstripe -c $((OSTCOUNT + 1)) $dir/dir$i/$tfile
5131         done
5132
5133         local expected=$NUMDIRS
5134         local cmd="$LFS find -c $OSTCOUNT $dir"
5135         local nums=$($cmd | wc -l)
5136
5137         [ $nums -eq $expected ] || {
5138                 $LFS getstripe -R $dir
5139                 error "'$cmd' wrong: found $nums, expected $expected"
5140         }
5141
5142         expected=$((NUMDIRS + onestripe))
5143         cmd="$LFS find -stripe-count +0 -type f $dir"
5144         nums=$($cmd | wc -l)
5145         [ $nums -eq $expected ] || {
5146                 $LFS getstripe -R $dir
5147                 error "'$cmd' wrong: found $nums, expected $expected"
5148         }
5149
5150         expected=$onestripe
5151         cmd="$LFS find -stripe-count 1 -type f $dir"
5152         nums=$($cmd | wc -l)
5153         [ $nums -eq $expected ] || {
5154                 $LFS getstripe -R $dir
5155                 error "'$cmd' wrong: found $nums, expected $expected"
5156         }
5157
5158         cmd="$LFS find -stripe-count -2 -type f $dir"
5159         nums=$($cmd | wc -l)
5160         [ $nums -eq $expected ] || {
5161                 $LFS getstripe -R $dir
5162                 error "'$cmd' wrong: found $nums, expected $expected"
5163         }
5164
5165         expected=0
5166         cmd="$LFS find -stripe-count $((OSTCOUNT + 1)) -type f $dir"
5167         nums=$($cmd | wc -l)
5168         [ $nums -eq $expected ] || {
5169                 $LFS getstripe -R $dir
5170                 error "'$cmd' wrong: found $nums, expected $expected"
5171         }
5172 }
5173 run_test 56s "check lfs find -stripe-count works"
5174
5175 test_56t() { # LU-611 #LU-9369
5176         local dir=$DIR/$tdir
5177
5178         setup_56 $dir 0 $NUMDIRS
5179         for i in $(seq $NUMDIRS); do
5180                 $LFS setstripe -S 8M $dir/dir$i/$tfile
5181         done
5182
5183         local expected=$NUMDIRS
5184         local cmd="$LFS find -S 8M $dir"
5185         local nums=$($cmd | wc -l)
5186
5187         [ $nums -eq $expected ] || {
5188                 $LFS getstripe -R $dir
5189                 error "'$cmd' wrong: found $nums, expected $expected"
5190         }
5191         rm -rf $dir
5192
5193         setup_56 $dir $NUMFILES $NUMDIRS "--stripe-size 512k"
5194
5195         $LFS setstripe -S 256k $dir/$tfile.{0,1,2,3}
5196
5197         expected=$(((NUMDIRS + 1) * NUMFILES))
5198         cmd="$LFS find -stripe-size 512k -type f $dir"
5199         nums=$($cmd | wc -l)
5200         [ $nums -eq $expected ] ||
5201                 error "'$cmd' wrong: found $nums, expected $expected"
5202
5203         cmd="$LFS find -stripe-size +320k -type f $dir"
5204         nums=$($cmd | wc -l)
5205         [ $nums -eq $expected ] ||
5206                 error "'$cmd' wrong: found $nums, expected $expected"
5207
5208         expected=$(((NUMDIRS + 1) * NUMFILES + 4))
5209         cmd="$LFS find -stripe-size +200k -type f $dir"
5210         nums=$($cmd | wc -l)
5211         [ $nums -eq $expected ] ||
5212                 error "'$cmd' wrong: found $nums, expected $expected"
5213
5214         cmd="$LFS find -stripe-size -640k -type f $dir"
5215         nums=$($cmd | wc -l)
5216         [ $nums -eq $expected ] ||
5217                 error "'$cmd' wrong: found $nums, expected $expected"
5218
5219         expected=4
5220         cmd="$LFS find -stripe-size 256k -type f $dir"
5221         nums=$($cmd | wc -l)
5222         [ $nums -eq $expected ] ||
5223                 error "'$cmd' wrong: found $nums, expected $expected"
5224
5225         cmd="$LFS find -stripe-size -320k -type f $dir"
5226         nums=$($cmd | wc -l)
5227         [ $nums -eq $expected ] ||
5228                 error "'$cmd' wrong: found $nums, expected $expected"
5229
5230         expected=0
5231         cmd="$LFS find -stripe-size 1024k -type f $dir"
5232         nums=$($cmd | wc -l)
5233         [ $nums -eq $expected ] ||
5234                 error "'$cmd' wrong: found $nums, expected $expected"
5235 }
5236 run_test 56t "check lfs find -stripe-size works"
5237
5238 test_56u() { # LU-611
5239         local dir=$DIR/$tdir
5240
5241         setup_56 $dir $NUMFILES $NUMDIRS "-i 0 -c 1"
5242
5243         if [[ $OSTCOUNT -gt 1 ]]; then
5244                 $LFS setstripe -i 1 -c 1 $dir/$tfile.{0,1,2,3}
5245                 onestripe=4
5246         else
5247                 onestripe=0
5248         fi
5249
5250         local expected=$(((NUMDIRS + 1) * NUMFILES))
5251         local cmd="$LFS find -stripe-index 0 -type f $dir"
5252         local nums=$($cmd | wc -l)
5253
5254         [ $nums -eq $expected ] ||
5255                 error "'$cmd' wrong: found $nums, expected $expected"
5256
5257         expected=$onestripe
5258         cmd="$LFS find -stripe-index 1 -type f $dir"
5259         nums=$($cmd | wc -l)
5260         [ $nums -eq $expected ] ||
5261                 error "'$cmd' wrong: found $nums, expected $expected"
5262
5263         cmd="$LFS find ! -stripe-index 0 -type f $dir"
5264         nums=$($cmd | wc -l)
5265         [ $nums -eq $expected ] ||
5266                 error "'$cmd' wrong: found $nums, expected $expected"
5267
5268         expected=0
5269         # This should produce an error and not return any files
5270         cmd="$LFS find -stripe-index $OSTCOUNT -type f $dir"
5271         nums=$($cmd 2>/dev/null | wc -l)
5272         [ $nums -eq $expected ] ||
5273                 error "'$cmd' wrong: found $nums, expected $expected"
5274
5275         if [[ $OSTCOUNT -gt 1 ]]; then
5276                 expected=$(((NUMDIRS + 1) * NUMFILES + onestripe))
5277                 cmd="$LFS find -stripe-index 0,1 -type f $dir"
5278                 nums=$($cmd | wc -l)
5279                 [ $nums -eq $expected ] ||
5280                         error "'$cmd' wrong: found $nums, expected $expected"
5281         fi
5282 }
5283 run_test 56u "check lfs find -stripe-index works"
5284
5285 test_56v() {
5286         local mdt_idx=0
5287         local dir=$DIR/$tdir
5288
5289         setup_56 $dir $NUMFILES $NUMDIRS
5290
5291         UUID=$(mdtuuid_from_index $mdt_idx $dir)
5292         [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT $mdt_idx"
5293
5294         for file in $($LFS find -m $UUID $dir); do
5295                 file_midx=$($LFS getstripe -m $file)
5296                 [ $file_midx -eq $mdt_idx ] ||
5297                         error "lfs find -m $UUID != getstripe -m $file_midx"
5298         done
5299 }
5300 run_test 56v "check 'lfs find -m match with lfs getstripe -m'"
5301
5302 test_56w() {
5303         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
5304         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5305
5306         local dir=$DIR/$tdir
5307
5308         setup_56 $dir $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
5309
5310         local stripe_size=$($LFS getstripe -S -d $dir) ||
5311                 error "$LFS getstripe -S -d $dir failed"
5312         stripe_size=${stripe_size%% *}
5313
5314         local file_size=$((stripe_size * OSTCOUNT))
5315         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
5316         local required_space=$((file_num * file_size))
5317         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
5318                            head -n1)
5319         [[ $free_space -le $((required_space / 1024)) ]] &&
5320                 skip_env "need $required_space, have $free_space kbytes"
5321
5322         local dd_bs=65536
5323         local dd_count=$((file_size / dd_bs))
5324
5325         # write data into the files
5326         local i
5327         local j
5328         local file
5329
5330         for i in $(seq $NUMFILES); do
5331                 file=$dir/file$i
5332                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5333                         error "write data into $file failed"
5334         done
5335         for i in $(seq $NUMDIRS); do
5336                 for j in $(seq $NUMFILES); do
5337                         file=$dir/dir$i/file$j
5338                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5339                                 error "write data into $file failed"
5340                 done
5341         done
5342
5343         # $LFS_MIGRATE will fail if hard link migration is unsupported
5344         if [[ $(lustre_version_code mds1) -gt $(version_code 2.5.55) ]]; then
5345                 createmany -l$dir/dir1/file1 $dir/dir1/link 200 ||
5346                         error "creating links to $dir/dir1/file1 failed"
5347         fi
5348
5349         local expected=-1
5350
5351         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
5352
5353         # lfs_migrate file
5354         local cmd="$LFS_MIGRATE -y -c $expected $dir/file1"
5355
5356         echo "$cmd"
5357         eval $cmd || error "$cmd failed"
5358
5359         check_stripe_count $dir/file1 $expected
5360
5361         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
5362         then
5363                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
5364                 # OST 1 if it is on OST 0. This file is small enough to
5365                 # be on only one stripe.
5366                 file=$dir/migr_1_ost
5367                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
5368                         error "write data into $file failed"
5369                 local obdidx=$($LFS getstripe -i $file)
5370                 local oldmd5=$(md5sum $file)
5371                 local newobdidx=0
5372
5373                 [[ $obdidx -eq 0 ]] && newobdidx=1
5374                 cmd="$LFS migrate -i $newobdidx $file"
5375                 echo $cmd
5376                 eval $cmd || error "$cmd failed"
5377
5378                 local realobdix=$($LFS getstripe -i $file)
5379                 local newmd5=$(md5sum $file)
5380
5381                 [[ $newobdidx -ne $realobdix ]] &&
5382                         error "new OST is different (was=$obdidx, "\
5383                               "wanted=$newobdidx, got=$realobdix)"
5384                 [[ "$oldmd5" != "$newmd5" ]] &&
5385                         error "md5sum differ: $oldmd5, $newmd5"
5386         fi
5387
5388         # lfs_migrate dir
5389         cmd="$LFS_MIGRATE -y -c $expected $dir/dir1"
5390         echo "$cmd"
5391         eval $cmd || error "$cmd failed"
5392
5393         for j in $(seq $NUMFILES); do
5394                 check_stripe_count $dir/dir1/file$j $expected
5395         done
5396
5397         # lfs_migrate works with lfs find
5398         cmd="$LFS find -stripe_count $OSTCOUNT -type f $dir |
5399              $LFS_MIGRATE -y -c $expected"
5400         echo "$cmd"
5401         eval $cmd || error "$cmd failed"
5402
5403         for i in $(seq 2 $NUMFILES); do
5404                 check_stripe_count $dir/file$i $expected
5405         done
5406         for i in $(seq 2 $NUMDIRS); do
5407                 for j in $(seq $NUMFILES); do
5408                 check_stripe_count $dir/dir$i/file$j $expected
5409                 done
5410         done
5411 }
5412 run_test 56w "check lfs_migrate -c stripe_count works"
5413
5414 test_56wb() {
5415         local file1=$DIR/$tdir/file1
5416         local create_pool=false
5417         local initial_pool=$($LFS getstripe -p $DIR)
5418         local pool_list=()
5419         local pool=""
5420
5421         echo -n "Creating test dir..."
5422         test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
5423         echo "done."
5424
5425         echo -n "Creating test file..."
5426         touch $file1 || error "cannot create file"
5427         echo "done."
5428
5429         echo -n "Detecting existing pools..."
5430         pool_list=($($LFS pool_list $FSNAME | grep "$FSNAME\." | cut -d. -f2))
5431
5432         if [ ${#pool_list[@]} -gt 0 ]; then
5433                 echo "${pool_list[@]}"
5434                 for thispool in "${pool_list[@]}"; do
5435                         if [[ -z "$initial_pool" ||
5436                               "$initial_pool" != "$thispool" ]]; then
5437                                 pool="$thispool"
5438                                 echo "Using existing pool '$pool'"
5439                                 break
5440                         fi
5441                 done
5442         else
5443                 echo "none detected."
5444         fi
5445         if [ -z "$pool" ]; then
5446                 pool=${POOL:-testpool}
5447                 [ "$initial_pool" = "$pool" ] && pool="testpool2"
5448                 echo -n "Creating pool '$pool'..."
5449                 create_pool=true
5450                 pool_add $pool &> /dev/null ||
5451                         error "pool_add failed"
5452                 echo "done."
5453
5454                 echo -n "Adding target to pool..."
5455                 pool_add_targets $pool 0 0 1 &> /dev/null ||
5456                         error "pool_add_targets failed"
5457                 echo "done."
5458         fi
5459
5460         echo -n "Setting pool using -p option..."
5461         $LFS_MIGRATE -y -q --no-rsync -p $pool $file1 &> /dev/null ||
5462                 error "migrate failed rc = $?"
5463         echo "done."
5464
5465         echo -n "Verifying test file is in pool after migrating..."
5466         [ "$($LFS getstripe -p $file1)" = $pool ] ||
5467                 error "file was not migrated to pool $pool"
5468         echo "done."
5469
5470         echo -n "Removing test file from pool '$pool'..."
5471         $LFS migrate $file1 &> /dev/null ||
5472                 error "cannot remove from pool"
5473         [ "$($LFS getstripe -p $file1)" ] &&
5474                 error "pool still set"
5475         echo "done."
5476
5477         echo -n "Setting pool using --pool option..."
5478         $LFS_MIGRATE -y -q --no-rsync --pool $pool $file1 &> /dev/null ||
5479                 error "migrate failed rc = $?"
5480         echo "done."
5481
5482         # Clean up
5483         rm -f $file1
5484         if $create_pool; then
5485                 destroy_test_pools 2> /dev/null ||
5486                         error "destroy test pools failed"
5487         fi
5488 }
5489 run_test 56wb "check lfs_migrate pool support"
5490
5491 test_56wc() {
5492         local file1="$DIR/$tdir/file 1"
5493
5494         echo -n "Creating test dir..."
5495         test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
5496         local def_stripe_size=$($LFS getstripe -S $DIR/$tdir 2>/dev/null)
5497         $LFS setstripe -S 1M -c 1 "$DIR/$tdir" &> /dev/null ||
5498                 error "cannot set stripe"
5499         echo "done"
5500
5501         echo -n "Setting initial stripe for test file..."
5502         $LFS setstripe -S 512K -c 1 "$file1" &> /dev/null ||
5503                 error "cannot set stripe"
5504         [ $($LFS getstripe -S "$file1") -eq 524288 ] ||
5505                 error "stripe size not set"
5506         echo "done."
5507
5508         # File currently set to -S 512K -c 1
5509
5510         # Ensure -c and -S options are rejected when -R is set
5511         echo -n "Verifying incompatible options are detected..."
5512         $LFS_MIGRATE -y -R -c 1 "$file1" &> /dev/null &&
5513                 error "incompatible -c and -R options not detected"
5514         $LFS_MIGRATE -y -R -S 1M "$file1" &> /dev/null &&
5515                 error "incompatible -S and -R options not detected"
5516         echo "done."
5517
5518         # Ensure unrecognized options are passed through to 'lfs migrate'
5519         echo -n "Verifying -S option is passed through to lfs migrate..."
5520         $LFS_MIGRATE -y -S 1M "$file1" &> /dev/null ||
5521                 error "migration failed"
5522         [ $($LFS getstripe -S "$file1") -eq 1048576 ] ||
5523                 error "file was not restriped"
5524         echo "done."
5525
5526         # File currently set to -S 1M -c 1
5527
5528         # Ensure long options are supported
5529         echo -n "Verifying long options supported..."
5530         $LFS_MIGRATE -y --non-block "$file1" &> /dev/null ||
5531                 error "long option without argument not supported"
5532         $LFS_MIGRATE -y --stripe-size 512K "$file1" &> /dev/null ||
5533                 error "long option with argument not supported"
5534         [ $($LFS getstripe -S "$file1") -eq 524288 ] ||
5535                 error "file not restriped with --stripe-size option"
5536         echo "done."
5537
5538         # File currently set to -S 512K -c 1
5539
5540         if [ "$OSTCOUNT" -gt 1 ]; then
5541                 echo -n "Verifying explicit stripe count can be set..."
5542                 $LFS_MIGRATE -y -c 2 "$file1" &> /dev/null ||
5543                         error "migrate failed"
5544                 [ $($LFS getstripe -c "$file1") -eq 2 ] ||
5545                         error "file not restriped to explicit count"
5546                 echo "done."
5547         fi
5548
5549         # File currently set to -S 512K -c 1 or -S 512K -c 2
5550
5551         # Ensure parent striping is used if -R is set, and no stripe
5552         # count or size is specified
5553         echo -n "Setting stripe for parent directory..."
5554         $LFS setstripe -S 1M -c 1 "$DIR/$tdir" &> /dev/null ||
5555                 error "cannot set stripe"
5556         echo "done."
5557
5558         echo -n "Verifying restripe option uses parent stripe settings..."
5559         $LFS_MIGRATE -y -R "$file1" &> /dev/null ||
5560                 error "migrate failed"
5561         [ $($LFS getstripe -S "$file1") -eq $def_stripe_size ] ||
5562                 error "file not restriped to parent settings"
5563         [ $($LFS getstripe -c "$file1") -eq 1 ] ||
5564                 error "file not restriped to parent settings"
5565         echo "done."
5566
5567         # File currently set to -S 1M -c 1
5568
5569         # Ensure striping is preserved if -R is not set, and no stripe
5570         # count or size is specified
5571         echo -n "Verifying striping size preserved when not specified..."
5572         local orig_stripe_size=$($LFS getstripe -S "$file1" 2>/dev/null)
5573         $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
5574                 error "cannot set stripe on parent directory"
5575         $LFS_MIGRATE -y "$file1" &> /dev/null ||
5576                 error "migrate failed"
5577         [ $($LFS getstripe -S "$file1") -eq $orig_stripe_size ] ||
5578                 error "file was restriped"
5579         echo "done."
5580
5581         # Ensure file name properly detected when final option has no argument
5582         echo -n "Verifying file name properly detected..."
5583         $LFS_MIGRATE -y "$file1" &> /dev/null ||
5584                 error "file name interpreted as option argument"
5585         echo "done."
5586
5587         # Clean up
5588         rm -f "$file1"
5589 }
5590 run_test 56wc "check unrecognized options for lfs_migrate are passed through"
5591
5592 test_56wd() {
5593         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
5594
5595         local file1=$DIR/$tdir/file1
5596
5597         echo -n "Creating test dir..."
5598         test_mkdir $DIR/$tdir || error "cannot create dir"
5599         echo "done."
5600
5601         echo -n "Creating test file..."
5602         touch $file1
5603         echo "done."
5604
5605         # Ensure 'lfs migrate' will fail by using a non-existent option,
5606         # and make sure rsync is not called to recover
5607         echo -n "Make sure --no-rsync option works..."
5608         $LFS_MIGRATE -y --no-rsync --invalid-opt $file1 2>&1 |
5609                 grep -q 'refusing to fall back to rsync' ||
5610                 error "rsync was called with --no-rsync set"
5611         echo "done."
5612
5613         # Ensure rsync is called without trying 'lfs migrate' first
5614         echo -n "Make sure --rsync option works..."
5615         $LFS_MIGRATE -y --rsync --invalid-opt $file1 2>&1 |
5616                 grep -q 'falling back to rsync' &&
5617                 error "lfs migrate was called with --rsync set"
5618         echo "done."
5619
5620         echo -n "Make sure --rsync and --no-rsync options are exclusive..."
5621         $LFS_MIGRATE -y --rsync --no-rsync $file1 2>&1 |
5622                 grep -q 'at the same time' ||
5623                 error "--rsync and --no-rsync accepted concurrently"
5624         echo "done."
5625
5626         # Clean up
5627         rm -f $file1
5628 }
5629 run_test 56wd "check lfs_migrate --rsync and --no-rsync work"
5630
5631 test_56x() {
5632         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
5633         check_swap_layouts_support
5634
5635         local dir=$DIR/$tdir
5636         local ref1=/etc/passwd
5637         local file1=$dir/file1
5638
5639         test_mkdir $dir || error "creating dir $dir"
5640         $LFS setstripe -c 2 $file1
5641         cp $ref1 $file1
5642         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
5643         stripe=$($LFS getstripe -c $file1)
5644         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5645         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5646
5647         # clean up
5648         rm -f $file1
5649 }
5650 run_test 56x "lfs migration support"
5651
5652 test_56xa() {
5653         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
5654         check_swap_layouts_support
5655
5656         local dir=$DIR/$tdir/$testnum
5657
5658         test_mkdir -p $dir
5659
5660         local ref1=/etc/passwd
5661         local file1=$dir/file1
5662
5663         $LFS setstripe -c 2 $file1
5664         cp $ref1 $file1
5665         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
5666
5667         local stripe=$($LFS getstripe -c $file1)
5668
5669         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5670         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5671
5672         # clean up
5673         rm -f $file1
5674 }
5675 run_test 56xa "lfs migration --block support"
5676
5677 check_migrate_links() {
5678         local dir="$1"
5679         local file1="$dir/file1"
5680         local begin="$2"
5681         local count="$3"
5682         local total_count=$(($begin + $count - 1))
5683         local symlink_count=10
5684         local uniq_count=10
5685
5686         if [ ! -f "$file1" ]; then
5687                 echo -n "creating initial file..."
5688                 $LFS setstripe -c 1 -S "512k" "$file1" ||
5689                         error "cannot setstripe initial file"
5690                 echo "done"
5691
5692                 echo -n "creating symlinks..."
5693                 for s in $(seq 1 $symlink_count); do
5694                         ln -s "$file1" "$dir/slink$s" ||
5695                                 error "cannot create symlinks"
5696                 done
5697                 echo "done"
5698
5699                 echo -n "creating nonlinked files..."
5700                 createmany -o "$dir/uniq" 1 10 &> /dev/null ||
5701                         error "cannot create nonlinked files"
5702                 echo "done"
5703         fi
5704
5705         # create hard links
5706         if [ ! -f "$dir/file$total_count" ]; then
5707                 echo -n "creating hard links $begin:$total_count..."
5708                 createmany -l"$file1" "$dir/file" "$begin" "$count" &>  \
5709                         /dev/null || error "cannot create hard links"
5710                 echo "done"
5711         fi
5712
5713         echo -n "checking number of hard links listed in xattrs..."
5714         local fid=$($LFS getstripe -F "$file1")
5715         local paths=($($LFS fid2path "$MOUNT" "$fid" 2> /dev/null))
5716
5717         echo "${#paths[*]}"
5718         if [ ${#paths[*]} -lt $total_count -a "$begin" -eq 2  ]; then
5719                         skip "hard link list has unexpected size, skipping test"
5720         fi
5721         if [ ${#paths[*]} -ge $total_count -a "$begin" -ne 2  ]; then
5722                         error "link names should exceed xattrs size"
5723         fi
5724
5725         echo -n "migrating files..."
5726         local migrate_out=$($LFS_MIGRATE -y -S '1m' $dir)
5727         local rc=$?
5728         [ $rc -eq 0 ] || error "migrate failed rc = $rc"
5729         echo "done"
5730
5731         # make sure all links have been properly migrated
5732         echo -n "verifying files..."
5733         fid=$($LFS getstripe -F "$file1") ||
5734                 error "cannot get fid for file $file1"
5735         for i in $(seq 2 $total_count); do
5736                 local fid2=$($LFS getstripe -F $dir/file$i)
5737
5738                 [ "$fid2" == "$fid" ] ||
5739                         error "migrated hard link has mismatched FID"
5740         done
5741
5742         # make sure hard links were properly detected, and migration was
5743         # performed only once for the entire link set; nonlinked files should
5744         # also be migrated
5745         local actual=$(grep -c 'done migrate' <<< "$migrate_out")
5746         local expected=$(($uniq_count + 1))
5747
5748         [ "$actual" -eq  "$expected" ] ||
5749                 error "hard links individually migrated ($actual != $expected)"
5750
5751         # make sure the correct number of hard links are present
5752         local hardlinks=$(stat -c '%h' "$file1")
5753
5754         [ $hardlinks -eq $total_count ] ||
5755                 error "num hard links $hardlinks != $total_count"
5756         echo "done"
5757
5758         return 0
5759 }
5760
5761 test_56xb() {
5762         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
5763                 skip "Need MDS version at least 2.10.55"
5764
5765         local dir="$DIR/$tdir"
5766
5767         test_mkdir "$dir" || error "cannot create dir $dir"
5768
5769         echo "testing lfs migrate mode when all links fit within xattrs"
5770         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir" 2 99
5771
5772         echo "testing rsync mode when all links fit within xattrs"
5773         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir" 2 99
5774
5775         echo "testing lfs migrate mode when all links do not fit within xattrs"
5776         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir" 101 100
5777
5778         echo "testing rsync mode when all links do not fit within xattrs"
5779         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir" 101 100
5780
5781         # clean up
5782         rm -rf $dir
5783 }
5784 run_test 56xb "lfs migration hard link support"
5785
5786 test_56y() {
5787         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
5788                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53"
5789
5790         local res=""
5791         local dir=$DIR/$tdir
5792         local f1=$dir/file1
5793         local f2=$dir/file2
5794
5795         test_mkdir -p $dir || error "creating dir $dir"
5796         touch $f1 || error "creating std file $f1"
5797         $MULTIOP $f2 H2c || error "creating released file $f2"
5798
5799         # a directory can be raid0, so ask only for files
5800         res=$($LFS find $dir -L raid0 -type f | wc -l)
5801         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5802
5803         res=$($LFS find $dir \! -L raid0 -type f | wc -l)
5804         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5805
5806         # only files can be released, so no need to force file search
5807         res=$($LFS find $dir -L released)
5808         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5809
5810         res=$($LFS find $dir -type f \! -L released)
5811         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5812 }
5813 run_test 56y "lfs find -L raid0|released"
5814
5815 test_56z() { # LU-4824
5816         # This checks to make sure 'lfs find' continues after errors
5817         # There are two classes of errors that should be caught:
5818         # - If multiple paths are provided, all should be searched even if one
5819         #   errors out
5820         # - If errors are encountered during the search, it should not terminate
5821         #   early
5822         local dir=$DIR/$tdir
5823         local i
5824
5825         test_mkdir $dir
5826         for i in d{0..9}; do
5827                 test_mkdir $dir/$i
5828         done
5829         touch $dir/d{0..9}/$tfile
5830         $LFS find $DIR/non_existent_dir $dir &&
5831                 error "$LFS find did not return an error"
5832         # Make a directory unsearchable. This should NOT be the last entry in
5833         # directory order.  Arbitrarily pick the 6th entry
5834         chmod 700 $($LFS find $dir -type d | sed '6!d')
5835
5836         local count=$($RUNAS $LFS find $DIR/non_existent $dir | wc -l)
5837
5838         # The user should be able to see 10 directories and 9 files
5839         [ $count == 19 ] || error "$LFS find did not continue after error"
5840 }
5841 run_test 56z "lfs find should continue after an error"
5842
5843 test_56aa() { # LU-5937
5844         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
5845
5846         local dir=$DIR/$tdir
5847
5848         mkdir $dir
5849         $LFS setdirstripe -c$MDSCOUNT $dir/striped_dir
5850
5851         createmany -o $dir/striped_dir/${tfile}- 1024
5852         local dirs=$($LFS find --size +8k $dir/)
5853
5854         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5855 }
5856 run_test 56aa "lfs find --size under striped dir"
5857
5858 test_56ab() { # LU-10705
5859         test_mkdir $DIR/$tdir
5860         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=8k count=1 seek=2k
5861         dd if=/dev/zero of=$DIR/$tdir/$tfile.2 bs=4k count=1 seek=4k
5862         dd if=/dev/zero of=$DIR/$tdir/$tfile.3 bs=1M count=2 seek=16
5863         # Flush writes to ensure valid blocks.  Need to be more thorough for
5864         # ZFS, since blocks are not allocated/returned to client immediately.
5865         sync_all_data
5866         wait_zfs_commit ost1 2
5867         cancel_lru_locks osc
5868         ls -ls $DIR/$tdir
5869
5870         local files=$($LFS find --size +16M $DIR/$tdir | wc -l)
5871
5872         [[ $files == 3 ]] || error ">16M size files $files isn't 3 as expected"
5873
5874         files=$($LFS find --blocks +1M $DIR/$tdir | wc -l)
5875         [[ $files == 1 ]] || error ">1M blocks files $files isn't 1 as expected"
5876
5877         rm -f $DIR/$tdir/$tfile.[123]
5878 }
5879 run_test 56ab "lfs find --blocks"
5880
5881 test_56ba() {
5882         # Create composite files with one component
5883         local dir=$DIR/$tdir
5884
5885         setup_56 $dir/1Mfiles 5 1 "-S 1M --component-end 1M"
5886         # Create composite files with three components
5887         setup_56 $dir/2Mfiles 5 2 "-E 2M -S 1M -E 4M -E 6M"
5888         # Create non-composite files
5889         createmany -o $dir/${tfile}- 10
5890
5891         local nfiles=$($LFS find --component-end 1M --type f $dir | wc -l)
5892
5893         [[ $nfiles == 10 ]] ||
5894                 error "lfs find -E 1M found $nfiles != 10 files"
5895
5896         nfiles=$($LFS find ! -E 1M --type f $dir | wc -l)
5897         [[ $nfiles == 25 ]] ||
5898                 error "lfs find ! -E 1M found $nfiles != 25 files"
5899
5900         # All files have a component that starts at 0
5901         nfiles=$($LFS find --component-start 0 --type f $dir | wc -l)
5902         [[ $nfiles == 35 ]] ||
5903                 error "lfs find --component-start 0 - $nfiles != 35 files"
5904
5905         nfiles=$($LFS find --component-start 2M --type f $dir | wc -l)
5906         [[ $nfiles == 15 ]] ||
5907                 error "lfs find --component-start 2M - $nfiles != 15 files"
5908
5909         # All files created here have a componenet that does not starts at 2M
5910         nfiles=$($LFS find ! --component-start 2M --type f $dir | wc -l)
5911         [[ $nfiles == 35 ]] ||
5912                 error "lfs find ! --component-start 2M - $nfiles != 35 files"
5913
5914         # Find files with a specified number of components
5915         local nfiles=$($LFS find --component-count 3 --type f $dir | wc -l)
5916         [[ $nfiles == 15 ]] ||
5917                 error "lfs find --component-count 3 - $nfiles != 15 files"
5918
5919         # Remember non-composite files have a component count of zero
5920         local nfiles=$($LFS find --component-count 0 --type f $dir | wc -l)
5921         [[ $nfiles == 10 ]] ||
5922                 error "lfs find --component-count 0 - $nfiles != 10 files"
5923
5924         nfiles=$($LFS find ! --component-count 3 --type f $dir | wc -l)
5925         [[ $nfiles == 20 ]] ||
5926                 error "lfs find ! --component-count 3 - $nfiles != 20 files"
5927
5928         # All files have a flag called "init"
5929         local nfiles=$($LFS find --component-flags init --type f $dir | wc -l)
5930         [[ $nfiles == 35 ]] ||
5931                 error "lfs find --component-flags init - $nfiles != 35 files"
5932
5933         # Multi-component files will have a component not initialized
5934         local nfiles=$($LFS find ! --component-flags init --type f $dir | wc -l)
5935         [[ $nfiles == 15 ]] ||
5936                 error "lfs find !--component-flags init - $nfiles != 15 files"
5937
5938         rm -rf $dir
5939
5940 }
5941 run_test 56ba "test lfs find --component-end, -start, -count, and -flags"
5942
5943 test_56ca() {
5944         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
5945                 skip "Need MDS version at least 2.10.57"
5946
5947         local td=$DIR/$tdir
5948         local tf=$td/$tfile
5949         local dir
5950         local nfiles
5951         local cmd
5952         local i
5953         local j
5954
5955         # create mirrored directories and mirrored files
5956         mkdir $td || error "mkdir $td failed"
5957         $LFS mirror create -N3 $td || error "create mirrored dir $td failed"
5958         createmany -o $tf- 10 || error "create $tf- failed"
5959
5960         for i in $(seq 2); do
5961                 dir=$td/dir$i
5962                 mkdir $dir || error "mkdir $dir failed"
5963                 $LFS mirror create -N$((3 + i)) $dir ||
5964                         error "create mirrored dir $dir failed"
5965                 createmany -o $dir/$tfile- 10 ||
5966                         error "create $dir/$tfile- failed"
5967         done
5968
5969         # change the states of some mirrored files
5970         echo foo > $tf-6
5971         for i in $(seq 2); do
5972                 dir=$td/dir$i
5973                 for j in $(seq 4 9); do
5974                         echo foo > $dir/$tfile-$j
5975                 done
5976         done
5977
5978         # find mirrored files with specific mirror count
5979         cmd="$LFS find --mirror-count 3 --type f $td"
5980         nfiles=$($cmd | wc -l)
5981         [[ $nfiles = 10 ]] || error "$cmd: $nfiles != 10 files"
5982
5983         cmd="$LFS find ! --mirror-count 3 --type f $td"
5984         nfiles=$($cmd | wc -l)
5985         [[ $nfiles = 20 ]] || error "$cmd: $nfiles != 20 files"
5986
5987         cmd="$LFS find --mirror-count +2 --type f $td"
5988         nfiles=$($cmd | wc -l)
5989         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
5990
5991         cmd="$LFS find --mirror-count -6 --type f $td"
5992         nfiles=$($cmd | wc -l)
5993         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
5994
5995         # find mirrored files with specific file state
5996         cmd="$LFS find --maxdepth 1 --mirror-state=^ro --type f $td"
5997         [[ $($cmd) = $tf-6 ]] || error "$cmd: didn't return $tf-6"
5998
5999         cmd="$LFS find --mirror-state=ro --type f $td"
6000         nfiles=$($cmd | wc -l)
6001         [[ $nfiles = 17 ]] || error "$cmd: $nfiles != 17 files"
6002
6003         cmd="$LFS find ! --mirror-state=ro --type f $td"
6004         nfiles=$($cmd | wc -l)
6005         [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
6006
6007         cmd="$LFS find --mirror-state=wp --type f $td"
6008         nfiles=$($cmd | wc -l)
6009         [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
6010
6011         cmd="$LFS find ! --mirror-state=sp --type f $td"
6012         nfiles=$($cmd | wc -l)
6013         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
6014 }
6015 run_test 56ca "check lfs find --mirror-count|-N and --mirror-state"
6016
6017 test_57a() {
6018         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6019         # note test will not do anything if MDS is not local
6020         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
6021                 skip_env "ldiskfs only test"
6022         fi
6023         remote_mds_nodsh && skip "remote MDS with nodsh"
6024
6025         local MNTDEV="osd*.*MDT*.mntdev"
6026         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
6027         [ -z "$DEV" ] && error "can't access $MNTDEV"
6028         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
6029                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
6030                         error "can't access $DEV"
6031                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
6032                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
6033                 rm $TMP/t57a.dump
6034         done
6035 }
6036 run_test 57a "verify MDS filesystem created with large inodes =="
6037
6038 test_57b() {
6039         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6040         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
6041                 skip_env "ldiskfs only test"
6042         fi
6043         remote_mds_nodsh && skip "remote MDS with nodsh"
6044
6045         local dir=$DIR/$tdir
6046         local filecount=100
6047         local file1=$dir/f1
6048         local fileN=$dir/f$filecount
6049
6050         rm -rf $dir || error "removing $dir"
6051         test_mkdir -c1 $dir
6052         local mdtidx=$($LFS getstripe -m $dir)
6053         local mdtname=MDT$(printf %04x $mdtidx)
6054         local facet=mds$((mdtidx + 1))
6055
6056         echo "mcreating $filecount files"
6057         createmany -m $dir/f 1 $filecount || error "creating files in $dir"
6058
6059         # verify that files do not have EAs yet
6060         $LFS getstripe $file1 2>&1 | grep -q "no stripe" ||
6061                 error "$file1 has an EA"
6062         $LFS getstripe $fileN 2>&1 | grep -q "no stripe" ||
6063                 error "$fileN has an EA"
6064
6065         sync
6066         sleep 1
6067         df $dir  #make sure we get new statfs data
6068         local mdsfree=$(do_facet $facet \
6069                         lctl get_param -n osd*.*$mdtname.kbytesfree)
6070         local mdcfree=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
6071         local file
6072
6073         echo "opening files to create objects/EAs"
6074         for file in $(seq -f $dir/f%g 1 $filecount); do
6075                 $OPENFILE -f O_RDWR $file > /dev/null 2>&1 ||
6076                         error "opening $file"
6077         done
6078
6079         # verify that files have EAs now
6080         $LFS getstripe $file1 | grep -q "obdidx" || error "$file1 missing EA"
6081         $LFS getstripe $fileN | grep -q "obdidx" || error "$fileN missing EA"
6082
6083         sleep 1  #make sure we get new statfs data
6084         df $dir
6085         local mdsfree2=$(do_facet $facet \
6086                          lctl get_param -n osd*.*$mdtname.kbytesfree)
6087         local mdcfree2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
6088
6089         if [[ $mdcfree2 -lt $((mdcfree - 16)) ]]; then
6090                 if [ "$mdsfree" != "$mdsfree2" ]; then
6091                         error "MDC before $mdcfree != after $mdcfree2"
6092                 else
6093                         echo "MDC before $mdcfree != after $mdcfree2"
6094                         echo "unable to confirm if MDS has large inodes"
6095                 fi
6096         fi
6097         rm -rf $dir
6098 }
6099 run_test 57b "default LOV EAs are stored inside large inodes ==="
6100
6101 test_58() {
6102         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6103         [ -z "$(which wiretest 2>/dev/null)" ] &&
6104                         skip_env "could not find wiretest"
6105
6106         wiretest
6107 }
6108 run_test 58 "verify cross-platform wire constants =============="
6109
6110 test_59() {
6111         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6112
6113         echo "touch 130 files"
6114         createmany -o $DIR/f59- 130
6115         echo "rm 130 files"
6116         unlinkmany $DIR/f59- 130
6117         sync
6118         # wait for commitment of removal
6119         wait_delete_completed
6120 }
6121 run_test 59 "verify cancellation of llog records async ========="
6122
6123 TEST60_HEAD="test_60 run $RANDOM"
6124 test_60a() {
6125         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6126         remote_mgs_nodsh && skip "remote MGS with nodsh"
6127         do_facet mgs "! which run-llog.sh &> /dev/null" &&
6128                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
6129                         skip_env "missing subtest run-llog.sh"
6130
6131         log "$TEST60_HEAD - from kernel mode"
6132         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
6133         do_facet mgs "bash run-llog.sh" || error "run-llog.sh failed"
6134         do_facet mgs $LCTL dk > $TMP/$tfile
6135
6136         # LU-6388: test llog_reader
6137         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
6138         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
6139         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
6140                         skip_env "missing llog_reader"
6141         local fstype=$(facet_fstype mgs)
6142         [ $fstype != ldiskfs -a $fstype != zfs ] &&
6143                 skip_env "Only for ldiskfs or zfs type mgs"
6144
6145         local mntpt=$(facet_mntpt mgs)
6146         local mgsdev=$(mgsdevname 1)
6147         local fid_list
6148         local fid
6149         local rec_list
6150         local rec
6151         local rec_type
6152         local obj_file
6153         local path
6154         local seq
6155         local oid
6156         local pass=true
6157
6158         #get fid and record list
6159         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
6160                 tail -n 4))
6161         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
6162                 tail -n 4))
6163         #remount mgs as ldiskfs or zfs type
6164         stop mgs || error "stop mgs failed"
6165         mount_fstype mgs || error "remount mgs failed"
6166         for ((i = 0; i < ${#fid_list[@]}; i++)); do
6167                 fid=${fid_list[i]}
6168                 rec=${rec_list[i]}
6169                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
6170                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
6171                 oid=$((16#$oid))
6172
6173                 case $fstype in
6174                         ldiskfs )
6175                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
6176                         zfs )
6177                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
6178                 esac
6179                 echo "obj_file is $obj_file"
6180                 do_facet mgs $llog_reader $obj_file
6181
6182                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
6183                         awk '{ print $3 }' | sed -e "s/^type=//g")
6184                 if [ $rec_type != $rec ]; then
6185                         echo "FAILED test_60a wrong record type $rec_type," \
6186                               "should be $rec"
6187                         pass=false
6188                         break
6189                 fi
6190
6191                 #check obj path if record type is LLOG_LOGID_MAGIC
6192                 if [ "$rec" == "1064553b" ]; then
6193                         path=$(do_facet mgs $llog_reader $obj_file |
6194                                 grep "path=" | awk '{ print $NF }' |
6195                                 sed -e "s/^path=//g")
6196                         if [ $obj_file != $mntpt/$path ]; then
6197                                 echo "FAILED test_60a wrong obj path" \
6198                                       "$montpt/$path, should be $obj_file"
6199                                 pass=false
6200                                 break
6201                         fi
6202                 fi
6203         done
6204         rm -f $TMP/$tfile
6205         #restart mgs before "error", otherwise it will block the next test
6206         stop mgs || error "stop mgs failed"
6207         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
6208         $pass || error "test failed, see FAILED test_60a messages for specifics"
6209 }
6210 run_test 60a "llog_test run from kernel module and test llog_reader"
6211
6212 test_60aa() {
6213         remote_mgs_nodsh && skip "remote MGS with nodsh"
6214
6215         # test old logid format
6216         if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
6217                 do_facet mgs $LCTL dl | grep MGS
6218                 do_facet mgs "$LCTL --device %MGS llog_print \\\\\\\$$FSNAME-client" ||
6219                         error "old llog_print failed"
6220         fi
6221
6222         # test new logid format
6223         if [ $(lustre_version_code mgs) -ge $(version_code 2.9.53) ]; then
6224                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
6225                         error "new llog_print failed"
6226         fi
6227 }
6228 run_test 60aa "llog_print works with FIDs and simple names"
6229
6230 test_60ab() {
6231         # test llog_print with params
6232
6233         [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.11.51) ]] ||
6234                 skip "Need server version greater than 2.11.51"
6235
6236         local yaml
6237         local orig_val
6238
6239         orig_val=$(do_facet mgs $LCTL get_param jobid_name)
6240         do_facet mgs $LCTL set_param -P jobid_name="testname"
6241
6242         yaml=$(do_facet mgs $LCTL --device MGS llog_print params |
6243             grep jobid_name | tail -n 1)
6244
6245         local param=`awk '{ print $10 }' <<< "$yaml"`
6246         local val=`awk '{ print $12 }' <<< "$yaml"`
6247         #return to the default
6248         do_facet mgs $LCTL set_param -P jobid_name=$orig_val
6249         [ $val = "testname" ] || error "bad value: $val"
6250         [ $param = "jobid_name," ] || error "Bad param: $param"
6251 }
6252 run_test 60ab "llog_print params output values from set_param -P"
6253
6254 test_60b() { # bug 6411
6255         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6256
6257         dmesg > $DIR/$tfile
6258         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
6259                                 /llog.test/ {
6260                                         if (marker)
6261                                                 from_marker++
6262                                         from_begin++
6263                                 }
6264                                 END {
6265                                         if (marker)
6266                                                 print from_marker
6267                                         else
6268                                                 print from_begin
6269                                 }")
6270         [[ $LLOG_COUNT -gt 100 ]] &&
6271                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
6272 }
6273 run_test 60b "limit repeated messages from CERROR/CWARN ========"
6274
6275 test_60c() {
6276         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6277
6278         echo "create 5000 files"
6279         createmany -o $DIR/f60c- 5000
6280 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
6281         lctl set_param fail_loc=0x80000137
6282         unlinkmany $DIR/f60c- 5000
6283         lctl set_param fail_loc=0
6284 }
6285 run_test 60c "unlink file when mds full"
6286
6287 test_60d() {
6288         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6289
6290         SAVEPRINTK=$(lctl get_param -n printk)
6291         # verify "lctl mark" is even working"
6292         MESSAGE="test message ID $RANDOM $$"
6293         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
6294         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
6295
6296         lctl set_param printk=0 || error "set lnet.printk failed"
6297         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
6298         MESSAGE="new test message ID $RANDOM $$"
6299         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
6300         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
6301         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
6302
6303         lctl set_param -n printk="$SAVEPRINTK"
6304 }
6305 run_test 60d "test printk console message masking"
6306
6307 test_60e() {
6308         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6309         remote_mds_nodsh && skip "remote MDS with nodsh"
6310
6311         touch $DIR/$tfile
6312 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
6313         do_facet mds1 lctl set_param fail_loc=0x15b
6314         rm $DIR/$tfile
6315 }
6316 run_test 60e "no space while new llog is being created"
6317
6318 test_61() {
6319         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6320
6321         f="$DIR/f61"
6322         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
6323         cancel_lru_locks osc
6324         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
6325         sync
6326 }
6327 run_test 61 "mmap() writes don't make sync hang ================"
6328
6329 # bug 2330 - insufficient obd_match error checking causes LBUG
6330 test_62() {
6331         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6332
6333         f="$DIR/f62"
6334         echo foo > $f
6335         cancel_lru_locks osc
6336         lctl set_param fail_loc=0x405
6337         cat $f && error "cat succeeded, expect -EIO"
6338         lctl set_param fail_loc=0
6339 }
6340 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
6341 # match every page all of the time.
6342 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
6343
6344 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
6345 # Though this test is irrelevant anymore, it helped to reveal some
6346 # other grant bugs (LU-4482), let's keep it.
6347 test_63a() {   # was test_63
6348         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6349
6350         MAX_DIRTY_MB=$(lctl get_param -n osc.*.max_dirty_mb | head -n 1)
6351
6352         for i in `seq 10` ; do
6353                 dd if=/dev/zero of=$DIR/f63 bs=8k &
6354                 sleep 5
6355                 kill $!
6356                 sleep 1
6357         done
6358
6359         rm -f $DIR/f63 || true
6360 }
6361 run_test 63a "Verify oig_wait interruption does not crash ======="
6362
6363 # bug 2248 - async write errors didn't return to application on sync
6364 # bug 3677 - async write errors left page locked
6365 test_63b() {
6366         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6367
6368         debugsave
6369         lctl set_param debug=-1
6370
6371         # ensure we have a grant to do async writes
6372         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
6373         rm $DIR/$tfile
6374
6375         sync    # sync lest earlier test intercept the fail_loc
6376
6377         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
6378         lctl set_param fail_loc=0x80000406
6379         $MULTIOP $DIR/$tfile Owy && \
6380                 error "sync didn't return ENOMEM"
6381         sync; sleep 2; sync     # do a real sync this time to flush page
6382         lctl get_param -n llite.*.dump_page_cache | grep locked && \
6383                 error "locked page left in cache after async error" || true
6384         debugrestore
6385 }
6386 run_test 63b "async write errors should be returned to fsync ==="
6387
6388 test_64a () {
6389         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6390
6391         df $DIR
6392         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
6393 }
6394 run_test 64a "verify filter grant calculations (in kernel) ====="
6395
6396 test_64b () {
6397         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6398
6399         sh oos.sh $MOUNT || error "oos.sh failed: $?"
6400 }
6401 run_test 64b "check out-of-space detection on client"
6402
6403 test_64c() {
6404         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
6405 }
6406 run_test 64c "verify grant shrink"
6407
6408 # this does exactly what osc_request.c:osc_announce_cached() does in
6409 # order to calculate max amount of grants to ask from server
6410 want_grant() {
6411         local tgt=$1
6412
6413         local page_size=$(get_page_size client)
6414
6415         local nrpages=$($LCTL get_param -n osc.${tgt}.max_pages_per_rpc)
6416         local rpc_in_flight=$($LCTL get_param -n osc.${tgt}.max_rpcs_in_flight)
6417
6418         ((rpc_in_flight ++));
6419         nrpages=$((nrpages * rpc_in_flight))
6420
6421         local dirty_max_pages=$($LCTL get_param -n osc.${tgt}.max_dirty_mb)
6422
6423         dirty_max_pages=$((dirty_max_pages * 1024 * 1024 / page_size))
6424
6425         [[ $dirty_max_pages -gt $nrpages ]] && nrpages=$dirty_max_pages
6426         local undirty=$((nrpages * page_size))
6427
6428         local max_extent_pages
6429         max_extent_pages=$($LCTL get_param osc.${tgt}.import |
6430             grep grant_max_extent_size | awk '{print $2}')
6431         max_extent_pages=$((max_extent_pages / page_size))
6432         local nrextents=$(((nrpages + max_extent_pages - 1) / max_extent_pages))
6433         local grant_extent_tax
6434         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
6435             grep grant_extent_tax | awk '{print $2}')
6436
6437         undirty=$((undirty + nrextents * grant_extent_tax))
6438
6439         echo $undirty
6440 }
6441
6442 # this is size of unit for grant allocation. It should be equal to
6443 # what tgt_grant.c:tgt_grant_chunk() calculates
6444 grant_chunk() {
6445         local tgt=$1
6446         local max_brw_size
6447         local grant_extent_tax
6448
6449         max_brw_size=$($LCTL get_param osc.${tgt}.import |
6450             grep max_brw_size | awk '{print $2}')
6451
6452         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
6453             grep grant_extent_tax | awk '{print $2}')
6454
6455         echo $(((max_brw_size + grant_extent_tax) * 2))
6456 }
6457
6458 test_64d() {
6459         [ $(lustre_version_code ost1) -lt $(version_code 2.10.56) ] &&
6460                 skip "OST < 2.10.55 doesn't limit grants enough"
6461
6462         local tgt=$($LCTL dl | grep "0000-osc-[^mM]" | awk '{print $4}')
6463         local file=$DIR/$tfile
6464
6465         [[ $($LCTL get_param osc.${tgt}.import |
6466              grep "connect_flags:.*grant_param") ]] ||
6467                 skip "no grant_param connect flag"
6468
6469         local olddebug=$($LCTL get_param -n debug 2> /dev/null)
6470
6471         $LCTL set_param debug="$OLDDEBUG" 2> /dev/null || true
6472
6473         local max_cur_granted=$(($(want_grant $tgt) + $(grant_chunk $tgt)))
6474         stack_trap "rm -f $file" EXIT
6475
6476         $SETSTRIPE $file -i 0 -c 1
6477         dd if=/dev/zero of=$file bs=1M count=1000 &
6478         ddpid=$!
6479
6480         while true
6481         do
6482                 local cur_grant=$($LCTL get_param -n osc.${tgt}.cur_grant_bytes)
6483                 if [[ $cur_grant -gt $max_cur_granted ]]
6484                 then
6485                         kill $ddpid
6486                         error "cur_grant $cur_grant > $max_cur_granted"
6487                 fi
6488                 kill -0 $ddpid
6489                 [[ $? -ne 0 ]] && break;
6490                 sleep 2
6491         done
6492
6493         rm -f $DIR/$tfile
6494         wait_delete_completed
6495         $LCTL set_param debug="$olddebug" 2> /dev/null || true
6496 }
6497 run_test 64d "check grant limit exceed"
6498
6499 # bug 1414 - set/get directories' stripe info
6500 test_65a() {
6501         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6502
6503         test_mkdir $DIR/$tdir
6504         touch $DIR/$tdir/f1
6505         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
6506 }
6507 run_test 65a "directory with no stripe info"
6508
6509 test_65b() {
6510         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6511
6512         test_mkdir $DIR/$tdir
6513         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
6514
6515         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
6516                                                 error "setstripe"
6517         touch $DIR/$tdir/f2
6518         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
6519 }
6520 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
6521
6522 test_65c() {
6523         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6524         [ $OSTCOUNT -lt 2 ] && skip_env "need at least 2 OSTs"
6525
6526         test_mkdir $DIR/$tdir
6527         local stripesize=$($GETSTRIPE -S $DIR/$tdir)
6528
6529         $LFS setstripe -S $((stripesize * 4)) -i 1 \
6530                 -c $((OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
6531         touch $DIR/$tdir/f3
6532         $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
6533 }
6534 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
6535
6536 test_65d() {
6537         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6538
6539         test_mkdir $DIR/$tdir
6540         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
6541         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
6542
6543         if [[ $STRIPECOUNT -le 0 ]]; then
6544                 sc=1
6545         elif [[ $STRIPECOUNT -gt 2000 ]]; then
6546 #LOV_MAX_STRIPE_COUNT is 2000
6547                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
6548         else
6549                 sc=$(($STRIPECOUNT - 1))
6550         fi
6551         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
6552         touch $DIR/$tdir/f4 $DIR/$tdir/f5
6553         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
6554                 error "lverify failed"
6555 }
6556 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
6557
6558 test_65e() {
6559         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6560
6561         test_mkdir $DIR/$tdir
6562
6563         $SETSTRIPE $DIR/$tdir || error "setstripe"
6564         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
6565                                         error "no stripe info failed"
6566         touch $DIR/$tdir/f6
6567         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
6568 }
6569 run_test 65e "directory setstripe defaults"
6570
6571 test_65f() {
6572         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6573
6574         test_mkdir $DIR/${tdir}f
6575         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
6576 }
6577 run_test 65f "dir setstripe permission (should return error) ==="
6578
6579 test_65g() {
6580         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6581
6582         test_mkdir $DIR/$tdir
6583         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
6584
6585         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
6586                 error "setstripe -S failed"
6587         $LFS setstripe -d $DIR/$tdir || error "setstripe -d failed"
6588         $LFS getstripe -v $DIR/$tdir | grep "Default" ||
6589                 error "delete default stripe failed"
6590 }
6591 run_test 65g "directory setstripe -d"
6592
6593 test_65h() {
6594         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6595
6596         test_mkdir $DIR/$tdir
6597         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
6598
6599         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
6600                 error "setstripe -S failed"
6601         test_mkdir $DIR/$tdir/dd1
6602         [ $($LFS getstripe -c $DIR/$tdir) = $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
6603                 error "stripe info inherit failed"
6604 }
6605 run_test 65h "directory stripe info inherit ===================="
6606
6607 test_65i() {
6608         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6609
6610         save_layout_restore_at_exit $MOUNT
6611
6612         # bug6367: set non-default striping on root directory
6613         $LFS setstripe -S 65536 -c -1 $MOUNT || error "error setting stripe"
6614
6615         # bug12836: getstripe on -1 default directory striping
6616         $LFS getstripe $MOUNT || error "getstripe $MOUNT failed"
6617
6618         # bug12836: getstripe -v on -1 default directory striping
6619         $LFS getstripe -v $MOUNT || error "getstripe -v $MOUNT failed"
6620
6621         # bug12836: new find on -1 default directory striping
6622         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
6623 }
6624 run_test 65i "various tests to set root directory striping"
6625
6626 test_65j() { # bug6367
6627         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6628
6629         sync; sleep 1
6630
6631         # if we aren't already remounting for each test, do so for this test
6632         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
6633                 cleanup || error "failed to unmount"
6634                 setup
6635         fi
6636
6637         save_layout_restore_at_exit $MOUNT
6638
6639         $SETSTRIPE -d $MOUNT || error "setstripe failed"
6640 }
6641 run_test 65j "set default striping on root directory (bug 6367)="
6642
6643 cleaup_65k() {
6644         rm -rf $DIR/$tdir
6645         wait_delete_completed
6646         do_facet $SINGLEMDS "lctl set_param -n \
6647                 osp.$ost*MDT0000.max_create_count=$max_count"
6648         do_facet $SINGLEMDS "lctl set_param -n \
6649                 osp.$ost*MDT0000.create_count=$count"
6650         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
6651         echo $INACTIVE_OSC "is Activate"
6652
6653         wait_osc_import_state mds ost$ostnum FULL
6654 }
6655
6656 test_65k() { # bug11679
6657         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6658         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6659         remote_mds_nodsh && skip "remote MDS with nodsh"
6660
6661         local disable_precreate=true
6662         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.8.54) ] &&
6663                 disable_precreate=false
6664
6665         echo "Check OST status: "
6666         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
6667                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
6668
6669         for OSC in $MDS_OSCS; do
6670                 echo $OSC "is active"
6671                 do_facet $SINGLEMDS lctl --device %$OSC activate
6672         done
6673
6674         for INACTIVE_OSC in $MDS_OSCS; do
6675                 local ost=$(osc_to_ost $INACTIVE_OSC)
6676                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
6677                                lov.*md*.target_obd |
6678                                awk -F: /$ost/'{ print $1 }' | head -n 1)
6679
6680                 mkdir -p $DIR/$tdir
6681                 $SETSTRIPE -i $ostnum -c 1 $DIR/$tdir
6682                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
6683
6684                 echo "Deactivate: " $INACTIVE_OSC
6685                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
6686
6687                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
6688                               osp.$ost*MDT0000.create_count")
6689                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
6690                                   osp.$ost*MDT0000.max_create_count")
6691                 $disable_precreate &&
6692                         do_facet $SINGLEMDS "lctl set_param -n \
6693                                 osp.$ost*MDT0000.max_create_count=0"
6694
6695                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
6696                         [ -f $DIR/$tdir/$idx ] && continue
6697                         echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
6698                         $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
6699                                 { cleanup_65k;
6700                                   error "setstripe $idx should succeed"; }
6701                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
6702                 done
6703                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
6704                 rmdir $DIR/$tdir
6705
6706                 do_facet $SINGLEMDS "lctl set_param -n \
6707                         osp.$ost*MDT0000.max_create_count=$max_count"
6708                 do_facet $SINGLEMDS "lctl set_param -n \
6709                         osp.$ost*MDT0000.create_count=$count"
6710                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
6711                 echo $INACTIVE_OSC "is Activate"
6712
6713                 wait_osc_import_state mds ost$ostnum FULL
6714         done
6715 }
6716 run_test 65k "validate manual striping works properly with deactivated OSCs"
6717
6718 test_65l() { # bug 12836
6719         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6720
6721         test_mkdir -p $DIR/$tdir/test_dir
6722         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
6723         $LFS find -mtime -1 $DIR/$tdir >/dev/null
6724 }
6725 run_test 65l "lfs find on -1 stripe dir ========================"
6726
6727 test_65m() {
6728         local layout=$(save_layout $MOUNT)
6729         $RUNAS $SETSTRIPE -c 2 $MOUNT && {
6730                 restore_layout $MOUNT $layout
6731                 error "setstripe should fail by non-root users"
6732         }
6733         true
6734 }
6735 run_test 65m "normal user can't set filesystem default stripe"
6736
6737 # bug 2543 - update blocks count on client
6738 test_66() {
6739         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6740
6741         COUNT=${COUNT:-8}
6742         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
6743         sync; sync_all_data; sync; sync_all_data
6744         cancel_lru_locks osc
6745         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
6746         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
6747 }
6748 run_test 66 "update inode blocks count on client ==============="
6749
6750 meminfo() {
6751         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
6752 }
6753
6754 swap_used() {
6755         swapon -s | awk '($1 == "'$1'") { print $4 }'
6756 }
6757
6758 # bug5265, obdfilter oa2dentry return -ENOENT
6759 # #define OBD_FAIL_SRV_ENOENT 0x217
6760 test_69() {
6761         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6762         remote_ost_nodsh && skip "remote OST with nodsh"
6763
6764         f="$DIR/$tfile"
6765         $SETSTRIPE -c 1 -i 0 $f
6766
6767         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
6768
6769         do_facet ost1 lctl set_param fail_loc=0x217
6770         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
6771         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
6772
6773         do_facet ost1 lctl set_param fail_loc=0
6774         $DIRECTIO write $f 0 2 || error "write error"
6775
6776         cancel_lru_locks osc
6777         $DIRECTIO read $f 0 1 || error "read error"
6778
6779         do_facet ost1 lctl set_param fail_loc=0x217
6780         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
6781
6782         do_facet ost1 lctl set_param fail_loc=0
6783         rm -f $f
6784 }
6785 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
6786
6787 test_71() {
6788         test_mkdir $DIR/$tdir
6789         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
6790         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
6791 }
6792 run_test 71 "Running dbench on lustre (don't segment fault) ===="
6793
6794 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
6795         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6796         [ "$RUNAS_ID" = "$UID" ] &&
6797                 skip_env "RUNAS_ID = UID = $UID -- skipping"
6798         # Check that testing environment is properly set up. Skip if not
6799         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS ||
6800                 skip_env "User $RUNAS_ID does not exist - skipping"
6801
6802         touch $DIR/$tfile
6803         chmod 777 $DIR/$tfile
6804         chmod ug+s $DIR/$tfile
6805         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
6806                 error "$RUNAS dd $DIR/$tfile failed"
6807         # See if we are still setuid/sgid
6808         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6809                 error "S/gid is not dropped on write"
6810         # Now test that MDS is updated too
6811         cancel_lru_locks mdc
6812         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6813                 error "S/gid is not dropped on MDS"
6814         rm -f $DIR/$tfile
6815 }
6816 run_test 72a "Test that remove suid works properly (bug5695) ===="
6817
6818 test_72b() { # bug 24226 -- keep mode setting when size is not changing
6819         local perm
6820
6821         [ "$RUNAS_ID" = "$UID" ] &&
6822                 skip_env "RUNAS_ID = UID = $UID -- skipping"
6823         [ "$RUNAS_ID" -eq 0 ] &&
6824                 skip_env "RUNAS_ID = 0 -- skipping"
6825         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6826         # Check that testing environment is properly set up. Skip if not
6827         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS ||
6828                 skip_env "User $RUNAS_ID does not exist - skipping"
6829
6830         touch $DIR/${tfile}-f{g,u}
6831         test_mkdir $DIR/${tfile}-dg
6832         test_mkdir $DIR/${tfile}-du
6833         chmod 770 $DIR/${tfile}-{f,d}{g,u}
6834         chmod g+s $DIR/${tfile}-{f,d}g
6835         chmod u+s $DIR/${tfile}-{f,d}u
6836         for perm in 777 2777 4777; do
6837                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
6838                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
6839                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
6840                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
6841         done
6842         true
6843 }
6844 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
6845
6846 # bug 3462 - multiple simultaneous MDC requests
6847 test_73() {
6848         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6849
6850         test_mkdir $DIR/d73-1
6851         test_mkdir $DIR/d73-2
6852         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
6853         pid1=$!
6854
6855         lctl set_param fail_loc=0x80000129
6856         $MULTIOP $DIR/d73-1/f73-2 Oc &
6857         sleep 1
6858         lctl set_param fail_loc=0
6859
6860         $MULTIOP $DIR/d73-2/f73-3 Oc &
6861         pid3=$!
6862
6863         kill -USR1 $pid1
6864         wait $pid1 || return 1
6865
6866         sleep 25
6867
6868         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
6869         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
6870         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
6871
6872         rm -rf $DIR/d73-*
6873 }
6874 run_test 73 "multiple MDC requests (should not deadlock)"
6875
6876 test_74a() { # bug 6149, 6184
6877         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6878
6879         touch $DIR/f74a
6880         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6881         #
6882         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6883         # will spin in a tight reconnection loop
6884         $LCTL set_param fail_loc=0x8000030e
6885         # get any lock that won't be difficult - lookup works.
6886         ls $DIR/f74a
6887         $LCTL set_param fail_loc=0
6888         rm -f $DIR/f74a
6889         true
6890 }
6891 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
6892
6893 test_74b() { # bug 13310
6894         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6895
6896         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6897         #
6898         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6899         # will spin in a tight reconnection loop
6900         $LCTL set_param fail_loc=0x8000030e
6901         # get a "difficult" lock
6902         touch $DIR/f74b
6903         $LCTL set_param fail_loc=0
6904         rm -f $DIR/f74b
6905         true
6906 }
6907 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
6908
6909 test_74c() {
6910         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6911
6912         #define OBD_FAIL_LDLM_NEW_LOCK
6913         $LCTL set_param fail_loc=0x319
6914         touch $DIR/$tfile && error "touch successful"
6915         $LCTL set_param fail_loc=0
6916         true
6917 }
6918 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
6919
6920 num_inodes() {
6921         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
6922 }
6923
6924 test_76() { # Now for bug 20433, added originally in bug 1443
6925         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6926
6927         local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
6928
6929         cancel_lru_locks osc
6930         BEFORE_INODES=$(num_inodes)
6931         echo "before inodes: $BEFORE_INODES"
6932         local COUNT=1000
6933         [ "$SLOW" = "no" ] && COUNT=100
6934         for i in $(seq $COUNT); do
6935                 touch $DIR/$tfile
6936                 rm -f $DIR/$tfile
6937         done
6938         cancel_lru_locks osc
6939         AFTER_INODES=$(num_inodes)
6940         echo "after inodes: $AFTER_INODES"
6941         local wait=0
6942         while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
6943                 sleep 2
6944                 AFTER_INODES=$(num_inodes)
6945                 wait=$((wait+2))
6946                 echo "wait $wait seconds inodes: $AFTER_INODES"
6947                 if [ $wait -gt 30 ]; then
6948                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
6949                 fi
6950         done
6951 }
6952 run_test 76 "confirm clients recycle inodes properly ===="
6953
6954
6955 export ORIG_CSUM=""
6956 set_checksums()
6957 {
6958         # Note: in sptlrpc modes which enable its own bulk checksum, the
6959         # original crc32_le bulk checksum will be automatically disabled,
6960         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
6961         # will be checked by sptlrpc code against sptlrpc bulk checksum.
6962         # In this case set_checksums() will not be no-op, because sptlrpc
6963         # bulk checksum will be enabled all through the test.
6964
6965         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
6966         lctl set_param -n osc.*.checksums $1
6967         return 0
6968 }
6969
6970 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6971                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
6972 CKSUM_TYPES=${CKSUM_TYPES:-$(lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6973                              tr -d [] | head -n1)}
6974 set_checksum_type()
6975 {
6976         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
6977         log "set checksum type to $1"
6978         return 0
6979 }
6980 F77_TMP=$TMP/f77-temp
6981 F77SZ=8
6982 setup_f77() {
6983         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
6984                 error "error writing to $F77_TMP"
6985 }
6986
6987 test_77a() { # bug 10889
6988         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6989         $GSS && skip_env "could not run with gss"
6990
6991         [ ! -f $F77_TMP ] && setup_f77
6992         set_checksums 1
6993         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
6994         set_checksums 0
6995         rm -f $DIR/$tfile
6996 }
6997 run_test 77a "normal checksum read/write operation"
6998
6999 test_77b() { # bug 10889
7000         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7001         $GSS && skip_env "could not run with gss"
7002
7003         [ ! -f $F77_TMP ] && setup_f77
7004         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
7005         $LCTL set_param fail_loc=0x80000409
7006         set_checksums 1
7007
7008         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
7009                 error "dd error: $?"
7010         $LCTL set_param fail_loc=0
7011
7012         for algo in $CKSUM_TYPES; do
7013                 cancel_lru_locks osc
7014                 set_checksum_type $algo
7015                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
7016                 $LCTL set_param fail_loc=0x80000408
7017                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
7018                 $LCTL set_param fail_loc=0
7019         done
7020         set_checksums 0
7021         set_checksum_type $ORIG_CSUM_TYPE
7022         rm -f $DIR/$tfile
7023 }
7024 run_test 77b "checksum error on client write, read"
7025
7026 cleanup_77c() {
7027         trap 0
7028         set_checksums 0
7029         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
7030         $check_ost &&
7031                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
7032         [ -n "$osc_file_prefix" ] && rm -f ${osc_file_prefix}*
7033         $check_ost && [ -n "$ost_file_prefix" ] &&
7034                 do_facet ost1 rm -f ${ost_file_prefix}\*
7035 }
7036
7037 test_77c() {
7038         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7039         $GSS && skip_env "could not run with gss"
7040         remote_ost_nodsh && skip "remote OST with nodsh"
7041
7042         local bad1
7043         local osc_file_prefix
7044         local osc_file
7045         local check_ost=false
7046         local ost_file_prefix
7047         local ost_file
7048         local orig_cksum
7049         local dump_cksum
7050         local fid
7051
7052         # ensure corruption will occur on first OSS/OST
7053         $LFS setstripe -i 0 $DIR/$tfile
7054
7055         [ ! -f $F77_TMP ] && setup_f77
7056         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
7057                 error "dd write error: $?"
7058         fid=$($LFS path2fid $DIR/$tfile)
7059
7060         if [ $(lustre_version_code ost1) -ge $(version_code 2.9.57) ]
7061         then
7062                 check_ost=true
7063                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
7064                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
7065         else
7066                 echo "OSS do not support bulk pages dump upon error"
7067         fi
7068
7069         osc_file_prefix=$($LCTL get_param -n debug_path)
7070         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
7071
7072         trap cleanup_77c EXIT
7073
7074         set_checksums 1
7075         # enable bulk pages dump upon error on Client
7076         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
7077         # enable bulk pages dump upon error on OSS
7078         $check_ost &&
7079                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
7080
7081         # flush Client cache to allow next read to reach OSS
7082         cancel_lru_locks osc
7083
7084         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
7085         $LCTL set_param fail_loc=0x80000408
7086         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
7087         $LCTL set_param fail_loc=0
7088
7089         rm -f $DIR/$tfile
7090
7091         # check cksum dump on Client
7092         osc_file=$(ls ${osc_file_prefix}*)
7093         [ -n "$osc_file" ] || error "no checksum dump file on Client"
7094         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
7095         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
7096         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
7097         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
7098                      cksum)
7099         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
7100         [[ "$orig_cksum" == "$dump_cksum" ]] ||
7101                 error "dump content does not match on Client"
7102
7103         $check_ost || skip "No need to check cksum dump on OSS"
7104
7105         # check cksum dump on OSS
7106         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
7107         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
7108         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
7109         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
7110         [[ "$orig_cksum" == "$dump_cksum" ]] ||
7111                 error "dump content does not match on OSS"
7112
7113         cleanup_77c
7114 }
7115 run_test 77c "checksum error on client read with debug"
7116
7117 test_77d() { # bug 10889
7118         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7119         $GSS && skip_env "could not run with gss"
7120
7121         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
7122         $LCTL set_param fail_loc=0x80000409
7123         set_checksums 1
7124         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
7125                 error "direct write: rc=$?"
7126         $LCTL set_param fail_loc=0
7127         set_checksums 0
7128
7129         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
7130         $LCTL set_param fail_loc=0x80000408
7131         set_checksums 1
7132         cancel_lru_locks osc
7133         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
7134                 error "direct read: rc=$?"
7135         $LCTL set_param fail_loc=0
7136         set_checksums 0
7137 }
7138 run_test 77d "checksum error on OST direct write, read"
7139
7140 test_77f() { # bug 10889
7141         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7142         $GSS && skip_env "could not run with gss"
7143
7144         set_checksums 1
7145         for algo in $CKSUM_TYPES; do
7146                 cancel_lru_locks osc
7147                 set_checksum_type $algo
7148                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
7149                 $LCTL set_param fail_loc=0x409
7150                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
7151                         error "direct write succeeded"
7152                 $LCTL set_param fail_loc=0
7153         done
7154         set_checksum_type $ORIG_CSUM_TYPE
7155         set_checksums 0
7156 }
7157 run_test 77f "repeat checksum error on write (expect error)"
7158
7159 test_77g() { # bug 10889
7160         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7161         $GSS && skip_env "could not run with gss"
7162         remote_ost_nodsh && skip "remote OST with nodsh"
7163
7164         [ ! -f $F77_TMP ] && setup_f77
7165
7166         local file=$DIR/$tfile
7167         stack_trap "rm -f $file" EXIT
7168
7169         $SETSTRIPE -c 1 -i 0 $file
7170         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
7171         do_facet ost1 lctl set_param fail_loc=0x8000021a
7172         set_checksums 1
7173         dd if=$F77_TMP of=$file bs=1M count=$F77SZ ||
7174                 error "write error: rc=$?"
7175         do_facet ost1 lctl set_param fail_loc=0
7176         set_checksums 0
7177
7178         cancel_lru_locks osc
7179         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
7180         do_facet ost1 lctl set_param fail_loc=0x8000021b
7181         set_checksums 1
7182         cmp $F77_TMP $file || error "file compare failed"
7183         do_facet ost1 lctl set_param fail_loc=0
7184         set_checksums 0
7185 }
7186 run_test 77g "checksum error on OST write, read"
7187
7188 test_77k() { # LU-10906
7189         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7190         $GSS && skip_env "could not run with gss"
7191
7192         local cksum_param="osc.$FSNAME*.checksums"
7193         local get_checksum="$LCTL get_param -n $cksum_param | head -n1"
7194         local checksum
7195         local i
7196
7197         [ "$ORIG_CSUM" ] || ORIG_CSUM=$(eval $get_checksum)
7198         stack_trap "wait_update $HOSTNAME '$get_checksum' $ORIG_CSUM" EXIT
7199         stack_trap "do_facet mgs $LCTL set_param -P $cksum_param=$ORIG_CSUM" \
7200                 EXIT
7201
7202         for i in 0 1; do
7203                 do_facet mgs $LCTL set_param -P $cksum_param=$i ||
7204                         error "failed to set checksum=$i on MGS"
7205                 wait_update $HOSTNAME "$get_checksum" $i
7206                 #remount
7207                 echo "remount client, checksum should be $i"
7208                 remount_client $MOUNT || "failed to remount client"
7209                 checksum=$(eval $get_checksum)
7210                 [ $checksum -eq $i ] || error "checksum($checksum) != $i"
7211         done
7212
7213         for opt in "checksum" "nochecksum"; do
7214                 #remount with mount option
7215                 echo "remount client with option $opt, checksum should be $i"
7216                 umount_client $MOUNT || "failed to umount client"
7217                 mount_client $MOUNT "$MOUNT_OPTS,$opt" ||
7218                         "failed to mount client with option '$opt'"
7219                 checksum=$(eval $get_checksum)
7220                 [ $checksum -eq $i ] || error "checksum($checksum) != $i"
7221                 i=$((i - 1))
7222         done
7223
7224         remount_client $MOUNT || "failed to remount client"
7225 }
7226 run_test 77k "enable/disable checksum correctly"
7227
7228 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
7229 rm -f $F77_TMP
7230 unset F77_TMP
7231
7232 cleanup_test_78() {
7233         trap 0
7234         rm -f $DIR/$tfile
7235 }
7236
7237 test_78() { # bug 10901
7238         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7239         remote_ost || skip_env "local OST"
7240
7241         NSEQ=5
7242         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
7243         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
7244         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
7245         echo "MemTotal: $MEMTOTAL"
7246
7247         # reserve 256MB of memory for the kernel and other running processes,
7248         # and then take 1/2 of the remaining memory for the read/write buffers.
7249         if [ $MEMTOTAL -gt 512 ] ;then
7250                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
7251         else
7252                 # for those poor memory-starved high-end clusters...
7253                 MEMTOTAL=$((MEMTOTAL / 2))
7254         fi
7255         echo "Mem to use for directio: $MEMTOTAL"
7256
7257         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
7258         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
7259         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
7260         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
7261                 head -n1)
7262         echo "Smallest OST: $SMALLESTOST"
7263         [[ $SMALLESTOST -lt 10240 ]] &&
7264                 skip "too small OSTSIZE, useless to run large O_DIRECT test"
7265
7266         trap cleanup_test_78 EXIT
7267
7268         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
7269                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
7270
7271         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
7272         echo "File size: $F78SIZE"
7273         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
7274         for i in $(seq 1 $NSEQ); do
7275                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
7276                 echo directIO rdwr round $i of $NSEQ
7277                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
7278         done
7279
7280         cleanup_test_78
7281 }
7282 run_test 78 "handle large O_DIRECT writes correctly ============"
7283
7284 test_79() { # bug 12743
7285         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7286
7287         wait_delete_completed
7288
7289         BKTOTAL=$(calc_osc_kbytes kbytestotal)
7290         BKFREE=$(calc_osc_kbytes kbytesfree)
7291         BKAVAIL=$(calc_osc_kbytes kbytesavail)
7292
7293         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
7294         DFTOTAL=`echo $STRING | cut -d, -f1`
7295         DFUSED=`echo $STRING  | cut -d, -f2`
7296         DFAVAIL=`echo $STRING | cut -d, -f3`
7297         DFFREE=$(($DFTOTAL - $DFUSED))
7298
7299         ALLOWANCE=$((64 * $OSTCOUNT))
7300
7301         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
7302            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
7303                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
7304         fi
7305         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
7306            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
7307                 error "df free($DFFREE) mismatch OST free($BKFREE)"
7308         fi
7309         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
7310            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
7311                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
7312         fi
7313 }
7314 run_test 79 "df report consistency check ======================="
7315
7316 test_80() { # bug 10718
7317         remote_ost_nodsh && skip "remote OST with nodsh"
7318         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7319
7320         # relax strong synchronous semantics for slow backends like ZFS
7321         local soc="obdfilter.*.sync_on_lock_cancel"
7322         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
7323         local hosts=
7324         if [ "$soc_old" != "never" ] &&
7325                 [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
7326                         hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
7327                                 facet_active_host $host; done | sort -u)
7328                         do_nodes $hosts lctl set_param $soc=never
7329         fi
7330
7331         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
7332         sync; sleep 1; sync
7333         local BEFORE=`date +%s`
7334         cancel_lru_locks osc
7335         local AFTER=`date +%s`
7336         local DIFF=$((AFTER-BEFORE))
7337         if [ $DIFF -gt 1 ] ; then
7338                 error "elapsed for 1M@1T = $DIFF"
7339         fi
7340
7341         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
7342
7343         rm -f $DIR/$tfile
7344 }
7345 run_test 80 "Page eviction is equally fast at high offsets too  ===="
7346
7347 test_81a() { # LU-456
7348         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7349         remote_ost_nodsh && skip "remote OST with nodsh"
7350
7351         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
7352         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
7353         do_facet ost1 lctl set_param fail_loc=0x80000228
7354
7355         # write should trigger a retry and success
7356         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
7357         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7358         RC=$?
7359         if [ $RC -ne 0 ] ; then
7360                 error "write should success, but failed for $RC"
7361         fi
7362 }
7363 run_test 81a "OST should retry write when get -ENOSPC ==============="
7364
7365 test_81b() { # LU-456
7366         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7367         remote_ost_nodsh && skip "remote OST with nodsh"
7368
7369         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
7370         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
7371         do_facet ost1 lctl set_param fail_loc=0x228
7372
7373         # write should retry several times and return -ENOSPC finally
7374         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
7375         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7376         RC=$?
7377         ENOSPC=28
7378         if [ $RC -ne $ENOSPC ] ; then
7379                 error "dd should fail for -ENOSPC, but succeed."
7380         fi
7381 }
7382 run_test 81b "OST should return -ENOSPC when retry still fails ======="
7383
7384 test_82() { # LU-1031
7385         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
7386         local gid1=14091995
7387         local gid2=16022000
7388
7389         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
7390         local MULTIPID1=$!
7391         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
7392         local MULTIPID2=$!
7393         kill -USR1 $MULTIPID2
7394         sleep 2
7395         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
7396                 error "First grouplock does not block second one"
7397         else
7398                 echo "Second grouplock blocks first one"
7399         fi
7400         kill -USR1 $MULTIPID1
7401         wait $MULTIPID1
7402         wait $MULTIPID2
7403 }
7404 run_test 82 "Basic grouplock test"
7405
7406 test_83() {
7407         local sfile="/boot/System.map-$(uname -r)"
7408         [ ! -f $sfile ] && skip "No $sfile found"
7409         # define OBD_FAIL_LLITE_PTASK_IO_FAIL 0x140d
7410         $LCTL set_param fail_loc=0x140d
7411         cp $sfile $DIR/$tfile || error "write failed"
7412         diff -c $sfile $DIR/$tfile || error "files are different"
7413         $LCTL set_param fail_loc=0
7414         rm -f $DIR/$tfile
7415 }
7416 run_test 83 "Short write in ptask ==============================="
7417
7418 test_99() {
7419         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs"
7420
7421         test_mkdir $DIR/$tdir.cvsroot
7422         chown $RUNAS_ID $DIR/$tdir.cvsroot
7423
7424         cd $TMP
7425         $RUNAS cvs -d $DIR/$tdir.cvsroot init || error "cvs init failed"
7426
7427         cd /etc/init.d
7428         # some versions of cvs import exit(1) when asked to import links or
7429         # files they can't read.  ignore those files.
7430         local toignore=$(find . -type l -printf '-I %f\n' -o \
7431                          ! -perm /4 -printf '-I %f\n')
7432         $RUNAS cvs -d $DIR/$tdir.cvsroot import -m "nomesg" $toignore \
7433                 $tdir.reposname vtag rtag
7434
7435         cd $DIR
7436         test_mkdir $DIR/$tdir.reposname
7437         chown $RUNAS_ID $DIR/$tdir.reposname
7438         $RUNAS cvs -d $DIR/$tdir.cvsroot co $tdir.reposname
7439
7440         cd $DIR/$tdir.reposname
7441         $RUNAS touch foo99
7442         $RUNAS cvs add -m 'addmsg' foo99
7443         $RUNAS cvs update
7444         $RUNAS cvs commit -m 'nomsg' foo99
7445         rm -fr $DIR/$tdir.cvsroot
7446 }
7447 run_test 99 "cvs strange file/directory operations"
7448
7449 test_100() {
7450         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7451         [[ "$NETTYPE" =~ tcp ]] ||
7452                 skip_env "TCP secure port test, not useful for NETTYPE=$NETTYPE"
7453         remote_ost_nodsh && skip "remote OST with nodsh"
7454         remote_mds_nodsh && skip "remote MDS with nodsh"
7455         remote_servers ||
7456                 skip "useless for local single node setup"
7457
7458         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
7459                 [ "$PROT" != "tcp" ] && continue
7460                 RPORT=$(echo $REMOTE | cut -d: -f2)
7461                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
7462
7463                 rc=0
7464                 LPORT=`echo $LOCAL | cut -d: -f2`
7465                 if [ $LPORT -ge 1024 ]; then
7466                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
7467                         netstat -tna
7468                         error_exit "local: $LPORT > 1024, remote: $RPORT"
7469                 fi
7470         done
7471         [ "$rc" = 0 ] || error_exit "privileged port not found" )
7472 }
7473 run_test 100 "check local port using privileged port ==========="
7474
7475 function get_named_value()
7476 {
7477     local tag
7478
7479     tag=$1
7480     while read ;do
7481         line=$REPLY
7482         case $line in
7483         $tag*)
7484             echo $line | sed "s/^$tag[ ]*//"
7485             break
7486             ;;
7487         esac
7488     done
7489 }
7490
7491 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
7492                    awk '/^max_cached_mb/ { print $2 }')
7493
7494 cleanup_101a() {
7495         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
7496         trap 0
7497 }
7498
7499 test_101a() {
7500         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7501         [ $MDSCOUNT -ge 2 ] && skip_env "needs < 2 MDTs" #LU-4322
7502
7503         local s
7504         local discard
7505         local nreads=10000
7506         local cache_limit=32
7507
7508         $LCTL set_param -n osc.*-osc*.rpc_stats 0
7509         trap cleanup_101a EXIT
7510         $LCTL set_param -n llite.*.read_ahead_stats 0
7511         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
7512
7513         #
7514         # randomly read 10000 of 64K chunks from file 3x 32MB in size
7515         #
7516         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
7517         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
7518
7519         discard=0
7520         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
7521                 get_named_value 'read but discarded' | cut -d" " -f1); do
7522                         discard=$(($discard + $s))
7523         done
7524         cleanup_101a
7525
7526         if [[ $(($discard * 10)) -gt $nreads ]]; then
7527                 $LCTL get_param osc.*-osc*.rpc_stats
7528                 $LCTL get_param llite.*.read_ahead_stats
7529                 error "too many ($discard) discarded pages"
7530         fi
7531         rm -f $DIR/$tfile || true
7532 }
7533 run_test 101a "check read-ahead for random reads"
7534
7535 setup_test101bc() {
7536         test_mkdir $DIR/$tdir
7537         local STRIPE_SIZE=$1
7538         local FILE_LENGTH=$2
7539         STRIPE_OFFSET=0
7540
7541         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
7542
7543         local list=$(comma_list $(osts_nodes))
7544         set_osd_param $list '' read_cache_enable 0
7545         set_osd_param $list '' writethrough_cache_enable 0
7546
7547         trap cleanup_test101bc EXIT
7548         # prepare the read-ahead file
7549         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
7550
7551         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
7552                                 count=$FILE_SIZE_MB 2> /dev/null
7553
7554 }
7555
7556 cleanup_test101bc() {
7557         trap 0
7558         rm -rf $DIR/$tdir
7559         rm -f $DIR/$tfile
7560
7561         local list=$(comma_list $(osts_nodes))
7562         set_osd_param $list '' read_cache_enable 1
7563         set_osd_param $list '' writethrough_cache_enable 1
7564 }
7565
7566 calc_total() {
7567         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
7568 }
7569
7570 ra_check_101() {
7571         local READ_SIZE=$1
7572         local STRIPE_SIZE=$2
7573         local FILE_LENGTH=$3
7574         local RA_INC=1048576
7575         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
7576         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
7577                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
7578         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
7579                         get_named_value 'read but discarded' |
7580                         cut -d" " -f1 | calc_total)
7581         if [[ $DISCARD -gt $discard_limit ]]; then
7582                 $LCTL get_param llite.*.read_ahead_stats
7583                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
7584         else
7585                 echo "Read-ahead success for size ${READ_SIZE}"
7586         fi
7587 }
7588
7589 test_101b() {
7590         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7591         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
7592
7593         local STRIPE_SIZE=1048576
7594         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
7595
7596         if [ $SLOW == "yes" ]; then
7597                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
7598         else
7599                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
7600         fi
7601
7602         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
7603
7604         # prepare the read-ahead file
7605         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
7606         cancel_lru_locks osc
7607         for BIDX in 2 4 8 16 32 64 128 256
7608         do
7609                 local BSIZE=$((BIDX*4096))
7610                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
7611                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
7612                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
7613                 $LCTL set_param -n llite.*.read_ahead_stats 0
7614                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
7615                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
7616                 cancel_lru_locks osc
7617                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
7618         done
7619         cleanup_test101bc
7620         true
7621 }
7622 run_test 101b "check stride-io mode read-ahead ================="
7623
7624 test_101c() {
7625         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7626
7627         local STRIPE_SIZE=1048576
7628         local FILE_LENGTH=$((STRIPE_SIZE*100))
7629         local nreads=10000
7630         local osc_rpc_stats
7631
7632         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
7633
7634         cancel_lru_locks osc
7635         $LCTL set_param osc.*.rpc_stats 0
7636         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
7637         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
7638                 local stats=$($LCTL get_param -n $osc_rpc_stats)
7639                 local lines=$(echo "$stats" | awk 'END {print NR;}')
7640                 local size
7641
7642                 if [ $lines -le 20 ]; then
7643                         continue
7644                 fi
7645                 for size in 1 2 4 8; do
7646                         local rpc=$(echo "$stats" |
7647                                     awk '($1 == "'$size':") {print $2; exit; }')
7648                         [ $rpc != 0 ] &&
7649                                 error "Small $((size*4))k read IO $rpc !"
7650                 done
7651                 echo "$osc_rpc_stats check passed!"
7652         done
7653         cleanup_test101bc
7654         true
7655 }
7656 run_test 101c "check stripe_size aligned read-ahead ================="
7657
7658 set_read_ahead() {
7659         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
7660         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
7661 }
7662
7663 test_101d() {
7664         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7665
7666         local file=$DIR/$tfile
7667         local sz_MB=${FILESIZE_101d:-500}
7668         local ra_MB=${READAHEAD_MB:-40}
7669
7670         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
7671         [ $free_MB -lt $sz_MB ] &&
7672                 skip "Need free space ${sz_MB}M, have ${free_MB}M"
7673
7674         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
7675         $SETSTRIPE -c -1 $file || error "setstripe failed"
7676
7677         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
7678         echo Cancel LRU locks on lustre client to flush the client cache
7679         cancel_lru_locks osc
7680
7681         echo Disable read-ahead
7682         local old_READAHEAD=$(set_read_ahead 0)
7683
7684         echo Reading the test file $file with read-ahead disabled
7685         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
7686
7687         echo Cancel LRU locks on lustre client to flush the client cache
7688         cancel_lru_locks osc
7689         echo Enable read-ahead with ${ra_MB}MB
7690         set_read_ahead $ra_MB
7691
7692         echo Reading the test file $file with read-ahead enabled
7693         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
7694
7695         echo "read-ahead disabled time read $raOFF"
7696         echo "read-ahead enabled  time read $raON"
7697
7698         set_read_ahead $old_READAHEAD
7699         rm -f $file
7700         wait_delete_completed
7701
7702         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
7703                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
7704 }
7705 run_test 101d "file read with and without read-ahead enabled"
7706
7707 test_101e() {
7708         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7709
7710         local file=$DIR/$tfile
7711         local size_KB=500  #KB
7712         local count=100
7713         local bsize=1024
7714
7715         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
7716         local need_KB=$((count * size_KB))
7717         [[ $free_KB -le $need_KB ]] &&
7718                 skip_env "Need free space $need_KB, have $free_KB"
7719
7720         echo "Creating $count ${size_KB}K test files"
7721         for ((i = 0; i < $count; i++)); do
7722                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
7723         done
7724
7725         echo "Cancel LRU locks on lustre client to flush the client cache"
7726         cancel_lru_locks $OSC
7727
7728         echo "Reset readahead stats"
7729         $LCTL set_param -n llite.*.read_ahead_stats 0
7730
7731         for ((i = 0; i < $count; i++)); do
7732                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
7733         done
7734
7735         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
7736                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
7737
7738         for ((i = 0; i < $count; i++)); do
7739                 rm -rf $file.$i 2>/dev/null
7740         done
7741
7742         #10000 means 20% reads are missing in readahead
7743         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
7744 }
7745 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
7746
7747 test_101f() {
7748         which iozone || skip_env "no iozone installed"
7749
7750         local old_debug=$($LCTL get_param debug)
7751         old_debug=${old_debug#*=}
7752         $LCTL set_param debug="reada mmap"
7753
7754         # create a test file
7755         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
7756
7757         echo Cancel LRU locks on lustre client to flush the client cache
7758         cancel_lru_locks osc
7759
7760         echo Reset readahead stats
7761         $LCTL set_param -n llite.*.read_ahead_stats 0
7762
7763         echo mmap read the file with small block size
7764         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
7765                 > /dev/null 2>&1
7766
7767         echo checking missing pages
7768         $LCTL get_param llite.*.read_ahead_stats
7769         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
7770                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
7771
7772         $LCTL set_param debug="$old_debug"
7773         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
7774         rm -f $DIR/$tfile
7775 }
7776 run_test 101f "check mmap read performance"
7777
7778 test_101g_brw_size_test() {
7779         local mb=$1
7780         local pages=$((mb * 1048576 / $(page_size)))
7781         local file=$DIR/$tfile
7782
7783         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
7784                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
7785         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
7786                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
7787                         return 2
7788         done
7789
7790         stack_trap "rm -f $file" EXIT
7791         $LCTL set_param -n osc.*.rpc_stats=0
7792
7793         # 10 RPCs should be enough for the test
7794         local count=10
7795         dd if=/dev/zero of=$file bs=${mb}M count=$count ||
7796                 { error "dd write ${mb} MB blocks failed"; return 3; }
7797         cancel_lru_locks osc
7798         dd of=/dev/null if=$file bs=${mb}M count=$count ||
7799                 { error "dd write ${mb} MB blocks failed"; return 4; }
7800
7801         # calculate number of full-sized read and write RPCs
7802         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
7803                 sed -n '/pages per rpc/,/^$/p' |
7804                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
7805                 END { print reads,writes }'))
7806         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
7807                 return 5
7808         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
7809                 return 6
7810
7811         return 0
7812 }
7813
7814 test_101g() {
7815         remote_ost_nodsh && skip "remote OST with nodsh"
7816
7817         local rpcs
7818         local osts=$(get_facets OST)
7819         local list=$(comma_list $(osts_nodes))
7820         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
7821         local brw_size="obdfilter.*.brw_size"
7822         local ostver=$(lustre_version_code ost1)
7823         local cliver=$(lustre_version_code client)
7824
7825         $LFS setstripe -i 0 -c 1 $DIR/$tfile
7826
7827         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
7828         if [ $ostver -ge $(version_code 2.8.52) -o \
7829              \( $ostver -ge $(version_code 2.7.17) -a \
7830                 $ostver -lt $(version_code 2.7.50) \) ] &&
7831            [ $cliver -ge $(version_code 2.8.52) -o \
7832              \( $cliver -ge $(version_code 2.7.17) -a \
7833                 $cliver -lt $(version_code 2.7.50) \) ]; then
7834                 [ $ostver -ge $(version_code 2.9.52) ] && suffix="M"
7835                 if [[ $orig_mb -lt 16 ]]; then
7836                         save_lustre_params $osts "$brw_size" > $p
7837                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
7838                                 error "set 16MB RPC size failed"
7839
7840                         echo "remount client to enable new RPC size"
7841                         remount_client $MOUNT || error "remount_client failed"
7842                 fi
7843
7844                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
7845                 # should be able to set brw_size=12, but no rpc_stats for that
7846                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
7847         fi
7848
7849         test_101g_brw_size_test 4 || error "4MB RPC test failed"
7850
7851         if [[ $orig_mb -lt 16 ]]; then
7852                 restore_lustre_params < $p
7853                 remount_client $MOUNT || error "remount_client restore failed"
7854         fi
7855
7856         rm -f $p $DIR/$tfile
7857 }
7858 run_test 101g "Big bulk(4/16 MiB) readahead"
7859
7860 setup_test102() {
7861         test_mkdir $DIR/$tdir
7862         chown $RUNAS_ID $DIR/$tdir
7863         STRIPE_SIZE=65536
7864         STRIPE_OFFSET=1
7865         STRIPE_COUNT=$OSTCOUNT
7866         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
7867
7868         trap cleanup_test102 EXIT
7869         cd $DIR
7870         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
7871         cd $DIR/$tdir
7872         for num in 1 2 3 4; do
7873                 for count in $(seq 1 $STRIPE_COUNT); do
7874                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
7875                                 local size=`expr $STRIPE_SIZE \* $num`
7876                                 local file=file"$num-$idx-$count"
7877                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
7878                         done
7879                 done
7880         done
7881
7882         cd $DIR
7883         $1 tar cf $TMP/f102.tar $tdir --xattrs
7884 }
7885
7886 cleanup_test102() {
7887         trap 0
7888         rm -f $TMP/f102.tar
7889         rm -rf $DIR/d0.sanity/d102
7890 }
7891
7892 test_102a() {
7893         [ "$UID" != 0 ] && skip "must run as root"
7894         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
7895                 skip_env "must have user_xattr"
7896
7897         [ -z "$(which setfattr 2>/dev/null)" ] &&
7898                 skip_env "could not find setfattr"
7899
7900         local testfile=$DIR/$tfile
7901
7902         touch $testfile
7903         echo "set/get xattr..."
7904         setfattr -n trusted.name1 -v value1 $testfile ||
7905                 error "setfattr -n trusted.name1=value1 $testfile failed"
7906         getfattr -n trusted.name1 $testfile 2> /dev/null |
7907           grep "trusted.name1=.value1" ||
7908                 error "$testfile missing trusted.name1=value1"
7909
7910         setfattr -n user.author1 -v author1 $testfile ||
7911                 error "setfattr -n user.author1=author1 $testfile failed"
7912         getfattr -n user.author1 $testfile 2> /dev/null |
7913           grep "user.author1=.author1" ||
7914                 error "$testfile missing trusted.author1=author1"
7915
7916         echo "listxattr..."
7917         setfattr -n trusted.name2 -v value2 $testfile ||
7918                 error "$testfile unable to set trusted.name2"
7919         setfattr -n trusted.name3 -v value3 $testfile ||
7920                 error "$testfile unable to set trusted.name3"
7921         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
7922             grep "trusted.name" | wc -l) -eq 3 ] ||
7923                 error "$testfile missing 3 trusted.name xattrs"
7924
7925         setfattr -n user.author2 -v author2 $testfile ||
7926                 error "$testfile unable to set user.author2"
7927         setfattr -n user.author3 -v author3 $testfile ||
7928                 error "$testfile unable to set user.author3"
7929         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
7930             grep "user.author" | wc -l) -eq 3 ] ||
7931                 error "$testfile missing 3 user.author xattrs"
7932
7933         echo "remove xattr..."
7934         setfattr -x trusted.name1 $testfile ||
7935                 error "$testfile error deleting trusted.name1"
7936         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
7937                 error "$testfile did not delete trusted.name1 xattr"
7938
7939         setfattr -x user.author1 $testfile ||
7940                 error "$testfile error deleting user.author1"
7941         echo "set lustre special xattr ..."
7942         $LFS setstripe -c1 $testfile
7943         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
7944                 awk -F "=" '/trusted.lov/ { print $2 }' )
7945         setfattr -n "trusted.lov" -v $lovea $testfile ||
7946                 error "$testfile doesn't ignore setting trusted.lov again"
7947         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
7948                 error "$testfile allow setting invalid trusted.lov"
7949         rm -f $testfile
7950 }
7951 run_test 102a "user xattr test =================================="
7952
7953 test_102b() {
7954         [ -z "$(which setfattr 2>/dev/null)" ] &&
7955                 skip_env "could not find setfattr"
7956         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
7957
7958         # b10930: get/set/list trusted.lov xattr
7959         echo "get/set/list trusted.lov xattr ..."
7960         local testfile=$DIR/$tfile
7961         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7962                 error "setstripe failed"
7963         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
7964                 error "getstripe failed"
7965         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
7966                 error "can't get trusted.lov from $testfile"
7967
7968         local testfile2=${testfile}2
7969         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
7970                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
7971
7972         $MCREATE $testfile2
7973         setfattr -n trusted.lov -v $value $testfile2
7974         local stripe_size=$($GETSTRIPE -S $testfile2)
7975         local stripe_count=$($GETSTRIPE -c $testfile2)
7976         [[ $stripe_size -eq 65536 ]] ||
7977                 error "stripe size $stripe_size != 65536"
7978         [[ $stripe_count -eq $STRIPECOUNT ]] ||
7979                 error "stripe count $stripe_count != $STRIPECOUNT"
7980         rm -f $DIR/$tfile
7981 }
7982 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
7983
7984 test_102c() {
7985         [ -z "$(which setfattr 2>/dev/null)" ] &&
7986                 skip_env "could not find setfattr"
7987         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
7988
7989         # b10930: get/set/list lustre.lov xattr
7990         echo "get/set/list lustre.lov xattr ..."
7991         test_mkdir $DIR/$tdir
7992         chown $RUNAS_ID $DIR/$tdir
7993         local testfile=$DIR/$tdir/$tfile
7994         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7995                 error "setstripe failed"
7996         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
7997                 error "getstripe failed"
7998         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
7999         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
8000
8001         local testfile2=${testfile}2
8002         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
8003                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
8004
8005         $RUNAS $MCREATE $testfile2
8006         $RUNAS setfattr -n lustre.lov -v $value $testfile2
8007         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
8008         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
8009         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
8010         [ $stripe_count -eq $STRIPECOUNT ] ||
8011                 error "stripe count $stripe_count != $STRIPECOUNT"
8012 }
8013 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
8014
8015 compare_stripe_info1() {
8016         local stripe_index_all_zero=true
8017
8018         for num in 1 2 3 4; do
8019                 for count in $(seq 1 $STRIPE_COUNT); do
8020                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
8021                                 local size=$((STRIPE_SIZE * num))
8022                                 local file=file"$num-$offset-$count"
8023                                 stripe_size=$($LFS getstripe -S $PWD/$file)
8024                                 [[ $stripe_size -ne $size ]] &&
8025                                     error "$file: size $stripe_size != $size"
8026                                 stripe_count=$($LFS getstripe -c $PWD/$file)
8027                                 # allow fewer stripes to be created, ORI-601
8028                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
8029                                     error "$file: count $stripe_count != $count"
8030                                 stripe_index=$($LFS getstripe -i $PWD/$file)
8031                                 [[ $stripe_index -ne 0 ]] &&
8032                                         stripe_index_all_zero=false
8033                         done
8034                 done
8035         done
8036         $stripe_index_all_zero &&
8037                 error "all files are being extracted starting from OST index 0"
8038         return 0
8039 }
8040
8041 have_xattrs_include() {
8042         tar --help | grep -q xattrs-include &&
8043                 echo --xattrs-include="lustre.*"
8044 }
8045
8046 test_102d() {
8047         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8048         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
8049
8050         XINC=$(have_xattrs_include)
8051         setup_test102
8052         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
8053         cd $DIR/$tdir/$tdir
8054         compare_stripe_info1
8055 }
8056 run_test 102d "tar restore stripe info from tarfile,not keep osts"
8057
8058 test_102f() {
8059         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8060         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
8061
8062         XINC=$(have_xattrs_include)
8063         setup_test102
8064         test_mkdir $DIR/$tdir.restore
8065         cd $DIR
8066         tar cf - --xattrs $tdir | tar xf - \
8067                 -C $DIR/$tdir.restore --xattrs $XINC
8068         cd $DIR/$tdir.restore/$tdir
8069         compare_stripe_info1
8070 }
8071 run_test 102f "tar copy files, not keep osts"
8072
8073 grow_xattr() {
8074         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
8075                 skip "must have user_xattr"
8076         [ -z "$(which setfattr 2>/dev/null)" ] &&
8077                 skip_env "could not find setfattr"
8078         [ -z "$(which getfattr 2>/dev/null)" ] &&
8079                 skip_env "could not find getfattr"
8080
8081         local xsize=${1:-1024}  # in bytes
8082         local file=$DIR/$tfile
8083         local value="$(generate_string $xsize)"
8084         local xbig=trusted.big
8085
8086         touch $file
8087         log "save $xbig on $file"
8088         setfattr -n $xbig -v $value $file ||
8089                 error "saving $xbig on $file failed"
8090
8091         local orig=$(get_xattr_value $xbig $file)
8092         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
8093
8094         local xsml=trusted.sml
8095         log "save $xsml on $file"
8096         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
8097
8098         local new=$(get_xattr_value $xbig $file)
8099         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
8100
8101         log "grow $xsml on $file"
8102         setfattr -n $xsml -v "$value" $file ||
8103                 error "growing $xsml on $file failed"
8104
8105         new=$(get_xattr_value $xbig $file)
8106         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
8107         log "$xbig still valid after growing $xsml"
8108
8109         rm -f $file
8110 }
8111
8112 test_102h() { # bug 15777
8113         grow_xattr 1024
8114 }
8115 run_test 102h "grow xattr from inside inode to external block"
8116
8117 test_102ha() {
8118         large_xattr_enabled || skip_env "large_xattr disabled"
8119
8120         grow_xattr $(max_xattr_size)
8121 }
8122 run_test 102ha "grow xattr from inside inode to external inode"
8123
8124 test_102i() { # bug 17038
8125         [ -z "$(which getfattr 2>/dev/null)" ] &&
8126                 skip "could not find getfattr"
8127
8128         touch $DIR/$tfile
8129         ln -s $DIR/$tfile $DIR/${tfile}link
8130         getfattr -n trusted.lov $DIR/$tfile ||
8131                 error "lgetxattr on $DIR/$tfile failed"
8132         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
8133                 grep -i "no such attr" ||
8134                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
8135         rm -f $DIR/$tfile $DIR/${tfile}link
8136 }
8137 run_test 102i "lgetxattr test on symbolic link ============"
8138
8139 test_102j() {
8140         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8141         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
8142
8143         XINC=$(have_xattrs_include)
8144         setup_test102 "$RUNAS"
8145         chown $RUNAS_ID $DIR/$tdir
8146         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
8147         cd $DIR/$tdir/$tdir
8148         compare_stripe_info1 "$RUNAS"
8149 }
8150 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
8151
8152 test_102k() {
8153         [ -z "$(which setfattr 2>/dev/null)" ] &&
8154                 skip "could not find setfattr"
8155
8156         touch $DIR/$tfile
8157         # b22187 just check that does not crash for regular file.
8158         setfattr -n trusted.lov $DIR/$tfile
8159         # b22187 'setfattr -n trusted.lov' should remove LOV EA for directories
8160         local test_kdir=$DIR/$tdir
8161         test_mkdir $test_kdir
8162         local default_size=$($LFS getstripe -S $test_kdir)
8163         local default_count=$($LFS getstripe -c $test_kdir)
8164         local default_offset=$($LFS getstripe -i $test_kdir)
8165         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
8166                 error 'dir setstripe failed'
8167         setfattr -n trusted.lov $test_kdir
8168         local stripe_size=$($LFS getstripe -S $test_kdir)
8169         local stripe_count=$($LFS getstripe -c $test_kdir)
8170         local stripe_offset=$($LFS getstripe -i $test_kdir)
8171         [ $stripe_size -eq $default_size ] ||
8172                 error "stripe size $stripe_size != $default_size"
8173         [ $stripe_count -eq $default_count ] ||
8174                 error "stripe count $stripe_count != $default_count"
8175         [ $stripe_offset -eq $default_offset ] ||
8176                 error "stripe offset $stripe_offset != $default_offset"
8177         rm -rf $DIR/$tfile $test_kdir
8178 }
8179 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
8180
8181 test_102l() {
8182         [ -z "$(which getfattr 2>/dev/null)" ] &&
8183                 skip "could not find getfattr"
8184
8185         # LU-532 trusted. xattr is invisible to non-root
8186         local testfile=$DIR/$tfile
8187
8188         touch $testfile
8189
8190         echo "listxattr as user..."
8191         chown $RUNAS_ID $testfile
8192         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
8193             grep -q "trusted" &&
8194                 error "$testfile trusted xattrs are user visible"
8195
8196         return 0;
8197 }
8198 run_test 102l "listxattr size test =================================="
8199
8200 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
8201         local path=$DIR/$tfile
8202         touch $path
8203
8204         listxattr_size_check $path || error "listattr_size_check $path failed"
8205 }
8206 run_test 102m "Ensure listxattr fails on small bufffer ========"
8207
8208 cleanup_test102
8209
8210 getxattr() { # getxattr path name
8211         # Return the base64 encoding of the value of xattr name on path.
8212         local path=$1
8213         local name=$2
8214
8215         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
8216         # file: $path
8217         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
8218         #
8219         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
8220
8221         getfattr --absolute-names --encoding=base64 --name=$name $path |
8222                 awk -F= -v name=$name '$1 == name {
8223                         print substr($0, index($0, "=") + 1);
8224         }'
8225 }
8226
8227 test_102n() { # LU-4101 mdt: protect internal xattrs
8228         [ -z "$(which setfattr 2>/dev/null)" ] &&
8229                 skip "could not find setfattr"
8230         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
8231         then
8232                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
8233         fi
8234
8235         local file0=$DIR/$tfile.0
8236         local file1=$DIR/$tfile.1
8237         local xattr0=$TMP/$tfile.0
8238         local xattr1=$TMP/$tfile.1
8239         local namelist="lov lma lmv link fid version som hsm"
8240         local name
8241         local value
8242
8243         rm -rf $file0 $file1 $xattr0 $xattr1
8244         touch $file0 $file1
8245
8246         # Get 'before' xattrs of $file1.
8247         getfattr --absolute-names --dump --match=- $file1 > $xattr0
8248
8249         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
8250                 namelist+=" lfsck_namespace"
8251         for name in $namelist; do
8252                 # Try to copy xattr from $file0 to $file1.
8253                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
8254
8255                 setfattr --name=trusted.$name --value="$value" $file1 ||
8256                         error "setxattr 'trusted.$name' failed"
8257
8258                 # Try to set a garbage xattr.
8259                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
8260
8261                 if [[ x$name == "xlov" ]]; then
8262                         setfattr --name=trusted.lov --value="$value" $file1 &&
8263                         error "setxattr invalid 'trusted.lov' success"
8264                 else
8265                         setfattr --name=trusted.$name --value="$value" $file1 ||
8266                                 error "setxattr invalid 'trusted.$name' failed"
8267                 fi
8268
8269                 # Try to remove the xattr from $file1. We don't care if this
8270                 # appears to succeed or fail, we just don't want there to be
8271                 # any changes or crashes.
8272                 setfattr --remove=$trusted.$name $file1 2> /dev/null
8273         done
8274
8275         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
8276         then
8277                 name="lfsck_ns"
8278                 # Try to copy xattr from $file0 to $file1.
8279                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
8280
8281                 setfattr --name=trusted.$name --value="$value" $file1 ||
8282                         error "setxattr 'trusted.$name' failed"
8283
8284                 # Try to set a garbage xattr.
8285                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
8286
8287                 setfattr --name=trusted.$name --value="$value" $file1 ||
8288                         error "setxattr 'trusted.$name' failed"
8289
8290                 # Try to remove the xattr from $file1. We don't care if this
8291                 # appears to succeed or fail, we just don't want there to be
8292                 # any changes or crashes.
8293                 setfattr --remove=$trusted.$name $file1 2> /dev/null
8294         fi
8295
8296         # Get 'after' xattrs of file1.
8297         getfattr --absolute-names --dump --match=- $file1 > $xattr1
8298
8299         if ! diff $xattr0 $xattr1; then
8300                 error "before and after xattrs of '$file1' differ"
8301         fi
8302
8303         rm -rf $file0 $file1 $xattr0 $xattr1
8304
8305         return 0
8306 }
8307 run_test 102n "silently ignore setxattr on internal trusted xattrs"
8308
8309 test_102p() { # LU-4703 setxattr did not check ownership
8310         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
8311                 skip "MDS needs to be at least 2.5.56"
8312
8313         local testfile=$DIR/$tfile
8314
8315         touch $testfile
8316
8317         echo "setfacl as user..."
8318         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
8319         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
8320
8321         echo "setfattr as user..."
8322         setfacl -m "u:$RUNAS_ID:---" $testfile
8323         $RUNAS setfattr -x system.posix_acl_access $testfile
8324         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
8325 }
8326 run_test 102p "check setxattr(2) correctly fails without permission"
8327
8328 test_102q() {
8329         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
8330                 skip "MDS needs to be at least 2.6.92"
8331
8332         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
8333 }
8334 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
8335
8336 test_102r() {
8337         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
8338                 skip "MDS needs to be at least 2.6.93"
8339
8340         touch $DIR/$tfile || error "touch"
8341         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
8342         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
8343         rm $DIR/$tfile || error "rm"
8344
8345         #normal directory
8346         mkdir -p $DIR/$tdir || error "mkdir"
8347         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
8348         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
8349         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
8350                 error "$testfile error deleting user.author1"
8351         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
8352                 grep "user.$(basename $tdir)" &&
8353                 error "$tdir did not delete user.$(basename $tdir)"
8354         rmdir $DIR/$tdir || error "rmdir"
8355
8356         #striped directory
8357         test_mkdir $DIR/$tdir
8358         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
8359         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
8360         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
8361                 error "$testfile error deleting user.author1"
8362         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
8363                 grep "user.$(basename $tdir)" &&
8364                 error "$tdir did not delete user.$(basename $tdir)"
8365         rmdir $DIR/$tdir || error "rm striped dir"
8366 }
8367 run_test 102r "set EAs with empty values"
8368
8369 test_102s() {
8370         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.52) ] &&
8371                 skip "MDS needs to be at least 2.11.52"
8372
8373         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
8374
8375         save_lustre_params client "llite.*.xattr_cache" > $save
8376
8377         for cache in 0 1; do
8378                 lctl set_param llite.*.xattr_cache=$cache
8379
8380                 rm -f $DIR/$tfile
8381                 touch $DIR/$tfile || error "touch"
8382                 for prefix in lustre security system trusted user; do
8383                         # Note getxattr() may fail with 'Operation not
8384                         # supported' or 'No such attribute' depending
8385                         # on prefix and cache.
8386                         getfattr -n $prefix.n102s $DIR/$tfile &&
8387                                 error "getxattr '$prefix.n102s' should fail (cache = $cache)"
8388                 done
8389         done
8390
8391         restore_lustre_params < $save
8392 }
8393 run_test 102s "getting nonexistent xattrs should fail"
8394
8395 run_acl_subtest()
8396 {
8397     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
8398     return $?
8399 }
8400
8401 test_103a() {
8402         [ "$UID" != 0 ] && skip "must run as root"
8403         $GSS && skip_env "could not run under gss"
8404         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
8405                 skip_env "must have acl enabled"
8406         [ -z "$(which setfacl 2>/dev/null)" ] &&
8407                 skip_env "could not find setfacl"
8408         remote_mds_nodsh && skip "remote MDS with nodsh"
8409
8410         gpasswd -a daemon bin                           # LU-5641
8411         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
8412
8413         declare -a identity_old
8414
8415         for num in $(seq $MDSCOUNT); do
8416                 switch_identity $num true || identity_old[$num]=$?
8417         done
8418
8419         SAVE_UMASK=$(umask)
8420         umask 0022
8421         mkdir -p $DIR/$tdir
8422         cd $DIR/$tdir
8423
8424         echo "performing cp ..."
8425         run_acl_subtest cp || error "run_acl_subtest cp failed"
8426         echo "performing getfacl-noacl..."
8427         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
8428         echo "performing misc..."
8429         run_acl_subtest misc || error  "misc test failed"
8430         echo "performing permissions..."
8431         run_acl_subtest permissions || error "permissions failed"
8432         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
8433         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
8434              \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
8435              $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
8436         then
8437                 echo "performing permissions xattr..."
8438                 run_acl_subtest permissions_xattr ||
8439                         error "permissions_xattr failed"
8440         fi
8441         echo "performing setfacl..."
8442         run_acl_subtest setfacl || error  "setfacl test failed"
8443
8444         # inheritance test got from HP
8445         echo "performing inheritance..."
8446         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
8447         chmod +x make-tree || error "chmod +x failed"
8448         run_acl_subtest inheritance || error "inheritance test failed"
8449         rm -f make-tree
8450
8451         echo "LU-974 ignore umask when acl is enabled..."
8452         run_acl_subtest 974 || error "LU-974 umask test failed"
8453         if [ $MDSCOUNT -ge 2 ]; then
8454                 run_acl_subtest 974_remote ||
8455                         error "LU-974 umask test failed under remote dir"
8456         fi
8457
8458         echo "LU-2561 newly created file is same size as directory..."
8459         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
8460                 run_acl_subtest 2561 || error "LU-2561 test failed"
8461         else
8462                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
8463         fi
8464
8465         run_acl_subtest 4924 || error "LU-4924 test failed"
8466
8467         cd $SAVE_PWD
8468         umask $SAVE_UMASK
8469
8470         for num in $(seq $MDSCOUNT); do
8471                 if [ "${identity_old[$num]}" = 1 ]; then
8472                         switch_identity $num false || identity_old[$num]=$?
8473                 fi
8474         done
8475 }
8476 run_test 103a "acl test"
8477
8478 test_103b() {
8479         local U
8480
8481         for U in {0..511}; do
8482                 {
8483                 local O=$(printf "%04o" $U)
8484
8485                 umask $(printf "%04o" $((511 ^ $O)))
8486                 $LFS setstripe -c 1 $DIR/$tfile.s$O
8487                 local S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.s$O))
8488
8489                 (( $S == ($O & 0666) )) ||
8490                         error "lfs setstripe $DIR/$tfile.s$O '$S' != '$O'"
8491
8492                 $LFS setstripe -E16M -c 1 -E1G -S4M $DIR/$tfile.p$O
8493                 S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.p$O))
8494                 (( $S == ($O & 0666) )) ||
8495                         error "lfs setstripe -E $DIR/$tfile.p$O '$S' != '$O'"
8496
8497                 $LFS setstripe -N2 -c 1 $DIR/$tfile.m$O
8498                 S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.m$O))
8499                 (( $S == ($O & 0666) )) ||
8500                         error "lfs setstripe -N2 $DIR/$tfile.m$O '$S' != '$O'"
8501                 rm -f $DIR/$tfile.[smp]$0
8502                 } &
8503         done
8504         wait
8505 }
8506 run_test 103b "umask lfs setstripe"
8507
8508 test_103c() {
8509         mkdir -p $DIR/$tdir
8510         cp -rp $DIR/$tdir $DIR/$tdir.bak
8511
8512         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
8513                 error "$DIR/$tdir shouldn't contain default ACL"
8514         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
8515                 error "$DIR/$tdir.bak shouldn't contain default ACL"
8516         true
8517 }
8518 run_test 103c "'cp -rp' won't set empty acl"
8519
8520 test_104a() {
8521         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8522
8523         touch $DIR/$tfile
8524         lfs df || error "lfs df failed"
8525         lfs df -ih || error "lfs df -ih failed"
8526         lfs df -h $DIR || error "lfs df -h $DIR failed"
8527         lfs df -i $DIR || error "lfs df -i $DIR failed"
8528         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
8529         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
8530
8531         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
8532         lctl --device %$OSC deactivate
8533         lfs df || error "lfs df with deactivated OSC failed"
8534         lctl --device %$OSC activate
8535         # wait the osc back to normal
8536         wait_osc_import_state client ost FULL
8537
8538         lfs df || error "lfs df with reactivated OSC failed"
8539         rm -f $DIR/$tfile
8540 }
8541 run_test 104a "lfs df [-ih] [path] test ========================="
8542
8543 test_104b() {
8544         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8545         [ $RUNAS_ID -eq $UID ] &&
8546                 skip_env "RUNAS_ID = UID = $UID -- skipping"
8547
8548         chmod 666 /dev/obd
8549         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
8550                         grep "Permission denied" | wc -l)))
8551         if [ $denied_cnt -ne 0 ]; then
8552                 error "lfs check servers test failed"
8553         fi
8554 }
8555 run_test 104b "$RUNAS lfs check servers test ===================="
8556
8557 test_105a() {
8558         # doesn't work on 2.4 kernels
8559         touch $DIR/$tfile
8560         if $(flock_is_enabled); then
8561                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
8562         else
8563                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
8564         fi
8565         rm -f $DIR/$tfile
8566 }
8567 run_test 105a "flock when mounted without -o flock test ========"
8568
8569 test_105b() {
8570         touch $DIR/$tfile
8571         if $(flock_is_enabled); then
8572                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
8573         else
8574                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
8575         fi
8576         rm -f $DIR/$tfile
8577 }
8578 run_test 105b "fcntl when mounted without -o flock test ========"
8579
8580 test_105c() {
8581         touch $DIR/$tfile
8582         if $(flock_is_enabled); then
8583                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
8584         else
8585                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
8586         fi
8587         rm -f $DIR/$tfile
8588 }
8589 run_test 105c "lockf when mounted without -o flock test"
8590
8591 test_105d() { # bug 15924
8592         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8593
8594         test_mkdir $DIR/$tdir
8595         flock_is_enabled || skip_env "mount w/o flock enabled"
8596         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
8597         $LCTL set_param fail_loc=0x80000315
8598         flocks_test 2 $DIR/$tdir
8599 }
8600 run_test 105d "flock race (should not freeze) ========"
8601
8602 test_105e() { # bug 22660 && 22040
8603         flock_is_enabled || skip_env "mount w/o flock enabled"
8604
8605         touch $DIR/$tfile
8606         flocks_test 3 $DIR/$tfile
8607 }
8608 run_test 105e "Two conflicting flocks from same process"
8609
8610 test_106() { #bug 10921
8611         test_mkdir $DIR/$tdir
8612         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
8613         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
8614 }
8615 run_test 106 "attempt exec of dir followed by chown of that dir"
8616
8617 test_107() {
8618         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8619
8620         CDIR=`pwd`
8621         local file=core
8622
8623         cd $DIR
8624         rm -f $file
8625
8626         local save_pattern=$(sysctl -n kernel.core_pattern)
8627         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
8628         sysctl -w kernel.core_pattern=$file
8629         sysctl -w kernel.core_uses_pid=0
8630
8631         ulimit -c unlimited
8632         sleep 60 &
8633         SLEEPPID=$!
8634
8635         sleep 1
8636
8637         kill -s 11 $SLEEPPID
8638         wait $SLEEPPID
8639         if [ -e $file ]; then
8640                 size=`stat -c%s $file`
8641                 [ $size -eq 0 ] && error "Fail to create core file $file"
8642         else
8643                 error "Fail to create core file $file"
8644         fi
8645         rm -f $file
8646         sysctl -w kernel.core_pattern=$save_pattern
8647         sysctl -w kernel.core_uses_pid=$save_uses_pid
8648         cd $CDIR
8649 }
8650 run_test 107 "Coredump on SIG"
8651
8652 test_110() {
8653         test_mkdir $DIR/$tdir
8654         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255)
8655         $LFS mkdir -c $MDSCOUNT $DIR/$tdir/$(str_repeat 'b' 256) &&
8656                 error "mkdir with 256 char should fail, but did not"
8657         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
8658                 error "create with 255 char failed"
8659         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
8660                 error "create with 256 char should fail, but did not"
8661
8662         ls -l $DIR/$tdir
8663         rm -rf $DIR/$tdir
8664 }
8665 run_test 110 "filename length checking"
8666
8667 #
8668 # Purpose: To verify dynamic thread (OSS) creation.
8669 #
8670 test_115() {
8671         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8672         remote_ost_nodsh && skip "remote OST with nodsh"
8673
8674         # Lustre does not stop service threads once they are started.
8675         # Reset number of running threads to default.
8676         stopall
8677         setupall
8678
8679         local OSTIO_pre
8680         local save_params="$TMP/sanity-$TESTNAME.parameters"
8681
8682         # Get ll_ost_io count before I/O
8683         OSTIO_pre=$(do_facet ost1 \
8684                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
8685         # Exit if lustre is not running (ll_ost_io not running).
8686         [ -z "$OSTIO_pre" ] && error "no OSS threads"
8687
8688         echo "Starting with $OSTIO_pre threads"
8689         local thread_max=$((OSTIO_pre * 2))
8690         local rpc_in_flight=$((thread_max * 2))
8691         # Number of I/O Process proposed to be started.
8692         local nfiles
8693         local facets=$(get_facets OST)
8694
8695         save_lustre_params client "osc.*OST*.max_rpcs_in_flight" > $save_params
8696         save_lustre_params $facets "ost.OSS.ost_io.threads_max" >> $save_params
8697
8698         # Set in_flight to $rpc_in_flight
8699         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
8700                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
8701         nfiles=${rpc_in_flight}
8702         # Set ost thread_max to $thread_max
8703         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
8704
8705         # 5 Minutes should be sufficient for max number of OSS
8706         # threads(thread_max) to be created.
8707         local timeout=300
8708
8709         # Start I/O.
8710         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
8711         test_mkdir $DIR/$tdir
8712         for i in $(seq $nfiles); do
8713                 local file=$DIR/$tdir/${tfile}-$i
8714                 $LFS setstripe -c -1 -i 0 $file
8715                 ($WTL $file $timeout)&
8716         done
8717
8718         # I/O Started - Wait for thread_started to reach thread_max or report
8719         # error if thread_started is more than thread_max.
8720         echo "Waiting for thread_started to reach thread_max"
8721         local thread_started=0
8722         local end_time=$((SECONDS + timeout))
8723
8724         while [ $SECONDS -le $end_time ] ; do
8725                 echo -n "."
8726                 # Get ost i/o thread_started count.
8727                 thread_started=$(do_facet ost1 \
8728                         "$LCTL get_param \
8729                         ost.OSS.ost_io.threads_started | cut -d= -f2")
8730                 # Break out if thread_started is equal/greater than thread_max
8731                 if [[ $thread_started -ge $thread_max ]]; then
8732                         echo ll_ost_io thread_started $thread_started, \
8733                                 equal/greater than thread_max $thread_max
8734                         break
8735                 fi
8736                 sleep 1
8737         done
8738
8739         # Cleanup - We have the numbers, Kill i/o jobs if running.
8740         jobcount=($(jobs -p))
8741         for i in $(seq 0 $((${#jobcount[@]}-1)))
8742         do
8743                 kill -9 ${jobcount[$i]}
8744                 if [ $? -ne 0 ] ; then
8745                         echo Warning: \
8746                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
8747                 fi
8748         done
8749
8750         # Cleanup files left by WTL binary.
8751         for i in $(seq $nfiles); do
8752                 local file=$DIR/$tdir/${tfile}-$i
8753                 rm -rf $file
8754                 if [ $? -ne 0 ] ; then
8755                         echo "Warning: Failed to delete file $file"
8756                 fi
8757         done
8758
8759         restore_lustre_params <$save_params
8760         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
8761
8762         # Error out if no new thread has started or Thread started is greater
8763         # than thread max.
8764         if [[ $thread_started -le $OSTIO_pre ||
8765                         $thread_started -gt $thread_max ]]; then
8766                 error "ll_ost_io: thread_started $thread_started" \
8767                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
8768                       "No new thread started or thread started greater " \
8769                       "than thread_max."
8770         fi
8771 }
8772 run_test 115 "verify dynamic thread creation===================="
8773
8774 free_min_max () {
8775         wait_delete_completed
8776         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8777         echo "OST kbytes available: ${AVAIL[@]}"
8778         MAXV=${AVAIL[0]}
8779         MAXI=0
8780         MINV=${AVAIL[0]}
8781         MINI=0
8782         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8783                 #echo OST $i: ${AVAIL[i]}kb
8784                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8785                         MAXV=${AVAIL[i]}
8786                         MAXI=$i
8787                 fi
8788                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8789                         MINV=${AVAIL[i]}
8790                         MINI=$i
8791                 fi
8792         done
8793         echo "Min free space: OST $MINI: $MINV"
8794         echo "Max free space: OST $MAXI: $MAXV"
8795 }
8796
8797 test_116a() { # was previously test_116()
8798         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8799         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
8800         remote_mds_nodsh && skip "remote MDS with nodsh"
8801
8802         echo -n "Free space priority "
8803         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
8804                 head -n1
8805         declare -a AVAIL
8806         free_min_max
8807
8808         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip"
8809         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip"
8810         trap simple_cleanup_common EXIT
8811
8812         # Check if we need to generate uneven OSTs
8813         test_mkdir -p $DIR/$tdir/OST${MINI}
8814         local FILL=$((MINV / 4))
8815         local DIFF=$((MAXV - MINV))
8816         local DIFF2=$((DIFF * 100 / MINV))
8817
8818         local threshold=$(do_facet $SINGLEMDS \
8819                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
8820         threshold=${threshold%%%}
8821         echo -n "Check for uneven OSTs: "
8822         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
8823
8824         if [[ $DIFF2 -gt $threshold ]]; then
8825                 echo "ok"
8826                 echo "Don't need to fill OST$MINI"
8827         else
8828                 # generate uneven OSTs. Write 2% over the QOS threshold value
8829                 echo "no"
8830                 DIFF=$((threshold - DIFF2 + 2))
8831                 DIFF2=$((MINV * DIFF / 100))
8832                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
8833                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
8834                         error "setstripe failed"
8835                 DIFF=$((DIFF2 / 2048))
8836                 i=0
8837                 while [ $i -lt $DIFF ]; do
8838                         i=$((i + 1))
8839                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
8840                                 bs=2M count=1 2>/dev/null
8841                         echo -n .
8842                 done
8843                 echo .
8844                 sync
8845                 sleep_maxage
8846                 free_min_max
8847         fi
8848
8849         DIFF=$((MAXV - MINV))
8850         DIFF2=$((DIFF * 100 / MINV))
8851         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
8852         if [ $DIFF2 -gt $threshold ]; then
8853                 echo "ok"
8854         else
8855                 echo "failed - QOS mode won't be used"
8856                 simple_cleanup_common
8857                 skip "QOS imbalance criteria not met"
8858         fi
8859
8860         MINI1=$MINI
8861         MINV1=$MINV
8862         MAXI1=$MAXI
8863         MAXV1=$MAXV
8864
8865         # now fill using QOS
8866         $SETSTRIPE -c 1 $DIR/$tdir
8867         FILL=$((FILL / 200))
8868         if [ $FILL -gt 600 ]; then
8869                 FILL=600
8870         fi
8871         echo "writing $FILL files to QOS-assigned OSTs"
8872         i=0
8873         while [ $i -lt $FILL ]; do
8874                 i=$((i + 1))
8875                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
8876                         count=1 2>/dev/null
8877                 echo -n .
8878         done
8879         echo "wrote $i 200k files"
8880         sync
8881         sleep_maxage
8882
8883         echo "Note: free space may not be updated, so measurements might be off"
8884         free_min_max
8885         DIFF2=$((MAXV - MINV))
8886         echo "free space delta: orig $DIFF final $DIFF2"
8887         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
8888         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
8889         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
8890         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
8891         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
8892         if [[ $DIFF -gt 0 ]]; then
8893                 FILL=$((DIFF2 * 100 / DIFF - 100))
8894                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
8895         fi
8896
8897         # Figure out which files were written where
8898         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8899                awk '/'$MINI1': / {print $2; exit}')
8900         echo $UUID
8901         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8902         echo "$MINC files created on smaller OST $MINI1"
8903         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8904                awk '/'$MAXI1': / {print $2; exit}')
8905         echo $UUID
8906         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8907         echo "$MAXC files created on larger OST $MAXI1"
8908         if [[ $MINC -gt 0 ]]; then
8909                 FILL=$((MAXC * 100 / MINC - 100))
8910                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
8911         fi
8912         [[ $MAXC -gt $MINC ]] ||
8913                 error_ignore LU-9 "stripe QOS didn't balance free space"
8914         simple_cleanup_common
8915 }
8916 run_test 116a "stripe QOS: free space balance ==================="
8917
8918 test_116b() { # LU-2093
8919         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8920         remote_mds_nodsh && skip "remote MDS with nodsh"
8921
8922 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
8923         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
8924                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
8925         [ -z "$old_rr" ] && skip "no QOS"
8926         do_facet $SINGLEMDS lctl set_param \
8927                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
8928         mkdir -p $DIR/$tdir
8929         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
8930         createmany -o $DIR/$tdir/f- 20 || error "can't create"
8931         do_facet $SINGLEMDS lctl set_param fail_loc=0
8932         rm -rf $DIR/$tdir
8933         do_facet $SINGLEMDS lctl set_param \
8934                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
8935 }
8936 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
8937
8938 test_117() # bug 10891
8939 {
8940         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8941
8942         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
8943         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
8944         lctl set_param fail_loc=0x21e
8945         > $DIR/$tfile || error "truncate failed"
8946         lctl set_param fail_loc=0
8947         echo "Truncate succeeded."
8948         rm -f $DIR/$tfile
8949 }
8950 run_test 117 "verify osd extend =========="
8951
8952 NO_SLOW_RESENDCOUNT=4
8953 export OLD_RESENDCOUNT=""
8954 set_resend_count () {
8955         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
8956         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
8957         lctl set_param -n $PROC_RESENDCOUNT $1
8958         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
8959 }
8960
8961 # for reduce test_118* time (b=14842)
8962 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8963
8964 # Reset async IO behavior after error case
8965 reset_async() {
8966         FILE=$DIR/reset_async
8967
8968         # Ensure all OSCs are cleared
8969         $SETSTRIPE -c -1 $FILE
8970         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
8971         sync
8972         rm $FILE
8973 }
8974
8975 test_118a() #bug 11710
8976 {
8977         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8978
8979         reset_async
8980
8981         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8982         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8983         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8984
8985         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8986                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8987                 return 1;
8988         fi
8989         rm -f $DIR/$tfile
8990 }
8991 run_test 118a "verify O_SYNC works =========="
8992
8993 test_118b()
8994 {
8995         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8996         remote_ost_nodsh && skip "remote OST with nodsh"
8997
8998         reset_async
8999
9000         #define OBD_FAIL_SRV_ENOENT 0x217
9001         set_nodes_failloc "$(osts_nodes)" 0x217
9002         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
9003         RC=$?
9004         set_nodes_failloc "$(osts_nodes)" 0
9005         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9006         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
9007                     grep -c writeback)
9008
9009         if [[ $RC -eq 0 ]]; then
9010                 error "Must return error due to dropped pages, rc=$RC"
9011                 return 1;
9012         fi
9013
9014         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9015                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9016                 return 1;
9017         fi
9018
9019         echo "Dirty pages not leaked on ENOENT"
9020
9021         # Due to the above error the OSC will issue all RPCs syncronously
9022         # until a subsequent RPC completes successfully without error.
9023         $MULTIOP $DIR/$tfile Ow4096yc
9024         rm -f $DIR/$tfile
9025
9026         return 0
9027 }
9028 run_test 118b "Reclaim dirty pages on fatal error =========="
9029
9030 test_118c()
9031 {
9032         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9033
9034         # for 118c, restore the original resend count, LU-1940
9035         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
9036                                 set_resend_count $OLD_RESENDCOUNT
9037         remote_ost_nodsh && skip "remote OST with nodsh"
9038
9039         reset_async
9040
9041         #define OBD_FAIL_OST_EROFS               0x216
9042         set_nodes_failloc "$(osts_nodes)" 0x216
9043
9044         # multiop should block due to fsync until pages are written
9045         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
9046         MULTIPID=$!
9047         sleep 1
9048
9049         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
9050                 error "Multiop failed to block on fsync, pid=$MULTIPID"
9051         fi
9052
9053         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
9054                     grep -c writeback)
9055         if [[ $WRITEBACK -eq 0 ]]; then
9056                 error "No page in writeback, writeback=$WRITEBACK"
9057         fi
9058
9059         set_nodes_failloc "$(osts_nodes)" 0
9060         wait $MULTIPID
9061         RC=$?
9062         if [[ $RC -ne 0 ]]; then
9063                 error "Multiop fsync failed, rc=$RC"
9064         fi
9065
9066         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9067         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
9068                     grep -c writeback)
9069         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9070                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9071         fi
9072
9073         rm -f $DIR/$tfile
9074         echo "Dirty pages flushed via fsync on EROFS"
9075         return 0
9076 }
9077 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
9078
9079 # continue to use small resend count to reduce test_118* time (b=14842)
9080 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
9081
9082 test_118d()
9083 {
9084         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9085         remote_ost_nodsh && skip "remote OST with nodsh"
9086
9087         reset_async
9088
9089         #define OBD_FAIL_OST_BRW_PAUSE_BULK
9090         set_nodes_failloc "$(osts_nodes)" 0x214
9091         # multiop should block due to fsync until pages are written
9092         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
9093         MULTIPID=$!
9094         sleep 1
9095
9096         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
9097                 error "Multiop failed to block on fsync, pid=$MULTIPID"
9098         fi
9099
9100         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
9101                     grep -c writeback)
9102         if [[ $WRITEBACK -eq 0 ]]; then
9103                 error "No page in writeback, writeback=$WRITEBACK"
9104         fi
9105
9106         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
9107         set_nodes_failloc "$(osts_nodes)" 0
9108
9109         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9110         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
9111                     grep -c writeback)
9112         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9113                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9114         fi
9115
9116         rm -f $DIR/$tfile
9117         echo "Dirty pages gaurenteed flushed via fsync"
9118         return 0
9119 }
9120 run_test 118d "Fsync validation inject a delay of the bulk =========="
9121
9122 test_118f() {
9123         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9124
9125         reset_async
9126
9127         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
9128         lctl set_param fail_loc=0x8000040a
9129
9130         # Should simulate EINVAL error which is fatal
9131         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
9132         RC=$?
9133         if [[ $RC -eq 0 ]]; then
9134                 error "Must return error due to dropped pages, rc=$RC"
9135         fi
9136
9137         lctl set_param fail_loc=0x0
9138
9139         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
9140         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9141         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
9142                     grep -c writeback)
9143         if [[ $LOCKED -ne 0 ]]; then
9144                 error "Locked pages remain in cache, locked=$LOCKED"
9145         fi
9146
9147         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9148                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9149         fi
9150
9151         rm -f $DIR/$tfile
9152         echo "No pages locked after fsync"
9153
9154         reset_async
9155         return 0
9156 }
9157 run_test 118f "Simulate unrecoverable OSC side error =========="
9158
9159 test_118g() {
9160         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9161
9162         reset_async
9163
9164         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
9165         lctl set_param fail_loc=0x406
9166
9167         # simulate local -ENOMEM
9168         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
9169         RC=$?
9170
9171         lctl set_param fail_loc=0
9172         if [[ $RC -eq 0 ]]; then
9173                 error "Must return error due to dropped pages, rc=$RC"
9174         fi
9175
9176         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
9177         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9178         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
9179                         grep -c writeback)
9180         if [[ $LOCKED -ne 0 ]]; then
9181                 error "Locked pages remain in cache, locked=$LOCKED"
9182         fi
9183
9184         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9185                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9186         fi
9187
9188         rm -f $DIR/$tfile
9189         echo "No pages locked after fsync"
9190
9191         reset_async
9192         return 0
9193 }
9194 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
9195
9196 test_118h() {
9197         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9198         remote_ost_nodsh && skip "remote OST with nodsh"
9199
9200         reset_async
9201
9202         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
9203         set_nodes_failloc "$(osts_nodes)" 0x20e
9204         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
9205         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
9206         RC=$?
9207
9208         set_nodes_failloc "$(osts_nodes)" 0
9209         if [[ $RC -eq 0 ]]; then
9210                 error "Must return error due to dropped pages, rc=$RC"
9211         fi
9212
9213         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
9214         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9215         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
9216                     grep -c writeback)
9217         if [[ $LOCKED -ne 0 ]]; then
9218                 error "Locked pages remain in cache, locked=$LOCKED"
9219         fi
9220
9221         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9222                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9223         fi
9224
9225         rm -f $DIR/$tfile
9226         echo "No pages locked after fsync"
9227
9228         return 0
9229 }
9230 run_test 118h "Verify timeout in handling recoverables errors  =========="
9231
9232 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
9233
9234 test_118i() {
9235         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9236         remote_ost_nodsh && skip "remote OST with nodsh"
9237
9238         reset_async
9239
9240         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
9241         set_nodes_failloc "$(osts_nodes)" 0x20e
9242
9243         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
9244         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
9245         PID=$!
9246         sleep 5
9247         set_nodes_failloc "$(osts_nodes)" 0
9248
9249         wait $PID
9250         RC=$?
9251         if [[ $RC -ne 0 ]]; then
9252                 error "got error, but should be not, rc=$RC"
9253         fi
9254
9255         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
9256         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9257         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
9258         if [[ $LOCKED -ne 0 ]]; then
9259                 error "Locked pages remain in cache, locked=$LOCKED"
9260         fi
9261
9262         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9263                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9264         fi
9265
9266         rm -f $DIR/$tfile
9267         echo "No pages locked after fsync"
9268
9269         return 0
9270 }
9271 run_test 118i "Fix error before timeout in recoverable error  =========="
9272
9273 [ "$SLOW" = "no" ] && set_resend_count 4
9274
9275 test_118j() {
9276         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9277         remote_ost_nodsh && skip "remote OST with nodsh"
9278
9279         reset_async
9280
9281         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
9282         set_nodes_failloc "$(osts_nodes)" 0x220
9283
9284         # return -EIO from OST
9285         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
9286         RC=$?
9287         set_nodes_failloc "$(osts_nodes)" 0x0
9288         if [[ $RC -eq 0 ]]; then
9289                 error "Must return error due to dropped pages, rc=$RC"
9290         fi
9291
9292         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
9293         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9294         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
9295         if [[ $LOCKED -ne 0 ]]; then
9296                 error "Locked pages remain in cache, locked=$LOCKED"
9297         fi
9298
9299         # in recoverable error on OST we want resend and stay until it finished
9300         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9301                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9302         fi
9303
9304         rm -f $DIR/$tfile
9305         echo "No pages locked after fsync"
9306
9307         return 0
9308 }
9309 run_test 118j "Simulate unrecoverable OST side error =========="
9310
9311 test_118k()
9312 {
9313         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9314         remote_ost_nodsh && skip "remote OSTs with nodsh"
9315
9316         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
9317         set_nodes_failloc "$(osts_nodes)" 0x20e
9318         test_mkdir $DIR/$tdir
9319
9320         for ((i=0;i<10;i++)); do
9321                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
9322                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
9323                 SLEEPPID=$!
9324                 sleep 0.500s
9325                 kill $SLEEPPID
9326                 wait $SLEEPPID
9327         done
9328
9329         set_nodes_failloc "$(osts_nodes)" 0
9330         rm -rf $DIR/$tdir
9331 }
9332 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
9333
9334 test_118l() # LU-646
9335 {
9336         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9337
9338         test_mkdir $DIR/$tdir
9339         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
9340         rm -rf $DIR/$tdir
9341 }
9342 run_test 118l "fsync dir"
9343
9344 test_118m() # LU-3066
9345 {
9346         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9347
9348         test_mkdir $DIR/$tdir
9349         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
9350         rm -rf $DIR/$tdir
9351 }
9352 run_test 118m "fdatasync dir ========="
9353
9354 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
9355
9356 test_118n()
9357 {
9358         local begin
9359         local end
9360
9361         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9362         remote_ost_nodsh && skip "remote OSTs with nodsh"
9363
9364         # Sleep to avoid a cached response.
9365         #define OBD_STATFS_CACHE_SECONDS 1
9366         sleep 2
9367
9368         # Inject a 10 second delay in the OST_STATFS handler.
9369         #define OBD_FAIL_OST_STATFS_DELAY 0x242
9370         set_nodes_failloc "$(osts_nodes)" 0x242
9371
9372         begin=$SECONDS
9373         stat --file-system $MOUNT > /dev/null
9374         end=$SECONDS
9375
9376         set_nodes_failloc "$(osts_nodes)" 0
9377
9378         if ((end - begin > 20)); then
9379             error "statfs took $((end - begin)) seconds, expected 10"
9380         fi
9381 }
9382 run_test 118n "statfs() sends OST_STATFS requests in parallel"
9383
9384 test_119a() # bug 11737
9385 {
9386         BSIZE=$((512 * 1024))
9387         directio write $DIR/$tfile 0 1 $BSIZE
9388         # We ask to read two blocks, which is more than a file size.
9389         # directio will indicate an error when requested and actual
9390         # sizes aren't equeal (a normal situation in this case) and
9391         # print actual read amount.
9392         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
9393         if [ "$NOB" != "$BSIZE" ]; then
9394                 error "read $NOB bytes instead of $BSIZE"
9395         fi
9396         rm -f $DIR/$tfile
9397 }
9398 run_test 119a "Short directIO read must return actual read amount"
9399
9400 test_119b() # bug 11737
9401 {
9402         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9403
9404         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
9405         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
9406         sync
9407         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) ||
9408                 error "direct read failed"
9409         rm -f $DIR/$tfile
9410 }
9411 run_test 119b "Sparse directIO read must return actual read amount"
9412
9413 test_119c() # bug 13099
9414 {
9415         BSIZE=1048576
9416         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
9417         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
9418         rm -f $DIR/$tfile
9419 }
9420 run_test 119c "Testing for direct read hitting hole"
9421
9422 test_119d() # bug 15950
9423 {
9424         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9425
9426         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
9427         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
9428         BSIZE=1048576
9429         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
9430         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
9431         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
9432         lctl set_param fail_loc=0x40d
9433         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
9434         pid_dio=$!
9435         sleep 1
9436         cat $DIR/$tfile > /dev/null &
9437         lctl set_param fail_loc=0
9438         pid_reads=$!
9439         wait $pid_dio
9440         log "the DIO writes have completed, now wait for the reads (should not block very long)"
9441         sleep 2
9442         [ -n "`ps h -p $pid_reads -o comm`" ] && \
9443         error "the read rpcs have not completed in 2s"
9444         rm -f $DIR/$tfile
9445         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
9446 }
9447 run_test 119d "The DIO path should try to send a new rpc once one is completed"
9448
9449 test_120a() {
9450         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9451         remote_mds_nodsh && skip "remote MDS with nodsh"
9452         test_mkdir $DIR/$tdir
9453         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9454                 skip_env "no early lock cancel on server"
9455
9456         lru_resize_disable mdc
9457         lru_resize_disable osc
9458         cancel_lru_locks mdc
9459         # asynchronous object destroy at MDT could cause bl ast to client
9460         cancel_lru_locks osc
9461
9462         stat $DIR/$tdir > /dev/null
9463         can1=$(do_facet $SINGLEMDS \
9464                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9465                awk '/ldlm_cancel/ {print $2}')
9466         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9467                awk '/ldlm_bl_callback/ {print $2}')
9468         test_mkdir -c1 $DIR/$tdir/d1
9469         can2=$(do_facet $SINGLEMDS \
9470                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9471                awk '/ldlm_cancel/ {print $2}')
9472         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9473                awk '/ldlm_bl_callback/ {print $2}')
9474         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9475         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9476         lru_resize_enable mdc
9477         lru_resize_enable osc
9478 }
9479 run_test 120a "Early Lock Cancel: mkdir test"
9480
9481 test_120b() {
9482         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9483         remote_mds_nodsh && skip "remote MDS with nodsh"
9484         test_mkdir $DIR/$tdir
9485         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9486                 skip_env "no early lock cancel on server"
9487
9488         lru_resize_disable mdc
9489         lru_resize_disable osc
9490         cancel_lru_locks mdc
9491         stat $DIR/$tdir > /dev/null
9492         can1=$(do_facet $SINGLEMDS \
9493                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9494                awk '/ldlm_cancel/ {print $2}')
9495         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9496                awk '/ldlm_bl_callback/ {print $2}')
9497         touch $DIR/$tdir/f1
9498         can2=$(do_facet $SINGLEMDS \
9499                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9500                awk '/ldlm_cancel/ {print $2}')
9501         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9502                awk '/ldlm_bl_callback/ {print $2}')
9503         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9504         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9505         lru_resize_enable mdc
9506         lru_resize_enable osc
9507 }
9508 run_test 120b "Early Lock Cancel: create test"
9509
9510 test_120c() {
9511         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9512         remote_mds_nodsh && skip "remote MDS with nodsh"
9513         test_mkdir -c1 $DIR/$tdir
9514         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9515                 skip "no early lock cancel on server"
9516
9517         lru_resize_disable mdc
9518         lru_resize_disable osc
9519         test_mkdir -c1 $DIR/$tdir/d1
9520         test_mkdir -c1 $DIR/$tdir/d2
9521         touch $DIR/$tdir/d1/f1
9522         cancel_lru_locks mdc
9523         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
9524         can1=$(do_facet $SINGLEMDS \
9525                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9526                awk '/ldlm_cancel/ {print $2}')
9527         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9528                awk '/ldlm_bl_callback/ {print $2}')
9529         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
9530         can2=$(do_facet $SINGLEMDS \
9531                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9532                awk '/ldlm_cancel/ {print $2}')
9533         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9534                awk '/ldlm_bl_callback/ {print $2}')
9535         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9536         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9537         lru_resize_enable mdc
9538         lru_resize_enable osc
9539 }
9540 run_test 120c "Early Lock Cancel: link test"
9541
9542 test_120d() {
9543         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9544         remote_mds_nodsh && skip "remote MDS with nodsh"
9545         test_mkdir -c1 $DIR/$tdir
9546         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9547                 skip_env "no early lock cancel on server"
9548
9549         lru_resize_disable mdc
9550         lru_resize_disable osc
9551         touch $DIR/$tdir
9552         cancel_lru_locks mdc
9553         stat $DIR/$tdir > /dev/null
9554         can1=$(do_facet $SINGLEMDS \
9555                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9556                awk '/ldlm_cancel/ {print $2}')
9557         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9558                awk '/ldlm_bl_callback/ {print $2}')
9559         chmod a+x $DIR/$tdir
9560         can2=$(do_facet $SINGLEMDS \
9561                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9562                awk '/ldlm_cancel/ {print $2}')
9563         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9564                awk '/ldlm_bl_callback/ {print $2}')
9565         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9566         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9567         lru_resize_enable mdc
9568         lru_resize_enable osc
9569 }
9570 run_test 120d "Early Lock Cancel: setattr test"
9571
9572 test_120e() {
9573         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9574         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9575                 skip_env "no early lock cancel on server"
9576         remote_mds_nodsh && skip "remote MDS with nodsh"
9577
9578         local dlmtrace_set=false
9579
9580         test_mkdir -c1 $DIR/$tdir
9581         lru_resize_disable mdc
9582         lru_resize_disable osc
9583         ! $LCTL get_param debug | grep -q dlmtrace &&
9584                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
9585         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
9586         cancel_lru_locks mdc
9587         cancel_lru_locks osc
9588         dd if=$DIR/$tdir/f1 of=/dev/null
9589         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
9590         # XXX client can not do early lock cancel of OST lock
9591         # during unlink (LU-4206), so cancel osc lock now.
9592         sleep 2
9593         cancel_lru_locks osc
9594         can1=$(do_facet $SINGLEMDS \
9595                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9596                awk '/ldlm_cancel/ {print $2}')
9597         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9598                awk '/ldlm_bl_callback/ {print $2}')
9599         unlink $DIR/$tdir/f1
9600         sleep 5
9601         can2=$(do_facet $SINGLEMDS \
9602                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9603                awk '/ldlm_cancel/ {print $2}')
9604         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9605                awk '/ldlm_bl_callback/ {print $2}')
9606         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
9607                 $LCTL dk $TMP/cancel.debug.txt
9608         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
9609                 $LCTL dk $TMP/blocking.debug.txt
9610         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
9611         lru_resize_enable mdc
9612         lru_resize_enable osc
9613 }
9614 run_test 120e "Early Lock Cancel: unlink test"
9615
9616 test_120f() {
9617         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9618         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9619                 skip_env "no early lock cancel on server"
9620         remote_mds_nodsh && skip "remote MDS with nodsh"
9621
9622         test_mkdir -c1 $DIR/$tdir
9623         lru_resize_disable mdc
9624         lru_resize_disable osc
9625         test_mkdir -c1 $DIR/$tdir/d1
9626         test_mkdir -c1 $DIR/$tdir/d2
9627         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
9628         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
9629         cancel_lru_locks mdc
9630         cancel_lru_locks osc
9631         dd if=$DIR/$tdir/d1/f1 of=/dev/null
9632         dd if=$DIR/$tdir/d2/f2 of=/dev/null
9633         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
9634         # XXX client can not do early lock cancel of OST lock
9635         # during rename (LU-4206), so cancel osc lock now.
9636         sleep 2
9637         cancel_lru_locks osc
9638         can1=$(do_facet $SINGLEMDS \
9639                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9640                awk '/ldlm_cancel/ {print $2}')
9641         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9642                awk '/ldlm_bl_callback/ {print $2}')
9643         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
9644         sleep 5
9645         can2=$(do_facet $SINGLEMDS \
9646                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9647                awk '/ldlm_cancel/ {print $2}')
9648         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9649                awk '/ldlm_bl_callback/ {print $2}')
9650         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9651         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9652         lru_resize_enable mdc
9653         lru_resize_enable osc
9654 }
9655 run_test 120f "Early Lock Cancel: rename test"
9656
9657 test_120g() {
9658         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9659         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9660                 skip_env "no early lock cancel on server"
9661         remote_mds_nodsh && skip "remote MDS with nodsh"
9662
9663         lru_resize_disable mdc
9664         lru_resize_disable osc
9665         count=10000
9666         echo create $count files
9667         test_mkdir $DIR/$tdir
9668         cancel_lru_locks mdc
9669         cancel_lru_locks osc
9670         t0=$(date +%s)
9671
9672         can0=$(do_facet $SINGLEMDS \
9673                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9674                awk '/ldlm_cancel/ {print $2}')
9675         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9676                awk '/ldlm_bl_callback/ {print $2}')
9677         createmany -o $DIR/$tdir/f $count
9678         sync
9679         can1=$(do_facet $SINGLEMDS \
9680                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9681                awk '/ldlm_cancel/ {print $2}')
9682         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9683                awk '/ldlm_bl_callback/ {print $2}')
9684         t1=$(date +%s)
9685         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
9686         echo rm $count files
9687         rm -r $DIR/$tdir
9688         sync
9689         can2=$(do_facet $SINGLEMDS \
9690                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9691                awk '/ldlm_cancel/ {print $2}')
9692         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9693                awk '/ldlm_bl_callback/ {print $2}')
9694         t2=$(date +%s)
9695         echo total: $count removes in $((t2-t1))
9696         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
9697         sleep 2
9698         # wait for commitment of removal
9699         lru_resize_enable mdc
9700         lru_resize_enable osc
9701 }
9702 run_test 120g "Early Lock Cancel: performance test"
9703
9704 test_121() { #bug #10589
9705         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9706
9707         rm -rf $DIR/$tfile
9708         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
9709 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
9710         lctl set_param fail_loc=0x310
9711         cancel_lru_locks osc > /dev/null
9712         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
9713         lctl set_param fail_loc=0
9714         [[ $reads -eq $writes ]] ||
9715                 error "read $reads blocks, must be $writes blocks"
9716 }
9717 run_test 121 "read cancel race ========="
9718
9719 test_123a() { # was test 123, statahead(bug 11401)
9720         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9721
9722         SLOWOK=0
9723         if ! grep -q "processor.*: 1" /proc/cpuinfo; then
9724                 log "testing UP system. Performance may be lower than expected."
9725                 SLOWOK=1
9726         fi
9727
9728         rm -rf $DIR/$tdir
9729         test_mkdir $DIR/$tdir
9730         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
9731         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
9732         MULT=10
9733         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
9734                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
9735
9736                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
9737                 lctl set_param -n llite.*.statahead_max 0
9738                 lctl get_param llite.*.statahead_max
9739                 cancel_lru_locks mdc
9740                 cancel_lru_locks osc
9741                 stime=`date +%s`
9742                 time ls -l $DIR/$tdir | wc -l
9743                 etime=`date +%s`
9744                 delta=$((etime - stime))
9745                 log "ls $i files without statahead: $delta sec"
9746                 lctl set_param llite.*.statahead_max=$max
9747
9748                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
9749                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
9750                 cancel_lru_locks mdc
9751                 cancel_lru_locks osc
9752                 stime=`date +%s`
9753                 time ls -l $DIR/$tdir | wc -l
9754                 etime=`date +%s`
9755                 delta_sa=$((etime - stime))
9756                 log "ls $i files with statahead: $delta_sa sec"
9757                 lctl get_param -n llite.*.statahead_stats
9758                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
9759
9760                 [[ $swrong -lt $ewrong ]] &&
9761                         log "statahead was stopped, maybe too many locks held!"
9762                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
9763
9764                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
9765                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
9766                     lctl set_param -n llite.*.statahead_max 0
9767                     lctl get_param llite.*.statahead_max
9768                     cancel_lru_locks mdc
9769                     cancel_lru_locks osc
9770                     stime=`date +%s`
9771                     time ls -l $DIR/$tdir | wc -l
9772                     etime=`date +%s`
9773                     delta=$((etime - stime))
9774                     log "ls $i files again without statahead: $delta sec"
9775                     lctl set_param llite.*.statahead_max=$max
9776                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
9777                         if [  $SLOWOK -eq 0 ]; then
9778                                 error "ls $i files is slower with statahead!"
9779                         else
9780                                 log "ls $i files is slower with statahead!"
9781                         fi
9782                         break
9783                     fi
9784                 fi
9785
9786                 [ $delta -gt 20 ] && break
9787                 [ $delta -gt 8 ] && MULT=$((50 / delta))
9788                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
9789         done
9790         log "ls done"
9791
9792         stime=`date +%s`
9793         rm -r $DIR/$tdir
9794         sync
9795         etime=`date +%s`
9796         delta=$((etime - stime))
9797         log "rm -r $DIR/$tdir/: $delta seconds"
9798         log "rm done"
9799         lctl get_param -n llite.*.statahead_stats
9800 }
9801 run_test 123a "verify statahead work"
9802
9803 test_123b () { # statahead(bug 15027)
9804         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9805
9806         test_mkdir $DIR/$tdir
9807         createmany -o $DIR/$tdir/$tfile-%d 1000
9808
9809         cancel_lru_locks mdc
9810         cancel_lru_locks osc
9811
9812 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
9813         lctl set_param fail_loc=0x80000803
9814         ls -lR $DIR/$tdir > /dev/null
9815         log "ls done"
9816         lctl set_param fail_loc=0x0
9817         lctl get_param -n llite.*.statahead_stats
9818         rm -r $DIR/$tdir
9819         sync
9820
9821 }
9822 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
9823
9824 test_124a() {
9825         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9826         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
9827                 skip_env "no lru resize on server"
9828
9829         local NR=2000
9830
9831         test_mkdir $DIR/$tdir
9832
9833         log "create $NR files at $DIR/$tdir"
9834         createmany -o $DIR/$tdir/f $NR ||
9835                 error "failed to create $NR files in $DIR/$tdir"
9836
9837         cancel_lru_locks mdc
9838         ls -l $DIR/$tdir > /dev/null
9839
9840         local NSDIR=""
9841         local LRU_SIZE=0
9842         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
9843                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
9844                 LRU_SIZE=$($LCTL get_param -n $PARAM)
9845                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
9846                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
9847                         log "NSDIR=$NSDIR"
9848                         log "NS=$(basename $NSDIR)"
9849                         break
9850                 fi
9851         done
9852
9853         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
9854                 skip "Not enough cached locks created!"
9855         fi
9856         log "LRU=$LRU_SIZE"
9857
9858         local SLEEP=30
9859
9860         # We know that lru resize allows one client to hold $LIMIT locks
9861         # for 10h. After that locks begin to be killed by client.
9862         local MAX_HRS=10
9863         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
9864         log "LIMIT=$LIMIT"
9865         if [ $LIMIT -lt $LRU_SIZE ]; then
9866                 skip "Limit is too small $LIMIT"
9867         fi
9868
9869         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
9870         # killing locks. Some time was spent for creating locks. This means
9871         # that up to the moment of sleep finish we must have killed some of
9872         # them (10-100 locks). This depends on how fast ther were created.
9873         # Many of them were touched in almost the same moment and thus will
9874         # be killed in groups.
9875         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
9876
9877         # Use $LRU_SIZE_B here to take into account real number of locks
9878         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
9879         local LRU_SIZE_B=$LRU_SIZE
9880         log "LVF=$LVF"
9881         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
9882         log "OLD_LVF=$OLD_LVF"
9883         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
9884
9885         # Let's make sure that we really have some margin. Client checks
9886         # cached locks every 10 sec.
9887         SLEEP=$((SLEEP+20))
9888         log "Sleep ${SLEEP} sec"
9889         local SEC=0
9890         while ((SEC<$SLEEP)); do
9891                 echo -n "..."
9892                 sleep 5
9893                 SEC=$((SEC+5))
9894                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
9895                 echo -n "$LRU_SIZE"
9896         done
9897         echo ""
9898         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
9899         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
9900
9901         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
9902                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
9903                 unlinkmany $DIR/$tdir/f $NR
9904                 return
9905         }
9906
9907         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
9908         log "unlink $NR files at $DIR/$tdir"
9909         unlinkmany $DIR/$tdir/f $NR
9910 }
9911 run_test 124a "lru resize ======================================="
9912
9913 get_max_pool_limit()
9914 {
9915         local limit=$($LCTL get_param \
9916                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
9917         local max=0
9918         for l in $limit; do
9919                 if [[ $l -gt $max ]]; then
9920                         max=$l
9921                 fi
9922         done
9923         echo $max
9924 }
9925
9926 test_124b() {
9927         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9928         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
9929                 skip_env "no lru resize on server"
9930
9931         LIMIT=$(get_max_pool_limit)
9932
9933         NR=$(($(default_lru_size)*20))
9934         if [[ $NR -gt $LIMIT ]]; then
9935                 log "Limit lock number by $LIMIT locks"
9936                 NR=$LIMIT
9937         fi
9938
9939         IFree=$(mdsrate_inodes_available)
9940         if [ $IFree -lt $NR ]; then
9941                 log "Limit lock number by $IFree inodes"
9942                 NR=$IFree
9943         fi
9944
9945         lru_resize_disable mdc
9946         test_mkdir -p $DIR/$tdir/disable_lru_resize
9947
9948         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
9949         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
9950         cancel_lru_locks mdc
9951         stime=`date +%s`
9952         PID=""
9953         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9954         PID="$PID $!"
9955         sleep 2
9956         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9957         PID="$PID $!"
9958         sleep 2
9959         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9960         PID="$PID $!"
9961         wait $PID
9962         etime=`date +%s`
9963         nolruresize_delta=$((etime-stime))
9964         log "ls -la time: $nolruresize_delta seconds"
9965         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9966         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
9967
9968         lru_resize_enable mdc
9969         test_mkdir -p $DIR/$tdir/enable_lru_resize
9970
9971         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
9972         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
9973         cancel_lru_locks mdc
9974         stime=`date +%s`
9975         PID=""
9976         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9977         PID="$PID $!"
9978         sleep 2
9979         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9980         PID="$PID $!"
9981         sleep 2
9982         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9983         PID="$PID $!"
9984         wait $PID
9985         etime=`date +%s`
9986         lruresize_delta=$((etime-stime))
9987         log "ls -la time: $lruresize_delta seconds"
9988         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9989
9990         if [ $lruresize_delta -gt $nolruresize_delta ]; then
9991                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
9992         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
9993                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
9994         else
9995                 log "lru resize performs the same with no lru resize"
9996         fi
9997         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
9998 }
9999 run_test 124b "lru resize (performance test) ======================="
10000
10001 test_124c() {
10002         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10003         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
10004                 skip_env "no lru resize on server"
10005
10006         # cache ununsed locks on client
10007         local nr=100
10008         cancel_lru_locks mdc
10009         test_mkdir $DIR/$tdir
10010         createmany -o $DIR/$tdir/f $nr ||
10011                 error "failed to create $nr files in $DIR/$tdir"
10012         ls -l $DIR/$tdir > /dev/null
10013
10014         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
10015         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10016         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
10017         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
10018         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
10019
10020         # set lru_max_age to 1 sec
10021         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
10022         echo "sleep $((recalc_p * 2)) seconds..."
10023         sleep $((recalc_p * 2))
10024
10025         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
10026         # restore lru_max_age
10027         $LCTL set_param -n $nsdir.lru_max_age $max_age
10028         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
10029         unlinkmany $DIR/$tdir/f $nr
10030 }
10031 run_test 124c "LRUR cancel very aged locks"
10032
10033 test_125() { # 13358
10034         $LCTL get_param -n llite.*.client_type | grep -q local ||
10035                 skip "must run as local client"
10036         $LCTL get_param -n mdc.*-mdc-*.connect_flags | grep -q acl ||
10037                 skip_env "must have acl enabled"
10038         [ -z "$(which setfacl)" ] && skip_env "must have setfacl tool"
10039
10040         test_mkdir $DIR/$tdir
10041         $LFS setstripe -S 65536 -c -1 $DIR/$tdir || error "setstripe failed"
10042         setfacl -R -m u:bin:rwx $DIR/$tdir || error "setfacl $DIR/$tdir failed"
10043         ls -ld $DIR/$tdir || error "cannot access $DIR/$tdir"
10044 }
10045 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
10046
10047 test_126() { # bug 12829/13455
10048         $GSS && skip_env "must run as gss disabled"
10049         $LCTL get_param -n llite.*.client_type | grep -q local ||
10050                 skip "must run as local client"
10051         [ "$UID" != 0 ] && skip "must run as root, not UID $UID"
10052
10053         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
10054         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
10055         rm -f $DIR/$tfile
10056         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
10057 }
10058 run_test 126 "check that the fsgid provided by the client is taken into account"
10059
10060 test_127a() { # bug 15521
10061         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10062
10063         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
10064         $LCTL set_param osc.*.stats=0
10065         FSIZE=$((2048 * 1024))
10066         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
10067         cancel_lru_locks osc
10068         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
10069
10070         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
10071         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
10072                 echo "got $COUNT $NAME"
10073                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
10074                 eval $NAME=$COUNT || error "Wrong proc format"
10075
10076                 case $NAME in
10077                         read_bytes|write_bytes)
10078                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
10079                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
10080                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
10081                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
10082                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
10083                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
10084                                 error "sumsquare is too small: $SUMSQ"
10085                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
10086                                 error "sumsquare is too big: $SUMSQ"
10087                         ;;
10088                         *) ;;
10089                 esac
10090         done < $DIR/${tfile}.tmp
10091
10092         #check that we actually got some stats
10093         [ "$read_bytes" ] || error "Missing read_bytes stats"
10094         [ "$write_bytes" ] || error "Missing write_bytes stats"
10095         [ "$read_bytes" != 0 ] || error "no read done"
10096         [ "$write_bytes" != 0 ] || error "no write done"
10097 }
10098 run_test 127a "verify the client stats are sane"
10099
10100 test_127b() { # bug LU-333
10101         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10102
10103         $LCTL set_param llite.*.stats=0
10104         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
10105
10106         # perform 2 reads and writes so MAX is different from SUM.
10107         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
10108         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
10109         cancel_lru_locks osc
10110         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
10111         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
10112
10113         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
10114         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
10115                 echo "got $COUNT $NAME"
10116                 eval $NAME=$COUNT || error "Wrong proc format"
10117
10118         case $NAME in
10119                 read_bytes)
10120                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
10121                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
10122                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
10123                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
10124                         ;;
10125                 write_bytes)
10126                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
10127                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
10128                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
10129                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
10130                         ;;
10131                         *) ;;
10132                 esac
10133         done < $TMP/${tfile}.tmp
10134
10135         #check that we actually got some stats
10136         [ "$read_bytes" ] || error "Missing read_bytes stats"
10137         [ "$write_bytes" ] || error "Missing write_bytes stats"
10138         [ "$read_bytes" != 0 ] || error "no read done"
10139         [ "$write_bytes" != 0 ] || error "no write done"
10140
10141         rm -f $TMP/${tfile}.tmp
10142 }
10143 run_test 127b "verify the llite client stats are sane"
10144
10145 test_128() { # bug 15212
10146         touch $DIR/$tfile
10147         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
10148                 find $DIR/$tfile
10149                 find $DIR/$tfile
10150         EOF
10151
10152         result=$(grep error $TMP/$tfile.log)
10153         rm -f $DIR/$tfile $TMP/$tfile.log
10154         [ -z "$result" ] ||
10155                 error "consecutive find's under interactive lfs failed"
10156 }
10157 run_test 128 "interactive lfs for 2 consecutive find's"
10158
10159 set_dir_limits () {
10160         local mntdev
10161         local canondev
10162         local node
10163
10164         local ldproc=/proc/fs/ldiskfs
10165         local facets=$(get_facets MDS)
10166
10167         for facet in ${facets//,/ }; do
10168                 canondev=$(ldiskfs_canon \
10169                            *.$(convert_facet2label $facet).mntdev $facet)
10170                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
10171                         ldproc=/sys/fs/ldiskfs
10172                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
10173                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
10174         done
10175 }
10176
10177 check_mds_dmesg() {
10178         local facets=$(get_facets MDS)
10179         for facet in ${facets//,/ }; do
10180                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
10181         done
10182         return 1
10183 }
10184
10185 test_129() {
10186         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10187         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
10188                 skip "Need MDS version with at least 2.5.56"
10189         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
10190                 skip_env "ldiskfs only test"
10191         fi
10192         remote_mds_nodsh && skip "remote MDS with nodsh"
10193
10194         local ENOSPC=28
10195         local EFBIG=27
10196         local has_warning=false
10197
10198         rm -rf $DIR/$tdir
10199         mkdir -p $DIR/$tdir
10200
10201         # block size of mds1
10202         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
10203         set_dir_limits $maxsize $maxsize
10204         local dirsize=$(stat -c%s "$DIR/$tdir")
10205         local nfiles=0
10206         while [[ $dirsize -le $maxsize ]]; do
10207                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
10208                 rc=$?
10209                 if ! $has_warning; then
10210                         check_mds_dmesg '"is approaching"' && has_warning=true
10211                 fi
10212                 # check two errors:
10213                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
10214                 # EFBIG for previous versions included in ldiskfs series
10215                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
10216                         set_dir_limits 0 0
10217                         echo "return code $rc received as expected"
10218
10219                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
10220                                 error_exit "create failed w/o dir size limit"
10221
10222                         check_mds_dmesg '"has reached"' ||
10223                                 error_exit "reached message should be output"
10224
10225                         [ $has_warning = "false" ] &&
10226                                 error_exit "warning message should be output"
10227
10228                         dirsize=$(stat -c%s "$DIR/$tdir")
10229
10230                         [[ $dirsize -ge $maxsize ]] && return 0
10231                         error_exit "current dir size $dirsize, " \
10232                                    "previous limit $maxsize"
10233                 elif [ $rc -ne 0 ]; then
10234                         set_dir_limits 0 0
10235                         error_exit "return $rc received instead of expected " \
10236                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
10237                 fi
10238                 nfiles=$((nfiles + 1))
10239                 dirsize=$(stat -c%s "$DIR/$tdir")
10240         done
10241
10242         set_dir_limits 0 0
10243         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
10244 }
10245 run_test 129 "test directory size limit ========================"
10246
10247 OLDIFS="$IFS"
10248 cleanup_130() {
10249         trap 0
10250         IFS="$OLDIFS"
10251 }
10252
10253 test_130a() {
10254         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10255         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
10256
10257         trap cleanup_130 EXIT RETURN
10258
10259         local fm_file=$DIR/$tfile
10260         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
10261         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
10262                 error "dd failed for $fm_file"
10263
10264         # LU-1795: test filefrag/FIEMAP once, even if unsupported
10265         filefrag -ves $fm_file
10266         RC=$?
10267         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10268                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
10269         [ $RC != 0 ] && error "filefrag $fm_file failed"
10270
10271         filefrag_op=$(filefrag -ve -k $fm_file |
10272                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10273         lun=$($GETSTRIPE -i $fm_file)
10274
10275         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
10276         IFS=$'\n'
10277         tot_len=0
10278         for line in $filefrag_op
10279         do
10280                 frag_lun=`echo $line | cut -d: -f5`
10281                 ext_len=`echo $line | cut -d: -f4`
10282                 if (( $frag_lun != $lun )); then
10283                         cleanup_130
10284                         error "FIEMAP on 1-stripe file($fm_file) failed"
10285                         return
10286                 fi
10287                 (( tot_len += ext_len ))
10288         done
10289
10290         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
10291                 cleanup_130
10292                 error "FIEMAP on 1-stripe file($fm_file) failed;"
10293                 return
10294         fi
10295
10296         cleanup_130
10297
10298         echo "FIEMAP on single striped file succeeded"
10299 }
10300 run_test 130a "FIEMAP (1-stripe file)"
10301
10302 test_130b() {
10303         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
10304
10305         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10306         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
10307
10308         trap cleanup_130 EXIT RETURN
10309
10310         local fm_file=$DIR/$tfile
10311         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
10312                         error "setstripe on $fm_file"
10313         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10314                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
10315
10316         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
10317                 error "dd failed on $fm_file"
10318
10319         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10320         filefrag_op=$(filefrag -ve -k $fm_file |
10321                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10322
10323         last_lun=$(echo $filefrag_op | cut -d: -f5 |
10324                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10325
10326         IFS=$'\n'
10327         tot_len=0
10328         num_luns=1
10329         for line in $filefrag_op
10330         do
10331                 frag_lun=$(echo $line | cut -d: -f5 |
10332                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10333                 ext_len=$(echo $line | cut -d: -f4)
10334                 if (( $frag_lun != $last_lun )); then
10335                         if (( tot_len != 1024 )); then
10336                                 cleanup_130
10337                                 error "FIEMAP on $fm_file failed; returned " \
10338                                 "len $tot_len for OST $last_lun instead of 1024"
10339                                 return
10340                         else
10341                                 (( num_luns += 1 ))
10342                                 tot_len=0
10343                         fi
10344                 fi
10345                 (( tot_len += ext_len ))
10346                 last_lun=$frag_lun
10347         done
10348         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
10349                 cleanup_130
10350                 error "FIEMAP on $fm_file failed; returned wrong number of " \
10351                         "luns or wrong len for OST $last_lun"
10352                 return
10353         fi
10354
10355         cleanup_130
10356
10357         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
10358 }
10359 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
10360
10361 test_130c() {
10362         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
10363
10364         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10365         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
10366
10367         trap cleanup_130 EXIT RETURN
10368
10369         local fm_file=$DIR/$tfile
10370         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
10371         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10372                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
10373
10374         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
10375                         error "dd failed on $fm_file"
10376
10377         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10378         filefrag_op=$(filefrag -ve -k $fm_file |
10379                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10380
10381         last_lun=$(echo $filefrag_op | cut -d: -f5 |
10382                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10383
10384         IFS=$'\n'
10385         tot_len=0
10386         num_luns=1
10387         for line in $filefrag_op
10388         do
10389                 frag_lun=$(echo $line | cut -d: -f5 |
10390                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10391                 ext_len=$(echo $line | cut -d: -f4)
10392                 if (( $frag_lun != $last_lun )); then
10393                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
10394                         if (( logical != 512 )); then
10395                                 cleanup_130
10396                                 error "FIEMAP on $fm_file failed; returned " \
10397                                 "logical start for lun $logical instead of 512"
10398                                 return
10399                         fi
10400                         if (( tot_len != 512 )); then
10401                                 cleanup_130
10402                                 error "FIEMAP on $fm_file failed; returned " \
10403                                 "len $tot_len for OST $last_lun instead of 1024"
10404                                 return
10405                         else
10406                                 (( num_luns += 1 ))
10407                                 tot_len=0
10408                         fi
10409                 fi
10410                 (( tot_len += ext_len ))
10411                 last_lun=$frag_lun
10412         done
10413         if (( num_luns != 2 || tot_len != 512 )); then
10414                 cleanup_130
10415                 error "FIEMAP on $fm_file failed; returned wrong number of " \
10416                         "luns or wrong len for OST $last_lun"
10417                 return
10418         fi
10419
10420         cleanup_130
10421
10422         echo "FIEMAP on 2-stripe file with hole succeeded"
10423 }
10424 run_test 130c "FIEMAP (2-stripe file with hole)"
10425
10426 test_130d() {
10427         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs"
10428
10429         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10430         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
10431
10432         trap cleanup_130 EXIT RETURN
10433
10434         local fm_file=$DIR/$tfile
10435         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
10436                         error "setstripe on $fm_file"
10437         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10438                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
10439
10440         local actual_stripe_count=$($GETSTRIPE -c $fm_file)
10441         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripe_count ||
10442                 error "dd failed on $fm_file"
10443
10444         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10445         filefrag_op=$(filefrag -ve -k $fm_file |
10446                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10447
10448         last_lun=$(echo $filefrag_op | cut -d: -f5 |
10449                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10450
10451         IFS=$'\n'
10452         tot_len=0
10453         num_luns=1
10454         for line in $filefrag_op
10455         do
10456                 frag_lun=$(echo $line | cut -d: -f5 |
10457                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10458                 ext_len=$(echo $line | cut -d: -f4)
10459                 if (( $frag_lun != $last_lun )); then
10460                         if (( tot_len != 1024 )); then
10461                                 cleanup_130
10462                                 error "FIEMAP on $fm_file failed; returned " \
10463                                 "len $tot_len for OST $last_lun instead of 1024"
10464                                 return
10465                         else
10466                                 (( num_luns += 1 ))
10467                                 tot_len=0
10468                         fi
10469                 fi
10470                 (( tot_len += ext_len ))
10471                 last_lun=$frag_lun
10472         done
10473         if (( num_luns != actual_stripe_count || tot_len != 1024 )); then
10474                 cleanup_130
10475                 error "FIEMAP on $fm_file failed; returned wrong number of " \
10476                         "luns or wrong len for OST $last_lun"
10477                 return
10478         fi
10479
10480         cleanup_130
10481
10482         echo "FIEMAP on N-stripe file succeeded"
10483 }
10484 run_test 130d "FIEMAP (N-stripe file)"
10485
10486 test_130e() {
10487         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
10488
10489         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10490         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
10491
10492         trap cleanup_130 EXIT RETURN
10493
10494         local fm_file=$DIR/$tfile
10495         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
10496         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10497                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
10498
10499         NUM_BLKS=512
10500         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
10501         for ((i = 0; i < $NUM_BLKS; i++))
10502         do
10503                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
10504         done
10505
10506         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10507         filefrag_op=$(filefrag -ve -k $fm_file |
10508                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10509
10510         last_lun=$(echo $filefrag_op | cut -d: -f5 |
10511                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10512
10513         IFS=$'\n'
10514         tot_len=0
10515         num_luns=1
10516         for line in $filefrag_op
10517         do
10518                 frag_lun=$(echo $line | cut -d: -f5 |
10519                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10520                 ext_len=$(echo $line | cut -d: -f4)
10521                 if (( $frag_lun != $last_lun )); then
10522                         if (( tot_len != $EXPECTED_LEN )); then
10523                                 cleanup_130
10524                                 error "FIEMAP on $fm_file failed; returned " \
10525                                 "len $tot_len for OST $last_lun instead " \
10526                                 "of $EXPECTED_LEN"
10527                                 return
10528                         else
10529                                 (( num_luns += 1 ))
10530                                 tot_len=0
10531                         fi
10532                 fi
10533                 (( tot_len += ext_len ))
10534                 last_lun=$frag_lun
10535         done
10536         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
10537                 cleanup_130
10538                 error "FIEMAP on $fm_file failed; returned wrong number " \
10539                         "of luns or wrong len for OST $last_lun"
10540                 return
10541         fi
10542
10543         cleanup_130
10544
10545         echo "FIEMAP with continuation calls succeeded"
10546 }
10547 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
10548
10549 test_130f() {
10550         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10551         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
10552
10553         local fm_file=$DIR/$tfile
10554         $MULTIOP $fm_file oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T33554432c ||
10555                 error "multiop create with lov_delay_create on $fm_file"
10556
10557         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10558         filefrag_extents=$(filefrag -vek $fm_file |
10559                            awk '/extents? found/ { print $2 }')
10560         if [[ "$filefrag_extents" != "0" ]]; then
10561                 error "FIEMAP on $fm_file failed; " \
10562                       "returned $filefrag_extents expected 0"
10563         fi
10564
10565         rm -f $fm_file
10566 }
10567 run_test 130f "FIEMAP (unstriped file)"
10568
10569 # Test for writev/readv
10570 test_131a() {
10571         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
10572                 error "writev test failed"
10573         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
10574                 error "readv failed"
10575         rm -f $DIR/$tfile
10576 }
10577 run_test 131a "test iov's crossing stripe boundary for writev/readv"
10578
10579 test_131b() {
10580         local fsize=$((524288 + 1048576 + 1572864))
10581         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
10582                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
10583                         error "append writev test failed"
10584
10585         ((fsize += 1572864 + 1048576))
10586         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
10587                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
10588                         error "append writev test failed"
10589         rm -f $DIR/$tfile
10590 }
10591 run_test 131b "test append writev"
10592
10593 test_131c() {
10594         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
10595         error "NOT PASS"
10596 }
10597 run_test 131c "test read/write on file w/o objects"
10598
10599 test_131d() {
10600         rwv -f $DIR/$tfile -w -n 1 1572864
10601         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
10602         if [ "$NOB" != 1572864 ]; then
10603                 error "Short read filed: read $NOB bytes instead of 1572864"
10604         fi
10605         rm -f $DIR/$tfile
10606 }
10607 run_test 131d "test short read"
10608
10609 test_131e() {
10610         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
10611         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
10612         error "read hitting hole failed"
10613         rm -f $DIR/$tfile
10614 }
10615 run_test 131e "test read hitting hole"
10616
10617 check_stats() {
10618         local facet=$1
10619         local op=$2
10620         local want=${3:-0}
10621         local res
10622
10623         case $facet in
10624         mds*) res=$(do_facet $facet \
10625                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
10626                  ;;
10627         ost*) res=$(do_facet $facet \
10628                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
10629                  ;;
10630         *) error "Wrong facet '$facet'" ;;
10631         esac
10632         echo $res
10633         [ "$res" ] || error "The counter for $op on $facet was not incremented"
10634         # if the argument $3 is zero, it means any stat increment is ok.
10635         if [[ $want -gt 0 ]]; then
10636                 local count=$(echo $res | awk '{ print $2 }')
10637                 [[ $count -ne $want ]] &&
10638                         error "The $op counter on $facet is $count, not $want"
10639         fi
10640 }
10641
10642 test_133a() {
10643         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10644         remote_ost_nodsh && skip "remote OST with nodsh"
10645         remote_mds_nodsh && skip "remote MDS with nodsh"
10646         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
10647                 skip_env "MDS doesn't support rename stats"
10648
10649         local testdir=$DIR/${tdir}/stats_testdir
10650
10651         mkdir -p $DIR/${tdir}
10652
10653         # clear stats.
10654         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10655         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10656
10657         # verify mdt stats first.
10658         mkdir ${testdir} || error "mkdir failed"
10659         check_stats $SINGLEMDS "mkdir" 1
10660         touch ${testdir}/${tfile} || error "touch failed"
10661         check_stats $SINGLEMDS "open" 1
10662         check_stats $SINGLEMDS "close" 1
10663         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
10664                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
10665                 check_stats $SINGLEMDS "mknod" 2
10666         }
10667         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
10668         check_stats $SINGLEMDS "unlink" 1
10669         rm -f ${testdir}/${tfile} || error "file remove failed"
10670         check_stats $SINGLEMDS "unlink" 2
10671
10672         # remove working dir and check mdt stats again.
10673         rmdir ${testdir} || error "rmdir failed"
10674         check_stats $SINGLEMDS "rmdir" 1
10675
10676         local testdir1=$DIR/${tdir}/stats_testdir1
10677         mkdir -p ${testdir}
10678         mkdir -p ${testdir1}
10679         touch ${testdir1}/test1
10680         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
10681         check_stats $SINGLEMDS "crossdir_rename" 1
10682
10683         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
10684         check_stats $SINGLEMDS "samedir_rename" 1
10685
10686         rm -rf $DIR/${tdir}
10687 }
10688 run_test 133a "Verifying MDT stats ========================================"
10689
10690 test_133b() {
10691         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10692         remote_ost_nodsh && skip "remote OST with nodsh"
10693         remote_mds_nodsh && skip "remote MDS with nodsh"
10694
10695         local testdir=$DIR/${tdir}/stats_testdir
10696
10697         mkdir -p ${testdir} || error "mkdir failed"
10698         touch ${testdir}/${tfile} || error "touch failed"
10699         cancel_lru_locks mdc
10700
10701         # clear stats.
10702         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10703         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10704
10705         # extra mdt stats verification.
10706         chmod 444 ${testdir}/${tfile} || error "chmod failed"
10707         check_stats $SINGLEMDS "setattr" 1
10708         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10709         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
10710         then            # LU-1740
10711                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
10712                 check_stats $SINGLEMDS "getattr" 1
10713         fi
10714         $LFS df || error "lfs failed"
10715         check_stats $SINGLEMDS "statfs" 1
10716
10717         rm -rf $DIR/${tdir}
10718 }
10719 run_test 133b "Verifying extra MDT stats =================================="
10720
10721 test_133c() {
10722         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10723         remote_ost_nodsh && skip "remote OST with nodsh"
10724         remote_mds_nodsh && skip "remote MDS with nodsh"
10725
10726         local testdir=$DIR/$tdir/stats_testdir
10727
10728         test_mkdir -p $testdir
10729
10730         # verify obdfilter stats.
10731         $SETSTRIPE -c 1 -i 0 $testdir/$tfile
10732         sync
10733         cancel_lru_locks osc
10734         wait_delete_completed
10735
10736         # clear stats.
10737         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10738         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10739
10740         dd if=/dev/zero of=$testdir/$tfile conv=notrunc bs=512k count=1 ||
10741                 error "dd failed"
10742         sync
10743         cancel_lru_locks osc
10744         check_stats ost1 "write" 1
10745
10746         dd if=$testdir/$tfile of=/dev/null bs=1k count=1 || error "dd failed"
10747         check_stats ost1 "read" 1
10748
10749         > $testdir/$tfile || error "truncate failed"
10750         check_stats ost1 "punch" 1
10751
10752         rm -f $testdir/$tfile || error "file remove failed"
10753         wait_delete_completed
10754         check_stats ost1 "destroy" 1
10755
10756         rm -rf $DIR/$tdir
10757 }
10758 run_test 133c "Verifying OST stats ========================================"
10759
10760 order_2() {
10761         local value=$1
10762         local orig=$value
10763         local order=1
10764
10765         while [ $value -ge 2 ]; do
10766                 order=$((order*2))
10767                 value=$((value/2))
10768         done
10769
10770         if [ $orig -gt $order ]; then
10771                 order=$((order*2))
10772         fi
10773         echo $order
10774 }
10775
10776 size_in_KMGT() {
10777     local value=$1
10778     local size=('K' 'M' 'G' 'T');
10779     local i=0
10780     local size_string=$value
10781
10782     while [ $value -ge 1024 ]; do
10783         if [ $i -gt 3 ]; then
10784             #T is the biggest unit we get here, if that is bigger,
10785             #just return XXXT
10786             size_string=${value}T
10787             break
10788         fi
10789         value=$((value >> 10))
10790         if [ $value -lt 1024 ]; then
10791             size_string=${value}${size[$i]}
10792             break
10793         fi
10794         i=$((i + 1))
10795     done
10796
10797     echo $size_string
10798 }
10799
10800 get_rename_size() {
10801         local size=$1
10802         local context=${2:-.}
10803         local sample=$(do_facet $SINGLEMDS $LCTL \
10804                 get_param mdt.$FSNAME-MDT0000.rename_stats |
10805                 grep -A1 $context |
10806                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
10807         echo $sample
10808 }
10809
10810 test_133d() {
10811         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10812         remote_ost_nodsh && skip "remote OST with nodsh"
10813         remote_mds_nodsh && skip "remote MDS with nodsh"
10814         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
10815                 skip_env "MDS doesn't support rename stats"
10816
10817         local testdir1=$DIR/${tdir}/stats_testdir1
10818         local testdir2=$DIR/${tdir}/stats_testdir2
10819         mkdir -p $DIR/${tdir}
10820
10821         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10822
10823         lfs mkdir -i 0 -c 1 ${testdir1} || error "mkdir failed"
10824         lfs mkdir -i 0 -c 1 ${testdir2} || error "mkdir failed"
10825
10826         createmany -o $testdir1/test 512 || error "createmany failed"
10827
10828         # check samedir rename size
10829         mv ${testdir1}/test0 ${testdir1}/test_0
10830
10831         local testdir1_size=$(ls -l $DIR/${tdir} |
10832                 awk '/stats_testdir1/ {print $5}')
10833         local testdir2_size=$(ls -l $DIR/${tdir} |
10834                 awk '/stats_testdir2/ {print $5}')
10835
10836         testdir1_size=$(order_2 $testdir1_size)
10837         testdir2_size=$(order_2 $testdir2_size)
10838
10839         testdir1_size=$(size_in_KMGT $testdir1_size)
10840         testdir2_size=$(size_in_KMGT $testdir2_size)
10841
10842         echo "source rename dir size: ${testdir1_size}"
10843         echo "target rename dir size: ${testdir2_size}"
10844
10845         local cmd="do_facet $SINGLEMDS $LCTL "
10846         cmd+="get_param mdt.$FSNAME-MDT0000.rename_stats"
10847
10848         eval $cmd || error "$cmd failed"
10849         local samedir=$($cmd | grep 'same_dir')
10850         local same_sample=$(get_rename_size $testdir1_size)
10851         [ -z "$samedir" ] && error "samedir_rename_size count error"
10852         [[ $same_sample -eq 1 ]] ||
10853                 error "samedir_rename_size error $same_sample"
10854         echo "Check same dir rename stats success"
10855
10856         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10857
10858         # check crossdir rename size
10859         mv ${testdir1}/test_0 ${testdir2}/test_0
10860
10861         testdir1_size=$(ls -l $DIR/${tdir} |
10862                 awk '/stats_testdir1/ {print $5}')
10863         testdir2_size=$(ls -l $DIR/${tdir} |
10864                 awk '/stats_testdir2/ {print $5}')
10865
10866         testdir1_size=$(order_2 $testdir1_size)
10867         testdir2_size=$(order_2 $testdir2_size)
10868
10869         testdir1_size=$(size_in_KMGT $testdir1_size)
10870         testdir2_size=$(size_in_KMGT $testdir2_size)
10871
10872         echo "source rename dir size: ${testdir1_size}"
10873         echo "target rename dir size: ${testdir2_size}"
10874
10875         eval $cmd || error "$cmd failed"
10876         local crossdir=$($cmd | grep 'crossdir')
10877         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
10878         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
10879         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
10880         [[ $src_sample -eq 1 ]] ||
10881                 error "crossdir_rename_size error $src_sample"
10882         [[ $tgt_sample -eq 1 ]] ||
10883                 error "crossdir_rename_size error $tgt_sample"
10884         echo "Check cross dir rename stats success"
10885         rm -rf $DIR/${tdir}
10886 }
10887 run_test 133d "Verifying rename_stats ========================================"
10888
10889 test_133e() {
10890         remote_mds_nodsh && skip "remote MDS with nodsh"
10891         remote_ost_nodsh && skip "remote OST with nodsh"
10892         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10893
10894         local testdir=$DIR/${tdir}/stats_testdir
10895         local ctr f0 f1 bs=32768 count=42 sum
10896
10897         mkdir -p ${testdir} || error "mkdir failed"
10898
10899         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
10900
10901         for ctr in {write,read}_bytes; do
10902                 sync
10903                 cancel_lru_locks osc
10904
10905                 do_facet ost1 $LCTL set_param -n \
10906                         "obdfilter.*.exports.clear=clear"
10907
10908                 if [ $ctr = write_bytes ]; then
10909                         f0=/dev/zero
10910                         f1=${testdir}/${tfile}
10911                 else
10912                         f0=${testdir}/${tfile}
10913                         f1=/dev/null
10914                 fi
10915
10916                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
10917                         error "dd failed"
10918                 sync
10919                 cancel_lru_locks osc
10920
10921                 sum=$(do_facet ost1 $LCTL get_param \
10922                         "obdfilter.*.exports.*.stats" |
10923                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
10924                                 $1 == ctr { sum += $7 }
10925                                 END { printf("%0.0f", sum) }')
10926
10927                 if ((sum != bs * count)); then
10928                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
10929                 fi
10930         done
10931
10932         rm -rf $DIR/${tdir}
10933 }
10934 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
10935
10936 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
10937
10938 test_133f() {
10939         # First without trusting modes.
10940         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10941         echo "proc_dirs='$proc_dirs'"
10942         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10943         find $proc_dirs -exec cat '{}' \; &> /dev/null
10944
10945         # Second verifying readability.
10946         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
10947
10948         # Verifing writability with badarea_io.
10949         find $proc_dirs \
10950                 -ignore_readdir_race \
10951                 -type f \
10952                 -not -name force_lbug \
10953                 -not -name changelog_mask \
10954                 -exec badarea_io '{}' \; ||
10955                         error "find $proc_dirs failed"
10956 }
10957 run_test 133f "Check reads/writes of client lustre proc files with bad area io"
10958
10959 test_133g() {
10960         remote_mds_nodsh && skip "remote MDS with nodsh"
10961         remote_ost_nodsh && skip "remote OST with nodsh"
10962
10963         # eventually, this can also be replaced with "lctl get_param -R",
10964         # but not until that option is always available on the server
10965         local facet
10966         for facet in mds1 ost1; do
10967                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
10968                         skip_noexit "Too old lustre on $facet"
10969                 local facet_proc_dirs=$(do_facet $facet \
10970                                         \\\ls -d $proc_regexp 2>/dev/null)
10971                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10972                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10973                 do_facet $facet find $facet_proc_dirs \
10974                         ! -name req_history \
10975                         -exec cat '{}' \\\; &> /dev/null
10976
10977                 do_facet $facet find $facet_proc_dirs \
10978                         ! -name req_history \
10979                         -type f \
10980                         -exec cat '{}' \\\; &> /dev/null ||
10981                                 error "proc file read failed"
10982
10983                 do_facet $facet find $facet_proc_dirs \
10984                         -ignore_readdir_race \
10985                         -type f \
10986                         -not -name force_lbug \
10987                         -not -name changelog_mask \
10988                         -exec badarea_io '{}' \\\; ||
10989                                 error "$facet find $facet_proc_dirs failed"
10990         done
10991
10992         # remount the FS in case writes/reads /proc break the FS
10993         cleanup || error "failed to unmount"
10994         setup || error "failed to setup"
10995         true
10996 }
10997 run_test 133g "Check reads/writes of server lustre proc files with bad area io"
10998
10999 test_133h() {
11000         remote_mds_nodsh && skip "remote MDS with nodsh"
11001         remote_ost_nodsh && skip "remote OST with nodsh"
11002         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
11003                 skip "Need MDS version at least 2.9.54"
11004
11005         local facet
11006
11007         for facet in client mds1 ost1; do
11008                 local facet_proc_dirs=$(do_facet $facet \
11009                                         \\\ls -d $proc_regexp 2> /dev/null)
11010                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
11011                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
11012                 # Get the list of files that are missing the terminating newline
11013                 local missing=($(do_facet $facet \
11014                         find ${facet_proc_dirs} -type f \|              \
11015                                 while read F\; do                       \
11016                                         awk -v FS='\v' -v RS='\v\v'     \
11017                                         "'END { if(NR>0 &&              \
11018                                         \\\$NF !~ /.*\\\n\$/)           \
11019                                                 print FILENAME}'"       \
11020                                         '\$F'\;                         \
11021                                 done 2>/dev/null))
11022                 [ ${#missing[*]} -eq 0 ] ||
11023                         error "files do not end with newline: ${missing[*]}"
11024         done
11025 }
11026 run_test 133h "Proc files should end with newlines"
11027
11028 test_134a() {
11029         remote_mds_nodsh && skip "remote MDS with nodsh"
11030         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
11031                 skip "Need MDS version at least 2.7.54"
11032
11033         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
11034         cancel_lru_locks mdc
11035
11036         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
11037         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
11038         [ $unused -eq 0 ] || error "$unused locks are not cleared"
11039
11040         local nr=1000
11041         createmany -o $DIR/$tdir/f $nr ||
11042                 error "failed to create $nr files in $DIR/$tdir"
11043         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
11044
11045         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
11046         do_facet mds1 $LCTL set_param fail_loc=0x327
11047         do_facet mds1 $LCTL set_param fail_val=500
11048         touch $DIR/$tdir/m
11049
11050         echo "sleep 10 seconds ..."
11051         sleep 10
11052         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
11053
11054         do_facet mds1 $LCTL set_param fail_loc=0
11055         do_facet mds1 $LCTL set_param fail_val=0
11056         [ $lck_cnt -lt $unused ] ||
11057                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
11058
11059         rm $DIR/$tdir/m
11060         unlinkmany $DIR/$tdir/f $nr
11061 }
11062 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
11063
11064 test_134b() {
11065         remote_mds_nodsh && skip "remote MDS with nodsh"
11066         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
11067                 skip "Need MDS version at least 2.7.54"
11068
11069         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
11070         cancel_lru_locks mdc
11071
11072         local low_wm=$(do_facet mds1 $LCTL get_param -n \
11073                         ldlm.lock_reclaim_threshold_mb)
11074         # disable reclaim temporarily
11075         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
11076
11077         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
11078         do_facet mds1 $LCTL set_param fail_loc=0x328
11079         do_facet mds1 $LCTL set_param fail_val=500
11080
11081         $LCTL set_param debug=+trace
11082
11083         local nr=600
11084         createmany -o $DIR/$tdir/f $nr &
11085         local create_pid=$!
11086
11087         echo "Sleep $TIMEOUT seconds ..."
11088         sleep $TIMEOUT
11089         if ! ps -p $create_pid  > /dev/null 2>&1; then
11090                 do_facet mds1 $LCTL set_param fail_loc=0
11091                 do_facet mds1 $LCTL set_param fail_val=0
11092                 do_facet mds1 $LCTL set_param \
11093                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
11094                 error "createmany finished incorrectly!"
11095         fi
11096         do_facet mds1 $LCTL set_param fail_loc=0
11097         do_facet mds1 $LCTL set_param fail_val=0
11098         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
11099         wait $create_pid || return 1
11100
11101         unlinkmany $DIR/$tdir/f $nr
11102 }
11103 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
11104
11105 test_140() { #bug-17379
11106         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11107
11108         test_mkdir $DIR/$tdir
11109         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
11110         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
11111
11112         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
11113         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
11114         local i=0
11115         while i=$((i + 1)); do
11116                 test_mkdir $i
11117                 cd $i || error "Changing to $i"
11118                 ln -s ../stat stat || error "Creating stat symlink"
11119                 # Read the symlink until ELOOP present,
11120                 # not LBUGing the system is considered success,
11121                 # we didn't overrun the stack.
11122                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
11123                 if [ $ret -ne 0 ]; then
11124                         if [ $ret -eq 40 ]; then
11125                                 break  # -ELOOP
11126                         else
11127                                 error "Open stat symlink"
11128                                         return
11129                         fi
11130                 fi
11131         done
11132         i=$((i - 1))
11133         echo "The symlink depth = $i"
11134         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
11135                                         error "Invalid symlink depth"
11136
11137         # Test recursive symlink
11138         ln -s symlink_self symlink_self
11139         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
11140         echo "open symlink_self returns $ret"
11141         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
11142 }
11143 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
11144
11145 test_150() {
11146         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11147
11148         local TF="$TMP/$tfile"
11149
11150         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
11151         cp $TF $DIR/$tfile
11152         cancel_lru_locks $OSC
11153         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
11154         remount_client $MOUNT
11155         df -P $MOUNT
11156         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
11157
11158         $TRUNCATE $TF 6000
11159         $TRUNCATE $DIR/$tfile 6000
11160         cancel_lru_locks $OSC
11161         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
11162
11163         echo "12345" >>$TF
11164         echo "12345" >>$DIR/$tfile
11165         cancel_lru_locks $OSC
11166         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
11167
11168         echo "12345" >>$TF
11169         echo "12345" >>$DIR/$tfile
11170         cancel_lru_locks $OSC
11171         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
11172
11173         rm -f $TF
11174         true
11175 }
11176 run_test 150 "truncate/append tests"
11177
11178 #LU-2902 roc_hit was not able to read all values from lproc
11179 function roc_hit_init() {
11180         local list=$(comma_list $(osts_nodes))
11181         local dir=$DIR/$tdir-check
11182         local file=$dir/$tfile
11183         local BEFORE
11184         local AFTER
11185         local idx
11186
11187         test_mkdir $dir
11188         #use setstripe to do a write to every ost
11189         for i in $(seq 0 $((OSTCOUNT-1))); do
11190                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
11191                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
11192                 idx=$(printf %04x $i)
11193                 BEFORE=$(get_osd_param $list *OST*$idx stats |
11194                         awk '$1 == "cache_access" {sum += $7}
11195                                 END { printf("%0.0f", sum) }')
11196
11197                 cancel_lru_locks osc
11198                 cat $file >/dev/null
11199
11200                 AFTER=$(get_osd_param $list *OST*$idx stats |
11201                         awk '$1 == "cache_access" {sum += $7}
11202                                 END { printf("%0.0f", sum) }')
11203
11204                 echo BEFORE:$BEFORE AFTER:$AFTER
11205                 if ! let "AFTER - BEFORE == 4"; then
11206                         rm -rf $dir
11207                         error "roc_hit is not safe to use"
11208                 fi
11209                 rm $file
11210         done
11211
11212         rm -rf $dir
11213 }
11214
11215 function roc_hit() {
11216         local list=$(comma_list $(osts_nodes))
11217         echo $(get_osd_param $list '' stats |
11218                 awk '$1 == "cache_hit" {sum += $7}
11219                         END { printf("%0.0f", sum) }')
11220 }
11221
11222 function set_cache() {
11223         local on=1
11224
11225         if [ "$2" == "off" ]; then
11226                 on=0;
11227         fi
11228         local list=$(comma_list $(osts_nodes))
11229         set_osd_param $list '' $1_cache_enable $on
11230
11231         cancel_lru_locks osc
11232 }
11233
11234 test_151() {
11235         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11236         remote_ost_nodsh && skip "remote OST with nodsh"
11237
11238         local CPAGES=3
11239         local list=$(comma_list $(osts_nodes))
11240
11241         # check whether obdfilter is cache capable at all
11242         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
11243                 skip "not cache-capable obdfilter"
11244         fi
11245
11246         # check cache is enabled on all obdfilters
11247         if get_osd_param $list '' read_cache_enable | grep 0; then
11248                 skip "oss cache is disabled"
11249         fi
11250
11251         set_osd_param $list '' writethrough_cache_enable 1
11252
11253         # check write cache is enabled on all obdfilters
11254         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
11255                 skip "oss write cache is NOT enabled"
11256         fi
11257
11258         roc_hit_init
11259
11260         #define OBD_FAIL_OBD_NO_LRU  0x609
11261         do_nodes $list $LCTL set_param fail_loc=0x609
11262
11263         # pages should be in the case right after write
11264         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
11265                 error "dd failed"
11266
11267         local BEFORE=$(roc_hit)
11268         cancel_lru_locks osc
11269         cat $DIR/$tfile >/dev/null
11270         local AFTER=$(roc_hit)
11271
11272         do_nodes $list $LCTL set_param fail_loc=0
11273
11274         if ! let "AFTER - BEFORE == CPAGES"; then
11275                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11276         fi
11277
11278         # the following read invalidates the cache
11279         cancel_lru_locks osc
11280         set_osd_param $list '' read_cache_enable 0
11281         cat $DIR/$tfile >/dev/null
11282
11283         # now data shouldn't be found in the cache
11284         BEFORE=$(roc_hit)
11285         cancel_lru_locks osc
11286         cat $DIR/$tfile >/dev/null
11287         AFTER=$(roc_hit)
11288         if let "AFTER - BEFORE != 0"; then
11289                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11290         fi
11291
11292         set_osd_param $list '' read_cache_enable 1
11293         rm -f $DIR/$tfile
11294 }
11295 run_test 151 "test cache on oss and controls ==============================="
11296
11297 test_152() {
11298         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11299
11300         local TF="$TMP/$tfile"
11301
11302         # simulate ENOMEM during write
11303 #define OBD_FAIL_OST_NOMEM      0x226
11304         lctl set_param fail_loc=0x80000226
11305         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
11306         cp $TF $DIR/$tfile
11307         sync || error "sync failed"
11308         lctl set_param fail_loc=0
11309
11310         # discard client's cache
11311         cancel_lru_locks osc
11312
11313         # simulate ENOMEM during read
11314         lctl set_param fail_loc=0x80000226
11315         cmp $TF $DIR/$tfile || error "cmp failed"
11316         lctl set_param fail_loc=0
11317
11318         rm -f $TF
11319 }
11320 run_test 152 "test read/write with enomem ============================"
11321
11322 test_153() {
11323         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
11324 }
11325 run_test 153 "test if fdatasync does not crash ======================="
11326
11327 dot_lustre_fid_permission_check() {
11328         local fid=$1
11329         local ffid=$MOUNT/.lustre/fid/$fid
11330         local test_dir=$2
11331
11332         echo "stat fid $fid"
11333         stat $ffid > /dev/null || error "stat $ffid failed."
11334         echo "touch fid $fid"
11335         touch $ffid || error "touch $ffid failed."
11336         echo "write to fid $fid"
11337         cat /etc/hosts > $ffid || error "write $ffid failed."
11338         echo "read fid $fid"
11339         diff /etc/hosts $ffid || error "read $ffid failed."
11340         echo "append write to fid $fid"
11341         cat /etc/hosts >> $ffid || error "append write $ffid failed."
11342         echo "rename fid $fid"
11343         mv $ffid $test_dir/$tfile.1 &&
11344                 error "rename $ffid to $tfile.1 should fail."
11345         touch $test_dir/$tfile.1
11346         mv $test_dir/$tfile.1 $ffid &&
11347                 error "rename $tfile.1 to $ffid should fail."
11348         rm -f $test_dir/$tfile.1
11349         echo "truncate fid $fid"
11350         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
11351         echo "link fid $fid"
11352         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
11353         if [[ $($LCTL get_param -n mdc.*-mdc-*.connect_flags) =~ acl ]]; then
11354                 echo "setfacl fid $fid"
11355                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
11356                 echo "getfacl fid $fid"
11357                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
11358         fi
11359         echo "unlink fid $fid"
11360         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
11361         echo "mknod fid $fid"
11362         mknod $ffid c 1 3 && error "mknod $ffid should fail."
11363
11364         fid=[0xf00000400:0x1:0x0]
11365         ffid=$MOUNT/.lustre/fid/$fid
11366
11367         echo "stat non-exist fid $fid"
11368         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
11369         echo "write to non-exist fid $fid"
11370         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
11371         echo "link new fid $fid"
11372         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
11373
11374         mkdir -p $test_dir/$tdir
11375         touch $test_dir/$tdir/$tfile
11376         fid=$($LFS path2fid $test_dir/$tdir)
11377         rc=$?
11378         [ $rc -ne 0 ] &&
11379                 error "error: could not get fid for $test_dir/$dir/$tfile."
11380
11381         ffid=$MOUNT/.lustre/fid/$fid
11382
11383         echo "ls $fid"
11384         ls $ffid > /dev/null || error "ls $ffid failed."
11385         echo "touch $fid/$tfile.1"
11386         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
11387
11388         echo "touch $MOUNT/.lustre/fid/$tfile"
11389         touch $MOUNT/.lustre/fid/$tfile && \
11390                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
11391
11392         echo "setxattr to $MOUNT/.lustre/fid"
11393         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
11394
11395         echo "listxattr for $MOUNT/.lustre/fid"
11396         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
11397
11398         echo "delxattr from $MOUNT/.lustre/fid"
11399         setfattr -x trusted.name1 $MOUNT/.lustre/fid
11400
11401         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
11402         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
11403                 error "touch invalid fid should fail."
11404
11405         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
11406         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
11407                 error "touch non-normal fid should fail."
11408
11409         echo "rename $tdir to $MOUNT/.lustre/fid"
11410         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
11411                 error "rename to $MOUNT/.lustre/fid should fail."
11412
11413         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
11414         then            # LU-3547
11415                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
11416                 local new_obf_mode=777
11417
11418                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
11419                 chmod $new_obf_mode $DIR/.lustre/fid ||
11420                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
11421
11422                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
11423                 [ $obf_mode -eq $new_obf_mode ] ||
11424                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
11425
11426                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
11427                 chmod $old_obf_mode $DIR/.lustre/fid ||
11428                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
11429         fi
11430
11431         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
11432         fid=$($LFS path2fid $test_dir/$tfile-2)
11433
11434         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
11435         then # LU-5424
11436                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
11437                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
11438                         error "create lov data thru .lustre failed"
11439         fi
11440         echo "cp /etc/passwd $test_dir/$tfile-2"
11441         cp /etc/passwd $test_dir/$tfile-2 ||
11442                 error "copy to $test_dir/$tfile-2 failed."
11443         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
11444         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
11445                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
11446
11447         rm -rf $test_dir/tfile.lnk
11448         rm -rf $test_dir/$tfile-2
11449 }
11450
11451 test_154A() {
11452         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11453                 skip "Need MDS version at least 2.4.1"
11454
11455         local tf=$DIR/$tfile
11456         touch $tf
11457
11458         local fid=$($LFS path2fid $tf)
11459         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
11460
11461         # check that we get the same pathname back
11462         local found=$($LFS fid2path $MOUNT "$fid")
11463         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
11464         [ "$found" == "$tf" ] ||
11465                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
11466 }
11467 run_test 154A "lfs path2fid and fid2path basic checks"
11468
11469 test_154B() {
11470         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11471                 skip "Need MDS version at least 2.4.1"
11472
11473         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
11474         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
11475         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
11476         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
11477
11478         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
11479         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
11480
11481         # check that we get the same pathname
11482         echo "PFID: $PFID, name: $name"
11483         local FOUND=$($LFS fid2path $MOUNT "$PFID")
11484         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
11485         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
11486                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
11487
11488         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
11489 }
11490 run_test 154B "verify the ll_decode_linkea tool"
11491
11492 test_154a() {
11493         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11494         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
11495         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
11496                 skip "Need MDS version at least 2.2.51"
11497         [ -z "$(which setfacl)" ] && skip_env "must have setfacl tool"
11498
11499         cp /etc/hosts $DIR/$tfile
11500
11501         fid=$($LFS path2fid $DIR/$tfile)
11502         rc=$?
11503         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
11504
11505         dot_lustre_fid_permission_check "$fid" $DIR ||
11506                 error "dot lustre permission check $fid failed"
11507
11508         ls -a $MOUNT | grep "\.lustre" && error ".lustre should not be listed"
11509
11510         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
11511
11512         touch $MOUNT/.lustre/file &&
11513                 error "creation is not allowed under .lustre"
11514
11515         mkdir $MOUNT/.lustre/dir &&
11516                 error "mkdir is not allowed under .lustre"
11517
11518         rm -rf $DIR/$tfile
11519 }
11520 run_test 154a "Open-by-FID"
11521
11522 test_154b() {
11523         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11524         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
11525         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
11526         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
11527                 skip "Need MDS version at least 2.2.51"
11528
11529         local remote_dir=$DIR/$tdir/remote_dir
11530         local MDTIDX=1
11531         local rc=0
11532
11533         mkdir -p $DIR/$tdir
11534         $LFS mkdir -i $MDTIDX $remote_dir ||
11535                 error "create remote directory failed"
11536
11537         cp /etc/hosts $remote_dir/$tfile
11538
11539         fid=$($LFS path2fid $remote_dir/$tfile)
11540         rc=$?
11541         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
11542
11543         dot_lustre_fid_permission_check "$fid" $remote_dir ||
11544                 error "dot lustre permission check $fid failed"
11545         rm -rf $DIR/$tdir
11546 }
11547 run_test 154b "Open-by-FID for remote directory"
11548
11549 test_154c() {
11550         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11551                 skip "Need MDS version at least 2.4.1"
11552
11553         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
11554         local FID1=$($LFS path2fid $DIR/$tfile.1)
11555         local FID2=$($LFS path2fid $DIR/$tfile.2)
11556         local FID3=$($LFS path2fid $DIR/$tfile.3)
11557
11558         local N=1
11559         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
11560                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
11561                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
11562                 local want=FID$N
11563                 [ "$FID" = "${!want}" ] ||
11564                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
11565                 N=$((N + 1))
11566         done
11567
11568         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
11569         do
11570                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
11571                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
11572                 N=$((N + 1))
11573         done
11574 }
11575 run_test 154c "lfs path2fid and fid2path multiple arguments"
11576
11577 test_154d() {
11578         remote_mds_nodsh && skip "remote MDS with nodsh"
11579         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
11580                 skip "Need MDS version at least 2.5.53"
11581
11582         if remote_mds; then
11583                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
11584         else
11585                 nid="0@lo"
11586         fi
11587         local proc_ofile="mdt.*.exports.'$nid'.open_files"
11588         local fd
11589         local cmd
11590
11591         rm -f $DIR/$tfile
11592         touch $DIR/$tfile
11593
11594         local fid=$($LFS path2fid $DIR/$tfile)
11595         # Open the file
11596         fd=$(free_fd)
11597         cmd="exec $fd<$DIR/$tfile"
11598         eval $cmd
11599         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
11600         echo "$fid_list" | grep "$fid"
11601         rc=$?
11602
11603         cmd="exec $fd>/dev/null"
11604         eval $cmd
11605         if [ $rc -ne 0 ]; then
11606                 error "FID $fid not found in open files list $fid_list"
11607         fi
11608 }
11609 run_test 154d "Verify open file fid"
11610
11611 test_154e()
11612 {
11613         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
11614                 skip "Need MDS version at least 2.6.50"
11615
11616         if ls -a $MOUNT | grep -q '^\.lustre$'; then
11617                 error ".lustre returned by readdir"
11618         fi
11619 }
11620 run_test 154e ".lustre is not returned by readdir"
11621
11622 test_154f() {
11623         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
11624
11625         # create parent directory on a single MDT to avoid cross-MDT hardlinks
11626         test_mkdir -p -c1 $DIR/$tdir/d
11627         # test dirs inherit from its stripe
11628         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
11629         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
11630         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
11631         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
11632         touch $DIR/f
11633
11634         # get fid of parents
11635         local FID0=$($LFS path2fid $DIR/$tdir/d)
11636         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
11637         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
11638         local FID3=$($LFS path2fid $DIR)
11639
11640         # check that path2fid --parents returns expected <parent_fid>/name
11641         # 1) test for a directory (single parent)
11642         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
11643         [ "$parent" == "$FID0/foo1" ] ||
11644                 error "expected parent: $FID0/foo1, got: $parent"
11645
11646         # 2) test for a file with nlink > 1 (multiple parents)
11647         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
11648         echo "$parent" | grep -F "$FID1/$tfile" ||
11649                 error "$FID1/$tfile not returned in parent list"
11650         echo "$parent" | grep -F "$FID2/link" ||
11651                 error "$FID2/link not returned in parent list"
11652
11653         # 3) get parent by fid
11654         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
11655         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11656         echo "$parent" | grep -F "$FID1/$tfile" ||
11657                 error "$FID1/$tfile not returned in parent list (by fid)"
11658         echo "$parent" | grep -F "$FID2/link" ||
11659                 error "$FID2/link not returned in parent list (by fid)"
11660
11661         # 4) test for entry in root directory
11662         parent=$($LFS path2fid --parents $DIR/f)
11663         echo "$parent" | grep -F "$FID3/f" ||
11664                 error "$FID3/f not returned in parent list"
11665
11666         # 5) test it on root directory
11667         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
11668                 error "$MOUNT should not have parents"
11669
11670         # enable xattr caching and check that linkea is correctly updated
11671         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
11672         save_lustre_params client "llite.*.xattr_cache" > $save
11673         lctl set_param llite.*.xattr_cache 1
11674
11675         # 6.1) linkea update on rename
11676         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
11677
11678         # get parents by fid
11679         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11680         # foo1 should no longer be returned in parent list
11681         echo "$parent" | grep -F "$FID1" &&
11682                 error "$FID1 should no longer be in parent list"
11683         # the new path should appear
11684         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
11685                 error "$FID2/$tfile.moved is not in parent list"
11686
11687         # 6.2) linkea update on unlink
11688         rm -f $DIR/$tdir/d/foo2/link
11689         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11690         # foo2/link should no longer be returned in parent list
11691         echo "$parent" | grep -F "$FID2/link" &&
11692                 error "$FID2/link should no longer be in parent list"
11693         true
11694
11695         rm -f $DIR/f
11696         restore_lustre_params < $save
11697         rm -f $save
11698 }
11699 run_test 154f "get parent fids by reading link ea"
11700
11701 test_154g()
11702 {
11703         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
11704         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) && \
11705            $(lustre_version_code client) -gt $(version_code 2.6.99) ]] ||
11706                 skip "Need MDS version at least 2.6.92"
11707
11708         mkdir -p $DIR/$tdir
11709         llapi_fid_test -d $DIR/$tdir
11710 }
11711 run_test 154g "various llapi FID tests"
11712
11713 test_155_small_load() {
11714     local temp=$TMP/$tfile
11715     local file=$DIR/$tfile
11716
11717     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
11718         error "dd of=$temp bs=6096 count=1 failed"
11719     cp $temp $file
11720     cancel_lru_locks $OSC
11721     cmp $temp $file || error "$temp $file differ"
11722
11723     $TRUNCATE $temp 6000
11724     $TRUNCATE $file 6000
11725     cmp $temp $file || error "$temp $file differ (truncate1)"
11726
11727     echo "12345" >>$temp
11728     echo "12345" >>$file
11729     cmp $temp $file || error "$temp $file differ (append1)"
11730
11731     echo "12345" >>$temp
11732     echo "12345" >>$file
11733     cmp $temp $file || error "$temp $file differ (append2)"
11734
11735     rm -f $temp $file
11736     true
11737 }
11738
11739 test_155_big_load() {
11740         remote_ost_nodsh && skip "remote OST with nodsh"
11741
11742         local temp=$TMP/$tfile
11743         local file=$DIR/$tfile
11744
11745         free_min_max
11746         local cache_size=$(do_facet ost$((MAXI+1)) \
11747                 "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
11748         local large_file_size=$((cache_size * 2))
11749
11750         echo "OSS cache size: $cache_size KB"
11751         echo "Large file size: $large_file_size KB"
11752
11753         [ $MAXV -le $large_file_size ] &&
11754                 skip_env "max available OST size needs > $large_file_size KB"
11755
11756         $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
11757
11758         dd if=/dev/urandom of=$temp bs=$large_file_size count=1k ||
11759                 error "dd of=$temp bs=$large_file_size count=1k failed"
11760         cp $temp $file
11761         ls -lh $temp $file
11762         cancel_lru_locks osc
11763         cmp $temp $file || error "$temp $file differ"
11764
11765         rm -f $temp $file
11766         true
11767 }
11768
11769 save_writethrough() {
11770         local facets=$(get_facets OST)
11771
11772         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
11773         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
11774 }
11775
11776 test_155a() {
11777         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11778
11779         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11780
11781         save_writethrough $p
11782
11783         set_cache read on
11784         set_cache writethrough on
11785         test_155_small_load
11786         restore_lustre_params < $p
11787         rm -f $p
11788 }
11789 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
11790
11791 test_155b() {
11792         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11793
11794         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11795
11796         save_writethrough $p
11797
11798         set_cache read on
11799         set_cache writethrough off
11800         test_155_small_load
11801         restore_lustre_params < $p
11802         rm -f $p
11803 }
11804 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
11805
11806 test_155c() {
11807         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11808
11809         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11810
11811         save_writethrough $p
11812
11813         set_cache read off
11814         set_cache writethrough on
11815         test_155_small_load
11816         restore_lustre_params < $p
11817         rm -f $p
11818 }
11819 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
11820
11821 test_155d() {
11822         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11823
11824         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11825
11826         save_writethrough $p
11827
11828         set_cache read off
11829         set_cache writethrough off
11830         test_155_small_load
11831         restore_lustre_params < $p
11832         rm -f $p
11833 }
11834 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
11835
11836 test_155e() {
11837         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11838
11839         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11840
11841         save_writethrough $p
11842
11843         set_cache read on
11844         set_cache writethrough on
11845         test_155_big_load
11846         restore_lustre_params < $p
11847         rm -f $p
11848 }
11849 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
11850
11851 test_155f() {
11852         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11853
11854         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11855
11856         save_writethrough $p
11857
11858         set_cache read on
11859         set_cache writethrough off
11860         test_155_big_load
11861         restore_lustre_params < $p
11862         rm -f $p
11863 }
11864 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
11865
11866 test_155g() {
11867         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11868
11869         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11870
11871         save_writethrough $p
11872
11873         set_cache read off
11874         set_cache writethrough on
11875         test_155_big_load
11876         restore_lustre_params < $p
11877         rm -f $p
11878 }
11879 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
11880
11881 test_155h() {
11882         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11883
11884         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11885
11886         save_writethrough $p
11887
11888         set_cache read off
11889         set_cache writethrough off
11890         test_155_big_load
11891         restore_lustre_params < $p
11892         rm -f $p
11893 }
11894 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
11895
11896 test_156() {
11897         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11898         remote_ost_nodsh && skip "remote OST with nodsh"
11899         [ "$(facet_fstype ost1)" = "zfs" -a \
11900            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
11901                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS"
11902
11903         local CPAGES=3
11904         local BEFORE
11905         local AFTER
11906         local file="$DIR/$tfile"
11907         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11908
11909         save_writethrough $p
11910         roc_hit_init
11911
11912         log "Turn on read and write cache"
11913         set_cache read on
11914         set_cache writethrough on
11915
11916         log "Write data and read it back."
11917         log "Read should be satisfied from the cache."
11918         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11919         BEFORE=$(roc_hit)
11920         cancel_lru_locks osc
11921         cat $file >/dev/null
11922         AFTER=$(roc_hit)
11923         if ! let "AFTER - BEFORE == CPAGES"; then
11924                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11925         else
11926                 log "cache hits:: before: $BEFORE, after: $AFTER"
11927         fi
11928
11929         log "Read again; it should be satisfied from the cache."
11930         BEFORE=$AFTER
11931         cancel_lru_locks osc
11932         cat $file >/dev/null
11933         AFTER=$(roc_hit)
11934         if ! let "AFTER - BEFORE == CPAGES"; then
11935                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11936         else
11937                 log "cache hits:: before: $BEFORE, after: $AFTER"
11938         fi
11939
11940         log "Turn off the read cache and turn on the write cache"
11941         set_cache read off
11942         set_cache writethrough on
11943
11944         log "Read again; it should be satisfied from the cache."
11945         BEFORE=$(roc_hit)
11946         cancel_lru_locks osc
11947         cat $file >/dev/null
11948         AFTER=$(roc_hit)
11949         if ! let "AFTER - BEFORE == CPAGES"; then
11950                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11951         else
11952                 log "cache hits:: before: $BEFORE, after: $AFTER"
11953         fi
11954
11955         log "Read again; it should not be satisfied from the cache."
11956         BEFORE=$AFTER
11957         cancel_lru_locks osc
11958         cat $file >/dev/null
11959         AFTER=$(roc_hit)
11960         if ! let "AFTER - BEFORE == 0"; then
11961                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11962         else
11963                 log "cache hits:: before: $BEFORE, after: $AFTER"
11964         fi
11965
11966         log "Write data and read it back."
11967         log "Read should be satisfied from the cache."
11968         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11969         BEFORE=$(roc_hit)
11970         cancel_lru_locks osc
11971         cat $file >/dev/null
11972         AFTER=$(roc_hit)
11973         if ! let "AFTER - BEFORE == CPAGES"; then
11974                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11975         else
11976                 log "cache hits:: before: $BEFORE, after: $AFTER"
11977         fi
11978
11979         log "Read again; it should not be satisfied from the cache."
11980         BEFORE=$AFTER
11981         cancel_lru_locks osc
11982         cat $file >/dev/null
11983         AFTER=$(roc_hit)
11984         if ! let "AFTER - BEFORE == 0"; then
11985                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11986         else
11987                 log "cache hits:: before: $BEFORE, after: $AFTER"
11988         fi
11989
11990         log "Turn off read and write cache"
11991         set_cache read off
11992         set_cache writethrough off
11993
11994         log "Write data and read it back"
11995         log "It should not be satisfied from the cache."
11996         rm -f $file
11997         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11998         cancel_lru_locks osc
11999         BEFORE=$(roc_hit)
12000         cat $file >/dev/null
12001         AFTER=$(roc_hit)
12002         if ! let "AFTER - BEFORE == 0"; then
12003                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
12004         else
12005                 log "cache hits:: before: $BEFORE, after: $AFTER"
12006         fi
12007
12008         log "Turn on the read cache and turn off the write cache"
12009         set_cache read on
12010         set_cache writethrough off
12011
12012         log "Write data and read it back"
12013         log "It should not be satisfied from the cache."
12014         rm -f $file
12015         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
12016         BEFORE=$(roc_hit)
12017         cancel_lru_locks osc
12018         cat $file >/dev/null
12019         AFTER=$(roc_hit)
12020         if ! let "AFTER - BEFORE == 0"; then
12021                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
12022         else
12023                 log "cache hits:: before: $BEFORE, after: $AFTER"
12024         fi
12025
12026         log "Read again; it should be satisfied from the cache."
12027         BEFORE=$(roc_hit)
12028         cancel_lru_locks osc
12029         cat $file >/dev/null
12030         AFTER=$(roc_hit)
12031         if ! let "AFTER - BEFORE == CPAGES"; then
12032                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
12033         else
12034                 log "cache hits:: before: $BEFORE, after: $AFTER"
12035         fi
12036
12037         restore_lustre_params < $p
12038         rm -f $p $file
12039 }
12040 run_test 156 "Verification of tunables"
12041
12042 test_160a() {
12043         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12044         remote_mds_nodsh && skip "remote MDS with nodsh"
12045         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
12046                 skip "Need MDS version at least 2.2.0"
12047
12048         changelog_register || error "changelog_register failed"
12049         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
12050         changelog_users $SINGLEMDS | grep -q $cl_user ||
12051                 error "User $cl_user not found in changelog_users"
12052
12053         # change something
12054         test_mkdir -p $DIR/$tdir/pics/2008/zachy
12055         changelog_clear 0 || error "changelog_clear failed"
12056         touch $DIR/$tdir/pics/2008/zachy/$tfile                 # open 1
12057         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg       # open 2
12058         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
12059         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
12060         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
12061         rm $DIR/$tdir/pics/desktop.jpg
12062
12063         changelog_dump | tail -10
12064
12065         echo "verifying changelog mask"
12066         changelog_chmask "-MKDIR"
12067         changelog_chmask "-CLOSE"
12068
12069         test_mkdir -p $DIR/$tdir/pics/zach/sofia                # not logged
12070         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # not logged
12071
12072         changelog_chmask "+MKDIR"
12073         changelog_chmask "+CLOSE"
12074
12075         test_mkdir -p $DIR/$tdir/pics/2008/sofia                # mkdir 1
12076         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # open 3
12077
12078         changelog_dump | tail -10
12079         MKDIRS=$(changelog_dump | grep -c "MKDIR")
12080         CLOSES=$(changelog_dump | grep -c "CLOSE")
12081         [ $MKDIRS -eq 1 ] || error "MKDIR changelog mask count $MKDIRS != 1"
12082         [ $CLOSES -eq 3 ] || error "CLOSE changelog mask count $CLOSES != 3"
12083
12084         # verify contents
12085         echo "verifying target fid"
12086         local fidc=$(changelog_extract_field "CREAT" "$tfile" "t=")
12087         local fidf=$($LFS path2fid $DIR/$tdir/pics/zach/$tfile)
12088         [ "$fidc" == "$fidf" ] ||
12089                 error "changelog '$tfile' fid $fidc != file fid $fidf"
12090         echo "verifying parent fid"
12091         # The FID returned from the Changelog may be the directory shard on
12092         # a different MDT, and not the FID returned by path2fid on the parent.
12093         # Instead of comparing FIDs, verify that fid2path(fidp) is correct,
12094         # since this is what will matter when recreating this file in the tree.
12095         local fidp=$(changelog_extract_field "CREAT" "$tfile" "p=")
12096         local pathp=$($LFS fid2path $MOUNT "$fidp")
12097         [ "${pathp%/}" == "$DIR/$tdir/pics/zach" ] ||
12098                 error "changelog fid2path($fidc) $pathp != $DIR/$tdir/pics/zach"
12099
12100         echo "getting records for $cl_user"
12101         changelog_users $SINGLEMDS
12102         local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user)
12103         local nclr=3
12104         __changelog_clear $SINGLEMDS $cl_user +$nclr ||
12105                 error "changelog_clear failed"
12106         local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user)
12107         echo "verifying user clear: $user_rec1 + $nclr == $user_rec2"
12108         [ $user_rec2 == $((user_rec1 + nclr)) ] ||
12109                 error "user index expect $user_rec1 + $nclr != $user_rec2"
12110
12111         local min0_rec=$(changelog_users $SINGLEMDS |
12112                 awk 'min == "" || $2 < min { min = $2 }; END { print min }')
12113         local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
12114                           awk '{ print $1; exit; }')
12115
12116         changelog_dump | tail -n 5
12117         echo "verifying user min purge: $min0_rec + 1 == $first_rec"
12118         [ $first_rec == $((min0_rec + 1)) ] ||
12119                 error "first index should be $min0_rec + 1 not $first_rec"
12120
12121         # LU-3446 changelog index reset on MDT restart
12122         local cur_rec1=$(changelog_users $SINGLEMDS |
12123                          awk '/^current.index:/ { print $NF }')
12124         changelog_clear 0 ||
12125                 error "clear all changelog records for $cl_user failed"
12126         stop $SINGLEMDS || error "Fail to stop $SINGLEMDS"
12127         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
12128                 error "Fail to start $SINGLEMDS"
12129         local cur_rec2=$(changelog_users $SINGLEMDS |
12130                          awk '/^current.index:/ { print $NF }')
12131         echo "verifying index survives MDT restart: $cur_rec1 == $cur_rec2"
12132         [ $cur_rec1 == $cur_rec2 ] ||
12133                 error "current index should be $cur_rec1 not $cur_rec2"
12134
12135         echo "verifying users from this test are deregistered"
12136         changelog_deregister || error "changelog_deregister failed"
12137         changelog_users $SINGLEMDS | grep -q $cl_user &&
12138                 error "User '$cl_user' still in changelog_users"
12139
12140         # lctl get_param -n mdd.*.changelog_users
12141         # current index: 144
12142         # ID    index (idle seconds)
12143         # cl3   144 (2)
12144         if ! changelog_users $SINGLEMDS | grep "^cl"; then
12145                 # this is the normal case where all users were deregistered
12146                 # make sure no new records are added when no users are present
12147                 local last_rec1=$(changelog_users $SINGLEMDS |
12148                                   awk '/^current.index:/ { print $NF }')
12149                 touch $DIR/$tdir/chloe
12150                 local last_rec2=$(changelog_users $SINGLEMDS |
12151                                   awk '/^current.index:/ { print $NF }')
12152                 echo "verify changelogs are off: $last_rec1 == $last_rec2"
12153                 [ $last_rec1 == $last_rec2 ] || error "changelogs not off"
12154         else
12155                 # any changelog users must be leftovers from a previous test
12156                 changelog_users $SINGLEMDS
12157                 echo "other changelog users; can't verify off"
12158         fi
12159 }
12160 run_test 160a "changelog sanity"
12161
12162 test_160b() { # LU-3587
12163         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12164         remote_mds_nodsh && skip "remote MDS with nodsh"
12165         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
12166                 skip "Need MDS version at least 2.2.0"
12167
12168         changelog_register || error "changelog_register failed"
12169         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
12170         changelog_users $SINGLEMDS | grep -q $cl_user ||
12171                 error "User '$cl_user' not found in changelog_users"
12172
12173         local longname1=$(str_repeat a 255)
12174         local longname2=$(str_repeat b 255)
12175
12176         cd $DIR
12177         echo "creating very long named file"
12178         touch $longname1 || error "create of '$longname1' failed"
12179         echo "renaming very long named file"
12180         mv $longname1 $longname2
12181
12182         changelog_dump | grep RENME | tail -n 5
12183         rm -f $longname2
12184 }
12185 run_test 160b "Verify that very long rename doesn't crash in changelog"
12186
12187 test_160c() {
12188         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12189         remote_mds_nodsh && skip "remote MDS with nodsh"
12190
12191         local rc=0
12192         local server_version=$(lustre_version_code $SINGLEMDS)
12193
12194         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12195                 [[ $server_version -gt $(version_code 2.5.1) &&
12196                    $server_version -lt $(version_code 2.5.50) ]] ||
12197                 skip "Need MDS version at least 2.5.58 or 2.5.2+"
12198
12199         # Registration step
12200         changelog_register || error "changelog_register failed"
12201
12202         rm -rf $DIR/$tdir
12203         mkdir -p $DIR/$tdir
12204         $MCREATE $DIR/$tdir/foo_160c
12205         changelog_chmask "-TRUNC"
12206         $TRUNCATE $DIR/$tdir/foo_160c 200
12207         changelog_chmask "+TRUNC"
12208         $TRUNCATE $DIR/$tdir/foo_160c 199
12209         changelog_dump | tail -n 5
12210         local truncs=$(changelog_dump | tail -n 5 | grep -c TRUNC)
12211         [ $truncs -eq 1 ] || error "TRUNC changelog mask count $truncs != 1"
12212 }
12213 run_test 160c "verify that changelog log catch the truncate event"
12214
12215 test_160d() {
12216         remote_mds_nodsh && skip "remote MDS with nodsh"
12217         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
12218         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12219         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.60) ]] ||
12220                 skip "Need MDS version at least 2.7.60"
12221
12222         # Registration step
12223         changelog_register || error "changelog_register failed"
12224
12225         mkdir -p $DIR/$tdir/migrate_dir
12226         changelog_clear 0 || error "changelog_clear failed"
12227
12228         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
12229         changelog_dump | tail -n 5
12230         local migrates=$(changelog_dump | grep -c "MIGRT")
12231         [ $migrates -eq 1 ] || error "MIGRATE changelog count $migrates != 1"
12232 }
12233 run_test 160d "verify that changelog log catch the migrate event"
12234
12235 test_160e() {
12236         remote_mds_nodsh && skip "remote MDS with nodsh"
12237
12238         # Create a user
12239         changelog_register || error "changelog_register failed"
12240
12241         # Delete a future user (expect fail)
12242         local MDT0=$(facet_svc $SINGLEMDS)
12243         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister "cl77"
12244         local rc=$?
12245
12246         if [ $rc -eq 0 ]; then
12247                 error "Deleted non-existant user cl77"
12248         elif [ $rc -ne 2 ]; then
12249                 error "changelog_deregister failed with $rc, expect 2 (ENOENT)"
12250         fi
12251
12252         # Clear to a bad index (1 billion should be safe)
12253         $LFS changelog_clear $MDT0 "${CL_USERS[$SINGLEMDS]%% *}" 1000000000
12254         rc=$?
12255
12256         if [ $rc -eq 0 ]; then
12257                 error "Successfully cleared to invalid CL index"
12258         elif [ $rc -ne 22 ]; then
12259                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
12260         fi
12261 }
12262 run_test 160e "changelog negative testing (should return errors)"
12263
12264 test_160f() {
12265         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12266         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
12267                 { skip "Need MDS version at least 2.10.56"; return 0; }
12268
12269         local mdts=$(comma_list $(mdts_nodes))
12270
12271         # Create a user
12272         changelog_register || error "first changelog_register failed"
12273         changelog_register || error "second changelog_register failed"
12274         local cl_users
12275         declare -A cl_user1
12276         declare -A cl_user2
12277         local user_rec1
12278         local user_rec2
12279         local i
12280
12281         # generate some changelog records to accumulate on each MDT
12282         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "test_mkdir $tdir failed"
12283         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12284                 error "create $DIR/$tdir/$tfile failed"
12285
12286         # check changelogs have been generated
12287         local nbcl=$(changelog_dump | wc -l)
12288         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12289
12290         for param in "changelog_max_idle_time=10" \
12291                      "changelog_gc=1" \
12292                      "changelog_min_gc_interval=2" \
12293                      "changelog_min_free_cat_entries=3"; do
12294                 local MDT0=$(facet_svc $SINGLEMDS)
12295                 local var="${param%=*}"
12296                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
12297
12298                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
12299                 do_nodes $mdts $LCTL set_param mdd.*.$param
12300         done
12301
12302         # force cl_user2 to be idle (1st part)
12303         sleep 9
12304
12305         # simulate changelog catalog almost full
12306         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
12307         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
12308
12309         for i in $(seq $MDSCOUNT); do
12310                 cl_users=(${CL_USERS[mds$i]})
12311                 cl_user1[mds$i]="${cl_users[0]}"
12312                 cl_user2[mds$i]="${cl_users[1]}"
12313
12314                 [ -n "${cl_user1[mds$i]}" ] ||
12315                         error "mds$i: no user registered"
12316                 [ -n "${cl_user2[mds$i]}" ] ||
12317                         error "mds$i: only ${cl_user2[mds$i]} is registered"
12318
12319                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12320                 [ -n "$user_rec1" ] ||
12321                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12322                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
12323                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12324                 [ -n "$user_rec2" ] ||
12325                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12326                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
12327                      "$user_rec1 + 2 == $user_rec2"
12328                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
12329                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
12330                               "$user_rec1 + 2, but is $user_rec2"
12331                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
12332                 [ -n "$user_rec2" ] ||
12333                         error "mds$i: User ${cl_user2[mds$i]} not registered"
12334                 [ $user_rec1 == $user_rec2 ] ||
12335                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
12336                               "$user_rec1, but is $user_rec2"
12337         done
12338
12339         # force cl_user2 to be idle (2nd part) and to reach
12340         # changelog_max_idle_time
12341         sleep 2
12342
12343         # generate one more changelog to trigger fail_loc
12344         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
12345                 error "create $DIR/$tdir/${tfile}bis failed"
12346
12347         # ensure gc thread is done
12348         for i in $(mdts_nodes); do
12349                 wait_update $i \
12350                         "ps -e -o comm= | grep chlg_gc_thread" "" 20 ||
12351                         error "$i: GC-thread not done"
12352         done
12353
12354         local first_rec
12355         for i in $(seq $MDSCOUNT); do
12356                 # check cl_user1 still registered
12357                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
12358                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12359                 # check cl_user2 unregistered
12360                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
12361                         error "mds$i: User ${cl_user2[mds$i]} still registered"
12362
12363                 # check changelogs are present and starting at $user_rec1 + 1
12364                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12365                 [ -n "$user_rec1" ] ||
12366                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12367                 first_rec=$($LFS changelog $(facet_svc mds$i) |
12368                             awk '{ print $1; exit; }')
12369
12370                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
12371                 [ $((user_rec1 + 1)) == $first_rec ] ||
12372                         error "mds$i: first index should be $user_rec1 + 1, " \
12373                               "but is $first_rec"
12374         done
12375 }
12376 run_test 160f "changelog garbage collect (timestamped users)"
12377
12378 test_160g() {
12379         remote_mds_nodsh && skip "remote MDS with nodsh"
12380         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
12381                 skip "Need MDS version at least 2.10.56"
12382
12383         local mdts=$(comma_list $(mdts_nodes))
12384
12385         #define OBD_FAIL_TIME_IN_CHLOG_USER     0x1314
12386         do_nodes $mdts $LCTL set_param fail_loc=0x1314
12387
12388         # Create a user
12389         changelog_register || error "first changelog_register failed"
12390         changelog_register || error "second changelog_register failed"
12391         local cl_users
12392         declare -A cl_user1
12393         declare -A cl_user2
12394         local user_rec1
12395         local user_rec2
12396         local i
12397
12398         # generate some changelog records to accumulate on each MDT
12399         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
12400         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12401                 error "create $DIR/$tdir/$tfile failed"
12402
12403         # check changelogs have been generated
12404         local nbcl=$(changelog_dump | wc -l)
12405         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12406
12407         for param in "changelog_max_idle_indexes=$((nbcl / 2))" \
12408                      "changelog_gc=1" \
12409                      "changelog_min_gc_interval=2" \
12410                      "changelog_min_free_cat_entries=3"; do
12411                 local MDT0=$(facet_svc $SINGLEMDS)
12412                 local var="${param%=*}"
12413                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
12414
12415                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
12416                 do_nodes $mdts $LCTL set_param mdd.*.$param ||
12417                         error "unable to set mdd.*.$param"
12418         done
12419
12420         # simulate changelog catalog almost full
12421         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
12422         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
12423
12424         for i in $(seq $MDSCOUNT); do
12425                 cl_users=(${CL_USERS[mds$i]})
12426                 cl_user1[mds$i]="${cl_users[0]}"
12427                 cl_user2[mds$i]="${cl_users[1]}"
12428
12429                 [ -n "${cl_user1[mds$i]}" ] ||
12430                         error "mds$i: no user registered"
12431                 [ -n "${cl_user2[mds$i]}" ] ||
12432                         error "mds$i: only ${cl_user1[mds$i]} is registered"
12433
12434                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12435                 [ -n "$user_rec1" ] ||
12436                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12437                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
12438                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12439                 [ -n "$user_rec2" ] ||
12440                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12441                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
12442                      "$user_rec1 + 2 == $user_rec2"
12443                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
12444                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
12445                               "$user_rec1 + 2, but is $user_rec2"
12446                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
12447                 [ -n "$user_rec2" ] ||
12448                         error "mds$i: User ${cl_user2[mds$i]} not registered"
12449                 [ $user_rec1 == $user_rec2 ] ||
12450                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
12451                               "$user_rec1, but is $user_rec2"
12452         done
12453
12454         # ensure we are past the previous changelog_min_gc_interval set above
12455         sleep 2
12456
12457         # generate one more changelog to trigger fail_loc
12458         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
12459                 error "create $DIR/$tdir/${tfile}bis failed"
12460
12461         # ensure gc thread is done
12462         for i in $(mdts_nodes); do
12463                 wait_update $i \
12464                         "ps -e -o comm= | grep chlg_gc_thread" "" 20 ||
12465                         error "$i: GC-thread not done"
12466         done
12467
12468         local first_rec
12469         for i in $(seq $MDSCOUNT); do
12470                 # check cl_user1 still registered
12471                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
12472                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12473                 # check cl_user2 unregistered
12474                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
12475                         error "mds$i: User ${cl_user2[mds$i]} still registered"
12476
12477                 # check changelogs are present and starting at $user_rec1 + 1
12478                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12479                 [ -n "$user_rec1" ] ||
12480                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12481                 first_rec=$($LFS changelog $(facet_svc mds$i) |
12482                             awk '{ print $1; exit; }')
12483
12484                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
12485                 [ $((user_rec1 + 1)) == $first_rec ] ||
12486                         error "mds$i: first index should be $user_rec1 + 1, " \
12487                               "but is $first_rec"
12488         done
12489 }
12490 run_test 160g "changelog garbage collect (old users)"
12491
12492 test_160h() {
12493         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12494         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
12495                 { skip "Need MDS version at least 2.10.56"; return 0; }
12496
12497         local mdts=$(comma_list $(mdts_nodes))
12498
12499         # Create a user
12500         changelog_register || error "first changelog_register failed"
12501         changelog_register || error "second changelog_register failed"
12502         local cl_users
12503         declare -A cl_user1
12504         declare -A cl_user2
12505         local user_rec1
12506         local user_rec2
12507         local i
12508
12509         # generate some changelog records to accumulate on each MDT
12510         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "test_mkdir $tdir failed"
12511         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12512                 error "create $DIR/$tdir/$tfile failed"
12513
12514         # check changelogs have been generated
12515         local nbcl=$(changelog_dump | wc -l)
12516         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12517
12518         for param in "changelog_max_idle_time=10" \
12519                      "changelog_gc=1" \
12520                      "changelog_min_gc_interval=2"; do
12521                 local MDT0=$(facet_svc $SINGLEMDS)
12522                 local var="${param%=*}"
12523                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
12524
12525                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
12526                 do_nodes $mdts $LCTL set_param mdd.*.$param
12527         done
12528
12529         # force cl_user2 to be idle (1st part)
12530         sleep 9
12531
12532         for i in $(seq $MDSCOUNT); do
12533                 cl_users=(${CL_USERS[mds$i]})
12534                 cl_user1[mds$i]="${cl_users[0]}"
12535                 cl_user2[mds$i]="${cl_users[1]}"
12536
12537                 [ -n "${cl_user1[mds$i]}" ] ||
12538                         error "mds$i: no user registered"
12539                 [ -n "${cl_user2[mds$i]}" ] ||
12540                         error "mds$i: only ${cl_user2[mds$i]} is registered"
12541
12542                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12543                 [ -n "$user_rec1" ] ||
12544                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12545                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
12546                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12547                 [ -n "$user_rec2" ] ||
12548                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12549                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
12550                      "$user_rec1 + 2 == $user_rec2"
12551                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
12552                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
12553                               "$user_rec1 + 2, but is $user_rec2"
12554                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
12555                 [ -n "$user_rec2" ] ||
12556                         error "mds$i: User ${cl_user2[mds$i]} not registered"
12557                 [ $user_rec1 == $user_rec2 ] ||
12558                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
12559                               "$user_rec1, but is $user_rec2"
12560         done
12561
12562         # force cl_user2 to be idle (2nd part) and to reach
12563         # changelog_max_idle_time
12564         sleep 2
12565
12566         # force each GC-thread start and block then
12567         # one per MDT/MDD, set fail_val accordingly
12568         #define OBD_FAIL_FORCE_GC_THREAD 0x1316
12569         do_nodes $mdts $LCTL set_param fail_loc=0x1316
12570
12571         # generate more changelogs to trigger fail_loc
12572         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
12573                 error "create $DIR/$tdir/${tfile}bis failed"
12574
12575         # stop MDT to stop GC-thread, should be done in back-ground as it will
12576         # block waiting for the thread to be released and exit
12577         declare -A stop_pids
12578         for i in $(seq $MDSCOUNT); do
12579                 stop mds$i &
12580                 stop_pids[mds$i]=$!
12581         done
12582
12583         for i in $(mdts_nodes); do
12584                 local facet
12585                 local nb=0
12586                 local facets=$(facets_up_on_host $i)
12587
12588                 for facet in ${facets//,/ }; do
12589                         if [[ $facet == mds* ]]; then
12590                                 nb=$((nb + 1))
12591                         fi
12592                 done
12593                 # ensure each MDS's gc threads are still present and all in "R"
12594                 # state (OBD_FAIL_FORCE_GC_THREAD effect!)
12595                 [[ $(do_node $i pgrep chlg_gc_thread | wc -l) -eq $nb ]] ||
12596                         error "$i: expected $nb GC-thread"
12597                 wait_update $i \
12598                         "ps -C chlg_gc_thread -o state --no-headers | uniq" \
12599                         "R" 20 ||
12600                         error "$i: GC-thread not found in R-state"
12601                 # check umounts of each MDT on MDS have reached kthread_stop()
12602                 [[ $(do_node $i pgrep umount | wc -l) -eq $nb ]] ||
12603                         error "$i: expected $nb umount"
12604                 wait_update $i \
12605                         "ps -C umount -o state --no-headers | uniq" "D" 20 ||
12606                         error "$i: umount not found in D-state"
12607         done
12608
12609         # release all GC-threads
12610         do_nodes $mdts $LCTL set_param fail_loc=0
12611
12612         # wait for MDT stop to complete
12613         for i in $(seq $MDSCOUNT); do
12614                 wait ${stop_pids[mds$i]} || error "mds$i: stop failed"
12615         done
12616
12617         # XXX
12618         # may try to check if any orphan changelog records are present
12619         # via ldiskfs/zfs and llog_reader...
12620
12621         # re-start/mount MDTs
12622         for i in $(seq $MDSCOUNT); do
12623                 start mds$i $(mdsdevname $i) $MDS_MOUNT_OPTS ||
12624                         error "Fail to start mds$i"
12625         done
12626
12627         local first_rec
12628         for i in $(seq $MDSCOUNT); do
12629                 # check cl_user1 still registered
12630                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
12631                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12632                 # check cl_user2 unregistered
12633                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
12634                         error "mds$i: User ${cl_user2[mds$i]} still registered"
12635
12636                 # check changelogs are present and starting at $user_rec1 + 1
12637                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12638                 [ -n "$user_rec1" ] ||
12639                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12640                 first_rec=$($LFS changelog $(facet_svc mds$i) |
12641                             awk '{ print $1; exit; }')
12642
12643                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
12644                 [ $((user_rec1 + 1)) == $first_rec ] ||
12645                         error "mds$i: first index should be $user_rec1 + 1, " \
12646                               "but is $first_rec"
12647         done
12648 }
12649 run_test 160h "changelog gc thread stop upon umount, orphan records delete " \
12650               "during mount"
12651
12652 test_160i() {
12653
12654         local mdts=$(comma_list $(mdts_nodes))
12655
12656         changelog_register || error "first changelog_register failed"
12657
12658         # generate some changelog records to accumulate on each MDT
12659         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
12660         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12661                 error "create $DIR/$tdir/$tfile failed"
12662
12663         # check changelogs have been generated
12664         local nbcl=$(changelog_dump | wc -l)
12665         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12666
12667         # simulate race between register and unregister
12668         # XXX as fail_loc is set per-MDS, with DNE configs the race
12669         # simulation will only occur for one MDT per MDS and for the
12670         # others the normal race scenario will take place
12671         #define CFS_FAIL_CHLOG_USER_REG_UNREG_RACE          0x1315
12672         do_nodes $mdts $LCTL set_param fail_loc=0x10001315
12673         do_nodes $mdts $LCTL set_param fail_val=1
12674
12675         # unregister 1st user
12676         changelog_deregister &
12677         local pid1=$!
12678         # wait some time for deregister work to reach race rdv
12679         sleep 2
12680         # register 2nd user
12681         changelog_register || error "2nd user register failed"
12682
12683         wait $pid1 || error "1st user deregister failed"
12684
12685         local i
12686         local last_rec
12687         declare -A LAST_REC
12688         for i in $(seq $MDSCOUNT); do
12689                 if changelog_users mds$i | grep "^cl"; then
12690                         # make sure new records are added with one user present
12691                         LAST_REC[mds$i]=$(changelog_users $SINGLEMDS |
12692                                           awk '/^current.index:/ { print $NF }')
12693                 else
12694                         error "mds$i has no user registered"
12695                 fi
12696         done
12697
12698         # generate more changelog records to accumulate on each MDT
12699         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
12700                 error "create $DIR/$tdir/${tfile}bis failed"
12701
12702         for i in $(seq $MDSCOUNT); do
12703                 last_rec=$(changelog_users $SINGLEMDS |
12704                            awk '/^current.index:/ { print $NF }')
12705                 echo "verify changelogs are on: $last_rec != ${LAST_REC[mds$i]}"
12706                 [ $last_rec != ${LAST_REC[mds$i]} ] ||
12707                         error "changelogs are off on mds$i"
12708         done
12709 }
12710 run_test 160i "changelog user register/unregister race"
12711
12712 test_161a() {
12713         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12714
12715         test_mkdir -c1 $DIR/$tdir
12716         cp /etc/hosts $DIR/$tdir/$tfile
12717         test_mkdir -c1 $DIR/$tdir/foo1
12718         test_mkdir -c1 $DIR/$tdir/foo2
12719         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
12720         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
12721         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
12722         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
12723         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
12724         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
12725                 $LFS fid2path $DIR $FID
12726                 error "bad link ea"
12727         fi
12728         # middle
12729         rm $DIR/$tdir/foo2/zachary
12730         # last
12731         rm $DIR/$tdir/foo2/thor
12732         # first
12733         rm $DIR/$tdir/$tfile
12734         # rename
12735         mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
12736         [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ] &&
12737                 { $LFS fid2path $DIR $FID; error "bad link rename"; }
12738         rm $DIR/$tdir/foo2/maggie
12739
12740         # overflow the EA
12741         local longname=$tfile.avg_len_is_thirty_two_
12742         stack_trap "unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
12743                 error_noexit 'failed to unlink many hardlinks'" EXIT
12744         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
12745                 error "failed to hardlink many files"
12746         links=$($LFS fid2path $DIR $FID | wc -l)
12747         echo -n "${links}/1000 links in link EA"
12748         [[ $links -gt 60 ]] || error "expected at least 60 links in link EA"
12749 }
12750 run_test 161a "link ea sanity"
12751
12752 test_161b() {
12753         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12754         [ $MDSCOUNT -lt 2 ] && skip_env "skipping remote directory test"
12755
12756         local MDTIDX=1
12757         local remote_dir=$DIR/$tdir/remote_dir
12758
12759         mkdir -p $DIR/$tdir
12760         $LFS mkdir -i $MDTIDX $remote_dir ||
12761                 error "create remote directory failed"
12762
12763         cp /etc/hosts $remote_dir/$tfile
12764         mkdir -p $remote_dir/foo1
12765         mkdir -p $remote_dir/foo2
12766         ln $remote_dir/$tfile $remote_dir/foo1/sofia
12767         ln $remote_dir/$tfile $remote_dir/foo2/zachary
12768         ln $remote_dir/$tfile $remote_dir/foo1/luna
12769         ln $remote_dir/$tfile $remote_dir/foo2/thor
12770
12771         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
12772                      tr -d ']')
12773         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
12774                 $LFS fid2path $DIR $FID
12775                 error "bad link ea"
12776         fi
12777         # middle
12778         rm $remote_dir/foo2/zachary
12779         # last
12780         rm $remote_dir/foo2/thor
12781         # first
12782         rm $remote_dir/$tfile
12783         # rename
12784         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
12785         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
12786         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
12787                 $LFS fid2path $DIR $FID
12788                 error "bad link rename"
12789         fi
12790         rm $remote_dir/foo2/maggie
12791
12792         # overflow the EA
12793         local longname=filename_avg_len_is_thirty_two_
12794         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
12795                 error "failed to hardlink many files"
12796         links=$($LFS fid2path $DIR $FID | wc -l)
12797         echo -n "${links}/1000 links in link EA"
12798         [[ ${links} -gt 60 ]] ||
12799                 error "expected at least 60 links in link EA"
12800         unlinkmany $remote_dir/foo2/$longname 1000 ||
12801         error "failed to unlink many hardlinks"
12802 }
12803 run_test 161b "link ea sanity under remote directory"
12804
12805 test_161c() {
12806         remote_mds_nodsh && skip "remote MDS with nodsh"
12807         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12808         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
12809                 skip "Need MDS version at least 2.1.5"
12810
12811         # define CLF_RENAME_LAST 0x0001
12812         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
12813         changelog_register || error "changelog_register failed"
12814
12815         rm -rf $DIR/$tdir
12816         test_mkdir -i $((MDSCOUNT - 1)) $DIR/$tdir
12817         touch $DIR/$tdir/foo_161c
12818         touch $DIR/$tdir/bar_161c
12819         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
12820         changelog_dump | grep RENME | tail -n 5
12821         local flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
12822         changelog_clear 0 || error "changelog_clear failed"
12823         if [ x$flags != "x0x1" ]; then
12824                 error "flag $flags is not 0x1"
12825         fi
12826
12827         echo "rename overwrite target with nlink = 1, changelog flags=$flags"
12828         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
12829         touch $DIR/$tdir/foo_161c
12830         touch $DIR/$tdir/bar_161c
12831         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
12832         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
12833         changelog_dump | grep RENME | tail -n 5
12834         flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
12835         changelog_clear 0 || error "changelog_clear failed"
12836         if [ x$flags != "x0x0" ]; then
12837                 error "flag $flags is not 0x0"
12838         fi
12839         echo "rename overwrite a target having nlink > 1," \
12840                 "changelog record has flags of $flags"
12841
12842         # rename doesn't overwrite a target (changelog flag 0x0)
12843         touch $DIR/$tdir/foo_161c
12844         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
12845         changelog_dump | grep RENME | tail -n 5
12846         flags=$(changelog_dump | grep RENME | tail -1 | cut -f5 -d' ')
12847         changelog_clear 0 || error "changelog_clear failed"
12848         if [ x$flags != "x0x0" ]; then
12849                 error "flag $flags is not 0x0"
12850         fi
12851         echo "rename doesn't overwrite a target," \
12852                 "changelog record has flags of $flags"
12853
12854         # define CLF_UNLINK_LAST 0x0001
12855         # unlink a file having nlink = 1 (changelog flag 0x1)
12856         rm -f $DIR/$tdir/foo2_161c
12857         changelog_dump | grep UNLNK | tail -n 5
12858         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
12859         changelog_clear 0 || error "changelog_clear failed"
12860         if [ x$flags != "x0x1" ]; then
12861                 error "flag $flags is not 0x1"
12862         fi
12863         echo "unlink a file having nlink = 1," \
12864                 "changelog record has flags of $flags"
12865
12866         # unlink a file having nlink > 1 (changelog flag 0x0)
12867         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
12868         rm -f $DIR/$tdir/foobar_161c
12869         changelog_dump | grep UNLNK | tail -n 5
12870         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
12871         changelog_clear 0 || error "changelog_clear failed"
12872         if [ x$flags != "x0x0" ]; then
12873                 error "flag $flags is not 0x0"
12874         fi
12875         echo "unlink a file having nlink > 1, changelog record flags '$flags'"
12876 }
12877 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
12878
12879 test_161d() {
12880         remote_mds_nodsh && skip "remote MDS with nodsh"
12881
12882         local pid
12883         local fid
12884
12885         changelog_register || error "changelog_register failed"
12886
12887         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
12888         # interfer with $MOUNT/.lustre/fid/ access
12889         mkdir $DIR/$tdir
12890         [[ $? -eq 0 ]] || error "mkdir failed"
12891
12892         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
12893         $LCTL set_param fail_loc=0x8000140c
12894         # 5s pause
12895         $LCTL set_param fail_val=5
12896
12897         # create file
12898         echo foofoo > $DIR/$tdir/$tfile &
12899         pid=$!
12900
12901         # wait for create to be delayed
12902         sleep 2
12903
12904         ps -p $pid
12905         [[ $? -eq 0 ]] || error "create should be blocked"
12906
12907         local tempfile=$(mktemp)
12908         fid=$(changelog_extract_field "CREAT" "$tfile" "t=")
12909         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
12910         # some delay may occur during ChangeLog publishing and file read just
12911         # above, that could allow file write to happen finally
12912         [[ -s $tempfile ]] && echo "file should be empty"
12913
12914         $LCTL set_param fail_loc=0
12915
12916         wait $pid
12917         [[ $? -eq 0 ]] || error "create failed"
12918 }
12919 run_test 161d "create with concurrent .lustre/fid access"
12920
12921 check_path() {
12922         local expected="$1"
12923         shift
12924         local fid="$2"
12925
12926         local path
12927         path=$($LFS fid2path "$@")
12928         local rc=$?
12929
12930         if [ $rc -ne 0 ]; then
12931                 error "path looked up of '$expected' failed: rc=$rc"
12932         elif [ "$path" != "$expected" ]; then
12933                 error "path looked up '$path' instead of '$expected'"
12934         else
12935                 echo "FID '$fid' resolves to path '$path' as expected"
12936         fi
12937 }
12938
12939 test_162a() { # was test_162
12940         test_mkdir -p -c1 $DIR/$tdir/d2
12941         touch $DIR/$tdir/d2/$tfile
12942         touch $DIR/$tdir/d2/x1
12943         touch $DIR/$tdir/d2/x2
12944         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
12945         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
12946         # regular file
12947         local fid=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
12948         check_path "$tdir/d2/$tfile" $FSNAME "$fid" --link 0
12949
12950         # softlink
12951         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
12952         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
12953         check_path "$tdir/d2/p/q/r/slink" $FSNAME "$fid" --link 0
12954
12955         # softlink to wrong file
12956         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
12957         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
12958         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME "$fid" --link 0
12959
12960         # hardlink
12961         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
12962         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
12963         fid=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
12964         # fid2path dir/fsname should both work
12965         check_path "$tdir/d2/a/b/c/new_file" $FSNAME "$fid" --link 1
12966         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR "$fid" --link 0
12967
12968         # hardlink count: check that there are 2 links
12969         local nlinks=$($LFS fid2path $DIR "$fid" | wc -l)
12970         [ $nlinks -eq 2 ] || error "expect 2 links, found $nlinks"
12971
12972         # hardlink indexing: remove the first link
12973         rm $DIR/$tdir/d2/p/q/r/hlink
12974         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $fid --link 0
12975 }
12976 run_test 162a "path lookup sanity"
12977
12978 test_162b() {
12979         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12980         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
12981
12982         mkdir $DIR/$tdir
12983         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
12984                                 error "create striped dir failed"
12985
12986         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
12987                                         tail -n 1 | awk '{print $2}')
12988         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
12989
12990         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
12991         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
12992
12993         # regular file
12994         for ((i=0;i<5;i++)); do
12995                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
12996                         error "get fid for f$i failed"
12997                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0
12998
12999                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
13000                         error "get fid for d$i failed"
13001                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0
13002         done
13003
13004         return 0
13005 }
13006 run_test 162b "striped directory path lookup sanity"
13007
13008 # LU-4239: Verify fid2path works with paths 100 or more directories deep
13009 test_162c() {
13010         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
13011                 skip "Need MDS version at least 2.7.51"
13012
13013         local lpath=$tdir.local
13014         local rpath=$tdir.remote
13015
13016         test_mkdir $DIR/$lpath
13017         test_mkdir $DIR/$rpath
13018
13019         for ((i = 0; i <= 101; i++)); do
13020                 lpath="$lpath/$i"
13021                 mkdir $DIR/$lpath
13022                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
13023                         error "get fid for local directory $DIR/$lpath failed"
13024                 check_path "$DIR/$lpath" $MOUNT $FID --link 0
13025
13026                 rpath="$rpath/$i"
13027                 test_mkdir $DIR/$rpath
13028                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
13029                         error "get fid for remote directory $DIR/$rpath failed"
13030                 check_path "$DIR/$rpath" $MOUNT $FID --link 0
13031         done
13032
13033         return 0
13034 }
13035 run_test 162c "fid2path works with paths 100 or more directories deep"
13036
13037 test_169() {
13038         # do directio so as not to populate the page cache
13039         log "creating a 10 Mb file"
13040         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
13041         log "starting reads"
13042         dd if=$DIR/$tfile of=/dev/null bs=4096 &
13043         log "truncating the file"
13044         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
13045         log "killing dd"
13046         kill %+ || true # reads might have finished
13047         echo "wait until dd is finished"
13048         wait
13049         log "removing the temporary file"
13050         rm -rf $DIR/$tfile || error "tmp file removal failed"
13051 }
13052 run_test 169 "parallel read and truncate should not deadlock"
13053
13054 test_170() {
13055         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13056
13057         $LCTL clear     # bug 18514
13058         $LCTL debug_daemon start $TMP/${tfile}_log_good
13059         touch $DIR/$tfile
13060         $LCTL debug_daemon stop
13061         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
13062                 error "sed failed to read log_good"
13063
13064         $LCTL debug_daemon start $TMP/${tfile}_log_good
13065         rm -rf $DIR/$tfile
13066         $LCTL debug_daemon stop
13067
13068         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
13069                error "lctl df log_bad failed"
13070
13071         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
13072         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
13073
13074         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
13075         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
13076
13077         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
13078                 error "bad_line good_line1 good_line2 are empty"
13079
13080         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
13081         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
13082         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
13083
13084         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
13085         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
13086         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
13087
13088         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
13089                 error "bad_line_new good_line_new are empty"
13090
13091         local expected_good=$((good_line1 + good_line2*2))
13092
13093         rm -f $TMP/${tfile}*
13094         # LU-231, short malformed line may not be counted into bad lines
13095         if [ $bad_line -ne $bad_line_new ] &&
13096                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
13097                 error "expected $bad_line bad lines, but got $bad_line_new"
13098                 return 1
13099         fi
13100
13101         if [ $expected_good -ne $good_line_new ]; then
13102                 error "expected $expected_good good lines, but got $good_line_new"
13103                 return 2
13104         fi
13105         true
13106 }
13107 run_test 170 "test lctl df to handle corrupted log ====================="
13108
13109 test_171() { # bug20592
13110         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13111
13112         #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
13113         $LCTL set_param fail_loc=0x50e
13114         $LCTL set_param fail_val=3000
13115         multiop_bg_pause $DIR/$tfile O_s || true
13116         local MULTIPID=$!
13117         kill -USR1 $MULTIPID
13118         # cause log dump
13119         sleep 3
13120         wait $MULTIPID
13121         if dmesg | grep "recursive fault"; then
13122                 error "caught a recursive fault"
13123         fi
13124         $LCTL set_param fail_loc=0
13125         true
13126 }
13127 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
13128
13129 # it would be good to share it with obdfilter-survey/iokit-libecho code
13130 setup_obdecho_osc () {
13131         local rc=0
13132         local ost_nid=$1
13133         local obdfilter_name=$2
13134         echo "Creating new osc for $obdfilter_name on $ost_nid"
13135         # make sure we can find loopback nid
13136         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
13137
13138         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
13139                            ${obdfilter_name}_osc_UUID || rc=2; }
13140         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
13141                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
13142         return $rc
13143 }
13144
13145 cleanup_obdecho_osc () {
13146         local obdfilter_name=$1
13147         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
13148         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
13149         return 0
13150 }
13151
13152 obdecho_test() {
13153         local OBD=$1
13154         local node=$2
13155         local pages=${3:-64}
13156         local rc=0
13157         local id
13158
13159         local count=10
13160         local obd_size=$(get_obd_size $node $OBD)
13161         local page_size=$(get_page_size $node)
13162         if [[ -n "$obd_size" ]]; then
13163                 local new_count=$((obd_size / (pages * page_size / 1024)))
13164                 [[ $new_count -ge $count ]] || count=$new_count
13165         fi
13166
13167         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
13168         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
13169                            rc=2; }
13170         if [ $rc -eq 0 ]; then
13171             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
13172             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
13173         fi
13174         echo "New object id is $id"
13175         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
13176                            rc=4; }
13177         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
13178                            "test_brw $count w v $pages $id" || rc=4; }
13179         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
13180                            rc=4; }
13181         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
13182                                         "cleanup" || rc=5; }
13183         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
13184                                         "detach" || rc=6; }
13185         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
13186         return $rc
13187 }
13188
13189 test_180a() {
13190         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13191
13192         if ! module_loaded obdecho; then
13193                 load_module obdecho/obdecho &&
13194                         stack_trap "rmmod obdecho" EXIT ||
13195                         error "unable to load obdecho on client"
13196         fi
13197
13198         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
13199         local host=$($LCTL get_param -n osc.$osc.import |
13200                      awk '/current_connection:/ { print $2 }' )
13201         local target=$($LCTL get_param -n osc.$osc.import |
13202                        awk '/target:/ { print $2 }' )
13203         target=${target%_UUID}
13204
13205         if [ -n "$target" ]; then
13206                 setup_obdecho_osc $host $target &&
13207                         stack_trap "cleanup_obdecho_osc $target" EXIT ||
13208                         { error "obdecho setup failed with $?"; return; }
13209
13210                 obdecho_test ${target}_osc client ||
13211                         error "obdecho_test failed on ${target}_osc"
13212         else
13213                 $LCTL get_param osc.$osc.import
13214                 error "there is no osc.$osc.import target"
13215         fi
13216 }
13217 run_test 180a "test obdecho on osc"
13218
13219 test_180b() {
13220         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13221         remote_ost_nodsh && skip "remote OST with nodsh"
13222
13223         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
13224                 stack_trap "do_facet ost1 rmmod obdecho" EXIT ||
13225                 error "failed to load module obdecho"
13226
13227         local target=$(do_facet ost1 $LCTL dl |
13228                        awk '/obdfilter/ { print $4; exit; }')
13229
13230         if [ -n "$target" ]; then
13231                 obdecho_test $target ost1 || error "obdecho_test failed with $?"
13232         else
13233                 do_facet ost1 $LCTL dl
13234                 error "there is no obdfilter target on ost1"
13235         fi
13236 }
13237 run_test 180b "test obdecho directly on obdfilter"
13238
13239 test_180c() { # LU-2598
13240         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13241         remote_ost_nodsh && skip "remote OST with nodsh"
13242         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
13243                 skip "Need MDS version at least 2.4.0"
13244
13245         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
13246                 stack_trap "do_facet ost1 rmmod obdecho" EXIT ||
13247                 error "failed to load module obdecho"
13248
13249         local target=$(do_facet ost1 $LCTL dl |
13250                        awk '/obdfilter/ { print $4; exit; }')
13251
13252         if [ -n "$target" ]; then
13253                 local pages=16384 # 64MB bulk I/O RPC size
13254
13255                 obdecho_test "$target" ost1 "$pages" ||
13256                         error "obdecho_test with pages=$pages failed with $?"
13257         else
13258                 do_facet ost1 $LCTL dl
13259                 error "there is no obdfilter target on ost1"
13260         fi
13261 }
13262 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
13263
13264 test_181() { # bug 22177
13265         test_mkdir $DIR/$tdir
13266         # create enough files to index the directory
13267         createmany -o $DIR/$tdir/foobar 4000
13268         # print attributes for debug purpose
13269         lsattr -d .
13270         # open dir
13271         multiop_bg_pause $DIR/$tdir D_Sc || return 1
13272         MULTIPID=$!
13273         # remove the files & current working dir
13274         unlinkmany $DIR/$tdir/foobar 4000
13275         rmdir $DIR/$tdir
13276         kill -USR1 $MULTIPID
13277         wait $MULTIPID
13278         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
13279         return 0
13280 }
13281 run_test 181 "Test open-unlinked dir ========================"
13282
13283 test_182() {
13284         local fcount=1000
13285         local tcount=10
13286
13287         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
13288
13289         $LCTL set_param mdc.*.rpc_stats=clear
13290
13291         for (( i = 0; i < $tcount; i++ )) ; do
13292                 mkdir $DIR/$tdir/$i
13293         done
13294
13295         for (( i = 0; i < $tcount; i++ )) ; do
13296                 createmany -o $DIR/$tdir/$i/f- $fcount &
13297         done
13298         wait
13299
13300         for (( i = 0; i < $tcount; i++ )) ; do
13301                 unlinkmany $DIR/$tdir/$i/f- $fcount &
13302         done
13303         wait
13304
13305         $LCTL get_param mdc.*.rpc_stats
13306
13307         rm -rf $DIR/$tdir
13308 }
13309 run_test 182 "Test parallel modify metadata operations ================"
13310
13311 test_183() { # LU-2275
13312         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13313         remote_mds_nodsh && skip "remote MDS with nodsh"
13314         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
13315                 skip "Need MDS version at least 2.3.56"
13316
13317         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
13318         echo aaa > $DIR/$tdir/$tfile
13319
13320 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
13321         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
13322
13323         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
13324         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
13325
13326         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
13327
13328         # Flush negative dentry cache
13329         touch $DIR/$tdir/$tfile
13330
13331         # We are not checking for any leaked references here, they'll
13332         # become evident next time we do cleanup with module unload.
13333         rm -rf $DIR/$tdir
13334 }
13335 run_test 183 "No crash or request leak in case of strange dispositions ========"
13336
13337 # test suite 184 is for LU-2016, LU-2017
13338 test_184a() {
13339         check_swap_layouts_support
13340
13341         dir0=$DIR/$tdir/$testnum
13342         test_mkdir -p -c1 $dir0
13343         ref1=/etc/passwd
13344         ref2=/etc/group
13345         file1=$dir0/f1
13346         file2=$dir0/f2
13347         $SETSTRIPE -c1 $file1
13348         cp $ref1 $file1
13349         $SETSTRIPE -c2 $file2
13350         cp $ref2 $file2
13351         gen1=$($GETSTRIPE -g $file1)
13352         gen2=$($GETSTRIPE -g $file2)
13353
13354         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
13355         gen=$($GETSTRIPE -g $file1)
13356         [[ $gen1 != $gen ]] ||
13357                 "Layout generation on $file1 does not change"
13358         gen=$($GETSTRIPE -g $file2)
13359         [[ $gen2 != $gen ]] ||
13360                 "Layout generation on $file2 does not change"
13361
13362         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
13363         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13364
13365         lfsck_verify_pfid $file1 $file2 || error "PFID are not transferred"
13366 }
13367 run_test 184a "Basic layout swap"
13368
13369 test_184b() {
13370         check_swap_layouts_support
13371
13372         dir0=$DIR/$tdir/$testnum
13373         mkdir -p $dir0 || error "creating dir $dir0"
13374         file1=$dir0/f1
13375         file2=$dir0/f2
13376         file3=$dir0/f3
13377         dir1=$dir0/d1
13378         dir2=$dir0/d2
13379         mkdir $dir1 $dir2
13380         $SETSTRIPE -c1 $file1
13381         $SETSTRIPE -c2 $file2
13382         $SETSTRIPE -c1 $file3
13383         chown $RUNAS_ID $file3
13384         gen1=$($GETSTRIPE -g $file1)
13385         gen2=$($GETSTRIPE -g $file2)
13386
13387         $LFS swap_layouts $dir1 $dir2 &&
13388                 error "swap of directories layouts should fail"
13389         $LFS swap_layouts $dir1 $file1 &&
13390                 error "swap of directory and file layouts should fail"
13391         $RUNAS $LFS swap_layouts $file1 $file2 &&
13392                 error "swap of file we cannot write should fail"
13393         $LFS swap_layouts $file1 $file3 &&
13394                 error "swap of file with different owner should fail"
13395         /bin/true # to clear error code
13396 }
13397 run_test 184b "Forbidden layout swap (will generate errors)"
13398
13399 test_184c() {
13400         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
13401         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n"
13402         check_swap_layouts_support
13403
13404         local dir0=$DIR/$tdir/$testnum
13405         mkdir -p $dir0 || error "creating dir $dir0"
13406
13407         local ref1=$dir0/ref1
13408         local ref2=$dir0/ref2
13409         local file1=$dir0/file1
13410         local file2=$dir0/file2
13411         # create a file large enough for the concurrent test
13412         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
13413         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
13414         echo "ref file size: ref1($(stat -c %s $ref1))," \
13415              "ref2($(stat -c %s $ref2))"
13416
13417         cp $ref2 $file2
13418         dd if=$ref1 of=$file1 bs=16k &
13419         local DD_PID=$!
13420
13421         # Make sure dd starts to copy file
13422         while [ ! -f $file1 ]; do sleep 0.1; done
13423
13424         $LFS swap_layouts $file1 $file2
13425         local rc=$?
13426         wait $DD_PID
13427         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
13428         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
13429
13430         # how many bytes copied before swapping layout
13431         local copied=$(stat -c %s $file2)
13432         local remaining=$(stat -c %s $ref1)
13433         remaining=$((remaining - copied))
13434         echo "Copied $copied bytes before swapping layout..."
13435
13436         cmp -n $copied $file1 $ref2 | grep differ &&
13437                 error "Content mismatch [0, $copied) of ref2 and file1"
13438         cmp -n $copied $file2 $ref1 ||
13439                 error "Content mismatch [0, $copied) of ref1 and file2"
13440         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
13441                 error "Content mismatch [$copied, EOF) of ref1 and file1"
13442
13443         # clean up
13444         rm -f $ref1 $ref2 $file1 $file2
13445 }
13446 run_test 184c "Concurrent write and layout swap"
13447
13448 test_184d() {
13449         check_swap_layouts_support
13450         [ -z "$(which getfattr 2>/dev/null)" ] &&
13451                 skip_env "no getfattr command"
13452
13453         local file1=$DIR/$tdir/$tfile-1
13454         local file2=$DIR/$tdir/$tfile-2
13455         local file3=$DIR/$tdir/$tfile-3
13456         local lovea1
13457         local lovea2
13458
13459         mkdir -p $DIR/$tdir
13460         touch $file1 || error "create $file1 failed"
13461         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
13462                 error "create $file2 failed"
13463         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
13464                 error "create $file3 failed"
13465         lovea1=$(get_layout_param $file1)
13466
13467         $LFS swap_layouts $file2 $file3 ||
13468                 error "swap $file2 $file3 layouts failed"
13469         $LFS swap_layouts $file1 $file2 ||
13470                 error "swap $file1 $file2 layouts failed"
13471
13472         lovea2=$(get_layout_param $file2)
13473         echo "$lovea1"
13474         echo "$lovea2"
13475         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
13476
13477         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
13478         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
13479 }
13480 run_test 184d "allow stripeless layouts swap"
13481
13482 test_184e() {
13483         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
13484                 skip "Need MDS version at least 2.6.94"
13485         check_swap_layouts_support
13486         [ -z "$(which getfattr 2>/dev/null)" ] &&
13487                 skip_env "no getfattr command"
13488
13489         local file1=$DIR/$tdir/$tfile-1
13490         local file2=$DIR/$tdir/$tfile-2
13491         local file3=$DIR/$tdir/$tfile-3
13492         local lovea
13493
13494         mkdir -p $DIR/$tdir
13495         touch $file1 || error "create $file1 failed"
13496         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
13497                 error "create $file2 failed"
13498         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
13499                 error "create $file3 failed"
13500
13501         $LFS swap_layouts $file1 $file2 ||
13502                 error "swap $file1 $file2 layouts failed"
13503
13504         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
13505         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
13506
13507         echo 123 > $file1 || error "Should be able to write into $file1"
13508
13509         $LFS swap_layouts $file1 $file3 ||
13510                 error "swap $file1 $file3 layouts failed"
13511
13512         echo 123 > $file1 || error "Should be able to write into $file1"
13513
13514         rm -rf $file1 $file2 $file3
13515 }
13516 run_test 184e "Recreate layout after stripeless layout swaps"
13517
13518 test_185() { # LU-2441
13519         # LU-3553 - no volatile file support in old servers
13520         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
13521                 skip "Need MDS version at least 2.3.60"
13522
13523         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
13524         touch $DIR/$tdir/spoo
13525         local mtime1=$(stat -c "%Y" $DIR/$tdir)
13526         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
13527                 error "cannot create/write a volatile file"
13528         [ "$FILESET" == "" ] &&
13529         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
13530                 error "FID is still valid after close"
13531
13532         multiop_bg_pause $DIR/$tdir vVw4096_c
13533         local multi_pid=$!
13534
13535         local OLD_IFS=$IFS
13536         IFS=":"
13537         local fidv=($fid)
13538         IFS=$OLD_IFS
13539         # assume that the next FID for this client is sequential, since stdout
13540         # is unfortunately eaten by multiop_bg_pause
13541         local n=$((${fidv[1]} + 1))
13542         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
13543         if [ "$FILESET" == "" ]; then
13544                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
13545                         error "FID is missing before close"
13546         fi
13547         kill -USR1 $multi_pid
13548         # 1 second delay, so if mtime change we will see it
13549         sleep 1
13550         local mtime2=$(stat -c "%Y" $DIR/$tdir)
13551         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
13552 }
13553 run_test 185 "Volatile file support"
13554
13555 test_187a() {
13556         remote_mds_nodsh && skip "remote MDS with nodsh"
13557         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
13558                 skip "Need MDS version at least 2.3.0"
13559
13560         local dir0=$DIR/$tdir/$testnum
13561         mkdir -p $dir0 || error "creating dir $dir0"
13562
13563         local file=$dir0/file1
13564         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
13565         local dv1=$($LFS data_version $file)
13566         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
13567         local dv2=$($LFS data_version $file)
13568         [[ $dv1 != $dv2 ]] ||
13569                 error "data version did not change on write $dv1 == $dv2"
13570
13571         # clean up
13572         rm -f $file1
13573 }
13574 run_test 187a "Test data version change"
13575
13576 test_187b() {
13577         remote_mds_nodsh && skip "remote MDS with nodsh"
13578         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
13579                 skip "Need MDS version at least 2.3.0"
13580
13581         local dir0=$DIR/$tdir/$testnum
13582         mkdir -p $dir0 || error "creating dir $dir0"
13583
13584         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
13585         [[ ${DV[0]} != ${DV[1]} ]] ||
13586                 error "data version did not change on write"\
13587                       " ${DV[0]} == ${DV[1]}"
13588
13589         # clean up
13590         rm -f $file1
13591 }
13592 run_test 187b "Test data version change on volatile file"
13593
13594 test_200() {
13595         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13596         remote_mgs_nodsh && skip "remote MGS with nodsh"
13597         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13598
13599         local POOL=${POOL:-cea1}
13600         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
13601         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
13602         # Pool OST targets
13603         local first_ost=0
13604         local last_ost=$(($OSTCOUNT - 1))
13605         local ost_step=2
13606         local ost_list=$(seq $first_ost $ost_step $last_ost)
13607         local ost_range="$first_ost $last_ost $ost_step"
13608         local test_path=$POOL_ROOT/$POOL_DIR_NAME
13609         local file_dir=$POOL_ROOT/file_tst
13610         local subdir=$test_path/subdir
13611         local rc=0
13612
13613         if ! combined_mgs_mds ; then
13614                 mount_mgs_client
13615         fi
13616
13617         while : ; do
13618                 # former test_200a test_200b
13619                 pool_add $POOL                          || { rc=$? ; break; }
13620                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
13621                 # former test_200c test_200d
13622                 mkdir -p $test_path
13623                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
13624                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
13625                 mkdir -p $subdir
13626                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
13627                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
13628                                                         || { rc=$? ; break; }
13629                 # former test_200e test_200f
13630                 local files=$((OSTCOUNT*3))
13631                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
13632                                                         || { rc=$? ; break; }
13633                 pool_create_files $POOL $file_dir $files "$ost_list" \
13634                                                         || { rc=$? ; break; }
13635                 # former test_200g test_200h
13636                 pool_lfs_df $POOL                       || { rc=$? ; break; }
13637                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
13638
13639                 # former test_201a test_201b test_201c
13640                 pool_remove_first_target $POOL          || { rc=$? ; break; }
13641
13642                 local f=$test_path/$tfile
13643                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
13644                 pool_remove $POOL $f                    || { rc=$? ; break; }
13645                 break
13646         done
13647
13648         destroy_test_pools
13649
13650         if ! combined_mgs_mds ; then
13651                 umount_mgs_client
13652         fi
13653         return $rc
13654 }
13655 run_test 200 "OST pools"
13656
13657 # usage: default_attr <count | size | offset>
13658 default_attr() {
13659         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
13660 }
13661
13662 # usage: check_default_stripe_attr
13663 check_default_stripe_attr() {
13664         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
13665         case $1 in
13666         --stripe-count|-c)
13667                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
13668         --stripe-size|-S)
13669                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
13670         --stripe-index|-i)
13671                 EXPECTED=-1;;
13672         *)
13673                 error "unknown getstripe attr '$1'"
13674         esac
13675
13676         [ $ACTUAL == $EXPECTED ] ||
13677                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
13678 }
13679
13680 test_204a() {
13681         test_mkdir $DIR/$tdir
13682         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
13683
13684         check_default_stripe_attr --stripe-count
13685         check_default_stripe_attr --stripe-size
13686         check_default_stripe_attr --stripe-index
13687 }
13688 run_test 204a "Print default stripe attributes"
13689
13690 test_204b() {
13691         test_mkdir $DIR/$tdir
13692         $SETSTRIPE --stripe-count 1 $DIR/$tdir
13693
13694         check_default_stripe_attr --stripe-size
13695         check_default_stripe_attr --stripe-index
13696 }
13697 run_test 204b "Print default stripe size and offset"
13698
13699 test_204c() {
13700         test_mkdir $DIR/$tdir
13701         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
13702
13703         check_default_stripe_attr --stripe-count
13704         check_default_stripe_attr --stripe-index
13705 }
13706 run_test 204c "Print default stripe count and offset"
13707
13708 test_204d() {
13709         test_mkdir $DIR/$tdir
13710         $SETSTRIPE --stripe-index 0 $DIR/$tdir
13711
13712         check_default_stripe_attr --stripe-count
13713         check_default_stripe_attr --stripe-size
13714 }
13715 run_test 204d "Print default stripe count and size"
13716
13717 test_204e() {
13718         test_mkdir $DIR/$tdir
13719         $SETSTRIPE -d $DIR/$tdir
13720
13721         check_default_stripe_attr --stripe-count --raw
13722         check_default_stripe_attr --stripe-size --raw
13723         check_default_stripe_attr --stripe-index --raw
13724 }
13725 run_test 204e "Print raw stripe attributes"
13726
13727 test_204f() {
13728         test_mkdir $DIR/$tdir
13729         $SETSTRIPE --stripe-count 1 $DIR/$tdir
13730
13731         check_default_stripe_attr --stripe-size --raw
13732         check_default_stripe_attr --stripe-index --raw
13733 }
13734 run_test 204f "Print raw stripe size and offset"
13735
13736 test_204g() {
13737         test_mkdir $DIR/$tdir
13738         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
13739
13740         check_default_stripe_attr --stripe-count --raw
13741         check_default_stripe_attr --stripe-index --raw
13742 }
13743 run_test 204g "Print raw stripe count and offset"
13744
13745 test_204h() {
13746         test_mkdir $DIR/$tdir
13747         $SETSTRIPE --stripe-index 0 $DIR/$tdir
13748
13749         check_default_stripe_attr --stripe-count --raw
13750         check_default_stripe_attr --stripe-size --raw
13751 }
13752 run_test 204h "Print raw stripe count and size"
13753
13754 # Figure out which job scheduler is being used, if any,
13755 # or use a fake one
13756 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
13757         JOBENV=SLURM_JOB_ID
13758 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
13759         JOBENV=LSB_JOBID
13760 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
13761         JOBENV=PBS_JOBID
13762 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
13763         JOBENV=LOADL_STEP_ID
13764 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
13765         JOBENV=JOB_ID
13766 else
13767         $LCTL list_param jobid_name > /dev/null 2>&1
13768         if [ $? -eq 0 ]; then
13769                 JOBENV=nodelocal
13770         else
13771                 JOBENV=FAKE_JOBID
13772         fi
13773 fi
13774 LUSTRE_JOBID_SIZE=31 # plus NUL terminator
13775
13776 verify_jobstats() {
13777         local cmd=($1)
13778         shift
13779         local facets="$@"
13780
13781 # we don't really need to clear the stats for this test to work, since each
13782 # command has a unique jobid, but it makes debugging easier if needed.
13783 #       for facet in $facets; do
13784 #               local dev=$(convert_facet2label $facet)
13785 #               # clear old jobstats
13786 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
13787 #       done
13788
13789         # use a new JobID for each test, or we might see an old one
13790         [ "$JOBENV" = "FAKE_JOBID" ] &&
13791                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
13792
13793         JOBVAL=${!JOBENV:0:$LUSTRE_JOBID_SIZE}
13794
13795         [ "$JOBENV" = "nodelocal" ] && {
13796                 FAKE_JOBID=id.$testnum.%e.$RANDOM
13797                 $LCTL set_param jobid_name=$FAKE_JOBID
13798                 JOBVAL=${FAKE_JOBID/\%e/$(basename ${cmd[0]})}
13799         }
13800
13801         log "Test: ${cmd[*]}"
13802         log "Using JobID environment $($LCTL get_param -n jobid_var)=$JOBVAL"
13803
13804         if [ $JOBENV = "FAKE_JOBID" ]; then
13805                 FAKE_JOBID=$JOBVAL ${cmd[*]}
13806         else
13807                 ${cmd[*]}
13808         fi
13809
13810         # all files are created on OST0000
13811         for facet in $facets; do
13812                 local stats="*.$(convert_facet2label $facet).job_stats"
13813
13814                 # strip out libtool wrappers for in-tree executables
13815                 if [ $(do_facet $facet lctl get_param $stats |
13816                        sed -e 's/\.lt-/./' | grep -c $JOBVAL) -ne 1 ]; then
13817                         do_facet $facet lctl get_param $stats
13818                         error "No jobstats for $JOBVAL found on $facet::$stats"
13819                 fi
13820         done
13821 }
13822
13823 jobstats_set() {
13824         local new_jobenv=$1
13825
13826         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$new_jobenv
13827         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $new_jobenv
13828 }
13829
13830 test_205() { # Job stats
13831         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13832         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
13833                 skip "Need MDS version with at least 2.7.1"
13834         remote_mgs_nodsh && skip "remote MGS with nodsh"
13835         remote_mds_nodsh && skip "remote MDS with nodsh"
13836         remote_ost_nodsh && skip "remote OST with nodsh"
13837         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
13838                 skip "Server doesn't support jobstats"
13839         [[ $JOBID_VAR = disable ]] && skip_env "jobstats is disabled"
13840
13841         local old_jobenv=$($LCTL get_param -n jobid_var)
13842         [ $old_jobenv != $JOBENV ] && jobstats_set $JOBENV
13843         stack_trap "do_facet mgs \
13844                 $LCTL conf_param $FSNAME.sys.jobid_var=$old_jobenv" EXIT
13845
13846         changelog_register
13847
13848         local old_interval=$(do_facet $SINGLEMDS lctl get_param -n \
13849                                 mdt.*.job_cleanup_interval | head -n 1)
13850         local new_interval=5
13851         do_facet $SINGLEMDS \
13852                 $LCTL set_param mdt.*.job_cleanup_interval=$new_interval
13853         stack_trap "do_facet $SINGLEMDS \
13854                 $LCTL set_param mdt.*.job_cleanup_interval=$old_interval" EXIT
13855         local start=$SECONDS
13856
13857         local cmd
13858         # mkdir
13859         cmd="mkdir $DIR/$tdir"
13860         verify_jobstats "$cmd" "$SINGLEMDS"
13861         # rmdir
13862         cmd="rmdir $DIR/$tdir"
13863         verify_jobstats "$cmd" "$SINGLEMDS"
13864         # mkdir on secondary MDT
13865         if [ $MDSCOUNT -gt 1 ]; then
13866                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
13867                 verify_jobstats "$cmd" "mds2"
13868         fi
13869         # mknod
13870         cmd="mknod $DIR/$tfile c 1 3"
13871         verify_jobstats "$cmd" "$SINGLEMDS"
13872         # unlink
13873         cmd="rm -f $DIR/$tfile"
13874         verify_jobstats "$cmd" "$SINGLEMDS"
13875         # create all files on OST0000 so verify_jobstats can find OST stats
13876         # open & close
13877         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
13878         verify_jobstats "$cmd" "$SINGLEMDS"
13879         # setattr
13880         cmd="touch $DIR/$tfile"
13881         verify_jobstats "$cmd" "$SINGLEMDS ost1"
13882         # write
13883         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
13884         verify_jobstats "$cmd" "ost1"
13885         # read
13886         cancel_lru_locks osc
13887         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
13888         verify_jobstats "$cmd" "ost1"
13889         # truncate
13890         cmd="$TRUNCATE $DIR/$tfile 0"
13891         verify_jobstats "$cmd" "$SINGLEMDS ost1"
13892         # rename
13893         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
13894         verify_jobstats "$cmd" "$SINGLEMDS"
13895         # jobstats expiry - sleep until old stats should be expired
13896         local left=$((new_interval + 5 - (SECONDS - start)))
13897         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
13898                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
13899                         "0" $left
13900         cmd="mkdir $DIR/$tdir.expire"
13901         verify_jobstats "$cmd" "$SINGLEMDS"
13902         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
13903             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
13904
13905         # Ensure that jobid are present in changelog (if supported by MDS)
13906         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ];then
13907                 changelog_dump | tail -10
13908                 jobids=$(changelog_dump | tail -9 | grep -c "j=")
13909                 [ $jobids -eq 9 ] ||
13910                         error "Wrong changelog jobid count $jobids != 9"
13911
13912                 # LU-5862
13913                 JOBENV="disable"
13914                 jobstats_set $JOBENV
13915                 touch $DIR/$tfile
13916                 changelog_dump | grep $tfile
13917                 jobids=$(changelog_dump | grep $tfile | tail -1 | grep -c "j=")
13918                 [ $jobids -eq 0 ] ||
13919                         error "Unexpected jobids when jobid_var=$JOBENV"
13920         fi
13921
13922         lctl set_param jobid_var=USER jobid_name="S.%j.%e.%u.%h.E"
13923         JOBENV="JOBCOMPLEX"
13924         JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname).E"
13925
13926         verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
13927 }
13928 run_test 205 "Verify job stats"
13929
13930 # LU-1480, LU-1773 and LU-1657
13931 test_206() {
13932         mkdir -p $DIR/$tdir
13933         $SETSTRIPE -c -1 $DIR/$tdir
13934 #define OBD_FAIL_LOV_INIT 0x1403
13935         $LCTL set_param fail_loc=0xa0001403
13936         $LCTL set_param fail_val=1
13937         touch $DIR/$tdir/$tfile || true
13938 }
13939 run_test 206 "fail lov_init_raid0() doesn't lbug"
13940
13941 test_207a() {
13942         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
13943         local fsz=`stat -c %s $DIR/$tfile`
13944         cancel_lru_locks mdc
13945
13946         # do not return layout in getattr intent
13947 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
13948         $LCTL set_param fail_loc=0x170
13949         local sz=`stat -c %s $DIR/$tfile`
13950
13951         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
13952
13953         rm -rf $DIR/$tfile
13954 }
13955 run_test 207a "can refresh layout at glimpse"
13956
13957 test_207b() {
13958         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
13959         local cksum=`md5sum $DIR/$tfile`
13960         local fsz=`stat -c %s $DIR/$tfile`
13961         cancel_lru_locks mdc
13962         cancel_lru_locks osc
13963
13964         # do not return layout in getattr intent
13965 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
13966         $LCTL set_param fail_loc=0x171
13967
13968         # it will refresh layout after the file is opened but before read issues
13969         echo checksum is "$cksum"
13970         echo "$cksum" |md5sum -c --quiet || error "file differs"
13971
13972         rm -rf $DIR/$tfile
13973 }
13974 run_test 207b "can refresh layout at open"
13975
13976 test_208() {
13977         # FIXME: in this test suite, only RD lease is used. This is okay
13978         # for now as only exclusive open is supported. After generic lease
13979         # is done, this test suite should be revised. - Jinshan
13980
13981         remote_mds_nodsh && skip "remote MDS with nodsh"
13982         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
13983                 skip "Need MDS version at least 2.4.52"
13984
13985         echo "==== test 1: verify get lease work"
13986         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
13987
13988         echo "==== test 2: verify lease can be broken by upcoming open"
13989         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
13990         local PID=$!
13991         sleep 1
13992
13993         $MULTIOP $DIR/$tfile oO_RDONLY:c
13994         kill -USR1 $PID && wait $PID || error "break lease error"
13995
13996         echo "==== test 3: verify lease can't be granted if an open already exists"
13997         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
13998         local PID=$!
13999         sleep 1
14000
14001         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
14002         kill -USR1 $PID && wait $PID || error "open file error"
14003
14004         echo "==== test 4: lease can sustain over recovery"
14005         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
14006         PID=$!
14007         sleep 1
14008
14009         fail mds1
14010
14011         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
14012
14013         echo "==== test 5: lease broken can't be regained by replay"
14014         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
14015         PID=$!
14016         sleep 1
14017
14018         # open file to break lease and then recovery
14019         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
14020         fail mds1
14021
14022         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
14023
14024         rm -f $DIR/$tfile
14025 }
14026 run_test 208 "Exclusive open"
14027
14028 test_209() {
14029         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
14030                 skip_env "must have disp_stripe"
14031
14032         touch $DIR/$tfile
14033         sync; sleep 5; sync;
14034
14035         echo 3 > /proc/sys/vm/drop_caches
14036         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
14037
14038         # open/close 500 times
14039         for i in $(seq 500); do
14040                 cat $DIR/$tfile
14041         done
14042
14043         echo 3 > /proc/sys/vm/drop_caches
14044         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
14045
14046         echo "before: $req_before, after: $req_after"
14047         [ $((req_after - req_before)) -ge 300 ] &&
14048                 error "open/close requests are not freed"
14049         return 0
14050 }
14051 run_test 209 "read-only open/close requests should be freed promptly"
14052
14053 test_212() {
14054         size=`date +%s`
14055         size=$((size % 8192 + 1))
14056         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
14057         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
14058         rm -f $DIR/f212 $DIR/f212.xyz
14059 }
14060 run_test 212 "Sendfile test ============================================"
14061
14062 test_213() {
14063         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
14064         cancel_lru_locks osc
14065         lctl set_param fail_loc=0x8000040f
14066         # generate a read lock
14067         cat $DIR/$tfile > /dev/null
14068         # write to the file, it will try to cancel the above read lock.
14069         cat /etc/hosts >> $DIR/$tfile
14070 }
14071 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
14072
14073 test_214() { # for bug 20133
14074         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
14075         for (( i=0; i < 340; i++ )) ; do
14076                 touch $DIR/$tdir/d214c/a$i
14077         done
14078
14079         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
14080         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
14081         ls $DIR/d214c || error "ls $DIR/d214c failed"
14082         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
14083         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
14084 }
14085 run_test 214 "hash-indexed directory test - bug 20133"
14086
14087 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
14088 create_lnet_proc_files() {
14089         lctl get_param -n $1 >$TMP/lnet_$1.sys || error "cannot read lnet.$1"
14090 }
14091
14092 # counterpart of create_lnet_proc_files
14093 remove_lnet_proc_files() {
14094         rm -f $TMP/lnet_$1.sys
14095 }
14096
14097 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
14098 # 3rd arg as regexp for body
14099 check_lnet_proc_stats() {
14100         local l=$(cat "$TMP/lnet_$1" |wc -l)
14101         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
14102
14103         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
14104 }
14105
14106 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
14107 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
14108 # optional and can be regexp for 2nd line (lnet.routes case)
14109 check_lnet_proc_entry() {
14110         local blp=2          # blp stands for 'position of 1st line of body'
14111         [ -z "$5" ] || blp=3 # lnet.routes case
14112
14113         local l=$(cat "$TMP/lnet_$1" |wc -l)
14114         # subtracting one from $blp because the body can be empty
14115         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
14116
14117         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
14118                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
14119
14120         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
14121                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
14122
14123         # bail out if any unexpected line happened
14124         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
14125         [ "$?" != 0 ] || error "$2 misformatted"
14126 }
14127
14128 test_215() { # for bugs 18102, 21079, 21517
14129         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14130
14131         local N='(0|[1-9][0-9]*)'       # non-negative numeric
14132         local P='[1-9][0-9]*'           # positive numeric
14133         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
14134         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
14135         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
14136         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
14137
14138         local L1 # regexp for 1st line
14139         local L2 # regexp for 2nd line (optional)
14140         local BR # regexp for the rest (body)
14141
14142         # lnet.stats should look as 11 space-separated non-negative numerics
14143         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
14144         create_lnet_proc_files "stats"
14145         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
14146         remove_lnet_proc_files "stats"
14147
14148         # lnet.routes should look like this:
14149         # Routing disabled/enabled
14150         # net hops priority state router
14151         # where net is a string like tcp0, hops > 0, priority >= 0,
14152         # state is up/down,
14153         # router is a string like 192.168.1.1@tcp2
14154         L1="^Routing (disabled|enabled)$"
14155         L2="^net +hops +priority +state +router$"
14156         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
14157         create_lnet_proc_files "routes"
14158         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
14159         remove_lnet_proc_files "routes"
14160
14161         # lnet.routers should look like this:
14162         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
14163         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
14164         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
14165         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
14166         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
14167         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
14168         create_lnet_proc_files "routers"
14169         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
14170         remove_lnet_proc_files "routers"
14171
14172         # lnet.peers should look like this:
14173         # nid refs state last max rtr min tx min queue
14174         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
14175         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
14176         # numeric (0 or >0 or <0), queue >= 0.
14177         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
14178         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
14179         create_lnet_proc_files "peers"
14180         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
14181         remove_lnet_proc_files "peers"
14182
14183         # lnet.buffers  should look like this:
14184         # pages count credits min
14185         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
14186         L1="^pages +count +credits +min$"
14187         BR="^ +$N +$N +$I +$I$"
14188         create_lnet_proc_files "buffers"
14189         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
14190         remove_lnet_proc_files "buffers"
14191
14192         # lnet.nis should look like this:
14193         # nid status alive refs peer rtr max tx min
14194         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
14195         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
14196         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
14197         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
14198         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
14199         create_lnet_proc_files "nis"
14200         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
14201         remove_lnet_proc_files "nis"
14202
14203         # can we successfully write to lnet.stats?
14204         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
14205 }
14206 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
14207
14208 test_216() { # bug 20317
14209         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14210         remote_ost_nodsh && skip "remote OST with nodsh"
14211
14212         local node
14213         local facets=$(get_facets OST)
14214         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
14215
14216         save_lustre_params client "osc.*.contention_seconds" > $p
14217         save_lustre_params $facets \
14218                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
14219         save_lustre_params $facets \
14220                 "ldlm.namespaces.filter-*.contended_locks" >> $p
14221         save_lustre_params $facets \
14222                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
14223         clear_stats osc.*.osc_stats
14224
14225         # agressive lockless i/o settings
14226         do_nodes $(comma_list $(osts_nodes)) \
14227                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
14228                         ldlm.namespaces.filter-*.contended_locks=0 \
14229                         ldlm.namespaces.filter-*.contention_seconds=60"
14230         lctl set_param -n osc.*.contention_seconds=60
14231
14232         $DIRECTIO write $DIR/$tfile 0 10 4096
14233         $CHECKSTAT -s 40960 $DIR/$tfile
14234
14235         # disable lockless i/o
14236         do_nodes $(comma_list $(osts_nodes)) \
14237                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
14238                         ldlm.namespaces.filter-*.contended_locks=32 \
14239                         ldlm.namespaces.filter-*.contention_seconds=0"
14240         lctl set_param -n osc.*.contention_seconds=0
14241         clear_stats osc.*.osc_stats
14242
14243         dd if=/dev/zero of=$DIR/$tfile count=0
14244         $CHECKSTAT -s 0 $DIR/$tfile
14245
14246         restore_lustre_params <$p
14247         rm -f $p
14248         rm $DIR/$tfile
14249 }
14250 run_test 216 "check lockless direct write updates file size and kms correctly"
14251
14252 test_217() { # bug 22430
14253         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14254
14255         local node
14256         local nid
14257
14258         for node in $(nodes_list); do
14259                 nid=$(host_nids_address $node $NETTYPE)
14260                 if [[ $nid = *-* ]] ; then
14261                         echo "lctl ping $(h2nettype $nid)"
14262                         lctl ping $(h2nettype $nid)
14263                 else
14264                         echo "skipping $node (no hyphen detected)"
14265                 fi
14266         done
14267 }
14268 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
14269
14270 test_218() {
14271        # do directio so as not to populate the page cache
14272        log "creating a 10 Mb file"
14273        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
14274        log "starting reads"
14275        dd if=$DIR/$tfile of=/dev/null bs=4096 &
14276        log "truncating the file"
14277        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
14278        log "killing dd"
14279        kill %+ || true # reads might have finished
14280        echo "wait until dd is finished"
14281        wait
14282        log "removing the temporary file"
14283        rm -rf $DIR/$tfile || error "tmp file removal failed"
14284 }
14285 run_test 218 "parallel read and truncate should not deadlock"
14286
14287 test_219() {
14288         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14289
14290         # write one partial page
14291         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
14292         # set no grant so vvp_io_commit_write will do sync write
14293         $LCTL set_param fail_loc=0x411
14294         # write a full page at the end of file
14295         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
14296
14297         $LCTL set_param fail_loc=0
14298         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
14299         $LCTL set_param fail_loc=0x411
14300         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
14301
14302         # LU-4201
14303         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
14304         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
14305 }
14306 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
14307
14308 test_220() { #LU-325
14309         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14310         remote_ost_nodsh && skip "remote OST with nodsh"
14311         remote_mds_nodsh && skip "remote MDS with nodsh"
14312         remote_mgs_nodsh && skip "remote MGS with nodsh"
14313
14314         local OSTIDX=0
14315
14316         # create on MDT0000 so the last_id and next_id are correct
14317         mkdir $DIR/$tdir
14318         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
14319         OST=${OST%_UUID}
14320
14321         # on the mdt's osc
14322         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
14323         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
14324                         osc.$mdtosc_proc1.prealloc_last_id)
14325         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
14326                         osc.$mdtosc_proc1.prealloc_next_id)
14327
14328         $LFS df -i
14329
14330         if ! combined_mgs_mds ; then
14331                 mount_mgs_client
14332         fi
14333
14334         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
14335         #define OBD_FAIL_OST_ENOINO              0x229
14336         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
14337         create_pool $FSNAME.$TESTNAME || return 1
14338         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
14339
14340         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
14341
14342         MDSOBJS=$((last_id - next_id))
14343         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
14344
14345         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
14346         echo "OST still has $count kbytes free"
14347
14348         echo "create $MDSOBJS files @next_id..."
14349         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
14350
14351         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
14352                         osc.$mdtosc_proc1.prealloc_last_id)
14353         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
14354                         osc.$mdtosc_proc1.prealloc_next_id)
14355
14356         echo "after creation, last_id=$last_id2, next_id=$next_id2"
14357         $LFS df -i
14358
14359         echo "cleanup..."
14360
14361         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
14362         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
14363
14364         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST ||
14365                 error "$LCTL pool_remove $FSNAME.$TESTNAME $OST failed"
14366         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
14367                 error "$LCTL pool_destroy $FSNAME.$TESTNAME failed"
14368         echo "unlink $MDSOBJS files @$next_id..."
14369         unlinkmany $DIR/$tdir/f $MDSOBJS || error "unlinkmany failed"
14370
14371         if ! combined_mgs_mds ; then
14372                 umount_mgs_client
14373         fi
14374 }
14375 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
14376
14377 test_221() {
14378         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14379
14380         dd if=`which date` of=$MOUNT/date oflag=sync
14381         chmod +x $MOUNT/date
14382
14383         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
14384         $LCTL set_param fail_loc=0x80001401
14385
14386         $MOUNT/date > /dev/null
14387         rm -f $MOUNT/date
14388 }
14389 run_test 221 "make sure fault and truncate race to not cause OOM"
14390
14391 test_222a () {
14392         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14393
14394         rm -rf $DIR/$tdir
14395         test_mkdir $DIR/$tdir
14396         $LFS setstripe -c 1 -i 0 $DIR/$tdir
14397         createmany -o $DIR/$tdir/$tfile 10
14398         cancel_lru_locks mdc
14399         cancel_lru_locks osc
14400         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
14401         $LCTL set_param fail_loc=0x31a
14402         ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
14403         $LCTL set_param fail_loc=0
14404         rm -r $DIR/$tdir
14405 }
14406 run_test 222a "AGL for ls should not trigger CLIO lock failure"
14407
14408 test_222b () {
14409         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14410
14411         rm -rf $DIR/$tdir
14412         test_mkdir $DIR/$tdir
14413         $LFS setstripe -c 1 -i 0 $DIR/$tdir
14414         createmany -o $DIR/$tdir/$tfile 10
14415         cancel_lru_locks mdc
14416         cancel_lru_locks osc
14417         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
14418         $LCTL set_param fail_loc=0x31a
14419         rm -r $DIR/$tdir || error "AGL for rmdir failed"
14420         $LCTL set_param fail_loc=0
14421 }
14422 run_test 222b "AGL for rmdir should not trigger CLIO lock failure"
14423
14424 test_223 () {
14425         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14426
14427         rm -rf $DIR/$tdir
14428         test_mkdir $DIR/$tdir
14429         $LFS setstripe -c 1 -i 0 $DIR/$tdir
14430         createmany -o $DIR/$tdir/$tfile 10
14431         cancel_lru_locks mdc
14432         cancel_lru_locks osc
14433         #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
14434         $LCTL set_param fail_loc=0x31b
14435         ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
14436         $LCTL set_param fail_loc=0
14437         rm -r $DIR/$tdir
14438 }
14439 run_test 223 "osc reenqueue if without AGL lock granted ======================="
14440
14441 test_224a() { # LU-1039, MRP-303
14442         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14443
14444         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
14445         $LCTL set_param fail_loc=0x508
14446         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
14447         $LCTL set_param fail_loc=0
14448         df $DIR
14449 }
14450 run_test 224a "Don't panic on bulk IO failure"
14451
14452 test_224b() { # LU-1039, MRP-303
14453         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14454
14455         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
14456         cancel_lru_locks osc
14457         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
14458         $LCTL set_param fail_loc=0x515
14459         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
14460         $LCTL set_param fail_loc=0
14461         df $DIR
14462 }
14463 run_test 224b "Don't panic on bulk IO failure"
14464
14465 test_224c() { # LU-6441
14466         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14467         remote_mds_nodsh && skip "remote MDS with nodsh"
14468
14469         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
14470         save_writethrough $p
14471         set_cache writethrough on
14472
14473         local pages_per_rpc=$($LCTL get_param \
14474                                 osc.*.max_pages_per_rpc)
14475         local at_max=$($LCTL get_param -n at_max)
14476         local timeout=$($LCTL get_param -n timeout)
14477         local test_at="$LCTL get_param -n at_max"
14478         local param_at="$FSNAME.sys.at_max"
14479         local test_timeout="$LCTL get_param -n timeout"
14480         local param_timeout="$FSNAME.sys.timeout"
14481
14482         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
14483
14484         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
14485                 error "conf_param at_max=0 failed"
14486         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
14487                 error "conf_param timeout=5 failed"
14488
14489         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
14490         do_facet ost1 $LCTL set_param fail_loc=0x520
14491         $LFS setstripe -c 1 -i 0 $DIR/$tfile
14492         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
14493         sync
14494         do_facet ost1 $LCTL set_param fail_loc=0
14495
14496         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
14497                 error "conf_param at_max=$at_max failed"
14498         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
14499                 $timeout || error "conf_param timeout=$timeout failed"
14500
14501         $LCTL set_param -n $pages_per_rpc
14502         restore_lustre_params < $p
14503         rm -f $p
14504 }
14505 run_test 224c "Don't hang if one of md lost during large bulk RPC"
14506
14507 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
14508 test_225a () {
14509         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14510         if [ -z ${MDSSURVEY} ]; then
14511                 skip_env "mds-survey not found"
14512         fi
14513         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
14514                 skip "Need MDS version at least 2.2.51"
14515
14516         local mds=$(facet_host $SINGLEMDS)
14517         local target=$(do_nodes $mds 'lctl dl' |
14518                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
14519
14520         local cmd1="file_count=1000 thrhi=4"
14521         local cmd2="dir_count=2 layer=mdd stripe_count=0"
14522         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
14523         local cmd="$cmd1 $cmd2 $cmd3"
14524
14525         rm -f ${TMP}/mds_survey*
14526         echo + $cmd
14527         eval $cmd || error "mds-survey with zero-stripe failed"
14528         cat ${TMP}/mds_survey*
14529         rm -f ${TMP}/mds_survey*
14530 }
14531 run_test 225a "Metadata survey sanity with zero-stripe"
14532
14533 test_225b () {
14534         if [ -z ${MDSSURVEY} ]; then
14535                 skip_env "mds-survey not found"
14536         fi
14537         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
14538                 skip "Need MDS version at least 2.2.51"
14539         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14540         remote_mds_nodsh && skip "remote MDS with nodsh"
14541         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
14542                 skip_env "Need to mount OST to test"
14543         fi
14544
14545         local mds=$(facet_host $SINGLEMDS)
14546         local target=$(do_nodes $mds 'lctl dl' |
14547                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
14548
14549         local cmd1="file_count=1000 thrhi=4"
14550         local cmd2="dir_count=2 layer=mdd stripe_count=1"
14551         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
14552         local cmd="$cmd1 $cmd2 $cmd3"
14553
14554         rm -f ${TMP}/mds_survey*
14555         echo + $cmd
14556         eval $cmd || error "mds-survey with stripe_count failed"
14557         cat ${TMP}/mds_survey*
14558         rm -f ${TMP}/mds_survey*
14559 }
14560 run_test 225b "Metadata survey sanity with stripe_count = 1"
14561
14562 mcreate_path2fid () {
14563         local mode=$1
14564         local major=$2
14565         local minor=$3
14566         local name=$4
14567         local desc=$5
14568         local path=$DIR/$tdir/$name
14569         local fid
14570         local rc
14571         local fid_path
14572
14573         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
14574                 error "cannot create $desc"
14575
14576         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
14577         rc=$?
14578         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
14579
14580         fid_path=$($LFS fid2path $MOUNT $fid)
14581         rc=$?
14582         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
14583
14584         [ "$path" == "$fid_path" ] ||
14585                 error "fid2path returned $fid_path, expected $path"
14586
14587         echo "pass with $path and $fid"
14588 }
14589
14590 test_226a () {
14591         rm -rf $DIR/$tdir
14592         mkdir -p $DIR/$tdir
14593
14594         mcreate_path2fid 0010666 0 0 fifo "FIFO"
14595         mcreate_path2fid 0020666 1 3 null "character special file (null)"
14596         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
14597         mcreate_path2fid 0040666 0 0 dir "directory"
14598         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
14599         mcreate_path2fid 0100666 0 0 file "regular file"
14600         mcreate_path2fid 0120666 0 0 link "symbolic link"
14601         mcreate_path2fid 0140666 0 0 sock "socket"
14602 }
14603 run_test 226a "call path2fid and fid2path on files of all type"
14604
14605 test_226b () {
14606         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14607
14608         local MDTIDX=1
14609
14610         rm -rf $DIR/$tdir
14611         mkdir -p $DIR/$tdir
14612         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
14613                 error "create remote directory failed"
14614         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
14615         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
14616                                 "character special file (null)"
14617         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
14618                                 "character special file (no device)"
14619         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
14620         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
14621                                 "block special file (loop)"
14622         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
14623         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
14624         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
14625 }
14626 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
14627
14628 # LU-1299 Executing or running ldd on a truncated executable does not
14629 # cause an out-of-memory condition.
14630 test_227() {
14631         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14632         [ -z "$(which ldd)" ] && skip_env "should have ldd tool"
14633
14634         dd if=$(which date) of=$MOUNT/date bs=1k count=1
14635         chmod +x $MOUNT/date
14636
14637         $MOUNT/date > /dev/null
14638         ldd $MOUNT/date > /dev/null
14639         rm -f $MOUNT/date
14640 }
14641 run_test 227 "running truncated executable does not cause OOM"
14642
14643 # LU-1512 try to reuse idle OI blocks
14644 test_228a() {
14645         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14646         remote_mds_nodsh && skip "remote MDS with nodsh"
14647         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14648                 skip_env "ldiskfs only test"
14649
14650         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14651         local myDIR=$DIR/$tdir
14652
14653         mkdir -p $myDIR
14654         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14655         $LCTL set_param fail_loc=0x80001002
14656         createmany -o $myDIR/t- 10000
14657         $LCTL set_param fail_loc=0
14658         # The guard is current the largest FID holder
14659         touch $myDIR/guard
14660         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14661                     tr -d '[')
14662         local IDX=$(($SEQ % 64))
14663
14664         do_facet $SINGLEMDS sync
14665         # Make sure journal flushed.
14666         sleep 6
14667         local blk1=$(do_facet $SINGLEMDS \
14668                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14669                      grep Blockcount | awk '{print $4}')
14670
14671         # Remove old files, some OI blocks will become idle.
14672         unlinkmany $myDIR/t- 10000
14673         # Create new files, idle OI blocks should be reused.
14674         createmany -o $myDIR/t- 2000
14675         do_facet $SINGLEMDS sync
14676         # Make sure journal flushed.
14677         sleep 6
14678         local blk2=$(do_facet $SINGLEMDS \
14679                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14680                      grep Blockcount | awk '{print $4}')
14681
14682         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14683 }
14684 run_test 228a "try to reuse idle OI blocks"
14685
14686 test_228b() {
14687         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14688         remote_mds_nodsh && skip "remote MDS with nodsh"
14689         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14690                 skip_env "ldiskfs only test"
14691
14692         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14693         local myDIR=$DIR/$tdir
14694
14695         mkdir -p $myDIR
14696         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14697         $LCTL set_param fail_loc=0x80001002
14698         createmany -o $myDIR/t- 10000
14699         $LCTL set_param fail_loc=0
14700         # The guard is current the largest FID holder
14701         touch $myDIR/guard
14702         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14703                     tr -d '[')
14704         local IDX=$(($SEQ % 64))
14705
14706         do_facet $SINGLEMDS sync
14707         # Make sure journal flushed.
14708         sleep 6
14709         local blk1=$(do_facet $SINGLEMDS \
14710                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14711                      grep Blockcount | awk '{print $4}')
14712
14713         # Remove old files, some OI blocks will become idle.
14714         unlinkmany $myDIR/t- 10000
14715
14716         # stop the MDT
14717         stop $SINGLEMDS || error "Fail to stop MDT."
14718         # remount the MDT
14719         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
14720
14721         df $MOUNT || error "Fail to df."
14722         # Create new files, idle OI blocks should be reused.
14723         createmany -o $myDIR/t- 2000
14724         do_facet $SINGLEMDS sync
14725         # Make sure journal flushed.
14726         sleep 6
14727         local blk2=$(do_facet $SINGLEMDS \
14728                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14729                      grep Blockcount | awk '{print $4}')
14730
14731         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14732 }
14733 run_test 228b "idle OI blocks can be reused after MDT restart"
14734
14735 #LU-1881
14736 test_228c() {
14737         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14738         remote_mds_nodsh && skip "remote MDS with nodsh"
14739         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14740                 skip_env "ldiskfs only test"
14741
14742         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14743         local myDIR=$DIR/$tdir
14744
14745         mkdir -p $myDIR
14746         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14747         $LCTL set_param fail_loc=0x80001002
14748         # 20000 files can guarantee there are index nodes in the OI file
14749         createmany -o $myDIR/t- 20000
14750         $LCTL set_param fail_loc=0
14751         # The guard is current the largest FID holder
14752         touch $myDIR/guard
14753         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14754                     tr -d '[')
14755         local IDX=$(($SEQ % 64))
14756
14757         do_facet $SINGLEMDS sync
14758         # Make sure journal flushed.
14759         sleep 6
14760         local blk1=$(do_facet $SINGLEMDS \
14761                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14762                      grep Blockcount | awk '{print $4}')
14763
14764         # Remove old files, some OI blocks will become idle.
14765         unlinkmany $myDIR/t- 20000
14766         rm -f $myDIR/guard
14767         # The OI file should become empty now
14768
14769         # Create new files, idle OI blocks should be reused.
14770         createmany -o $myDIR/t- 2000
14771         do_facet $SINGLEMDS sync
14772         # Make sure journal flushed.
14773         sleep 6
14774         local blk2=$(do_facet $SINGLEMDS \
14775                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14776                      grep Blockcount | awk '{print $4}')
14777
14778         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14779 }
14780 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
14781
14782 test_229() { # LU-2482, LU-3448
14783         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14784         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
14785         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
14786                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53"
14787
14788         rm -f $DIR/$tfile
14789
14790         # Create a file with a released layout and stripe count 2.
14791         $MULTIOP $DIR/$tfile H2c ||
14792                 error "failed to create file with released layout"
14793
14794         $GETSTRIPE -v $DIR/$tfile
14795
14796         local pattern=$($GETSTRIPE -L $DIR/$tfile)
14797         [ X"$pattern" = X"released" ] || error "pattern error ($pattern)"
14798
14799         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
14800         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
14801         stat $DIR/$tfile || error "failed to stat released file"
14802
14803         chown $RUNAS_ID $DIR/$tfile ||
14804                 error "chown $RUNAS_ID $DIR/$tfile failed"
14805
14806         chgrp $RUNAS_ID $DIR/$tfile ||
14807                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
14808
14809         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
14810         rm $DIR/$tfile || error "failed to remove released file"
14811 }
14812 run_test 229 "getstripe/stat/rm/attr changes work on released files"
14813
14814 test_230a() {
14815         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14816         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14817
14818         local MDTIDX=1
14819
14820         test_mkdir $DIR/$tdir
14821         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
14822         local mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230_local)
14823         [ $mdt_idx -ne 0 ] &&
14824                 error "create local directory on wrong MDT $mdt_idx"
14825
14826         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
14827                         error "create remote directory failed"
14828         local mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230)
14829         [ $mdt_idx -ne $MDTIDX ] &&
14830                 error "create remote directory on wrong MDT $mdt_idx"
14831
14832         createmany -o $DIR/$tdir/test_230/t- 10 ||
14833                 error "create files on remote directory failed"
14834         mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230/t-0)
14835         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
14836         rm -r $DIR/$tdir || error "unlink remote directory failed"
14837 }
14838 run_test 230a "Create remote directory and files under the remote directory"
14839
14840 test_230b() {
14841         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14842         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14843
14844         local MDTIDX=1
14845         local mdt_index
14846         local i
14847         local file
14848         local pid
14849         local stripe_count
14850         local migrate_dir=$DIR/$tdir/migrate_dir
14851         local other_dir=$DIR/$tdir/other_dir
14852
14853         test_mkdir $DIR/$tdir
14854         test_mkdir -i0 -c1 $migrate_dir
14855         test_mkdir -i0 -c1 $other_dir
14856         for ((i=0; i<10; i++)); do
14857                 mkdir -p $migrate_dir/dir_${i}
14858                 createmany -o $migrate_dir/dir_${i}/f 10 ||
14859                         error "create files under remote dir failed $i"
14860         done
14861
14862         cp /etc/passwd $migrate_dir/$tfile
14863         cp /etc/passwd $other_dir/$tfile
14864         chattr +SAD $migrate_dir
14865         chattr +SAD $migrate_dir/$tfile
14866
14867         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14868         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14869         local old_dir_mode=$(stat -c%f $migrate_dir)
14870         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
14871
14872         mkdir -p $migrate_dir/dir_default_stripe2
14873         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
14874         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
14875
14876         mkdir -p $other_dir
14877         ln $migrate_dir/$tfile $other_dir/luna
14878         ln $migrate_dir/$tfile $migrate_dir/sofia
14879         ln $other_dir/$tfile $migrate_dir/david
14880         ln -s $migrate_dir/$tfile $other_dir/zachary
14881         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
14882         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
14883
14884         $LFS migrate -m $MDTIDX $migrate_dir ||
14885                 error "fails on migrating remote dir to MDT1"
14886
14887         echo "migratate to MDT1, then checking.."
14888         for ((i = 0; i < 10; i++)); do
14889                 for file in $(find $migrate_dir/dir_${i}); do
14890                         mdt_index=$($LFS getstripe -m $file)
14891                         [ $mdt_index == $MDTIDX ] ||
14892                                 error "$file is not on MDT${MDTIDX}"
14893                 done
14894         done
14895
14896         # the multiple link file should still in MDT0
14897         mdt_index=$($LFS getstripe -m $migrate_dir/$tfile)
14898         [ $mdt_index == 0 ] ||
14899                 error "$file is not on MDT${MDTIDX}"
14900
14901         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14902         [ "$old_dir_flag" = "$new_dir_flag" ] ||
14903                 error " expect $old_dir_flag get $new_dir_flag"
14904
14905         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14906         [ "$old_file_flag" = "$new_file_flag" ] ||
14907                 error " expect $old_file_flag get $new_file_flag"
14908
14909         local new_dir_mode=$(stat -c%f $migrate_dir)
14910         [ "$old_dir_mode" = "$new_dir_mode" ] ||
14911                 error "expect mode $old_dir_mode get $new_dir_mode"
14912
14913         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
14914         [ "$old_file_mode" = "$new_file_mode" ] ||
14915                 error "expect mode $old_file_mode get $new_file_mode"
14916
14917         diff /etc/passwd $migrate_dir/$tfile ||
14918                 error "$tfile different after migration"
14919
14920         diff /etc/passwd $other_dir/luna ||
14921                 error "luna different after migration"
14922
14923         diff /etc/passwd $migrate_dir/sofia ||
14924                 error "sofia different after migration"
14925
14926         diff /etc/passwd $migrate_dir/david ||
14927                 error "david different after migration"
14928
14929         diff /etc/passwd $other_dir/zachary ||
14930                 error "zachary different after migration"
14931
14932         diff /etc/passwd $migrate_dir/${tfile}_ln ||
14933                 error "${tfile}_ln different after migration"
14934
14935         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
14936                 error "${tfile}_ln_other different after migration"
14937
14938         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
14939         [ $stripe_count = 2 ] ||
14940                 error "dir strpe_count $d != 2 after migration."
14941
14942         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
14943         [ $stripe_count = 2 ] ||
14944                 error "file strpe_count $d != 2 after migration."
14945
14946         #migrate back to MDT0
14947         MDTIDX=0
14948
14949         $LFS migrate -m $MDTIDX $migrate_dir ||
14950                 error "fails on migrating remote dir to MDT0"
14951
14952         echo "migrate back to MDT0, checking.."
14953         for file in $(find $migrate_dir); do
14954                 mdt_index=$($LFS getstripe -m $file)
14955                 [ $mdt_index == $MDTIDX ] ||
14956                         error "$file is not on MDT${MDTIDX}"
14957         done
14958
14959         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14960         [ "$old_dir_flag" = "$new_dir_flag" ] ||
14961                 error " expect $old_dir_flag get $new_dir_flag"
14962
14963         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14964         [ "$old_file_flag" = "$new_file_flag" ] ||
14965                 error " expect $old_file_flag get $new_file_flag"
14966
14967         local new_dir_mode=$(stat -c%f $migrate_dir)
14968         [ "$old_dir_mode" = "$new_dir_mode" ] ||
14969                 error "expect mode $old_dir_mode get $new_dir_mode"
14970
14971         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
14972         [ "$old_file_mode" = "$new_file_mode" ] ||
14973                 error "expect mode $old_file_mode get $new_file_mode"
14974
14975         diff /etc/passwd ${migrate_dir}/$tfile ||
14976                 error "$tfile different after migration"
14977
14978         diff /etc/passwd ${other_dir}/luna ||
14979                 error "luna different after migration"
14980
14981         diff /etc/passwd ${migrate_dir}/sofia ||
14982                 error "sofia different after migration"
14983
14984         diff /etc/passwd ${other_dir}/zachary ||
14985                 error "zachary different after migration"
14986
14987         diff /etc/passwd $migrate_dir/${tfile}_ln ||
14988                 error "${tfile}_ln different after migration"
14989
14990         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
14991                 error "${tfile}_ln_other different after migration"
14992
14993         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
14994         [ $stripe_count = 2 ] ||
14995                 error "dir strpe_count $d != 2 after migration."
14996
14997         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
14998         [ $stripe_count = 2 ] ||
14999                 error "file strpe_count $d != 2 after migration."
15000
15001         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15002 }
15003 run_test 230b "migrate directory"
15004
15005 test_230c() {
15006         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15007         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15008         remote_mds_nodsh && skip "remote MDS with nodsh"
15009
15010         local MDTIDX=1
15011         local mdt_index
15012         local file
15013         local migrate_dir=$DIR/$tdir/migrate_dir
15014
15015         #If migrating directory fails in the middle, all entries of
15016         #the directory is still accessiable.
15017         test_mkdir $DIR/$tdir
15018         test_mkdir -i0 -c1 $migrate_dir
15019         stat $migrate_dir
15020         createmany -o $migrate_dir/f 10 ||
15021                 error "create files under ${migrate_dir} failed"
15022
15023         #failed after migrating 5 entries
15024         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
15025         do_facet mds1 lctl set_param fail_loc=0x20001801
15026         do_facet mds1 lctl  set_param fail_val=5
15027         local t=$(ls $migrate_dir | wc -l)
15028         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
15029                 error "migrate should fail after 5 entries"
15030
15031         mkdir $migrate_dir/dir &&
15032                 error "mkdir succeeds under migrating directory"
15033         touch $migrate_dir/file &&
15034                 error "touch file succeeds under migrating directory"
15035
15036         local u=$(ls $migrate_dir | wc -l)
15037         [ "$u" == "$t" ] || error "$u != $t during migration"
15038
15039         for file in $(find $migrate_dir); do
15040                 stat $file || error "stat $file failed"
15041         done
15042
15043         do_facet mds1 lctl set_param fail_loc=0
15044         do_facet mds1 lctl set_param fail_val=0
15045
15046         $LFS migrate -m $MDTIDX $migrate_dir ||
15047                 error "migrate open files should failed with open files"
15048
15049         echo "Finish migration, then checking.."
15050         for file in $(find $migrate_dir); do
15051                 mdt_index=$($LFS getstripe -m $file)
15052                 [ $mdt_index == $MDTIDX ] ||
15053                         error "$file is not on MDT${MDTIDX}"
15054         done
15055
15056         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15057 }
15058 run_test 230c "check directory accessiblity if migration is failed"
15059
15060 test_230d() {
15061         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15062         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15063
15064         local MDTIDX=1
15065         local mdt_index
15066         local migrate_dir=$DIR/$tdir/migrate_dir
15067         local i
15068         local j
15069
15070         test_mkdir $DIR/$tdir
15071         test_mkdir -i0 -c1 $migrate_dir
15072
15073         for ((i=0; i<100; i++)); do
15074                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
15075                 createmany -o $migrate_dir/dir_${i}/f 100 ||
15076                         error "create files under remote dir failed $i"
15077         done
15078
15079         $LFS migrate -m $MDTIDX $migrate_dir ||
15080                 error "migrate remote dir error"
15081
15082         echo "Finish migration, then checking.."
15083         for file in $(find $migrate_dir); do
15084                 mdt_index=$($LFS getstripe -m $file)
15085                 [ $mdt_index == $MDTIDX ] ||
15086                         error "$file is not on MDT${MDTIDX}"
15087         done
15088
15089         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15090 }
15091 run_test 230d "check migrate big directory"
15092
15093 test_230e() {
15094         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15095         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15096
15097         local i
15098         local j
15099         local a_fid
15100         local b_fid
15101
15102         mkdir -p $DIR/$tdir
15103         mkdir $DIR/$tdir/migrate_dir
15104         mkdir $DIR/$tdir/other_dir
15105         touch $DIR/$tdir/migrate_dir/a
15106         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
15107         ls $DIR/$tdir/other_dir
15108
15109         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
15110                 error "migrate dir fails"
15111
15112         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
15113         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
15114
15115         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15116         [ $mdt_index == 0 ] || error "a is not on MDT0"
15117
15118         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
15119                 error "migrate dir fails"
15120
15121         mdt_index=$($LFS getstripe -m $DIR/$tdir/other_dir)
15122         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
15123
15124         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15125         [ $mdt_index == 1 ] || error "a is not on MDT1"
15126
15127         mdt_index=$($LFS getstripe -m $DIR/$tdir/other_dir/b)
15128         [ $mdt_index == 1 ] || error "b is not on MDT1"
15129
15130         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
15131         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
15132
15133         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
15134
15135         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15136 }
15137 run_test 230e "migrate mulitple local link files"
15138
15139 test_230f() {
15140         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15141         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15142
15143         local a_fid
15144         local ln_fid
15145
15146         mkdir -p $DIR/$tdir
15147         mkdir $DIR/$tdir/migrate_dir
15148         $LFS mkdir -i1 $DIR/$tdir/other_dir
15149         touch $DIR/$tdir/migrate_dir/a
15150         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
15151         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
15152         ls $DIR/$tdir/other_dir
15153
15154         # a should be migrated to MDT1, since no other links on MDT0
15155         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
15156                 error "#1 migrate dir fails"
15157         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
15158         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
15159         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15160         [ $mdt_index == 1 ] || error "a is not on MDT1"
15161
15162         # a should stay on MDT1, because it is a mulitple link file
15163         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
15164                 error "#2 migrate dir fails"
15165         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15166         [ $mdt_index == 1 ] || error "a is not on MDT1"
15167
15168         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
15169                 error "#3 migrate dir fails"
15170
15171         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
15172         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
15173         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
15174
15175         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
15176         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
15177
15178         # a should be migrated to MDT0, since no other links on MDT1
15179         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
15180                 error "#4 migrate dir fails"
15181         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15182         [ $mdt_index == 0 ] || error "a is not on MDT0"
15183
15184         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15185 }
15186 run_test 230f "migrate mulitple remote link files"
15187
15188 test_230g() {
15189         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15190         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15191
15192         mkdir -p $DIR/$tdir/migrate_dir
15193
15194         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
15195                 error "migrating dir to non-exist MDT succeeds"
15196         true
15197 }
15198 run_test 230g "migrate dir to non-exist MDT"
15199
15200 test_230h() {
15201         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15202         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15203         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
15204                 skip "Need MDS version at least 2.7.64"
15205
15206         local mdt_index
15207
15208         mkdir -p $DIR/$tdir/migrate_dir
15209
15210         $LFS migrate -m1 $DIR &&
15211                 error "migrating mountpoint1 should fail"
15212
15213         $LFS migrate -m1 $DIR/$tdir/.. &&
15214                 error "migrating mountpoint2 should fail"
15215
15216         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
15217                 error "migrating $tdir fail"
15218
15219         mdt_index=$($LFS getstripe -m $DIR/$tdir)
15220         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
15221
15222         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
15223         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
15224
15225 }
15226 run_test 230h "migrate .. and root"
15227
15228 test_230i() {
15229         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15230         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15231
15232         mkdir -p $DIR/$tdir/migrate_dir
15233
15234         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
15235                 error "migration fails with a tailing slash"
15236
15237         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
15238                 error "migration fails with two tailing slashes"
15239 }
15240 run_test 230i "lfs migrate -m tolerates trailing slashes"
15241
15242 test_231a()
15243 {
15244         # For simplicity this test assumes that max_pages_per_rpc
15245         # is the same across all OSCs
15246         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
15247         local bulk_size=$((max_pages * 4096))
15248         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
15249                                        head -n 1)
15250
15251         mkdir -p $DIR/$tdir
15252         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
15253                 error "failed to set stripe with -S ${brw_size}M option"
15254
15255         # clear the OSC stats
15256         $LCTL set_param osc.*.stats=0 &>/dev/null
15257         stop_writeback
15258
15259         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
15260         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
15261                 oflag=direct &>/dev/null || error "dd failed"
15262
15263         sync; sleep 1; sync # just to be safe
15264         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
15265         if [ x$nrpcs != "x1" ]; then
15266                 $LCTL get_param osc.*.stats
15267                 error "found $nrpcs ost_write RPCs, not 1 as expected"
15268         fi
15269
15270         start_writeback
15271         # Drop the OSC cache, otherwise we will read from it
15272         cancel_lru_locks osc
15273
15274         # clear the OSC stats
15275         $LCTL set_param osc.*.stats=0 &>/dev/null
15276
15277         # Client reads $bulk_size.
15278         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
15279                 iflag=direct &>/dev/null || error "dd failed"
15280
15281         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
15282         if [ x$nrpcs != "x1" ]; then
15283                 $LCTL get_param osc.*.stats
15284                 error "found $nrpcs ost_read RPCs, not 1 as expected"
15285         fi
15286 }
15287 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
15288
15289 test_231b() {
15290         mkdir -p $DIR/$tdir
15291         local i
15292         for i in {0..1023}; do
15293                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
15294                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
15295                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
15296         done
15297         sync
15298 }
15299 run_test 231b "must not assert on fully utilized OST request buffer"
15300
15301 test_232a() {
15302         mkdir -p $DIR/$tdir
15303         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
15304
15305         #define OBD_FAIL_LDLM_OST_LVB            0x31c
15306         do_facet ost1 $LCTL set_param fail_loc=0x31c
15307
15308         # ignore dd failure
15309         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
15310
15311         do_facet ost1 $LCTL set_param fail_loc=0
15312         umount_client $MOUNT || error "umount failed"
15313         mount_client $MOUNT || error "mount failed"
15314         stop ost1 || error "cannot stop ost1"
15315         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
15316 }
15317 run_test 232a "failed lock should not block umount"
15318
15319 test_232b() {
15320         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.58) ] ||
15321                 skip "Need MDS version at least 2.10.58"
15322
15323         mkdir -p $DIR/$tdir
15324         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
15325         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1
15326         sync
15327         cancel_lru_locks osc
15328
15329         #define OBD_FAIL_LDLM_OST_LVB            0x31c
15330         do_facet ost1 $LCTL set_param fail_loc=0x31c
15331
15332         # ignore failure
15333         $LFS data_version $DIR/$tdir/$tfile || true
15334
15335         do_facet ost1 $LCTL set_param fail_loc=0
15336         umount_client $MOUNT || error "umount failed"
15337         mount_client $MOUNT || error "mount failed"
15338         stop ost1 || error "cannot stop ost1"
15339         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
15340 }
15341 run_test 232b "failed data version lock should not block umount"
15342
15343 test_233a() {
15344         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
15345                 skip "Need MDS version at least 2.3.64"
15346         [ -n "$FILESET" ] && skip_env "SKIP due to FILESET set"
15347
15348         local fid=$($LFS path2fid $MOUNT)
15349
15350         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
15351                 error "cannot access $MOUNT using its FID '$fid'"
15352 }
15353 run_test 233a "checking that OBF of the FS root succeeds"
15354
15355 test_233b() {
15356         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
15357                 skip "Need MDS version at least 2.5.90"
15358         [ -n "$FILESET" ] && skip_env "SKIP due to FILESET set"
15359
15360         local fid=$($LFS path2fid $MOUNT/.lustre)
15361
15362         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
15363                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
15364
15365         fid=$($LFS path2fid $MOUNT/.lustre/fid)
15366         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
15367                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
15368 }
15369 run_test 233b "checking that OBF of the FS .lustre succeeds"
15370
15371 test_234() {
15372         local p="$TMP/sanityN-$TESTNAME.parameters"
15373         save_lustre_params client "llite.*.xattr_cache" > $p
15374         lctl set_param llite.*.xattr_cache 1 ||
15375                 skip_env "xattr cache is not supported"
15376
15377         mkdir -p $DIR/$tdir || error "mkdir failed"
15378         touch $DIR/$tdir/$tfile || error "touch failed"
15379         # OBD_FAIL_LLITE_XATTR_ENOMEM
15380         $LCTL set_param fail_loc=0x1405
15381         getfattr -n user.attr $DIR/$tdir/$tfile &&
15382                 error "getfattr should have failed with ENOMEM"
15383         $LCTL set_param fail_loc=0x0
15384         rm -rf $DIR/$tdir
15385
15386         restore_lustre_params < $p
15387         rm -f $p
15388 }
15389 run_test 234 "xattr cache should not crash on ENOMEM"
15390
15391 test_235() {
15392         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
15393                 skip "Need MDS version at least 2.4.52"
15394
15395         flock_deadlock $DIR/$tfile
15396         local RC=$?
15397         case $RC in
15398                 0)
15399                 ;;
15400                 124) error "process hangs on a deadlock"
15401                 ;;
15402                 *) error "error executing flock_deadlock $DIR/$tfile"
15403                 ;;
15404         esac
15405 }
15406 run_test 235 "LU-1715: flock deadlock detection does not work properly"
15407
15408 #LU-2935
15409 test_236() {
15410         check_swap_layouts_support
15411
15412         local ref1=/etc/passwd
15413         local ref2=/etc/group
15414         local file1=$DIR/$tdir/f1
15415         local file2=$DIR/$tdir/f2
15416
15417         test_mkdir -c1 $DIR/$tdir
15418         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
15419         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
15420         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
15421         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
15422         local fd=$(free_fd)
15423         local cmd="exec $fd<>$file2"
15424         eval $cmd
15425         rm $file2
15426         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
15427                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
15428         cmd="exec $fd>&-"
15429         eval $cmd
15430         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
15431
15432         #cleanup
15433         rm -rf $DIR/$tdir
15434 }
15435 run_test 236 "Layout swap on open unlinked file"
15436
15437 # test to verify file handle related system calls
15438 # (name_to_handle_at/open_by_handle_at)
15439 # The new system calls are supported in glibc >= 2.14.
15440
15441 test_237() {
15442         echo "Test file_handle syscalls" > $DIR/$tfile ||
15443                 error "write failed"
15444         check_fhandle_syscalls $DIR/$tfile ||
15445                 error "check_fhandle_syscalls failed"
15446 }
15447 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
15448
15449 # LU-4659 linkea consistency
15450 test_238() {
15451         local server_version=$(lustre_version_code $SINGLEMDS)
15452
15453         [[ $server_version -gt $(version_code 2.5.57) ]] ||
15454                 [[ $server_version -gt $(version_code 2.5.1) &&
15455                    $server_version -lt $(version_code 2.5.50) ]] ||
15456                 skip "Need MDS version at least 2.5.58 or 2.5.2+"
15457
15458         touch $DIR/$tfile
15459         ln $DIR/$tfile $DIR/$tfile.lnk
15460         touch $DIR/$tfile.new
15461         mv $DIR/$tfile.new $DIR/$tfile
15462         local fid1=$($LFS path2fid $DIR/$tfile)
15463         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
15464         local path1=$($LFS fid2path $FSNAME "$fid1")
15465         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
15466         local path2=$($LFS fid2path $FSNAME "$fid2")
15467         [ $tfile.lnk == $path2 ] ||
15468                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
15469         rm -f $DIR/$tfile*
15470 }
15471 run_test 238 "Verify linkea consistency"
15472
15473 test_239A() { # was test_239
15474         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
15475                 skip "Need MDS version at least 2.5.60"
15476
15477         local list=$(comma_list $(mdts_nodes))
15478
15479         mkdir -p $DIR/$tdir
15480         createmany -o $DIR/$tdir/f- 5000
15481         unlinkmany $DIR/$tdir/f- 5000
15482         [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ] &&
15483                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
15484         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
15485                         osp.*MDT*.sync_in_flight" | calc_sum)
15486         [ "$changes" -eq 0 ] || error "$changes not synced"
15487 }
15488 run_test 239A "osp_sync test"
15489
15490 test_239a() { #LU-5297
15491         remote_mds_nodsh && skip "remote MDS with nodsh"
15492
15493         touch $DIR/$tfile
15494         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
15495         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
15496         chgrp $RUNAS_GID $DIR/$tfile
15497         wait_delete_completed
15498 }
15499 run_test 239a "process invalid osp sync record correctly"
15500
15501 test_239b() { #LU-5297
15502         remote_mds_nodsh && skip "remote MDS with nodsh"
15503
15504         touch $DIR/$tfile1
15505         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
15506         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
15507         chgrp $RUNAS_GID $DIR/$tfile1
15508         wait_delete_completed
15509         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
15510         touch $DIR/$tfile2
15511         chgrp $RUNAS_GID $DIR/$tfile2
15512         wait_delete_completed
15513 }
15514 run_test 239b "process osp sync record with ENOMEM error correctly"
15515
15516 test_240() {
15517         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15518         remote_mds_nodsh && skip "remote MDS with nodsh"
15519
15520         mkdir -p $DIR/$tdir
15521
15522         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
15523                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
15524         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
15525                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
15526
15527         umount_client $MOUNT || error "umount failed"
15528         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
15529         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
15530         mount_client $MOUNT || error "failed to mount client"
15531
15532         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
15533         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
15534 }
15535 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
15536
15537 test_241_bio() {
15538         for LOOP in $(seq $1); do
15539                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
15540                 cancel_lru_locks $OSC || true
15541         done
15542 }
15543
15544 test_241_dio() {
15545         for LOOP in $(seq $1); do
15546                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
15547                                                 iflag=direct 2>/dev/null
15548         done
15549 }
15550
15551 test_241a() { # was test_241
15552         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
15553         ls -la $DIR/$tfile
15554         cancel_lru_locks $OSC
15555         test_241_bio 1000 &
15556         PID=$!
15557         test_241_dio 1000
15558         wait $PID
15559 }
15560 run_test 241a "bio vs dio"
15561
15562 test_241b() {
15563         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
15564         ls -la $DIR/$tfile
15565         test_241_dio 1000 &
15566         PID=$!
15567         test_241_dio 1000
15568         wait $PID
15569 }
15570 run_test 241b "dio vs dio"
15571
15572 test_242() {
15573         remote_mds_nodsh && skip "remote MDS with nodsh"
15574
15575         mkdir -p $DIR/$tdir
15576         touch $DIR/$tdir/$tfile
15577
15578         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
15579         do_facet mds1 lctl set_param fail_loc=0x105
15580         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
15581
15582         do_facet mds1 lctl set_param fail_loc=0
15583         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
15584 }
15585 run_test 242 "mdt_readpage failure should not cause directory unreadable"
15586
15587 test_243()
15588 {
15589         test_mkdir $DIR/$tdir
15590         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
15591 }
15592 run_test 243 "various group lock tests"
15593
15594 test_244()
15595 {
15596         test_mkdir $DIR/$tdir
15597         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
15598         sendfile_grouplock $DIR/$tdir/$tfile || \
15599                 error "sendfile+grouplock failed"
15600         rm -rf $DIR/$tdir
15601 }
15602 run_test 244 "sendfile with group lock tests"
15603
15604 test_245() {
15605         local flagname="multi_mod_rpcs"
15606         local connect_data_name="max_mod_rpcs"
15607         local out
15608
15609         # check if multiple modify RPCs flag is set
15610         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
15611                 grep "connect_flags:")
15612         echo "$out"
15613
15614         echo "$out" | grep -qw $flagname
15615         if [ $? -ne 0 ]; then
15616                 echo "connect flag $flagname is not set"
15617                 return
15618         fi
15619
15620         # check if multiple modify RPCs data is set
15621         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
15622         echo "$out"
15623
15624         echo "$out" | grep -qw $connect_data_name ||
15625                 error "import should have connect data $connect_data_name"
15626 }
15627 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
15628
15629 test_246() { # LU-7371
15630         remote_ost_nodsh && skip "remote OST with nodsh"
15631         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
15632                 skip "Need OST version >= 2.7.62"
15633
15634         do_facet ost1 $LCTL set_param fail_val=4095
15635 #define OBD_FAIL_OST_READ_SIZE          0x234
15636         do_facet ost1 $LCTL set_param fail_loc=0x234
15637         $LFS setstripe $DIR/$tfile -i 0 -c 1
15638         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
15639         cancel_lru_locks $FSNAME-OST0000
15640         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
15641 }
15642 run_test 246 "Read file of size 4095 should return right length"
15643
15644 cleanup_247() {
15645         local submount=$1
15646
15647         trap 0
15648         umount_client $submount
15649         rmdir $submount
15650 }
15651
15652 test_247a() {
15653         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
15654                 grep -q subtree ||
15655                 skip_env "Fileset feature is not supported"
15656
15657         local submount=${MOUNT}_$tdir
15658
15659         mkdir $MOUNT/$tdir
15660         mkdir -p $submount || error "mkdir $submount failed"
15661         FILESET="$FILESET/$tdir" mount_client $submount ||
15662                 error "mount $submount failed"
15663         trap "cleanup_247 $submount" EXIT
15664         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
15665         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
15666                 error "read $MOUNT/$tdir/$tfile failed"
15667         cleanup_247 $submount
15668 }
15669 run_test 247a "mount subdir as fileset"
15670
15671 test_247b() {
15672         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15673                 skip_env "Fileset feature is not supported"
15674
15675         local submount=${MOUNT}_$tdir
15676
15677         rm -rf $MOUNT/$tdir
15678         mkdir -p $submount || error "mkdir $submount failed"
15679         SKIP_FILESET=1
15680         FILESET="$FILESET/$tdir" mount_client $submount &&
15681                 error "mount $submount should fail"
15682         rmdir $submount
15683 }
15684 run_test 247b "mount subdir that dose not exist"
15685
15686 test_247c() {
15687         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15688                 skip_env "Fileset feature is not supported"
15689
15690         local submount=${MOUNT}_$tdir
15691
15692         mkdir -p $MOUNT/$tdir/dir1
15693         mkdir -p $submount || error "mkdir $submount failed"
15694         trap "cleanup_247 $submount" EXIT
15695         FILESET="$FILESET/$tdir" mount_client $submount ||
15696                 error "mount $submount failed"
15697         local fid=$($LFS path2fid $MOUNT/)
15698         $LFS fid2path $submount $fid && error "fid2path should fail"
15699         cleanup_247 $submount
15700 }
15701 run_test 247c "running fid2path outside root"
15702
15703 test_247d() {
15704         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15705                 skip "Fileset feature is not supported"
15706
15707         local submount=${MOUNT}_$tdir
15708
15709         mkdir -p $MOUNT/$tdir/dir1
15710         mkdir -p $submount || error "mkdir $submount failed"
15711         FILESET="$FILESET/$tdir" mount_client $submount ||
15712                 error "mount $submount failed"
15713         trap "cleanup_247 $submount" EXIT
15714         local fid=$($LFS path2fid $submount/dir1)
15715         $LFS fid2path $submount $fid || error "fid2path should succeed"
15716         cleanup_247 $submount
15717 }
15718 run_test 247d "running fid2path inside root"
15719
15720 # LU-8037
15721 test_247e() {
15722         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
15723                 grep -q subtree ||
15724                 skip "Fileset feature is not supported"
15725
15726         local submount=${MOUNT}_$tdir
15727
15728         mkdir $MOUNT/$tdir
15729         mkdir -p $submount || error "mkdir $submount failed"
15730         FILESET="$FILESET/.." mount_client $submount &&
15731                 error "mount $submount should fail"
15732         rmdir $submount
15733 }
15734 run_test 247e "mount .. as fileset"
15735
15736 test_248() {
15737         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
15738         [ -z "$fast_read_sav" ] && skip "no fast read support"
15739
15740         # create a large file for fast read verification
15741         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
15742
15743         # make sure the file is created correctly
15744         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
15745                 { rm -f $DIR/$tfile; skip "file creation error"; }
15746
15747         echo "Test 1: verify that fast read is 4 times faster on cache read"
15748
15749         # small read with fast read enabled
15750         $LCTL set_param -n llite.*.fast_read=1
15751         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
15752                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15753                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15754         # small read with fast read disabled
15755         $LCTL set_param -n llite.*.fast_read=0
15756         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
15757                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15758                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15759
15760         # verify that fast read is 4 times faster for cache read
15761         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
15762                 error_not_in_vm "fast read was not 4 times faster: " \
15763                            "$t_fast vs $t_slow"
15764
15765         echo "Test 2: verify the performance between big and small read"
15766         $LCTL set_param -n llite.*.fast_read=1
15767
15768         # 1k non-cache read
15769         cancel_lru_locks osc
15770         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
15771                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15772                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15773
15774         # 1M non-cache read
15775         cancel_lru_locks osc
15776         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
15777                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15778                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15779
15780         # verify that big IO is not 4 times faster than small IO
15781         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
15782                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
15783
15784         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
15785         rm -f $DIR/$tfile
15786 }
15787 run_test 248 "fast read verification"
15788
15789 test_249() { # LU-7890
15790         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
15791                 skip "Need at least version 2.8.54"
15792
15793         rm -f $DIR/$tfile
15794         $SETSTRIPE -c 1 $DIR/$tfile
15795         # Offset 2T == 4k * 512M
15796         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
15797                 error "dd to 2T offset failed"
15798 }
15799 run_test 249 "Write above 2T file size"
15800
15801 test_250() {
15802         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
15803          && skip "no 16TB file size limit on ZFS"
15804
15805         $SETSTRIPE -c 1 $DIR/$tfile
15806         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
15807         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
15808         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
15809         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
15810                 conv=notrunc,fsync && error "append succeeded"
15811         return 0
15812 }
15813 run_test 250 "Write above 16T limit"
15814
15815 test_251() {
15816         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
15817
15818         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
15819         #Skip once - writing the first stripe will succeed
15820         $LCTL set_param fail_loc=0xa0001407 fail_val=1
15821         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
15822                 error "short write happened"
15823
15824         $LCTL set_param fail_loc=0xa0001407 fail_val=1
15825         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
15826                 error "short read happened"
15827
15828         rm -f $DIR/$tfile
15829 }
15830 run_test 251 "Handling short read and write correctly"
15831
15832 test_252() {
15833         remote_mds_nodsh && skip "remote MDS with nodsh"
15834         remote_ost_nodsh && skip "remote OST with nodsh"
15835         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
15836              "$(facet_fstype mds1)" != "ldiskfs" ]; then
15837                 skip_env "ldiskfs only test"
15838         fi
15839
15840         local tgt
15841         local dev
15842         local out
15843         local uuid
15844         local num
15845         local gen
15846
15847         # check lr_reader on OST0000
15848         tgt=ost1
15849         dev=$(facet_device $tgt)
15850         out=$(do_facet $tgt $LR_READER $dev)
15851         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15852         echo "$out"
15853         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
15854         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
15855                 error "Invalid uuid returned by $LR_READER on target $tgt"
15856         echo -e "uuid returned by $LR_READER is '$uuid'\n"
15857
15858         # check lr_reader -c on MDT0000
15859         tgt=mds1
15860         dev=$(facet_device $tgt)
15861         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
15862                 skip "$LR_READER does not support additional options"
15863         fi
15864         out=$(do_facet $tgt $LR_READER -c $dev)
15865         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15866         echo "$out"
15867         num=$(echo "$out" | grep -c "mdtlov")
15868         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
15869                 error "Invalid number of mdtlov clients returned by $LR_READER"
15870         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
15871
15872         # check lr_reader -cr on MDT0000
15873         out=$(do_facet $tgt $LR_READER -cr $dev)
15874         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15875         echo "$out"
15876         echo "$out" | grep -q "^reply_data:$" ||
15877                 error "$LR_READER should have returned 'reply_data' section"
15878         num=$(echo "$out" | grep -c "client_generation")
15879         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
15880 }
15881 run_test 252 "check lr_reader tool"
15882
15883 test_253_fill_ost() {
15884         local size_mb #how many MB should we write to pass watermark
15885         local lwm=$3  #low watermark
15886         local free_10mb #10% of free space
15887
15888         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
15889         size_mb=$((free_kb / 1024 - lwm))
15890         free_10mb=$((free_kb / 10240))
15891         #If 10% of free space cross low watermark use it
15892         if (( free_10mb > size_mb )); then
15893                 size_mb=$free_10mb
15894         else
15895                 #At least we need to store 1.1 of difference between
15896                 #free space and low watermark
15897                 size_mb=$((size_mb + size_mb / 10))
15898         fi
15899         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
15900                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
15901                          oflag=append conv=notrunc
15902         fi
15903
15904         sleep_maxage
15905
15906         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
15907         echo "OST still has $((free_kb / 1024)) mbytes free"
15908 }
15909
15910 test_253() {
15911         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15912         remote_mds_nodsh && skip "remote MDS with nodsh"
15913         remote_mgs_nodsh && skip "remote MGS with nodsh"
15914
15915         local ostidx=0
15916         local rc=0
15917
15918         local ost_name=$($LFS osts |
15919                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
15920         # on the mdt's osc
15921         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
15922         do_facet $SINGLEMDS $LCTL get_param -n \
15923                 osp.$mdtosc_proc1.reserved_mb_high ||
15924                 skip  "remote MDS does not support reserved_mb_high"
15925
15926         rm -rf $DIR/$tdir
15927         wait_mds_ost_sync
15928         wait_delete_completed
15929         mkdir $DIR/$tdir
15930
15931         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
15932                         osp.$mdtosc_proc1.reserved_mb_high)
15933         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
15934                         osp.$mdtosc_proc1.reserved_mb_low)
15935         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
15936
15937         if ! combined_mgs_mds ; then
15938                 mount_mgs_client
15939         fi
15940         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
15941         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
15942                 error "Adding $ost_name to pool failed"
15943
15944         # Wait for client to see a OST at pool
15945         wait_update $HOSTNAME "$LCTL get_param -n
15946                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
15947                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
15948                 error "Client can not see the pool"
15949         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
15950                 error "Setstripe failed"
15951
15952         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
15953         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
15954         echo "OST still has $((blocks/1024)) mbytes free"
15955
15956         local new_lwm=$((blocks/1024-10))
15957         do_facet $SINGLEMDS $LCTL set_param \
15958                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
15959         do_facet $SINGLEMDS $LCTL set_param \
15960                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
15961
15962         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
15963
15964         #First enospc could execute orphan deletion so repeat.
15965         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
15966
15967         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
15968                         osp.$mdtosc_proc1.prealloc_status)
15969         echo "prealloc_status $oa_status"
15970
15971         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
15972                 error "File creation should fail"
15973         #object allocation was stopped, but we still able to append files
15974         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
15975                 error "Append failed"
15976         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
15977
15978         wait_delete_completed
15979
15980         sleep_maxage
15981
15982         for i in $(seq 10 12); do
15983                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
15984                         error "File creation failed after rm";
15985         done
15986
15987         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
15988                         osp.$mdtosc_proc1.prealloc_status)
15989         echo "prealloc_status $oa_status"
15990
15991         if (( oa_status != 0 )); then
15992                 error "Object allocation still disable after rm"
15993         fi
15994         do_facet $SINGLEMDS $LCTL set_param \
15995                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
15996         do_facet $SINGLEMDS $LCTL set_param \
15997                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
15998
15999
16000         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
16001                 error "Remove $ost_name from pool failed"
16002         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
16003                 error "Pool destroy fialed"
16004
16005         if ! combined_mgs_mds ; then
16006                 umount_mgs_client
16007         fi
16008 }
16009 run_test 253 "Check object allocation limit"
16010
16011 test_254() {
16012         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16013         remote_mds_nodsh && skip "remote MDS with nodsh"
16014         do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_size ||
16015                 skip "MDS does not support changelog_size"
16016
16017         local cl_user
16018         local MDT0=$(facet_svc $SINGLEMDS)
16019
16020         changelog_register || error "changelog_register failed"
16021
16022         changelog_clear 0 || error "changelog_clear failed"
16023
16024         local size1=$(do_facet $SINGLEMDS \
16025                       $LCTL get_param -n mdd.$MDT0.changelog_size)
16026         echo "Changelog size $size1"
16027
16028         rm -rf $DIR/$tdir
16029         $LFS mkdir -i 0 $DIR/$tdir
16030         # change something
16031         mkdir -p $DIR/$tdir/pics/2008/zachy
16032         touch $DIR/$tdir/pics/2008/zachy/timestamp
16033         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
16034         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
16035         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
16036         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
16037         rm $DIR/$tdir/pics/desktop.jpg
16038
16039         local size2=$(do_facet $SINGLEMDS \
16040                       $LCTL get_param -n mdd.$MDT0.changelog_size)
16041         echo "Changelog size after work $size2"
16042
16043         (( $size2 > $size1 )) ||
16044                 error "new Changelog size=$size2 less than old size=$size1"
16045 }
16046 run_test 254 "Check changelog size"
16047
16048 ladvise_no_type()
16049 {
16050         local type=$1
16051         local file=$2
16052
16053         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
16054                 awk -F: '{print $2}' | grep $type > /dev/null
16055         if [ $? -ne 0 ]; then
16056                 return 0
16057         fi
16058         return 1
16059 }
16060
16061 ladvise_no_ioctl()
16062 {
16063         local file=$1
16064
16065         lfs ladvise -a willread $file > /dev/null 2>&1
16066         if [ $? -eq 0 ]; then
16067                 return 1
16068         fi
16069
16070         lfs ladvise -a willread $file 2>&1 |
16071                 grep "Inappropriate ioctl for device" > /dev/null
16072         if [ $? -eq 0 ]; then
16073                 return 0
16074         fi
16075         return 1
16076 }
16077
16078 percent() {
16079         bc <<<"scale=2; ($1 - $2) * 100 / $2"
16080 }
16081
16082 # run a random read IO workload
16083 # usage: random_read_iops <filename> <filesize> <iosize>
16084 random_read_iops() {
16085         local file=$1
16086         local fsize=$2
16087         local iosize=${3:-4096}
16088
16089         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
16090                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
16091 }
16092
16093 drop_file_oss_cache() {
16094         local file="$1"
16095         local nodes="$2"
16096
16097         $LFS ladvise -a dontneed $file 2>/dev/null ||
16098                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
16099 }
16100
16101 ladvise_willread_performance()
16102 {
16103         local repeat=10
16104         local average_origin=0
16105         local average_cache=0
16106         local average_ladvise=0
16107
16108         for ((i = 1; i <= $repeat; i++)); do
16109                 echo "Iter $i/$repeat: reading without willread hint"
16110                 cancel_lru_locks osc
16111                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
16112                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
16113                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
16114                 average_origin=$(bc <<<"$average_origin + $speed_origin")
16115
16116                 cancel_lru_locks osc
16117                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
16118                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
16119                 average_cache=$(bc <<<"$average_cache + $speed_cache")
16120
16121                 cancel_lru_locks osc
16122                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
16123                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
16124                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
16125                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
16126                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
16127         done
16128         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
16129         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
16130         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
16131
16132         speedup_cache=$(percent $average_cache $average_origin)
16133         speedup_ladvise=$(percent $average_ladvise $average_origin)
16134
16135         echo "Average uncached read: $average_origin"
16136         echo "Average speedup with OSS cached read: " \
16137                 "$average_cache = +$speedup_cache%"
16138         echo "Average speedup with ladvise willread: " \
16139                 "$average_ladvise = +$speedup_ladvise%"
16140
16141         local lowest_speedup=20
16142         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
16143                 echo "Speedup with OSS cached read less than $lowest_speedup%," \
16144                         "got $average_cache%. Skipping ladvise willread check."
16145                 return 0
16146         fi
16147
16148         # the test won't work on ZFS until it supports 'ladvise dontneed', but
16149         # it is still good to run until then to exercise 'ladvise willread'
16150         ! $LFS ladvise -a dontneed $DIR/$tfile &&
16151                 [ "$(facet_fstype ost1)" = "zfs" ] &&
16152                 echo "osd-zfs does not support dontneed or drop_caches" &&
16153                 return 0
16154
16155         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
16156         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
16157                 error_not_in_vm "Speedup with willread is less than " \
16158                         "$lowest_speedup%, got $average_ladvise%"
16159 }
16160
16161 test_255a() {
16162         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
16163                 skip "lustre < 2.8.54 does not support ladvise "
16164         remote_ost_nodsh && skip "remote OST with nodsh"
16165
16166         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
16167
16168         ladvise_no_type willread $DIR/$tfile &&
16169                 skip "willread ladvise is not supported"
16170
16171         ladvise_no_ioctl $DIR/$tfile &&
16172                 skip "ladvise ioctl is not supported"
16173
16174         local size_mb=100
16175         local size=$((size_mb * 1048576))
16176         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
16177                 error "dd to $DIR/$tfile failed"
16178
16179         lfs ladvise -a willread $DIR/$tfile ||
16180                 error "Ladvise failed with no range argument"
16181
16182         lfs ladvise -a willread -s 0 $DIR/$tfile ||
16183                 error "Ladvise failed with no -l or -e argument"
16184
16185         lfs ladvise -a willread -e 1 $DIR/$tfile ||
16186                 error "Ladvise failed with only -e argument"
16187
16188         lfs ladvise -a willread -l 1 $DIR/$tfile ||
16189                 error "Ladvise failed with only -l argument"
16190
16191         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
16192                 error "End offset should not be smaller than start offset"
16193
16194         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
16195                 error "End offset should not be equal to start offset"
16196
16197         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
16198                 error "Ladvise failed with overflowing -s argument"
16199
16200         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
16201                 error "Ladvise failed with overflowing -e argument"
16202
16203         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
16204                 error "Ladvise failed with overflowing -l argument"
16205
16206         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
16207                 error "Ladvise succeeded with conflicting -l and -e arguments"
16208
16209         echo "Synchronous ladvise should wait"
16210         local delay=4
16211 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
16212         do_nodes $(comma_list $(osts_nodes)) \
16213                 $LCTL set_param fail_val=$delay fail_loc=0x237
16214
16215         local start_ts=$SECONDS
16216         lfs ladvise -a willread $DIR/$tfile ||
16217                 error "Ladvise failed with no range argument"
16218         local end_ts=$SECONDS
16219         local inteval_ts=$((end_ts - start_ts))
16220
16221         if [ $inteval_ts -lt $(($delay - 1)) ]; then
16222                 error "Synchronous advice didn't wait reply"
16223         fi
16224
16225         echo "Asynchronous ladvise shouldn't wait"
16226         local start_ts=$SECONDS
16227         lfs ladvise -a willread -b $DIR/$tfile ||
16228                 error "Ladvise failed with no range argument"
16229         local end_ts=$SECONDS
16230         local inteval_ts=$((end_ts - start_ts))
16231
16232         if [ $inteval_ts -gt $(($delay / 2)) ]; then
16233                 error "Asynchronous advice blocked"
16234         fi
16235
16236         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
16237         ladvise_willread_performance
16238 }
16239 run_test 255a "check 'lfs ladvise -a willread'"
16240
16241 facet_meminfo() {
16242         local facet=$1
16243         local info=$2
16244
16245         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
16246 }
16247
16248 test_255b() {
16249         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
16250                 skip "lustre < 2.8.54 does not support ladvise "
16251         remote_ost_nodsh && skip "remote OST with nodsh"
16252
16253         lfs setstripe -c 1 -i 0 $DIR/$tfile
16254
16255         ladvise_no_type dontneed $DIR/$tfile &&
16256                 skip "dontneed ladvise is not supported"
16257
16258         ladvise_no_ioctl $DIR/$tfile &&
16259                 skip "ladvise ioctl is not supported"
16260
16261         ! $LFS ladvise -a dontneed $DIR/$tfile &&
16262                 [ "$(facet_fstype ost1)" = "zfs" ] &&
16263                 skip "zfs-osd does not support 'ladvise dontneed'"
16264
16265         local size_mb=100
16266         local size=$((size_mb * 1048576))
16267         # In order to prevent disturbance of other processes, only check 3/4
16268         # of the memory usage
16269         local kibibytes=$((size_mb * 1024 * 3 / 4))
16270
16271         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
16272                 error "dd to $DIR/$tfile failed"
16273
16274         #force write to complete before dropping OST cache & checking memory
16275         sync
16276
16277         local total=$(facet_meminfo ost1 MemTotal)
16278         echo "Total memory: $total KiB"
16279
16280         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
16281         local before_read=$(facet_meminfo ost1 Cached)
16282         echo "Cache used before read: $before_read KiB"
16283
16284         lfs ladvise -a willread $DIR/$tfile ||
16285                 error "Ladvise willread failed"
16286         local after_read=$(facet_meminfo ost1 Cached)
16287         echo "Cache used after read: $after_read KiB"
16288
16289         lfs ladvise -a dontneed $DIR/$tfile ||
16290                 error "Ladvise dontneed again failed"
16291         local no_read=$(facet_meminfo ost1 Cached)
16292         echo "Cache used after dontneed ladvise: $no_read KiB"
16293
16294         if [ $total -lt $((before_read + kibibytes)) ]; then
16295                 echo "Memory is too small, abort checking"
16296                 return 0
16297         fi
16298
16299         if [ $((before_read + kibibytes)) -gt $after_read ]; then
16300                 error "Ladvise willread should use more memory" \
16301                         "than $kibibytes KiB"
16302         fi
16303
16304         if [ $((no_read + kibibytes)) -gt $after_read ]; then
16305                 error "Ladvise dontneed should release more memory" \
16306                         "than $kibibytes KiB"
16307         fi
16308 }
16309 run_test 255b "check 'lfs ladvise -a dontneed'"
16310
16311 test_255c() {
16312         [ $(lustre_version_code ost1) -lt $(version_code 2.10.50) ] &&
16313                 skip "lustre < 2.10.53 does not support lockahead"
16314
16315         local count
16316         local new_count
16317         local difference
16318         local i
16319         local rc
16320
16321         test_mkdir -p $DIR/$tdir
16322         $SETSTRIPE -i 0 $DIR/$tdir
16323
16324         #test 10 returns only success/failure
16325         i=10
16326         lockahead_test -d $DIR/$tdir -t $i -f $tfile
16327         rc=$?
16328         if [ $rc -eq 255 ]; then
16329                 error "Ladvise test${i} failed, ${rc}"
16330         fi
16331
16332         #test 11 counts lock enqueue requests, all others count new locks
16333         i=11
16334         count=$(do_facet ost1 \
16335                 $LCTL get_param -n ost.OSS.ost.stats)
16336         count=$(echo "$count" | grep ldlm_extent_enqueue | awk '{ print $2 }')
16337
16338         lockahead_test -d $DIR/$tdir -t $i -f $tfile
16339         rc=$?
16340         if [ $rc -eq 255 ]; then
16341                 error "Ladvise test${i} failed, ${rc}"
16342         fi
16343
16344         new_count=$(do_facet ost1 \
16345                 $LCTL get_param -n ost.OSS.ost.stats)
16346         new_count=$(echo "$new_count" | grep ldlm_extent_enqueue | \
16347                    awk '{ print $2 }')
16348
16349         difference="$((new_count - count))"
16350         if [ $difference -ne $rc ]; then
16351                 error "Ladvise test${i}, bad enqueue count, returned " \
16352                       "${rc}, actual ${difference}"
16353         fi
16354
16355         for i in $(seq 12 21); do
16356                 # If we do not do this, we run the risk of having too many
16357                 # locks and starting lock cancellation while we are checking
16358                 # lock counts.
16359                 cancel_lru_locks osc
16360
16361                 count=$($LCTL get_param -n \
16362                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
16363
16364                 lockahead_test -d $DIR/$tdir -t $i -f $tfile
16365                 rc=$?
16366                 if [ $rc -eq 255 ]; then
16367                         error "Ladvise test ${i} failed, ${rc}"
16368                 fi
16369
16370                 new_count=$($LCTL get_param -n \
16371                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
16372                 difference="$((new_count - count))"
16373
16374                 # Test 15 output is divided by 100 to map down to valid return
16375                 if [ $i -eq 15 ]; then
16376                         rc="$((rc * 100))"
16377                 fi
16378
16379                 if [ $difference -ne $rc ]; then
16380                         error "Ladvise test ${i}, bad lock count, returned " \
16381                               "${rc}, actual ${difference}"
16382                 fi
16383         done
16384
16385         #test 22 returns only success/failure
16386         i=22
16387         lockahead_test -d $DIR/$tdir -t $i -f $tfile
16388         rc=$?
16389         if [ $rc -eq 255 ]; then
16390                 error "Ladvise test${i} failed, ${rc}"
16391         fi
16392 }
16393 run_test 255c "suite of ladvise lockahead tests"
16394
16395 test_256() {
16396         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16397         remote_mds_nodsh && skip "remote MDS with nodsh"
16398         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
16399                 skip "ldiskfs only test"
16400         changelog_users $SINGLEMDS | grep "^cl" &&
16401                 skip "active changelog user"
16402
16403         local cl_user
16404         local cat_sl
16405         local mdt_dev
16406
16407         mdt_dev=$(mdsdevname 1)
16408         echo $mdt_dev
16409
16410         changelog_register || error "changelog_register failed"
16411
16412         rm -rf $DIR/$tdir
16413         mkdir -p $DIR/$tdir
16414
16415         changelog_clear 0 || error "changelog_clear failed"
16416
16417         # change something
16418         touch $DIR/$tdir/{1..10}
16419
16420         # stop the MDT
16421         stop $SINGLEMDS || error "Fail to stop MDT"
16422
16423         # remount the MDT
16424
16425         start $SINGLEMDS $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT"
16426
16427         #after mount new plainllog is used
16428         touch $DIR/$tdir/{11..19}
16429         local tmpfile=$(mktemp -u $tfile.XXXXXX)
16430         cat_sl=$(do_facet $SINGLEMDS "sync; \
16431                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
16432                  llog_reader $tmpfile | grep -c type=1064553b")
16433         do_facet $SINGLEMDS llog_reader $tmpfile
16434
16435         [ $cat_sl != 2 ] && error "Changelog catalog has $cat_sl != 2 slots"
16436
16437         changelog_clear 0 || error "changelog_clear failed"
16438
16439         cat_sl=$(do_facet $SINGLEMDS "sync; \
16440                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
16441                  llog_reader $tmpfile | grep -c type=1064553b; rm -f $tmpfile")
16442
16443         if (( cat_sl == 2 )); then
16444                 error "Empty plain llog was not deleted from changelog catalog"
16445         elif (( cat_sl != 1 )); then
16446                 error "Active plain llog shouldn't be deleted from catalog"
16447         fi
16448 }
16449 run_test 256 "Check llog delete for empty and not full state"
16450
16451 test_257() {
16452         remote_mds_nodsh && skip "remote MDS with nodsh"
16453         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
16454                 skip "Need MDS version at least 2.8.55"
16455
16456         test_mkdir $DIR/$tdir
16457
16458         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
16459                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
16460         stat $DIR/$tdir
16461
16462 #define OBD_FAIL_MDS_XATTR_REP                  0x161
16463         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
16464         local facet=mds$((mdtidx + 1))
16465         set_nodes_failloc $(facet_active_host $facet) 0x80000161
16466         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
16467
16468         stop $facet || error "stop MDS failed"
16469         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
16470                 error "start MDS fail"
16471 }
16472 run_test 257 "xattr locks are not lost"
16473
16474 # Verify we take the i_mutex when security requires it
16475 test_258a() {
16476 #define OBD_FAIL_IMUTEX_SEC 0x141c
16477         $LCTL set_param fail_loc=0x141c
16478         touch $DIR/$tfile
16479         chmod u+s $DIR/$tfile
16480         chmod a+rwx $DIR/$tfile
16481         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
16482         RC=$?
16483         if [ $RC -ne 0 ]; then
16484                 error "error, failed to take i_mutex, rc=$?"
16485         fi
16486         rm -f $DIR/$tfile
16487 }
16488 run_test 258a
16489
16490 # Verify we do NOT take the i_mutex in the normal case
16491 test_258b() {
16492 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
16493         $LCTL set_param fail_loc=0x141d
16494         touch $DIR/$tfile
16495         chmod a+rwx $DIR
16496         chmod a+rw $DIR/$tfile
16497         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
16498         RC=$?
16499         if [ $RC -ne 0 ]; then
16500                 error "error, took i_mutex unnecessarily, rc=$?"
16501         fi
16502         rm -f $DIR/$tfile
16503
16504 }
16505 run_test 258b "verify i_mutex security behavior"
16506
16507 test_259() {
16508         local file=$DIR/$tfile
16509         local before
16510         local after
16511
16512         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
16513                 skip "ldiskfs only test" && return
16514
16515         stack_trap "rm -f $file" EXIT
16516
16517         wait_delete_completed
16518         before=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
16519         echo "before: $before"
16520
16521         $LFS setstripe -i 0 -c 1 $file
16522         dd if=/dev/zero of=$file bs=1M count=10 || error "couldn't write"
16523         sync_all_data
16524         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
16525         echo "after write: $after"
16526
16527 #define OBD_FAIL_OSD_FAIL_AT_TRUNCATE          0x2301
16528         do_facet ost1 $LCTL set_param fail_loc=0x2301
16529         $TRUNCATE $file 0
16530         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
16531         echo "after truncate: $after"
16532
16533         stop ost1
16534         do_facet ost1 $LCTL set_param fail_loc=0
16535         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
16536         sleep 2
16537         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
16538         echo "after restart: $after"
16539         [ $((after - before)) -ge $(fs_log_size ost1) ] &&
16540                 error "missing truncate?"
16541
16542         return 0
16543 }
16544 run_test 259 "crash at delayed truncate"
16545
16546 test_260() {
16547 #define OBD_FAIL_MDC_CLOSE               0x806
16548         $LCTL set_param fail_loc=0x80000806
16549         touch $DIR/$tfile
16550
16551 }
16552 run_test 260 "Check mdc_close fail"
16553
16554 ### Data-on-MDT sanity tests ###
16555 test_270a() {
16556         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16557                 skip "Need MDS version at least 2.10.55"
16558
16559         # create DoM file
16560         local dom=$DIR/$tdir/dom_file
16561         local tmp=$DIR/$tdir/tmp_file
16562
16563         mkdir -p $DIR/$tdir
16564
16565         # basic checks for DoM component creation
16566         $LFS setstripe -E 1024K -E 1024K -L mdt $dom 2>/dev/null &&
16567                 error "Can set MDT layout to non-first entry"
16568
16569         $LFS setstripe -E 1024K -L mdt -E 1024K -L mdt $dom 2>/dev/null &&
16570                 error "Can define multiple entries as MDT layout"
16571
16572         $LFS setstripe -E 1M -L mdt $dom ||
16573                 error "Can't create DoM layout"
16574
16575         [ $($LFS getstripe -L $dom) == "mdt" ] || error "bad pattern"
16576         [ $($LFS getstripe -c $dom) == 0 ] || error "bad stripe count"
16577         [ $($LFS getstripe -S $dom) == 1048576 ] || error "bad stripe size"
16578
16579         local mdtidx=$($LFS getstripe -m $dom)
16580         local mdtname=MDT$(printf %04x $mdtidx)
16581         local facet=mds$((mdtidx + 1))
16582         local space_check=1
16583
16584         # Skip free space checks with ZFS
16585         if [ "$(facet_fstype $facet)" == "zfs" ]; then
16586                 space_check=0
16587         fi
16588
16589         # write
16590         sync
16591         local mdtfree1=$(do_facet $facet \
16592                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16593         dd if=/dev/urandom of=$tmp bs=1024 count=100
16594         # check also direct IO along write
16595         dd if=$tmp of=$dom bs=102400 count=1 oflag=direct
16596         sync
16597         cmp $tmp $dom || error "file data is different"
16598         [ $(stat -c%s $dom) == 102400 ] || error "bad size after write"
16599         if [ $space_check == 1 ]; then
16600                 local mdtfree2=$(do_facet $facet \
16601                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16602                 [ $(($mdtfree1 - $mdtfree2)) -ge 102 ] ||
16603                         error "MDT free space is wrong after write"
16604         fi
16605
16606         # truncate
16607         $TRUNCATE $dom 10000
16608         [ $(stat -c%s $dom) == 10000 ] || error "bad size after truncate"
16609         if [ $space_check == 1 ]; then
16610                 mdtfree1=$(do_facet $facet \
16611                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16612                 [ $(($mdtfree1 - $mdtfree2)) -ge 92 ] ||
16613                         error "MDT free space is wrong after truncate"
16614         fi
16615
16616         # append
16617         cat $tmp >> $dom
16618         sync
16619         [ $(stat -c%s $dom) == 112400 ] || error "bad size after append"
16620         if [ $space_check == 1 ]; then
16621                 mdtfree2=$(do_facet $facet \
16622                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16623                 [ $(($mdtfree1 - $mdtfree2)) -ge 102 ] ||
16624                         error "MDT free space is wrong after append"
16625         fi
16626
16627         # delete
16628         rm $dom
16629         if [ $space_check == 1 ]; then
16630                 mdtfree1=$(do_facet $facet \
16631                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16632                 [ $(($mdtfree1 - $mdtfree2)) -ge 112 ] ||
16633                         error "MDT free space is wrong after removal"
16634         fi
16635
16636         # combined striping
16637         $LFS setstripe -E 1024K -L mdt -E EOF $dom ||
16638                 error "Can't create DoM + OST striping"
16639
16640         dd if=/dev/urandom of=$tmp bs=1024 count=2000
16641         # check also direct IO along write
16642         dd if=$tmp of=$dom bs=102400 count=20 oflag=direct
16643         sync
16644         cmp $tmp $dom || error "file data is different"
16645         [ $(stat -c%s $dom) == 2048000 ] || error "bad size after write"
16646         rm $dom
16647         rm $tmp
16648
16649         return 0
16650 }
16651 run_test 270a "DoM: basic functionality tests"
16652
16653 test_270b() {
16654         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16655                 skip "Need MDS version at least 2.10.55"
16656
16657         local dom=$DIR/$tdir/dom_file
16658         local max_size=1048576
16659
16660         mkdir -p $DIR/$tdir
16661         $LFS setstripe -E $max_size -L mdt $dom
16662
16663         # truncate over the limit
16664         $TRUNCATE $dom $(($max_size + 1)) &&
16665                 error "successful truncate over the maximum size"
16666         # write over the limit
16667         dd if=/dev/zero of=$dom bs=$max_size seek=1 count=1 &&
16668                 error "successful write over the maximum size"
16669         # append over the limit
16670         dd if=/dev/zero of=$dom bs=$(($max_size - 3)) count=1
16671         echo "12345" >> $dom && error "successful append over the maximum size"
16672         rm $dom
16673
16674         return 0
16675 }
16676 run_test 270b "DoM: maximum size overflow checks for DoM-only file"
16677
16678 test_270c() {
16679         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16680                 skip "Need MDS version at least 2.10.55"
16681
16682         mkdir -p $DIR/$tdir
16683         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16684
16685         # check files inherit DoM EA
16686         touch $DIR/$tdir/first
16687         [ $($GETSTRIPE -L $DIR/$tdir/first) == "mdt" ] ||
16688                 error "bad pattern"
16689         [ $($LFS getstripe -c $DIR/$tdir/first) == 0 ] ||
16690                 error "bad stripe count"
16691         [ $($LFS getstripe -S $DIR/$tdir/first) == 1048576 ] ||
16692                 error "bad stripe size"
16693
16694         # check directory inherits DoM EA and uses it as default
16695         mkdir $DIR/$tdir/subdir
16696         touch $DIR/$tdir/subdir/second
16697         [ $($LFS getstripe -L $DIR/$tdir/subdir/second) == "mdt" ] ||
16698                 error "bad pattern in sub-directory"
16699         [ $($LFS getstripe -c $DIR/$tdir/subdir/second) == 0 ] ||
16700                 error "bad stripe count in sub-directory"
16701         [ $($LFS getstripe -S $DIR/$tdir/subdir/second) == 1048576 ] ||
16702                 error "bad stripe size in sub-directory"
16703         return 0
16704 }
16705 run_test 270c "DoM: DoM EA inheritance tests"
16706
16707 test_270d() {
16708         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16709                 skip "Need MDS version at least 2.10.55"
16710
16711         mkdir -p $DIR/$tdir
16712         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16713
16714         # inherit default DoM striping
16715         mkdir $DIR/$tdir/subdir
16716         touch $DIR/$tdir/subdir/f1
16717
16718         # change default directory striping
16719         $LFS setstripe -c 1 $DIR/$tdir/subdir
16720         touch $DIR/$tdir/subdir/f2
16721         [ $($LFS getstripe -c $DIR/$tdir/subdir/f2) == 1 ] ||
16722                 error "wrong default striping in file 2"
16723         [ $($LFS getstripe -L $DIR/$tdir/subdir/f2) == "raid0" ] ||
16724                 error "bad pattern in file 2"
16725         return 0
16726 }
16727 run_test 270d "DoM: change striping from DoM to RAID0"
16728
16729 test_270e() {
16730         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16731                 skip "Need MDS version at least 2.10.55"
16732
16733         mkdir -p $DIR/$tdir/dom
16734         mkdir -p $DIR/$tdir/norm
16735         DOMFILES=20
16736         NORMFILES=10
16737         $LFS setstripe -E 1M -L mdt $DIR/$tdir/dom
16738         $LFS setstripe -i 0 -S 2M $DIR/$tdir/norm
16739
16740         createmany -o $DIR/$tdir/dom/dom- $DOMFILES
16741         createmany -o $DIR/$tdir/norm/norm- $NORMFILES
16742
16743         # find DoM files by layout
16744         NUM=$($LFS find -L mdt -type f $DIR/$tdir 2>/dev/null | wc -l)
16745         [ $NUM -eq  $DOMFILES ] ||
16746                 error "lfs find -L: found $NUM, expected $DOMFILES"
16747         echo "Test 1: lfs find 20 DOM files by layout: OK"
16748
16749         # there should be 1 dir with default DOM striping
16750         NUM=$($LFS find -L mdt -type d $DIR/$tdir 2>/dev/null | wc -l)
16751         [ $NUM -eq  1 ] ||
16752                 error "lfs find -L: found $NUM, expected 1 dir"
16753         echo "Test 2: lfs find 1 DOM dir by layout: OK"
16754
16755         # find DoM files by stripe size
16756         NUM=$($LFS find -S -1200K -type f $DIR/$tdir 2>/dev/null | wc -l)
16757         [ $NUM -eq  $DOMFILES ] ||
16758                 error "lfs find -S: found $NUM, expected $DOMFILES"
16759         echo "Test 4: lfs find 20 DOM files by stripe size: OK"
16760
16761         # find files by stripe offset except DoM files
16762         NUM=$($LFS find -i 0 -type f $DIR/$tdir 2>/dev/null | wc -l)
16763         [ $NUM -eq  $NORMFILES ] ||
16764                 error "lfs find -i: found $NUM, expected $NORMFILES"
16765         echo "Test 5: lfs find no DOM files by stripe index: OK"
16766         return 0
16767 }
16768 run_test 270e "DoM: lfs find with DoM files test"
16769
16770 test_270f() {
16771         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16772                 skip "Need MDS version at least 2.10.55"
16773
16774         local mdtname=${FSNAME}-MDT0000-mdtlov
16775         local dom=$DIR/$tdir/dom_file
16776         local dom_limit_saved=$(do_facet mds1 $LCTL get_param -n \
16777                                                 lod.$mdtname.dom_stripesize)
16778         local dom_limit=131072
16779
16780         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=$dom_limit
16781         local dom_current=$(do_facet mds1 $LCTL get_param -n \
16782                                                 lod.$mdtname.dom_stripesize)
16783         [ ${dom_limit} -eq ${dom_current} ] ||
16784                 error "Cannot change per-MDT DoM stripe limit to $dom_limit"
16785
16786         $LFS mkdir -i 0 -c 1 $DIR/$tdir
16787         $LFS setstripe -d $DIR/$tdir
16788         $LFS setstripe -E $dom_limit -L mdt $DIR/$tdir ||
16789                 error "Can't set directory default striping"
16790
16791         # exceed maximum stripe size
16792         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
16793                 error "Can't create file with $((dom_limit * 2)) DoM stripe"
16794         [ $($LFS getstripe -S $dom) -eq $((dom_limit * 2)) ] &&
16795                 error "Able to create DoM component size more than LOD limit"
16796
16797         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=0
16798         dom_current=$(do_facet mds1 $LCTL get_param -n \
16799                                                 lod.$mdtname.dom_stripesize)
16800         [ 0 -eq ${dom_current} ] ||
16801                 error "Can't set zero DoM stripe limit"
16802         rm $dom
16803
16804         # attempt to create DoM file on server with disabled DoM should
16805         # remove DoM entry from layout and be succeed
16806         $LFS setstripe -E $dom_limit -L mdt -E -1 $dom ||
16807                 error "Can't create DoM file (DoM is disabled)"
16808         [ $($LFS getstripe -L $dom) == "mdt" ] &&
16809                 error "File has DoM component while DoM is disabled"
16810         rm $dom
16811
16812         # attempt to create DoM file with only DoM stripe should return error
16813         $LFS setstripe -E $dom_limit -L mdt $dom &&
16814                 error "Able to create DoM-only file while DoM is disabled"
16815
16816         # too low values to be aligned with smallest stripe size 64K
16817         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=30000
16818         dom_current=$(do_facet mds1 $LCTL get_param -n \
16819                                                 lod.$mdtname.dom_stripesize)
16820         [ 30000 -eq ${dom_current} ] &&
16821                 error "Can set too small DoM stripe limit"
16822
16823         # 64K is a minimal stripe size in Lustre, expect limit of that size
16824         [ 65536 -eq ${dom_current} ] ||
16825                 error "Limit is not set to 64K but ${dom_current}"
16826
16827         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=2147483648
16828         dom_current=$(do_facet mds1 $LCTL get_param -n \
16829                                                 lod.$mdtname.dom_stripesize)
16830         echo $dom_current
16831         [ 2147483648 -eq ${dom_current} ] &&
16832                 error "Can set too large DoM stripe limit"
16833
16834         do_facet mds1 $LCTL set_param -n \
16835                                 lod.$mdtname.dom_stripesize=$((dom_limit * 2))
16836         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
16837                 error "Can't create DoM component size after limit change"
16838         do_facet mds1 $LCTL set_param -n \
16839                                 lod.$mdtname.dom_stripesize=$((dom_limit / 2))
16840         $LFS setstripe -E $dom_limit -L mdt ${dom}_big ||
16841                 error "Can't create DoM file after limit decrease"
16842         [ $($LFS getstripe -S ${dom}_big) -eq $((dom_limit / 2)) ] ||
16843                 error "Can create big DoM component after limit decrease"
16844         touch ${dom}_def ||
16845                 error "Can't create file with old default layout"
16846
16847         do_facet mds1 $LCTL set_param -n lod.*.dom_stripesize=$dom_limit_saved
16848         return 0
16849 }
16850 run_test 270f "DoM: maximum DoM stripe size checks"
16851
16852 test_271a() {
16853         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16854                 skip "Need MDS version at least 2.10.55"
16855
16856         local dom=$DIR/$tdir/dom
16857
16858         mkdir -p $DIR/$tdir
16859
16860         $LFS setstripe -E 1024K -L mdt $dom
16861
16862         lctl set_param -n mdc.*.stats=clear
16863         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
16864         cat $dom > /dev/null
16865         local reads=$(lctl get_param -n mdc.*.stats |
16866                         awk '/ost_read/ {print $2}')
16867         [ -z $reads ] || error "Unexpected $reads READ RPCs"
16868         ls $dom
16869         rm -f $dom
16870 }
16871 run_test 271a "DoM: data is cached for read after write"
16872
16873 test_271b() {
16874         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16875                 skip "Need MDS version at least 2.10.55"
16876
16877         local dom=$DIR/$tdir/dom
16878
16879         mkdir -p $DIR/$tdir
16880
16881         $LFS setstripe -E 1024K -L mdt -E EOF $dom
16882
16883         lctl set_param -n mdc.*.stats=clear
16884         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
16885         cancel_lru_locks mdc
16886         $CHECKSTAT -t file -s 4096 $dom || error "stat #1 fails"
16887         # second stat to check size is cached on client
16888         $CHECKSTAT -t file -s 4096 $dom || error "stat #2 fails"
16889         local gls=$(lctl get_param -n mdc.*.stats |
16890                         awk '/ldlm_glimpse/ {print $2}')
16891         [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
16892         rm -f $dom
16893 }
16894 run_test 271b "DoM: no glimpse RPC for stat (DoM only file)"
16895
16896 test_271ba() {
16897         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16898                 skip "Need MDS version at least 2.10.55"
16899
16900         local dom=$DIR/$tdir/dom
16901
16902         mkdir -p $DIR/$tdir
16903
16904         $LFS setstripe -E 1024K -L mdt -E EOF $dom
16905
16906         lctl set_param -n mdc.*.stats=clear
16907         lctl set_param -n osc.*.stats=clear
16908         dd if=/dev/zero of=$dom bs=2048K count=1 || return 1
16909         cancel_lru_locks mdc
16910         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
16911         # second stat to check size is cached on client
16912         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
16913         local gls=$(lctl get_param -n mdc.*.stats |
16914                         awk '/ldlm_glimpse/ {print $2}')
16915         [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
16916         local gls=$(lctl get_param -n osc.*.stats |
16917                         awk '/ldlm_glimpse/ {print $2}')
16918         [ -z $gls ] || error "Unexpected $gls OSC glimpse RPCs"
16919         rm -f $dom
16920 }
16921 run_test 271ba "DoM: no glimpse RPC for stat (combined file)"
16922
16923 test_271c() {
16924         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16925                 skip "Need MDS version at least 2.10.55"
16926
16927         local dom=$DIR/$tdir/dom
16928
16929         mkdir -p $DIR/$tdir
16930
16931         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16932
16933         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
16934         local facet=mds$((mdtidx + 1))
16935
16936         cancel_lru_locks mdc
16937         do_facet $facet lctl set_param -n mdt.*.dom_lock=0
16938         createmany -o $dom 1000
16939         lctl set_param -n mdc.*.stats=clear
16940         smalliomany -w $dom 1000 200
16941         lctl get_param -n mdc.*.stats
16942         local enq=$(lctl get_param -n mdc.*.stats |
16943                         awk '/ldlm_ibits_enqueue/ {print $2}')
16944         # Each file has 1 open, 1 IO enqueues, total 2000
16945         # but now we have also +1 getxattr for security.capability, total 3000
16946         [ $enq -ge 2000 ] || error "Too few enqueues $enq, expected > 2000"
16947         unlinkmany $dom 1000
16948
16949         cancel_lru_locks mdc
16950         do_facet $facet lctl set_param -n mdt.*.dom_lock=1
16951         createmany -o $dom 1000
16952         lctl set_param -n mdc.*.stats=clear
16953         smalliomany -w $dom 1000 200
16954         lctl get_param -n mdc.*.stats
16955         local enq_2=$(lctl get_param -n mdc.*.stats |
16956                         awk '/ldlm_ibits_enqueue/ {print $2}')
16957         # Expect to see reduced amount of RPCs by 1000 due to single enqueue
16958         # for OPEN and IO lock.
16959         [ $((enq - enq_2)) -ge 1000 ] ||
16960                 error "Too many enqueues $enq_2, expected about $((enq - 1000))"
16961         unlinkmany $dom 1000
16962         return 0
16963 }
16964 run_test 271c "DoM: IO lock at open saves enqueue RPCs"
16965
16966 test_275() {
16967         remote_ost_nodsh && skip "remote OST with nodsh"
16968         [ $(lustre_version_code ost1) -lt $(version_code 2.10.57) ] &&
16969                 skip "Need OST version >= 2.10.57"
16970
16971         local file=$DIR/$tfile
16972         local oss
16973
16974         oss=$(comma_list $(osts_nodes))
16975
16976         dd if=/dev/urandom of=$file bs=1M count=2 ||
16977                 error "failed to create a file"
16978         cancel_lru_locks osc
16979
16980         #lock 1
16981         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
16982                 error "failed to read a file"
16983
16984 #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
16985         $LCTL set_param fail_loc=0x8000031f
16986
16987         cancel_lru_locks osc &
16988         sleep 1
16989
16990 #define OBD_FAIL_LDLM_PROLONG_PAUSE      0x32b
16991         do_nodes $oss $LCTL set_param fail_loc=0x8000032b
16992         #IO takes another lock, but matches the PENDING one
16993         #and places it to the IO RPC
16994         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
16995                 error "failed to read a file with PENDING lock"
16996 }
16997 run_test 275 "Read on a canceled duplicate lock"
16998
16999 test_276() {
17000         remote_ost_nodsh && skip "remote OST with nodsh"
17001         local pid
17002
17003         do_facet ost1 "(while true; do \
17004                 $LCTL get_param obdfilter.*.filesfree > /dev/null 2>&1; \
17005                 done) & pid=\\\$!; echo \\\$pid > $TMP/sanity_276_pid" &
17006         pid=$!
17007
17008         for LOOP in $(seq 20); do
17009                 stop ost1
17010                 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
17011         done
17012         kill -9 $pid
17013         do_facet ost1 "pid=\\\$(cat $TMP/sanity_276_pid); kill -9 \\\$pid; \
17014                 rm $TMP/sanity_276_pid"
17015 }
17016 run_test 276 "Race between mount and obd_statfs"
17017
17018 cleanup_test_300() {
17019         trap 0
17020         umask $SAVE_UMASK
17021 }
17022 test_striped_dir() {
17023         local mdt_index=$1
17024         local stripe_count
17025         local stripe_index
17026
17027         mkdir -p $DIR/$tdir
17028
17029         SAVE_UMASK=$(umask)
17030         trap cleanup_test_300 RETURN EXIT
17031
17032         $LFS setdirstripe -i $mdt_index -c 2 -H all_char -o 755 \
17033                                                 $DIR/$tdir/striped_dir ||
17034                 error "set striped dir error"
17035
17036         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
17037         [ "$mode" = "755" ] || error "expect 755 got $mode"
17038
17039         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
17040                 error "getdirstripe failed"
17041         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
17042         if [ "$stripe_count" != "2" ]; then
17043                 error "1:stripe_count is $stripe_count, expect 2"
17044         fi
17045         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
17046         if [ "$stripe_count" != "2" ]; then
17047                 error "2:stripe_count is $stripe_count, expect 2"
17048         fi
17049
17050         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
17051         if [ "$stripe_index" != "$mdt_index" ]; then
17052                 error "stripe_index is $stripe_index, expect $mdt_index"
17053         fi
17054
17055         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
17056                 error "nlink error after create striped dir"
17057
17058         mkdir $DIR/$tdir/striped_dir/a
17059         mkdir $DIR/$tdir/striped_dir/b
17060
17061         stat $DIR/$tdir/striped_dir/a ||
17062                 error "create dir under striped dir failed"
17063         stat $DIR/$tdir/striped_dir/b ||
17064                 error "create dir under striped dir failed"
17065
17066         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
17067                 error "nlink error after mkdir"
17068
17069         rmdir $DIR/$tdir/striped_dir/a
17070         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
17071                 error "nlink error after rmdir"
17072
17073         rmdir $DIR/$tdir/striped_dir/b
17074         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
17075                 error "nlink error after rmdir"
17076
17077         chattr +i $DIR/$tdir/striped_dir
17078         createmany -o $DIR/$tdir/striped_dir/f 10 &&
17079                 error "immutable flags not working under striped dir!"
17080         chattr -i $DIR/$tdir/striped_dir
17081
17082         rmdir $DIR/$tdir/striped_dir ||
17083                 error "rmdir striped dir error"
17084
17085         cleanup_test_300
17086
17087         true
17088 }
17089
17090 test_300a() {
17091         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
17092                 skip "skipped for lustre < 2.7.0"
17093         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17094         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17095
17096         test_striped_dir 0 || error "failed on striped dir on MDT0"
17097         test_striped_dir 1 || error "failed on striped dir on MDT0"
17098 }
17099 run_test 300a "basic striped dir sanity test"
17100
17101 test_300b() {
17102         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
17103                 skip "skipped for lustre < 2.7.0"
17104         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17105         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17106
17107         local i
17108         local mtime1
17109         local mtime2
17110         local mtime3
17111
17112         test_mkdir $DIR/$tdir || error "mkdir fail"
17113         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
17114                 error "set striped dir error"
17115         for i in {0..9}; do
17116                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
17117                 sleep 1
17118                 touch $DIR/$tdir/striped_dir/file_$i || error "touch error $i"
17119                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
17120                 [ $mtime1 -eq $mtime2 ] && error "mtime unchanged after create"
17121                 sleep 1
17122                 rm -f $DIR/$tdir/striped_dir/file_$i || error "unlink error $i"
17123                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
17124                 [ $mtime2 -eq $mtime3 ] && error "mtime unchanged after unlink"
17125         done
17126         true
17127 }
17128 run_test 300b "check ctime/mtime for striped dir"
17129
17130 test_300c() {
17131         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
17132                 skip "skipped for lustre < 2.7.0"
17133         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17134         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17135
17136         local file_count
17137
17138         mkdir -p $DIR/$tdir
17139         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
17140                 error "set striped dir error"
17141
17142         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
17143                 error "chown striped dir failed"
17144
17145         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
17146                 error "create 5k files failed"
17147
17148         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
17149
17150         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
17151
17152         rm -rf $DIR/$tdir
17153 }
17154 run_test 300c "chown && check ls under striped directory"
17155
17156 test_300d() {
17157         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
17158                 skip "skipped for lustre < 2.7.0"
17159         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17160         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17161
17162         local stripe_count
17163         local file
17164
17165         mkdir -p $DIR/$tdir
17166         $SETSTRIPE -c 2 $DIR/$tdir
17167
17168         #local striped directory
17169         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
17170                 error "set striped dir error"
17171         createmany -o $DIR/$tdir/striped_dir/f 10 ||
17172                 error "create 10 files failed"
17173
17174         #remote striped directory
17175         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
17176                 error "set striped dir error"
17177         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
17178                 error "create 10 files failed"
17179
17180         for file in $(find $DIR/$tdir); do
17181                 stripe_count=$($LFS getstripe -c $file)
17182                 [ $stripe_count -eq 2 ] ||
17183                         error "wrong stripe $stripe_count for $file"
17184         done
17185
17186         rm -rf $DIR/$tdir
17187 }
17188 run_test 300d "check default stripe under striped directory"
17189
17190 test_300e() {
17191         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17192                 skip "Need MDS version at least 2.7.55"
17193         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17194         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17195
17196         local stripe_count
17197         local file
17198
17199         mkdir -p $DIR/$tdir
17200
17201         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
17202                 error "set striped dir error"
17203
17204         touch $DIR/$tdir/striped_dir/a
17205         touch $DIR/$tdir/striped_dir/b
17206         touch $DIR/$tdir/striped_dir/c
17207
17208         mkdir $DIR/$tdir/striped_dir/dir_a
17209         mkdir $DIR/$tdir/striped_dir/dir_b
17210         mkdir $DIR/$tdir/striped_dir/dir_c
17211
17212         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_a ||
17213                 error "set striped adir under striped dir error"
17214
17215         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
17216                 error "set striped bdir under striped dir error"
17217
17218         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_c ||
17219                 error "set striped cdir under striped dir error"
17220
17221         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
17222                 error "rename dir under striped dir fails"
17223
17224         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
17225                 error "rename dir under different stripes fails"
17226
17227         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
17228                 error "rename file under striped dir should succeed"
17229
17230         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
17231                 error "rename dir under striped dir should succeed"
17232
17233         rm -rf $DIR/$tdir
17234 }
17235 run_test 300e "check rename under striped directory"
17236
17237 test_300f() {
17238         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17239         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17240         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17241                 skip "Need MDS version at least 2.7.55"
17242
17243         local stripe_count
17244         local file
17245
17246         rm -rf $DIR/$tdir
17247         mkdir -p $DIR/$tdir
17248
17249         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
17250                 error "set striped dir error"
17251
17252         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir1 ||
17253                 error "set striped dir error"
17254
17255         touch $DIR/$tdir/striped_dir/a
17256         mkdir $DIR/$tdir/striped_dir/dir_a
17257         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
17258                 error "create striped dir under striped dir fails"
17259
17260         touch $DIR/$tdir/striped_dir1/b
17261         mkdir $DIR/$tdir/striped_dir1/dir_b
17262         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
17263                 error "create striped dir under striped dir fails"
17264
17265         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
17266                 error "rename dir under different striped dir should fail"
17267
17268         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
17269                 error "rename striped dir under diff striped dir should fail"
17270
17271         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
17272                 error "rename file under diff striped dirs fails"
17273
17274         rm -rf $DIR/$tdir
17275 }
17276 run_test 300f "check rename cross striped directory"
17277
17278 test_300_check_default_striped_dir()
17279 {
17280         local dirname=$1
17281         local default_count=$2
17282         local default_index=$3
17283         local stripe_count
17284         local stripe_index
17285         local dir_stripe_index
17286         local dir
17287
17288         echo "checking $dirname $default_count $default_index"
17289         $LFS setdirstripe -D -c $default_count -i $default_index \
17290                                 -t all_char $DIR/$tdir/$dirname ||
17291                 error "set default stripe on striped dir error"
17292         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
17293         [ $stripe_count -eq $default_count ] ||
17294                 error "expect $default_count get $stripe_count for $dirname"
17295
17296         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
17297         [ $stripe_index -eq $default_index ] ||
17298                 error "expect $default_index get $stripe_index for $dirname"
17299
17300         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
17301                                                 error "create dirs failed"
17302
17303         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
17304         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
17305         for dir in $(find $DIR/$tdir/$dirname/*); do
17306                 stripe_count=$($LFS getdirstripe -c $dir)
17307                 [ $stripe_count -eq $default_count ] ||
17308                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
17309                 error "stripe count $default_count != $stripe_count for $dir"
17310
17311                 stripe_index=$($LFS getdirstripe -i $dir)
17312                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
17313                         error "$stripe_index != $default_index for $dir"
17314
17315                 #check default stripe
17316                 stripe_count=$($LFS getdirstripe -D -c $dir)
17317                 [ $stripe_count -eq $default_count ] ||
17318                 error "default count $default_count != $stripe_count for $dir"
17319
17320                 stripe_index=$($LFS getdirstripe -D -i $dir)
17321                 [ $stripe_index -eq $default_index ] ||
17322                 error "default index $default_index != $stripe_index for $dir"
17323         done
17324         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
17325 }
17326
17327 test_300g() {
17328         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17329         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17330                 skip "Need MDS version at least 2.7.55"
17331
17332         local dir
17333         local stripe_count
17334         local stripe_index
17335
17336         mkdir $DIR/$tdir
17337         mkdir $DIR/$tdir/normal_dir
17338
17339         #Checking when client cache stripe index
17340         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
17341         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
17342                 error "create striped_dir failed"
17343
17344         $LFS setdirstripe -i0 $DIR/$tdir/striped_dir/dir0 ||
17345                 error "create dir0 fails"
17346         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir0)
17347         [ $stripe_index -eq 0 ] ||
17348                 error "dir0 expect index 0 got $stripe_index"
17349
17350         mkdir $DIR/$tdir/striped_dir/dir1 ||
17351                 error "create dir1 fails"
17352         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
17353         [ $stripe_index -eq 1 ] ||
17354                 error "dir1 expect index 1 got $stripe_index"
17355
17356         #check default stripe count/stripe index
17357         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
17358         test_300_check_default_striped_dir normal_dir 1 0
17359         test_300_check_default_striped_dir normal_dir 2 1
17360         test_300_check_default_striped_dir normal_dir 2 -1
17361
17362         #delete default stripe information
17363         echo "delete default stripeEA"
17364         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
17365                 error "set default stripe on striped dir error"
17366
17367         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
17368         for dir in $(find $DIR/$tdir/normal_dir/*); do
17369                 stripe_count=$($LFS getdirstripe -c $dir)
17370                 [ $stripe_count -eq 0 ] ||
17371                         error "expect 1 get $stripe_count for $dir"
17372                 stripe_index=$($LFS getdirstripe -i $dir)
17373                 [ $stripe_index -eq 0 ] ||
17374                         error "expect 0 get $stripe_index for $dir"
17375         done
17376 }
17377 run_test 300g "check default striped directory for normal directory"
17378
17379 test_300h() {
17380         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17381         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17382                 skip "Need MDS version at least 2.7.55"
17383
17384         local dir
17385         local stripe_count
17386
17387         mkdir $DIR/$tdir
17388         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
17389                 error "set striped dir error"
17390
17391         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
17392         test_300_check_default_striped_dir striped_dir 1 0
17393         test_300_check_default_striped_dir striped_dir 2 1
17394         test_300_check_default_striped_dir striped_dir 2 -1
17395
17396         #delete default stripe information
17397         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
17398                 error "set default stripe on striped dir error"
17399
17400         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
17401         for dir in $(find $DIR/$tdir/striped_dir/*); do
17402                 stripe_count=$($LFS getdirstripe -c $dir)
17403                 [ $stripe_count -eq 0 ] ||
17404                         error "expect 1 get $stripe_count for $dir"
17405         done
17406 }
17407 run_test 300h "check default striped directory for striped directory"
17408
17409 test_300i() {
17410         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17411         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17412         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17413                 skip "Need MDS version at least 2.7.55"
17414
17415         local stripe_count
17416         local file
17417
17418         mkdir $DIR/$tdir
17419
17420         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
17421                 error "set striped dir error"
17422
17423         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
17424                 error "create files under striped dir failed"
17425
17426         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
17427                 error "set striped hashdir error"
17428
17429         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
17430                 error "create dir0 under hash dir failed"
17431         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
17432                 error "create dir1 under hash dir failed"
17433
17434         # unfortunately, we need to umount to clear dir layout cache for now
17435         # once we fully implement dir layout, we can drop this
17436         umount_client $MOUNT || error "umount failed"
17437         mount_client $MOUNT || error "mount failed"
17438
17439         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
17440         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
17441         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
17442
17443         #set the stripe to be unknown hash type
17444         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
17445         $LCTL set_param fail_loc=0x1901
17446         for ((i = 0; i < 10; i++)); do
17447                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
17448                         error "stat f-$i failed"
17449                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
17450         done
17451
17452         touch $DIR/$tdir/striped_dir/f0 &&
17453                 error "create under striped dir with unknown hash should fail"
17454
17455         $LCTL set_param fail_loc=0
17456
17457         umount_client $MOUNT || error "umount failed"
17458         mount_client $MOUNT || error "mount failed"
17459
17460         return 0
17461 }
17462 run_test 300i "client handle unknown hash type striped directory"
17463
17464 test_300j() {
17465         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17466         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17467         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17468                 skip "Need MDS version at least 2.7.55"
17469
17470         local stripe_count
17471         local file
17472
17473         mkdir $DIR/$tdir
17474
17475         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
17476         $LCTL set_param fail_loc=0x1702
17477         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
17478                 error "set striped dir error"
17479
17480         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
17481                 error "create files under striped dir failed"
17482
17483         $LCTL set_param fail_loc=0
17484
17485         rm -rf $DIR/$tdir || error "unlink striped dir fails"
17486
17487         return 0
17488 }
17489 run_test 300j "test large update record"
17490
17491 test_300k() {
17492         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17493         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17494         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17495                 skip "Need MDS version at least 2.7.55"
17496
17497         local stripe_count
17498         local file
17499
17500         mkdir $DIR/$tdir
17501
17502         #define OBD_FAIL_LARGE_STRIPE   0x1703
17503         $LCTL set_param fail_loc=0x1703
17504         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
17505                 error "set striped dir error"
17506         $LCTL set_param fail_loc=0
17507
17508         $LFS getdirstripe $DIR/$tdir/striped_dir ||
17509                 error "getstripeddir fails"
17510         rm -rf $DIR/$tdir/striped_dir ||
17511                 error "unlink striped dir fails"
17512
17513         return 0
17514 }
17515 run_test 300k "test large striped directory"
17516
17517 test_300l() {
17518         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17519         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17520         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17521                 skip "Need MDS version at least 2.7.55"
17522
17523         local stripe_index
17524
17525         test_mkdir -p $DIR/$tdir/striped_dir
17526         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
17527                         error "chown $RUNAS_ID failed"
17528         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
17529                 error "set default striped dir failed"
17530
17531         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
17532         $LCTL set_param fail_loc=0x80000158
17533         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
17534
17535         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
17536         [ $stripe_index -eq 1 ] ||
17537                 error "expect 1 get $stripe_index for $dir"
17538 }
17539 run_test 300l "non-root user to create dir under striped dir with stale layout"
17540
17541 test_300m() {
17542         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17543         [ $MDSCOUNT -ge 2 ] && skip_env "Only for single MDT"
17544         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17545                 skip "Need MDS version at least 2.7.55"
17546
17547         mkdir -p $DIR/$tdir/striped_dir
17548         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
17549                 error "set default stripes dir error"
17550
17551         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
17552
17553         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
17554         [ $stripe_count -eq 0 ] ||
17555                         error "expect 0 get $stripe_count for a"
17556
17557         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
17558                 error "set default stripes dir error"
17559
17560         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
17561
17562         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
17563         [ $stripe_count -eq 0 ] ||
17564                         error "expect 0 get $stripe_count for b"
17565
17566         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
17567                 error "set default stripes dir error"
17568
17569         mkdir $DIR/$tdir/striped_dir/c &&
17570                 error "default stripe_index is invalid, mkdir c should fails"
17571
17572         rm -rf $DIR/$tdir || error "rmdir fails"
17573 }
17574 run_test 300m "setstriped directory on single MDT FS"
17575
17576 cleanup_300n() {
17577         local list=$(comma_list $(mdts_nodes))
17578
17579         trap 0
17580         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
17581 }
17582
17583 test_300n() {
17584         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17585         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17586         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17587                 skip "Need MDS version at least 2.7.55"
17588         remote_mds_nodsh && skip "remote MDS with nodsh"
17589
17590         local stripe_index
17591         local list=$(comma_list $(mdts_nodes))
17592
17593         trap cleanup_300n RETURN EXIT
17594         mkdir -p $DIR/$tdir
17595         chmod 777 $DIR/$tdir
17596         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
17597                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
17598                 error "create striped dir succeeds with gid=0"
17599
17600         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
17601         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
17602                 error "create striped dir fails with gid=-1"
17603
17604         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
17605         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
17606                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
17607                 error "set default striped dir succeeds with gid=0"
17608
17609
17610         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
17611         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
17612                 error "set default striped dir fails with gid=-1"
17613
17614
17615         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
17616         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
17617                                         error "create test_dir fails"
17618         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
17619                                         error "create test_dir1 fails"
17620         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
17621                                         error "create test_dir2 fails"
17622         cleanup_300n
17623 }
17624 run_test 300n "non-root user to create dir under striped dir with default EA"
17625
17626 test_300o() {
17627         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17628         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17629         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17630                 skip "Need MDS version at least 2.7.55"
17631
17632         local numfree1
17633         local numfree2
17634
17635         mkdir -p $DIR/$tdir
17636
17637         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
17638         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
17639         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
17640                 skip "not enough free inodes $numfree1 $numfree2"
17641         fi
17642
17643         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
17644         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
17645         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
17646                 skip "not enough free space $numfree1 $numfree2"
17647         fi
17648
17649         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
17650                 error "setdirstripe fails"
17651
17652         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
17653                 error "create dirs fails"
17654
17655         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
17656         ls $DIR/$tdir/striped_dir > /dev/null ||
17657                 error "ls striped dir fails"
17658         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
17659                 error "unlink big striped dir fails"
17660 }
17661 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
17662
17663 test_300p() {
17664         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17665         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17666         remote_mds_nodsh && skip "remote MDS with nodsh"
17667
17668         mkdir -p $DIR/$tdir
17669
17670         #define OBD_FAIL_OUT_ENOSPC     0x1704
17671         do_facet mds2 lctl set_param fail_loc=0x80001704
17672         $LFS setdirstripe -i 0 -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 \
17673                  && error "create striped directory should fail"
17674
17675         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
17676
17677         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
17678         true
17679 }
17680 run_test 300p "create striped directory without space"
17681
17682 test_300q() {
17683         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17684         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17685
17686         local fd=$(free_fd)
17687         local cmd="exec $fd<$tdir"
17688         cd $DIR
17689         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
17690         eval $cmd
17691         cmd="exec $fd<&-"
17692         trap "eval $cmd" EXIT
17693         cd $tdir || error "cd $tdir fails"
17694         rmdir  ../$tdir || error "rmdir $tdir fails"
17695         mkdir local_dir && error "create dir succeeds"
17696         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
17697         eval $cmd
17698         return 0
17699 }
17700 run_test 300q "create remote directory under orphan directory"
17701
17702 prepare_remote_file() {
17703         mkdir $DIR/$tdir/src_dir ||
17704                 error "create remote source failed"
17705
17706         cp /etc/hosts $DIR/$tdir/src_dir/a ||
17707                  error "cp to remote source failed"
17708         touch $DIR/$tdir/src_dir/a
17709
17710         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
17711                 error "create remote target dir failed"
17712
17713         touch $DIR/$tdir/tgt_dir/b
17714
17715         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
17716                 error "rename dir cross MDT failed!"
17717
17718         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
17719                 error "src_child still exists after rename"
17720
17721         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
17722                 error "missing file(a) after rename"
17723
17724         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
17725                 error "diff after rename"
17726 }
17727
17728 test_310a() {
17729         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 4 MDTs"
17730         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17731
17732         local remote_file=$DIR/$tdir/tgt_dir/b
17733
17734         mkdir -p $DIR/$tdir
17735
17736         prepare_remote_file || error "prepare remote file failed"
17737
17738         #open-unlink file
17739         $OPENUNLINK $remote_file $remote_file ||
17740                 error "openunlink $remote_file failed"
17741         $CHECKSTAT -a $remote_file || error "$remote_file exists"
17742 }
17743 run_test 310a "open unlink remote file"
17744
17745 test_310b() {
17746         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 4 MDTs"
17747         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17748
17749         local remote_file=$DIR/$tdir/tgt_dir/b
17750
17751         mkdir -p $DIR/$tdir
17752
17753         prepare_remote_file || error "prepare remote file failed"
17754
17755         ln $remote_file $DIR/$tfile || error "link failed for remote file"
17756         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
17757         $CHECKSTAT -t file $remote_file || error "check file failed"
17758 }
17759 run_test 310b "unlink remote file with multiple links while open"
17760
17761 test_310c() {
17762         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17763         [[ $MDSCOUNT -lt 4 ]] && skip_env "needs >= 4 MDTs"
17764
17765         local remote_file=$DIR/$tdir/tgt_dir/b
17766
17767         mkdir -p $DIR/$tdir
17768
17769         prepare_remote_file || error "prepare remote file failed"
17770
17771         ln $remote_file $DIR/$tfile || error "link failed for remote file"
17772         multiop_bg_pause $remote_file O_uc ||
17773                         error "mulitop failed for remote file"
17774         MULTIPID=$!
17775         $MULTIOP $DIR/$tfile Ouc
17776         kill -USR1 $MULTIPID
17777         wait $MULTIPID
17778 }
17779 run_test 310c "open-unlink remote file with multiple links"
17780
17781 #LU-4825
17782 test_311() {
17783         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17784         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
17785         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
17786                 skip "lustre < 2.8.54 does not contain LU-4825 fix"
17787         remote_mds_nodsh && skip "remote MDS with nodsh"
17788
17789         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
17790
17791         mkdir -p $DIR/$tdir
17792         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
17793         createmany -o $DIR/$tdir/$tfile. 1000
17794
17795         # statfs data is not real time, let's just calculate it
17796         old_iused=$((old_iused + 1000))
17797
17798         local count=$(do_facet $SINGLEMDS "lctl get_param -n \
17799                         osp.*OST0000*MDT0000.create_count")
17800         local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
17801                                 osp.*OST0000*MDT0000.max_create_count")
17802         for idx in $(seq $MDSCOUNT); do
17803                 do_facet mds$idx "lctl set_param -n \
17804                         osp.*OST0000*MDT000?.max_create_count=0"
17805         done
17806
17807         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
17808         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
17809         [ $index -ne 0 ] || error "$tfile stripe index is 0"
17810
17811         unlinkmany $DIR/$tdir/$tfile. 1000
17812
17813         for idx in $(seq $MDSCOUNT); do
17814                 do_facet mds$idx "lctl set_param -n \
17815                         osp.*OST0000*MDT000?.max_create_count=$max_count"
17816                 do_facet mds$idx "lctl set_param -n \
17817                         osp.*OST0000*MDT000?.create_count=$count"
17818         done
17819
17820         local new_iused
17821         for i in $(seq 120); do
17822                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
17823                 # system may be too busy to destroy all objs in time, use
17824                 # a somewhat small value to not fail autotest
17825                 [ $((old_iused - new_iused)) -gt 400 ] && break
17826                 sleep 1
17827         done
17828
17829         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
17830         [ $((old_iused - new_iused)) -gt 400 ] ||
17831                 error "objs not destroyed after unlink"
17832 }
17833 run_test 311 "disable OSP precreate, and unlink should destroy objs"
17834
17835 zfs_oid_to_objid()
17836 {
17837         local ost=$1
17838         local objid=$2
17839
17840         local vdevdir=$(dirname $(facet_vdevice $ost))
17841         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
17842         local zfs_zapid=$(do_facet $ost $cmd |
17843                           grep -w "/O/0/d$((objid%32))" -C 5 |
17844                           awk '/Object/{getline; print $1}')
17845         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
17846                           awk "/$objid = /"'{printf $3}')
17847
17848         echo $zfs_objid
17849 }
17850
17851 zfs_object_blksz() {
17852         local ost=$1
17853         local objid=$2
17854
17855         local vdevdir=$(dirname $(facet_vdevice $ost))
17856         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
17857         local blksz=$(do_facet $ost $cmd $objid |
17858                       awk '/dblk/{getline; printf $4}')
17859
17860         case "${blksz: -1}" in
17861                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
17862                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
17863                 *) ;;
17864         esac
17865
17866         echo $blksz
17867 }
17868
17869 test_312() { # LU-4856
17870         remote_ost_nodsh && skip "remote OST with nodsh"
17871         [ $(facet_fstype ost1) = "zfs" ] ||
17872                 skip_env "the test only applies to zfs"
17873
17874         local max_blksz=$(do_facet ost1 \
17875                           $ZFS get -p recordsize $(facet_device ost1) |
17876                           awk '!/VALUE/{print $3}')
17877         local min_blksz=$(getconf PAGE_SIZE)
17878
17879         # to make life a little bit easier
17880         $LFS mkdir -c 1 -i 0 $DIR/$tdir
17881         $LFS setstripe -c 1 -i 0 $DIR/$tdir
17882
17883         local tf=$DIR/$tdir/$tfile
17884         touch $tf
17885         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17886
17887         # Get ZFS object id
17888         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17889
17890         # block size change by sequential over write
17891         local blksz
17892         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
17893                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
17894
17895                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
17896                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
17897         done
17898         rm -f $tf
17899
17900         # block size change by sequential append write
17901         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
17902         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17903         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17904
17905         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
17906                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
17907                         oflag=sync conv=notrunc
17908
17909                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
17910                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
17911                         error "blksz error, actual $blksz, "    \
17912                                 "expected: 2 * $count * $min_blksz"
17913         done
17914         rm -f $tf
17915
17916         # random write
17917         touch $tf
17918         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17919         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17920
17921         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
17922         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17923         [ $blksz -eq $min_blksz ] ||
17924                 error "blksz error: $blksz, expected: $min_blksz"
17925
17926         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
17927         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17928         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
17929
17930         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
17931         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17932         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
17933 }
17934 run_test 312 "make sure ZFS adjusts its block size by write pattern"
17935
17936 test_313() {
17937         remote_ost_nodsh && skip "remote OST with nodsh"
17938
17939         local file=$DIR/$tfile
17940         rm -f $file
17941         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
17942
17943         # define OBD_FAIL_TGT_RCVD_EIO           0x720
17944         do_facet ost1 "$LCTL set_param fail_loc=0x720"
17945         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
17946                 error "write should failed"
17947         do_facet ost1 "$LCTL set_param fail_loc=0"
17948         rm -f $file
17949 }
17950 run_test 313 "io should fail after last_rcvd update fail"
17951
17952 test_314() {
17953         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
17954
17955         $SETSTRIPE -c 2 -i 0 $DIR/$tfile || error "setstripe failed"
17956         do_facet ost1 "$LCTL set_param fail_loc=0x720"
17957         rm -f $DIR/$tfile
17958         wait_delete_completed
17959         do_facet ost1 "$LCTL set_param fail_loc=0"
17960 }
17961 run_test 314 "OSP shouldn't fail after last_rcvd update failure"
17962
17963 test_315() { # LU-618
17964         local file=$DIR/$tfile
17965         rm -f $file
17966
17967         $MULTIOP $file oO_CREAT:O_DIRECT:O_RDWR:w4096000c
17968         $MULTIOP $file oO_RDONLY:r4096000_c &
17969         PID=$!
17970
17971         sleep 2
17972
17973         local rbytes=$(awk '/read_bytes/ { print $2 }' /proc/$PID/io)
17974         kill -USR1 $PID
17975
17976         [ $rbytes -gt 4000000 ] || error "read is not accounted ($rbytes)"
17977         rm -f $file
17978 }
17979 run_test 315 "read should be accounted"
17980
17981 test_316() {
17982         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17983         large_xattr_enabled || skip_env "large_xattr disabled"
17984
17985         rm -rf $DIR/$tdir/d
17986         mkdir -p $DIR/$tdir/d
17987         chown nobody $DIR/$tdir/d
17988         touch $DIR/$tdir/d/file
17989
17990         $LFS mv -M1 $DIR/$tdir/d || error "lfs mv failed"
17991 }
17992 run_test 316 "lfs mv"
17993
17994 test_317() {
17995         local trunc_sz
17996         local grant_blk_size
17997
17998         if [ "$(facet_fstype $facet)" == "zfs" ]; then
17999                 skip "LU-10370: no implementation for ZFS" && return
18000         fi
18001
18002         stack_trap "rm -f $DIR/$tfile" EXIT
18003         grant_blk_size=$($LCTL get_param osc.$FSNAME*.import |
18004                         awk '/grant_block_size:/ { print $2; exit; }')
18005         #
18006         # Create File of size 5M. Truncate it to below size's and verify
18007         # blocks count.
18008         #
18009         dd if=/dev/zero of=$DIR/$tfile bs=5M count=1 conv=fsync ||
18010                 error "Create file : $DIR/$tfile"
18011
18012         for trunc_sz in 2097152 4097 4000 509 0; do
18013                 $TRUNCATE $DIR/$tfile $trunc_sz ||
18014                         error "truncate $tfile to $trunc_sz failed"
18015                 local sz=$(stat --format=%s $DIR/$tfile)
18016                 local blk=$(stat --format=%b $DIR/$tfile)
18017                 local trunc_blk=$((((trunc_sz + (grant_blk_size - 1) ) /
18018                                      grant_blk_size) * 8))
18019
18020                 if [[ $blk -ne $trunc_blk ]]; then
18021                         $(which stat) $DIR/$tfile
18022                         error "Expected Block $trunc_blk got $blk for $tfile"
18023                 fi
18024
18025                 $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
18026                         error "Expected Size $trunc_sz got $sz for $tfile"
18027         done
18028
18029         #
18030         # sparse file test
18031         # Create file with a hole and write actual two blocks. Block count
18032         # must be 16.
18033         #
18034         dd if=/dev/zero of=$DIR/$tfile bs=$grant_blk_size count=2 seek=5 \
18035                 conv=fsync || error "Create file : $DIR/$tfile"
18036
18037         # Calculate the final truncate size.
18038         trunc_sz=$(($(stat --format=%s $DIR/$tfile) - (grant_blk_size + 1)))
18039
18040         #
18041         # truncate to size $trunc_sz bytes. Strip the last block
18042         # The block count must drop to 8
18043         #
18044         $TRUNCATE $DIR/$tfile $trunc_sz ||
18045                 error "truncate $tfile to $trunc_sz failed"
18046
18047         local trunc_bsz=$((grant_blk_size / $(stat --format=%B $DIR/$tfile)))
18048         sz=$(stat --format=%s $DIR/$tfile)
18049         blk=$(stat --format=%b $DIR/$tfile)
18050
18051         if [[ $blk -ne $trunc_bsz ]]; then
18052                 $(which stat) $DIR/$tfile
18053                 error "Expected Block $trunc_bsz got $blk for $tfile"
18054         fi
18055
18056         $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
18057                 error "Expected Size $trunc_sz got $sz for $tfile"
18058 }
18059 run_test 317 "Verify blocks get correctly update after truncate"
18060
18061 test_fake_rw() {
18062         local read_write=$1
18063         if [ "$read_write" = "write" ]; then
18064                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
18065         elif [ "$read_write" = "read" ]; then
18066                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
18067         else
18068                 error "argument error"
18069         fi
18070
18071         # turn off debug for performance testing
18072         local saved_debug=$($LCTL get_param -n debug)
18073         $LCTL set_param debug=0
18074
18075         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
18076
18077         # get ost1 size - lustre-OST0000
18078         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
18079         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
18080         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
18081
18082         if [ "$read_write" = "read" ]; then
18083                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
18084         fi
18085
18086         local start_time=$(date +%s.%N)
18087         $dd_cmd bs=1M count=$blocks oflag=sync ||
18088                 error "real dd $read_write error"
18089         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
18090
18091         if [ "$read_write" = "write" ]; then
18092                 rm -f $DIR/$tfile
18093         fi
18094
18095         # define OBD_FAIL_OST_FAKE_RW           0x238
18096         do_facet ost1 $LCTL set_param fail_loc=0x238
18097
18098         local start_time=$(date +%s.%N)
18099         $dd_cmd bs=1M count=$blocks oflag=sync ||
18100                 error "fake dd $read_write error"
18101         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
18102
18103         if [ "$read_write" = "write" ]; then
18104                 # verify file size
18105                 cancel_lru_locks osc
18106                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
18107                         error "$tfile size not $blocks MB"
18108         fi
18109         do_facet ost1 $LCTL set_param fail_loc=0
18110
18111         echo "fake $read_write $duration_fake vs. normal $read_write" \
18112                 "$duration in seconds"
18113         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
18114                 error_not_in_vm "fake write is slower"
18115
18116         $LCTL set_param -n debug="$saved_debug"
18117         rm -f $DIR/$tfile
18118 }
18119 test_399a() { # LU-7655 for OST fake write
18120         remote_ost_nodsh && skip "remote OST with nodsh"
18121
18122         test_fake_rw write
18123 }
18124 run_test 399a "fake write should not be slower than normal write"
18125
18126 test_399b() { # LU-8726 for OST fake read
18127         remote_ost_nodsh && skip "remote OST with nodsh"
18128         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
18129                 skip_env "ldiskfs only test"
18130         fi
18131
18132         test_fake_rw read
18133 }
18134 run_test 399b "fake read should not be slower than normal read"
18135
18136 test_400a() { # LU-1606, was conf-sanity test_74
18137         if ! which $CC > /dev/null 2>&1; then
18138                 skip_env "$CC is not installed"
18139         fi
18140
18141         local extra_flags=''
18142         local out=$TMP/$tfile
18143         local prefix=/usr/include/lustre
18144         local prog
18145
18146         if ! [[ -d $prefix ]]; then
18147                 # Assume we're running in tree and fixup the include path.
18148                 extra_flags+=" -I$LUSTRE/include"
18149                 extra_flags+=" -L$LUSTRE/utils"
18150         fi
18151
18152         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
18153                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
18154                         error "client api broken"
18155         done
18156         rm -f $out
18157 }
18158 run_test 400a "Lustre client api program can compile and link"
18159
18160 test_400b() { # LU-1606, LU-5011
18161         local header
18162         local out=$TMP/$tfile
18163         local prefix=/usr/include/linux/lustre
18164
18165         # We use a hard coded prefix so that this test will not fail
18166         # when run in tree. There are headers in lustre/include/lustre/
18167         # that are not packaged (like lustre_idl.h) and have more
18168         # complicated include dependencies (like config.h and lnet/types.h).
18169         # Since this test about correct packaging we just skip them when
18170         # they don't exist (see below) rather than try to fixup cppflags.
18171
18172         if ! which $CC > /dev/null 2>&1; then
18173                 skip_env "$CC is not installed"
18174         fi
18175
18176         for header in $prefix/*.h; do
18177                 if ! [[ -f "$header" ]]; then
18178                         continue
18179                 fi
18180
18181                 if [[ "$(basename $header)" == lustre_ioctl.h ]]; then
18182                         continue # lustre_ioctl.h is internal header
18183                 fi
18184
18185                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
18186                         error "cannot compile '$header'"
18187         done
18188         rm -f $out
18189 }
18190 run_test 400b "packaged headers can be compiled"
18191
18192 test_401a() { #LU-7437
18193         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
18194         [ -n "$printf_arg" ] && skip_env "find does not support -printf"
18195
18196         #count the number of parameters by "list_param -R"
18197         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
18198         #count the number of parameters by listing proc files
18199         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
18200         echo "proc_dirs='$proc_dirs'"
18201         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
18202         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
18203                       sort -u | wc -l)
18204
18205         [ $params -eq $procs ] ||
18206                 error "found $params parameters vs. $procs proc files"
18207
18208         # test the list_param -D option only returns directories
18209         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
18210         #count the number of parameters by listing proc directories
18211         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
18212                 sort -u | wc -l)
18213
18214         [ $params -eq $procs ] ||
18215                 error "found $params parameters vs. $procs proc files"
18216 }
18217 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
18218
18219 test_401b() {
18220         local save=$($LCTL get_param -n jobid_var)
18221         local tmp=testing
18222
18223         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
18224                 error "no error returned when setting bad parameters"
18225
18226         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
18227         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
18228
18229         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
18230         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
18231         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
18232 }
18233 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
18234
18235 test_401c() {
18236         local jobid_var_old=$($LCTL get_param -n jobid_var)
18237         local jobid_var_new
18238
18239         $LCTL set_param jobid_var= &&
18240                 error "no error returned for 'set_param a='"
18241
18242         jobid_var_new=$($LCTL get_param -n jobid_var)
18243         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
18244                 error "jobid_var was changed by setting without value"
18245
18246         $LCTL set_param jobid_var &&
18247                 error "no error returned for 'set_param a'"
18248
18249         jobid_var_new=$($LCTL get_param -n jobid_var)
18250         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
18251                 error "jobid_var was changed by setting without value"
18252 }
18253 run_test 401c "Verify 'lctl set_param' without value fails in either format."
18254
18255 test_401d() {
18256         local jobid_var_old=$($LCTL get_param -n jobid_var)
18257         local jobid_var_new
18258         local new_value="foo=bar"
18259
18260         $LCTL set_param jobid_var=$new_value ||
18261                 error "'set_param a=b' did not accept a value containing '='"
18262
18263         jobid_var_new=$($LCTL get_param -n jobid_var)
18264         [[ "$jobid_var_new" == "$new_value" ]] ||
18265                 error "'set_param a=b' failed on a value containing '='"
18266
18267         # Reset the jobid_var to test the other format
18268         $LCTL set_param jobid_var=$jobid_var_old
18269         jobid_var_new=$($LCTL get_param -n jobid_var)
18270         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
18271                 error "failed to reset jobid_var"
18272
18273         $LCTL set_param jobid_var $new_value ||
18274                 error "'set_param a b' did not accept a value containing '='"
18275
18276         jobid_var_new=$($LCTL get_param -n jobid_var)
18277         [[ "$jobid_var_new" == "$new_value" ]] ||
18278                 error "'set_param a b' failed on a value containing '='"
18279
18280         $LCTL set_param jobid_var $jobid_var_old
18281         jobid_var_new=$($LCTL get_param -n jobid_var)
18282         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
18283                 error "failed to reset jobid_var"
18284 }
18285 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
18286
18287 test_402() {
18288         local server_version=$(lustre_version_code $SINGLEMDS)
18289         [[ $server_version -ge $(version_code 2.7.66) ]] ||
18290         [[ $server_version -ge $(version_code 2.7.18.4) &&
18291                 $server_version -lt $(version_code 2.7.50) ]] ||
18292         [[ $server_version -ge $(version_code 2.7.2) &&
18293                 $server_version -lt $(version_code 2.7.11) ]] ||
18294                 skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+"
18295         remote_mds_nodsh && skip "remote MDS with nodsh"
18296
18297         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
18298 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
18299         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
18300         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
18301                 echo "Touch failed - OK"
18302 }
18303 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
18304
18305 test_403() {
18306         local file1=$DIR/$tfile.1
18307         local file2=$DIR/$tfile.2
18308         local tfile=$TMP/$tfile
18309
18310         rm -f $file1 $file2 $tfile
18311
18312         touch $file1
18313         ln $file1 $file2
18314
18315         # 30 sec OBD_TIMEOUT in ll_getattr()
18316         # right before populating st_nlink
18317         $LCTL set_param fail_loc=0x80001409
18318         stat -c %h $file1 > $tfile &
18319
18320         # create an alias, drop all locks and reclaim the dentry
18321         < $file2
18322         cancel_lru_locks mdc
18323         cancel_lru_locks osc
18324         sysctl -w vm.drop_caches=2
18325
18326         wait
18327
18328         [ $(cat $tfile) -gt 0 ] || error "wrong nlink count: $(cat $tfile)"
18329
18330         rm -f $tfile $file1 $file2
18331 }
18332 run_test 403 "i_nlink should not drop to zero due to aliasing"
18333
18334 test_404() { # LU-6601
18335         local server_version=$(lustre_version_code $SINGLEMDS)
18336         [[ $server_version -ge $(version_code 2.8.53) ]] ||
18337                 skip "Need server version newer than 2.8.52"
18338         remote_mds_nodsh && skip "remote MDS with nodsh"
18339
18340         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
18341                 awk '/osp .*-osc-MDT/ { print $4}')
18342
18343         local osp
18344         for osp in $mosps; do
18345                 echo "Deactivate: " $osp
18346                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
18347                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
18348                         awk -vp=$osp '$4 == p { print $2 }')
18349                 [ $stat = IN ] || {
18350                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
18351                         error "deactivate error"
18352                 }
18353                 echo "Activate: " $osp
18354                 do_facet $SINGLEMDS $LCTL --device %$osp activate
18355                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
18356                         awk -vp=$osp '$4 == p { print $2 }')
18357                 [ $stat = UP ] || {
18358                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
18359                         error "activate error"
18360                 }
18361         done
18362 }
18363 run_test 404 "validate manual {de}activated works properly for OSPs"
18364
18365 test_405() {
18366         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) -o \
18367         [ $(lustre_version_code client) -lt $(version_code 2.6.99) ] &&
18368                 skip "Layout swap lock is not supported"
18369         check_swap_layouts_support
18370
18371         test_mkdir $DIR/$tdir
18372         swap_lock_test -d $DIR/$tdir ||
18373                 error "One layout swap locked test failed"
18374 }
18375 run_test 405 "Various layout swap lock tests"
18376
18377 test_406() {
18378         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
18379         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
18380         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
18381         [ $PARALLEL == "yes" ] && skip "skip parallel run"
18382         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
18383                 skip "Need MDS version at least 2.8.50"
18384
18385         local def_stripe_size=$($LFS getstripe -S $MOUNT)
18386         local test_pool=$TESTNAME
18387
18388         if ! combined_mgs_mds ; then
18389                 mount_mgs_client
18390         fi
18391         pool_add $test_pool || error "pool_add failed"
18392         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
18393                 error "pool_add_targets failed"
18394
18395         save_layout_restore_at_exit $MOUNT
18396
18397         # parent set default stripe count only, child will stripe from both
18398         # parent and fs default
18399         $LFS setstripe -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
18400                 error "setstripe $MOUNT failed"
18401         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
18402         $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
18403         for i in $(seq 10); do
18404                 local f=$DIR/$tdir/$tfile.$i
18405                 touch $f || error "touch failed"
18406                 local count=$($LFS getstripe -c $f)
18407                 [ $count -eq $OSTCOUNT ] ||
18408                         error "$f stripe count $count != $OSTCOUNT"
18409                 local offset=$($LFS getstripe -i $f)
18410                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
18411                 local size=$($LFS getstripe -S $f)
18412                 [ $size -eq $((def_stripe_size * 2)) ] ||
18413                         error "$f stripe size $size != $((def_stripe_size * 2))"
18414                 local pool=$($LFS getstripe -p $f)
18415                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
18416         done
18417
18418         # change fs default striping, delete parent default striping, now child
18419         # will stripe from new fs default striping only
18420         $LFS setstripe -c 1 -S $def_stripe_size -i 0 $MOUNT ||
18421                 error "change $MOUNT default stripe failed"
18422         $LFS setstripe -c 0 $DIR/$tdir ||
18423                 error "delete $tdir default stripe failed"
18424         for i in $(seq 11 20); do
18425                 local f=$DIR/$tdir/$tfile.$i
18426                 touch $f || error "touch $f failed"
18427                 local count=$($LFS getstripe -c $f)
18428                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
18429                 local offset=$($LFS getstripe -i $f)
18430                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
18431                 local size=$($LFS getstripe -S $f)
18432                 [ $size -eq $def_stripe_size ] ||
18433                         error "$f stripe size $size != $def_stripe_size"
18434                 local pool=$($LFS getstripe -p $f)
18435                 [ $pool == $test_pool ] || error "$f pool $pool isn't set"
18436         done
18437
18438         unlinkmany $DIR/$tdir/$tfile. 1 20
18439
18440         local f=$DIR/$tdir/$tfile
18441         pool_remove_all_targets $test_pool $f
18442         pool_remove $test_pool $f
18443
18444         if ! combined_mgs_mds ; then
18445                 umount_mgs_client
18446         fi
18447 }
18448 run_test 406 "DNE support fs default striping"
18449
18450 test_407() {
18451         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
18452         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
18453                 skip "Need MDS version at least 2.8.55"
18454         remote_mds_nodsh && skip "remote MDS with nodsh"
18455
18456         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
18457                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
18458         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
18459                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
18460         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
18461
18462         #define OBD_FAIL_DT_TXN_STOP    0x2019
18463         for idx in $(seq $MDSCOUNT); do
18464                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
18465         done
18466         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
18467         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
18468                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
18469         true
18470 }
18471 run_test 407 "transaction fail should cause operation fail"
18472
18473 test_408() {
18474         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
18475
18476         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
18477         lctl set_param fail_loc=0x8000040a
18478         # let ll_prepare_partial_page() fail
18479         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
18480
18481         rm -f $DIR/$tfile
18482
18483         # create at least 100 unused inodes so that
18484         # shrink_icache_memory(0) should not return 0
18485         touch $DIR/$tfile-{0..100}
18486         rm -f $DIR/$tfile-{0..100}
18487         sync
18488
18489         echo 2 > /proc/sys/vm/drop_caches
18490 }
18491 run_test 408 "drop_caches should not hang due to page leaks"
18492
18493 test_409()
18494 {
18495         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
18496         check_mount_and_prep
18497
18498         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
18499         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
18500         touch $DIR/$tdir/guard || error "(2) Fail to create"
18501
18502         local PREFIX=$(str_repeat 'A' 128)
18503         echo "Create 1K hard links start at $(date)"
18504         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
18505                 error "(3) Fail to hard link"
18506
18507         echo "Links count should be right although linkEA overflow"
18508         stat $DIR/$tdir/guard || error "(4) Fail to stat"
18509         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
18510         [ $linkcount -eq 1001 ] ||
18511                 error "(5) Unexpected hard links count: $linkcount"
18512
18513         echo "List all links start at $(date)"
18514         ls -l $DIR/$tdir/foo > /dev/null ||
18515                 error "(6) Fail to list $DIR/$tdir/foo"
18516
18517         echo "Unlink hard links start at $(date)"
18518         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
18519                 error "(7) Fail to unlink"
18520 }
18521 run_test 409 "Large amount of cross-MDTs hard links on the same file"
18522
18523 test_410()
18524 {
18525         [[ $(lustre_version_code client) -lt $(version_code 2.9.59) ]] &&
18526                 skip "Need client version at least 2.9.59"
18527
18528         # Create a file, and stat it from the kernel
18529         local testfile=$DIR/$tfile
18530         touch $testfile
18531
18532         local run_id=$RANDOM
18533         local my_ino=$(stat --format "%i" $testfile)
18534
18535         # Try to insert the module. This will always fail as the
18536         # module is designed to not be inserted.
18537         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
18538             &> /dev/null
18539
18540         # Anything but success is a test failure
18541         dmesg | grep -q \
18542             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
18543             error "no inode match"
18544 }
18545 run_test 410 "Test inode number returned from kernel thread"
18546
18547 cleanup_test411_cgroup() {
18548         trap 0
18549         rmdir "$1"
18550 }
18551
18552 test_411() {
18553         local cg_basedir=/sys/fs/cgroup/memory
18554         # LU-9966
18555         test -f "$cg_basedir/memory.kmem.limit_in_bytes" ||
18556                 skip "no setup for cgroup"
18557
18558         dd if=/dev/zero of=$DIR/$tfile bs=1M count=100 conv=fsync ||
18559                 error "test file creation failed"
18560         cancel_lru_locks osc
18561
18562         # Create a very small memory cgroup to force a slab allocation error
18563         local cgdir=$cg_basedir/osc_slab_alloc
18564         mkdir $cgdir || error "cgroup mkdir '$cgdir' failed"
18565         trap "cleanup_test411_cgroup $cgdir" EXIT
18566         echo 2M > $cgdir/memory.kmem.limit_in_bytes
18567         echo 1M > $cgdir/memory.limit_in_bytes
18568
18569         # Should not LBUG, just be killed by oom-killer
18570         sh -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null" &&
18571                 error "fail to trigger a memory allocation error"
18572
18573         cleanup_test411_cgroup $cgdir
18574
18575         return 0
18576 }
18577 run_test 411 "Slab allocation error with cgroup does not LBUG"
18578
18579 test_412() {
18580         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
18581         if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
18582                 skip "Need server version at least 2.10.55"
18583         fi
18584
18585         $LFS mkdir -i $((MDSCOUNT - 1)),$((MDSCOUNT - 2)) $DIR/$tdir ||
18586                 error "mkdir failed"
18587         $LFS getdirstripe $DIR/$tdir
18588         local stripe_index=$($LFS getdirstripe -i $DIR/$tdir)
18589         [ $stripe_index -eq $((MDSCOUNT - 1)) ] ||
18590                 error "expect $((MDSCOUT - 1)) get $stripe_index"
18591         local stripe_count=$($LFS getdirstripe -T $DIR/$tdir)
18592         [ $stripe_count -eq 2 ] ||
18593                 error "expect 2 get $stripe_count"
18594 }
18595 run_test 412 "mkdir on specific MDTs"
18596
18597 test_413() {
18598         [ $MDSCOUNT -lt 2 ] &&
18599                 skip "We need at least 2 MDTs for this test"
18600
18601         if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
18602                 skip "Need server version at least 2.10.55"
18603         fi
18604
18605         mkdir $DIR/$tdir || error "mkdir failed"
18606
18607         # find MDT that is the most full
18608         local max=$($LFS df | grep MDT |
18609                 awk 'BEGIN { a=0 }
18610                         { sub("%", "", $5)
18611                           if (0+$5 >= a)
18612                           {
18613                                 a = $5
18614                                 b = $6
18615                           }
18616                         }
18617                      END { split(b, c, ":")
18618                            sub("]", "", c[2])
18619                            print c[2]
18620                          }')
18621
18622         for i in $(seq $((MDSCOUNT - 1))); do
18623                 $LFS mkdir -c $i $DIR/$tdir/d$i ||
18624                         error "mkdir d$i failed"
18625                 $LFS getdirstripe $DIR/$tdir/d$i
18626                 local stripe_index=$($LFS getdirstripe -i $DIR/$tdir/d$i)
18627                 [ $stripe_index -ne $max ] ||
18628                         error "don't expect $max"
18629         done
18630 }
18631 run_test 413 "mkdir on less full MDTs"
18632
18633 test_414() {
18634 #define OBD_FAIL_PTLRPC_BULK_ATTACH      0x521
18635         $LCTL set_param fail_loc=0x80000521
18636         dd if=/dev/zero of=$DIR/$tfile bs=2M count=1 oflag=sync
18637         rm -f $DIR/$tfile
18638 }
18639 run_test 414 "simulate ENOMEM in ptlrpc_register_bulk()"
18640
18641 prep_801() {
18642         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
18643         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
18644                 skip "Need server version at least 2.9.55"
18645
18646         start_full_debug_logging
18647 }
18648
18649 post_801() {
18650         stop_full_debug_logging
18651 }
18652
18653 barrier_stat() {
18654         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
18655                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
18656                            awk '/The barrier for/ { print $7 }')
18657                 echo $st
18658         else
18659                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
18660                 echo \'$st\'
18661         fi
18662 }
18663
18664 barrier_expired() {
18665         local expired
18666
18667         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
18668                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
18669                           awk '/will be expired/ { print $7 }')
18670         else
18671                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
18672         fi
18673
18674         echo $expired
18675 }
18676
18677 test_801a() {
18678         prep_801
18679
18680         echo "Start barrier_freeze at: $(date)"
18681         #define OBD_FAIL_BARRIER_DELAY          0x2202
18682         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
18683         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
18684
18685         sleep 2
18686         local b_status=$(barrier_stat)
18687         echo "Got barrier status at: $(date)"
18688         [ "$b_status" = "'freezing_p1'" ] ||
18689                 error "(1) unexpected barrier status $b_status"
18690
18691         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
18692         wait
18693         b_status=$(barrier_stat)
18694         [ "$b_status" = "'frozen'" ] ||
18695                 error "(2) unexpected barrier status $b_status"
18696
18697         local expired=$(barrier_expired)
18698         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
18699         sleep $((expired + 3))
18700
18701         b_status=$(barrier_stat)
18702         [ "$b_status" = "'expired'" ] ||
18703                 error "(3) unexpected barrier status $b_status"
18704
18705         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
18706                 error "(4) fail to freeze barrier"
18707
18708         b_status=$(barrier_stat)
18709         [ "$b_status" = "'frozen'" ] ||
18710                 error "(5) unexpected barrier status $b_status"
18711
18712         echo "Start barrier_thaw at: $(date)"
18713         #define OBD_FAIL_BARRIER_DELAY          0x2202
18714         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
18715         do_facet mgs $LCTL barrier_thaw $FSNAME &
18716
18717         sleep 2
18718         b_status=$(barrier_stat)
18719         echo "Got barrier status at: $(date)"
18720         [ "$b_status" = "'thawing'" ] ||
18721                 error "(6) unexpected barrier status $b_status"
18722
18723         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
18724         wait
18725         b_status=$(barrier_stat)
18726         [ "$b_status" = "'thawed'" ] ||
18727                 error "(7) unexpected barrier status $b_status"
18728
18729         #define OBD_FAIL_BARRIER_FAILURE        0x2203
18730         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
18731         do_facet mgs $LCTL barrier_freeze $FSNAME
18732
18733         b_status=$(barrier_stat)
18734         [ "$b_status" = "'failed'" ] ||
18735                 error "(8) unexpected barrier status $b_status"
18736
18737         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
18738         do_facet mgs $LCTL barrier_thaw $FSNAME
18739
18740         post_801
18741 }
18742 run_test 801a "write barrier user interfaces and stat machine"
18743
18744 test_801b() {
18745         prep_801
18746
18747         mkdir $DIR/$tdir || error "(1) fail to mkdir"
18748         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
18749         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
18750         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
18751         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
18752
18753         cancel_lru_locks mdc
18754
18755         # 180 seconds should be long enough
18756         do_facet mgs $LCTL barrier_freeze $FSNAME 180
18757
18758         local b_status=$(barrier_stat)
18759         [ "$b_status" = "'frozen'" ] ||
18760                 error "(6) unexpected barrier status $b_status"
18761
18762         mkdir $DIR/$tdir/d0/d10 &
18763         mkdir_pid=$!
18764
18765         touch $DIR/$tdir/d1/f13 &
18766         touch_pid=$!
18767
18768         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
18769         ln_pid=$!
18770
18771         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
18772         mv_pid=$!
18773
18774         rm -f $DIR/$tdir/d4/f12 &
18775         rm_pid=$!
18776
18777         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
18778
18779         # To guarantee taht the 'stat' is not blocked
18780         b_status=$(barrier_stat)
18781         [ "$b_status" = "'frozen'" ] ||
18782                 error "(8) unexpected barrier status $b_status"
18783
18784         # let above commands to run at background
18785         sleep 5
18786
18787         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
18788         ps -p $touch_pid || error "(10) touch should be blocked"
18789         ps -p $ln_pid || error "(11) link should be blocked"
18790         ps -p $mv_pid || error "(12) rename should be blocked"
18791         ps -p $rm_pid || error "(13) unlink should be blocked"
18792
18793         b_status=$(barrier_stat)
18794         [ "$b_status" = "'frozen'" ] ||
18795                 error "(14) unexpected barrier status $b_status"
18796
18797         do_facet mgs $LCTL barrier_thaw $FSNAME
18798         b_status=$(barrier_stat)
18799         [ "$b_status" = "'thawed'" ] ||
18800                 error "(15) unexpected barrier status $b_status"
18801
18802         wait $mkdir_pid || error "(16) mkdir should succeed"
18803         wait $touch_pid || error "(17) touch should succeed"
18804         wait $ln_pid || error "(18) link should succeed"
18805         wait $mv_pid || error "(19) rename should succeed"
18806         wait $rm_pid || error "(20) unlink should succeed"
18807
18808         post_801
18809 }
18810 run_test 801b "modification will be blocked by write barrier"
18811
18812 test_801c() {
18813         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
18814
18815         prep_801
18816
18817         stop mds2 || error "(1) Fail to stop mds2"
18818
18819         do_facet mgs $LCTL barrier_freeze $FSNAME 30
18820
18821         local b_status=$(barrier_stat)
18822         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
18823                 do_facet mgs $LCTL barrier_thaw $FSNAME
18824                 error "(2) unexpected barrier status $b_status"
18825         }
18826
18827         do_facet mgs $LCTL barrier_rescan $FSNAME ||
18828                 error "(3) Fail to rescan barrier bitmap"
18829
18830         do_facet mgs $LCTL barrier_freeze $FSNAME 10
18831
18832         b_status=$(barrier_stat)
18833         [ "$b_status" = "'frozen'" ] ||
18834                 error "(4) unexpected barrier status $b_status"
18835
18836         do_facet mgs $LCTL barrier_thaw $FSNAME
18837         b_status=$(barrier_stat)
18838         [ "$b_status" = "'thawed'" ] ||
18839                 error "(5) unexpected barrier status $b_status"
18840
18841         local devname=$(mdsdevname 2)
18842
18843         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
18844
18845         do_facet mgs $LCTL barrier_rescan $FSNAME ||
18846                 error "(7) Fail to rescan barrier bitmap"
18847
18848         post_801
18849 }
18850 run_test 801c "rescan barrier bitmap"
18851
18852 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
18853 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
18854 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
18855
18856 cleanup_802() {
18857         trap 0
18858
18859         stopall
18860         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
18861         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
18862         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
18863         setupall
18864 }
18865
18866 test_802() {
18867
18868         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
18869         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
18870                 skip "Need server version at least 2.9.55"
18871
18872         mkdir $DIR/$tdir || error "(1) fail to mkdir"
18873
18874         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
18875                 error "(2) Fail to copy"
18876
18877         trap cleanup_802 EXIT
18878
18879         # sync by force before remount as readonly
18880         sync; sync_all_data; sleep 3; sync_all_data
18881
18882         stopall
18883
18884         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
18885         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
18886         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
18887
18888         echo "Mount the server as read only"
18889         setupall server_only || error "(3) Fail to start servers"
18890
18891         echo "Mount client without ro should fail"
18892         mount_client $MOUNT &&
18893                 error "(4) Mount client without 'ro' should fail"
18894
18895         echo "Mount client with ro should succeed"
18896         mount_client $MOUNT ro ||
18897                 error "(5) Mount client with 'ro' should succeed"
18898
18899         echo "Modify should be refused"
18900         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
18901
18902         echo "Read should be allowed"
18903         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
18904                 error "(7) Read should succeed under ro mode"
18905
18906         cleanup_802
18907 }
18908 run_test 802 "simulate readonly device"
18909
18910 test_803() {
18911         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
18912         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.54) ] &&
18913                 skip "MDS needs to be newer than 2.10.54"
18914
18915         mkdir -p $DIR/$tdir
18916         # Create some objects on all MDTs to trigger related logs objects
18917         for idx in $(seq $MDSCOUNT); do
18918                 $LFS mkdir -c $MDSCOUNT -i $((idx % $MDSCOUNT)) \
18919                         $DIR/$tdir/dir${idx} ||
18920                         error "Fail to create $DIR/$tdir/dir${idx}"
18921         done
18922
18923         sync; sleep 3
18924         echo "before create:"
18925         $LFS df -i $MOUNT
18926         local before_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18927
18928         for ((i=0; i<10; i++)); do
18929                 $LFS mkdir -c 1 -i 1 $DIR/$tdir/foo$i ||
18930                         error "Fail to create $DIR/$tdir/foo$i"
18931         done
18932
18933         sync; sleep 3
18934         echo "after create:"
18935         $LFS df -i $MOUNT
18936         local after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18937
18938         [ $after_used -ge $((before_used + 10)) ] ||
18939                 error "before ($before_used) + 10 > after ($after_used)"
18940
18941         for ((i=0; i<10; i++)); do
18942                 rm -rf $DIR/$tdir/foo$i ||
18943                         error "Fail to remove $DIR/$tdir/foo$i"
18944         done
18945
18946         sleep 3 # avoid MDT return cached statfs
18947         wait_delete_completed
18948         echo "after unlink:"
18949         $LFS df -i $MOUNT
18950         before_used=$after_used
18951         after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18952
18953         [ $after_used -le $((before_used - 8)) ] ||
18954                 error "before ($before_used) - 8 < after ($after_used)"
18955 }
18956 run_test 803 "verify agent object for remote object"
18957
18958 test_804() {
18959         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
18960         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.54) ] &&
18961                 skip "MDS needs to be newer than 2.10.54"
18962         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
18963                 skip_env "ldiskfs only test"
18964
18965         mkdir -p $DIR/$tdir
18966         $LFS mkdir -c 1 -i 1 $DIR/$tdir/dir0 ||
18967                 error "Fail to create $DIR/$tdir/dir0"
18968
18969         local fid=$($LFS path2fid $DIR/$tdir/dir0)
18970         local dev=$(mdsdevname 2)
18971
18972         do_facet mds2 "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18973                 grep ${fid} || error "NOT found agent entry for dir0"
18974
18975         $LFS mkdir -c $MDSCOUNT -i 0 $DIR/$tdir/dir1 ||
18976                 error "Fail to create $DIR/$tdir/dir1"
18977
18978         touch $DIR/$tdir/dir1/foo0 ||
18979                 error "Fail to create $DIR/$tdir/dir1/foo0"
18980         fid=$($LFS path2fid $DIR/$tdir/dir1/foo0)
18981         local rc=0
18982
18983         for idx in $(seq $MDSCOUNT); do
18984                 dev=$(mdsdevname $idx)
18985                 do_facet mds${idx} \
18986                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18987                         grep ${fid} && rc=$idx
18988         done
18989
18990         mv $DIR/$tdir/dir1/foo0 $DIR/$tdir/dir1/foo1 ||
18991                 error "Fail to rename foo0 to foo1"
18992         if [ $rc -eq 0 ]; then
18993                 for idx in $(seq $MDSCOUNT); do
18994                         dev=$(mdsdevname $idx)
18995                         do_facet mds${idx} \
18996                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18997                         grep ${fid} && rc=$idx
18998                 done
18999         fi
19000
19001         mv $DIR/$tdir/dir1/foo1 $DIR/$tdir/dir1/foo2 ||
19002                 error "Fail to rename foo1 to foo2"
19003         if [ $rc -eq 0 ]; then
19004                 for idx in $(seq $MDSCOUNT); do
19005                         dev=$(mdsdevname $idx)
19006                         do_facet mds${idx} \
19007                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
19008                         grep ${fid} && rc=$idx
19009                 done
19010         fi
19011
19012         [ $rc -ne 0 ] || error "NOT found agent entry for foo"
19013
19014         ln $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir0/guard ||
19015                 error "Fail to link to $DIR/$tdir/dir1/foo2"
19016         mv $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir1/foo0 ||
19017                 error "Fail to rename foo2 to foo0"
19018         unlink $DIR/$tdir/dir1/foo0 ||
19019                 error "Fail to unlink $DIR/$tdir/dir1/foo0"
19020         rm -rf $DIR/$tdir/dir0 ||
19021                 error "Fail to rm $DIR/$tdir/dir0"
19022
19023         for idx in $(seq $MDSCOUNT); do
19024                 dev=$(mdsdevname $idx)
19025                 rc=0
19026
19027                 stop mds${idx}
19028                 run_e2fsck $(facet_active_host mds$idx) $dev -n ||
19029                         rc=$?
19030                 start mds${idx} $dev $MDS_MOUNT_OPTS ||
19031                         error "mount mds$idx failed"
19032                 df $MOUNT > /dev/null 2>&1
19033
19034                 # e2fsck should not return error
19035                 [ $rc -eq 0 ] ||
19036                         error "e2fsck detected error on MDT${idx}: rc=$rc"
19037         done
19038 }
19039 run_test 804 "verify agent entry for remote entry"
19040
19041 cleanup_805() {
19042         do_facet $SINGLEMDS zfs set quota=$old $fsset
19043         unlinkmany $DIR/$tdir/f- 1000000
19044         trap 0
19045 }
19046
19047 test_805() {
19048         local zfs_version=$(do_node $SINGLEMDS cat /sys/module/zfs/version)
19049         [ "$(facet_fstype mds1)" != "zfs" ] &&
19050                 skip "ZFS specific test"
19051         [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
19052                 skip "netfree not implemented before 0.7"
19053         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
19054                 skip "Need MDS version at least 2.10.57"
19055
19056         local fsset
19057         local freekb
19058         local usedkb
19059         local old
19060         local quota
19061         local pref="osd-zfs.lustre-MDT0000."
19062
19063         # limit available space on MDS dataset to meet nospace issue
19064         # quickly. then ZFS 0.7.2 can use reserved space if asked
19065         # properly (using netfree flag in osd_declare_destroy()
19066         fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
19067         old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
19068                 gawk '{print $3}')
19069         freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
19070         usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
19071         let "usedkb=usedkb-freekb"
19072         let "freekb=freekb/2"
19073         if let "freekb > 5000"; then
19074                 let "freekb=5000"
19075         fi
19076         do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
19077         trap cleanup_805 EXIT
19078         mkdir $DIR/$tdir
19079         $LFS setstripe -E 1M -L mdt $DIR/$tdir || error "DoM not working"
19080         createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
19081         rm -rf $DIR/$tdir || error "not able to remove"
19082         do_facet $SINGLEMDS zfs set quota=$old $fsset
19083         trap 0
19084 }
19085 run_test 805 "ZFS can remove from full fs"
19086
19087 #
19088 # tests that do cleanup/setup should be run at the end
19089 #
19090
19091 test_900() {
19092         [ $PARALLEL == "yes" ] && skip "skip parallel run"
19093         local ls
19094
19095         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
19096         $LCTL set_param fail_loc=0x903
19097
19098         cancel_lru_locks MGC
19099
19100         FAIL_ON_ERROR=true cleanup
19101         FAIL_ON_ERROR=true setup
19102 }
19103 run_test 900 "umount should not race with any mgc requeue thread"
19104
19105 complete $SECONDS
19106 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
19107 check_and_cleanup_lustre
19108 if [ "$I_MOUNTED" != "yes" ]; then
19109         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
19110 fi
19111 exit_status