Whamcloud - gitweb
LU-10928 tests: sanity/133b should wait a bit
[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         # Sleep to avoid a cached response.
10715         #define OBD_STATFS_CACHE_SECONDS 1
10716         sleep 2
10717         $LFS df || error "lfs failed"
10718         check_stats $SINGLEMDS "statfs" 1
10719
10720         rm -rf $DIR/${tdir}
10721 }
10722 run_test 133b "Verifying extra MDT stats =================================="
10723
10724 test_133c() {
10725         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10726         remote_ost_nodsh && skip "remote OST with nodsh"
10727         remote_mds_nodsh && skip "remote MDS with nodsh"
10728
10729         local testdir=$DIR/$tdir/stats_testdir
10730
10731         test_mkdir -p $testdir
10732
10733         # verify obdfilter stats.
10734         $SETSTRIPE -c 1 -i 0 $testdir/$tfile
10735         sync
10736         cancel_lru_locks osc
10737         wait_delete_completed
10738
10739         # clear stats.
10740         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10741         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10742
10743         dd if=/dev/zero of=$testdir/$tfile conv=notrunc bs=512k count=1 ||
10744                 error "dd failed"
10745         sync
10746         cancel_lru_locks osc
10747         check_stats ost1 "write" 1
10748
10749         dd if=$testdir/$tfile of=/dev/null bs=1k count=1 || error "dd failed"
10750         check_stats ost1 "read" 1
10751
10752         > $testdir/$tfile || error "truncate failed"
10753         check_stats ost1 "punch" 1
10754
10755         rm -f $testdir/$tfile || error "file remove failed"
10756         wait_delete_completed
10757         check_stats ost1 "destroy" 1
10758
10759         rm -rf $DIR/$tdir
10760 }
10761 run_test 133c "Verifying OST stats ========================================"
10762
10763 order_2() {
10764         local value=$1
10765         local orig=$value
10766         local order=1
10767
10768         while [ $value -ge 2 ]; do
10769                 order=$((order*2))
10770                 value=$((value/2))
10771         done
10772
10773         if [ $orig -gt $order ]; then
10774                 order=$((order*2))
10775         fi
10776         echo $order
10777 }
10778
10779 size_in_KMGT() {
10780     local value=$1
10781     local size=('K' 'M' 'G' 'T');
10782     local i=0
10783     local size_string=$value
10784
10785     while [ $value -ge 1024 ]; do
10786         if [ $i -gt 3 ]; then
10787             #T is the biggest unit we get here, if that is bigger,
10788             #just return XXXT
10789             size_string=${value}T
10790             break
10791         fi
10792         value=$((value >> 10))
10793         if [ $value -lt 1024 ]; then
10794             size_string=${value}${size[$i]}
10795             break
10796         fi
10797         i=$((i + 1))
10798     done
10799
10800     echo $size_string
10801 }
10802
10803 get_rename_size() {
10804         local size=$1
10805         local context=${2:-.}
10806         local sample=$(do_facet $SINGLEMDS $LCTL \
10807                 get_param mdt.$FSNAME-MDT0000.rename_stats |
10808                 grep -A1 $context |
10809                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
10810         echo $sample
10811 }
10812
10813 test_133d() {
10814         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10815         remote_ost_nodsh && skip "remote OST with nodsh"
10816         remote_mds_nodsh && skip "remote MDS with nodsh"
10817         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
10818                 skip_env "MDS doesn't support rename stats"
10819
10820         local testdir1=$DIR/${tdir}/stats_testdir1
10821         local testdir2=$DIR/${tdir}/stats_testdir2
10822         mkdir -p $DIR/${tdir}
10823
10824         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10825
10826         lfs mkdir -i 0 -c 1 ${testdir1} || error "mkdir failed"
10827         lfs mkdir -i 0 -c 1 ${testdir2} || error "mkdir failed"
10828
10829         createmany -o $testdir1/test 512 || error "createmany failed"
10830
10831         # check samedir rename size
10832         mv ${testdir1}/test0 ${testdir1}/test_0
10833
10834         local testdir1_size=$(ls -l $DIR/${tdir} |
10835                 awk '/stats_testdir1/ {print $5}')
10836         local testdir2_size=$(ls -l $DIR/${tdir} |
10837                 awk '/stats_testdir2/ {print $5}')
10838
10839         testdir1_size=$(order_2 $testdir1_size)
10840         testdir2_size=$(order_2 $testdir2_size)
10841
10842         testdir1_size=$(size_in_KMGT $testdir1_size)
10843         testdir2_size=$(size_in_KMGT $testdir2_size)
10844
10845         echo "source rename dir size: ${testdir1_size}"
10846         echo "target rename dir size: ${testdir2_size}"
10847
10848         local cmd="do_facet $SINGLEMDS $LCTL "
10849         cmd+="get_param mdt.$FSNAME-MDT0000.rename_stats"
10850
10851         eval $cmd || error "$cmd failed"
10852         local samedir=$($cmd | grep 'same_dir')
10853         local same_sample=$(get_rename_size $testdir1_size)
10854         [ -z "$samedir" ] && error "samedir_rename_size count error"
10855         [[ $same_sample -eq 1 ]] ||
10856                 error "samedir_rename_size error $same_sample"
10857         echo "Check same dir rename stats success"
10858
10859         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10860
10861         # check crossdir rename size
10862         mv ${testdir1}/test_0 ${testdir2}/test_0
10863
10864         testdir1_size=$(ls -l $DIR/${tdir} |
10865                 awk '/stats_testdir1/ {print $5}')
10866         testdir2_size=$(ls -l $DIR/${tdir} |
10867                 awk '/stats_testdir2/ {print $5}')
10868
10869         testdir1_size=$(order_2 $testdir1_size)
10870         testdir2_size=$(order_2 $testdir2_size)
10871
10872         testdir1_size=$(size_in_KMGT $testdir1_size)
10873         testdir2_size=$(size_in_KMGT $testdir2_size)
10874
10875         echo "source rename dir size: ${testdir1_size}"
10876         echo "target rename dir size: ${testdir2_size}"
10877
10878         eval $cmd || error "$cmd failed"
10879         local crossdir=$($cmd | grep 'crossdir')
10880         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
10881         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
10882         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
10883         [[ $src_sample -eq 1 ]] ||
10884                 error "crossdir_rename_size error $src_sample"
10885         [[ $tgt_sample -eq 1 ]] ||
10886                 error "crossdir_rename_size error $tgt_sample"
10887         echo "Check cross dir rename stats success"
10888         rm -rf $DIR/${tdir}
10889 }
10890 run_test 133d "Verifying rename_stats ========================================"
10891
10892 test_133e() {
10893         remote_mds_nodsh && skip "remote MDS with nodsh"
10894         remote_ost_nodsh && skip "remote OST with nodsh"
10895         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10896
10897         local testdir=$DIR/${tdir}/stats_testdir
10898         local ctr f0 f1 bs=32768 count=42 sum
10899
10900         mkdir -p ${testdir} || error "mkdir failed"
10901
10902         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
10903
10904         for ctr in {write,read}_bytes; do
10905                 sync
10906                 cancel_lru_locks osc
10907
10908                 do_facet ost1 $LCTL set_param -n \
10909                         "obdfilter.*.exports.clear=clear"
10910
10911                 if [ $ctr = write_bytes ]; then
10912                         f0=/dev/zero
10913                         f1=${testdir}/${tfile}
10914                 else
10915                         f0=${testdir}/${tfile}
10916                         f1=/dev/null
10917                 fi
10918
10919                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
10920                         error "dd failed"
10921                 sync
10922                 cancel_lru_locks osc
10923
10924                 sum=$(do_facet ost1 $LCTL get_param \
10925                         "obdfilter.*.exports.*.stats" |
10926                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
10927                                 $1 == ctr { sum += $7 }
10928                                 END { printf("%0.0f", sum) }')
10929
10930                 if ((sum != bs * count)); then
10931                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
10932                 fi
10933         done
10934
10935         rm -rf $DIR/${tdir}
10936 }
10937 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
10938
10939 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
10940
10941 test_133f() {
10942         # First without trusting modes.
10943         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10944         echo "proc_dirs='$proc_dirs'"
10945         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10946         find $proc_dirs -exec cat '{}' \; &> /dev/null
10947
10948         # Second verifying readability.
10949         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
10950
10951         # Verifing writability with badarea_io.
10952         find $proc_dirs \
10953                 -ignore_readdir_race \
10954                 -type f \
10955                 -not -name force_lbug \
10956                 -not -name changelog_mask \
10957                 -exec badarea_io '{}' \; ||
10958                         error "find $proc_dirs failed"
10959 }
10960 run_test 133f "Check reads/writes of client lustre proc files with bad area io"
10961
10962 test_133g() {
10963         remote_mds_nodsh && skip "remote MDS with nodsh"
10964         remote_ost_nodsh && skip "remote OST with nodsh"
10965
10966         # eventually, this can also be replaced with "lctl get_param -R",
10967         # but not until that option is always available on the server
10968         local facet
10969         for facet in mds1 ost1; do
10970                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
10971                         skip_noexit "Too old lustre on $facet"
10972                 local facet_proc_dirs=$(do_facet $facet \
10973                                         \\\ls -d $proc_regexp 2>/dev/null)
10974                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10975                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10976                 do_facet $facet find $facet_proc_dirs \
10977                         ! -name req_history \
10978                         -exec cat '{}' \\\; &> /dev/null
10979
10980                 do_facet $facet find $facet_proc_dirs \
10981                         ! -name req_history \
10982                         -type f \
10983                         -exec cat '{}' \\\; &> /dev/null ||
10984                                 error "proc file read failed"
10985
10986                 do_facet $facet find $facet_proc_dirs \
10987                         -ignore_readdir_race \
10988                         -type f \
10989                         -not -name force_lbug \
10990                         -not -name changelog_mask \
10991                         -exec badarea_io '{}' \\\; ||
10992                                 error "$facet find $facet_proc_dirs failed"
10993         done
10994
10995         # remount the FS in case writes/reads /proc break the FS
10996         cleanup || error "failed to unmount"
10997         setup || error "failed to setup"
10998         true
10999 }
11000 run_test 133g "Check reads/writes of server lustre proc files with bad area io"
11001
11002 test_133h() {
11003         remote_mds_nodsh && skip "remote MDS with nodsh"
11004         remote_ost_nodsh && skip "remote OST with nodsh"
11005         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
11006                 skip "Need MDS version at least 2.9.54"
11007
11008         local facet
11009
11010         for facet in client mds1 ost1; do
11011                 local facet_proc_dirs=$(do_facet $facet \
11012                                         \\\ls -d $proc_regexp 2> /dev/null)
11013                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
11014                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
11015                 # Get the list of files that are missing the terminating newline
11016                 local missing=($(do_facet $facet \
11017                         find ${facet_proc_dirs} -type f \|              \
11018                                 while read F\; do                       \
11019                                         awk -v FS='\v' -v RS='\v\v'     \
11020                                         "'END { if(NR>0 &&              \
11021                                         \\\$NF !~ /.*\\\n\$/)           \
11022                                                 print FILENAME}'"       \
11023                                         '\$F'\;                         \
11024                                 done 2>/dev/null))
11025                 [ ${#missing[*]} -eq 0 ] ||
11026                         error "files do not end with newline: ${missing[*]}"
11027         done
11028 }
11029 run_test 133h "Proc files should end with newlines"
11030
11031 test_134a() {
11032         remote_mds_nodsh && skip "remote MDS with nodsh"
11033         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
11034                 skip "Need MDS version at least 2.7.54"
11035
11036         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
11037         cancel_lru_locks mdc
11038
11039         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
11040         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
11041         [ $unused -eq 0 ] || error "$unused locks are not cleared"
11042
11043         local nr=1000
11044         createmany -o $DIR/$tdir/f $nr ||
11045                 error "failed to create $nr files in $DIR/$tdir"
11046         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
11047
11048         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
11049         do_facet mds1 $LCTL set_param fail_loc=0x327
11050         do_facet mds1 $LCTL set_param fail_val=500
11051         touch $DIR/$tdir/m
11052
11053         echo "sleep 10 seconds ..."
11054         sleep 10
11055         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
11056
11057         do_facet mds1 $LCTL set_param fail_loc=0
11058         do_facet mds1 $LCTL set_param fail_val=0
11059         [ $lck_cnt -lt $unused ] ||
11060                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
11061
11062         rm $DIR/$tdir/m
11063         unlinkmany $DIR/$tdir/f $nr
11064 }
11065 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
11066
11067 test_134b() {
11068         remote_mds_nodsh && skip "remote MDS with nodsh"
11069         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
11070                 skip "Need MDS version at least 2.7.54"
11071
11072         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
11073         cancel_lru_locks mdc
11074
11075         local low_wm=$(do_facet mds1 $LCTL get_param -n \
11076                         ldlm.lock_reclaim_threshold_mb)
11077         # disable reclaim temporarily
11078         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
11079
11080         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
11081         do_facet mds1 $LCTL set_param fail_loc=0x328
11082         do_facet mds1 $LCTL set_param fail_val=500
11083
11084         $LCTL set_param debug=+trace
11085
11086         local nr=600
11087         createmany -o $DIR/$tdir/f $nr &
11088         local create_pid=$!
11089
11090         echo "Sleep $TIMEOUT seconds ..."
11091         sleep $TIMEOUT
11092         if ! ps -p $create_pid  > /dev/null 2>&1; then
11093                 do_facet mds1 $LCTL set_param fail_loc=0
11094                 do_facet mds1 $LCTL set_param fail_val=0
11095                 do_facet mds1 $LCTL set_param \
11096                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
11097                 error "createmany finished incorrectly!"
11098         fi
11099         do_facet mds1 $LCTL set_param fail_loc=0
11100         do_facet mds1 $LCTL set_param fail_val=0
11101         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
11102         wait $create_pid || return 1
11103
11104         unlinkmany $DIR/$tdir/f $nr
11105 }
11106 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
11107
11108 test_140() { #bug-17379
11109         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11110
11111         test_mkdir $DIR/$tdir
11112         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
11113         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
11114
11115         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
11116         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
11117         local i=0
11118         while i=$((i + 1)); do
11119                 test_mkdir $i
11120                 cd $i || error "Changing to $i"
11121                 ln -s ../stat stat || error "Creating stat symlink"
11122                 # Read the symlink until ELOOP present,
11123                 # not LBUGing the system is considered success,
11124                 # we didn't overrun the stack.
11125                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
11126                 if [ $ret -ne 0 ]; then
11127                         if [ $ret -eq 40 ]; then
11128                                 break  # -ELOOP
11129                         else
11130                                 error "Open stat symlink"
11131                                         return
11132                         fi
11133                 fi
11134         done
11135         i=$((i - 1))
11136         echo "The symlink depth = $i"
11137         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
11138                                         error "Invalid symlink depth"
11139
11140         # Test recursive symlink
11141         ln -s symlink_self symlink_self
11142         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
11143         echo "open symlink_self returns $ret"
11144         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
11145 }
11146 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
11147
11148 test_150() {
11149         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11150
11151         local TF="$TMP/$tfile"
11152
11153         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
11154         cp $TF $DIR/$tfile
11155         cancel_lru_locks $OSC
11156         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
11157         remount_client $MOUNT
11158         df -P $MOUNT
11159         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
11160
11161         $TRUNCATE $TF 6000
11162         $TRUNCATE $DIR/$tfile 6000
11163         cancel_lru_locks $OSC
11164         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
11165
11166         echo "12345" >>$TF
11167         echo "12345" >>$DIR/$tfile
11168         cancel_lru_locks $OSC
11169         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
11170
11171         echo "12345" >>$TF
11172         echo "12345" >>$DIR/$tfile
11173         cancel_lru_locks $OSC
11174         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
11175
11176         rm -f $TF
11177         true
11178 }
11179 run_test 150 "truncate/append tests"
11180
11181 #LU-2902 roc_hit was not able to read all values from lproc
11182 function roc_hit_init() {
11183         local list=$(comma_list $(osts_nodes))
11184         local dir=$DIR/$tdir-check
11185         local file=$dir/$tfile
11186         local BEFORE
11187         local AFTER
11188         local idx
11189
11190         test_mkdir $dir
11191         #use setstripe to do a write to every ost
11192         for i in $(seq 0 $((OSTCOUNT-1))); do
11193                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
11194                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
11195                 idx=$(printf %04x $i)
11196                 BEFORE=$(get_osd_param $list *OST*$idx stats |
11197                         awk '$1 == "cache_access" {sum += $7}
11198                                 END { printf("%0.0f", sum) }')
11199
11200                 cancel_lru_locks osc
11201                 cat $file >/dev/null
11202
11203                 AFTER=$(get_osd_param $list *OST*$idx stats |
11204                         awk '$1 == "cache_access" {sum += $7}
11205                                 END { printf("%0.0f", sum) }')
11206
11207                 echo BEFORE:$BEFORE AFTER:$AFTER
11208                 if ! let "AFTER - BEFORE == 4"; then
11209                         rm -rf $dir
11210                         error "roc_hit is not safe to use"
11211                 fi
11212                 rm $file
11213         done
11214
11215         rm -rf $dir
11216 }
11217
11218 function roc_hit() {
11219         local list=$(comma_list $(osts_nodes))
11220         echo $(get_osd_param $list '' stats |
11221                 awk '$1 == "cache_hit" {sum += $7}
11222                         END { printf("%0.0f", sum) }')
11223 }
11224
11225 function set_cache() {
11226         local on=1
11227
11228         if [ "$2" == "off" ]; then
11229                 on=0;
11230         fi
11231         local list=$(comma_list $(osts_nodes))
11232         set_osd_param $list '' $1_cache_enable $on
11233
11234         cancel_lru_locks osc
11235 }
11236
11237 test_151() {
11238         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11239         remote_ost_nodsh && skip "remote OST with nodsh"
11240
11241         local CPAGES=3
11242         local list=$(comma_list $(osts_nodes))
11243
11244         # check whether obdfilter is cache capable at all
11245         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
11246                 skip "not cache-capable obdfilter"
11247         fi
11248
11249         # check cache is enabled on all obdfilters
11250         if get_osd_param $list '' read_cache_enable | grep 0; then
11251                 skip "oss cache is disabled"
11252         fi
11253
11254         set_osd_param $list '' writethrough_cache_enable 1
11255
11256         # check write cache is enabled on all obdfilters
11257         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
11258                 skip "oss write cache is NOT enabled"
11259         fi
11260
11261         roc_hit_init
11262
11263         #define OBD_FAIL_OBD_NO_LRU  0x609
11264         do_nodes $list $LCTL set_param fail_loc=0x609
11265
11266         # pages should be in the case right after write
11267         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
11268                 error "dd failed"
11269
11270         local BEFORE=$(roc_hit)
11271         cancel_lru_locks osc
11272         cat $DIR/$tfile >/dev/null
11273         local AFTER=$(roc_hit)
11274
11275         do_nodes $list $LCTL set_param fail_loc=0
11276
11277         if ! let "AFTER - BEFORE == CPAGES"; then
11278                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11279         fi
11280
11281         # the following read invalidates the cache
11282         cancel_lru_locks osc
11283         set_osd_param $list '' read_cache_enable 0
11284         cat $DIR/$tfile >/dev/null
11285
11286         # now data shouldn't be found in the cache
11287         BEFORE=$(roc_hit)
11288         cancel_lru_locks osc
11289         cat $DIR/$tfile >/dev/null
11290         AFTER=$(roc_hit)
11291         if let "AFTER - BEFORE != 0"; then
11292                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11293         fi
11294
11295         set_osd_param $list '' read_cache_enable 1
11296         rm -f $DIR/$tfile
11297 }
11298 run_test 151 "test cache on oss and controls ==============================="
11299
11300 test_152() {
11301         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11302
11303         local TF="$TMP/$tfile"
11304
11305         # simulate ENOMEM during write
11306 #define OBD_FAIL_OST_NOMEM      0x226
11307         lctl set_param fail_loc=0x80000226
11308         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
11309         cp $TF $DIR/$tfile
11310         sync || error "sync failed"
11311         lctl set_param fail_loc=0
11312
11313         # discard client's cache
11314         cancel_lru_locks osc
11315
11316         # simulate ENOMEM during read
11317         lctl set_param fail_loc=0x80000226
11318         cmp $TF $DIR/$tfile || error "cmp failed"
11319         lctl set_param fail_loc=0
11320
11321         rm -f $TF
11322 }
11323 run_test 152 "test read/write with enomem ============================"
11324
11325 test_153() {
11326         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
11327 }
11328 run_test 153 "test if fdatasync does not crash ======================="
11329
11330 dot_lustre_fid_permission_check() {
11331         local fid=$1
11332         local ffid=$MOUNT/.lustre/fid/$fid
11333         local test_dir=$2
11334
11335         echo "stat fid $fid"
11336         stat $ffid > /dev/null || error "stat $ffid failed."
11337         echo "touch fid $fid"
11338         touch $ffid || error "touch $ffid failed."
11339         echo "write to fid $fid"
11340         cat /etc/hosts > $ffid || error "write $ffid failed."
11341         echo "read fid $fid"
11342         diff /etc/hosts $ffid || error "read $ffid failed."
11343         echo "append write to fid $fid"
11344         cat /etc/hosts >> $ffid || error "append write $ffid failed."
11345         echo "rename fid $fid"
11346         mv $ffid $test_dir/$tfile.1 &&
11347                 error "rename $ffid to $tfile.1 should fail."
11348         touch $test_dir/$tfile.1
11349         mv $test_dir/$tfile.1 $ffid &&
11350                 error "rename $tfile.1 to $ffid should fail."
11351         rm -f $test_dir/$tfile.1
11352         echo "truncate fid $fid"
11353         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
11354         echo "link fid $fid"
11355         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
11356         if [[ $($LCTL get_param -n mdc.*-mdc-*.connect_flags) =~ acl ]]; then
11357                 echo "setfacl fid $fid"
11358                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
11359                 echo "getfacl fid $fid"
11360                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
11361         fi
11362         echo "unlink fid $fid"
11363         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
11364         echo "mknod fid $fid"
11365         mknod $ffid c 1 3 && error "mknod $ffid should fail."
11366
11367         fid=[0xf00000400:0x1:0x0]
11368         ffid=$MOUNT/.lustre/fid/$fid
11369
11370         echo "stat non-exist fid $fid"
11371         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
11372         echo "write to non-exist fid $fid"
11373         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
11374         echo "link new fid $fid"
11375         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
11376
11377         mkdir -p $test_dir/$tdir
11378         touch $test_dir/$tdir/$tfile
11379         fid=$($LFS path2fid $test_dir/$tdir)
11380         rc=$?
11381         [ $rc -ne 0 ] &&
11382                 error "error: could not get fid for $test_dir/$dir/$tfile."
11383
11384         ffid=$MOUNT/.lustre/fid/$fid
11385
11386         echo "ls $fid"
11387         ls $ffid > /dev/null || error "ls $ffid failed."
11388         echo "touch $fid/$tfile.1"
11389         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
11390
11391         echo "touch $MOUNT/.lustre/fid/$tfile"
11392         touch $MOUNT/.lustre/fid/$tfile && \
11393                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
11394
11395         echo "setxattr to $MOUNT/.lustre/fid"
11396         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
11397
11398         echo "listxattr for $MOUNT/.lustre/fid"
11399         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
11400
11401         echo "delxattr from $MOUNT/.lustre/fid"
11402         setfattr -x trusted.name1 $MOUNT/.lustre/fid
11403
11404         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
11405         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
11406                 error "touch invalid fid should fail."
11407
11408         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
11409         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
11410                 error "touch non-normal fid should fail."
11411
11412         echo "rename $tdir to $MOUNT/.lustre/fid"
11413         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
11414                 error "rename to $MOUNT/.lustre/fid should fail."
11415
11416         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
11417         then            # LU-3547
11418                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
11419                 local new_obf_mode=777
11420
11421                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
11422                 chmod $new_obf_mode $DIR/.lustre/fid ||
11423                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
11424
11425                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
11426                 [ $obf_mode -eq $new_obf_mode ] ||
11427                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
11428
11429                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
11430                 chmod $old_obf_mode $DIR/.lustre/fid ||
11431                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
11432         fi
11433
11434         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
11435         fid=$($LFS path2fid $test_dir/$tfile-2)
11436
11437         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
11438         then # LU-5424
11439                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
11440                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
11441                         error "create lov data thru .lustre failed"
11442         fi
11443         echo "cp /etc/passwd $test_dir/$tfile-2"
11444         cp /etc/passwd $test_dir/$tfile-2 ||
11445                 error "copy to $test_dir/$tfile-2 failed."
11446         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
11447         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
11448                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
11449
11450         rm -rf $test_dir/tfile.lnk
11451         rm -rf $test_dir/$tfile-2
11452 }
11453
11454 test_154A() {
11455         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11456                 skip "Need MDS version at least 2.4.1"
11457
11458         local tf=$DIR/$tfile
11459         touch $tf
11460
11461         local fid=$($LFS path2fid $tf)
11462         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
11463
11464         # check that we get the same pathname back
11465         local found=$($LFS fid2path $MOUNT "$fid")
11466         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
11467         [ "$found" == "$tf" ] ||
11468                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
11469 }
11470 run_test 154A "lfs path2fid and fid2path basic checks"
11471
11472 test_154B() {
11473         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11474                 skip "Need MDS version at least 2.4.1"
11475
11476         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
11477         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
11478         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
11479         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
11480
11481         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
11482         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
11483
11484         # check that we get the same pathname
11485         echo "PFID: $PFID, name: $name"
11486         local FOUND=$($LFS fid2path $MOUNT "$PFID")
11487         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
11488         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
11489                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
11490
11491         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
11492 }
11493 run_test 154B "verify the ll_decode_linkea tool"
11494
11495 test_154a() {
11496         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11497         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
11498         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
11499                 skip "Need MDS version at least 2.2.51"
11500         [ -z "$(which setfacl)" ] && skip_env "must have setfacl tool"
11501
11502         cp /etc/hosts $DIR/$tfile
11503
11504         fid=$($LFS path2fid $DIR/$tfile)
11505         rc=$?
11506         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
11507
11508         dot_lustre_fid_permission_check "$fid" $DIR ||
11509                 error "dot lustre permission check $fid failed"
11510
11511         ls -a $MOUNT | grep "\.lustre" && error ".lustre should not be listed"
11512
11513         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
11514
11515         touch $MOUNT/.lustre/file &&
11516                 error "creation is not allowed under .lustre"
11517
11518         mkdir $MOUNT/.lustre/dir &&
11519                 error "mkdir is not allowed under .lustre"
11520
11521         rm -rf $DIR/$tfile
11522 }
11523 run_test 154a "Open-by-FID"
11524
11525 test_154b() {
11526         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11527         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
11528         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
11529         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
11530                 skip "Need MDS version at least 2.2.51"
11531
11532         local remote_dir=$DIR/$tdir/remote_dir
11533         local MDTIDX=1
11534         local rc=0
11535
11536         mkdir -p $DIR/$tdir
11537         $LFS mkdir -i $MDTIDX $remote_dir ||
11538                 error "create remote directory failed"
11539
11540         cp /etc/hosts $remote_dir/$tfile
11541
11542         fid=$($LFS path2fid $remote_dir/$tfile)
11543         rc=$?
11544         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
11545
11546         dot_lustre_fid_permission_check "$fid" $remote_dir ||
11547                 error "dot lustre permission check $fid failed"
11548         rm -rf $DIR/$tdir
11549 }
11550 run_test 154b "Open-by-FID for remote directory"
11551
11552 test_154c() {
11553         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11554                 skip "Need MDS version at least 2.4.1"
11555
11556         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
11557         local FID1=$($LFS path2fid $DIR/$tfile.1)
11558         local FID2=$($LFS path2fid $DIR/$tfile.2)
11559         local FID3=$($LFS path2fid $DIR/$tfile.3)
11560
11561         local N=1
11562         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
11563                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
11564                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
11565                 local want=FID$N
11566                 [ "$FID" = "${!want}" ] ||
11567                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
11568                 N=$((N + 1))
11569         done
11570
11571         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
11572         do
11573                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
11574                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
11575                 N=$((N + 1))
11576         done
11577 }
11578 run_test 154c "lfs path2fid and fid2path multiple arguments"
11579
11580 test_154d() {
11581         remote_mds_nodsh && skip "remote MDS with nodsh"
11582         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
11583                 skip "Need MDS version at least 2.5.53"
11584
11585         if remote_mds; then
11586                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
11587         else
11588                 nid="0@lo"
11589         fi
11590         local proc_ofile="mdt.*.exports.'$nid'.open_files"
11591         local fd
11592         local cmd
11593
11594         rm -f $DIR/$tfile
11595         touch $DIR/$tfile
11596
11597         local fid=$($LFS path2fid $DIR/$tfile)
11598         # Open the file
11599         fd=$(free_fd)
11600         cmd="exec $fd<$DIR/$tfile"
11601         eval $cmd
11602         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
11603         echo "$fid_list" | grep "$fid"
11604         rc=$?
11605
11606         cmd="exec $fd>/dev/null"
11607         eval $cmd
11608         if [ $rc -ne 0 ]; then
11609                 error "FID $fid not found in open files list $fid_list"
11610         fi
11611 }
11612 run_test 154d "Verify open file fid"
11613
11614 test_154e()
11615 {
11616         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
11617                 skip "Need MDS version at least 2.6.50"
11618
11619         if ls -a $MOUNT | grep -q '^\.lustre$'; then
11620                 error ".lustre returned by readdir"
11621         fi
11622 }
11623 run_test 154e ".lustre is not returned by readdir"
11624
11625 test_154f() {
11626         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
11627
11628         # create parent directory on a single MDT to avoid cross-MDT hardlinks
11629         test_mkdir -p -c1 $DIR/$tdir/d
11630         # test dirs inherit from its stripe
11631         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
11632         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
11633         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
11634         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
11635         touch $DIR/f
11636
11637         # get fid of parents
11638         local FID0=$($LFS path2fid $DIR/$tdir/d)
11639         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
11640         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
11641         local FID3=$($LFS path2fid $DIR)
11642
11643         # check that path2fid --parents returns expected <parent_fid>/name
11644         # 1) test for a directory (single parent)
11645         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
11646         [ "$parent" == "$FID0/foo1" ] ||
11647                 error "expected parent: $FID0/foo1, got: $parent"
11648
11649         # 2) test for a file with nlink > 1 (multiple parents)
11650         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
11651         echo "$parent" | grep -F "$FID1/$tfile" ||
11652                 error "$FID1/$tfile not returned in parent list"
11653         echo "$parent" | grep -F "$FID2/link" ||
11654                 error "$FID2/link not returned in parent list"
11655
11656         # 3) get parent by fid
11657         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
11658         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11659         echo "$parent" | grep -F "$FID1/$tfile" ||
11660                 error "$FID1/$tfile not returned in parent list (by fid)"
11661         echo "$parent" | grep -F "$FID2/link" ||
11662                 error "$FID2/link not returned in parent list (by fid)"
11663
11664         # 4) test for entry in root directory
11665         parent=$($LFS path2fid --parents $DIR/f)
11666         echo "$parent" | grep -F "$FID3/f" ||
11667                 error "$FID3/f not returned in parent list"
11668
11669         # 5) test it on root directory
11670         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
11671                 error "$MOUNT should not have parents"
11672
11673         # enable xattr caching and check that linkea is correctly updated
11674         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
11675         save_lustre_params client "llite.*.xattr_cache" > $save
11676         lctl set_param llite.*.xattr_cache 1
11677
11678         # 6.1) linkea update on rename
11679         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
11680
11681         # get parents by fid
11682         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11683         # foo1 should no longer be returned in parent list
11684         echo "$parent" | grep -F "$FID1" &&
11685                 error "$FID1 should no longer be in parent list"
11686         # the new path should appear
11687         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
11688                 error "$FID2/$tfile.moved is not in parent list"
11689
11690         # 6.2) linkea update on unlink
11691         rm -f $DIR/$tdir/d/foo2/link
11692         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11693         # foo2/link should no longer be returned in parent list
11694         echo "$parent" | grep -F "$FID2/link" &&
11695                 error "$FID2/link should no longer be in parent list"
11696         true
11697
11698         rm -f $DIR/f
11699         restore_lustre_params < $save
11700         rm -f $save
11701 }
11702 run_test 154f "get parent fids by reading link ea"
11703
11704 test_154g()
11705 {
11706         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
11707         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) && \
11708            $(lustre_version_code client) -gt $(version_code 2.6.99) ]] ||
11709                 skip "Need MDS version at least 2.6.92"
11710
11711         mkdir -p $DIR/$tdir
11712         llapi_fid_test -d $DIR/$tdir
11713 }
11714 run_test 154g "various llapi FID tests"
11715
11716 test_155_small_load() {
11717     local temp=$TMP/$tfile
11718     local file=$DIR/$tfile
11719
11720     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
11721         error "dd of=$temp bs=6096 count=1 failed"
11722     cp $temp $file
11723     cancel_lru_locks $OSC
11724     cmp $temp $file || error "$temp $file differ"
11725
11726     $TRUNCATE $temp 6000
11727     $TRUNCATE $file 6000
11728     cmp $temp $file || error "$temp $file differ (truncate1)"
11729
11730     echo "12345" >>$temp
11731     echo "12345" >>$file
11732     cmp $temp $file || error "$temp $file differ (append1)"
11733
11734     echo "12345" >>$temp
11735     echo "12345" >>$file
11736     cmp $temp $file || error "$temp $file differ (append2)"
11737
11738     rm -f $temp $file
11739     true
11740 }
11741
11742 test_155_big_load() {
11743         remote_ost_nodsh && skip "remote OST with nodsh"
11744
11745         local temp=$TMP/$tfile
11746         local file=$DIR/$tfile
11747
11748         free_min_max
11749         local cache_size=$(do_facet ost$((MAXI+1)) \
11750                 "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
11751         local large_file_size=$((cache_size * 2))
11752
11753         echo "OSS cache size: $cache_size KB"
11754         echo "Large file size: $large_file_size KB"
11755
11756         [ $MAXV -le $large_file_size ] &&
11757                 skip_env "max available OST size needs > $large_file_size KB"
11758
11759         $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
11760
11761         dd if=/dev/urandom of=$temp bs=$large_file_size count=1k ||
11762                 error "dd of=$temp bs=$large_file_size count=1k failed"
11763         cp $temp $file
11764         ls -lh $temp $file
11765         cancel_lru_locks osc
11766         cmp $temp $file || error "$temp $file differ"
11767
11768         rm -f $temp $file
11769         true
11770 }
11771
11772 save_writethrough() {
11773         local facets=$(get_facets OST)
11774
11775         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
11776         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
11777 }
11778
11779 test_155a() {
11780         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11781
11782         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11783
11784         save_writethrough $p
11785
11786         set_cache read on
11787         set_cache writethrough on
11788         test_155_small_load
11789         restore_lustre_params < $p
11790         rm -f $p
11791 }
11792 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
11793
11794 test_155b() {
11795         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11796
11797         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11798
11799         save_writethrough $p
11800
11801         set_cache read on
11802         set_cache writethrough off
11803         test_155_small_load
11804         restore_lustre_params < $p
11805         rm -f $p
11806 }
11807 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
11808
11809 test_155c() {
11810         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11811
11812         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11813
11814         save_writethrough $p
11815
11816         set_cache read off
11817         set_cache writethrough on
11818         test_155_small_load
11819         restore_lustre_params < $p
11820         rm -f $p
11821 }
11822 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
11823
11824 test_155d() {
11825         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11826
11827         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11828
11829         save_writethrough $p
11830
11831         set_cache read off
11832         set_cache writethrough off
11833         test_155_small_load
11834         restore_lustre_params < $p
11835         rm -f $p
11836 }
11837 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
11838
11839 test_155e() {
11840         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11841
11842         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11843
11844         save_writethrough $p
11845
11846         set_cache read on
11847         set_cache writethrough on
11848         test_155_big_load
11849         restore_lustre_params < $p
11850         rm -f $p
11851 }
11852 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
11853
11854 test_155f() {
11855         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11856
11857         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11858
11859         save_writethrough $p
11860
11861         set_cache read on
11862         set_cache writethrough off
11863         test_155_big_load
11864         restore_lustre_params < $p
11865         rm -f $p
11866 }
11867 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
11868
11869 test_155g() {
11870         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11871
11872         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11873
11874         save_writethrough $p
11875
11876         set_cache read off
11877         set_cache writethrough on
11878         test_155_big_load
11879         restore_lustre_params < $p
11880         rm -f $p
11881 }
11882 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
11883
11884 test_155h() {
11885         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11886
11887         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11888
11889         save_writethrough $p
11890
11891         set_cache read off
11892         set_cache writethrough off
11893         test_155_big_load
11894         restore_lustre_params < $p
11895         rm -f $p
11896 }
11897 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
11898
11899 test_156() {
11900         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11901         remote_ost_nodsh && skip "remote OST with nodsh"
11902         [ "$(facet_fstype ost1)" = "zfs" -a \
11903            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
11904                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS"
11905
11906         local CPAGES=3
11907         local BEFORE
11908         local AFTER
11909         local file="$DIR/$tfile"
11910         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11911
11912         save_writethrough $p
11913         roc_hit_init
11914
11915         log "Turn on read and write cache"
11916         set_cache read on
11917         set_cache writethrough on
11918
11919         log "Write data and read it back."
11920         log "Read should be satisfied from the cache."
11921         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11922         BEFORE=$(roc_hit)
11923         cancel_lru_locks osc
11924         cat $file >/dev/null
11925         AFTER=$(roc_hit)
11926         if ! let "AFTER - BEFORE == CPAGES"; then
11927                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11928         else
11929                 log "cache hits:: before: $BEFORE, after: $AFTER"
11930         fi
11931
11932         log "Read again; it should be satisfied from the cache."
11933         BEFORE=$AFTER
11934         cancel_lru_locks osc
11935         cat $file >/dev/null
11936         AFTER=$(roc_hit)
11937         if ! let "AFTER - BEFORE == CPAGES"; then
11938                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11939         else
11940                 log "cache hits:: before: $BEFORE, after: $AFTER"
11941         fi
11942
11943         log "Turn off the read cache and turn on the write cache"
11944         set_cache read off
11945         set_cache writethrough on
11946
11947         log "Read again; it should be satisfied from the cache."
11948         BEFORE=$(roc_hit)
11949         cancel_lru_locks osc
11950         cat $file >/dev/null
11951         AFTER=$(roc_hit)
11952         if ! let "AFTER - BEFORE == CPAGES"; then
11953                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11954         else
11955                 log "cache hits:: before: $BEFORE, after: $AFTER"
11956         fi
11957
11958         log "Read again; it should not be satisfied from the cache."
11959         BEFORE=$AFTER
11960         cancel_lru_locks osc
11961         cat $file >/dev/null
11962         AFTER=$(roc_hit)
11963         if ! let "AFTER - BEFORE == 0"; then
11964                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11965         else
11966                 log "cache hits:: before: $BEFORE, after: $AFTER"
11967         fi
11968
11969         log "Write data and read it back."
11970         log "Read should be satisfied from the cache."
11971         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11972         BEFORE=$(roc_hit)
11973         cancel_lru_locks osc
11974         cat $file >/dev/null
11975         AFTER=$(roc_hit)
11976         if ! let "AFTER - BEFORE == CPAGES"; then
11977                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11978         else
11979                 log "cache hits:: before: $BEFORE, after: $AFTER"
11980         fi
11981
11982         log "Read again; it should not be satisfied from the cache."
11983         BEFORE=$AFTER
11984         cancel_lru_locks osc
11985         cat $file >/dev/null
11986         AFTER=$(roc_hit)
11987         if ! let "AFTER - BEFORE == 0"; then
11988                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11989         else
11990                 log "cache hits:: before: $BEFORE, after: $AFTER"
11991         fi
11992
11993         log "Turn off read and write cache"
11994         set_cache read off
11995         set_cache writethrough off
11996
11997         log "Write data and read it back"
11998         log "It should not be satisfied from the cache."
11999         rm -f $file
12000         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
12001         cancel_lru_locks osc
12002         BEFORE=$(roc_hit)
12003         cat $file >/dev/null
12004         AFTER=$(roc_hit)
12005         if ! let "AFTER - BEFORE == 0"; then
12006                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
12007         else
12008                 log "cache hits:: before: $BEFORE, after: $AFTER"
12009         fi
12010
12011         log "Turn on the read cache and turn off the write cache"
12012         set_cache read on
12013         set_cache writethrough off
12014
12015         log "Write data and read it back"
12016         log "It should not be satisfied from the cache."
12017         rm -f $file
12018         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
12019         BEFORE=$(roc_hit)
12020         cancel_lru_locks osc
12021         cat $file >/dev/null
12022         AFTER=$(roc_hit)
12023         if ! let "AFTER - BEFORE == 0"; then
12024                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
12025         else
12026                 log "cache hits:: before: $BEFORE, after: $AFTER"
12027         fi
12028
12029         log "Read again; it should be satisfied from the cache."
12030         BEFORE=$(roc_hit)
12031         cancel_lru_locks osc
12032         cat $file >/dev/null
12033         AFTER=$(roc_hit)
12034         if ! let "AFTER - BEFORE == CPAGES"; then
12035                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
12036         else
12037                 log "cache hits:: before: $BEFORE, after: $AFTER"
12038         fi
12039
12040         restore_lustre_params < $p
12041         rm -f $p $file
12042 }
12043 run_test 156 "Verification of tunables"
12044
12045 test_160a() {
12046         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12047         remote_mds_nodsh && skip "remote MDS with nodsh"
12048         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
12049                 skip "Need MDS version at least 2.2.0"
12050
12051         changelog_register || error "changelog_register failed"
12052         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
12053         changelog_users $SINGLEMDS | grep -q $cl_user ||
12054                 error "User $cl_user not found in changelog_users"
12055
12056         # change something
12057         test_mkdir -p $DIR/$tdir/pics/2008/zachy
12058         changelog_clear 0 || error "changelog_clear failed"
12059         touch $DIR/$tdir/pics/2008/zachy/$tfile                 # open 1
12060         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg       # open 2
12061         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
12062         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
12063         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
12064         rm $DIR/$tdir/pics/desktop.jpg
12065
12066         changelog_dump | tail -10
12067
12068         echo "verifying changelog mask"
12069         changelog_chmask "-MKDIR"
12070         changelog_chmask "-CLOSE"
12071
12072         test_mkdir -p $DIR/$tdir/pics/zach/sofia                # not logged
12073         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # not logged
12074
12075         changelog_chmask "+MKDIR"
12076         changelog_chmask "+CLOSE"
12077
12078         test_mkdir -p $DIR/$tdir/pics/2008/sofia                # mkdir 1
12079         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # open 3
12080
12081         changelog_dump | tail -10
12082         MKDIRS=$(changelog_dump | grep -c "MKDIR")
12083         CLOSES=$(changelog_dump | grep -c "CLOSE")
12084         [ $MKDIRS -eq 1 ] || error "MKDIR changelog mask count $MKDIRS != 1"
12085         [ $CLOSES -eq 3 ] || error "CLOSE changelog mask count $CLOSES != 3"
12086
12087         # verify contents
12088         echo "verifying target fid"
12089         local fidc=$(changelog_extract_field "CREAT" "$tfile" "t=")
12090         local fidf=$($LFS path2fid $DIR/$tdir/pics/zach/$tfile)
12091         [ "$fidc" == "$fidf" ] ||
12092                 error "changelog '$tfile' fid $fidc != file fid $fidf"
12093         echo "verifying parent fid"
12094         # The FID returned from the Changelog may be the directory shard on
12095         # a different MDT, and not the FID returned by path2fid on the parent.
12096         # Instead of comparing FIDs, verify that fid2path(fidp) is correct,
12097         # since this is what will matter when recreating this file in the tree.
12098         local fidp=$(changelog_extract_field "CREAT" "$tfile" "p=")
12099         local pathp=$($LFS fid2path $MOUNT "$fidp")
12100         [ "${pathp%/}" == "$DIR/$tdir/pics/zach" ] ||
12101                 error "changelog fid2path($fidc) $pathp != $DIR/$tdir/pics/zach"
12102
12103         echo "getting records for $cl_user"
12104         changelog_users $SINGLEMDS
12105         local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user)
12106         local nclr=3
12107         __changelog_clear $SINGLEMDS $cl_user +$nclr ||
12108                 error "changelog_clear failed"
12109         local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user)
12110         echo "verifying user clear: $user_rec1 + $nclr == $user_rec2"
12111         [ $user_rec2 == $((user_rec1 + nclr)) ] ||
12112                 error "user index expect $user_rec1 + $nclr != $user_rec2"
12113
12114         local min0_rec=$(changelog_users $SINGLEMDS |
12115                 awk 'min == "" || $2 < min { min = $2 }; END { print min }')
12116         local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
12117                           awk '{ print $1; exit; }')
12118
12119         changelog_dump | tail -n 5
12120         echo "verifying user min purge: $min0_rec + 1 == $first_rec"
12121         [ $first_rec == $((min0_rec + 1)) ] ||
12122                 error "first index should be $min0_rec + 1 not $first_rec"
12123
12124         # LU-3446 changelog index reset on MDT restart
12125         local cur_rec1=$(changelog_users $SINGLEMDS |
12126                          awk '/^current.index:/ { print $NF }')
12127         changelog_clear 0 ||
12128                 error "clear all changelog records for $cl_user failed"
12129         stop $SINGLEMDS || error "Fail to stop $SINGLEMDS"
12130         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
12131                 error "Fail to start $SINGLEMDS"
12132         local cur_rec2=$(changelog_users $SINGLEMDS |
12133                          awk '/^current.index:/ { print $NF }')
12134         echo "verifying index survives MDT restart: $cur_rec1 == $cur_rec2"
12135         [ $cur_rec1 == $cur_rec2 ] ||
12136                 error "current index should be $cur_rec1 not $cur_rec2"
12137
12138         echo "verifying users from this test are deregistered"
12139         changelog_deregister || error "changelog_deregister failed"
12140         changelog_users $SINGLEMDS | grep -q $cl_user &&
12141                 error "User '$cl_user' still in changelog_users"
12142
12143         # lctl get_param -n mdd.*.changelog_users
12144         # current index: 144
12145         # ID    index (idle seconds)
12146         # cl3   144 (2)
12147         if ! changelog_users $SINGLEMDS | grep "^cl"; then
12148                 # this is the normal case where all users were deregistered
12149                 # make sure no new records are added when no users are present
12150                 local last_rec1=$(changelog_users $SINGLEMDS |
12151                                   awk '/^current.index:/ { print $NF }')
12152                 touch $DIR/$tdir/chloe
12153                 local last_rec2=$(changelog_users $SINGLEMDS |
12154                                   awk '/^current.index:/ { print $NF }')
12155                 echo "verify changelogs are off: $last_rec1 == $last_rec2"
12156                 [ $last_rec1 == $last_rec2 ] || error "changelogs not off"
12157         else
12158                 # any changelog users must be leftovers from a previous test
12159                 changelog_users $SINGLEMDS
12160                 echo "other changelog users; can't verify off"
12161         fi
12162 }
12163 run_test 160a "changelog sanity"
12164
12165 test_160b() { # LU-3587
12166         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12167         remote_mds_nodsh && skip "remote MDS with nodsh"
12168         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
12169                 skip "Need MDS version at least 2.2.0"
12170
12171         changelog_register || error "changelog_register failed"
12172         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
12173         changelog_users $SINGLEMDS | grep -q $cl_user ||
12174                 error "User '$cl_user' not found in changelog_users"
12175
12176         local longname1=$(str_repeat a 255)
12177         local longname2=$(str_repeat b 255)
12178
12179         cd $DIR
12180         echo "creating very long named file"
12181         touch $longname1 || error "create of '$longname1' failed"
12182         echo "renaming very long named file"
12183         mv $longname1 $longname2
12184
12185         changelog_dump | grep RENME | tail -n 5
12186         rm -f $longname2
12187 }
12188 run_test 160b "Verify that very long rename doesn't crash in changelog"
12189
12190 test_160c() {
12191         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12192         remote_mds_nodsh && skip "remote MDS with nodsh"
12193
12194         local rc=0
12195         local server_version=$(lustre_version_code $SINGLEMDS)
12196
12197         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12198                 [[ $server_version -gt $(version_code 2.5.1) &&
12199                    $server_version -lt $(version_code 2.5.50) ]] ||
12200                 skip "Need MDS version at least 2.5.58 or 2.5.2+"
12201
12202         # Registration step
12203         changelog_register || error "changelog_register failed"
12204
12205         rm -rf $DIR/$tdir
12206         mkdir -p $DIR/$tdir
12207         $MCREATE $DIR/$tdir/foo_160c
12208         changelog_chmask "-TRUNC"
12209         $TRUNCATE $DIR/$tdir/foo_160c 200
12210         changelog_chmask "+TRUNC"
12211         $TRUNCATE $DIR/$tdir/foo_160c 199
12212         changelog_dump | tail -n 5
12213         local truncs=$(changelog_dump | tail -n 5 | grep -c TRUNC)
12214         [ $truncs -eq 1 ] || error "TRUNC changelog mask count $truncs != 1"
12215 }
12216 run_test 160c "verify that changelog log catch the truncate event"
12217
12218 test_160d() {
12219         remote_mds_nodsh && skip "remote MDS with nodsh"
12220         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
12221         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12222         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.60) ]] ||
12223                 skip "Need MDS version at least 2.7.60"
12224
12225         # Registration step
12226         changelog_register || error "changelog_register failed"
12227
12228         mkdir -p $DIR/$tdir/migrate_dir
12229         changelog_clear 0 || error "changelog_clear failed"
12230
12231         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
12232         changelog_dump | tail -n 5
12233         local migrates=$(changelog_dump | grep -c "MIGRT")
12234         [ $migrates -eq 1 ] || error "MIGRATE changelog count $migrates != 1"
12235 }
12236 run_test 160d "verify that changelog log catch the migrate event"
12237
12238 test_160e() {
12239         remote_mds_nodsh && skip "remote MDS with nodsh"
12240
12241         # Create a user
12242         changelog_register || error "changelog_register failed"
12243
12244         # Delete a future user (expect fail)
12245         local MDT0=$(facet_svc $SINGLEMDS)
12246         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister "cl77"
12247         local rc=$?
12248
12249         if [ $rc -eq 0 ]; then
12250                 error "Deleted non-existant user cl77"
12251         elif [ $rc -ne 2 ]; then
12252                 error "changelog_deregister failed with $rc, expect 2 (ENOENT)"
12253         fi
12254
12255         # Clear to a bad index (1 billion should be safe)
12256         $LFS changelog_clear $MDT0 "${CL_USERS[$SINGLEMDS]%% *}" 1000000000
12257         rc=$?
12258
12259         if [ $rc -eq 0 ]; then
12260                 error "Successfully cleared to invalid CL index"
12261         elif [ $rc -ne 22 ]; then
12262                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
12263         fi
12264 }
12265 run_test 160e "changelog negative testing (should return errors)"
12266
12267 test_160f() {
12268         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12269         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
12270                 { skip "Need MDS version at least 2.10.56"; return 0; }
12271
12272         local mdts=$(comma_list $(mdts_nodes))
12273
12274         # Create a user
12275         changelog_register || error "first changelog_register failed"
12276         changelog_register || error "second changelog_register failed"
12277         local cl_users
12278         declare -A cl_user1
12279         declare -A cl_user2
12280         local user_rec1
12281         local user_rec2
12282         local i
12283
12284         # generate some changelog records to accumulate on each MDT
12285         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "test_mkdir $tdir failed"
12286         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12287                 error "create $DIR/$tdir/$tfile failed"
12288
12289         # check changelogs have been generated
12290         local nbcl=$(changelog_dump | wc -l)
12291         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12292
12293         for param in "changelog_max_idle_time=10" \
12294                      "changelog_gc=1" \
12295                      "changelog_min_gc_interval=2" \
12296                      "changelog_min_free_cat_entries=3"; do
12297                 local MDT0=$(facet_svc $SINGLEMDS)
12298                 local var="${param%=*}"
12299                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
12300
12301                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
12302                 do_nodes $mdts $LCTL set_param mdd.*.$param
12303         done
12304
12305         # force cl_user2 to be idle (1st part)
12306         sleep 9
12307
12308         # simulate changelog catalog almost full
12309         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
12310         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
12311
12312         for i in $(seq $MDSCOUNT); do
12313                 cl_users=(${CL_USERS[mds$i]})
12314                 cl_user1[mds$i]="${cl_users[0]}"
12315                 cl_user2[mds$i]="${cl_users[1]}"
12316
12317                 [ -n "${cl_user1[mds$i]}" ] ||
12318                         error "mds$i: no user registered"
12319                 [ -n "${cl_user2[mds$i]}" ] ||
12320                         error "mds$i: only ${cl_user2[mds$i]} is registered"
12321
12322                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12323                 [ -n "$user_rec1" ] ||
12324                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12325                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
12326                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12327                 [ -n "$user_rec2" ] ||
12328                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12329                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
12330                      "$user_rec1 + 2 == $user_rec2"
12331                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
12332                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
12333                               "$user_rec1 + 2, but is $user_rec2"
12334                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
12335                 [ -n "$user_rec2" ] ||
12336                         error "mds$i: User ${cl_user2[mds$i]} not registered"
12337                 [ $user_rec1 == $user_rec2 ] ||
12338                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
12339                               "$user_rec1, but is $user_rec2"
12340         done
12341
12342         # force cl_user2 to be idle (2nd part) and to reach
12343         # changelog_max_idle_time
12344         sleep 2
12345
12346         # generate one more changelog to trigger fail_loc
12347         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
12348                 error "create $DIR/$tdir/${tfile}bis failed"
12349
12350         # ensure gc thread is done
12351         for i in $(mdts_nodes); do
12352                 wait_update $i \
12353                         "ps -e -o comm= | grep chlg_gc_thread" "" 20 ||
12354                         error "$i: GC-thread not done"
12355         done
12356
12357         local first_rec
12358         for i in $(seq $MDSCOUNT); do
12359                 # check cl_user1 still registered
12360                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
12361                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12362                 # check cl_user2 unregistered
12363                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
12364                         error "mds$i: User ${cl_user2[mds$i]} still registered"
12365
12366                 # check changelogs are present and starting at $user_rec1 + 1
12367                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12368                 [ -n "$user_rec1" ] ||
12369                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12370                 first_rec=$($LFS changelog $(facet_svc mds$i) |
12371                             awk '{ print $1; exit; }')
12372
12373                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
12374                 [ $((user_rec1 + 1)) == $first_rec ] ||
12375                         error "mds$i: first index should be $user_rec1 + 1, " \
12376                               "but is $first_rec"
12377         done
12378 }
12379 run_test 160f "changelog garbage collect (timestamped users)"
12380
12381 test_160g() {
12382         remote_mds_nodsh && skip "remote MDS with nodsh"
12383         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
12384                 skip "Need MDS version at least 2.10.56"
12385
12386         local mdts=$(comma_list $(mdts_nodes))
12387
12388         #define OBD_FAIL_TIME_IN_CHLOG_USER     0x1314
12389         do_nodes $mdts $LCTL set_param fail_loc=0x1314
12390
12391         # Create a user
12392         changelog_register || error "first changelog_register failed"
12393         changelog_register || error "second changelog_register failed"
12394         local cl_users
12395         declare -A cl_user1
12396         declare -A cl_user2
12397         local user_rec1
12398         local user_rec2
12399         local i
12400
12401         # generate some changelog records to accumulate on each MDT
12402         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
12403         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12404                 error "create $DIR/$tdir/$tfile failed"
12405
12406         # check changelogs have been generated
12407         local nbcl=$(changelog_dump | wc -l)
12408         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12409
12410         for param in "changelog_max_idle_indexes=$((nbcl / 2))" \
12411                      "changelog_gc=1" \
12412                      "changelog_min_gc_interval=2" \
12413                      "changelog_min_free_cat_entries=3"; do
12414                 local MDT0=$(facet_svc $SINGLEMDS)
12415                 local var="${param%=*}"
12416                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
12417
12418                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
12419                 do_nodes $mdts $LCTL set_param mdd.*.$param ||
12420                         error "unable to set mdd.*.$param"
12421         done
12422
12423         # simulate changelog catalog almost full
12424         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
12425         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
12426
12427         for i in $(seq $MDSCOUNT); do
12428                 cl_users=(${CL_USERS[mds$i]})
12429                 cl_user1[mds$i]="${cl_users[0]}"
12430                 cl_user2[mds$i]="${cl_users[1]}"
12431
12432                 [ -n "${cl_user1[mds$i]}" ] ||
12433                         error "mds$i: no user registered"
12434                 [ -n "${cl_user2[mds$i]}" ] ||
12435                         error "mds$i: only ${cl_user1[mds$i]} is registered"
12436
12437                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12438                 [ -n "$user_rec1" ] ||
12439                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12440                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
12441                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12442                 [ -n "$user_rec2" ] ||
12443                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12444                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
12445                      "$user_rec1 + 2 == $user_rec2"
12446                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
12447                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
12448                               "$user_rec1 + 2, but is $user_rec2"
12449                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
12450                 [ -n "$user_rec2" ] ||
12451                         error "mds$i: User ${cl_user2[mds$i]} not registered"
12452                 [ $user_rec1 == $user_rec2 ] ||
12453                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
12454                               "$user_rec1, but is $user_rec2"
12455         done
12456
12457         # ensure we are past the previous changelog_min_gc_interval set above
12458         sleep 2
12459
12460         # generate one more changelog to trigger fail_loc
12461         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
12462                 error "create $DIR/$tdir/${tfile}bis failed"
12463
12464         # ensure gc thread is done
12465         for i in $(mdts_nodes); do
12466                 wait_update $i \
12467                         "ps -e -o comm= | grep chlg_gc_thread" "" 20 ||
12468                         error "$i: GC-thread not done"
12469         done
12470
12471         local first_rec
12472         for i in $(seq $MDSCOUNT); do
12473                 # check cl_user1 still registered
12474                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
12475                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12476                 # check cl_user2 unregistered
12477                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
12478                         error "mds$i: User ${cl_user2[mds$i]} still registered"
12479
12480                 # check changelogs are present and starting at $user_rec1 + 1
12481                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12482                 [ -n "$user_rec1" ] ||
12483                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12484                 first_rec=$($LFS changelog $(facet_svc mds$i) |
12485                             awk '{ print $1; exit; }')
12486
12487                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
12488                 [ $((user_rec1 + 1)) == $first_rec ] ||
12489                         error "mds$i: first index should be $user_rec1 + 1, " \
12490                               "but is $first_rec"
12491         done
12492 }
12493 run_test 160g "changelog garbage collect (old users)"
12494
12495 test_160h() {
12496         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12497         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
12498                 { skip "Need MDS version at least 2.10.56"; return 0; }
12499
12500         local mdts=$(comma_list $(mdts_nodes))
12501
12502         # Create a user
12503         changelog_register || error "first changelog_register failed"
12504         changelog_register || error "second changelog_register failed"
12505         local cl_users
12506         declare -A cl_user1
12507         declare -A cl_user2
12508         local user_rec1
12509         local user_rec2
12510         local i
12511
12512         # generate some changelog records to accumulate on each MDT
12513         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "test_mkdir $tdir failed"
12514         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12515                 error "create $DIR/$tdir/$tfile failed"
12516
12517         # check changelogs have been generated
12518         local nbcl=$(changelog_dump | wc -l)
12519         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12520
12521         for param in "changelog_max_idle_time=10" \
12522                      "changelog_gc=1" \
12523                      "changelog_min_gc_interval=2"; do
12524                 local MDT0=$(facet_svc $SINGLEMDS)
12525                 local var="${param%=*}"
12526                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
12527
12528                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
12529                 do_nodes $mdts $LCTL set_param mdd.*.$param
12530         done
12531
12532         # force cl_user2 to be idle (1st part)
12533         sleep 9
12534
12535         for i in $(seq $MDSCOUNT); do
12536                 cl_users=(${CL_USERS[mds$i]})
12537                 cl_user1[mds$i]="${cl_users[0]}"
12538                 cl_user2[mds$i]="${cl_users[1]}"
12539
12540                 [ -n "${cl_user1[mds$i]}" ] ||
12541                         error "mds$i: no user registered"
12542                 [ -n "${cl_user2[mds$i]}" ] ||
12543                         error "mds$i: only ${cl_user2[mds$i]} is registered"
12544
12545                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12546                 [ -n "$user_rec1" ] ||
12547                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12548                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
12549                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12550                 [ -n "$user_rec2" ] ||
12551                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12552                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
12553                      "$user_rec1 + 2 == $user_rec2"
12554                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
12555                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
12556                               "$user_rec1 + 2, but is $user_rec2"
12557                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
12558                 [ -n "$user_rec2" ] ||
12559                         error "mds$i: User ${cl_user2[mds$i]} not registered"
12560                 [ $user_rec1 == $user_rec2 ] ||
12561                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
12562                               "$user_rec1, but is $user_rec2"
12563         done
12564
12565         # force cl_user2 to be idle (2nd part) and to reach
12566         # changelog_max_idle_time
12567         sleep 2
12568
12569         # force each GC-thread start and block then
12570         # one per MDT/MDD, set fail_val accordingly
12571         #define OBD_FAIL_FORCE_GC_THREAD 0x1316
12572         do_nodes $mdts $LCTL set_param fail_loc=0x1316
12573
12574         # generate more changelogs to trigger fail_loc
12575         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
12576                 error "create $DIR/$tdir/${tfile}bis failed"
12577
12578         # stop MDT to stop GC-thread, should be done in back-ground as it will
12579         # block waiting for the thread to be released and exit
12580         declare -A stop_pids
12581         for i in $(seq $MDSCOUNT); do
12582                 stop mds$i &
12583                 stop_pids[mds$i]=$!
12584         done
12585
12586         for i in $(mdts_nodes); do
12587                 local facet
12588                 local nb=0
12589                 local facets=$(facets_up_on_host $i)
12590
12591                 for facet in ${facets//,/ }; do
12592                         if [[ $facet == mds* ]]; then
12593                                 nb=$((nb + 1))
12594                         fi
12595                 done
12596                 # ensure each MDS's gc threads are still present and all in "R"
12597                 # state (OBD_FAIL_FORCE_GC_THREAD effect!)
12598                 [[ $(do_node $i pgrep chlg_gc_thread | wc -l) -eq $nb ]] ||
12599                         error "$i: expected $nb GC-thread"
12600                 wait_update $i \
12601                         "ps -C chlg_gc_thread -o state --no-headers | uniq" \
12602                         "R" 20 ||
12603                         error "$i: GC-thread not found in R-state"
12604                 # check umounts of each MDT on MDS have reached kthread_stop()
12605                 [[ $(do_node $i pgrep umount | wc -l) -eq $nb ]] ||
12606                         error "$i: expected $nb umount"
12607                 wait_update $i \
12608                         "ps -C umount -o state --no-headers | uniq" "D" 20 ||
12609                         error "$i: umount not found in D-state"
12610         done
12611
12612         # release all GC-threads
12613         do_nodes $mdts $LCTL set_param fail_loc=0
12614
12615         # wait for MDT stop to complete
12616         for i in $(seq $MDSCOUNT); do
12617                 wait ${stop_pids[mds$i]} || error "mds$i: stop failed"
12618         done
12619
12620         # XXX
12621         # may try to check if any orphan changelog records are present
12622         # via ldiskfs/zfs and llog_reader...
12623
12624         # re-start/mount MDTs
12625         for i in $(seq $MDSCOUNT); do
12626                 start mds$i $(mdsdevname $i) $MDS_MOUNT_OPTS ||
12627                         error "Fail to start mds$i"
12628         done
12629
12630         local first_rec
12631         for i in $(seq $MDSCOUNT); do
12632                 # check cl_user1 still registered
12633                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
12634                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12635                 # check cl_user2 unregistered
12636                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
12637                         error "mds$i: User ${cl_user2[mds$i]} still registered"
12638
12639                 # check changelogs are present and starting at $user_rec1 + 1
12640                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
12641                 [ -n "$user_rec1" ] ||
12642                         error "mds$i: User ${cl_user1[mds$i]} not registered"
12643                 first_rec=$($LFS changelog $(facet_svc mds$i) |
12644                             awk '{ print $1; exit; }')
12645
12646                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
12647                 [ $((user_rec1 + 1)) == $first_rec ] ||
12648                         error "mds$i: first index should be $user_rec1 + 1, " \
12649                               "but is $first_rec"
12650         done
12651 }
12652 run_test 160h "changelog gc thread stop upon umount, orphan records delete " \
12653               "during mount"
12654
12655 test_160i() {
12656
12657         local mdts=$(comma_list $(mdts_nodes))
12658
12659         changelog_register || error "first changelog_register failed"
12660
12661         # generate some changelog records to accumulate on each MDT
12662         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
12663         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12664                 error "create $DIR/$tdir/$tfile failed"
12665
12666         # check changelogs have been generated
12667         local nbcl=$(changelog_dump | wc -l)
12668         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12669
12670         # simulate race between register and unregister
12671         # XXX as fail_loc is set per-MDS, with DNE configs the race
12672         # simulation will only occur for one MDT per MDS and for the
12673         # others the normal race scenario will take place
12674         #define CFS_FAIL_CHLOG_USER_REG_UNREG_RACE          0x1315
12675         do_nodes $mdts $LCTL set_param fail_loc=0x10001315
12676         do_nodes $mdts $LCTL set_param fail_val=1
12677
12678         # unregister 1st user
12679         changelog_deregister &
12680         local pid1=$!
12681         # wait some time for deregister work to reach race rdv
12682         sleep 2
12683         # register 2nd user
12684         changelog_register || error "2nd user register failed"
12685
12686         wait $pid1 || error "1st user deregister failed"
12687
12688         local i
12689         local last_rec
12690         declare -A LAST_REC
12691         for i in $(seq $MDSCOUNT); do
12692                 if changelog_users mds$i | grep "^cl"; then
12693                         # make sure new records are added with one user present
12694                         LAST_REC[mds$i]=$(changelog_users $SINGLEMDS |
12695                                           awk '/^current.index:/ { print $NF }')
12696                 else
12697                         error "mds$i has no user registered"
12698                 fi
12699         done
12700
12701         # generate more changelog records to accumulate on each MDT
12702         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
12703                 error "create $DIR/$tdir/${tfile}bis failed"
12704
12705         for i in $(seq $MDSCOUNT); do
12706                 last_rec=$(changelog_users $SINGLEMDS |
12707                            awk '/^current.index:/ { print $NF }')
12708                 echo "verify changelogs are on: $last_rec != ${LAST_REC[mds$i]}"
12709                 [ $last_rec != ${LAST_REC[mds$i]} ] ||
12710                         error "changelogs are off on mds$i"
12711         done
12712 }
12713 run_test 160i "changelog user register/unregister race"
12714
12715 test_161a() {
12716         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12717
12718         test_mkdir -c1 $DIR/$tdir
12719         cp /etc/hosts $DIR/$tdir/$tfile
12720         test_mkdir -c1 $DIR/$tdir/foo1
12721         test_mkdir -c1 $DIR/$tdir/foo2
12722         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
12723         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
12724         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
12725         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
12726         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
12727         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
12728                 $LFS fid2path $DIR $FID
12729                 error "bad link ea"
12730         fi
12731         # middle
12732         rm $DIR/$tdir/foo2/zachary
12733         # last
12734         rm $DIR/$tdir/foo2/thor
12735         # first
12736         rm $DIR/$tdir/$tfile
12737         # rename
12738         mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
12739         [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ] &&
12740                 { $LFS fid2path $DIR $FID; error "bad link rename"; }
12741         rm $DIR/$tdir/foo2/maggie
12742
12743         # overflow the EA
12744         local longname=$tfile.avg_len_is_thirty_two_
12745         stack_trap "unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
12746                 error_noexit 'failed to unlink many hardlinks'" EXIT
12747         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
12748                 error "failed to hardlink many files"
12749         links=$($LFS fid2path $DIR $FID | wc -l)
12750         echo -n "${links}/1000 links in link EA"
12751         [[ $links -gt 60 ]] || error "expected at least 60 links in link EA"
12752 }
12753 run_test 161a "link ea sanity"
12754
12755 test_161b() {
12756         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12757         [ $MDSCOUNT -lt 2 ] && skip_env "skipping remote directory test"
12758
12759         local MDTIDX=1
12760         local remote_dir=$DIR/$tdir/remote_dir
12761
12762         mkdir -p $DIR/$tdir
12763         $LFS mkdir -i $MDTIDX $remote_dir ||
12764                 error "create remote directory failed"
12765
12766         cp /etc/hosts $remote_dir/$tfile
12767         mkdir -p $remote_dir/foo1
12768         mkdir -p $remote_dir/foo2
12769         ln $remote_dir/$tfile $remote_dir/foo1/sofia
12770         ln $remote_dir/$tfile $remote_dir/foo2/zachary
12771         ln $remote_dir/$tfile $remote_dir/foo1/luna
12772         ln $remote_dir/$tfile $remote_dir/foo2/thor
12773
12774         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
12775                      tr -d ']')
12776         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
12777                 $LFS fid2path $DIR $FID
12778                 error "bad link ea"
12779         fi
12780         # middle
12781         rm $remote_dir/foo2/zachary
12782         # last
12783         rm $remote_dir/foo2/thor
12784         # first
12785         rm $remote_dir/$tfile
12786         # rename
12787         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
12788         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
12789         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
12790                 $LFS fid2path $DIR $FID
12791                 error "bad link rename"
12792         fi
12793         rm $remote_dir/foo2/maggie
12794
12795         # overflow the EA
12796         local longname=filename_avg_len_is_thirty_two_
12797         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
12798                 error "failed to hardlink many files"
12799         links=$($LFS fid2path $DIR $FID | wc -l)
12800         echo -n "${links}/1000 links in link EA"
12801         [[ ${links} -gt 60 ]] ||
12802                 error "expected at least 60 links in link EA"
12803         unlinkmany $remote_dir/foo2/$longname 1000 ||
12804         error "failed to unlink many hardlinks"
12805 }
12806 run_test 161b "link ea sanity under remote directory"
12807
12808 test_161c() {
12809         remote_mds_nodsh && skip "remote MDS with nodsh"
12810         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12811         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
12812                 skip "Need MDS version at least 2.1.5"
12813
12814         # define CLF_RENAME_LAST 0x0001
12815         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
12816         changelog_register || error "changelog_register failed"
12817
12818         rm -rf $DIR/$tdir
12819         test_mkdir -i $((MDSCOUNT - 1)) $DIR/$tdir
12820         touch $DIR/$tdir/foo_161c
12821         touch $DIR/$tdir/bar_161c
12822         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
12823         changelog_dump | grep RENME | tail -n 5
12824         local flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
12825         changelog_clear 0 || error "changelog_clear failed"
12826         if [ x$flags != "x0x1" ]; then
12827                 error "flag $flags is not 0x1"
12828         fi
12829
12830         echo "rename overwrite target with nlink = 1, changelog flags=$flags"
12831         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
12832         touch $DIR/$tdir/foo_161c
12833         touch $DIR/$tdir/bar_161c
12834         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
12835         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
12836         changelog_dump | grep RENME | tail -n 5
12837         flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
12838         changelog_clear 0 || error "changelog_clear failed"
12839         if [ x$flags != "x0x0" ]; then
12840                 error "flag $flags is not 0x0"
12841         fi
12842         echo "rename overwrite a target having nlink > 1," \
12843                 "changelog record has flags of $flags"
12844
12845         # rename doesn't overwrite a target (changelog flag 0x0)
12846         touch $DIR/$tdir/foo_161c
12847         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
12848         changelog_dump | grep RENME | tail -n 5
12849         flags=$(changelog_dump | grep RENME | tail -1 | cut -f5 -d' ')
12850         changelog_clear 0 || error "changelog_clear failed"
12851         if [ x$flags != "x0x0" ]; then
12852                 error "flag $flags is not 0x0"
12853         fi
12854         echo "rename doesn't overwrite a target," \
12855                 "changelog record has flags of $flags"
12856
12857         # define CLF_UNLINK_LAST 0x0001
12858         # unlink a file having nlink = 1 (changelog flag 0x1)
12859         rm -f $DIR/$tdir/foo2_161c
12860         changelog_dump | grep UNLNK | tail -n 5
12861         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
12862         changelog_clear 0 || error "changelog_clear failed"
12863         if [ x$flags != "x0x1" ]; then
12864                 error "flag $flags is not 0x1"
12865         fi
12866         echo "unlink a file having nlink = 1," \
12867                 "changelog record has flags of $flags"
12868
12869         # unlink a file having nlink > 1 (changelog flag 0x0)
12870         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
12871         rm -f $DIR/$tdir/foobar_161c
12872         changelog_dump | grep UNLNK | tail -n 5
12873         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
12874         changelog_clear 0 || error "changelog_clear failed"
12875         if [ x$flags != "x0x0" ]; then
12876                 error "flag $flags is not 0x0"
12877         fi
12878         echo "unlink a file having nlink > 1, changelog record flags '$flags'"
12879 }
12880 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
12881
12882 test_161d() {
12883         remote_mds_nodsh && skip "remote MDS with nodsh"
12884
12885         local pid
12886         local fid
12887
12888         changelog_register || error "changelog_register failed"
12889
12890         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
12891         # interfer with $MOUNT/.lustre/fid/ access
12892         mkdir $DIR/$tdir
12893         [[ $? -eq 0 ]] || error "mkdir failed"
12894
12895         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
12896         $LCTL set_param fail_loc=0x8000140c
12897         # 5s pause
12898         $LCTL set_param fail_val=5
12899
12900         # create file
12901         echo foofoo > $DIR/$tdir/$tfile &
12902         pid=$!
12903
12904         # wait for create to be delayed
12905         sleep 2
12906
12907         ps -p $pid
12908         [[ $? -eq 0 ]] || error "create should be blocked"
12909
12910         local tempfile=$(mktemp)
12911         fid=$(changelog_extract_field "CREAT" "$tfile" "t=")
12912         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
12913         # some delay may occur during ChangeLog publishing and file read just
12914         # above, that could allow file write to happen finally
12915         [[ -s $tempfile ]] && echo "file should be empty"
12916
12917         $LCTL set_param fail_loc=0
12918
12919         wait $pid
12920         [[ $? -eq 0 ]] || error "create failed"
12921 }
12922 run_test 161d "create with concurrent .lustre/fid access"
12923
12924 check_path() {
12925         local expected="$1"
12926         shift
12927         local fid="$2"
12928
12929         local path
12930         path=$($LFS fid2path "$@")
12931         local rc=$?
12932
12933         if [ $rc -ne 0 ]; then
12934                 error "path looked up of '$expected' failed: rc=$rc"
12935         elif [ "$path" != "$expected" ]; then
12936                 error "path looked up '$path' instead of '$expected'"
12937         else
12938                 echo "FID '$fid' resolves to path '$path' as expected"
12939         fi
12940 }
12941
12942 test_162a() { # was test_162
12943         test_mkdir -p -c1 $DIR/$tdir/d2
12944         touch $DIR/$tdir/d2/$tfile
12945         touch $DIR/$tdir/d2/x1
12946         touch $DIR/$tdir/d2/x2
12947         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
12948         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
12949         # regular file
12950         local fid=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
12951         check_path "$tdir/d2/$tfile" $FSNAME "$fid" --link 0
12952
12953         # softlink
12954         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
12955         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
12956         check_path "$tdir/d2/p/q/r/slink" $FSNAME "$fid" --link 0
12957
12958         # softlink to wrong file
12959         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
12960         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
12961         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME "$fid" --link 0
12962
12963         # hardlink
12964         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
12965         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
12966         fid=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
12967         # fid2path dir/fsname should both work
12968         check_path "$tdir/d2/a/b/c/new_file" $FSNAME "$fid" --link 1
12969         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR "$fid" --link 0
12970
12971         # hardlink count: check that there are 2 links
12972         local nlinks=$($LFS fid2path $DIR "$fid" | wc -l)
12973         [ $nlinks -eq 2 ] || error "expect 2 links, found $nlinks"
12974
12975         # hardlink indexing: remove the first link
12976         rm $DIR/$tdir/d2/p/q/r/hlink
12977         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $fid --link 0
12978 }
12979 run_test 162a "path lookup sanity"
12980
12981 test_162b() {
12982         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12983         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
12984
12985         mkdir $DIR/$tdir
12986         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
12987                                 error "create striped dir failed"
12988
12989         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
12990                                         tail -n 1 | awk '{print $2}')
12991         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
12992
12993         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
12994         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
12995
12996         # regular file
12997         for ((i=0;i<5;i++)); do
12998                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
12999                         error "get fid for f$i failed"
13000                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0
13001
13002                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
13003                         error "get fid for d$i failed"
13004                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0
13005         done
13006
13007         return 0
13008 }
13009 run_test 162b "striped directory path lookup sanity"
13010
13011 # LU-4239: Verify fid2path works with paths 100 or more directories deep
13012 test_162c() {
13013         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
13014                 skip "Need MDS version at least 2.7.51"
13015
13016         local lpath=$tdir.local
13017         local rpath=$tdir.remote
13018
13019         test_mkdir $DIR/$lpath
13020         test_mkdir $DIR/$rpath
13021
13022         for ((i = 0; i <= 101; i++)); do
13023                 lpath="$lpath/$i"
13024                 mkdir $DIR/$lpath
13025                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
13026                         error "get fid for local directory $DIR/$lpath failed"
13027                 check_path "$DIR/$lpath" $MOUNT $FID --link 0
13028
13029                 rpath="$rpath/$i"
13030                 test_mkdir $DIR/$rpath
13031                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
13032                         error "get fid for remote directory $DIR/$rpath failed"
13033                 check_path "$DIR/$rpath" $MOUNT $FID --link 0
13034         done
13035
13036         return 0
13037 }
13038 run_test 162c "fid2path works with paths 100 or more directories deep"
13039
13040 test_169() {
13041         # do directio so as not to populate the page cache
13042         log "creating a 10 Mb file"
13043         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
13044         log "starting reads"
13045         dd if=$DIR/$tfile of=/dev/null bs=4096 &
13046         log "truncating the file"
13047         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
13048         log "killing dd"
13049         kill %+ || true # reads might have finished
13050         echo "wait until dd is finished"
13051         wait
13052         log "removing the temporary file"
13053         rm -rf $DIR/$tfile || error "tmp file removal failed"
13054 }
13055 run_test 169 "parallel read and truncate should not deadlock"
13056
13057 test_170() {
13058         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13059
13060         $LCTL clear     # bug 18514
13061         $LCTL debug_daemon start $TMP/${tfile}_log_good
13062         touch $DIR/$tfile
13063         $LCTL debug_daemon stop
13064         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
13065                 error "sed failed to read log_good"
13066
13067         $LCTL debug_daemon start $TMP/${tfile}_log_good
13068         rm -rf $DIR/$tfile
13069         $LCTL debug_daemon stop
13070
13071         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
13072                error "lctl df log_bad failed"
13073
13074         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
13075         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
13076
13077         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
13078         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
13079
13080         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
13081                 error "bad_line good_line1 good_line2 are empty"
13082
13083         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
13084         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
13085         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
13086
13087         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
13088         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
13089         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
13090
13091         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
13092                 error "bad_line_new good_line_new are empty"
13093
13094         local expected_good=$((good_line1 + good_line2*2))
13095
13096         rm -f $TMP/${tfile}*
13097         # LU-231, short malformed line may not be counted into bad lines
13098         if [ $bad_line -ne $bad_line_new ] &&
13099                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
13100                 error "expected $bad_line bad lines, but got $bad_line_new"
13101                 return 1
13102         fi
13103
13104         if [ $expected_good -ne $good_line_new ]; then
13105                 error "expected $expected_good good lines, but got $good_line_new"
13106                 return 2
13107         fi
13108         true
13109 }
13110 run_test 170 "test lctl df to handle corrupted log ====================="
13111
13112 test_171() { # bug20592
13113         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13114
13115         #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
13116         $LCTL set_param fail_loc=0x50e
13117         $LCTL set_param fail_val=3000
13118         multiop_bg_pause $DIR/$tfile O_s || true
13119         local MULTIPID=$!
13120         kill -USR1 $MULTIPID
13121         # cause log dump
13122         sleep 3
13123         wait $MULTIPID
13124         if dmesg | grep "recursive fault"; then
13125                 error "caught a recursive fault"
13126         fi
13127         $LCTL set_param fail_loc=0
13128         true
13129 }
13130 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
13131
13132 # it would be good to share it with obdfilter-survey/iokit-libecho code
13133 setup_obdecho_osc () {
13134         local rc=0
13135         local ost_nid=$1
13136         local obdfilter_name=$2
13137         echo "Creating new osc for $obdfilter_name on $ost_nid"
13138         # make sure we can find loopback nid
13139         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
13140
13141         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
13142                            ${obdfilter_name}_osc_UUID || rc=2; }
13143         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
13144                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
13145         return $rc
13146 }
13147
13148 cleanup_obdecho_osc () {
13149         local obdfilter_name=$1
13150         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
13151         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
13152         return 0
13153 }
13154
13155 obdecho_test() {
13156         local OBD=$1
13157         local node=$2
13158         local pages=${3:-64}
13159         local rc=0
13160         local id
13161
13162         local count=10
13163         local obd_size=$(get_obd_size $node $OBD)
13164         local page_size=$(get_page_size $node)
13165         if [[ -n "$obd_size" ]]; then
13166                 local new_count=$((obd_size / (pages * page_size / 1024)))
13167                 [[ $new_count -ge $count ]] || count=$new_count
13168         fi
13169
13170         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
13171         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
13172                            rc=2; }
13173         if [ $rc -eq 0 ]; then
13174             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
13175             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
13176         fi
13177         echo "New object id is $id"
13178         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
13179                            rc=4; }
13180         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
13181                            "test_brw $count w v $pages $id" || rc=4; }
13182         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
13183                            rc=4; }
13184         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
13185                                         "cleanup" || rc=5; }
13186         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
13187                                         "detach" || rc=6; }
13188         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
13189         return $rc
13190 }
13191
13192 test_180a() {
13193         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13194
13195         if ! module_loaded obdecho; then
13196                 load_module obdecho/obdecho &&
13197                         stack_trap "rmmod obdecho" EXIT ||
13198                         error "unable to load obdecho on client"
13199         fi
13200
13201         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
13202         local host=$($LCTL get_param -n osc.$osc.import |
13203                      awk '/current_connection:/ { print $2 }' )
13204         local target=$($LCTL get_param -n osc.$osc.import |
13205                        awk '/target:/ { print $2 }' )
13206         target=${target%_UUID}
13207
13208         if [ -n "$target" ]; then
13209                 setup_obdecho_osc $host $target &&
13210                         stack_trap "cleanup_obdecho_osc $target" EXIT ||
13211                         { error "obdecho setup failed with $?"; return; }
13212
13213                 obdecho_test ${target}_osc client ||
13214                         error "obdecho_test failed on ${target}_osc"
13215         else
13216                 $LCTL get_param osc.$osc.import
13217                 error "there is no osc.$osc.import target"
13218         fi
13219 }
13220 run_test 180a "test obdecho on osc"
13221
13222 test_180b() {
13223         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13224         remote_ost_nodsh && skip "remote OST with nodsh"
13225
13226         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
13227                 stack_trap "do_facet ost1 rmmod obdecho" EXIT ||
13228                 error "failed to load module obdecho"
13229
13230         local target=$(do_facet ost1 $LCTL dl |
13231                        awk '/obdfilter/ { print $4; exit; }')
13232
13233         if [ -n "$target" ]; then
13234                 obdecho_test $target ost1 || error "obdecho_test failed with $?"
13235         else
13236                 do_facet ost1 $LCTL dl
13237                 error "there is no obdfilter target on ost1"
13238         fi
13239 }
13240 run_test 180b "test obdecho directly on obdfilter"
13241
13242 test_180c() { # LU-2598
13243         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13244         remote_ost_nodsh && skip "remote OST with nodsh"
13245         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
13246                 skip "Need MDS version at least 2.4.0"
13247
13248         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
13249                 stack_trap "do_facet ost1 rmmod obdecho" EXIT ||
13250                 error "failed to load module obdecho"
13251
13252         local target=$(do_facet ost1 $LCTL dl |
13253                        awk '/obdfilter/ { print $4; exit; }')
13254
13255         if [ -n "$target" ]; then
13256                 local pages=16384 # 64MB bulk I/O RPC size
13257
13258                 obdecho_test "$target" ost1 "$pages" ||
13259                         error "obdecho_test with pages=$pages failed with $?"
13260         else
13261                 do_facet ost1 $LCTL dl
13262                 error "there is no obdfilter target on ost1"
13263         fi
13264 }
13265 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
13266
13267 test_181() { # bug 22177
13268         test_mkdir $DIR/$tdir
13269         # create enough files to index the directory
13270         createmany -o $DIR/$tdir/foobar 4000
13271         # print attributes for debug purpose
13272         lsattr -d .
13273         # open dir
13274         multiop_bg_pause $DIR/$tdir D_Sc || return 1
13275         MULTIPID=$!
13276         # remove the files & current working dir
13277         unlinkmany $DIR/$tdir/foobar 4000
13278         rmdir $DIR/$tdir
13279         kill -USR1 $MULTIPID
13280         wait $MULTIPID
13281         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
13282         return 0
13283 }
13284 run_test 181 "Test open-unlinked dir ========================"
13285
13286 test_182() {
13287         local fcount=1000
13288         local tcount=10
13289
13290         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
13291
13292         $LCTL set_param mdc.*.rpc_stats=clear
13293
13294         for (( i = 0; i < $tcount; i++ )) ; do
13295                 mkdir $DIR/$tdir/$i
13296         done
13297
13298         for (( i = 0; i < $tcount; i++ )) ; do
13299                 createmany -o $DIR/$tdir/$i/f- $fcount &
13300         done
13301         wait
13302
13303         for (( i = 0; i < $tcount; i++ )) ; do
13304                 unlinkmany $DIR/$tdir/$i/f- $fcount &
13305         done
13306         wait
13307
13308         $LCTL get_param mdc.*.rpc_stats
13309
13310         rm -rf $DIR/$tdir
13311 }
13312 run_test 182 "Test parallel modify metadata operations ================"
13313
13314 test_183() { # LU-2275
13315         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13316         remote_mds_nodsh && skip "remote MDS with nodsh"
13317         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
13318                 skip "Need MDS version at least 2.3.56"
13319
13320         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
13321         echo aaa > $DIR/$tdir/$tfile
13322
13323 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
13324         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
13325
13326         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
13327         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
13328
13329         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
13330
13331         # Flush negative dentry cache
13332         touch $DIR/$tdir/$tfile
13333
13334         # We are not checking for any leaked references here, they'll
13335         # become evident next time we do cleanup with module unload.
13336         rm -rf $DIR/$tdir
13337 }
13338 run_test 183 "No crash or request leak in case of strange dispositions ========"
13339
13340 # test suite 184 is for LU-2016, LU-2017
13341 test_184a() {
13342         check_swap_layouts_support
13343
13344         dir0=$DIR/$tdir/$testnum
13345         test_mkdir -p -c1 $dir0
13346         ref1=/etc/passwd
13347         ref2=/etc/group
13348         file1=$dir0/f1
13349         file2=$dir0/f2
13350         $SETSTRIPE -c1 $file1
13351         cp $ref1 $file1
13352         $SETSTRIPE -c2 $file2
13353         cp $ref2 $file2
13354         gen1=$($GETSTRIPE -g $file1)
13355         gen2=$($GETSTRIPE -g $file2)
13356
13357         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
13358         gen=$($GETSTRIPE -g $file1)
13359         [[ $gen1 != $gen ]] ||
13360                 "Layout generation on $file1 does not change"
13361         gen=$($GETSTRIPE -g $file2)
13362         [[ $gen2 != $gen ]] ||
13363                 "Layout generation on $file2 does not change"
13364
13365         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
13366         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13367
13368         lfsck_verify_pfid $file1 $file2 || error "PFID are not transferred"
13369 }
13370 run_test 184a "Basic layout swap"
13371
13372 test_184b() {
13373         check_swap_layouts_support
13374
13375         dir0=$DIR/$tdir/$testnum
13376         mkdir -p $dir0 || error "creating dir $dir0"
13377         file1=$dir0/f1
13378         file2=$dir0/f2
13379         file3=$dir0/f3
13380         dir1=$dir0/d1
13381         dir2=$dir0/d2
13382         mkdir $dir1 $dir2
13383         $SETSTRIPE -c1 $file1
13384         $SETSTRIPE -c2 $file2
13385         $SETSTRIPE -c1 $file3
13386         chown $RUNAS_ID $file3
13387         gen1=$($GETSTRIPE -g $file1)
13388         gen2=$($GETSTRIPE -g $file2)
13389
13390         $LFS swap_layouts $dir1 $dir2 &&
13391                 error "swap of directories layouts should fail"
13392         $LFS swap_layouts $dir1 $file1 &&
13393                 error "swap of directory and file layouts should fail"
13394         $RUNAS $LFS swap_layouts $file1 $file2 &&
13395                 error "swap of file we cannot write should fail"
13396         $LFS swap_layouts $file1 $file3 &&
13397                 error "swap of file with different owner should fail"
13398         /bin/true # to clear error code
13399 }
13400 run_test 184b "Forbidden layout swap (will generate errors)"
13401
13402 test_184c() {
13403         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
13404         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n"
13405         check_swap_layouts_support
13406
13407         local dir0=$DIR/$tdir/$testnum
13408         mkdir -p $dir0 || error "creating dir $dir0"
13409
13410         local ref1=$dir0/ref1
13411         local ref2=$dir0/ref2
13412         local file1=$dir0/file1
13413         local file2=$dir0/file2
13414         # create a file large enough for the concurrent test
13415         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
13416         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
13417         echo "ref file size: ref1($(stat -c %s $ref1))," \
13418              "ref2($(stat -c %s $ref2))"
13419
13420         cp $ref2 $file2
13421         dd if=$ref1 of=$file1 bs=16k &
13422         local DD_PID=$!
13423
13424         # Make sure dd starts to copy file
13425         while [ ! -f $file1 ]; do sleep 0.1; done
13426
13427         $LFS swap_layouts $file1 $file2
13428         local rc=$?
13429         wait $DD_PID
13430         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
13431         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
13432
13433         # how many bytes copied before swapping layout
13434         local copied=$(stat -c %s $file2)
13435         local remaining=$(stat -c %s $ref1)
13436         remaining=$((remaining - copied))
13437         echo "Copied $copied bytes before swapping layout..."
13438
13439         cmp -n $copied $file1 $ref2 | grep differ &&
13440                 error "Content mismatch [0, $copied) of ref2 and file1"
13441         cmp -n $copied $file2 $ref1 ||
13442                 error "Content mismatch [0, $copied) of ref1 and file2"
13443         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
13444                 error "Content mismatch [$copied, EOF) of ref1 and file1"
13445
13446         # clean up
13447         rm -f $ref1 $ref2 $file1 $file2
13448 }
13449 run_test 184c "Concurrent write and layout swap"
13450
13451 test_184d() {
13452         check_swap_layouts_support
13453         [ -z "$(which getfattr 2>/dev/null)" ] &&
13454                 skip_env "no getfattr command"
13455
13456         local file1=$DIR/$tdir/$tfile-1
13457         local file2=$DIR/$tdir/$tfile-2
13458         local file3=$DIR/$tdir/$tfile-3
13459         local lovea1
13460         local lovea2
13461
13462         mkdir -p $DIR/$tdir
13463         touch $file1 || error "create $file1 failed"
13464         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
13465                 error "create $file2 failed"
13466         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
13467                 error "create $file3 failed"
13468         lovea1=$(get_layout_param $file1)
13469
13470         $LFS swap_layouts $file2 $file3 ||
13471                 error "swap $file2 $file3 layouts failed"
13472         $LFS swap_layouts $file1 $file2 ||
13473                 error "swap $file1 $file2 layouts failed"
13474
13475         lovea2=$(get_layout_param $file2)
13476         echo "$lovea1"
13477         echo "$lovea2"
13478         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
13479
13480         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
13481         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
13482 }
13483 run_test 184d "allow stripeless layouts swap"
13484
13485 test_184e() {
13486         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
13487                 skip "Need MDS version at least 2.6.94"
13488         check_swap_layouts_support
13489         [ -z "$(which getfattr 2>/dev/null)" ] &&
13490                 skip_env "no getfattr command"
13491
13492         local file1=$DIR/$tdir/$tfile-1
13493         local file2=$DIR/$tdir/$tfile-2
13494         local file3=$DIR/$tdir/$tfile-3
13495         local lovea
13496
13497         mkdir -p $DIR/$tdir
13498         touch $file1 || error "create $file1 failed"
13499         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
13500                 error "create $file2 failed"
13501         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
13502                 error "create $file3 failed"
13503
13504         $LFS swap_layouts $file1 $file2 ||
13505                 error "swap $file1 $file2 layouts failed"
13506
13507         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
13508         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
13509
13510         echo 123 > $file1 || error "Should be able to write into $file1"
13511
13512         $LFS swap_layouts $file1 $file3 ||
13513                 error "swap $file1 $file3 layouts failed"
13514
13515         echo 123 > $file1 || error "Should be able to write into $file1"
13516
13517         rm -rf $file1 $file2 $file3
13518 }
13519 run_test 184e "Recreate layout after stripeless layout swaps"
13520
13521 test_185() { # LU-2441
13522         # LU-3553 - no volatile file support in old servers
13523         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
13524                 skip "Need MDS version at least 2.3.60"
13525
13526         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
13527         touch $DIR/$tdir/spoo
13528         local mtime1=$(stat -c "%Y" $DIR/$tdir)
13529         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
13530                 error "cannot create/write a volatile file"
13531         [ "$FILESET" == "" ] &&
13532         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
13533                 error "FID is still valid after close"
13534
13535         multiop_bg_pause $DIR/$tdir vVw4096_c
13536         local multi_pid=$!
13537
13538         local OLD_IFS=$IFS
13539         IFS=":"
13540         local fidv=($fid)
13541         IFS=$OLD_IFS
13542         # assume that the next FID for this client is sequential, since stdout
13543         # is unfortunately eaten by multiop_bg_pause
13544         local n=$((${fidv[1]} + 1))
13545         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
13546         if [ "$FILESET" == "" ]; then
13547                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
13548                         error "FID is missing before close"
13549         fi
13550         kill -USR1 $multi_pid
13551         # 1 second delay, so if mtime change we will see it
13552         sleep 1
13553         local mtime2=$(stat -c "%Y" $DIR/$tdir)
13554         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
13555 }
13556 run_test 185 "Volatile file support"
13557
13558 test_187a() {
13559         remote_mds_nodsh && skip "remote MDS with nodsh"
13560         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
13561                 skip "Need MDS version at least 2.3.0"
13562
13563         local dir0=$DIR/$tdir/$testnum
13564         mkdir -p $dir0 || error "creating dir $dir0"
13565
13566         local file=$dir0/file1
13567         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
13568         local dv1=$($LFS data_version $file)
13569         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
13570         local dv2=$($LFS data_version $file)
13571         [[ $dv1 != $dv2 ]] ||
13572                 error "data version did not change on write $dv1 == $dv2"
13573
13574         # clean up
13575         rm -f $file1
13576 }
13577 run_test 187a "Test data version change"
13578
13579 test_187b() {
13580         remote_mds_nodsh && skip "remote MDS with nodsh"
13581         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
13582                 skip "Need MDS version at least 2.3.0"
13583
13584         local dir0=$DIR/$tdir/$testnum
13585         mkdir -p $dir0 || error "creating dir $dir0"
13586
13587         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
13588         [[ ${DV[0]} != ${DV[1]} ]] ||
13589                 error "data version did not change on write"\
13590                       " ${DV[0]} == ${DV[1]}"
13591
13592         # clean up
13593         rm -f $file1
13594 }
13595 run_test 187b "Test data version change on volatile file"
13596
13597 test_200() {
13598         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13599         remote_mgs_nodsh && skip "remote MGS with nodsh"
13600         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13601
13602         local POOL=${POOL:-cea1}
13603         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
13604         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
13605         # Pool OST targets
13606         local first_ost=0
13607         local last_ost=$(($OSTCOUNT - 1))
13608         local ost_step=2
13609         local ost_list=$(seq $first_ost $ost_step $last_ost)
13610         local ost_range="$first_ost $last_ost $ost_step"
13611         local test_path=$POOL_ROOT/$POOL_DIR_NAME
13612         local file_dir=$POOL_ROOT/file_tst
13613         local subdir=$test_path/subdir
13614         local rc=0
13615
13616         if ! combined_mgs_mds ; then
13617                 mount_mgs_client
13618         fi
13619
13620         while : ; do
13621                 # former test_200a test_200b
13622                 pool_add $POOL                          || { rc=$? ; break; }
13623                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
13624                 # former test_200c test_200d
13625                 mkdir -p $test_path
13626                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
13627                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
13628                 mkdir -p $subdir
13629                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
13630                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
13631                                                         || { rc=$? ; break; }
13632                 # former test_200e test_200f
13633                 local files=$((OSTCOUNT*3))
13634                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
13635                                                         || { rc=$? ; break; }
13636                 pool_create_files $POOL $file_dir $files "$ost_list" \
13637                                                         || { rc=$? ; break; }
13638                 # former test_200g test_200h
13639                 pool_lfs_df $POOL                       || { rc=$? ; break; }
13640                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
13641
13642                 # former test_201a test_201b test_201c
13643                 pool_remove_first_target $POOL          || { rc=$? ; break; }
13644
13645                 local f=$test_path/$tfile
13646                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
13647                 pool_remove $POOL $f                    || { rc=$? ; break; }
13648                 break
13649         done
13650
13651         destroy_test_pools
13652
13653         if ! combined_mgs_mds ; then
13654                 umount_mgs_client
13655         fi
13656         return $rc
13657 }
13658 run_test 200 "OST pools"
13659
13660 # usage: default_attr <count | size | offset>
13661 default_attr() {
13662         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
13663 }
13664
13665 # usage: check_default_stripe_attr
13666 check_default_stripe_attr() {
13667         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
13668         case $1 in
13669         --stripe-count|-c)
13670                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
13671         --stripe-size|-S)
13672                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
13673         --stripe-index|-i)
13674                 EXPECTED=-1;;
13675         *)
13676                 error "unknown getstripe attr '$1'"
13677         esac
13678
13679         [ $ACTUAL == $EXPECTED ] ||
13680                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
13681 }
13682
13683 test_204a() {
13684         test_mkdir $DIR/$tdir
13685         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
13686
13687         check_default_stripe_attr --stripe-count
13688         check_default_stripe_attr --stripe-size
13689         check_default_stripe_attr --stripe-index
13690 }
13691 run_test 204a "Print default stripe attributes"
13692
13693 test_204b() {
13694         test_mkdir $DIR/$tdir
13695         $SETSTRIPE --stripe-count 1 $DIR/$tdir
13696
13697         check_default_stripe_attr --stripe-size
13698         check_default_stripe_attr --stripe-index
13699 }
13700 run_test 204b "Print default stripe size and offset"
13701
13702 test_204c() {
13703         test_mkdir $DIR/$tdir
13704         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
13705
13706         check_default_stripe_attr --stripe-count
13707         check_default_stripe_attr --stripe-index
13708 }
13709 run_test 204c "Print default stripe count and offset"
13710
13711 test_204d() {
13712         test_mkdir $DIR/$tdir
13713         $SETSTRIPE --stripe-index 0 $DIR/$tdir
13714
13715         check_default_stripe_attr --stripe-count
13716         check_default_stripe_attr --stripe-size
13717 }
13718 run_test 204d "Print default stripe count and size"
13719
13720 test_204e() {
13721         test_mkdir $DIR/$tdir
13722         $SETSTRIPE -d $DIR/$tdir
13723
13724         check_default_stripe_attr --stripe-count --raw
13725         check_default_stripe_attr --stripe-size --raw
13726         check_default_stripe_attr --stripe-index --raw
13727 }
13728 run_test 204e "Print raw stripe attributes"
13729
13730 test_204f() {
13731         test_mkdir $DIR/$tdir
13732         $SETSTRIPE --stripe-count 1 $DIR/$tdir
13733
13734         check_default_stripe_attr --stripe-size --raw
13735         check_default_stripe_attr --stripe-index --raw
13736 }
13737 run_test 204f "Print raw stripe size and offset"
13738
13739 test_204g() {
13740         test_mkdir $DIR/$tdir
13741         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
13742
13743         check_default_stripe_attr --stripe-count --raw
13744         check_default_stripe_attr --stripe-index --raw
13745 }
13746 run_test 204g "Print raw stripe count and offset"
13747
13748 test_204h() {
13749         test_mkdir $DIR/$tdir
13750         $SETSTRIPE --stripe-index 0 $DIR/$tdir
13751
13752         check_default_stripe_attr --stripe-count --raw
13753         check_default_stripe_attr --stripe-size --raw
13754 }
13755 run_test 204h "Print raw stripe count and size"
13756
13757 # Figure out which job scheduler is being used, if any,
13758 # or use a fake one
13759 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
13760         JOBENV=SLURM_JOB_ID
13761 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
13762         JOBENV=LSB_JOBID
13763 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
13764         JOBENV=PBS_JOBID
13765 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
13766         JOBENV=LOADL_STEP_ID
13767 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
13768         JOBENV=JOB_ID
13769 else
13770         $LCTL list_param jobid_name > /dev/null 2>&1
13771         if [ $? -eq 0 ]; then
13772                 JOBENV=nodelocal
13773         else
13774                 JOBENV=FAKE_JOBID
13775         fi
13776 fi
13777 LUSTRE_JOBID_SIZE=31 # plus NUL terminator
13778
13779 verify_jobstats() {
13780         local cmd=($1)
13781         shift
13782         local facets="$@"
13783
13784 # we don't really need to clear the stats for this test to work, since each
13785 # command has a unique jobid, but it makes debugging easier if needed.
13786 #       for facet in $facets; do
13787 #               local dev=$(convert_facet2label $facet)
13788 #               # clear old jobstats
13789 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
13790 #       done
13791
13792         # use a new JobID for each test, or we might see an old one
13793         [ "$JOBENV" = "FAKE_JOBID" ] &&
13794                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
13795
13796         JOBVAL=${!JOBENV:0:$LUSTRE_JOBID_SIZE}
13797
13798         [ "$JOBENV" = "nodelocal" ] && {
13799                 FAKE_JOBID=id.$testnum.%e.$RANDOM
13800                 $LCTL set_param jobid_name=$FAKE_JOBID
13801                 JOBVAL=${FAKE_JOBID/\%e/$(basename ${cmd[0]})}
13802         }
13803
13804         log "Test: ${cmd[*]}"
13805         log "Using JobID environment $($LCTL get_param -n jobid_var)=$JOBVAL"
13806
13807         if [ $JOBENV = "FAKE_JOBID" ]; then
13808                 FAKE_JOBID=$JOBVAL ${cmd[*]}
13809         else
13810                 ${cmd[*]}
13811         fi
13812
13813         # all files are created on OST0000
13814         for facet in $facets; do
13815                 local stats="*.$(convert_facet2label $facet).job_stats"
13816
13817                 # strip out libtool wrappers for in-tree executables
13818                 if [ $(do_facet $facet lctl get_param $stats |
13819                        sed -e 's/\.lt-/./' | grep -c $JOBVAL) -ne 1 ]; then
13820                         do_facet $facet lctl get_param $stats
13821                         error "No jobstats for $JOBVAL found on $facet::$stats"
13822                 fi
13823         done
13824 }
13825
13826 jobstats_set() {
13827         local new_jobenv=$1
13828
13829         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$new_jobenv
13830         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $new_jobenv
13831 }
13832
13833 test_205() { # Job stats
13834         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13835         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
13836                 skip "Need MDS version with at least 2.7.1"
13837         remote_mgs_nodsh && skip "remote MGS with nodsh"
13838         remote_mds_nodsh && skip "remote MDS with nodsh"
13839         remote_ost_nodsh && skip "remote OST with nodsh"
13840         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
13841                 skip "Server doesn't support jobstats"
13842         [[ $JOBID_VAR = disable ]] && skip_env "jobstats is disabled"
13843
13844         local old_jobenv=$($LCTL get_param -n jobid_var)
13845         [ $old_jobenv != $JOBENV ] && jobstats_set $JOBENV
13846         stack_trap "do_facet mgs \
13847                 $LCTL conf_param $FSNAME.sys.jobid_var=$old_jobenv" EXIT
13848
13849         changelog_register
13850
13851         local old_interval=$(do_facet $SINGLEMDS lctl get_param -n \
13852                                 mdt.*.job_cleanup_interval | head -n 1)
13853         local new_interval=5
13854         do_facet $SINGLEMDS \
13855                 $LCTL set_param mdt.*.job_cleanup_interval=$new_interval
13856         stack_trap "do_facet $SINGLEMDS \
13857                 $LCTL set_param mdt.*.job_cleanup_interval=$old_interval" EXIT
13858         local start=$SECONDS
13859
13860         local cmd
13861         # mkdir
13862         cmd="mkdir $DIR/$tdir"
13863         verify_jobstats "$cmd" "$SINGLEMDS"
13864         # rmdir
13865         cmd="rmdir $DIR/$tdir"
13866         verify_jobstats "$cmd" "$SINGLEMDS"
13867         # mkdir on secondary MDT
13868         if [ $MDSCOUNT -gt 1 ]; then
13869                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
13870                 verify_jobstats "$cmd" "mds2"
13871         fi
13872         # mknod
13873         cmd="mknod $DIR/$tfile c 1 3"
13874         verify_jobstats "$cmd" "$SINGLEMDS"
13875         # unlink
13876         cmd="rm -f $DIR/$tfile"
13877         verify_jobstats "$cmd" "$SINGLEMDS"
13878         # create all files on OST0000 so verify_jobstats can find OST stats
13879         # open & close
13880         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
13881         verify_jobstats "$cmd" "$SINGLEMDS"
13882         # setattr
13883         cmd="touch $DIR/$tfile"
13884         verify_jobstats "$cmd" "$SINGLEMDS ost1"
13885         # write
13886         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
13887         verify_jobstats "$cmd" "ost1"
13888         # read
13889         cancel_lru_locks osc
13890         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
13891         verify_jobstats "$cmd" "ost1"
13892         # truncate
13893         cmd="$TRUNCATE $DIR/$tfile 0"
13894         verify_jobstats "$cmd" "$SINGLEMDS ost1"
13895         # rename
13896         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
13897         verify_jobstats "$cmd" "$SINGLEMDS"
13898         # jobstats expiry - sleep until old stats should be expired
13899         local left=$((new_interval + 5 - (SECONDS - start)))
13900         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
13901                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
13902                         "0" $left
13903         cmd="mkdir $DIR/$tdir.expire"
13904         verify_jobstats "$cmd" "$SINGLEMDS"
13905         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
13906             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
13907
13908         # Ensure that jobid are present in changelog (if supported by MDS)
13909         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ];then
13910                 changelog_dump | tail -10
13911                 jobids=$(changelog_dump | tail -9 | grep -c "j=")
13912                 [ $jobids -eq 9 ] ||
13913                         error "Wrong changelog jobid count $jobids != 9"
13914
13915                 # LU-5862
13916                 JOBENV="disable"
13917                 jobstats_set $JOBENV
13918                 touch $DIR/$tfile
13919                 changelog_dump | grep $tfile
13920                 jobids=$(changelog_dump | grep $tfile | tail -1 | grep -c "j=")
13921                 [ $jobids -eq 0 ] ||
13922                         error "Unexpected jobids when jobid_var=$JOBENV"
13923         fi
13924
13925         lctl set_param jobid_var=USER jobid_name="S.%j.%e.%u.%h.E"
13926         JOBENV="JOBCOMPLEX"
13927         JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname).E"
13928
13929         verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
13930 }
13931 run_test 205 "Verify job stats"
13932
13933 # LU-1480, LU-1773 and LU-1657
13934 test_206() {
13935         mkdir -p $DIR/$tdir
13936         $SETSTRIPE -c -1 $DIR/$tdir
13937 #define OBD_FAIL_LOV_INIT 0x1403
13938         $LCTL set_param fail_loc=0xa0001403
13939         $LCTL set_param fail_val=1
13940         touch $DIR/$tdir/$tfile || true
13941 }
13942 run_test 206 "fail lov_init_raid0() doesn't lbug"
13943
13944 test_207a() {
13945         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
13946         local fsz=`stat -c %s $DIR/$tfile`
13947         cancel_lru_locks mdc
13948
13949         # do not return layout in getattr intent
13950 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
13951         $LCTL set_param fail_loc=0x170
13952         local sz=`stat -c %s $DIR/$tfile`
13953
13954         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
13955
13956         rm -rf $DIR/$tfile
13957 }
13958 run_test 207a "can refresh layout at glimpse"
13959
13960 test_207b() {
13961         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
13962         local cksum=`md5sum $DIR/$tfile`
13963         local fsz=`stat -c %s $DIR/$tfile`
13964         cancel_lru_locks mdc
13965         cancel_lru_locks osc
13966
13967         # do not return layout in getattr intent
13968 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
13969         $LCTL set_param fail_loc=0x171
13970
13971         # it will refresh layout after the file is opened but before read issues
13972         echo checksum is "$cksum"
13973         echo "$cksum" |md5sum -c --quiet || error "file differs"
13974
13975         rm -rf $DIR/$tfile
13976 }
13977 run_test 207b "can refresh layout at open"
13978
13979 test_208() {
13980         # FIXME: in this test suite, only RD lease is used. This is okay
13981         # for now as only exclusive open is supported. After generic lease
13982         # is done, this test suite should be revised. - Jinshan
13983
13984         remote_mds_nodsh && skip "remote MDS with nodsh"
13985         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
13986                 skip "Need MDS version at least 2.4.52"
13987
13988         echo "==== test 1: verify get lease work"
13989         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
13990
13991         echo "==== test 2: verify lease can be broken by upcoming open"
13992         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
13993         local PID=$!
13994         sleep 1
13995
13996         $MULTIOP $DIR/$tfile oO_RDONLY:c
13997         kill -USR1 $PID && wait $PID || error "break lease error"
13998
13999         echo "==== test 3: verify lease can't be granted if an open already exists"
14000         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
14001         local PID=$!
14002         sleep 1
14003
14004         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
14005         kill -USR1 $PID && wait $PID || error "open file error"
14006
14007         echo "==== test 4: lease can sustain over recovery"
14008         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
14009         PID=$!
14010         sleep 1
14011
14012         fail mds1
14013
14014         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
14015
14016         echo "==== test 5: lease broken can't be regained by replay"
14017         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
14018         PID=$!
14019         sleep 1
14020
14021         # open file to break lease and then recovery
14022         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
14023         fail mds1
14024
14025         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
14026
14027         rm -f $DIR/$tfile
14028 }
14029 run_test 208 "Exclusive open"
14030
14031 test_209() {
14032         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
14033                 skip_env "must have disp_stripe"
14034
14035         touch $DIR/$tfile
14036         sync; sleep 5; sync;
14037
14038         echo 3 > /proc/sys/vm/drop_caches
14039         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
14040
14041         # open/close 500 times
14042         for i in $(seq 500); do
14043                 cat $DIR/$tfile
14044         done
14045
14046         echo 3 > /proc/sys/vm/drop_caches
14047         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
14048
14049         echo "before: $req_before, after: $req_after"
14050         [ $((req_after - req_before)) -ge 300 ] &&
14051                 error "open/close requests are not freed"
14052         return 0
14053 }
14054 run_test 209 "read-only open/close requests should be freed promptly"
14055
14056 test_212() {
14057         size=`date +%s`
14058         size=$((size % 8192 + 1))
14059         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
14060         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
14061         rm -f $DIR/f212 $DIR/f212.xyz
14062 }
14063 run_test 212 "Sendfile test ============================================"
14064
14065 test_213() {
14066         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
14067         cancel_lru_locks osc
14068         lctl set_param fail_loc=0x8000040f
14069         # generate a read lock
14070         cat $DIR/$tfile > /dev/null
14071         # write to the file, it will try to cancel the above read lock.
14072         cat /etc/hosts >> $DIR/$tfile
14073 }
14074 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
14075
14076 test_214() { # for bug 20133
14077         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
14078         for (( i=0; i < 340; i++ )) ; do
14079                 touch $DIR/$tdir/d214c/a$i
14080         done
14081
14082         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
14083         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
14084         ls $DIR/d214c || error "ls $DIR/d214c failed"
14085         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
14086         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
14087 }
14088 run_test 214 "hash-indexed directory test - bug 20133"
14089
14090 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
14091 create_lnet_proc_files() {
14092         lctl get_param -n $1 >$TMP/lnet_$1.sys || error "cannot read lnet.$1"
14093 }
14094
14095 # counterpart of create_lnet_proc_files
14096 remove_lnet_proc_files() {
14097         rm -f $TMP/lnet_$1.sys
14098 }
14099
14100 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
14101 # 3rd arg as regexp for body
14102 check_lnet_proc_stats() {
14103         local l=$(cat "$TMP/lnet_$1" |wc -l)
14104         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
14105
14106         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
14107 }
14108
14109 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
14110 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
14111 # optional and can be regexp for 2nd line (lnet.routes case)
14112 check_lnet_proc_entry() {
14113         local blp=2          # blp stands for 'position of 1st line of body'
14114         [ -z "$5" ] || blp=3 # lnet.routes case
14115
14116         local l=$(cat "$TMP/lnet_$1" |wc -l)
14117         # subtracting one from $blp because the body can be empty
14118         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
14119
14120         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
14121                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
14122
14123         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
14124                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
14125
14126         # bail out if any unexpected line happened
14127         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
14128         [ "$?" != 0 ] || error "$2 misformatted"
14129 }
14130
14131 test_215() { # for bugs 18102, 21079, 21517
14132         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14133
14134         local N='(0|[1-9][0-9]*)'       # non-negative numeric
14135         local P='[1-9][0-9]*'           # positive numeric
14136         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
14137         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
14138         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
14139         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
14140
14141         local L1 # regexp for 1st line
14142         local L2 # regexp for 2nd line (optional)
14143         local BR # regexp for the rest (body)
14144
14145         # lnet.stats should look as 11 space-separated non-negative numerics
14146         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
14147         create_lnet_proc_files "stats"
14148         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
14149         remove_lnet_proc_files "stats"
14150
14151         # lnet.routes should look like this:
14152         # Routing disabled/enabled
14153         # net hops priority state router
14154         # where net is a string like tcp0, hops > 0, priority >= 0,
14155         # state is up/down,
14156         # router is a string like 192.168.1.1@tcp2
14157         L1="^Routing (disabled|enabled)$"
14158         L2="^net +hops +priority +state +router$"
14159         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
14160         create_lnet_proc_files "routes"
14161         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
14162         remove_lnet_proc_files "routes"
14163
14164         # lnet.routers should look like this:
14165         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
14166         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
14167         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
14168         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
14169         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
14170         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
14171         create_lnet_proc_files "routers"
14172         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
14173         remove_lnet_proc_files "routers"
14174
14175         # lnet.peers should look like this:
14176         # nid refs state last max rtr min tx min queue
14177         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
14178         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
14179         # numeric (0 or >0 or <0), queue >= 0.
14180         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
14181         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
14182         create_lnet_proc_files "peers"
14183         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
14184         remove_lnet_proc_files "peers"
14185
14186         # lnet.buffers  should look like this:
14187         # pages count credits min
14188         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
14189         L1="^pages +count +credits +min$"
14190         BR="^ +$N +$N +$I +$I$"
14191         create_lnet_proc_files "buffers"
14192         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
14193         remove_lnet_proc_files "buffers"
14194
14195         # lnet.nis should look like this:
14196         # nid status alive refs peer rtr max tx min
14197         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
14198         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
14199         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
14200         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
14201         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
14202         create_lnet_proc_files "nis"
14203         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
14204         remove_lnet_proc_files "nis"
14205
14206         # can we successfully write to lnet.stats?
14207         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
14208 }
14209 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
14210
14211 test_216() { # bug 20317
14212         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14213         remote_ost_nodsh && skip "remote OST with nodsh"
14214
14215         local node
14216         local facets=$(get_facets OST)
14217         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
14218
14219         save_lustre_params client "osc.*.contention_seconds" > $p
14220         save_lustre_params $facets \
14221                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
14222         save_lustre_params $facets \
14223                 "ldlm.namespaces.filter-*.contended_locks" >> $p
14224         save_lustre_params $facets \
14225                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
14226         clear_stats osc.*.osc_stats
14227
14228         # agressive lockless i/o settings
14229         do_nodes $(comma_list $(osts_nodes)) \
14230                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
14231                         ldlm.namespaces.filter-*.contended_locks=0 \
14232                         ldlm.namespaces.filter-*.contention_seconds=60"
14233         lctl set_param -n osc.*.contention_seconds=60
14234
14235         $DIRECTIO write $DIR/$tfile 0 10 4096
14236         $CHECKSTAT -s 40960 $DIR/$tfile
14237
14238         # disable lockless i/o
14239         do_nodes $(comma_list $(osts_nodes)) \
14240                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
14241                         ldlm.namespaces.filter-*.contended_locks=32 \
14242                         ldlm.namespaces.filter-*.contention_seconds=0"
14243         lctl set_param -n osc.*.contention_seconds=0
14244         clear_stats osc.*.osc_stats
14245
14246         dd if=/dev/zero of=$DIR/$tfile count=0
14247         $CHECKSTAT -s 0 $DIR/$tfile
14248
14249         restore_lustre_params <$p
14250         rm -f $p
14251         rm $DIR/$tfile
14252 }
14253 run_test 216 "check lockless direct write updates file size and kms correctly"
14254
14255 test_217() { # bug 22430
14256         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14257
14258         local node
14259         local nid
14260
14261         for node in $(nodes_list); do
14262                 nid=$(host_nids_address $node $NETTYPE)
14263                 if [[ $nid = *-* ]] ; then
14264                         echo "lctl ping $(h2nettype $nid)"
14265                         lctl ping $(h2nettype $nid)
14266                 else
14267                         echo "skipping $node (no hyphen detected)"
14268                 fi
14269         done
14270 }
14271 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
14272
14273 test_218() {
14274        # do directio so as not to populate the page cache
14275        log "creating a 10 Mb file"
14276        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
14277        log "starting reads"
14278        dd if=$DIR/$tfile of=/dev/null bs=4096 &
14279        log "truncating the file"
14280        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
14281        log "killing dd"
14282        kill %+ || true # reads might have finished
14283        echo "wait until dd is finished"
14284        wait
14285        log "removing the temporary file"
14286        rm -rf $DIR/$tfile || error "tmp file removal failed"
14287 }
14288 run_test 218 "parallel read and truncate should not deadlock"
14289
14290 test_219() {
14291         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14292
14293         # write one partial page
14294         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
14295         # set no grant so vvp_io_commit_write will do sync write
14296         $LCTL set_param fail_loc=0x411
14297         # write a full page at the end of file
14298         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
14299
14300         $LCTL set_param fail_loc=0
14301         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
14302         $LCTL set_param fail_loc=0x411
14303         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
14304
14305         # LU-4201
14306         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
14307         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
14308 }
14309 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
14310
14311 test_220() { #LU-325
14312         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14313         remote_ost_nodsh && skip "remote OST with nodsh"
14314         remote_mds_nodsh && skip "remote MDS with nodsh"
14315         remote_mgs_nodsh && skip "remote MGS with nodsh"
14316
14317         local OSTIDX=0
14318
14319         # create on MDT0000 so the last_id and next_id are correct
14320         mkdir $DIR/$tdir
14321         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
14322         OST=${OST%_UUID}
14323
14324         # on the mdt's osc
14325         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
14326         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
14327                         osc.$mdtosc_proc1.prealloc_last_id)
14328         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
14329                         osc.$mdtosc_proc1.prealloc_next_id)
14330
14331         $LFS df -i
14332
14333         if ! combined_mgs_mds ; then
14334                 mount_mgs_client
14335         fi
14336
14337         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
14338         #define OBD_FAIL_OST_ENOINO              0x229
14339         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
14340         create_pool $FSNAME.$TESTNAME || return 1
14341         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
14342
14343         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
14344
14345         MDSOBJS=$((last_id - next_id))
14346         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
14347
14348         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
14349         echo "OST still has $count kbytes free"
14350
14351         echo "create $MDSOBJS files @next_id..."
14352         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
14353
14354         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
14355                         osc.$mdtosc_proc1.prealloc_last_id)
14356         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
14357                         osc.$mdtosc_proc1.prealloc_next_id)
14358
14359         echo "after creation, last_id=$last_id2, next_id=$next_id2"
14360         $LFS df -i
14361
14362         echo "cleanup..."
14363
14364         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
14365         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
14366
14367         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST ||
14368                 error "$LCTL pool_remove $FSNAME.$TESTNAME $OST failed"
14369         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
14370                 error "$LCTL pool_destroy $FSNAME.$TESTNAME failed"
14371         echo "unlink $MDSOBJS files @$next_id..."
14372         unlinkmany $DIR/$tdir/f $MDSOBJS || error "unlinkmany failed"
14373
14374         if ! combined_mgs_mds ; then
14375                 umount_mgs_client
14376         fi
14377 }
14378 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
14379
14380 test_221() {
14381         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14382
14383         dd if=`which date` of=$MOUNT/date oflag=sync
14384         chmod +x $MOUNT/date
14385
14386         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
14387         $LCTL set_param fail_loc=0x80001401
14388
14389         $MOUNT/date > /dev/null
14390         rm -f $MOUNT/date
14391 }
14392 run_test 221 "make sure fault and truncate race to not cause OOM"
14393
14394 test_222a () {
14395         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14396
14397         rm -rf $DIR/$tdir
14398         test_mkdir $DIR/$tdir
14399         $LFS setstripe -c 1 -i 0 $DIR/$tdir
14400         createmany -o $DIR/$tdir/$tfile 10
14401         cancel_lru_locks mdc
14402         cancel_lru_locks osc
14403         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
14404         $LCTL set_param fail_loc=0x31a
14405         ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
14406         $LCTL set_param fail_loc=0
14407         rm -r $DIR/$tdir
14408 }
14409 run_test 222a "AGL for ls should not trigger CLIO lock failure"
14410
14411 test_222b () {
14412         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14413
14414         rm -rf $DIR/$tdir
14415         test_mkdir $DIR/$tdir
14416         $LFS setstripe -c 1 -i 0 $DIR/$tdir
14417         createmany -o $DIR/$tdir/$tfile 10
14418         cancel_lru_locks mdc
14419         cancel_lru_locks osc
14420         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
14421         $LCTL set_param fail_loc=0x31a
14422         rm -r $DIR/$tdir || error "AGL for rmdir failed"
14423         $LCTL set_param fail_loc=0
14424 }
14425 run_test 222b "AGL for rmdir should not trigger CLIO lock failure"
14426
14427 test_223 () {
14428         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14429
14430         rm -rf $DIR/$tdir
14431         test_mkdir $DIR/$tdir
14432         $LFS setstripe -c 1 -i 0 $DIR/$tdir
14433         createmany -o $DIR/$tdir/$tfile 10
14434         cancel_lru_locks mdc
14435         cancel_lru_locks osc
14436         #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
14437         $LCTL set_param fail_loc=0x31b
14438         ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
14439         $LCTL set_param fail_loc=0
14440         rm -r $DIR/$tdir
14441 }
14442 run_test 223 "osc reenqueue if without AGL lock granted ======================="
14443
14444 test_224a() { # LU-1039, MRP-303
14445         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14446
14447         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
14448         $LCTL set_param fail_loc=0x508
14449         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
14450         $LCTL set_param fail_loc=0
14451         df $DIR
14452 }
14453 run_test 224a "Don't panic on bulk IO failure"
14454
14455 test_224b() { # LU-1039, MRP-303
14456         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14457
14458         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
14459         cancel_lru_locks osc
14460         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
14461         $LCTL set_param fail_loc=0x515
14462         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
14463         $LCTL set_param fail_loc=0
14464         df $DIR
14465 }
14466 run_test 224b "Don't panic on bulk IO failure"
14467
14468 test_224c() { # LU-6441
14469         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14470         remote_mds_nodsh && skip "remote MDS with nodsh"
14471
14472         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
14473         save_writethrough $p
14474         set_cache writethrough on
14475
14476         local pages_per_rpc=$($LCTL get_param \
14477                                 osc.*.max_pages_per_rpc)
14478         local at_max=$($LCTL get_param -n at_max)
14479         local timeout=$($LCTL get_param -n timeout)
14480         local test_at="$LCTL get_param -n at_max"
14481         local param_at="$FSNAME.sys.at_max"
14482         local test_timeout="$LCTL get_param -n timeout"
14483         local param_timeout="$FSNAME.sys.timeout"
14484
14485         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
14486
14487         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
14488                 error "conf_param at_max=0 failed"
14489         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
14490                 error "conf_param timeout=5 failed"
14491
14492         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
14493         do_facet ost1 $LCTL set_param fail_loc=0x520
14494         $LFS setstripe -c 1 -i 0 $DIR/$tfile
14495         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
14496         sync
14497         do_facet ost1 $LCTL set_param fail_loc=0
14498
14499         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
14500                 error "conf_param at_max=$at_max failed"
14501         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
14502                 $timeout || error "conf_param timeout=$timeout failed"
14503
14504         $LCTL set_param -n $pages_per_rpc
14505         restore_lustre_params < $p
14506         rm -f $p
14507 }
14508 run_test 224c "Don't hang if one of md lost during large bulk RPC"
14509
14510 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
14511 test_225a () {
14512         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14513         if [ -z ${MDSSURVEY} ]; then
14514                 skip_env "mds-survey not found"
14515         fi
14516         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
14517                 skip "Need MDS version at least 2.2.51"
14518
14519         local mds=$(facet_host $SINGLEMDS)
14520         local target=$(do_nodes $mds 'lctl dl' |
14521                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
14522
14523         local cmd1="file_count=1000 thrhi=4"
14524         local cmd2="dir_count=2 layer=mdd stripe_count=0"
14525         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
14526         local cmd="$cmd1 $cmd2 $cmd3"
14527
14528         rm -f ${TMP}/mds_survey*
14529         echo + $cmd
14530         eval $cmd || error "mds-survey with zero-stripe failed"
14531         cat ${TMP}/mds_survey*
14532         rm -f ${TMP}/mds_survey*
14533 }
14534 run_test 225a "Metadata survey sanity with zero-stripe"
14535
14536 test_225b () {
14537         if [ -z ${MDSSURVEY} ]; then
14538                 skip_env "mds-survey not found"
14539         fi
14540         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
14541                 skip "Need MDS version at least 2.2.51"
14542         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14543         remote_mds_nodsh && skip "remote MDS with nodsh"
14544         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
14545                 skip_env "Need to mount OST to test"
14546         fi
14547
14548         local mds=$(facet_host $SINGLEMDS)
14549         local target=$(do_nodes $mds 'lctl dl' |
14550                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
14551
14552         local cmd1="file_count=1000 thrhi=4"
14553         local cmd2="dir_count=2 layer=mdd stripe_count=1"
14554         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
14555         local cmd="$cmd1 $cmd2 $cmd3"
14556
14557         rm -f ${TMP}/mds_survey*
14558         echo + $cmd
14559         eval $cmd || error "mds-survey with stripe_count failed"
14560         cat ${TMP}/mds_survey*
14561         rm -f ${TMP}/mds_survey*
14562 }
14563 run_test 225b "Metadata survey sanity with stripe_count = 1"
14564
14565 mcreate_path2fid () {
14566         local mode=$1
14567         local major=$2
14568         local minor=$3
14569         local name=$4
14570         local desc=$5
14571         local path=$DIR/$tdir/$name
14572         local fid
14573         local rc
14574         local fid_path
14575
14576         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
14577                 error "cannot create $desc"
14578
14579         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
14580         rc=$?
14581         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
14582
14583         fid_path=$($LFS fid2path $MOUNT $fid)
14584         rc=$?
14585         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
14586
14587         [ "$path" == "$fid_path" ] ||
14588                 error "fid2path returned $fid_path, expected $path"
14589
14590         echo "pass with $path and $fid"
14591 }
14592
14593 test_226a () {
14594         rm -rf $DIR/$tdir
14595         mkdir -p $DIR/$tdir
14596
14597         mcreate_path2fid 0010666 0 0 fifo "FIFO"
14598         mcreate_path2fid 0020666 1 3 null "character special file (null)"
14599         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
14600         mcreate_path2fid 0040666 0 0 dir "directory"
14601         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
14602         mcreate_path2fid 0100666 0 0 file "regular file"
14603         mcreate_path2fid 0120666 0 0 link "symbolic link"
14604         mcreate_path2fid 0140666 0 0 sock "socket"
14605 }
14606 run_test 226a "call path2fid and fid2path on files of all type"
14607
14608 test_226b () {
14609         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14610
14611         local MDTIDX=1
14612
14613         rm -rf $DIR/$tdir
14614         mkdir -p $DIR/$tdir
14615         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
14616                 error "create remote directory failed"
14617         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
14618         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
14619                                 "character special file (null)"
14620         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
14621                                 "character special file (no device)"
14622         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
14623         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
14624                                 "block special file (loop)"
14625         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
14626         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
14627         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
14628 }
14629 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
14630
14631 # LU-1299 Executing or running ldd on a truncated executable does not
14632 # cause an out-of-memory condition.
14633 test_227() {
14634         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14635         [ -z "$(which ldd)" ] && skip_env "should have ldd tool"
14636
14637         dd if=$(which date) of=$MOUNT/date bs=1k count=1
14638         chmod +x $MOUNT/date
14639
14640         $MOUNT/date > /dev/null
14641         ldd $MOUNT/date > /dev/null
14642         rm -f $MOUNT/date
14643 }
14644 run_test 227 "running truncated executable does not cause OOM"
14645
14646 # LU-1512 try to reuse idle OI blocks
14647 test_228a() {
14648         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14649         remote_mds_nodsh && skip "remote MDS with nodsh"
14650         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14651                 skip_env "ldiskfs only test"
14652
14653         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14654         local myDIR=$DIR/$tdir
14655
14656         mkdir -p $myDIR
14657         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14658         $LCTL set_param fail_loc=0x80001002
14659         createmany -o $myDIR/t- 10000
14660         $LCTL set_param fail_loc=0
14661         # The guard is current the largest FID holder
14662         touch $myDIR/guard
14663         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14664                     tr -d '[')
14665         local IDX=$(($SEQ % 64))
14666
14667         do_facet $SINGLEMDS sync
14668         # Make sure journal flushed.
14669         sleep 6
14670         local blk1=$(do_facet $SINGLEMDS \
14671                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14672                      grep Blockcount | awk '{print $4}')
14673
14674         # Remove old files, some OI blocks will become idle.
14675         unlinkmany $myDIR/t- 10000
14676         # Create new files, idle OI blocks should be reused.
14677         createmany -o $myDIR/t- 2000
14678         do_facet $SINGLEMDS sync
14679         # Make sure journal flushed.
14680         sleep 6
14681         local blk2=$(do_facet $SINGLEMDS \
14682                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14683                      grep Blockcount | awk '{print $4}')
14684
14685         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14686 }
14687 run_test 228a "try to reuse idle OI blocks"
14688
14689 test_228b() {
14690         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14691         remote_mds_nodsh && skip "remote MDS with nodsh"
14692         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14693                 skip_env "ldiskfs only test"
14694
14695         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14696         local myDIR=$DIR/$tdir
14697
14698         mkdir -p $myDIR
14699         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14700         $LCTL set_param fail_loc=0x80001002
14701         createmany -o $myDIR/t- 10000
14702         $LCTL set_param fail_loc=0
14703         # The guard is current the largest FID holder
14704         touch $myDIR/guard
14705         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14706                     tr -d '[')
14707         local IDX=$(($SEQ % 64))
14708
14709         do_facet $SINGLEMDS sync
14710         # Make sure journal flushed.
14711         sleep 6
14712         local blk1=$(do_facet $SINGLEMDS \
14713                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14714                      grep Blockcount | awk '{print $4}')
14715
14716         # Remove old files, some OI blocks will become idle.
14717         unlinkmany $myDIR/t- 10000
14718
14719         # stop the MDT
14720         stop $SINGLEMDS || error "Fail to stop MDT."
14721         # remount the MDT
14722         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
14723
14724         df $MOUNT || error "Fail to df."
14725         # Create new files, idle OI blocks should be reused.
14726         createmany -o $myDIR/t- 2000
14727         do_facet $SINGLEMDS sync
14728         # Make sure journal flushed.
14729         sleep 6
14730         local blk2=$(do_facet $SINGLEMDS \
14731                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14732                      grep Blockcount | awk '{print $4}')
14733
14734         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14735 }
14736 run_test 228b "idle OI blocks can be reused after MDT restart"
14737
14738 #LU-1881
14739 test_228c() {
14740         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14741         remote_mds_nodsh && skip "remote MDS with nodsh"
14742         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14743                 skip_env "ldiskfs only test"
14744
14745         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14746         local myDIR=$DIR/$tdir
14747
14748         mkdir -p $myDIR
14749         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14750         $LCTL set_param fail_loc=0x80001002
14751         # 20000 files can guarantee there are index nodes in the OI file
14752         createmany -o $myDIR/t- 20000
14753         $LCTL set_param fail_loc=0
14754         # The guard is current the largest FID holder
14755         touch $myDIR/guard
14756         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14757                     tr -d '[')
14758         local IDX=$(($SEQ % 64))
14759
14760         do_facet $SINGLEMDS sync
14761         # Make sure journal flushed.
14762         sleep 6
14763         local blk1=$(do_facet $SINGLEMDS \
14764                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14765                      grep Blockcount | awk '{print $4}')
14766
14767         # Remove old files, some OI blocks will become idle.
14768         unlinkmany $myDIR/t- 20000
14769         rm -f $myDIR/guard
14770         # The OI file should become empty now
14771
14772         # Create new files, idle OI blocks should be reused.
14773         createmany -o $myDIR/t- 2000
14774         do_facet $SINGLEMDS sync
14775         # Make sure journal flushed.
14776         sleep 6
14777         local blk2=$(do_facet $SINGLEMDS \
14778                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14779                      grep Blockcount | awk '{print $4}')
14780
14781         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14782 }
14783 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
14784
14785 test_229() { # LU-2482, LU-3448
14786         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14787         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
14788         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
14789                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53"
14790
14791         rm -f $DIR/$tfile
14792
14793         # Create a file with a released layout and stripe count 2.
14794         $MULTIOP $DIR/$tfile H2c ||
14795                 error "failed to create file with released layout"
14796
14797         $GETSTRIPE -v $DIR/$tfile
14798
14799         local pattern=$($GETSTRIPE -L $DIR/$tfile)
14800         [ X"$pattern" = X"released" ] || error "pattern error ($pattern)"
14801
14802         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
14803         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
14804         stat $DIR/$tfile || error "failed to stat released file"
14805
14806         chown $RUNAS_ID $DIR/$tfile ||
14807                 error "chown $RUNAS_ID $DIR/$tfile failed"
14808
14809         chgrp $RUNAS_ID $DIR/$tfile ||
14810                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
14811
14812         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
14813         rm $DIR/$tfile || error "failed to remove released file"
14814 }
14815 run_test 229 "getstripe/stat/rm/attr changes work on released files"
14816
14817 test_230a() {
14818         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14819         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14820
14821         local MDTIDX=1
14822
14823         test_mkdir $DIR/$tdir
14824         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
14825         local mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230_local)
14826         [ $mdt_idx -ne 0 ] &&
14827                 error "create local directory on wrong MDT $mdt_idx"
14828
14829         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
14830                         error "create remote directory failed"
14831         local mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230)
14832         [ $mdt_idx -ne $MDTIDX ] &&
14833                 error "create remote directory on wrong MDT $mdt_idx"
14834
14835         createmany -o $DIR/$tdir/test_230/t- 10 ||
14836                 error "create files on remote directory failed"
14837         mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230/t-0)
14838         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
14839         rm -r $DIR/$tdir || error "unlink remote directory failed"
14840 }
14841 run_test 230a "Create remote directory and files under the remote directory"
14842
14843 test_230b() {
14844         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14845         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14846
14847         local MDTIDX=1
14848         local mdt_index
14849         local i
14850         local file
14851         local pid
14852         local stripe_count
14853         local migrate_dir=$DIR/$tdir/migrate_dir
14854         local other_dir=$DIR/$tdir/other_dir
14855
14856         test_mkdir $DIR/$tdir
14857         test_mkdir -i0 -c1 $migrate_dir
14858         test_mkdir -i0 -c1 $other_dir
14859         for ((i=0; i<10; i++)); do
14860                 mkdir -p $migrate_dir/dir_${i}
14861                 createmany -o $migrate_dir/dir_${i}/f 10 ||
14862                         error "create files under remote dir failed $i"
14863         done
14864
14865         cp /etc/passwd $migrate_dir/$tfile
14866         cp /etc/passwd $other_dir/$tfile
14867         chattr +SAD $migrate_dir
14868         chattr +SAD $migrate_dir/$tfile
14869
14870         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14871         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14872         local old_dir_mode=$(stat -c%f $migrate_dir)
14873         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
14874
14875         mkdir -p $migrate_dir/dir_default_stripe2
14876         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
14877         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
14878
14879         mkdir -p $other_dir
14880         ln $migrate_dir/$tfile $other_dir/luna
14881         ln $migrate_dir/$tfile $migrate_dir/sofia
14882         ln $other_dir/$tfile $migrate_dir/david
14883         ln -s $migrate_dir/$tfile $other_dir/zachary
14884         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
14885         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
14886
14887         $LFS migrate -m $MDTIDX $migrate_dir ||
14888                 error "fails on migrating remote dir to MDT1"
14889
14890         echo "migratate to MDT1, then checking.."
14891         for ((i = 0; i < 10; i++)); do
14892                 for file in $(find $migrate_dir/dir_${i}); do
14893                         mdt_index=$($LFS getstripe -m $file)
14894                         [ $mdt_index == $MDTIDX ] ||
14895                                 error "$file is not on MDT${MDTIDX}"
14896                 done
14897         done
14898
14899         # the multiple link file should still in MDT0
14900         mdt_index=$($LFS getstripe -m $migrate_dir/$tfile)
14901         [ $mdt_index == 0 ] ||
14902                 error "$file is not on MDT${MDTIDX}"
14903
14904         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14905         [ "$old_dir_flag" = "$new_dir_flag" ] ||
14906                 error " expect $old_dir_flag get $new_dir_flag"
14907
14908         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14909         [ "$old_file_flag" = "$new_file_flag" ] ||
14910                 error " expect $old_file_flag get $new_file_flag"
14911
14912         local new_dir_mode=$(stat -c%f $migrate_dir)
14913         [ "$old_dir_mode" = "$new_dir_mode" ] ||
14914                 error "expect mode $old_dir_mode get $new_dir_mode"
14915
14916         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
14917         [ "$old_file_mode" = "$new_file_mode" ] ||
14918                 error "expect mode $old_file_mode get $new_file_mode"
14919
14920         diff /etc/passwd $migrate_dir/$tfile ||
14921                 error "$tfile different after migration"
14922
14923         diff /etc/passwd $other_dir/luna ||
14924                 error "luna different after migration"
14925
14926         diff /etc/passwd $migrate_dir/sofia ||
14927                 error "sofia different after migration"
14928
14929         diff /etc/passwd $migrate_dir/david ||
14930                 error "david different after migration"
14931
14932         diff /etc/passwd $other_dir/zachary ||
14933                 error "zachary different after migration"
14934
14935         diff /etc/passwd $migrate_dir/${tfile}_ln ||
14936                 error "${tfile}_ln different after migration"
14937
14938         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
14939                 error "${tfile}_ln_other different after migration"
14940
14941         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
14942         [ $stripe_count = 2 ] ||
14943                 error "dir strpe_count $d != 2 after migration."
14944
14945         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
14946         [ $stripe_count = 2 ] ||
14947                 error "file strpe_count $d != 2 after migration."
14948
14949         #migrate back to MDT0
14950         MDTIDX=0
14951
14952         $LFS migrate -m $MDTIDX $migrate_dir ||
14953                 error "fails on migrating remote dir to MDT0"
14954
14955         echo "migrate back to MDT0, checking.."
14956         for file in $(find $migrate_dir); do
14957                 mdt_index=$($LFS getstripe -m $file)
14958                 [ $mdt_index == $MDTIDX ] ||
14959                         error "$file is not on MDT${MDTIDX}"
14960         done
14961
14962         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14963         [ "$old_dir_flag" = "$new_dir_flag" ] ||
14964                 error " expect $old_dir_flag get $new_dir_flag"
14965
14966         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14967         [ "$old_file_flag" = "$new_file_flag" ] ||
14968                 error " expect $old_file_flag get $new_file_flag"
14969
14970         local new_dir_mode=$(stat -c%f $migrate_dir)
14971         [ "$old_dir_mode" = "$new_dir_mode" ] ||
14972                 error "expect mode $old_dir_mode get $new_dir_mode"
14973
14974         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
14975         [ "$old_file_mode" = "$new_file_mode" ] ||
14976                 error "expect mode $old_file_mode get $new_file_mode"
14977
14978         diff /etc/passwd ${migrate_dir}/$tfile ||
14979                 error "$tfile different after migration"
14980
14981         diff /etc/passwd ${other_dir}/luna ||
14982                 error "luna different after migration"
14983
14984         diff /etc/passwd ${migrate_dir}/sofia ||
14985                 error "sofia different after migration"
14986
14987         diff /etc/passwd ${other_dir}/zachary ||
14988                 error "zachary different after migration"
14989
14990         diff /etc/passwd $migrate_dir/${tfile}_ln ||
14991                 error "${tfile}_ln different after migration"
14992
14993         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
14994                 error "${tfile}_ln_other different after migration"
14995
14996         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
14997         [ $stripe_count = 2 ] ||
14998                 error "dir strpe_count $d != 2 after migration."
14999
15000         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
15001         [ $stripe_count = 2 ] ||
15002                 error "file strpe_count $d != 2 after migration."
15003
15004         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15005 }
15006 run_test 230b "migrate directory"
15007
15008 test_230c() {
15009         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15010         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15011         remote_mds_nodsh && skip "remote MDS with nodsh"
15012
15013         local MDTIDX=1
15014         local mdt_index
15015         local file
15016         local migrate_dir=$DIR/$tdir/migrate_dir
15017
15018         #If migrating directory fails in the middle, all entries of
15019         #the directory is still accessiable.
15020         test_mkdir $DIR/$tdir
15021         test_mkdir -i0 -c1 $migrate_dir
15022         stat $migrate_dir
15023         createmany -o $migrate_dir/f 10 ||
15024                 error "create files under ${migrate_dir} failed"
15025
15026         #failed after migrating 5 entries
15027         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
15028         do_facet mds1 lctl set_param fail_loc=0x20001801
15029         do_facet mds1 lctl  set_param fail_val=5
15030         local t=$(ls $migrate_dir | wc -l)
15031         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
15032                 error "migrate should fail after 5 entries"
15033
15034         mkdir $migrate_dir/dir &&
15035                 error "mkdir succeeds under migrating directory"
15036         touch $migrate_dir/file &&
15037                 error "touch file succeeds under migrating directory"
15038
15039         local u=$(ls $migrate_dir | wc -l)
15040         [ "$u" == "$t" ] || error "$u != $t during migration"
15041
15042         for file in $(find $migrate_dir); do
15043                 stat $file || error "stat $file failed"
15044         done
15045
15046         do_facet mds1 lctl set_param fail_loc=0
15047         do_facet mds1 lctl set_param fail_val=0
15048
15049         $LFS migrate -m $MDTIDX $migrate_dir ||
15050                 error "migrate open files should failed with open files"
15051
15052         echo "Finish migration, then checking.."
15053         for file in $(find $migrate_dir); do
15054                 mdt_index=$($LFS getstripe -m $file)
15055                 [ $mdt_index == $MDTIDX ] ||
15056                         error "$file is not on MDT${MDTIDX}"
15057         done
15058
15059         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15060 }
15061 run_test 230c "check directory accessiblity if migration is failed"
15062
15063 test_230d() {
15064         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15065         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15066
15067         local MDTIDX=1
15068         local mdt_index
15069         local migrate_dir=$DIR/$tdir/migrate_dir
15070         local i
15071         local j
15072
15073         test_mkdir $DIR/$tdir
15074         test_mkdir -i0 -c1 $migrate_dir
15075
15076         for ((i=0; i<100; i++)); do
15077                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
15078                 createmany -o $migrate_dir/dir_${i}/f 100 ||
15079                         error "create files under remote dir failed $i"
15080         done
15081
15082         $LFS migrate -m $MDTIDX $migrate_dir ||
15083                 error "migrate remote dir error"
15084
15085         echo "Finish migration, then checking.."
15086         for file in $(find $migrate_dir); do
15087                 mdt_index=$($LFS getstripe -m $file)
15088                 [ $mdt_index == $MDTIDX ] ||
15089                         error "$file is not on MDT${MDTIDX}"
15090         done
15091
15092         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15093 }
15094 run_test 230d "check migrate big directory"
15095
15096 test_230e() {
15097         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15098         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15099
15100         local i
15101         local j
15102         local a_fid
15103         local b_fid
15104
15105         mkdir -p $DIR/$tdir
15106         mkdir $DIR/$tdir/migrate_dir
15107         mkdir $DIR/$tdir/other_dir
15108         touch $DIR/$tdir/migrate_dir/a
15109         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
15110         ls $DIR/$tdir/other_dir
15111
15112         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
15113                 error "migrate dir fails"
15114
15115         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
15116         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
15117
15118         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15119         [ $mdt_index == 0 ] || error "a is not on MDT0"
15120
15121         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
15122                 error "migrate dir fails"
15123
15124         mdt_index=$($LFS getstripe -m $DIR/$tdir/other_dir)
15125         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
15126
15127         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15128         [ $mdt_index == 1 ] || error "a is not on MDT1"
15129
15130         mdt_index=$($LFS getstripe -m $DIR/$tdir/other_dir/b)
15131         [ $mdt_index == 1 ] || error "b is not on MDT1"
15132
15133         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
15134         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
15135
15136         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
15137
15138         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15139 }
15140 run_test 230e "migrate mulitple local link files"
15141
15142 test_230f() {
15143         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15144         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15145
15146         local a_fid
15147         local ln_fid
15148
15149         mkdir -p $DIR/$tdir
15150         mkdir $DIR/$tdir/migrate_dir
15151         $LFS mkdir -i1 $DIR/$tdir/other_dir
15152         touch $DIR/$tdir/migrate_dir/a
15153         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
15154         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
15155         ls $DIR/$tdir/other_dir
15156
15157         # a should be migrated to MDT1, since no other links on MDT0
15158         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
15159                 error "#1 migrate dir fails"
15160         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
15161         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
15162         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15163         [ $mdt_index == 1 ] || error "a is not on MDT1"
15164
15165         # a should stay on MDT1, because it is a mulitple link file
15166         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
15167                 error "#2 migrate dir fails"
15168         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15169         [ $mdt_index == 1 ] || error "a is not on MDT1"
15170
15171         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
15172                 error "#3 migrate dir fails"
15173
15174         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
15175         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
15176         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
15177
15178         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
15179         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
15180
15181         # a should be migrated to MDT0, since no other links on MDT1
15182         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
15183                 error "#4 migrate dir fails"
15184         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
15185         [ $mdt_index == 0 ] || error "a is not on MDT0"
15186
15187         rm -rf $DIR/$tdir || error "rm dir failed after migration"
15188 }
15189 run_test 230f "migrate mulitple remote link files"
15190
15191 test_230g() {
15192         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15193         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15194
15195         mkdir -p $DIR/$tdir/migrate_dir
15196
15197         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
15198                 error "migrating dir to non-exist MDT succeeds"
15199         true
15200 }
15201 run_test 230g "migrate dir to non-exist MDT"
15202
15203 test_230h() {
15204         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15205         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15206         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
15207                 skip "Need MDS version at least 2.7.64"
15208
15209         local mdt_index
15210
15211         mkdir -p $DIR/$tdir/migrate_dir
15212
15213         $LFS migrate -m1 $DIR &&
15214                 error "migrating mountpoint1 should fail"
15215
15216         $LFS migrate -m1 $DIR/$tdir/.. &&
15217                 error "migrating mountpoint2 should fail"
15218
15219         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
15220                 error "migrating $tdir fail"
15221
15222         mdt_index=$($LFS getstripe -m $DIR/$tdir)
15223         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
15224
15225         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
15226         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
15227
15228 }
15229 run_test 230h "migrate .. and root"
15230
15231 test_230i() {
15232         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15233         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15234
15235         mkdir -p $DIR/$tdir/migrate_dir
15236
15237         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
15238                 error "migration fails with a tailing slash"
15239
15240         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
15241                 error "migration fails with two tailing slashes"
15242 }
15243 run_test 230i "lfs migrate -m tolerates trailing slashes"
15244
15245 test_231a()
15246 {
15247         # For simplicity this test assumes that max_pages_per_rpc
15248         # is the same across all OSCs
15249         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
15250         local bulk_size=$((max_pages * 4096))
15251         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
15252                                        head -n 1)
15253
15254         mkdir -p $DIR/$tdir
15255         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
15256                 error "failed to set stripe with -S ${brw_size}M option"
15257
15258         # clear the OSC stats
15259         $LCTL set_param osc.*.stats=0 &>/dev/null
15260         stop_writeback
15261
15262         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
15263         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
15264                 oflag=direct &>/dev/null || error "dd failed"
15265
15266         sync; sleep 1; sync # just to be safe
15267         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
15268         if [ x$nrpcs != "x1" ]; then
15269                 $LCTL get_param osc.*.stats
15270                 error "found $nrpcs ost_write RPCs, not 1 as expected"
15271         fi
15272
15273         start_writeback
15274         # Drop the OSC cache, otherwise we will read from it
15275         cancel_lru_locks osc
15276
15277         # clear the OSC stats
15278         $LCTL set_param osc.*.stats=0 &>/dev/null
15279
15280         # Client reads $bulk_size.
15281         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
15282                 iflag=direct &>/dev/null || error "dd failed"
15283
15284         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
15285         if [ x$nrpcs != "x1" ]; then
15286                 $LCTL get_param osc.*.stats
15287                 error "found $nrpcs ost_read RPCs, not 1 as expected"
15288         fi
15289 }
15290 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
15291
15292 test_231b() {
15293         mkdir -p $DIR/$tdir
15294         local i
15295         for i in {0..1023}; do
15296                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
15297                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
15298                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
15299         done
15300         sync
15301 }
15302 run_test 231b "must not assert on fully utilized OST request buffer"
15303
15304 test_232a() {
15305         mkdir -p $DIR/$tdir
15306         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
15307
15308         #define OBD_FAIL_LDLM_OST_LVB            0x31c
15309         do_facet ost1 $LCTL set_param fail_loc=0x31c
15310
15311         # ignore dd failure
15312         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
15313
15314         do_facet ost1 $LCTL set_param fail_loc=0
15315         umount_client $MOUNT || error "umount failed"
15316         mount_client $MOUNT || error "mount failed"
15317         stop ost1 || error "cannot stop ost1"
15318         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
15319 }
15320 run_test 232a "failed lock should not block umount"
15321
15322 test_232b() {
15323         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.58) ] ||
15324                 skip "Need MDS version at least 2.10.58"
15325
15326         mkdir -p $DIR/$tdir
15327         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
15328         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1
15329         sync
15330         cancel_lru_locks osc
15331
15332         #define OBD_FAIL_LDLM_OST_LVB            0x31c
15333         do_facet ost1 $LCTL set_param fail_loc=0x31c
15334
15335         # ignore failure
15336         $LFS data_version $DIR/$tdir/$tfile || true
15337
15338         do_facet ost1 $LCTL set_param fail_loc=0
15339         umount_client $MOUNT || error "umount failed"
15340         mount_client $MOUNT || error "mount failed"
15341         stop ost1 || error "cannot stop ost1"
15342         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
15343 }
15344 run_test 232b "failed data version lock should not block umount"
15345
15346 test_233a() {
15347         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
15348                 skip "Need MDS version at least 2.3.64"
15349         [ -n "$FILESET" ] && skip_env "SKIP due to FILESET set"
15350
15351         local fid=$($LFS path2fid $MOUNT)
15352
15353         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
15354                 error "cannot access $MOUNT using its FID '$fid'"
15355 }
15356 run_test 233a "checking that OBF of the FS root succeeds"
15357
15358 test_233b() {
15359         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
15360                 skip "Need MDS version at least 2.5.90"
15361         [ -n "$FILESET" ] && skip_env "SKIP due to FILESET set"
15362
15363         local fid=$($LFS path2fid $MOUNT/.lustre)
15364
15365         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
15366                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
15367
15368         fid=$($LFS path2fid $MOUNT/.lustre/fid)
15369         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
15370                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
15371 }
15372 run_test 233b "checking that OBF of the FS .lustre succeeds"
15373
15374 test_234() {
15375         local p="$TMP/sanityN-$TESTNAME.parameters"
15376         save_lustre_params client "llite.*.xattr_cache" > $p
15377         lctl set_param llite.*.xattr_cache 1 ||
15378                 skip_env "xattr cache is not supported"
15379
15380         mkdir -p $DIR/$tdir || error "mkdir failed"
15381         touch $DIR/$tdir/$tfile || error "touch failed"
15382         # OBD_FAIL_LLITE_XATTR_ENOMEM
15383         $LCTL set_param fail_loc=0x1405
15384         getfattr -n user.attr $DIR/$tdir/$tfile &&
15385                 error "getfattr should have failed with ENOMEM"
15386         $LCTL set_param fail_loc=0x0
15387         rm -rf $DIR/$tdir
15388
15389         restore_lustre_params < $p
15390         rm -f $p
15391 }
15392 run_test 234 "xattr cache should not crash on ENOMEM"
15393
15394 test_235() {
15395         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
15396                 skip "Need MDS version at least 2.4.52"
15397
15398         flock_deadlock $DIR/$tfile
15399         local RC=$?
15400         case $RC in
15401                 0)
15402                 ;;
15403                 124) error "process hangs on a deadlock"
15404                 ;;
15405                 *) error "error executing flock_deadlock $DIR/$tfile"
15406                 ;;
15407         esac
15408 }
15409 run_test 235 "LU-1715: flock deadlock detection does not work properly"
15410
15411 #LU-2935
15412 test_236() {
15413         check_swap_layouts_support
15414
15415         local ref1=/etc/passwd
15416         local ref2=/etc/group
15417         local file1=$DIR/$tdir/f1
15418         local file2=$DIR/$tdir/f2
15419
15420         test_mkdir -c1 $DIR/$tdir
15421         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
15422         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
15423         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
15424         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
15425         local fd=$(free_fd)
15426         local cmd="exec $fd<>$file2"
15427         eval $cmd
15428         rm $file2
15429         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
15430                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
15431         cmd="exec $fd>&-"
15432         eval $cmd
15433         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
15434
15435         #cleanup
15436         rm -rf $DIR/$tdir
15437 }
15438 run_test 236 "Layout swap on open unlinked file"
15439
15440 # test to verify file handle related system calls
15441 # (name_to_handle_at/open_by_handle_at)
15442 # The new system calls are supported in glibc >= 2.14.
15443
15444 test_237() {
15445         echo "Test file_handle syscalls" > $DIR/$tfile ||
15446                 error "write failed"
15447         check_fhandle_syscalls $DIR/$tfile ||
15448                 error "check_fhandle_syscalls failed"
15449 }
15450 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
15451
15452 # LU-4659 linkea consistency
15453 test_238() {
15454         local server_version=$(lustre_version_code $SINGLEMDS)
15455
15456         [[ $server_version -gt $(version_code 2.5.57) ]] ||
15457                 [[ $server_version -gt $(version_code 2.5.1) &&
15458                    $server_version -lt $(version_code 2.5.50) ]] ||
15459                 skip "Need MDS version at least 2.5.58 or 2.5.2+"
15460
15461         touch $DIR/$tfile
15462         ln $DIR/$tfile $DIR/$tfile.lnk
15463         touch $DIR/$tfile.new
15464         mv $DIR/$tfile.new $DIR/$tfile
15465         local fid1=$($LFS path2fid $DIR/$tfile)
15466         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
15467         local path1=$($LFS fid2path $FSNAME "$fid1")
15468         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
15469         local path2=$($LFS fid2path $FSNAME "$fid2")
15470         [ $tfile.lnk == $path2 ] ||
15471                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
15472         rm -f $DIR/$tfile*
15473 }
15474 run_test 238 "Verify linkea consistency"
15475
15476 test_239A() { # was test_239
15477         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
15478                 skip "Need MDS version at least 2.5.60"
15479
15480         local list=$(comma_list $(mdts_nodes))
15481
15482         mkdir -p $DIR/$tdir
15483         createmany -o $DIR/$tdir/f- 5000
15484         unlinkmany $DIR/$tdir/f- 5000
15485         [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ] &&
15486                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
15487         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
15488                         osp.*MDT*.sync_in_flight" | calc_sum)
15489         [ "$changes" -eq 0 ] || error "$changes not synced"
15490 }
15491 run_test 239A "osp_sync test"
15492
15493 test_239a() { #LU-5297
15494         remote_mds_nodsh && skip "remote MDS with nodsh"
15495
15496         touch $DIR/$tfile
15497         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
15498         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
15499         chgrp $RUNAS_GID $DIR/$tfile
15500         wait_delete_completed
15501 }
15502 run_test 239a "process invalid osp sync record correctly"
15503
15504 test_239b() { #LU-5297
15505         remote_mds_nodsh && skip "remote MDS with nodsh"
15506
15507         touch $DIR/$tfile1
15508         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
15509         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
15510         chgrp $RUNAS_GID $DIR/$tfile1
15511         wait_delete_completed
15512         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
15513         touch $DIR/$tfile2
15514         chgrp $RUNAS_GID $DIR/$tfile2
15515         wait_delete_completed
15516 }
15517 run_test 239b "process osp sync record with ENOMEM error correctly"
15518
15519 test_240() {
15520         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
15521         remote_mds_nodsh && skip "remote MDS with nodsh"
15522
15523         mkdir -p $DIR/$tdir
15524
15525         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
15526                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
15527         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
15528                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
15529
15530         umount_client $MOUNT || error "umount failed"
15531         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
15532         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
15533         mount_client $MOUNT || error "failed to mount client"
15534
15535         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
15536         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
15537 }
15538 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
15539
15540 test_241_bio() {
15541         for LOOP in $(seq $1); do
15542                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
15543                 cancel_lru_locks $OSC || true
15544         done
15545 }
15546
15547 test_241_dio() {
15548         for LOOP in $(seq $1); do
15549                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
15550                                                 iflag=direct 2>/dev/null
15551         done
15552 }
15553
15554 test_241a() { # was test_241
15555         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
15556         ls -la $DIR/$tfile
15557         cancel_lru_locks $OSC
15558         test_241_bio 1000 &
15559         PID=$!
15560         test_241_dio 1000
15561         wait $PID
15562 }
15563 run_test 241a "bio vs dio"
15564
15565 test_241b() {
15566         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
15567         ls -la $DIR/$tfile
15568         test_241_dio 1000 &
15569         PID=$!
15570         test_241_dio 1000
15571         wait $PID
15572 }
15573 run_test 241b "dio vs dio"
15574
15575 test_242() {
15576         remote_mds_nodsh && skip "remote MDS with nodsh"
15577
15578         mkdir -p $DIR/$tdir
15579         touch $DIR/$tdir/$tfile
15580
15581         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
15582         do_facet mds1 lctl set_param fail_loc=0x105
15583         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
15584
15585         do_facet mds1 lctl set_param fail_loc=0
15586         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
15587 }
15588 run_test 242 "mdt_readpage failure should not cause directory unreadable"
15589
15590 test_243()
15591 {
15592         test_mkdir $DIR/$tdir
15593         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
15594 }
15595 run_test 243 "various group lock tests"
15596
15597 test_244()
15598 {
15599         test_mkdir $DIR/$tdir
15600         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
15601         sendfile_grouplock $DIR/$tdir/$tfile || \
15602                 error "sendfile+grouplock failed"
15603         rm -rf $DIR/$tdir
15604 }
15605 run_test 244 "sendfile with group lock tests"
15606
15607 test_245() {
15608         local flagname="multi_mod_rpcs"
15609         local connect_data_name="max_mod_rpcs"
15610         local out
15611
15612         # check if multiple modify RPCs flag is set
15613         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
15614                 grep "connect_flags:")
15615         echo "$out"
15616
15617         echo "$out" | grep -qw $flagname
15618         if [ $? -ne 0 ]; then
15619                 echo "connect flag $flagname is not set"
15620                 return
15621         fi
15622
15623         # check if multiple modify RPCs data is set
15624         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
15625         echo "$out"
15626
15627         echo "$out" | grep -qw $connect_data_name ||
15628                 error "import should have connect data $connect_data_name"
15629 }
15630 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
15631
15632 test_246() { # LU-7371
15633         remote_ost_nodsh && skip "remote OST with nodsh"
15634         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
15635                 skip "Need OST version >= 2.7.62"
15636
15637         do_facet ost1 $LCTL set_param fail_val=4095
15638 #define OBD_FAIL_OST_READ_SIZE          0x234
15639         do_facet ost1 $LCTL set_param fail_loc=0x234
15640         $LFS setstripe $DIR/$tfile -i 0 -c 1
15641         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
15642         cancel_lru_locks $FSNAME-OST0000
15643         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
15644 }
15645 run_test 246 "Read file of size 4095 should return right length"
15646
15647 cleanup_247() {
15648         local submount=$1
15649
15650         trap 0
15651         umount_client $submount
15652         rmdir $submount
15653 }
15654
15655 test_247a() {
15656         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
15657                 grep -q subtree ||
15658                 skip_env "Fileset feature is not supported"
15659
15660         local submount=${MOUNT}_$tdir
15661
15662         mkdir $MOUNT/$tdir
15663         mkdir -p $submount || error "mkdir $submount failed"
15664         FILESET="$FILESET/$tdir" mount_client $submount ||
15665                 error "mount $submount failed"
15666         trap "cleanup_247 $submount" EXIT
15667         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
15668         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
15669                 error "read $MOUNT/$tdir/$tfile failed"
15670         cleanup_247 $submount
15671 }
15672 run_test 247a "mount subdir as fileset"
15673
15674 test_247b() {
15675         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15676                 skip_env "Fileset feature is not supported"
15677
15678         local submount=${MOUNT}_$tdir
15679
15680         rm -rf $MOUNT/$tdir
15681         mkdir -p $submount || error "mkdir $submount failed"
15682         SKIP_FILESET=1
15683         FILESET="$FILESET/$tdir" mount_client $submount &&
15684                 error "mount $submount should fail"
15685         rmdir $submount
15686 }
15687 run_test 247b "mount subdir that dose not exist"
15688
15689 test_247c() {
15690         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15691                 skip_env "Fileset feature is not supported"
15692
15693         local submount=${MOUNT}_$tdir
15694
15695         mkdir -p $MOUNT/$tdir/dir1
15696         mkdir -p $submount || error "mkdir $submount failed"
15697         trap "cleanup_247 $submount" EXIT
15698         FILESET="$FILESET/$tdir" mount_client $submount ||
15699                 error "mount $submount failed"
15700         local fid=$($LFS path2fid $MOUNT/)
15701         $LFS fid2path $submount $fid && error "fid2path should fail"
15702         cleanup_247 $submount
15703 }
15704 run_test 247c "running fid2path outside root"
15705
15706 test_247d() {
15707         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15708                 skip "Fileset feature is not supported"
15709
15710         local submount=${MOUNT}_$tdir
15711
15712         mkdir -p $MOUNT/$tdir/dir1
15713         mkdir -p $submount || error "mkdir $submount failed"
15714         FILESET="$FILESET/$tdir" mount_client $submount ||
15715                 error "mount $submount failed"
15716         trap "cleanup_247 $submount" EXIT
15717         local fid=$($LFS path2fid $submount/dir1)
15718         $LFS fid2path $submount $fid || error "fid2path should succeed"
15719         cleanup_247 $submount
15720 }
15721 run_test 247d "running fid2path inside root"
15722
15723 # LU-8037
15724 test_247e() {
15725         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
15726                 grep -q subtree ||
15727                 skip "Fileset feature is not supported"
15728
15729         local submount=${MOUNT}_$tdir
15730
15731         mkdir $MOUNT/$tdir
15732         mkdir -p $submount || error "mkdir $submount failed"
15733         FILESET="$FILESET/.." mount_client $submount &&
15734                 error "mount $submount should fail"
15735         rmdir $submount
15736 }
15737 run_test 247e "mount .. as fileset"
15738
15739 test_248() {
15740         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
15741         [ -z "$fast_read_sav" ] && skip "no fast read support"
15742
15743         # create a large file for fast read verification
15744         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
15745
15746         # make sure the file is created correctly
15747         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
15748                 { rm -f $DIR/$tfile; skip "file creation error"; }
15749
15750         echo "Test 1: verify that fast read is 4 times faster on cache read"
15751
15752         # small read with fast read enabled
15753         $LCTL set_param -n llite.*.fast_read=1
15754         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
15755                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15756                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15757         # small read with fast read disabled
15758         $LCTL set_param -n llite.*.fast_read=0
15759         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
15760                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15761                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15762
15763         # verify that fast read is 4 times faster for cache read
15764         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
15765                 error_not_in_vm "fast read was not 4 times faster: " \
15766                            "$t_fast vs $t_slow"
15767
15768         echo "Test 2: verify the performance between big and small read"
15769         $LCTL set_param -n llite.*.fast_read=1
15770
15771         # 1k non-cache read
15772         cancel_lru_locks osc
15773         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
15774                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15775                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15776
15777         # 1M non-cache read
15778         cancel_lru_locks osc
15779         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
15780                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15781                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15782
15783         # verify that big IO is not 4 times faster than small IO
15784         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
15785                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
15786
15787         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
15788         rm -f $DIR/$tfile
15789 }
15790 run_test 248 "fast read verification"
15791
15792 test_249() { # LU-7890
15793         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
15794                 skip "Need at least version 2.8.54"
15795
15796         rm -f $DIR/$tfile
15797         $SETSTRIPE -c 1 $DIR/$tfile
15798         # Offset 2T == 4k * 512M
15799         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
15800                 error "dd to 2T offset failed"
15801 }
15802 run_test 249 "Write above 2T file size"
15803
15804 test_250() {
15805         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
15806          && skip "no 16TB file size limit on ZFS"
15807
15808         $SETSTRIPE -c 1 $DIR/$tfile
15809         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
15810         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
15811         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
15812         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
15813                 conv=notrunc,fsync && error "append succeeded"
15814         return 0
15815 }
15816 run_test 250 "Write above 16T limit"
15817
15818 test_251() {
15819         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
15820
15821         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
15822         #Skip once - writing the first stripe will succeed
15823         $LCTL set_param fail_loc=0xa0001407 fail_val=1
15824         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
15825                 error "short write happened"
15826
15827         $LCTL set_param fail_loc=0xa0001407 fail_val=1
15828         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
15829                 error "short read happened"
15830
15831         rm -f $DIR/$tfile
15832 }
15833 run_test 251 "Handling short read and write correctly"
15834
15835 test_252() {
15836         remote_mds_nodsh && skip "remote MDS with nodsh"
15837         remote_ost_nodsh && skip "remote OST with nodsh"
15838         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
15839              "$(facet_fstype mds1)" != "ldiskfs" ]; then
15840                 skip_env "ldiskfs only test"
15841         fi
15842
15843         local tgt
15844         local dev
15845         local out
15846         local uuid
15847         local num
15848         local gen
15849
15850         # check lr_reader on OST0000
15851         tgt=ost1
15852         dev=$(facet_device $tgt)
15853         out=$(do_facet $tgt $LR_READER $dev)
15854         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15855         echo "$out"
15856         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
15857         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
15858                 error "Invalid uuid returned by $LR_READER on target $tgt"
15859         echo -e "uuid returned by $LR_READER is '$uuid'\n"
15860
15861         # check lr_reader -c on MDT0000
15862         tgt=mds1
15863         dev=$(facet_device $tgt)
15864         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
15865                 skip "$LR_READER does not support additional options"
15866         fi
15867         out=$(do_facet $tgt $LR_READER -c $dev)
15868         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15869         echo "$out"
15870         num=$(echo "$out" | grep -c "mdtlov")
15871         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
15872                 error "Invalid number of mdtlov clients returned by $LR_READER"
15873         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
15874
15875         # check lr_reader -cr on MDT0000
15876         out=$(do_facet $tgt $LR_READER -cr $dev)
15877         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15878         echo "$out"
15879         echo "$out" | grep -q "^reply_data:$" ||
15880                 error "$LR_READER should have returned 'reply_data' section"
15881         num=$(echo "$out" | grep -c "client_generation")
15882         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
15883 }
15884 run_test 252 "check lr_reader tool"
15885
15886 test_253_fill_ost() {
15887         local size_mb #how many MB should we write to pass watermark
15888         local lwm=$3  #low watermark
15889         local free_10mb #10% of free space
15890
15891         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
15892         size_mb=$((free_kb / 1024 - lwm))
15893         free_10mb=$((free_kb / 10240))
15894         #If 10% of free space cross low watermark use it
15895         if (( free_10mb > size_mb )); then
15896                 size_mb=$free_10mb
15897         else
15898                 #At least we need to store 1.1 of difference between
15899                 #free space and low watermark
15900                 size_mb=$((size_mb + size_mb / 10))
15901         fi
15902         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
15903                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
15904                          oflag=append conv=notrunc
15905         fi
15906
15907         sleep_maxage
15908
15909         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
15910         echo "OST still has $((free_kb / 1024)) mbytes free"
15911 }
15912
15913 test_253() {
15914         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15915         remote_mds_nodsh && skip "remote MDS with nodsh"
15916         remote_mgs_nodsh && skip "remote MGS with nodsh"
15917
15918         local ostidx=0
15919         local rc=0
15920
15921         local ost_name=$($LFS osts |
15922                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
15923         # on the mdt's osc
15924         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
15925         do_facet $SINGLEMDS $LCTL get_param -n \
15926                 osp.$mdtosc_proc1.reserved_mb_high ||
15927                 skip  "remote MDS does not support reserved_mb_high"
15928
15929         rm -rf $DIR/$tdir
15930         wait_mds_ost_sync
15931         wait_delete_completed
15932         mkdir $DIR/$tdir
15933
15934         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
15935                         osp.$mdtosc_proc1.reserved_mb_high)
15936         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
15937                         osp.$mdtosc_proc1.reserved_mb_low)
15938         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
15939
15940         if ! combined_mgs_mds ; then
15941                 mount_mgs_client
15942         fi
15943         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
15944         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
15945                 error "Adding $ost_name to pool failed"
15946
15947         # Wait for client to see a OST at pool
15948         wait_update $HOSTNAME "$LCTL get_param -n
15949                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
15950                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
15951                 error "Client can not see the pool"
15952         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
15953                 error "Setstripe failed"
15954
15955         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
15956         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
15957         echo "OST still has $((blocks/1024)) mbytes free"
15958
15959         local new_lwm=$((blocks/1024-10))
15960         do_facet $SINGLEMDS $LCTL set_param \
15961                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
15962         do_facet $SINGLEMDS $LCTL set_param \
15963                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
15964
15965         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
15966
15967         #First enospc could execute orphan deletion so repeat.
15968         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
15969
15970         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
15971                         osp.$mdtosc_proc1.prealloc_status)
15972         echo "prealloc_status $oa_status"
15973
15974         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
15975                 error "File creation should fail"
15976         #object allocation was stopped, but we still able to append files
15977         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
15978                 error "Append failed"
15979         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
15980
15981         wait_delete_completed
15982
15983         sleep_maxage
15984
15985         for i in $(seq 10 12); do
15986                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
15987                         error "File creation failed after rm";
15988         done
15989
15990         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
15991                         osp.$mdtosc_proc1.prealloc_status)
15992         echo "prealloc_status $oa_status"
15993
15994         if (( oa_status != 0 )); then
15995                 error "Object allocation still disable after rm"
15996         fi
15997         do_facet $SINGLEMDS $LCTL set_param \
15998                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
15999         do_facet $SINGLEMDS $LCTL set_param \
16000                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
16001
16002
16003         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
16004                 error "Remove $ost_name from pool failed"
16005         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
16006                 error "Pool destroy fialed"
16007
16008         if ! combined_mgs_mds ; then
16009                 umount_mgs_client
16010         fi
16011 }
16012 run_test 253 "Check object allocation limit"
16013
16014 test_254() {
16015         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16016         remote_mds_nodsh && skip "remote MDS with nodsh"
16017         do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_size ||
16018                 skip "MDS does not support changelog_size"
16019
16020         local cl_user
16021         local MDT0=$(facet_svc $SINGLEMDS)
16022
16023         changelog_register || error "changelog_register failed"
16024
16025         changelog_clear 0 || error "changelog_clear failed"
16026
16027         local size1=$(do_facet $SINGLEMDS \
16028                       $LCTL get_param -n mdd.$MDT0.changelog_size)
16029         echo "Changelog size $size1"
16030
16031         rm -rf $DIR/$tdir
16032         $LFS mkdir -i 0 $DIR/$tdir
16033         # change something
16034         mkdir -p $DIR/$tdir/pics/2008/zachy
16035         touch $DIR/$tdir/pics/2008/zachy/timestamp
16036         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
16037         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
16038         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
16039         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
16040         rm $DIR/$tdir/pics/desktop.jpg
16041
16042         local size2=$(do_facet $SINGLEMDS \
16043                       $LCTL get_param -n mdd.$MDT0.changelog_size)
16044         echo "Changelog size after work $size2"
16045
16046         (( $size2 > $size1 )) ||
16047                 error "new Changelog size=$size2 less than old size=$size1"
16048 }
16049 run_test 254 "Check changelog size"
16050
16051 ladvise_no_type()
16052 {
16053         local type=$1
16054         local file=$2
16055
16056         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
16057                 awk -F: '{print $2}' | grep $type > /dev/null
16058         if [ $? -ne 0 ]; then
16059                 return 0
16060         fi
16061         return 1
16062 }
16063
16064 ladvise_no_ioctl()
16065 {
16066         local file=$1
16067
16068         lfs ladvise -a willread $file > /dev/null 2>&1
16069         if [ $? -eq 0 ]; then
16070                 return 1
16071         fi
16072
16073         lfs ladvise -a willread $file 2>&1 |
16074                 grep "Inappropriate ioctl for device" > /dev/null
16075         if [ $? -eq 0 ]; then
16076                 return 0
16077         fi
16078         return 1
16079 }
16080
16081 percent() {
16082         bc <<<"scale=2; ($1 - $2) * 100 / $2"
16083 }
16084
16085 # run a random read IO workload
16086 # usage: random_read_iops <filename> <filesize> <iosize>
16087 random_read_iops() {
16088         local file=$1
16089         local fsize=$2
16090         local iosize=${3:-4096}
16091
16092         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
16093                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
16094 }
16095
16096 drop_file_oss_cache() {
16097         local file="$1"
16098         local nodes="$2"
16099
16100         $LFS ladvise -a dontneed $file 2>/dev/null ||
16101                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
16102 }
16103
16104 ladvise_willread_performance()
16105 {
16106         local repeat=10
16107         local average_origin=0
16108         local average_cache=0
16109         local average_ladvise=0
16110
16111         for ((i = 1; i <= $repeat; i++)); do
16112                 echo "Iter $i/$repeat: reading without willread hint"
16113                 cancel_lru_locks osc
16114                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
16115                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
16116                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
16117                 average_origin=$(bc <<<"$average_origin + $speed_origin")
16118
16119                 cancel_lru_locks osc
16120                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
16121                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
16122                 average_cache=$(bc <<<"$average_cache + $speed_cache")
16123
16124                 cancel_lru_locks osc
16125                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
16126                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
16127                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
16128                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
16129                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
16130         done
16131         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
16132         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
16133         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
16134
16135         speedup_cache=$(percent $average_cache $average_origin)
16136         speedup_ladvise=$(percent $average_ladvise $average_origin)
16137
16138         echo "Average uncached read: $average_origin"
16139         echo "Average speedup with OSS cached read: " \
16140                 "$average_cache = +$speedup_cache%"
16141         echo "Average speedup with ladvise willread: " \
16142                 "$average_ladvise = +$speedup_ladvise%"
16143
16144         local lowest_speedup=20
16145         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
16146                 echo "Speedup with OSS cached read less than $lowest_speedup%," \
16147                         "got $average_cache%. Skipping ladvise willread check."
16148                 return 0
16149         fi
16150
16151         # the test won't work on ZFS until it supports 'ladvise dontneed', but
16152         # it is still good to run until then to exercise 'ladvise willread'
16153         ! $LFS ladvise -a dontneed $DIR/$tfile &&
16154                 [ "$(facet_fstype ost1)" = "zfs" ] &&
16155                 echo "osd-zfs does not support dontneed or drop_caches" &&
16156                 return 0
16157
16158         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
16159         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
16160                 error_not_in_vm "Speedup with willread is less than " \
16161                         "$lowest_speedup%, got $average_ladvise%"
16162 }
16163
16164 test_255a() {
16165         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
16166                 skip "lustre < 2.8.54 does not support ladvise "
16167         remote_ost_nodsh && skip "remote OST with nodsh"
16168
16169         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
16170
16171         ladvise_no_type willread $DIR/$tfile &&
16172                 skip "willread ladvise is not supported"
16173
16174         ladvise_no_ioctl $DIR/$tfile &&
16175                 skip "ladvise ioctl is not supported"
16176
16177         local size_mb=100
16178         local size=$((size_mb * 1048576))
16179         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
16180                 error "dd to $DIR/$tfile failed"
16181
16182         lfs ladvise -a willread $DIR/$tfile ||
16183                 error "Ladvise failed with no range argument"
16184
16185         lfs ladvise -a willread -s 0 $DIR/$tfile ||
16186                 error "Ladvise failed with no -l or -e argument"
16187
16188         lfs ladvise -a willread -e 1 $DIR/$tfile ||
16189                 error "Ladvise failed with only -e argument"
16190
16191         lfs ladvise -a willread -l 1 $DIR/$tfile ||
16192                 error "Ladvise failed with only -l argument"
16193
16194         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
16195                 error "End offset should not be smaller than start offset"
16196
16197         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
16198                 error "End offset should not be equal to start offset"
16199
16200         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
16201                 error "Ladvise failed with overflowing -s argument"
16202
16203         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
16204                 error "Ladvise failed with overflowing -e argument"
16205
16206         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
16207                 error "Ladvise failed with overflowing -l argument"
16208
16209         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
16210                 error "Ladvise succeeded with conflicting -l and -e arguments"
16211
16212         echo "Synchronous ladvise should wait"
16213         local delay=4
16214 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
16215         do_nodes $(comma_list $(osts_nodes)) \
16216                 $LCTL set_param fail_val=$delay fail_loc=0x237
16217
16218         local start_ts=$SECONDS
16219         lfs ladvise -a willread $DIR/$tfile ||
16220                 error "Ladvise failed with no range argument"
16221         local end_ts=$SECONDS
16222         local inteval_ts=$((end_ts - start_ts))
16223
16224         if [ $inteval_ts -lt $(($delay - 1)) ]; then
16225                 error "Synchronous advice didn't wait reply"
16226         fi
16227
16228         echo "Asynchronous ladvise shouldn't wait"
16229         local start_ts=$SECONDS
16230         lfs ladvise -a willread -b $DIR/$tfile ||
16231                 error "Ladvise failed with no range argument"
16232         local end_ts=$SECONDS
16233         local inteval_ts=$((end_ts - start_ts))
16234
16235         if [ $inteval_ts -gt $(($delay / 2)) ]; then
16236                 error "Asynchronous advice blocked"
16237         fi
16238
16239         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
16240         ladvise_willread_performance
16241 }
16242 run_test 255a "check 'lfs ladvise -a willread'"
16243
16244 facet_meminfo() {
16245         local facet=$1
16246         local info=$2
16247
16248         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
16249 }
16250
16251 test_255b() {
16252         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
16253                 skip "lustre < 2.8.54 does not support ladvise "
16254         remote_ost_nodsh && skip "remote OST with nodsh"
16255
16256         lfs setstripe -c 1 -i 0 $DIR/$tfile
16257
16258         ladvise_no_type dontneed $DIR/$tfile &&
16259                 skip "dontneed ladvise is not supported"
16260
16261         ladvise_no_ioctl $DIR/$tfile &&
16262                 skip "ladvise ioctl is not supported"
16263
16264         ! $LFS ladvise -a dontneed $DIR/$tfile &&
16265                 [ "$(facet_fstype ost1)" = "zfs" ] &&
16266                 skip "zfs-osd does not support 'ladvise dontneed'"
16267
16268         local size_mb=100
16269         local size=$((size_mb * 1048576))
16270         # In order to prevent disturbance of other processes, only check 3/4
16271         # of the memory usage
16272         local kibibytes=$((size_mb * 1024 * 3 / 4))
16273
16274         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
16275                 error "dd to $DIR/$tfile failed"
16276
16277         #force write to complete before dropping OST cache & checking memory
16278         sync
16279
16280         local total=$(facet_meminfo ost1 MemTotal)
16281         echo "Total memory: $total KiB"
16282
16283         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
16284         local before_read=$(facet_meminfo ost1 Cached)
16285         echo "Cache used before read: $before_read KiB"
16286
16287         lfs ladvise -a willread $DIR/$tfile ||
16288                 error "Ladvise willread failed"
16289         local after_read=$(facet_meminfo ost1 Cached)
16290         echo "Cache used after read: $after_read KiB"
16291
16292         lfs ladvise -a dontneed $DIR/$tfile ||
16293                 error "Ladvise dontneed again failed"
16294         local no_read=$(facet_meminfo ost1 Cached)
16295         echo "Cache used after dontneed ladvise: $no_read KiB"
16296
16297         if [ $total -lt $((before_read + kibibytes)) ]; then
16298                 echo "Memory is too small, abort checking"
16299                 return 0
16300         fi
16301
16302         if [ $((before_read + kibibytes)) -gt $after_read ]; then
16303                 error "Ladvise willread should use more memory" \
16304                         "than $kibibytes KiB"
16305         fi
16306
16307         if [ $((no_read + kibibytes)) -gt $after_read ]; then
16308                 error "Ladvise dontneed should release more memory" \
16309                         "than $kibibytes KiB"
16310         fi
16311 }
16312 run_test 255b "check 'lfs ladvise -a dontneed'"
16313
16314 test_255c() {
16315         [ $(lustre_version_code ost1) -lt $(version_code 2.10.50) ] &&
16316                 skip "lustre < 2.10.53 does not support lockahead"
16317
16318         local count
16319         local new_count
16320         local difference
16321         local i
16322         local rc
16323
16324         test_mkdir -p $DIR/$tdir
16325         $SETSTRIPE -i 0 $DIR/$tdir
16326
16327         #test 10 returns only success/failure
16328         i=10
16329         lockahead_test -d $DIR/$tdir -t $i -f $tfile
16330         rc=$?
16331         if [ $rc -eq 255 ]; then
16332                 error "Ladvise test${i} failed, ${rc}"
16333         fi
16334
16335         #test 11 counts lock enqueue requests, all others count new locks
16336         i=11
16337         count=$(do_facet ost1 \
16338                 $LCTL get_param -n ost.OSS.ost.stats)
16339         count=$(echo "$count" | grep ldlm_extent_enqueue | awk '{ print $2 }')
16340
16341         lockahead_test -d $DIR/$tdir -t $i -f $tfile
16342         rc=$?
16343         if [ $rc -eq 255 ]; then
16344                 error "Ladvise test${i} failed, ${rc}"
16345         fi
16346
16347         new_count=$(do_facet ost1 \
16348                 $LCTL get_param -n ost.OSS.ost.stats)
16349         new_count=$(echo "$new_count" | grep ldlm_extent_enqueue | \
16350                    awk '{ print $2 }')
16351
16352         difference="$((new_count - count))"
16353         if [ $difference -ne $rc ]; then
16354                 error "Ladvise test${i}, bad enqueue count, returned " \
16355                       "${rc}, actual ${difference}"
16356         fi
16357
16358         for i in $(seq 12 21); do
16359                 # If we do not do this, we run the risk of having too many
16360                 # locks and starting lock cancellation while we are checking
16361                 # lock counts.
16362                 cancel_lru_locks osc
16363
16364                 count=$($LCTL get_param -n \
16365                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
16366
16367                 lockahead_test -d $DIR/$tdir -t $i -f $tfile
16368                 rc=$?
16369                 if [ $rc -eq 255 ]; then
16370                         error "Ladvise test ${i} failed, ${rc}"
16371                 fi
16372
16373                 new_count=$($LCTL get_param -n \
16374                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
16375                 difference="$((new_count - count))"
16376
16377                 # Test 15 output is divided by 100 to map down to valid return
16378                 if [ $i -eq 15 ]; then
16379                         rc="$((rc * 100))"
16380                 fi
16381
16382                 if [ $difference -ne $rc ]; then
16383                         error "Ladvise test ${i}, bad lock count, returned " \
16384                               "${rc}, actual ${difference}"
16385                 fi
16386         done
16387
16388         #test 22 returns only success/failure
16389         i=22
16390         lockahead_test -d $DIR/$tdir -t $i -f $tfile
16391         rc=$?
16392         if [ $rc -eq 255 ]; then
16393                 error "Ladvise test${i} failed, ${rc}"
16394         fi
16395 }
16396 run_test 255c "suite of ladvise lockahead tests"
16397
16398 test_256() {
16399         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16400         remote_mds_nodsh && skip "remote MDS with nodsh"
16401         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
16402                 skip "ldiskfs only test"
16403         changelog_users $SINGLEMDS | grep "^cl" &&
16404                 skip "active changelog user"
16405
16406         local cl_user
16407         local cat_sl
16408         local mdt_dev
16409
16410         mdt_dev=$(mdsdevname 1)
16411         echo $mdt_dev
16412
16413         changelog_register || error "changelog_register failed"
16414
16415         rm -rf $DIR/$tdir
16416         mkdir -p $DIR/$tdir
16417
16418         changelog_clear 0 || error "changelog_clear failed"
16419
16420         # change something
16421         touch $DIR/$tdir/{1..10}
16422
16423         # stop the MDT
16424         stop $SINGLEMDS || error "Fail to stop MDT"
16425
16426         # remount the MDT
16427
16428         start $SINGLEMDS $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT"
16429
16430         #after mount new plainllog is used
16431         touch $DIR/$tdir/{11..19}
16432         local tmpfile=$(mktemp -u $tfile.XXXXXX)
16433         cat_sl=$(do_facet $SINGLEMDS "sync; \
16434                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
16435                  llog_reader $tmpfile | grep -c type=1064553b")
16436         do_facet $SINGLEMDS llog_reader $tmpfile
16437
16438         [ $cat_sl != 2 ] && error "Changelog catalog has $cat_sl != 2 slots"
16439
16440         changelog_clear 0 || error "changelog_clear failed"
16441
16442         cat_sl=$(do_facet $SINGLEMDS "sync; \
16443                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
16444                  llog_reader $tmpfile | grep -c type=1064553b; rm -f $tmpfile")
16445
16446         if (( cat_sl == 2 )); then
16447                 error "Empty plain llog was not deleted from changelog catalog"
16448         elif (( cat_sl != 1 )); then
16449                 error "Active plain llog shouldn't be deleted from catalog"
16450         fi
16451 }
16452 run_test 256 "Check llog delete for empty and not full state"
16453
16454 test_257() {
16455         remote_mds_nodsh && skip "remote MDS with nodsh"
16456         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
16457                 skip "Need MDS version at least 2.8.55"
16458
16459         test_mkdir $DIR/$tdir
16460
16461         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
16462                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
16463         stat $DIR/$tdir
16464
16465 #define OBD_FAIL_MDS_XATTR_REP                  0x161
16466         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
16467         local facet=mds$((mdtidx + 1))
16468         set_nodes_failloc $(facet_active_host $facet) 0x80000161
16469         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
16470
16471         stop $facet || error "stop MDS failed"
16472         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
16473                 error "start MDS fail"
16474 }
16475 run_test 257 "xattr locks are not lost"
16476
16477 # Verify we take the i_mutex when security requires it
16478 test_258a() {
16479 #define OBD_FAIL_IMUTEX_SEC 0x141c
16480         $LCTL set_param fail_loc=0x141c
16481         touch $DIR/$tfile
16482         chmod u+s $DIR/$tfile
16483         chmod a+rwx $DIR/$tfile
16484         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
16485         RC=$?
16486         if [ $RC -ne 0 ]; then
16487                 error "error, failed to take i_mutex, rc=$?"
16488         fi
16489         rm -f $DIR/$tfile
16490 }
16491 run_test 258a
16492
16493 # Verify we do NOT take the i_mutex in the normal case
16494 test_258b() {
16495 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
16496         $LCTL set_param fail_loc=0x141d
16497         touch $DIR/$tfile
16498         chmod a+rwx $DIR
16499         chmod a+rw $DIR/$tfile
16500         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
16501         RC=$?
16502         if [ $RC -ne 0 ]; then
16503                 error "error, took i_mutex unnecessarily, rc=$?"
16504         fi
16505         rm -f $DIR/$tfile
16506
16507 }
16508 run_test 258b "verify i_mutex security behavior"
16509
16510 test_259() {
16511         local file=$DIR/$tfile
16512         local before
16513         local after
16514
16515         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
16516                 skip "ldiskfs only test" && return
16517
16518         stack_trap "rm -f $file" EXIT
16519
16520         wait_delete_completed
16521         before=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
16522         echo "before: $before"
16523
16524         $LFS setstripe -i 0 -c 1 $file
16525         dd if=/dev/zero of=$file bs=1M count=10 || error "couldn't write"
16526         sync_all_data
16527         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
16528         echo "after write: $after"
16529
16530 #define OBD_FAIL_OSD_FAIL_AT_TRUNCATE          0x2301
16531         do_facet ost1 $LCTL set_param fail_loc=0x2301
16532         $TRUNCATE $file 0
16533         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
16534         echo "after truncate: $after"
16535
16536         stop ost1
16537         do_facet ost1 $LCTL set_param fail_loc=0
16538         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
16539         sleep 2
16540         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
16541         echo "after restart: $after"
16542         [ $((after - before)) -ge $(fs_log_size ost1) ] &&
16543                 error "missing truncate?"
16544
16545         return 0
16546 }
16547 run_test 259 "crash at delayed truncate"
16548
16549 test_260() {
16550 #define OBD_FAIL_MDC_CLOSE               0x806
16551         $LCTL set_param fail_loc=0x80000806
16552         touch $DIR/$tfile
16553
16554 }
16555 run_test 260 "Check mdc_close fail"
16556
16557 ### Data-on-MDT sanity tests ###
16558 test_270a() {
16559         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16560                 skip "Need MDS version at least 2.10.55"
16561
16562         # create DoM file
16563         local dom=$DIR/$tdir/dom_file
16564         local tmp=$DIR/$tdir/tmp_file
16565
16566         mkdir -p $DIR/$tdir
16567
16568         # basic checks for DoM component creation
16569         $LFS setstripe -E 1024K -E 1024K -L mdt $dom 2>/dev/null &&
16570                 error "Can set MDT layout to non-first entry"
16571
16572         $LFS setstripe -E 1024K -L mdt -E 1024K -L mdt $dom 2>/dev/null &&
16573                 error "Can define multiple entries as MDT layout"
16574
16575         $LFS setstripe -E 1M -L mdt $dom ||
16576                 error "Can't create DoM layout"
16577
16578         [ $($LFS getstripe -L $dom) == "mdt" ] || error "bad pattern"
16579         [ $($LFS getstripe -c $dom) == 0 ] || error "bad stripe count"
16580         [ $($LFS getstripe -S $dom) == 1048576 ] || error "bad stripe size"
16581
16582         local mdtidx=$($LFS getstripe -m $dom)
16583         local mdtname=MDT$(printf %04x $mdtidx)
16584         local facet=mds$((mdtidx + 1))
16585         local space_check=1
16586
16587         # Skip free space checks with ZFS
16588         if [ "$(facet_fstype $facet)" == "zfs" ]; then
16589                 space_check=0
16590         fi
16591
16592         # write
16593         sync
16594         local mdtfree1=$(do_facet $facet \
16595                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16596         dd if=/dev/urandom of=$tmp bs=1024 count=100
16597         # check also direct IO along write
16598         dd if=$tmp of=$dom bs=102400 count=1 oflag=direct
16599         sync
16600         cmp $tmp $dom || error "file data is different"
16601         [ $(stat -c%s $dom) == 102400 ] || error "bad size after write"
16602         if [ $space_check == 1 ]; then
16603                 local mdtfree2=$(do_facet $facet \
16604                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16605                 [ $(($mdtfree1 - $mdtfree2)) -ge 102 ] ||
16606                         error "MDT free space is wrong after write"
16607         fi
16608
16609         # truncate
16610         $TRUNCATE $dom 10000
16611         [ $(stat -c%s $dom) == 10000 ] || error "bad size after truncate"
16612         if [ $space_check == 1 ]; then
16613                 mdtfree1=$(do_facet $facet \
16614                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16615                 [ $(($mdtfree1 - $mdtfree2)) -ge 92 ] ||
16616                         error "MDT free space is wrong after truncate"
16617         fi
16618
16619         # append
16620         cat $tmp >> $dom
16621         sync
16622         [ $(stat -c%s $dom) == 112400 ] || error "bad size after append"
16623         if [ $space_check == 1 ]; then
16624                 mdtfree2=$(do_facet $facet \
16625                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16626                 [ $(($mdtfree1 - $mdtfree2)) -ge 102 ] ||
16627                         error "MDT free space is wrong after append"
16628         fi
16629
16630         # delete
16631         rm $dom
16632         if [ $space_check == 1 ]; then
16633                 mdtfree1=$(do_facet $facet \
16634                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
16635                 [ $(($mdtfree1 - $mdtfree2)) -ge 112 ] ||
16636                         error "MDT free space is wrong after removal"
16637         fi
16638
16639         # combined striping
16640         $LFS setstripe -E 1024K -L mdt -E EOF $dom ||
16641                 error "Can't create DoM + OST striping"
16642
16643         dd if=/dev/urandom of=$tmp bs=1024 count=2000
16644         # check also direct IO along write
16645         dd if=$tmp of=$dom bs=102400 count=20 oflag=direct
16646         sync
16647         cmp $tmp $dom || error "file data is different"
16648         [ $(stat -c%s $dom) == 2048000 ] || error "bad size after write"
16649         rm $dom
16650         rm $tmp
16651
16652         return 0
16653 }
16654 run_test 270a "DoM: basic functionality tests"
16655
16656 test_270b() {
16657         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16658                 skip "Need MDS version at least 2.10.55"
16659
16660         local dom=$DIR/$tdir/dom_file
16661         local max_size=1048576
16662
16663         mkdir -p $DIR/$tdir
16664         $LFS setstripe -E $max_size -L mdt $dom
16665
16666         # truncate over the limit
16667         $TRUNCATE $dom $(($max_size + 1)) &&
16668                 error "successful truncate over the maximum size"
16669         # write over the limit
16670         dd if=/dev/zero of=$dom bs=$max_size seek=1 count=1 &&
16671                 error "successful write over the maximum size"
16672         # append over the limit
16673         dd if=/dev/zero of=$dom bs=$(($max_size - 3)) count=1
16674         echo "12345" >> $dom && error "successful append over the maximum size"
16675         rm $dom
16676
16677         return 0
16678 }
16679 run_test 270b "DoM: maximum size overflow checks for DoM-only file"
16680
16681 test_270c() {
16682         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16683                 skip "Need MDS version at least 2.10.55"
16684
16685         mkdir -p $DIR/$tdir
16686         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16687
16688         # check files inherit DoM EA
16689         touch $DIR/$tdir/first
16690         [ $($GETSTRIPE -L $DIR/$tdir/first) == "mdt" ] ||
16691                 error "bad pattern"
16692         [ $($LFS getstripe -c $DIR/$tdir/first) == 0 ] ||
16693                 error "bad stripe count"
16694         [ $($LFS getstripe -S $DIR/$tdir/first) == 1048576 ] ||
16695                 error "bad stripe size"
16696
16697         # check directory inherits DoM EA and uses it as default
16698         mkdir $DIR/$tdir/subdir
16699         touch $DIR/$tdir/subdir/second
16700         [ $($LFS getstripe -L $DIR/$tdir/subdir/second) == "mdt" ] ||
16701                 error "bad pattern in sub-directory"
16702         [ $($LFS getstripe -c $DIR/$tdir/subdir/second) == 0 ] ||
16703                 error "bad stripe count in sub-directory"
16704         [ $($LFS getstripe -S $DIR/$tdir/subdir/second) == 1048576 ] ||
16705                 error "bad stripe size in sub-directory"
16706         return 0
16707 }
16708 run_test 270c "DoM: DoM EA inheritance tests"
16709
16710 test_270d() {
16711         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16712                 skip "Need MDS version at least 2.10.55"
16713
16714         mkdir -p $DIR/$tdir
16715         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16716
16717         # inherit default DoM striping
16718         mkdir $DIR/$tdir/subdir
16719         touch $DIR/$tdir/subdir/f1
16720
16721         # change default directory striping
16722         $LFS setstripe -c 1 $DIR/$tdir/subdir
16723         touch $DIR/$tdir/subdir/f2
16724         [ $($LFS getstripe -c $DIR/$tdir/subdir/f2) == 1 ] ||
16725                 error "wrong default striping in file 2"
16726         [ $($LFS getstripe -L $DIR/$tdir/subdir/f2) == "raid0" ] ||
16727                 error "bad pattern in file 2"
16728         return 0
16729 }
16730 run_test 270d "DoM: change striping from DoM to RAID0"
16731
16732 test_270e() {
16733         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16734                 skip "Need MDS version at least 2.10.55"
16735
16736         mkdir -p $DIR/$tdir/dom
16737         mkdir -p $DIR/$tdir/norm
16738         DOMFILES=20
16739         NORMFILES=10
16740         $LFS setstripe -E 1M -L mdt $DIR/$tdir/dom
16741         $LFS setstripe -i 0 -S 2M $DIR/$tdir/norm
16742
16743         createmany -o $DIR/$tdir/dom/dom- $DOMFILES
16744         createmany -o $DIR/$tdir/norm/norm- $NORMFILES
16745
16746         # find DoM files by layout
16747         NUM=$($LFS find -L mdt -type f $DIR/$tdir 2>/dev/null | wc -l)
16748         [ $NUM -eq  $DOMFILES ] ||
16749                 error "lfs find -L: found $NUM, expected $DOMFILES"
16750         echo "Test 1: lfs find 20 DOM files by layout: OK"
16751
16752         # there should be 1 dir with default DOM striping
16753         NUM=$($LFS find -L mdt -type d $DIR/$tdir 2>/dev/null | wc -l)
16754         [ $NUM -eq  1 ] ||
16755                 error "lfs find -L: found $NUM, expected 1 dir"
16756         echo "Test 2: lfs find 1 DOM dir by layout: OK"
16757
16758         # find DoM files by stripe size
16759         NUM=$($LFS find -S -1200K -type f $DIR/$tdir 2>/dev/null | wc -l)
16760         [ $NUM -eq  $DOMFILES ] ||
16761                 error "lfs find -S: found $NUM, expected $DOMFILES"
16762         echo "Test 4: lfs find 20 DOM files by stripe size: OK"
16763
16764         # find files by stripe offset except DoM files
16765         NUM=$($LFS find -i 0 -type f $DIR/$tdir 2>/dev/null | wc -l)
16766         [ $NUM -eq  $NORMFILES ] ||
16767                 error "lfs find -i: found $NUM, expected $NORMFILES"
16768         echo "Test 5: lfs find no DOM files by stripe index: OK"
16769         return 0
16770 }
16771 run_test 270e "DoM: lfs find with DoM files test"
16772
16773 test_270f() {
16774         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16775                 skip "Need MDS version at least 2.10.55"
16776
16777         local mdtname=${FSNAME}-MDT0000-mdtlov
16778         local dom=$DIR/$tdir/dom_file
16779         local dom_limit_saved=$(do_facet mds1 $LCTL get_param -n \
16780                                                 lod.$mdtname.dom_stripesize)
16781         local dom_limit=131072
16782
16783         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=$dom_limit
16784         local dom_current=$(do_facet mds1 $LCTL get_param -n \
16785                                                 lod.$mdtname.dom_stripesize)
16786         [ ${dom_limit} -eq ${dom_current} ] ||
16787                 error "Cannot change per-MDT DoM stripe limit to $dom_limit"
16788
16789         $LFS mkdir -i 0 -c 1 $DIR/$tdir
16790         $LFS setstripe -d $DIR/$tdir
16791         $LFS setstripe -E $dom_limit -L mdt $DIR/$tdir ||
16792                 error "Can't set directory default striping"
16793
16794         # exceed maximum stripe size
16795         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
16796                 error "Can't create file with $((dom_limit * 2)) DoM stripe"
16797         [ $($LFS getstripe -S $dom) -eq $((dom_limit * 2)) ] &&
16798                 error "Able to create DoM component size more than LOD limit"
16799
16800         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=0
16801         dom_current=$(do_facet mds1 $LCTL get_param -n \
16802                                                 lod.$mdtname.dom_stripesize)
16803         [ 0 -eq ${dom_current} ] ||
16804                 error "Can't set zero DoM stripe limit"
16805         rm $dom
16806
16807         # attempt to create DoM file on server with disabled DoM should
16808         # remove DoM entry from layout and be succeed
16809         $LFS setstripe -E $dom_limit -L mdt -E -1 $dom ||
16810                 error "Can't create DoM file (DoM is disabled)"
16811         [ $($LFS getstripe -L $dom) == "mdt" ] &&
16812                 error "File has DoM component while DoM is disabled"
16813         rm $dom
16814
16815         # attempt to create DoM file with only DoM stripe should return error
16816         $LFS setstripe -E $dom_limit -L mdt $dom &&
16817                 error "Able to create DoM-only file while DoM is disabled"
16818
16819         # too low values to be aligned with smallest stripe size 64K
16820         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=30000
16821         dom_current=$(do_facet mds1 $LCTL get_param -n \
16822                                                 lod.$mdtname.dom_stripesize)
16823         [ 30000 -eq ${dom_current} ] &&
16824                 error "Can set too small DoM stripe limit"
16825
16826         # 64K is a minimal stripe size in Lustre, expect limit of that size
16827         [ 65536 -eq ${dom_current} ] ||
16828                 error "Limit is not set to 64K but ${dom_current}"
16829
16830         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=2147483648
16831         dom_current=$(do_facet mds1 $LCTL get_param -n \
16832                                                 lod.$mdtname.dom_stripesize)
16833         echo $dom_current
16834         [ 2147483648 -eq ${dom_current} ] &&
16835                 error "Can set too large DoM stripe limit"
16836
16837         do_facet mds1 $LCTL set_param -n \
16838                                 lod.$mdtname.dom_stripesize=$((dom_limit * 2))
16839         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
16840                 error "Can't create DoM component size after limit change"
16841         do_facet mds1 $LCTL set_param -n \
16842                                 lod.$mdtname.dom_stripesize=$((dom_limit / 2))
16843         $LFS setstripe -E $dom_limit -L mdt ${dom}_big ||
16844                 error "Can't create DoM file after limit decrease"
16845         [ $($LFS getstripe -S ${dom}_big) -eq $((dom_limit / 2)) ] ||
16846                 error "Can create big DoM component after limit decrease"
16847         touch ${dom}_def ||
16848                 error "Can't create file with old default layout"
16849
16850         do_facet mds1 $LCTL set_param -n lod.*.dom_stripesize=$dom_limit_saved
16851         return 0
16852 }
16853 run_test 270f "DoM: maximum DoM stripe size checks"
16854
16855 test_271a() {
16856         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16857                 skip "Need MDS version at least 2.10.55"
16858
16859         local dom=$DIR/$tdir/dom
16860
16861         mkdir -p $DIR/$tdir
16862
16863         $LFS setstripe -E 1024K -L mdt $dom
16864
16865         lctl set_param -n mdc.*.stats=clear
16866         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
16867         cat $dom > /dev/null
16868         local reads=$(lctl get_param -n mdc.*.stats |
16869                         awk '/ost_read/ {print $2}')
16870         [ -z $reads ] || error "Unexpected $reads READ RPCs"
16871         ls $dom
16872         rm -f $dom
16873 }
16874 run_test 271a "DoM: data is cached for read after write"
16875
16876 test_271b() {
16877         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16878                 skip "Need MDS version at least 2.10.55"
16879
16880         local dom=$DIR/$tdir/dom
16881
16882         mkdir -p $DIR/$tdir
16883
16884         $LFS setstripe -E 1024K -L mdt -E EOF $dom
16885
16886         lctl set_param -n mdc.*.stats=clear
16887         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
16888         cancel_lru_locks mdc
16889         $CHECKSTAT -t file -s 4096 $dom || error "stat #1 fails"
16890         # second stat to check size is cached on client
16891         $CHECKSTAT -t file -s 4096 $dom || error "stat #2 fails"
16892         local gls=$(lctl get_param -n mdc.*.stats |
16893                         awk '/ldlm_glimpse/ {print $2}')
16894         [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
16895         rm -f $dom
16896 }
16897 run_test 271b "DoM: no glimpse RPC for stat (DoM only file)"
16898
16899 test_271ba() {
16900         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16901                 skip "Need MDS version at least 2.10.55"
16902
16903         local dom=$DIR/$tdir/dom
16904
16905         mkdir -p $DIR/$tdir
16906
16907         $LFS setstripe -E 1024K -L mdt -E EOF $dom
16908
16909         lctl set_param -n mdc.*.stats=clear
16910         lctl set_param -n osc.*.stats=clear
16911         dd if=/dev/zero of=$dom bs=2048K count=1 || return 1
16912         cancel_lru_locks mdc
16913         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
16914         # second stat to check size is cached on client
16915         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
16916         local gls=$(lctl get_param -n mdc.*.stats |
16917                         awk '/ldlm_glimpse/ {print $2}')
16918         [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
16919         local gls=$(lctl get_param -n osc.*.stats |
16920                         awk '/ldlm_glimpse/ {print $2}')
16921         [ -z $gls ] || error "Unexpected $gls OSC glimpse RPCs"
16922         rm -f $dom
16923 }
16924 run_test 271ba "DoM: no glimpse RPC for stat (combined file)"
16925
16926 test_271c() {
16927         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16928                 skip "Need MDS version at least 2.10.55"
16929
16930         local dom=$DIR/$tdir/dom
16931
16932         mkdir -p $DIR/$tdir
16933
16934         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16935
16936         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
16937         local facet=mds$((mdtidx + 1))
16938
16939         cancel_lru_locks mdc
16940         do_facet $facet lctl set_param -n mdt.*.dom_lock=0
16941         createmany -o $dom 1000
16942         lctl set_param -n mdc.*.stats=clear
16943         smalliomany -w $dom 1000 200
16944         lctl get_param -n mdc.*.stats
16945         local enq=$(lctl get_param -n mdc.*.stats |
16946                         awk '/ldlm_ibits_enqueue/ {print $2}')
16947         # Each file has 1 open, 1 IO enqueues, total 2000
16948         # but now we have also +1 getxattr for security.capability, total 3000
16949         [ $enq -ge 2000 ] || error "Too few enqueues $enq, expected > 2000"
16950         unlinkmany $dom 1000
16951
16952         cancel_lru_locks mdc
16953         do_facet $facet lctl set_param -n mdt.*.dom_lock=1
16954         createmany -o $dom 1000
16955         lctl set_param -n mdc.*.stats=clear
16956         smalliomany -w $dom 1000 200
16957         lctl get_param -n mdc.*.stats
16958         local enq_2=$(lctl get_param -n mdc.*.stats |
16959                         awk '/ldlm_ibits_enqueue/ {print $2}')
16960         # Expect to see reduced amount of RPCs by 1000 due to single enqueue
16961         # for OPEN and IO lock.
16962         [ $((enq - enq_2)) -ge 1000 ] ||
16963                 error "Too many enqueues $enq_2, expected about $((enq - 1000))"
16964         unlinkmany $dom 1000
16965         return 0
16966 }
16967 run_test 271c "DoM: IO lock at open saves enqueue RPCs"
16968
16969 test_275() {
16970         remote_ost_nodsh && skip "remote OST with nodsh"
16971         [ $(lustre_version_code ost1) -lt $(version_code 2.10.57) ] &&
16972                 skip "Need OST version >= 2.10.57"
16973
16974         local file=$DIR/$tfile
16975         local oss
16976
16977         oss=$(comma_list $(osts_nodes))
16978
16979         dd if=/dev/urandom of=$file bs=1M count=2 ||
16980                 error "failed to create a file"
16981         cancel_lru_locks osc
16982
16983         #lock 1
16984         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
16985                 error "failed to read a file"
16986
16987 #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
16988         $LCTL set_param fail_loc=0x8000031f
16989
16990         cancel_lru_locks osc &
16991         sleep 1
16992
16993 #define OBD_FAIL_LDLM_PROLONG_PAUSE      0x32b
16994         do_nodes $oss $LCTL set_param fail_loc=0x8000032b
16995         #IO takes another lock, but matches the PENDING one
16996         #and places it to the IO RPC
16997         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
16998                 error "failed to read a file with PENDING lock"
16999 }
17000 run_test 275 "Read on a canceled duplicate lock"
17001
17002 test_276() {
17003         remote_ost_nodsh && skip "remote OST with nodsh"
17004         local pid
17005
17006         do_facet ost1 "(while true; do \
17007                 $LCTL get_param obdfilter.*.filesfree > /dev/null 2>&1; \
17008                 done) & pid=\\\$!; echo \\\$pid > $TMP/sanity_276_pid" &
17009         pid=$!
17010
17011         for LOOP in $(seq 20); do
17012                 stop ost1
17013                 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
17014         done
17015         kill -9 $pid
17016         do_facet ost1 "pid=\\\$(cat $TMP/sanity_276_pid); kill -9 \\\$pid; \
17017                 rm $TMP/sanity_276_pid"
17018 }
17019 run_test 276 "Race between mount and obd_statfs"
17020
17021 cleanup_test_300() {
17022         trap 0
17023         umask $SAVE_UMASK
17024 }
17025 test_striped_dir() {
17026         local mdt_index=$1
17027         local stripe_count
17028         local stripe_index
17029
17030         mkdir -p $DIR/$tdir
17031
17032         SAVE_UMASK=$(umask)
17033         trap cleanup_test_300 RETURN EXIT
17034
17035         $LFS setdirstripe -i $mdt_index -c 2 -H all_char -o 755 \
17036                                                 $DIR/$tdir/striped_dir ||
17037                 error "set striped dir error"
17038
17039         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
17040         [ "$mode" = "755" ] || error "expect 755 got $mode"
17041
17042         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
17043                 error "getdirstripe failed"
17044         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
17045         if [ "$stripe_count" != "2" ]; then
17046                 error "1:stripe_count is $stripe_count, expect 2"
17047         fi
17048         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
17049         if [ "$stripe_count" != "2" ]; then
17050                 error "2:stripe_count is $stripe_count, expect 2"
17051         fi
17052
17053         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
17054         if [ "$stripe_index" != "$mdt_index" ]; then
17055                 error "stripe_index is $stripe_index, expect $mdt_index"
17056         fi
17057
17058         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
17059                 error "nlink error after create striped dir"
17060
17061         mkdir $DIR/$tdir/striped_dir/a
17062         mkdir $DIR/$tdir/striped_dir/b
17063
17064         stat $DIR/$tdir/striped_dir/a ||
17065                 error "create dir under striped dir failed"
17066         stat $DIR/$tdir/striped_dir/b ||
17067                 error "create dir under striped dir failed"
17068
17069         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
17070                 error "nlink error after mkdir"
17071
17072         rmdir $DIR/$tdir/striped_dir/a
17073         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
17074                 error "nlink error after rmdir"
17075
17076         rmdir $DIR/$tdir/striped_dir/b
17077         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
17078                 error "nlink error after rmdir"
17079
17080         chattr +i $DIR/$tdir/striped_dir
17081         createmany -o $DIR/$tdir/striped_dir/f 10 &&
17082                 error "immutable flags not working under striped dir!"
17083         chattr -i $DIR/$tdir/striped_dir
17084
17085         rmdir $DIR/$tdir/striped_dir ||
17086                 error "rmdir striped dir error"
17087
17088         cleanup_test_300
17089
17090         true
17091 }
17092
17093 test_300a() {
17094         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
17095                 skip "skipped for lustre < 2.7.0"
17096         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17097         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17098
17099         test_striped_dir 0 || error "failed on striped dir on MDT0"
17100         test_striped_dir 1 || error "failed on striped dir on MDT0"
17101 }
17102 run_test 300a "basic striped dir sanity test"
17103
17104 test_300b() {
17105         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
17106                 skip "skipped for lustre < 2.7.0"
17107         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17108         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17109
17110         local i
17111         local mtime1
17112         local mtime2
17113         local mtime3
17114
17115         test_mkdir $DIR/$tdir || error "mkdir fail"
17116         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
17117                 error "set striped dir error"
17118         for i in {0..9}; do
17119                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
17120                 sleep 1
17121                 touch $DIR/$tdir/striped_dir/file_$i || error "touch error $i"
17122                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
17123                 [ $mtime1 -eq $mtime2 ] && error "mtime unchanged after create"
17124                 sleep 1
17125                 rm -f $DIR/$tdir/striped_dir/file_$i || error "unlink error $i"
17126                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
17127                 [ $mtime2 -eq $mtime3 ] && error "mtime unchanged after unlink"
17128         done
17129         true
17130 }
17131 run_test 300b "check ctime/mtime for striped dir"
17132
17133 test_300c() {
17134         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
17135                 skip "skipped for lustre < 2.7.0"
17136         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17137         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17138
17139         local file_count
17140
17141         mkdir -p $DIR/$tdir
17142         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
17143                 error "set striped dir error"
17144
17145         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
17146                 error "chown striped dir failed"
17147
17148         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
17149                 error "create 5k files failed"
17150
17151         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
17152
17153         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
17154
17155         rm -rf $DIR/$tdir
17156 }
17157 run_test 300c "chown && check ls under striped directory"
17158
17159 test_300d() {
17160         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
17161                 skip "skipped for lustre < 2.7.0"
17162         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17163         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17164
17165         local stripe_count
17166         local file
17167
17168         mkdir -p $DIR/$tdir
17169         $SETSTRIPE -c 2 $DIR/$tdir
17170
17171         #local striped directory
17172         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
17173                 error "set striped dir error"
17174         createmany -o $DIR/$tdir/striped_dir/f 10 ||
17175                 error "create 10 files failed"
17176
17177         #remote striped directory
17178         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
17179                 error "set striped dir error"
17180         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
17181                 error "create 10 files failed"
17182
17183         for file in $(find $DIR/$tdir); do
17184                 stripe_count=$($LFS getstripe -c $file)
17185                 [ $stripe_count -eq 2 ] ||
17186                         error "wrong stripe $stripe_count for $file"
17187         done
17188
17189         rm -rf $DIR/$tdir
17190 }
17191 run_test 300d "check default stripe under striped directory"
17192
17193 test_300e() {
17194         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17195                 skip "Need MDS version at least 2.7.55"
17196         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17197         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17198
17199         local stripe_count
17200         local file
17201
17202         mkdir -p $DIR/$tdir
17203
17204         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
17205                 error "set striped dir error"
17206
17207         touch $DIR/$tdir/striped_dir/a
17208         touch $DIR/$tdir/striped_dir/b
17209         touch $DIR/$tdir/striped_dir/c
17210
17211         mkdir $DIR/$tdir/striped_dir/dir_a
17212         mkdir $DIR/$tdir/striped_dir/dir_b
17213         mkdir $DIR/$tdir/striped_dir/dir_c
17214
17215         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_a ||
17216                 error "set striped adir under striped dir error"
17217
17218         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
17219                 error "set striped bdir under striped dir error"
17220
17221         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_c ||
17222                 error "set striped cdir under striped dir error"
17223
17224         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
17225                 error "rename dir under striped dir fails"
17226
17227         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
17228                 error "rename dir under different stripes fails"
17229
17230         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
17231                 error "rename file under striped dir should succeed"
17232
17233         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
17234                 error "rename dir under striped dir should succeed"
17235
17236         rm -rf $DIR/$tdir
17237 }
17238 run_test 300e "check rename under striped directory"
17239
17240 test_300f() {
17241         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17242         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17243         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17244                 skip "Need MDS version at least 2.7.55"
17245
17246         local stripe_count
17247         local file
17248
17249         rm -rf $DIR/$tdir
17250         mkdir -p $DIR/$tdir
17251
17252         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
17253                 error "set striped dir error"
17254
17255         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir1 ||
17256                 error "set striped dir error"
17257
17258         touch $DIR/$tdir/striped_dir/a
17259         mkdir $DIR/$tdir/striped_dir/dir_a
17260         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
17261                 error "create striped dir under striped dir fails"
17262
17263         touch $DIR/$tdir/striped_dir1/b
17264         mkdir $DIR/$tdir/striped_dir1/dir_b
17265         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
17266                 error "create striped dir under striped dir fails"
17267
17268         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
17269                 error "rename dir under different striped dir should fail"
17270
17271         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
17272                 error "rename striped dir under diff striped dir should fail"
17273
17274         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
17275                 error "rename file under diff striped dirs fails"
17276
17277         rm -rf $DIR/$tdir
17278 }
17279 run_test 300f "check rename cross striped directory"
17280
17281 test_300_check_default_striped_dir()
17282 {
17283         local dirname=$1
17284         local default_count=$2
17285         local default_index=$3
17286         local stripe_count
17287         local stripe_index
17288         local dir_stripe_index
17289         local dir
17290
17291         echo "checking $dirname $default_count $default_index"
17292         $LFS setdirstripe -D -c $default_count -i $default_index \
17293                                 -t all_char $DIR/$tdir/$dirname ||
17294                 error "set default stripe on striped dir error"
17295         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
17296         [ $stripe_count -eq $default_count ] ||
17297                 error "expect $default_count get $stripe_count for $dirname"
17298
17299         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
17300         [ $stripe_index -eq $default_index ] ||
17301                 error "expect $default_index get $stripe_index for $dirname"
17302
17303         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
17304                                                 error "create dirs failed"
17305
17306         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
17307         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
17308         for dir in $(find $DIR/$tdir/$dirname/*); do
17309                 stripe_count=$($LFS getdirstripe -c $dir)
17310                 [ $stripe_count -eq $default_count ] ||
17311                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
17312                 error "stripe count $default_count != $stripe_count for $dir"
17313
17314                 stripe_index=$($LFS getdirstripe -i $dir)
17315                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
17316                         error "$stripe_index != $default_index for $dir"
17317
17318                 #check default stripe
17319                 stripe_count=$($LFS getdirstripe -D -c $dir)
17320                 [ $stripe_count -eq $default_count ] ||
17321                 error "default count $default_count != $stripe_count for $dir"
17322
17323                 stripe_index=$($LFS getdirstripe -D -i $dir)
17324                 [ $stripe_index -eq $default_index ] ||
17325                 error "default index $default_index != $stripe_index for $dir"
17326         done
17327         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
17328 }
17329
17330 test_300g() {
17331         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17332         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17333                 skip "Need MDS version at least 2.7.55"
17334
17335         local dir
17336         local stripe_count
17337         local stripe_index
17338
17339         mkdir $DIR/$tdir
17340         mkdir $DIR/$tdir/normal_dir
17341
17342         #Checking when client cache stripe index
17343         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
17344         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
17345                 error "create striped_dir failed"
17346
17347         $LFS setdirstripe -i0 $DIR/$tdir/striped_dir/dir0 ||
17348                 error "create dir0 fails"
17349         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir0)
17350         [ $stripe_index -eq 0 ] ||
17351                 error "dir0 expect index 0 got $stripe_index"
17352
17353         mkdir $DIR/$tdir/striped_dir/dir1 ||
17354                 error "create dir1 fails"
17355         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
17356         [ $stripe_index -eq 1 ] ||
17357                 error "dir1 expect index 1 got $stripe_index"
17358
17359         #check default stripe count/stripe index
17360         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
17361         test_300_check_default_striped_dir normal_dir 1 0
17362         test_300_check_default_striped_dir normal_dir 2 1
17363         test_300_check_default_striped_dir normal_dir 2 -1
17364
17365         #delete default stripe information
17366         echo "delete default stripeEA"
17367         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
17368                 error "set default stripe on striped dir error"
17369
17370         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
17371         for dir in $(find $DIR/$tdir/normal_dir/*); do
17372                 stripe_count=$($LFS getdirstripe -c $dir)
17373                 [ $stripe_count -eq 0 ] ||
17374                         error "expect 1 get $stripe_count for $dir"
17375                 stripe_index=$($LFS getdirstripe -i $dir)
17376                 [ $stripe_index -eq 0 ] ||
17377                         error "expect 0 get $stripe_index for $dir"
17378         done
17379 }
17380 run_test 300g "check default striped directory for normal directory"
17381
17382 test_300h() {
17383         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17384         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17385                 skip "Need MDS version at least 2.7.55"
17386
17387         local dir
17388         local stripe_count
17389
17390         mkdir $DIR/$tdir
17391         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
17392                 error "set striped dir error"
17393
17394         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
17395         test_300_check_default_striped_dir striped_dir 1 0
17396         test_300_check_default_striped_dir striped_dir 2 1
17397         test_300_check_default_striped_dir striped_dir 2 -1
17398
17399         #delete default stripe information
17400         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
17401                 error "set default stripe on striped dir error"
17402
17403         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
17404         for dir in $(find $DIR/$tdir/striped_dir/*); do
17405                 stripe_count=$($LFS getdirstripe -c $dir)
17406                 [ $stripe_count -eq 0 ] ||
17407                         error "expect 1 get $stripe_count for $dir"
17408         done
17409 }
17410 run_test 300h "check default striped directory for striped directory"
17411
17412 test_300i() {
17413         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17414         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17415         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17416                 skip "Need MDS version at least 2.7.55"
17417
17418         local stripe_count
17419         local file
17420
17421         mkdir $DIR/$tdir
17422
17423         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
17424                 error "set striped dir error"
17425
17426         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
17427                 error "create files under striped dir failed"
17428
17429         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
17430                 error "set striped hashdir error"
17431
17432         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
17433                 error "create dir0 under hash dir failed"
17434         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
17435                 error "create dir1 under hash dir failed"
17436
17437         # unfortunately, we need to umount to clear dir layout cache for now
17438         # once we fully implement dir layout, we can drop this
17439         umount_client $MOUNT || error "umount failed"
17440         mount_client $MOUNT || error "mount failed"
17441
17442         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
17443         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
17444         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
17445
17446         #set the stripe to be unknown hash type
17447         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
17448         $LCTL set_param fail_loc=0x1901
17449         for ((i = 0; i < 10; i++)); do
17450                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
17451                         error "stat f-$i failed"
17452                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
17453         done
17454
17455         touch $DIR/$tdir/striped_dir/f0 &&
17456                 error "create under striped dir with unknown hash should fail"
17457
17458         $LCTL set_param fail_loc=0
17459
17460         umount_client $MOUNT || error "umount failed"
17461         mount_client $MOUNT || error "mount failed"
17462
17463         return 0
17464 }
17465 run_test 300i "client handle unknown hash type striped directory"
17466
17467 test_300j() {
17468         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17469         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17470         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17471                 skip "Need MDS version at least 2.7.55"
17472
17473         local stripe_count
17474         local file
17475
17476         mkdir $DIR/$tdir
17477
17478         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
17479         $LCTL set_param fail_loc=0x1702
17480         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
17481                 error "set striped dir error"
17482
17483         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
17484                 error "create files under striped dir failed"
17485
17486         $LCTL set_param fail_loc=0
17487
17488         rm -rf $DIR/$tdir || error "unlink striped dir fails"
17489
17490         return 0
17491 }
17492 run_test 300j "test large update record"
17493
17494 test_300k() {
17495         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17496         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17497         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17498                 skip "Need MDS version at least 2.7.55"
17499
17500         local stripe_count
17501         local file
17502
17503         mkdir $DIR/$tdir
17504
17505         #define OBD_FAIL_LARGE_STRIPE   0x1703
17506         $LCTL set_param fail_loc=0x1703
17507         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
17508                 error "set striped dir error"
17509         $LCTL set_param fail_loc=0
17510
17511         $LFS getdirstripe $DIR/$tdir/striped_dir ||
17512                 error "getstripeddir fails"
17513         rm -rf $DIR/$tdir/striped_dir ||
17514                 error "unlink striped dir fails"
17515
17516         return 0
17517 }
17518 run_test 300k "test large striped directory"
17519
17520 test_300l() {
17521         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17522         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17523         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17524                 skip "Need MDS version at least 2.7.55"
17525
17526         local stripe_index
17527
17528         test_mkdir -p $DIR/$tdir/striped_dir
17529         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
17530                         error "chown $RUNAS_ID failed"
17531         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
17532                 error "set default striped dir failed"
17533
17534         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
17535         $LCTL set_param fail_loc=0x80000158
17536         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
17537
17538         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
17539         [ $stripe_index -eq 1 ] ||
17540                 error "expect 1 get $stripe_index for $dir"
17541 }
17542 run_test 300l "non-root user to create dir under striped dir with stale layout"
17543
17544 test_300m() {
17545         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17546         [ $MDSCOUNT -ge 2 ] && skip_env "Only for single MDT"
17547         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17548                 skip "Need MDS version at least 2.7.55"
17549
17550         mkdir -p $DIR/$tdir/striped_dir
17551         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
17552                 error "set default stripes dir error"
17553
17554         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
17555
17556         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
17557         [ $stripe_count -eq 0 ] ||
17558                         error "expect 0 get $stripe_count for a"
17559
17560         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
17561                 error "set default stripes dir error"
17562
17563         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
17564
17565         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
17566         [ $stripe_count -eq 0 ] ||
17567                         error "expect 0 get $stripe_count for b"
17568
17569         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
17570                 error "set default stripes dir error"
17571
17572         mkdir $DIR/$tdir/striped_dir/c &&
17573                 error "default stripe_index is invalid, mkdir c should fails"
17574
17575         rm -rf $DIR/$tdir || error "rmdir fails"
17576 }
17577 run_test 300m "setstriped directory on single MDT FS"
17578
17579 cleanup_300n() {
17580         local list=$(comma_list $(mdts_nodes))
17581
17582         trap 0
17583         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
17584 }
17585
17586 test_300n() {
17587         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17588         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17589         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17590                 skip "Need MDS version at least 2.7.55"
17591         remote_mds_nodsh && skip "remote MDS with nodsh"
17592
17593         local stripe_index
17594         local list=$(comma_list $(mdts_nodes))
17595
17596         trap cleanup_300n RETURN EXIT
17597         mkdir -p $DIR/$tdir
17598         chmod 777 $DIR/$tdir
17599         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
17600                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
17601                 error "create striped dir succeeds with gid=0"
17602
17603         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
17604         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
17605                 error "create striped dir fails with gid=-1"
17606
17607         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
17608         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
17609                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
17610                 error "set default striped dir succeeds with gid=0"
17611
17612
17613         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
17614         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
17615                 error "set default striped dir fails with gid=-1"
17616
17617
17618         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
17619         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
17620                                         error "create test_dir fails"
17621         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
17622                                         error "create test_dir1 fails"
17623         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
17624                                         error "create test_dir2 fails"
17625         cleanup_300n
17626 }
17627 run_test 300n "non-root user to create dir under striped dir with default EA"
17628
17629 test_300o() {
17630         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17631         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17632         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
17633                 skip "Need MDS version at least 2.7.55"
17634
17635         local numfree1
17636         local numfree2
17637
17638         mkdir -p $DIR/$tdir
17639
17640         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
17641         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
17642         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
17643                 skip "not enough free inodes $numfree1 $numfree2"
17644         fi
17645
17646         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
17647         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
17648         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
17649                 skip "not enough free space $numfree1 $numfree2"
17650         fi
17651
17652         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
17653                 error "setdirstripe fails"
17654
17655         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
17656                 error "create dirs fails"
17657
17658         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
17659         ls $DIR/$tdir/striped_dir > /dev/null ||
17660                 error "ls striped dir fails"
17661         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
17662                 error "unlink big striped dir fails"
17663 }
17664 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
17665
17666 test_300p() {
17667         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17668         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17669         remote_mds_nodsh && skip "remote MDS with nodsh"
17670
17671         mkdir -p $DIR/$tdir
17672
17673         #define OBD_FAIL_OUT_ENOSPC     0x1704
17674         do_facet mds2 lctl set_param fail_loc=0x80001704
17675         $LFS setdirstripe -i 0 -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 \
17676                  && error "create striped directory should fail"
17677
17678         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
17679
17680         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
17681         true
17682 }
17683 run_test 300p "create striped directory without space"
17684
17685 test_300q() {
17686         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17687         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17688
17689         local fd=$(free_fd)
17690         local cmd="exec $fd<$tdir"
17691         cd $DIR
17692         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
17693         eval $cmd
17694         cmd="exec $fd<&-"
17695         trap "eval $cmd" EXIT
17696         cd $tdir || error "cd $tdir fails"
17697         rmdir  ../$tdir || error "rmdir $tdir fails"
17698         mkdir local_dir && error "create dir succeeds"
17699         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
17700         eval $cmd
17701         return 0
17702 }
17703 run_test 300q "create remote directory under orphan directory"
17704
17705 prepare_remote_file() {
17706         mkdir $DIR/$tdir/src_dir ||
17707                 error "create remote source failed"
17708
17709         cp /etc/hosts $DIR/$tdir/src_dir/a ||
17710                  error "cp to remote source failed"
17711         touch $DIR/$tdir/src_dir/a
17712
17713         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
17714                 error "create remote target dir failed"
17715
17716         touch $DIR/$tdir/tgt_dir/b
17717
17718         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
17719                 error "rename dir cross MDT failed!"
17720
17721         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
17722                 error "src_child still exists after rename"
17723
17724         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
17725                 error "missing file(a) after rename"
17726
17727         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
17728                 error "diff after rename"
17729 }
17730
17731 test_310a() {
17732         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 4 MDTs"
17733         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17734
17735         local remote_file=$DIR/$tdir/tgt_dir/b
17736
17737         mkdir -p $DIR/$tdir
17738
17739         prepare_remote_file || error "prepare remote file failed"
17740
17741         #open-unlink file
17742         $OPENUNLINK $remote_file $remote_file ||
17743                 error "openunlink $remote_file failed"
17744         $CHECKSTAT -a $remote_file || error "$remote_file exists"
17745 }
17746 run_test 310a "open unlink remote file"
17747
17748 test_310b() {
17749         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 4 MDTs"
17750         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17751
17752         local remote_file=$DIR/$tdir/tgt_dir/b
17753
17754         mkdir -p $DIR/$tdir
17755
17756         prepare_remote_file || error "prepare remote file failed"
17757
17758         ln $remote_file $DIR/$tfile || error "link failed for remote file"
17759         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
17760         $CHECKSTAT -t file $remote_file || error "check file failed"
17761 }
17762 run_test 310b "unlink remote file with multiple links while open"
17763
17764 test_310c() {
17765         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17766         [[ $MDSCOUNT -lt 4 ]] && skip_env "needs >= 4 MDTs"
17767
17768         local remote_file=$DIR/$tdir/tgt_dir/b
17769
17770         mkdir -p $DIR/$tdir
17771
17772         prepare_remote_file || error "prepare remote file failed"
17773
17774         ln $remote_file $DIR/$tfile || error "link failed for remote file"
17775         multiop_bg_pause $remote_file O_uc ||
17776                         error "mulitop failed for remote file"
17777         MULTIPID=$!
17778         $MULTIOP $DIR/$tfile Ouc
17779         kill -USR1 $MULTIPID
17780         wait $MULTIPID
17781 }
17782 run_test 310c "open-unlink remote file with multiple links"
17783
17784 #LU-4825
17785 test_311() {
17786         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17787         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
17788         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
17789                 skip "lustre < 2.8.54 does not contain LU-4825 fix"
17790         remote_mds_nodsh && skip "remote MDS with nodsh"
17791
17792         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
17793
17794         mkdir -p $DIR/$tdir
17795         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
17796         createmany -o $DIR/$tdir/$tfile. 1000
17797
17798         # statfs data is not real time, let's just calculate it
17799         old_iused=$((old_iused + 1000))
17800
17801         local count=$(do_facet $SINGLEMDS "lctl get_param -n \
17802                         osp.*OST0000*MDT0000.create_count")
17803         local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
17804                                 osp.*OST0000*MDT0000.max_create_count")
17805         for idx in $(seq $MDSCOUNT); do
17806                 do_facet mds$idx "lctl set_param -n \
17807                         osp.*OST0000*MDT000?.max_create_count=0"
17808         done
17809
17810         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
17811         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
17812         [ $index -ne 0 ] || error "$tfile stripe index is 0"
17813
17814         unlinkmany $DIR/$tdir/$tfile. 1000
17815
17816         for idx in $(seq $MDSCOUNT); do
17817                 do_facet mds$idx "lctl set_param -n \
17818                         osp.*OST0000*MDT000?.max_create_count=$max_count"
17819                 do_facet mds$idx "lctl set_param -n \
17820                         osp.*OST0000*MDT000?.create_count=$count"
17821         done
17822
17823         local new_iused
17824         for i in $(seq 120); do
17825                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
17826                 # system may be too busy to destroy all objs in time, use
17827                 # a somewhat small value to not fail autotest
17828                 [ $((old_iused - new_iused)) -gt 400 ] && break
17829                 sleep 1
17830         done
17831
17832         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
17833         [ $((old_iused - new_iused)) -gt 400 ] ||
17834                 error "objs not destroyed after unlink"
17835 }
17836 run_test 311 "disable OSP precreate, and unlink should destroy objs"
17837
17838 zfs_oid_to_objid()
17839 {
17840         local ost=$1
17841         local objid=$2
17842
17843         local vdevdir=$(dirname $(facet_vdevice $ost))
17844         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
17845         local zfs_zapid=$(do_facet $ost $cmd |
17846                           grep -w "/O/0/d$((objid%32))" -C 5 |
17847                           awk '/Object/{getline; print $1}')
17848         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
17849                           awk "/$objid = /"'{printf $3}')
17850
17851         echo $zfs_objid
17852 }
17853
17854 zfs_object_blksz() {
17855         local ost=$1
17856         local objid=$2
17857
17858         local vdevdir=$(dirname $(facet_vdevice $ost))
17859         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
17860         local blksz=$(do_facet $ost $cmd $objid |
17861                       awk '/dblk/{getline; printf $4}')
17862
17863         case "${blksz: -1}" in
17864                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
17865                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
17866                 *) ;;
17867         esac
17868
17869         echo $blksz
17870 }
17871
17872 test_312() { # LU-4856
17873         remote_ost_nodsh && skip "remote OST with nodsh"
17874         [ $(facet_fstype ost1) = "zfs" ] ||
17875                 skip_env "the test only applies to zfs"
17876
17877         local max_blksz=$(do_facet ost1 \
17878                           $ZFS get -p recordsize $(facet_device ost1) |
17879                           awk '!/VALUE/{print $3}')
17880         local min_blksz=$(getconf PAGE_SIZE)
17881
17882         # to make life a little bit easier
17883         $LFS mkdir -c 1 -i 0 $DIR/$tdir
17884         $LFS setstripe -c 1 -i 0 $DIR/$tdir
17885
17886         local tf=$DIR/$tdir/$tfile
17887         touch $tf
17888         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17889
17890         # Get ZFS object id
17891         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17892
17893         # block size change by sequential over write
17894         local blksz
17895         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
17896                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
17897
17898                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
17899                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
17900         done
17901         rm -f $tf
17902
17903         # block size change by sequential append write
17904         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
17905         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17906         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17907
17908         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
17909                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
17910                         oflag=sync conv=notrunc
17911
17912                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
17913                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
17914                         error "blksz error, actual $blksz, "    \
17915                                 "expected: 2 * $count * $min_blksz"
17916         done
17917         rm -f $tf
17918
17919         # random write
17920         touch $tf
17921         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17922         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17923
17924         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
17925         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17926         [ $blksz -eq $min_blksz ] ||
17927                 error "blksz error: $blksz, expected: $min_blksz"
17928
17929         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
17930         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17931         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
17932
17933         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
17934         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17935         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
17936 }
17937 run_test 312 "make sure ZFS adjusts its block size by write pattern"
17938
17939 test_313() {
17940         remote_ost_nodsh && skip "remote OST with nodsh"
17941
17942         local file=$DIR/$tfile
17943         rm -f $file
17944         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
17945
17946         # define OBD_FAIL_TGT_RCVD_EIO           0x720
17947         do_facet ost1 "$LCTL set_param fail_loc=0x720"
17948         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
17949                 error "write should failed"
17950         do_facet ost1 "$LCTL set_param fail_loc=0"
17951         rm -f $file
17952 }
17953 run_test 313 "io should fail after last_rcvd update fail"
17954
17955 test_314() {
17956         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
17957
17958         $SETSTRIPE -c 2 -i 0 $DIR/$tfile || error "setstripe failed"
17959         do_facet ost1 "$LCTL set_param fail_loc=0x720"
17960         rm -f $DIR/$tfile
17961         wait_delete_completed
17962         do_facet ost1 "$LCTL set_param fail_loc=0"
17963 }
17964 run_test 314 "OSP shouldn't fail after last_rcvd update failure"
17965
17966 test_315() { # LU-618
17967         local file=$DIR/$tfile
17968         rm -f $file
17969
17970         $MULTIOP $file oO_CREAT:O_DIRECT:O_RDWR:w4096000c
17971         $MULTIOP $file oO_RDONLY:r4096000_c &
17972         PID=$!
17973
17974         sleep 2
17975
17976         local rbytes=$(awk '/read_bytes/ { print $2 }' /proc/$PID/io)
17977         kill -USR1 $PID
17978
17979         [ $rbytes -gt 4000000 ] || error "read is not accounted ($rbytes)"
17980         rm -f $file
17981 }
17982 run_test 315 "read should be accounted"
17983
17984 test_316() {
17985         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17986         large_xattr_enabled || skip_env "large_xattr disabled"
17987
17988         rm -rf $DIR/$tdir/d
17989         mkdir -p $DIR/$tdir/d
17990         chown nobody $DIR/$tdir/d
17991         touch $DIR/$tdir/d/file
17992
17993         $LFS mv -M1 $DIR/$tdir/d || error "lfs mv failed"
17994 }
17995 run_test 316 "lfs mv"
17996
17997 test_317() {
17998         local trunc_sz
17999         local grant_blk_size
18000
18001         if [ "$(facet_fstype $facet)" == "zfs" ]; then
18002                 skip "LU-10370: no implementation for ZFS" && return
18003         fi
18004
18005         stack_trap "rm -f $DIR/$tfile" EXIT
18006         grant_blk_size=$($LCTL get_param osc.$FSNAME*.import |
18007                         awk '/grant_block_size:/ { print $2; exit; }')
18008         #
18009         # Create File of size 5M. Truncate it to below size's and verify
18010         # blocks count.
18011         #
18012         dd if=/dev/zero of=$DIR/$tfile bs=5M count=1 conv=fsync ||
18013                 error "Create file : $DIR/$tfile"
18014
18015         for trunc_sz in 2097152 4097 4000 509 0; do
18016                 $TRUNCATE $DIR/$tfile $trunc_sz ||
18017                         error "truncate $tfile to $trunc_sz failed"
18018                 local sz=$(stat --format=%s $DIR/$tfile)
18019                 local blk=$(stat --format=%b $DIR/$tfile)
18020                 local trunc_blk=$((((trunc_sz + (grant_blk_size - 1) ) /
18021                                      grant_blk_size) * 8))
18022
18023                 if [[ $blk -ne $trunc_blk ]]; then
18024                         $(which stat) $DIR/$tfile
18025                         error "Expected Block $trunc_blk got $blk for $tfile"
18026                 fi
18027
18028                 $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
18029                         error "Expected Size $trunc_sz got $sz for $tfile"
18030         done
18031
18032         #
18033         # sparse file test
18034         # Create file with a hole and write actual two blocks. Block count
18035         # must be 16.
18036         #
18037         dd if=/dev/zero of=$DIR/$tfile bs=$grant_blk_size count=2 seek=5 \
18038                 conv=fsync || error "Create file : $DIR/$tfile"
18039
18040         # Calculate the final truncate size.
18041         trunc_sz=$(($(stat --format=%s $DIR/$tfile) - (grant_blk_size + 1)))
18042
18043         #
18044         # truncate to size $trunc_sz bytes. Strip the last block
18045         # The block count must drop to 8
18046         #
18047         $TRUNCATE $DIR/$tfile $trunc_sz ||
18048                 error "truncate $tfile to $trunc_sz failed"
18049
18050         local trunc_bsz=$((grant_blk_size / $(stat --format=%B $DIR/$tfile)))
18051         sz=$(stat --format=%s $DIR/$tfile)
18052         blk=$(stat --format=%b $DIR/$tfile)
18053
18054         if [[ $blk -ne $trunc_bsz ]]; then
18055                 $(which stat) $DIR/$tfile
18056                 error "Expected Block $trunc_bsz got $blk for $tfile"
18057         fi
18058
18059         $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
18060                 error "Expected Size $trunc_sz got $sz for $tfile"
18061 }
18062 run_test 317 "Verify blocks get correctly update after truncate"
18063
18064 test_fake_rw() {
18065         local read_write=$1
18066         if [ "$read_write" = "write" ]; then
18067                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
18068         elif [ "$read_write" = "read" ]; then
18069                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
18070         else
18071                 error "argument error"
18072         fi
18073
18074         # turn off debug for performance testing
18075         local saved_debug=$($LCTL get_param -n debug)
18076         $LCTL set_param debug=0
18077
18078         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
18079
18080         # get ost1 size - lustre-OST0000
18081         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
18082         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
18083         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
18084
18085         if [ "$read_write" = "read" ]; then
18086                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
18087         fi
18088
18089         local start_time=$(date +%s.%N)
18090         $dd_cmd bs=1M count=$blocks oflag=sync ||
18091                 error "real dd $read_write error"
18092         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
18093
18094         if [ "$read_write" = "write" ]; then
18095                 rm -f $DIR/$tfile
18096         fi
18097
18098         # define OBD_FAIL_OST_FAKE_RW           0x238
18099         do_facet ost1 $LCTL set_param fail_loc=0x238
18100
18101         local start_time=$(date +%s.%N)
18102         $dd_cmd bs=1M count=$blocks oflag=sync ||
18103                 error "fake dd $read_write error"
18104         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
18105
18106         if [ "$read_write" = "write" ]; then
18107                 # verify file size
18108                 cancel_lru_locks osc
18109                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
18110                         error "$tfile size not $blocks MB"
18111         fi
18112         do_facet ost1 $LCTL set_param fail_loc=0
18113
18114         echo "fake $read_write $duration_fake vs. normal $read_write" \
18115                 "$duration in seconds"
18116         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
18117                 error_not_in_vm "fake write is slower"
18118
18119         $LCTL set_param -n debug="$saved_debug"
18120         rm -f $DIR/$tfile
18121 }
18122 test_399a() { # LU-7655 for OST fake write
18123         remote_ost_nodsh && skip "remote OST with nodsh"
18124
18125         test_fake_rw write
18126 }
18127 run_test 399a "fake write should not be slower than normal write"
18128
18129 test_399b() { # LU-8726 for OST fake read
18130         remote_ost_nodsh && skip "remote OST with nodsh"
18131         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
18132                 skip_env "ldiskfs only test"
18133         fi
18134
18135         test_fake_rw read
18136 }
18137 run_test 399b "fake read should not be slower than normal read"
18138
18139 test_400a() { # LU-1606, was conf-sanity test_74
18140         if ! which $CC > /dev/null 2>&1; then
18141                 skip_env "$CC is not installed"
18142         fi
18143
18144         local extra_flags=''
18145         local out=$TMP/$tfile
18146         local prefix=/usr/include/lustre
18147         local prog
18148
18149         if ! [[ -d $prefix ]]; then
18150                 # Assume we're running in tree and fixup the include path.
18151                 extra_flags+=" -I$LUSTRE/include"
18152                 extra_flags+=" -L$LUSTRE/utils"
18153         fi
18154
18155         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
18156                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
18157                         error "client api broken"
18158         done
18159         rm -f $out
18160 }
18161 run_test 400a "Lustre client api program can compile and link"
18162
18163 test_400b() { # LU-1606, LU-5011
18164         local header
18165         local out=$TMP/$tfile
18166         local prefix=/usr/include/linux/lustre
18167
18168         # We use a hard coded prefix so that this test will not fail
18169         # when run in tree. There are headers in lustre/include/lustre/
18170         # that are not packaged (like lustre_idl.h) and have more
18171         # complicated include dependencies (like config.h and lnet/types.h).
18172         # Since this test about correct packaging we just skip them when
18173         # they don't exist (see below) rather than try to fixup cppflags.
18174
18175         if ! which $CC > /dev/null 2>&1; then
18176                 skip_env "$CC is not installed"
18177         fi
18178
18179         for header in $prefix/*.h; do
18180                 if ! [[ -f "$header" ]]; then
18181                         continue
18182                 fi
18183
18184                 if [[ "$(basename $header)" == lustre_ioctl.h ]]; then
18185                         continue # lustre_ioctl.h is internal header
18186                 fi
18187
18188                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
18189                         error "cannot compile '$header'"
18190         done
18191         rm -f $out
18192 }
18193 run_test 400b "packaged headers can be compiled"
18194
18195 test_401a() { #LU-7437
18196         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
18197         [ -n "$printf_arg" ] && skip_env "find does not support -printf"
18198
18199         #count the number of parameters by "list_param -R"
18200         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
18201         #count the number of parameters by listing proc files
18202         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
18203         echo "proc_dirs='$proc_dirs'"
18204         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
18205         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
18206                       sort -u | wc -l)
18207
18208         [ $params -eq $procs ] ||
18209                 error "found $params parameters vs. $procs proc files"
18210
18211         # test the list_param -D option only returns directories
18212         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
18213         #count the number of parameters by listing proc directories
18214         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
18215                 sort -u | wc -l)
18216
18217         [ $params -eq $procs ] ||
18218                 error "found $params parameters vs. $procs proc files"
18219 }
18220 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
18221
18222 test_401b() {
18223         local save=$($LCTL get_param -n jobid_var)
18224         local tmp=testing
18225
18226         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
18227                 error "no error returned when setting bad parameters"
18228
18229         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
18230         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
18231
18232         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
18233         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
18234         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
18235 }
18236 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
18237
18238 test_401c() {
18239         local jobid_var_old=$($LCTL get_param -n jobid_var)
18240         local jobid_var_new
18241
18242         $LCTL set_param jobid_var= &&
18243                 error "no error returned for 'set_param a='"
18244
18245         jobid_var_new=$($LCTL get_param -n jobid_var)
18246         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
18247                 error "jobid_var was changed by setting without value"
18248
18249         $LCTL set_param jobid_var &&
18250                 error "no error returned for 'set_param a'"
18251
18252         jobid_var_new=$($LCTL get_param -n jobid_var)
18253         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
18254                 error "jobid_var was changed by setting without value"
18255 }
18256 run_test 401c "Verify 'lctl set_param' without value fails in either format."
18257
18258 test_401d() {
18259         local jobid_var_old=$($LCTL get_param -n jobid_var)
18260         local jobid_var_new
18261         local new_value="foo=bar"
18262
18263         $LCTL set_param jobid_var=$new_value ||
18264                 error "'set_param a=b' did not accept a value containing '='"
18265
18266         jobid_var_new=$($LCTL get_param -n jobid_var)
18267         [[ "$jobid_var_new" == "$new_value" ]] ||
18268                 error "'set_param a=b' failed on a value containing '='"
18269
18270         # Reset the jobid_var to test the other format
18271         $LCTL set_param jobid_var=$jobid_var_old
18272         jobid_var_new=$($LCTL get_param -n jobid_var)
18273         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
18274                 error "failed to reset jobid_var"
18275
18276         $LCTL set_param jobid_var $new_value ||
18277                 error "'set_param a b' did not accept a value containing '='"
18278
18279         jobid_var_new=$($LCTL get_param -n jobid_var)
18280         [[ "$jobid_var_new" == "$new_value" ]] ||
18281                 error "'set_param a b' failed on a value containing '='"
18282
18283         $LCTL set_param jobid_var $jobid_var_old
18284         jobid_var_new=$($LCTL get_param -n jobid_var)
18285         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
18286                 error "failed to reset jobid_var"
18287 }
18288 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
18289
18290 test_402() {
18291         local server_version=$(lustre_version_code $SINGLEMDS)
18292         [[ $server_version -ge $(version_code 2.7.66) ]] ||
18293         [[ $server_version -ge $(version_code 2.7.18.4) &&
18294                 $server_version -lt $(version_code 2.7.50) ]] ||
18295         [[ $server_version -ge $(version_code 2.7.2) &&
18296                 $server_version -lt $(version_code 2.7.11) ]] ||
18297                 skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+"
18298         remote_mds_nodsh && skip "remote MDS with nodsh"
18299
18300         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
18301 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
18302         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
18303         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
18304                 echo "Touch failed - OK"
18305 }
18306 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
18307
18308 test_403() {
18309         local file1=$DIR/$tfile.1
18310         local file2=$DIR/$tfile.2
18311         local tfile=$TMP/$tfile
18312
18313         rm -f $file1 $file2 $tfile
18314
18315         touch $file1
18316         ln $file1 $file2
18317
18318         # 30 sec OBD_TIMEOUT in ll_getattr()
18319         # right before populating st_nlink
18320         $LCTL set_param fail_loc=0x80001409
18321         stat -c %h $file1 > $tfile &
18322
18323         # create an alias, drop all locks and reclaim the dentry
18324         < $file2
18325         cancel_lru_locks mdc
18326         cancel_lru_locks osc
18327         sysctl -w vm.drop_caches=2
18328
18329         wait
18330
18331         [ $(cat $tfile) -gt 0 ] || error "wrong nlink count: $(cat $tfile)"
18332
18333         rm -f $tfile $file1 $file2
18334 }
18335 run_test 403 "i_nlink should not drop to zero due to aliasing"
18336
18337 test_404() { # LU-6601
18338         local server_version=$(lustre_version_code $SINGLEMDS)
18339         [[ $server_version -ge $(version_code 2.8.53) ]] ||
18340                 skip "Need server version newer than 2.8.52"
18341         remote_mds_nodsh && skip "remote MDS with nodsh"
18342
18343         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
18344                 awk '/osp .*-osc-MDT/ { print $4}')
18345
18346         local osp
18347         for osp in $mosps; do
18348                 echo "Deactivate: " $osp
18349                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
18350                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
18351                         awk -vp=$osp '$4 == p { print $2 }')
18352                 [ $stat = IN ] || {
18353                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
18354                         error "deactivate error"
18355                 }
18356                 echo "Activate: " $osp
18357                 do_facet $SINGLEMDS $LCTL --device %$osp activate
18358                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
18359                         awk -vp=$osp '$4 == p { print $2 }')
18360                 [ $stat = UP ] || {
18361                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
18362                         error "activate error"
18363                 }
18364         done
18365 }
18366 run_test 404 "validate manual {de}activated works properly for OSPs"
18367
18368 test_405() {
18369         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) -o \
18370         [ $(lustre_version_code client) -lt $(version_code 2.6.99) ] &&
18371                 skip "Layout swap lock is not supported"
18372         check_swap_layouts_support
18373
18374         test_mkdir $DIR/$tdir
18375         swap_lock_test -d $DIR/$tdir ||
18376                 error "One layout swap locked test failed"
18377 }
18378 run_test 405 "Various layout swap lock tests"
18379
18380 test_406() {
18381         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
18382         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
18383         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
18384         [ $PARALLEL == "yes" ] && skip "skip parallel run"
18385         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
18386                 skip "Need MDS version at least 2.8.50"
18387
18388         local def_stripe_size=$($LFS getstripe -S $MOUNT)
18389         local test_pool=$TESTNAME
18390
18391         if ! combined_mgs_mds ; then
18392                 mount_mgs_client
18393         fi
18394         pool_add $test_pool || error "pool_add failed"
18395         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
18396                 error "pool_add_targets failed"
18397
18398         save_layout_restore_at_exit $MOUNT
18399
18400         # parent set default stripe count only, child will stripe from both
18401         # parent and fs default
18402         $LFS setstripe -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
18403                 error "setstripe $MOUNT failed"
18404         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
18405         $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
18406         for i in $(seq 10); do
18407                 local f=$DIR/$tdir/$tfile.$i
18408                 touch $f || error "touch failed"
18409                 local count=$($LFS getstripe -c $f)
18410                 [ $count -eq $OSTCOUNT ] ||
18411                         error "$f stripe count $count != $OSTCOUNT"
18412                 local offset=$($LFS getstripe -i $f)
18413                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
18414                 local size=$($LFS getstripe -S $f)
18415                 [ $size -eq $((def_stripe_size * 2)) ] ||
18416                         error "$f stripe size $size != $((def_stripe_size * 2))"
18417                 local pool=$($LFS getstripe -p $f)
18418                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
18419         done
18420
18421         # change fs default striping, delete parent default striping, now child
18422         # will stripe from new fs default striping only
18423         $LFS setstripe -c 1 -S $def_stripe_size -i 0 $MOUNT ||
18424                 error "change $MOUNT default stripe failed"
18425         $LFS setstripe -c 0 $DIR/$tdir ||
18426                 error "delete $tdir default stripe failed"
18427         for i in $(seq 11 20); do
18428                 local f=$DIR/$tdir/$tfile.$i
18429                 touch $f || error "touch $f failed"
18430                 local count=$($LFS getstripe -c $f)
18431                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
18432                 local offset=$($LFS getstripe -i $f)
18433                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
18434                 local size=$($LFS getstripe -S $f)
18435                 [ $size -eq $def_stripe_size ] ||
18436                         error "$f stripe size $size != $def_stripe_size"
18437                 local pool=$($LFS getstripe -p $f)
18438                 [ $pool == $test_pool ] || error "$f pool $pool isn't set"
18439         done
18440
18441         unlinkmany $DIR/$tdir/$tfile. 1 20
18442
18443         local f=$DIR/$tdir/$tfile
18444         pool_remove_all_targets $test_pool $f
18445         pool_remove $test_pool $f
18446
18447         if ! combined_mgs_mds ; then
18448                 umount_mgs_client
18449         fi
18450 }
18451 run_test 406 "DNE support fs default striping"
18452
18453 test_407() {
18454         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
18455         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
18456                 skip "Need MDS version at least 2.8.55"
18457         remote_mds_nodsh && skip "remote MDS with nodsh"
18458
18459         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
18460                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
18461         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
18462                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
18463         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
18464
18465         #define OBD_FAIL_DT_TXN_STOP    0x2019
18466         for idx in $(seq $MDSCOUNT); do
18467                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
18468         done
18469         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
18470         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
18471                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
18472         true
18473 }
18474 run_test 407 "transaction fail should cause operation fail"
18475
18476 test_408() {
18477         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
18478
18479         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
18480         lctl set_param fail_loc=0x8000040a
18481         # let ll_prepare_partial_page() fail
18482         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
18483
18484         rm -f $DIR/$tfile
18485
18486         # create at least 100 unused inodes so that
18487         # shrink_icache_memory(0) should not return 0
18488         touch $DIR/$tfile-{0..100}
18489         rm -f $DIR/$tfile-{0..100}
18490         sync
18491
18492         echo 2 > /proc/sys/vm/drop_caches
18493 }
18494 run_test 408 "drop_caches should not hang due to page leaks"
18495
18496 test_409()
18497 {
18498         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
18499         check_mount_and_prep
18500
18501         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
18502         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
18503         touch $DIR/$tdir/guard || error "(2) Fail to create"
18504
18505         local PREFIX=$(str_repeat 'A' 128)
18506         echo "Create 1K hard links start at $(date)"
18507         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
18508                 error "(3) Fail to hard link"
18509
18510         echo "Links count should be right although linkEA overflow"
18511         stat $DIR/$tdir/guard || error "(4) Fail to stat"
18512         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
18513         [ $linkcount -eq 1001 ] ||
18514                 error "(5) Unexpected hard links count: $linkcount"
18515
18516         echo "List all links start at $(date)"
18517         ls -l $DIR/$tdir/foo > /dev/null ||
18518                 error "(6) Fail to list $DIR/$tdir/foo"
18519
18520         echo "Unlink hard links start at $(date)"
18521         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
18522                 error "(7) Fail to unlink"
18523 }
18524 run_test 409 "Large amount of cross-MDTs hard links on the same file"
18525
18526 test_410()
18527 {
18528         [[ $(lustre_version_code client) -lt $(version_code 2.9.59) ]] &&
18529                 skip "Need client version at least 2.9.59"
18530
18531         # Create a file, and stat it from the kernel
18532         local testfile=$DIR/$tfile
18533         touch $testfile
18534
18535         local run_id=$RANDOM
18536         local my_ino=$(stat --format "%i" $testfile)
18537
18538         # Try to insert the module. This will always fail as the
18539         # module is designed to not be inserted.
18540         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
18541             &> /dev/null
18542
18543         # Anything but success is a test failure
18544         dmesg | grep -q \
18545             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
18546             error "no inode match"
18547 }
18548 run_test 410 "Test inode number returned from kernel thread"
18549
18550 cleanup_test411_cgroup() {
18551         trap 0
18552         rmdir "$1"
18553 }
18554
18555 test_411() {
18556         local cg_basedir=/sys/fs/cgroup/memory
18557         # LU-9966
18558         test -f "$cg_basedir/memory.kmem.limit_in_bytes" ||
18559                 skip "no setup for cgroup"
18560
18561         dd if=/dev/zero of=$DIR/$tfile bs=1M count=100 conv=fsync ||
18562                 error "test file creation failed"
18563         cancel_lru_locks osc
18564
18565         # Create a very small memory cgroup to force a slab allocation error
18566         local cgdir=$cg_basedir/osc_slab_alloc
18567         mkdir $cgdir || error "cgroup mkdir '$cgdir' failed"
18568         trap "cleanup_test411_cgroup $cgdir" EXIT
18569         echo 2M > $cgdir/memory.kmem.limit_in_bytes
18570         echo 1M > $cgdir/memory.limit_in_bytes
18571
18572         # Should not LBUG, just be killed by oom-killer
18573         sh -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null" &&
18574                 error "fail to trigger a memory allocation error"
18575
18576         cleanup_test411_cgroup $cgdir
18577
18578         return 0
18579 }
18580 run_test 411 "Slab allocation error with cgroup does not LBUG"
18581
18582 test_412() {
18583         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
18584         if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
18585                 skip "Need server version at least 2.10.55"
18586         fi
18587
18588         $LFS mkdir -i $((MDSCOUNT - 1)),$((MDSCOUNT - 2)) $DIR/$tdir ||
18589                 error "mkdir failed"
18590         $LFS getdirstripe $DIR/$tdir
18591         local stripe_index=$($LFS getdirstripe -i $DIR/$tdir)
18592         [ $stripe_index -eq $((MDSCOUNT - 1)) ] ||
18593                 error "expect $((MDSCOUT - 1)) get $stripe_index"
18594         local stripe_count=$($LFS getdirstripe -T $DIR/$tdir)
18595         [ $stripe_count -eq 2 ] ||
18596                 error "expect 2 get $stripe_count"
18597 }
18598 run_test 412 "mkdir on specific MDTs"
18599
18600 test_413() {
18601         [ $MDSCOUNT -lt 2 ] &&
18602                 skip "We need at least 2 MDTs for this test"
18603
18604         if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
18605                 skip "Need server version at least 2.10.55"
18606         fi
18607
18608         mkdir $DIR/$tdir || error "mkdir failed"
18609
18610         # find MDT that is the most full
18611         local max=$($LFS df | grep MDT |
18612                 awk 'BEGIN { a=0 }
18613                         { sub("%", "", $5)
18614                           if (0+$5 >= a)
18615                           {
18616                                 a = $5
18617                                 b = $6
18618                           }
18619                         }
18620                      END { split(b, c, ":")
18621                            sub("]", "", c[2])
18622                            print c[2]
18623                          }')
18624
18625         for i in $(seq $((MDSCOUNT - 1))); do
18626                 $LFS mkdir -c $i $DIR/$tdir/d$i ||
18627                         error "mkdir d$i failed"
18628                 $LFS getdirstripe $DIR/$tdir/d$i
18629                 local stripe_index=$($LFS getdirstripe -i $DIR/$tdir/d$i)
18630                 [ $stripe_index -ne $max ] ||
18631                         error "don't expect $max"
18632         done
18633 }
18634 run_test 413 "mkdir on less full MDTs"
18635
18636 test_414() {
18637 #define OBD_FAIL_PTLRPC_BULK_ATTACH      0x521
18638         $LCTL set_param fail_loc=0x80000521
18639         dd if=/dev/zero of=$DIR/$tfile bs=2M count=1 oflag=sync
18640         rm -f $DIR/$tfile
18641 }
18642 run_test 414 "simulate ENOMEM in ptlrpc_register_bulk()"
18643
18644 prep_801() {
18645         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
18646         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
18647                 skip "Need server version at least 2.9.55"
18648
18649         start_full_debug_logging
18650 }
18651
18652 post_801() {
18653         stop_full_debug_logging
18654 }
18655
18656 barrier_stat() {
18657         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
18658                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
18659                            awk '/The barrier for/ { print $7 }')
18660                 echo $st
18661         else
18662                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
18663                 echo \'$st\'
18664         fi
18665 }
18666
18667 barrier_expired() {
18668         local expired
18669
18670         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
18671                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
18672                           awk '/will be expired/ { print $7 }')
18673         else
18674                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
18675         fi
18676
18677         echo $expired
18678 }
18679
18680 test_801a() {
18681         prep_801
18682
18683         echo "Start barrier_freeze at: $(date)"
18684         #define OBD_FAIL_BARRIER_DELAY          0x2202
18685         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
18686         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
18687
18688         sleep 2
18689         local b_status=$(barrier_stat)
18690         echo "Got barrier status at: $(date)"
18691         [ "$b_status" = "'freezing_p1'" ] ||
18692                 error "(1) unexpected barrier status $b_status"
18693
18694         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
18695         wait
18696         b_status=$(barrier_stat)
18697         [ "$b_status" = "'frozen'" ] ||
18698                 error "(2) unexpected barrier status $b_status"
18699
18700         local expired=$(barrier_expired)
18701         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
18702         sleep $((expired + 3))
18703
18704         b_status=$(barrier_stat)
18705         [ "$b_status" = "'expired'" ] ||
18706                 error "(3) unexpected barrier status $b_status"
18707
18708         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
18709                 error "(4) fail to freeze barrier"
18710
18711         b_status=$(barrier_stat)
18712         [ "$b_status" = "'frozen'" ] ||
18713                 error "(5) unexpected barrier status $b_status"
18714
18715         echo "Start barrier_thaw at: $(date)"
18716         #define OBD_FAIL_BARRIER_DELAY          0x2202
18717         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
18718         do_facet mgs $LCTL barrier_thaw $FSNAME &
18719
18720         sleep 2
18721         b_status=$(barrier_stat)
18722         echo "Got barrier status at: $(date)"
18723         [ "$b_status" = "'thawing'" ] ||
18724                 error "(6) unexpected barrier status $b_status"
18725
18726         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
18727         wait
18728         b_status=$(barrier_stat)
18729         [ "$b_status" = "'thawed'" ] ||
18730                 error "(7) unexpected barrier status $b_status"
18731
18732         #define OBD_FAIL_BARRIER_FAILURE        0x2203
18733         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
18734         do_facet mgs $LCTL barrier_freeze $FSNAME
18735
18736         b_status=$(barrier_stat)
18737         [ "$b_status" = "'failed'" ] ||
18738                 error "(8) unexpected barrier status $b_status"
18739
18740         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
18741         do_facet mgs $LCTL barrier_thaw $FSNAME
18742
18743         post_801
18744 }
18745 run_test 801a "write barrier user interfaces and stat machine"
18746
18747 test_801b() {
18748         prep_801
18749
18750         mkdir $DIR/$tdir || error "(1) fail to mkdir"
18751         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
18752         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
18753         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
18754         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
18755
18756         cancel_lru_locks mdc
18757
18758         # 180 seconds should be long enough
18759         do_facet mgs $LCTL barrier_freeze $FSNAME 180
18760
18761         local b_status=$(barrier_stat)
18762         [ "$b_status" = "'frozen'" ] ||
18763                 error "(6) unexpected barrier status $b_status"
18764
18765         mkdir $DIR/$tdir/d0/d10 &
18766         mkdir_pid=$!
18767
18768         touch $DIR/$tdir/d1/f13 &
18769         touch_pid=$!
18770
18771         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
18772         ln_pid=$!
18773
18774         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
18775         mv_pid=$!
18776
18777         rm -f $DIR/$tdir/d4/f12 &
18778         rm_pid=$!
18779
18780         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
18781
18782         # To guarantee taht the 'stat' is not blocked
18783         b_status=$(barrier_stat)
18784         [ "$b_status" = "'frozen'" ] ||
18785                 error "(8) unexpected barrier status $b_status"
18786
18787         # let above commands to run at background
18788         sleep 5
18789
18790         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
18791         ps -p $touch_pid || error "(10) touch should be blocked"
18792         ps -p $ln_pid || error "(11) link should be blocked"
18793         ps -p $mv_pid || error "(12) rename should be blocked"
18794         ps -p $rm_pid || error "(13) unlink should be blocked"
18795
18796         b_status=$(barrier_stat)
18797         [ "$b_status" = "'frozen'" ] ||
18798                 error "(14) unexpected barrier status $b_status"
18799
18800         do_facet mgs $LCTL barrier_thaw $FSNAME
18801         b_status=$(barrier_stat)
18802         [ "$b_status" = "'thawed'" ] ||
18803                 error "(15) unexpected barrier status $b_status"
18804
18805         wait $mkdir_pid || error "(16) mkdir should succeed"
18806         wait $touch_pid || error "(17) touch should succeed"
18807         wait $ln_pid || error "(18) link should succeed"
18808         wait $mv_pid || error "(19) rename should succeed"
18809         wait $rm_pid || error "(20) unlink should succeed"
18810
18811         post_801
18812 }
18813 run_test 801b "modification will be blocked by write barrier"
18814
18815 test_801c() {
18816         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
18817
18818         prep_801
18819
18820         stop mds2 || error "(1) Fail to stop mds2"
18821
18822         do_facet mgs $LCTL barrier_freeze $FSNAME 30
18823
18824         local b_status=$(barrier_stat)
18825         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
18826                 do_facet mgs $LCTL barrier_thaw $FSNAME
18827                 error "(2) unexpected barrier status $b_status"
18828         }
18829
18830         do_facet mgs $LCTL barrier_rescan $FSNAME ||
18831                 error "(3) Fail to rescan barrier bitmap"
18832
18833         do_facet mgs $LCTL barrier_freeze $FSNAME 10
18834
18835         b_status=$(barrier_stat)
18836         [ "$b_status" = "'frozen'" ] ||
18837                 error "(4) unexpected barrier status $b_status"
18838
18839         do_facet mgs $LCTL barrier_thaw $FSNAME
18840         b_status=$(barrier_stat)
18841         [ "$b_status" = "'thawed'" ] ||
18842                 error "(5) unexpected barrier status $b_status"
18843
18844         local devname=$(mdsdevname 2)
18845
18846         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
18847
18848         do_facet mgs $LCTL barrier_rescan $FSNAME ||
18849                 error "(7) Fail to rescan barrier bitmap"
18850
18851         post_801
18852 }
18853 run_test 801c "rescan barrier bitmap"
18854
18855 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
18856 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
18857 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
18858
18859 cleanup_802() {
18860         trap 0
18861
18862         stopall
18863         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
18864         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
18865         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
18866         setupall
18867 }
18868
18869 test_802() {
18870
18871         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
18872         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
18873                 skip "Need server version at least 2.9.55"
18874
18875         mkdir $DIR/$tdir || error "(1) fail to mkdir"
18876
18877         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
18878                 error "(2) Fail to copy"
18879
18880         trap cleanup_802 EXIT
18881
18882         # sync by force before remount as readonly
18883         sync; sync_all_data; sleep 3; sync_all_data
18884
18885         stopall
18886
18887         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
18888         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
18889         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
18890
18891         echo "Mount the server as read only"
18892         setupall server_only || error "(3) Fail to start servers"
18893
18894         echo "Mount client without ro should fail"
18895         mount_client $MOUNT &&
18896                 error "(4) Mount client without 'ro' should fail"
18897
18898         echo "Mount client with ro should succeed"
18899         mount_client $MOUNT ro ||
18900                 error "(5) Mount client with 'ro' should succeed"
18901
18902         echo "Modify should be refused"
18903         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
18904
18905         echo "Read should be allowed"
18906         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
18907                 error "(7) Read should succeed under ro mode"
18908
18909         cleanup_802
18910 }
18911 run_test 802 "simulate readonly device"
18912
18913 test_803() {
18914         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
18915         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.54) ] &&
18916                 skip "MDS needs to be newer than 2.10.54"
18917
18918         mkdir -p $DIR/$tdir
18919         # Create some objects on all MDTs to trigger related logs objects
18920         for idx in $(seq $MDSCOUNT); do
18921                 $LFS mkdir -c $MDSCOUNT -i $((idx % $MDSCOUNT)) \
18922                         $DIR/$tdir/dir${idx} ||
18923                         error "Fail to create $DIR/$tdir/dir${idx}"
18924         done
18925
18926         sync; sleep 3
18927         echo "before create:"
18928         $LFS df -i $MOUNT
18929         local before_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18930
18931         for ((i=0; i<10; i++)); do
18932                 $LFS mkdir -c 1 -i 1 $DIR/$tdir/foo$i ||
18933                         error "Fail to create $DIR/$tdir/foo$i"
18934         done
18935
18936         sync; sleep 3
18937         echo "after create:"
18938         $LFS df -i $MOUNT
18939         local after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18940
18941         [ $after_used -ge $((before_used + 10)) ] ||
18942                 error "before ($before_used) + 10 > after ($after_used)"
18943
18944         for ((i=0; i<10; i++)); do
18945                 rm -rf $DIR/$tdir/foo$i ||
18946                         error "Fail to remove $DIR/$tdir/foo$i"
18947         done
18948
18949         sleep 3 # avoid MDT return cached statfs
18950         wait_delete_completed
18951         echo "after unlink:"
18952         $LFS df -i $MOUNT
18953         before_used=$after_used
18954         after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18955
18956         [ $after_used -le $((before_used - 8)) ] ||
18957                 error "before ($before_used) - 8 < after ($after_used)"
18958 }
18959 run_test 803 "verify agent object for remote object"
18960
18961 test_804() {
18962         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
18963         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.54) ] &&
18964                 skip "MDS needs to be newer than 2.10.54"
18965         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
18966                 skip_env "ldiskfs only test"
18967
18968         mkdir -p $DIR/$tdir
18969         $LFS mkdir -c 1 -i 1 $DIR/$tdir/dir0 ||
18970                 error "Fail to create $DIR/$tdir/dir0"
18971
18972         local fid=$($LFS path2fid $DIR/$tdir/dir0)
18973         local dev=$(mdsdevname 2)
18974
18975         do_facet mds2 "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18976                 grep ${fid} || error "NOT found agent entry for dir0"
18977
18978         $LFS mkdir -c $MDSCOUNT -i 0 $DIR/$tdir/dir1 ||
18979                 error "Fail to create $DIR/$tdir/dir1"
18980
18981         touch $DIR/$tdir/dir1/foo0 ||
18982                 error "Fail to create $DIR/$tdir/dir1/foo0"
18983         fid=$($LFS path2fid $DIR/$tdir/dir1/foo0)
18984         local rc=0
18985
18986         for idx in $(seq $MDSCOUNT); do
18987                 dev=$(mdsdevname $idx)
18988                 do_facet mds${idx} \
18989                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18990                         grep ${fid} && rc=$idx
18991         done
18992
18993         mv $DIR/$tdir/dir1/foo0 $DIR/$tdir/dir1/foo1 ||
18994                 error "Fail to rename foo0 to foo1"
18995         if [ $rc -eq 0 ]; then
18996                 for idx in $(seq $MDSCOUNT); do
18997                         dev=$(mdsdevname $idx)
18998                         do_facet mds${idx} \
18999                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
19000                         grep ${fid} && rc=$idx
19001                 done
19002         fi
19003
19004         mv $DIR/$tdir/dir1/foo1 $DIR/$tdir/dir1/foo2 ||
19005                 error "Fail to rename foo1 to foo2"
19006         if [ $rc -eq 0 ]; then
19007                 for idx in $(seq $MDSCOUNT); do
19008                         dev=$(mdsdevname $idx)
19009                         do_facet mds${idx} \
19010                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
19011                         grep ${fid} && rc=$idx
19012                 done
19013         fi
19014
19015         [ $rc -ne 0 ] || error "NOT found agent entry for foo"
19016
19017         ln $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir0/guard ||
19018                 error "Fail to link to $DIR/$tdir/dir1/foo2"
19019         mv $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir1/foo0 ||
19020                 error "Fail to rename foo2 to foo0"
19021         unlink $DIR/$tdir/dir1/foo0 ||
19022                 error "Fail to unlink $DIR/$tdir/dir1/foo0"
19023         rm -rf $DIR/$tdir/dir0 ||
19024                 error "Fail to rm $DIR/$tdir/dir0"
19025
19026         for idx in $(seq $MDSCOUNT); do
19027                 dev=$(mdsdevname $idx)
19028                 rc=0
19029
19030                 stop mds${idx}
19031                 run_e2fsck $(facet_active_host mds$idx) $dev -n ||
19032                         rc=$?
19033                 start mds${idx} $dev $MDS_MOUNT_OPTS ||
19034                         error "mount mds$idx failed"
19035                 df $MOUNT > /dev/null 2>&1
19036
19037                 # e2fsck should not return error
19038                 [ $rc -eq 0 ] ||
19039                         error "e2fsck detected error on MDT${idx}: rc=$rc"
19040         done
19041 }
19042 run_test 804 "verify agent entry for remote entry"
19043
19044 cleanup_805() {
19045         do_facet $SINGLEMDS zfs set quota=$old $fsset
19046         unlinkmany $DIR/$tdir/f- 1000000
19047         trap 0
19048 }
19049
19050 test_805() {
19051         local zfs_version=$(do_node $SINGLEMDS cat /sys/module/zfs/version)
19052         [ "$(facet_fstype mds1)" != "zfs" ] &&
19053                 skip "ZFS specific test"
19054         [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
19055                 skip "netfree not implemented before 0.7"
19056         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
19057                 skip "Need MDS version at least 2.10.57"
19058
19059         local fsset
19060         local freekb
19061         local usedkb
19062         local old
19063         local quota
19064         local pref="osd-zfs.lustre-MDT0000."
19065
19066         # limit available space on MDS dataset to meet nospace issue
19067         # quickly. then ZFS 0.7.2 can use reserved space if asked
19068         # properly (using netfree flag in osd_declare_destroy()
19069         fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
19070         old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
19071                 gawk '{print $3}')
19072         freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
19073         usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
19074         let "usedkb=usedkb-freekb"
19075         let "freekb=freekb/2"
19076         if let "freekb > 5000"; then
19077                 let "freekb=5000"
19078         fi
19079         do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
19080         trap cleanup_805 EXIT
19081         mkdir $DIR/$tdir
19082         $LFS setstripe -E 1M -L mdt $DIR/$tdir || error "DoM not working"
19083         createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
19084         rm -rf $DIR/$tdir || error "not able to remove"
19085         do_facet $SINGLEMDS zfs set quota=$old $fsset
19086         trap 0
19087 }
19088 run_test 805 "ZFS can remove from full fs"
19089
19090 #
19091 # tests that do cleanup/setup should be run at the end
19092 #
19093
19094 test_900() {
19095         [ $PARALLEL == "yes" ] && skip "skip parallel run"
19096         local ls
19097
19098         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
19099         $LCTL set_param fail_loc=0x903
19100
19101         cancel_lru_locks MGC
19102
19103         FAIL_ON_ERROR=true cleanup
19104         FAIL_ON_ERROR=true setup
19105 }
19106 run_test 900 "umount should not race with any mgc requeue thread"
19107
19108 complete $SECONDS
19109 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
19110 check_and_cleanup_lustre
19111 if [ "$I_MOUNTED" != "yes" ]; then
19112         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
19113 fi
19114 exit_status