Whamcloud - gitweb
cdc56bf7417a518b9fd6e2e159e7953eb25cd3f0
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: LU-9693 LU-6493 LU-9693
12 ALWAYS_EXCEPT="$SANITY_EXCEPT  42a     42b     42c"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skipped tests: LU-8411 LU-9096 LU-9054 LU-10680 ..
16 ALWAYS_EXCEPT="  407     253     312     160f   160g    $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 #                                  5          12          (min)"
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
64
65 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
66         # bug number for skipped test: LU-1957
67         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  180"
68         #                                               13    (min)"
69         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
70 fi
71
72 # Get the SLES version so we can make decisions on if a test should be run
73 #
74 # Returns a version string that should only be used in comparing
75 # strings returned by version_code()
76
77 sles_version_code()
78 {
79         local version=$(grep VERSION_ID /etc/os-release | cut -d'"' -f2)
80
81         # All SuSE Linux versions have one decimal. version_code expects two
82         local sles_version=$version.0
83         version_code $sles_version
84 }
85
86 if [ -r /etc/SuSE-release ]; then
87         sles_version=$(sles_version_code)
88         [ $sles_version -lt $(version_code 11.4.0) ] &&
89                 # bug number for skipped test: LU-4341
90                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT  170"
91         [ $sles_version -lt $(version_code 12.0.0) ] &&
92                 # bug number for skipped test: LU-3703
93                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT  234"
94 fi
95
96 FAIL_ON_ERROR=false
97
98 cleanup() {
99         echo -n "cln.."
100         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
101         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
102 }
103 setup() {
104         echo -n "mnt.."
105         load_modules
106         setupall || exit 10
107         echo "done"
108 }
109
110 check_swap_layouts_support()
111 {
112         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
113                 { skip "Does not support layout lock."; return 0; }
114         return 1
115 }
116
117 check_and_setup_lustre
118 DIR=${DIR:-$MOUNT}
119 assert_DIR
120
121 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
122
123 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
124 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
125 rm -rf $DIR/[Rdfs][0-9]*
126
127 # $RUNAS_ID may get set incorrectly somewhere else
128 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
129
130 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
131
132 build_test_filter
133
134 if [ "${ONLY}" = "MOUNT" ] ; then
135         echo "Lustre is up, please go on"
136         exit
137 fi
138
139 echo "preparing for tests involving mounts"
140 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
141 touch $EXT2_DEV
142 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
143 echo # add a newline after mke2fs.
144
145 umask 077
146
147 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
148 lctl set_param debug=-1 2> /dev/null || true
149 test_0a() {
150         touch $DIR/$tfile
151         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
152         rm $DIR/$tfile
153         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
154 }
155 run_test 0a "touch; rm ====================="
156
157 test_0b() {
158         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
159         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
160 }
161 run_test 0b "chmod 0755 $DIR ============================="
162
163 test_0c() {
164         $LCTL get_param mdc.*.import | grep "state: FULL" ||
165                 error "import not FULL"
166         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
167                 error "bad target"
168 }
169 run_test 0c "check import proc"
170
171 test_0d() { # LU-3397
172         [ $(lustre_version_code mgs) -lt $(version_code 2.10.57) ] &&
173                 skip "proc exports not supported before 2.10.57" && return
174
175         local mgs_exp="mgs.MGS.exports"
176         local client_uuid=$($LCTL get_param -n mgc.*.uuid)
177         local exp_client_nid
178         local exp_client_version
179         local exp_val
180         local imp_val
181         local temp_imp=$DIR/$tfile.import
182         local temp_exp=$DIR/$tfile.export
183
184         # save mgc import file to $temp_imp
185         $LCTL get_param mgc.*.import | tee $temp_imp
186         # Check if client uuid is found in MGS export
187         for exp_client_nid in $(do_facet mgs $LCTL get_param -N $mgs_exp.*); do
188                 [ $(do_facet mgs $LCTL get_param $exp_client_nid.uuid) == \
189                         $client_uuid ] &&
190                         break;
191         done
192         # save mgs export file to $temp_exp
193         do_facet mgs $LCTL get_param $exp_client_nid.export | tee $temp_exp
194
195         # Compare the value of field "connect_flags"
196         imp_val=$(grep "connect_flags" $temp_imp)
197         exp_val=$(grep "connect_flags" $temp_exp)
198         [ "$exp_val" == "$imp_val" ] ||
199                 error "export flags '$exp_val' != import flags '$imp_val'"
200
201         # Compare the value of client version
202         exp_client_version=$(awk '/target_version:/ { print $2 }' $temp_exp)
203         exp_val=$(version_code $exp_client_version)
204         imp_val=$(lustre_version_code client)
205         [ "$exp_val" == "$imp_val" ] ||
206                 error "export client version '$exp_val' != '$imp_val'"
207 }
208 run_test 0d "check export proc ============================="
209
210 test_1() {
211         test_mkdir $DIR/$tdir
212         test_mkdir $DIR/$tdir/d2
213         mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
214         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
215         rmdir $DIR/$tdir/d2
216         rmdir $DIR/$tdir
217         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
218 }
219 run_test 1 "mkdir; remkdir; rmdir"
220
221 test_2() {
222         test_mkdir $DIR/$tdir
223         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
224         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
225         rm -r $DIR/$tdir
226         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
227 }
228 run_test 2 "mkdir; touch; rmdir; check file"
229
230 test_3() {
231         test_mkdir $DIR/$tdir
232         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
233         touch $DIR/$tdir/$tfile
234         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
235         rm -r $DIR/$tdir
236         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
237 }
238 run_test 3 "mkdir; touch; rmdir; check dir"
239
240 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
241 test_4() {
242         test_mkdir -i 1 $DIR/$tdir
243
244         touch $DIR/$tdir/$tfile ||
245                 error "Create file under remote directory failed"
246
247         rmdir $DIR/$tdir &&
248                 error "Expect error removing in-use dir $DIR/$tdir"
249
250         test -d $DIR/$tdir || error "Remote directory disappeared"
251
252         rm -rf $DIR/$tdir || error "remove remote dir error"
253 }
254 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
255
256 test_5() {
257         test_mkdir $DIR/$tdir
258         test_mkdir $DIR/$tdir/d2
259         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
260         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
261         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
262 }
263 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2"
264
265 test_6a() {
266         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
267         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
268         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
269                 error "$tfile does not have perm 0666 or UID $UID"
270         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
271         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
272                 error "$tfile should be 0666 and owned by UID $UID"
273 }
274 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
275
276 test_6c() {
277         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
278         touch $DIR/$tfile
279         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
280         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
281                 error "$tfile should be owned by UID $RUNAS_ID"
282         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
283         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
284                 error "$tfile should be owned by UID $RUNAS_ID"
285 }
286 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
287
288 test_6e() {
289         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
290         touch $DIR/$tfile
291         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
292         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
293                 error "$tfile should be owned by GID $UID"
294         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
295         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
296                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
297 }
298 run_test 6e "touch+chgrp $tfile; $RUNAS chgrp $tfile (should return error)"
299
300 test_6g() {
301         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
302         test_mkdir $DIR/$tdir
303         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
304         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
305         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
306         test_mkdir $DIR/$tdir/d/subdir
307         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
308                 error "$tdir/d/subdir should be GID $RUNAS_GID"
309         if [[ $MDSCOUNT -gt 1 ]]; then
310                 # check remote dir sgid inherite
311                 $LFS mkdir -i 0 $DIR/$tdir.local ||
312                         error "mkdir $tdir.local failed"
313                 chmod g+s $DIR/$tdir.local ||
314                         error "chmod $tdir.local failed"
315                 chgrp $RUNAS_GID $DIR/$tdir.local ||
316                         error "chgrp $tdir.local failed"
317                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
318                         error "mkdir $tdir.remote failed"
319                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
320                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
321                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
322                         error "$tdir.remote should be mode 02755"
323         fi
324 }
325 run_test 6g "verify new dir in sgid dir inherits group"
326
327 test_6h() { # bug 7331
328         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
329         touch $DIR/$tfile || error "touch failed"
330         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
331         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
332                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
333         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
334                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
335 }
336 run_test 6h "$RUNAS chown RUNAS_ID.0 .../$tfile (should return error)"
337
338 test_7a() {
339         test_mkdir $DIR/$tdir
340         $MCREATE $DIR/$tdir/$tfile
341         chmod 0666 $DIR/$tdir/$tfile
342         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
343                 error "$tdir/$tfile should be mode 0666"
344 }
345 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
346
347 test_7b() {
348         if [ ! -d $DIR/$tdir ]; then
349                 test_mkdir $DIR/$tdir
350         fi
351         $MCREATE $DIR/$tdir/$tfile
352         echo -n foo > $DIR/$tdir/$tfile
353         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
354         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
355 }
356 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
357
358 test_8() {
359         test_mkdir $DIR/$tdir
360         touch $DIR/$tdir/$tfile
361         chmod 0666 $DIR/$tdir/$tfile
362         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
363                 error "$tfile mode not 0666"
364 }
365 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
366
367 test_9() {
368         test_mkdir $DIR/$tdir
369         test_mkdir $DIR/$tdir/d2
370         test_mkdir $DIR/$tdir/d2/d3
371         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
372 }
373 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
374
375 test_10() {
376         test_mkdir $DIR/$tdir
377         test_mkdir $DIR/$tdir/d2
378         touch $DIR/$tdir/d2/$tfile
379         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
380                 error "$tdir/d2/$tfile not a file"
381 }
382 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
383
384 test_11() {
385         test_mkdir $DIR/$tdir
386         test_mkdir $DIR/$tdir/d2
387         chmod 0666 $DIR/$tdir/d2
388         chmod 0705 $DIR/$tdir/d2
389         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
390                 error "$tdir/d2 mode not 0705"
391 }
392 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
393
394 test_12() {
395         test_mkdir $DIR/$tdir
396         touch $DIR/$tdir/$tfile
397         chmod 0666 $DIR/$tdir/$tfile
398         chmod 0654 $DIR/$tdir/$tfile
399         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
400                 error "$tdir/d2 mode not 0654"
401 }
402 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
403
404 test_13() {
405         test_mkdir $DIR/$tdir
406         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
407         >  $DIR/$tdir/$tfile
408         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
409                 error "$tdir/$tfile size not 0 after truncate"
410 }
411 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
412
413 test_14() {
414         test_mkdir $DIR/$tdir
415         touch $DIR/$tdir/$tfile
416         rm $DIR/$tdir/$tfile
417         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
418 }
419 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
420
421 test_15() {
422         test_mkdir $DIR/$tdir
423         touch $DIR/$tdir/$tfile
424         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
425         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
426                 error "$tdir/${tfile_2} not a file after rename"
427         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
428 }
429 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
430
431 test_16() {
432         test_mkdir $DIR/$tdir
433         touch $DIR/$tdir/$tfile
434         rm -rf $DIR/$tdir/$tfile
435         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
436 }
437 run_test 16 "touch .../d16/f; rm -rf .../d16/f"
438
439 test_17a() {
440         test_mkdir $DIR/$tdir
441         touch $DIR/$tdir/$tfile
442         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
443         ls -l $DIR/$tdir
444         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
445                 error "$tdir/l-exist not a symlink"
446         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
447                 error "$tdir/l-exist not referencing a file"
448         rm -f $DIR/$tdir/l-exist
449         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
450 }
451 run_test 17a "symlinks: create, remove (real)"
452
453 test_17b() {
454         test_mkdir $DIR/$tdir
455         ln -s no-such-file $DIR/$tdir/l-dangle
456         ls -l $DIR/$tdir
457         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
458                 error "$tdir/l-dangle not referencing no-such-file"
459         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
460                 error "$tdir/l-dangle not referencing non-existent file"
461         rm -f $DIR/$tdir/l-dangle
462         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
463 }
464 run_test 17b "symlinks: create, remove (dangling)"
465
466 test_17c() { # bug 3440 - don't save failed open RPC for replay
467         test_mkdir $DIR/$tdir
468         ln -s foo $DIR/$tdir/$tfile
469         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
470 }
471 run_test 17c "symlinks: open dangling (should return error)"
472
473 test_17d() {
474         test_mkdir $DIR/$tdir
475         ln -s foo $DIR/$tdir/$tfile
476         touch $DIR/$tdir/$tfile || error "creating to new symlink"
477 }
478 run_test 17d "symlinks: create dangling"
479
480 test_17e() {
481         test_mkdir $DIR/$tdir
482         local foo=$DIR/$tdir/$tfile
483         ln -s $foo $foo || error "create symlink failed"
484         ls -l $foo || error "ls -l failed"
485         ls $foo && error "ls not failed" || true
486 }
487 run_test 17e "symlinks: create recursive symlink (should return error)"
488
489 test_17f() {
490         test_mkdir $DIR/$tdir
491         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
492         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
493         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
494         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
495         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
496         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
497         ls -l  $DIR/$tdir
498 }
499 run_test 17f "symlinks: long and very long symlink name"
500
501 # str_repeat(S, N) generate a string that is string S repeated N times
502 str_repeat() {
503         local s=$1
504         local n=$2
505         local ret=''
506         while [ $((n -= 1)) -ge 0 ]; do
507                 ret=$ret$s
508         done
509         echo $ret
510 }
511
512 # Long symlinks and LU-2241
513 test_17g() {
514         test_mkdir $DIR/$tdir
515         local TESTS="59 60 61 4094 4095"
516
517         # Fix for inode size boundary in 2.1.4
518         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
519                 TESTS="4094 4095"
520
521         # Patch not applied to 2.2 or 2.3 branches
522         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
523         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
524                 TESTS="4094 4095"
525
526         # skip long symlink name for rhel6.5.
527         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
528         grep -q '6.5' /etc/redhat-release &>/dev/null &&
529                 TESTS="59 60 61 4062 4063"
530
531         for i in $TESTS; do
532                 local SYMNAME=$(str_repeat 'x' $i)
533                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
534                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
535         done
536 }
537 run_test 17g "symlinks: really long symlink name and inode boundaries"
538
539 test_17h() { #bug 17378
540         remote_mds_nodsh && skip "remote MDS with nodsh" && return
541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
542         local mdt_idx
543         test_mkdir $DIR/$tdir
544         mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
545         $LFS setstripe -c -1 $DIR/$tdir
546         #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
547         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
548         touch $DIR/$tdir/$tfile || true
549 }
550 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
551
552 test_17i() { #bug 20018
553         remote_mds_nodsh && skip "remote MDS with nodsh" && return
554         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
555         test_mkdir -c1 $DIR/$tdir
556         local foo=$DIR/$tdir/$tfile
557         local mdt_idx
558         mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
559         ln -s $foo $foo || error "create symlink failed"
560 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
561         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
562         ls -l $foo && error "error not detected"
563         return 0
564 }
565 run_test 17i "don't panic on short symlink (should return error)"
566
567 test_17k() { #bug 22301
568         [[ -z "$(which rsync 2>/dev/null)" ]] &&
569                 skip "no rsync command" && return 0
570         rsync --help | grep -q xattr ||
571                 skip_env "$(rsync --version | head -n1) does not support xattrs"
572         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
573         test_mkdir $DIR/$tdir
574         test_mkdir $DIR/$tdir.new
575         touch $DIR/$tdir/$tfile
576         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
577         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
578                 error "rsync failed with xattrs enabled"
579 }
580 run_test 17k "symlinks: rsync with xattrs enabled"
581
582 test_17l() { # LU-279
583         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
584                 skip "no getfattr command" && return 0
585         test_mkdir $DIR/$tdir
586         touch $DIR/$tdir/$tfile
587         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
588         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
589                 # -h to not follow symlinks. -m '' to list all the xattrs.
590                 # grep to remove first line: '# file: $path'.
591                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
592                 do
593                         lgetxattr_size_check $path $xattr ||
594                                 error "lgetxattr_size_check $path $xattr failed"
595                 done
596         done
597 }
598 run_test 17l "Ensure lgetxattr's returned xattr size is consistent"
599
600 # LU-1540
601 test_17m() {
602         local short_sym="0123456789"
603         local wdir=$DIR/$tdir
604         local i
605
606         remote_mds_nodsh && skip "remote MDS with nodsh" && return
607         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
608         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
609                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
610
611         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
612                 skip "ldiskfs only test" && return 0
613
614         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
615
616         test_mkdir $wdir
617         long_sym=$short_sym
618         # create a long symlink file
619         for ((i = 0; i < 4; ++i)); do
620                 long_sym=${long_sym}${long_sym}
621         done
622
623         echo "create 512 short and long symlink files under $wdir"
624         for ((i = 0; i < 256; ++i)); do
625                 ln -sf ${long_sym}"a5a5" $wdir/long-$i
626                 ln -sf ${short_sym}"a5a5" $wdir/short-$i
627         done
628
629         echo "erase them"
630         rm -f $wdir/*
631         sync
632         wait_delete_completed
633
634         echo "recreate the 512 symlink files with a shorter string"
635         for ((i = 0; i < 512; ++i)); do
636                 # rewrite the symlink file with a shorter string
637                 ln -sf ${long_sym} $wdir/long-$i || error "long_sym failed"
638                 ln -sf ${short_sym} $wdir/short-$i || error "short_sym failed"
639         done
640
641         local mds_index=$(($($LFS getstripe -M $wdir) + 1))
642         local devname=$(mdsdevname $mds_index)
643
644         echo "stop and checking mds${mds_index}:"
645         # e2fsck should not return error
646         stop mds${mds_index}
647         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
648         rc=$?
649
650         start mds${mds_index} $devname $MDS_MOUNT_OPTS ||
651                 error "start mds${mds_index} failed"
652         df $MOUNT > /dev/null 2>&1
653         [ $rc -eq 0 ] ||
654                 error "e2fsck detected error for short/long symlink: rc=$rc"
655         rm -f $wdir/*
656 }
657 run_test 17m "run e2fsck against MDT which contains short/long symlink"
658
659 check_fs_consistency_17n() {
660         local mdt_index
661         local rc=0
662
663         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
664         # so it only check MDT1/MDT2 instead of all of MDTs.
665         for mdt_index in 1 2; do
666                 local devname=$(mdsdevname $mdt_index)
667                 # e2fsck should not return error
668                 stop mds${mdt_index}
669                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
670                         rc=$((rc + $?))
671
672                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
673                         error "mount mds$mdt_index failed"
674                 df $MOUNT > /dev/null 2>&1
675         done
676         return $rc
677 }
678
679 test_17n() {
680         local i
681
682         remote_mds_nodsh && skip "remote MDS with nodsh" && return
683         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
684         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
685                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
686
687         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
688                 skip "ldiskfs only test" && return 0
689
690         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
691
692         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
693
694         test_mkdir $DIR/$tdir
695         for ((i=0; i<10; i++)); do
696                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
697                         error "create remote dir error $i"
698                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
699                         error "create files under remote dir failed $i"
700         done
701
702         check_fs_consistency_17n ||
703                 error "e2fsck report error after create files under remote dir"
704
705         for ((i = 0; i < 10; i++)); do
706                 rm -rf $DIR/$tdir/remote_dir_${i} ||
707                         error "destroy remote dir error $i"
708         done
709
710         check_fs_consistency_17n ||
711                 error "e2fsck report error after unlink files under remote dir"
712
713         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
714                 skip "lustre < 2.4.50 does not support migrate mv " && return
715
716         for ((i = 0; i < 10; i++)); do
717                 mkdir -p $DIR/$tdir/remote_dir_${i}
718                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
719                         error "create files under remote dir failed $i"
720                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
721                         error "migrate remote dir error $i"
722         done
723         check_fs_consistency_17n || error "e2fsck report error after migration"
724
725         for ((i = 0; i < 10; i++)); do
726                 rm -rf $DIR/$tdir/remote_dir_${i} ||
727                         error "destroy remote dir error $i"
728         done
729
730         check_fs_consistency_17n || error "e2fsck report error after unlink"
731 }
732 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
733
734 test_17o() {
735         remote_mds_nodsh && skip "remote MDS with nodsh" && return
736         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
737                 skip "Need MDS version at least 2.3.64" && return
738
739         local wdir=$DIR/${tdir}o
740         local mdt_index
741         local rc=0
742
743         test_mkdir $wdir
744         touch $wdir/$tfile
745         mdt_index=$($LFS getstripe -M $wdir/$tfile)
746         mdt_index=$((mdt_index + 1))
747
748         cancel_lru_locks mdc
749         #fail mds will wait the failover finish then set
750         #following fail_loc to avoid interfer the recovery process.
751         fail mds${mdt_index}
752
753         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
754         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
755         ls -l $wdir/$tfile && rc=1
756         do_facet mds${mdt_index} lctl set_param fail_loc=0
757         [[ $rc -eq 0 ]] || error "stat file should fail"
758 }
759 run_test 17o "stat file with incompat LMA feature"
760
761 test_18() {
762         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
763         ls $DIR || error "Failed to ls $DIR: $?"
764 }
765 run_test 18 "touch .../f ; ls ... =============================="
766
767 test_19a() {
768         touch $DIR/$tfile
769         ls -l $DIR
770         rm $DIR/$tfile
771         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
772 }
773 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
774
775 test_19b() {
776         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
777 }
778 run_test 19b "ls -l .../f19 (should return error) =============="
779
780 test_19c() {
781         [ $RUNAS_ID -eq $UID ] &&
782                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
783         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
784 }
785 run_test 19c "$RUNAS touch .../f19 (should return error) =="
786
787 test_19d() {
788         cat $DIR/f19 && error || true
789 }
790 run_test 19d "cat .../f19 (should return error) =============="
791
792 test_20() {
793         touch $DIR/$tfile
794         rm $DIR/$tfile
795         touch $DIR/$tfile
796         rm $DIR/$tfile
797         touch $DIR/$tfile
798         rm $DIR/$tfile
799         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
800 }
801 run_test 20 "touch .../f ; ls -l ..."
802
803 test_21() {
804         test_mkdir $DIR/$tdir
805         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
806         ln -s dangle $DIR/$tdir/link
807         echo foo >> $DIR/$tdir/link
808         cat $DIR/$tdir/dangle
809         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
810         $CHECKSTAT -f -t file $DIR/$tdir/link ||
811                 error "$tdir/link not linked to a file"
812 }
813 run_test 21 "write to dangling link"
814
815 test_22() {
816         local wdir=$DIR/$tdir
817         test_mkdir $wdir
818         chown $RUNAS_ID:$RUNAS_GID $wdir
819         (cd $wdir || error "cd $wdir failed";
820                 $RUNAS tar cf - /etc/hosts /etc/sysconfig/network |
821                 $RUNAS tar xf -)
822         ls -lR $wdir/etc || error "ls -lR $wdir/etc failed"
823         $CHECKSTAT -t dir $wdir/etc || error "checkstat -t dir failed"
824         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $wdir/etc ||
825                 error "checkstat -u failed"
826 }
827 run_test 22 "unpack tar archive as non-root user"
828
829 # was test_23
830 test_23a() {
831         test_mkdir $DIR/$tdir
832         local file=$DIR/$tdir/$tfile
833
834         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
835         openfile -f O_CREAT:O_EXCL $file &&
836                 error "$file recreate succeeded" || true
837 }
838 run_test 23a "O_CREAT|O_EXCL in subdir"
839
840 test_23b() { # bug 18988
841         test_mkdir $DIR/$tdir
842         local file=$DIR/$tdir/$tfile
843
844         rm -f $file
845         echo foo > $file || error "write filed"
846         echo bar >> $file || error "append filed"
847         $CHECKSTAT -s 8 $file || error "wrong size"
848         rm $file
849 }
850 run_test 23b "O_APPEND check"
851
852 # LU-9409, size with O_APPEND and tiny writes
853 test_23c() {
854         local file=$DIR/$tfile
855
856         # single dd
857         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800
858         $CHECKSTAT -s 6400 $file || error "wrong size, expected 6400"
859         rm -f $file
860
861         # racing tiny writes
862         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
863         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
864         wait
865         $CHECKSTAT -s 12800 $file || error "wrong size, expected 12800"
866         rm -f $file
867
868         #racing tiny & normal writes
869         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4096 count=4 &
870         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=100 &
871         wait
872         $CHECKSTAT -s 17184 $file || error "wrong size, expected 17184"
873         rm -f $file
874
875         #racing tiny & normal writes 2, ugly numbers
876         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4099 count=11 &
877         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=17 count=173 &
878         wait
879         $CHECKSTAT -s 48030 $file || error "wrong size, expected 48030"
880         rm -f $file
881 }
882 run_test 23c "O_APPEND size checks for tiny writes"
883
884 # rename sanity
885 test_24a() {
886         echo '-- same directory rename'
887         test_mkdir $DIR/$tdir
888         touch $DIR/$tdir/$tfile.1
889         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
890         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
891 }
892 run_test 24a "rename file to non-existent target"
893
894 test_24b() {
895         test_mkdir $DIR/$tdir
896         touch $DIR/$tdir/$tfile.{1,2}
897         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
898         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
899         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
900 }
901 run_test 24b "rename file to existing target"
902
903 test_24c() {
904         test_mkdir $DIR/$tdir
905         test_mkdir $DIR/$tdir/d$testnum.1
906         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
907         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
908         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
909 }
910 run_test 24c "rename directory to non-existent target"
911
912 test_24d() {
913         test_mkdir -c1 $DIR/$tdir
914         test_mkdir -c1 $DIR/$tdir/d$testnum.1
915         test_mkdir -c1 $DIR/$tdir/d$testnum.2
916         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
917         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
918         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
919 }
920 run_test 24d "rename directory to existing target"
921
922 test_24e() {
923         echo '-- cross directory renames --'
924         test_mkdir $DIR/R5a
925         test_mkdir $DIR/R5b
926         touch $DIR/R5a/f
927         mv $DIR/R5a/f $DIR/R5b/g
928         $CHECKSTAT -a $DIR/R5a/f || error "$DIR/R5a/f exists"
929         $CHECKSTAT -t file $DIR/R5b/g || error "$DIR/R5b/g not file type"
930 }
931 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
932
933 test_24f() {
934         test_mkdir $DIR/R6a
935         test_mkdir $DIR/R6b
936         touch $DIR/R6a/f $DIR/R6b/g
937         mv $DIR/R6a/f $DIR/R6b/g
938         $CHECKSTAT -a $DIR/R6a/f || error "$DIR/R6a/f exists"
939         $CHECKSTAT -t file $DIR/R6b/g || error "$DIR/R6b/g not file type"
940 }
941 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
942
943 test_24g() {
944         test_mkdir $DIR/R7a
945         test_mkdir $DIR/R7b
946         test_mkdir $DIR/R7a/d
947         mv $DIR/R7a/d $DIR/R7b/e
948         $CHECKSTAT -a $DIR/R7a/d || error "$DIR/R7a/d exists"
949         $CHECKSTAT -t dir $DIR/R7b/e || error "$DIR/R7b/e not dir type"
950 }
951 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
952
953 test_24h() {
954         test_mkdir -c1 $DIR/R8a
955         test_mkdir -c1 $DIR/R8b
956         test_mkdir -c1 $DIR/R8a/d
957         test_mkdir -c1 $DIR/R8b/e
958         mrename $DIR/R8a/d $DIR/R8b/e
959         $CHECKSTAT -a $DIR/R8a/d || error "$DIR/R8a/d exists"
960         $CHECKSTAT -t dir $DIR/R8b/e || error "$DIR/R8b/e not dir type"
961 }
962 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
963
964 test_24i() {
965         echo "-- rename error cases"
966         test_mkdir $DIR/R9
967         test_mkdir $DIR/R9/a
968         touch $DIR/R9/f
969         mrename $DIR/R9/f $DIR/R9/a
970         $CHECKSTAT -t file $DIR/R9/f || error "$DIR/R9/f not file type"
971         $CHECKSTAT -t dir  $DIR/R9/a || error "$DIR/R9/a not dir type"
972         $CHECKSTAT -a $DIR/R9/a/f || error "$DIR/R9/a/f exists"
973 }
974 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
975
976 test_24j() {
977         test_mkdir $DIR/R10
978         mrename $DIR/R10/f $DIR/R10/g
979         $CHECKSTAT -t dir $DIR/R10 || error "$DIR/R10 not dir type"
980         $CHECKSTAT -a $DIR/R10/f || error "$DIR/R10/f exists"
981         $CHECKSTAT -a $DIR/R10/g || error "$DIR/R10/g exists"
982 }
983 run_test 24j "source does not exist ============================"
984
985 test_24k() {
986         test_mkdir $DIR/R11a
987         test_mkdir $DIR/R11a/d
988         touch $DIR/R11a/f
989         mv $DIR/R11a/f $DIR/R11a/d
990         $CHECKSTAT -a $DIR/R11a/f || error "$DIR/R11a/f exists"
991         $CHECKSTAT -t file $DIR/R11a/d/f || error "$DIR/R11a/d/f not file type"
992 }
993 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
994
995 # bug 2429 - rename foo foo foo creates invalid file
996 test_24l() {
997         f="$DIR/f24l"
998         $MULTIOP $f OcNs || error "rename of ${f} to itself failed"
999 }
1000 run_test 24l "Renaming a file to itself ========================"
1001
1002 test_24m() {
1003         f="$DIR/f24m"
1004         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
1005         # on ext3 this does not remove either the source or target files
1006         # though the "expected" operation would be to remove the source
1007         $CHECKSTAT -t file ${f} || error "${f} missing"
1008         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
1009 }
1010 run_test 24m "Renaming a file to a hard link to itself ========="
1011
1012 test_24n() {
1013     f="$DIR/f24n"
1014     # this stats the old file after it was renamed, so it should fail
1015     touch ${f}
1016     $CHECKSTAT ${f} || error "${f} missing"
1017     mv ${f} ${f}.rename
1018     $CHECKSTAT ${f}.rename || error "${f}.rename missing"
1019     $CHECKSTAT -a ${f} || error "${f} exists"
1020 }
1021 run_test 24n "Statting the old file after renaming (Posix rename 2)"
1022
1023 test_24o() {
1024         test_mkdir $DIR/$tdir
1025         rename_many -s random -v -n 10 $DIR/$tdir
1026 }
1027 run_test 24o "rename of files during htree split"
1028
1029 test_24p() {
1030         test_mkdir $DIR/R12a
1031         test_mkdir $DIR/R12b
1032         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
1033         mrename $DIR/R12a $DIR/R12b
1034         $CHECKSTAT -a $DIR/R12a || error "$DIR/R12a exists"
1035         $CHECKSTAT -t dir $DIR/R12b || error "$DIR/R12b not dir type"
1036         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
1037         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
1038 }
1039 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
1040
1041 cleanup_multiop_pause() {
1042         trap 0
1043         kill -USR1 $MULTIPID
1044 }
1045
1046 test_24q() {
1047         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1048         test_mkdir $DIR/R13a
1049         test_mkdir $DIR/R13b
1050         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
1051         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
1052         MULTIPID=$!
1053
1054         trap cleanup_multiop_pause EXIT
1055         mrename $DIR/R13a $DIR/R13b
1056         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1057         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1058         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1059         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1060         cleanup_multiop_pause
1061         wait $MULTIPID || error "multiop close failed"
1062 }
1063 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1064
1065 test_24r() { #bug 3789
1066         test_mkdir $DIR/R14a
1067         test_mkdir $DIR/R14a/b
1068         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1069         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1070         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1071 }
1072 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1073
1074 test_24s() {
1075         test_mkdir $DIR/R15a
1076         test_mkdir $DIR/R15a/b
1077         test_mkdir $DIR/R15a/b/c
1078         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1079         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1080         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1081 }
1082 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1083 test_24t() {
1084         test_mkdir $DIR/R16a
1085         test_mkdir $DIR/R16a/b
1086         test_mkdir $DIR/R16a/b/c
1087         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1088         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1089         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1090 }
1091 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1092
1093 test_24u() { # bug12192
1094         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error "multiop failed"
1095         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1096 }
1097 run_test 24u "create stripe file"
1098
1099 page_size() {
1100         local size
1101         size=$(getconf PAGE_SIZE 2>/dev/null)
1102         echo -n ${size:-4096}
1103 }
1104
1105 simple_cleanup_common() {
1106         local rc=0
1107         trap 0
1108         [ -z "$DIR" -o -z "$tdir" ] && return 0
1109
1110         local start=$SECONDS
1111         rm -rf $DIR/$tdir
1112         rc=$?
1113         wait_delete_completed
1114         echo "cleanup time $((SECONDS - start))"
1115         return $rc
1116 }
1117
1118 max_pages_per_rpc() {
1119         local mdtname="$(printf "MDT%04x" ${1:-0})"
1120         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1121 }
1122
1123 test_24v() {
1124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1125         local nrfiles=${COUNT:-100000}
1126         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1127         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
1128
1129         local fname="$DIR/$tdir/$tfile"
1130         test_mkdir "$(dirname $fname)"
1131         # assume MDT0000 has the fewest inodes
1132         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1133         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1134         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1135
1136         trap simple_cleanup_common EXIT
1137
1138         createmany -m "$fname" $nrfiles
1139
1140         cancel_lru_locks mdc
1141         lctl set_param mdc.*.stats clear
1142
1143         # was previously test_24D: LU-6101
1144         # readdir() returns correct number of entries after cursor reload
1145         local num_ls=$(ls $DIR/$tdir | wc -l)
1146         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1147         local num_all=$(ls -a $DIR/$tdir | wc -l)
1148         if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
1149              $num_all -ne $((nrfiles + 2)) ]; then
1150                 error "Expected $nrfiles files, got $num_ls " \
1151                         "($num_uniq unique $num_all .&..)"
1152         fi
1153         # LU-5 large readdir
1154         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1155         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1156         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1157         # take into account of overhead in lu_dirpage header and end mark in
1158         # each page, plus one in rpc_num calculation.
1159         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1160         local page_entries=$((($(page_size) - 24) / dirent_size))
1161         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1162         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1163         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1164         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1165         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1166         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1167                 error "large readdir doesn't take effect: " \
1168                       "$mds_readpage should be about $rpc_max"
1169
1170         simple_cleanup_common
1171 }
1172 run_test 24v "list large directory (test hash collision, b=17560)"
1173
1174 test_24w() { # bug21506
1175         SZ1=234852
1176         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1177         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1178         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1179         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1180         [[ "$SZ1" -eq "$SZ2" ]] ||
1181                 error "Error reading at the end of the file $tfile"
1182 }
1183 run_test 24w "Reading a file larger than 4Gb"
1184
1185 test_24x() {
1186         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1187
1188         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1189                 skip "Need MDS version at least 2.7.56" && return
1190
1191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1192         local MDTIDX=1
1193         local remote_dir=$DIR/$tdir/remote_dir
1194
1195         test_mkdir $DIR/$tdir
1196         $LFS mkdir -i $MDTIDX $remote_dir ||
1197                 error "create remote directory failed"
1198
1199         test_mkdir $DIR/$tdir/src_dir
1200         touch $DIR/$tdir/src_file
1201         test_mkdir $remote_dir/tgt_dir
1202         touch $remote_dir/tgt_file
1203
1204         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1205                 error "rename dir cross MDT failed!"
1206
1207         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1208                 error "rename file cross MDT failed!"
1209
1210         touch $DIR/$tdir/ln_file
1211         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1212                 error "ln file cross MDT failed"
1213
1214         rm -rf $DIR/$tdir || error "Can not delete directories"
1215 }
1216 run_test 24x "cross MDT rename/link"
1217
1218 test_24y() {
1219         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1220         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1221         local remote_dir=$DIR/$tdir/remote_dir
1222         local mdtidx=1
1223
1224         test_mkdir $DIR/$tdir
1225         $LFS mkdir -i $mdtidx $remote_dir ||
1226                    error "create remote directory failed"
1227
1228         test_mkdir $remote_dir/src_dir
1229         touch $remote_dir/src_file
1230         test_mkdir $remote_dir/tgt_dir
1231         touch $remote_dir/tgt_file
1232
1233         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1234                 error "rename subdir in the same remote dir failed!"
1235
1236         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1237                 error "rename files in the same remote dir failed!"
1238
1239         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1240                 error "link files in the same remote dir failed!"
1241
1242         rm -rf $DIR/$tdir || error "Can not delete directories"
1243 }
1244 run_test 24y "rename/link on the same dir should succeed"
1245
1246 test_24A() { # LU-3182
1247         local NFILES=5000
1248
1249         rm -rf $DIR/$tdir
1250         test_mkdir $DIR/$tdir
1251         trap simple_cleanup_common EXIT
1252         createmany -m $DIR/$tdir/$tfile $NFILES
1253         local t=$(ls $DIR/$tdir | wc -l)
1254         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1255         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1256         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1257                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1258         fi
1259
1260         simple_cleanup_common || error "Can not delete directories"
1261 }
1262 run_test 24A "readdir() returns correct number of entries."
1263
1264 test_24B() { # LU-4805
1265         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1266         local count
1267
1268         test_mkdir $DIR/$tdir
1269         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1270                 error "create striped dir failed"
1271
1272         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1273         [ $count -eq 2 ] || error "Expected 2, got $count"
1274
1275         touch $DIR/$tdir/striped_dir/a
1276
1277         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1278         [ $count -eq 3 ] || error "Expected 3, got $count"
1279
1280         touch $DIR/$tdir/striped_dir/.f
1281
1282         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1283         [ $count -eq 4 ] || error "Expected 4, got $count"
1284
1285         rm -rf $DIR/$tdir || error "Can not delete directories"
1286 }
1287 run_test 24B "readdir for striped dir return correct number of entries"
1288
1289 test_24C() {
1290         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1291
1292         mkdir $DIR/$tdir
1293         mkdir $DIR/$tdir/d0
1294         mkdir $DIR/$tdir/d1
1295
1296         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1297                 error "create striped dir failed"
1298
1299         cd $DIR/$tdir/d0/striped_dir
1300
1301         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1302         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1303         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1304
1305         [ "$d0_ino" = "$parent_ino" ] ||
1306                 error ".. wrong, expect $d0_ino, get $parent_ino"
1307
1308         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1309                 error "mv striped dir failed"
1310
1311         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1312
1313         [ "$d1_ino" = "$parent_ino" ] ||
1314                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1315 }
1316 run_test 24C "check .. in striped dir"
1317
1318 test_24E() {
1319         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1320         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1321
1322         mkdir -p $DIR/$tdir
1323         mkdir $DIR/$tdir/src_dir
1324         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1325                 error "create remote source failed"
1326
1327         touch $DIR/$tdir/src_dir/src_child/a
1328
1329         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1330                 error "create remote target dir failed"
1331
1332         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1333                 error "create remote target child failed"
1334
1335         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1336                 error "rename dir cross MDT failed!"
1337
1338         find $DIR/$tdir
1339
1340         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1341                 error "src_child still exists after rename"
1342
1343         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1344                 error "missing file(a) after rename"
1345
1346         rm -rf $DIR/$tdir || error "Can not delete directories"
1347 }
1348 run_test 24E "cross MDT rename/link"
1349
1350 test_25a() {
1351         echo '== symlink sanity ============================================='
1352
1353         test_mkdir $DIR/d25
1354         ln -s d25 $DIR/s25
1355         touch $DIR/s25/foo ||
1356                 error "File creation in symlinked directory failed"
1357 }
1358 run_test 25a "create file in symlinked directory ==============="
1359
1360 test_25b() {
1361         [ ! -d $DIR/d25 ] && test_25a
1362         $CHECKSTAT -t file $DIR/s25/foo || error "$DIR/s25/foo not file type"
1363 }
1364 run_test 25b "lookup file in symlinked directory ==============="
1365
1366 test_26a() {
1367         test_mkdir $DIR/d26
1368         test_mkdir $DIR/d26/d26-2
1369         ln -s d26/d26-2 $DIR/s26
1370         touch $DIR/s26/foo || error "File creation failed"
1371 }
1372 run_test 26a "multiple component symlink ======================="
1373
1374 test_26b() {
1375         test_mkdir -p $DIR/$tdir/d26-2
1376         ln -s $tdir/d26-2/foo $DIR/s26-2
1377         touch $DIR/s26-2 || error "File creation failed"
1378 }
1379 run_test 26b "multiple component symlink at end of lookup ======"
1380
1381 test_26c() {
1382         test_mkdir $DIR/d26.2
1383         touch $DIR/d26.2/foo
1384         ln -s d26.2 $DIR/s26.2-1
1385         ln -s s26.2-1 $DIR/s26.2-2
1386         ln -s s26.2-2 $DIR/s26.2-3
1387         chmod 0666 $DIR/s26.2-3/foo
1388 }
1389 run_test 26c "chain of symlinks"
1390
1391 # recursive symlinks (bug 439)
1392 test_26d() {
1393         ln -s d26-3/foo $DIR/d26-3
1394 }
1395 run_test 26d "create multiple component recursive symlink"
1396
1397 test_26e() {
1398         [ ! -h $DIR/d26-3 ] && test_26d
1399         rm $DIR/d26-3
1400 }
1401 run_test 26e "unlink multiple component recursive symlink"
1402
1403 # recursive symlinks (bug 7022)
1404 test_26f() {
1405         test_mkdir $DIR/$tdir
1406         test_mkdir $DIR/$tdir/$tfile
1407         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1408         test_mkdir -p lndir/bar1
1409         test_mkdir $DIR/$tdir/$tfile/$tfile
1410         cd $tfile                || error "cd $tfile failed"
1411         ln -s .. dotdot          || error "ln dotdot failed"
1412         ln -s dotdot/lndir lndir || error "ln lndir failed"
1413         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1414         output=`ls $tfile/$tfile/lndir/bar1`
1415         [ "$output" = bar1 ] && error "unexpected output"
1416         rm -r $tfile             || error "rm $tfile failed"
1417         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1418 }
1419 run_test 26f "rm -r of a directory which has recursive symlink"
1420
1421 test_27a() {
1422         test_mkdir $DIR/$tdir
1423         $LFS getstripe $DIR/$tdir
1424         $LFS setstripe -c 1 $DIR/$tdir/$tfile || error "setstripe failed"
1425         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1426         cp /etc/hosts $DIR/$tdir/$tfile || error "Can't copy to one stripe file"
1427 }
1428 run_test 27a "one stripe file"
1429
1430 test_27b() {
1431         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1432         test_mkdir $DIR/$tdir
1433         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1434         $LFS getstripe -c $DIR/$tdir/$tfile
1435         [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
1436                 error "two-stripe file doesn't have two stripes"
1437
1438         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1439 }
1440 run_test 27b "create and write to two stripe file"
1441
1442 test_27d() {
1443         test_mkdir $DIR/$tdir
1444         $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile ||
1445                 error "setstripe failed"
1446         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1447         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1448 }
1449 run_test 27d "create file with default settings"
1450
1451 test_27e() {
1452         # LU-5839 adds check for existed layout before setting it
1453         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1454                 skip "Need MDS version at least 2.7.56" && return
1455         test_mkdir $DIR/$tdir
1456         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1457         $LFS setstripe -c 2 $DIR/$tdir/$tfile && error "setstripe worked twice"
1458         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1459 }
1460 run_test 27e "setstripe existing file (should return error)"
1461
1462 test_27f() {
1463         test_mkdir $DIR/$tdir
1464         $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1465                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1466         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1467                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1468         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1469         $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1470 }
1471 run_test 27f "setstripe with bad stripe size (should return error)"
1472
1473 test_27g() {
1474         test_mkdir $DIR/$tdir
1475         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1476         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "no stripe info" ||
1477                 error "$DIR/$tdir/$tfile has object"
1478 }
1479 run_test 27g "$LFS getstripe with no objects"
1480
1481 test_27i() {
1482         test_mkdir $DIR/$tdir
1483         touch $DIR/$tdir/$tfile || error "touch failed"
1484         [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1485                 error "missing objects"
1486 }
1487 run_test 27i "$LFS getstripe with some objects"
1488
1489 test_27j() {
1490         test_mkdir $DIR/$tdir
1491         $LFS setstripe -i $OSTCOUNT $DIR/$tdir/$tfile &&
1492                 error "setstripe failed" || true
1493 }
1494 run_test 27j "setstripe with bad stripe offset (should return error)"
1495
1496 test_27k() { # bug 2844
1497         test_mkdir $DIR/$tdir
1498         local file=$DIR/$tdir/$tfile
1499         local ll_max_blksize=$((4 * 1024 * 1024))
1500         $LFS setstripe -S 67108864 $file || error "setstripe failed"
1501         local blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1502         [ $blksize -le $ll_max_blksize ] || error "1:$blksize > $ll_max_blksize"
1503         dd if=/dev/zero of=$file bs=4k count=1
1504         blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1505         [ $blksize -le $ll_max_blksize ] || error "2:$blksize > $ll_max_blksize"
1506 }
1507 run_test 27k "limit i_blksize for broken user apps"
1508
1509 test_27l() {
1510         mcreate $DIR/$tfile || error "creating file"
1511         $RUNAS $LFS setstripe -c 1 $DIR/$tfile &&
1512                 error "setstripe should have failed" || true
1513 }
1514 run_test 27l "check setstripe permissions (should return error)"
1515
1516 test_27m() {
1517         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1518
1519         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1520                    head -n1)
1521         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1522                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1523                 return
1524         fi
1525         trap simple_cleanup_common EXIT
1526         test_mkdir $DIR/$tdir
1527         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.1
1528         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
1529                 error "dd should fill OST0"
1530         i=2
1531         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.$i; do
1532                 i=$((i + 1))
1533                 [ $i -gt 256 ] && break
1534         done
1535         i=$((i + 1))
1536         touch $DIR/$tdir/$tfile.$i
1537         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1538             awk '{print $1}'| grep -w "0") ] &&
1539                 error "OST0 was full but new created file still use it"
1540         i=$((i + 1))
1541         touch $DIR/$tdir/$tfile.$i
1542         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1543             awk '{print $1}'| grep -w "0") ] &&
1544                 error "OST0 was full but new created file still use it"
1545         simple_cleanup_common
1546 }
1547 run_test 27m "create file while OST0 was full"
1548
1549 sleep_maxage() {
1550         local delay=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1551                       awk '{ print $1 * 2; exit; }')
1552         sleep $delay
1553 }
1554
1555 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1556 # if the OST isn't full anymore.
1557 reset_enospc() {
1558         local OSTIDX=${1:-""}
1559
1560         local list=$(comma_list $(osts_nodes))
1561         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1562
1563         do_nodes $list lctl set_param fail_loc=0
1564         sync    # initiate all OST_DESTROYs from MDS to OST
1565         sleep_maxage
1566 }
1567
1568 exhaust_precreations() {
1569         local OSTIDX=$1
1570         local FAILLOC=$2
1571         local FAILIDX=${3:-$OSTIDX}
1572         local ofacet=ost$((OSTIDX + 1))
1573
1574         test_mkdir -p -c1 $DIR/$tdir
1575         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1576         local mfacet=mds$((mdtidx + 1))
1577         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1578
1579         local OST=$(ostname_from_index $OSTIDX)
1580
1581         # on the mdt's osc
1582         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1583         local last_id=$(do_facet $mfacet lctl get_param -n \
1584                         osc.$mdtosc_proc1.prealloc_last_id)
1585         local next_id=$(do_facet $mfacet lctl get_param -n \
1586                         osc.$mdtosc_proc1.prealloc_next_id)
1587
1588         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1589         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1590
1591         test_mkdir -p $DIR/$tdir/${OST}
1592         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1593 #define OBD_FAIL_OST_ENOSPC              0x215
1594         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1595         echo "Creating to objid $last_id on ost $OST..."
1596         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1597         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1598         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1599         sleep_maxage
1600 }
1601
1602 exhaust_all_precreations() {
1603         local i
1604         for (( i=0; i < OSTCOUNT; i++ )) ; do
1605                 exhaust_precreations $i $1 -1
1606         done
1607 }
1608
1609 test_27n() {
1610         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1611         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1612         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1613         remote_ost_nodsh && skip "remote OST with nodsh" && return
1614
1615         reset_enospc
1616         rm -f $DIR/$tdir/$tfile
1617         exhaust_precreations 0 0x80000215
1618         $LFS setstripe -c -1 $DIR/$tdir || error "setstripe failed"
1619         touch $DIR/$tdir/$tfile || error "touch failed"
1620         $LFS getstripe $DIR/$tdir/$tfile
1621         reset_enospc
1622 }
1623 run_test 27n "create file with some full OSTs"
1624
1625 test_27o() {
1626         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1627         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1628         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1629         remote_ost_nodsh && skip "remote OST with nodsh" && return
1630
1631         reset_enospc
1632         rm -f $DIR/$tdir/$tfile
1633         exhaust_all_precreations 0x215
1634
1635         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1636
1637         reset_enospc
1638         rm -rf $DIR/$tdir/*
1639 }
1640 run_test 27o "create file with all full OSTs (should error)"
1641
1642 test_27p() {
1643         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1645         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1646         remote_ost_nodsh && skip "remote OST with nodsh" && return
1647
1648         reset_enospc
1649         rm -f $DIR/$tdir/$tfile
1650         test_mkdir $DIR/$tdir
1651
1652         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1653         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1654         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1655
1656         exhaust_precreations 0 0x80000215
1657         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1658         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1659         $LFS getstripe $DIR/$tdir/$tfile
1660
1661         reset_enospc
1662 }
1663 run_test 27p "append to a truncated file with some full OSTs"
1664
1665 test_27q() {
1666         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1667         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1668         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1669         remote_ost_nodsh && skip "remote OST with nodsh" && return
1670
1671         reset_enospc
1672         rm -f $DIR/$tdir/$tfile
1673
1674         test_mkdir $DIR/$tdir
1675         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1676         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1677                 error "truncate $DIR/$tdir/$tfile failed"
1678         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1679
1680         exhaust_all_precreations 0x215
1681
1682         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1683         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1684
1685         reset_enospc
1686 }
1687 run_test 27q "append to truncated file with all OSTs full (should error)"
1688
1689 test_27r() {
1690         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1691         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1692         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1693         remote_ost_nodsh && skip "remote OST with nodsh" && return
1694
1695         reset_enospc
1696         rm -f $DIR/$tdir/$tfile
1697         exhaust_precreations 0 0x80000215
1698
1699         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1700
1701         reset_enospc
1702 }
1703 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1704
1705 test_27s() { # bug 10725
1706         test_mkdir $DIR/$tdir
1707         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1708         local stripe_count=0
1709         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1710         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1711                 error "stripe width >= 2^32 succeeded" || true
1712
1713 }
1714 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1715
1716 test_27t() { # bug 10864
1717         WDIR=$(pwd)
1718         WLFS=$(which lfs)
1719         cd $DIR
1720         touch $tfile
1721         $WLFS getstripe $tfile
1722         cd $WDIR
1723 }
1724 run_test 27t "check that utils parse path correctly"
1725
1726 test_27u() { # bug 4900
1727         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1728         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1729         local index
1730         local list=$(comma_list $(mdts_nodes))
1731
1732 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1733         do_nodes $list $LCTL set_param fail_loc=0x139
1734         test_mkdir -p $DIR/$tdir
1735         trap simple_cleanup_common EXIT
1736         createmany -o $DIR/$tdir/t- 1000
1737         do_nodes $list $LCTL set_param fail_loc=0
1738
1739         TLOG=$TMP/$tfile.getstripe
1740         $LFS getstripe $DIR/$tdir > $TLOG
1741         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1742         unlinkmany $DIR/$tdir/t- 1000
1743         trap 0
1744         [[ $OBJS -gt 0 ]] &&
1745                 error "$OBJS objects created on OST-0. See $TLOG" ||
1746                 rm -f $TLOG
1747 }
1748 run_test 27u "skip object creation on OSC w/o objects"
1749
1750 test_27v() { # bug 4900
1751         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1752         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1753         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1754         remote_ost_nodsh && skip "remote OST with nodsh" && return
1755
1756         exhaust_all_precreations 0x215
1757         reset_enospc
1758
1759         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
1760
1761         touch $DIR/$tdir/$tfile
1762         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1763         # all except ost1
1764         for (( i=1; i < OSTCOUNT; i++ )); do
1765                 do_facet ost$i lctl set_param fail_loc=0x705
1766         done
1767         local START=`date +%s`
1768         createmany -o $DIR/$tdir/$tfile 32
1769
1770         local FINISH=`date +%s`
1771         local TIMEOUT=`lctl get_param -n timeout`
1772         local PROCESS=$((FINISH - START))
1773         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1774                error "$FINISH - $START >= $TIMEOUT / 2"
1775         sleep $((TIMEOUT / 2 - PROCESS))
1776         reset_enospc
1777 }
1778 run_test 27v "skip object creation on slow OST"
1779
1780 test_27w() { # bug 10997
1781         test_mkdir $DIR/$tdir
1782         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1783         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
1784                 error "stripe size $size != 65536" || true
1785         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
1786                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
1787 }
1788 run_test 27w "check $LFS setstripe -S and getstrip -d options"
1789
1790 test_27wa() {
1791         [[ $OSTCOUNT -lt 2 ]] &&
1792                 skip_env "skipping multiple stripe count/offset test" && return
1793
1794         test_mkdir $DIR/$tdir
1795         for i in $(seq 1 $OSTCOUNT); do
1796                 offset=$((i - 1))
1797                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
1798                         error "setstripe -c $i -i $offset failed"
1799                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
1800                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
1801                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1802                 [ $index -ne $offset ] &&
1803                         error "stripe offset $index != $offset" || true
1804         done
1805 }
1806 run_test 27wa "check $LFS setstripe -c -i options"
1807
1808 test_27x() {
1809         remote_ost_nodsh && skip "remote OST with nodsh" && return
1810         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1811         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1812         OFFSET=$(($OSTCOUNT - 1))
1813         OSTIDX=0
1814         local OST=$(ostname_from_index $OSTIDX)
1815
1816         test_mkdir $DIR/$tdir
1817         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
1818         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1819         sleep_maxage
1820         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1821         for i in $(seq 0 $OFFSET); do
1822                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
1823                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
1824                 error "OST0 was degraded but new created file still use it"
1825         done
1826         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1827 }
1828 run_test 27x "create files while OST0 is degraded"
1829
1830 test_27y() {
1831         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1832         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1833         remote_ost_nodsh && skip "remote OST with nodsh" && return
1834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1835
1836         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1837         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1838                 osc.$mdtosc.prealloc_last_id)
1839         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1840                 osc.$mdtosc.prealloc_next_id)
1841         local fcount=$((last_id - next_id))
1842         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1843         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1844
1845         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1846                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1847         local OST_DEACTIVE_IDX=-1
1848         local OSC
1849         local OSTIDX
1850         local OST
1851
1852         for OSC in $MDS_OSCS; do
1853                 OST=$(osc_to_ost $OSC)
1854                 OSTIDX=$(index_from_ostuuid $OST)
1855                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1856                         OST_DEACTIVE_IDX=$OSTIDX
1857                 fi
1858                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1859                         echo $OSC "is Deactivated:"
1860                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1861                 fi
1862         done
1863
1864         OSTIDX=$(index_from_ostuuid $OST)
1865         test_mkdir $DIR/$tdir
1866         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
1867
1868         for OSC in $MDS_OSCS; do
1869                 OST=$(osc_to_ost $OSC)
1870                 OSTIDX=$(index_from_ostuuid $OST)
1871                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1872                         echo $OST "is degraded:"
1873                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1874                                                 obdfilter.$OST.degraded=1
1875                 fi
1876         done
1877
1878         sleep_maxage
1879         createmany -o $DIR/$tdir/$tfile $fcount
1880
1881         for OSC in $MDS_OSCS; do
1882                 OST=$(osc_to_ost $OSC)
1883                 OSTIDX=$(index_from_ostuuid $OST)
1884                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1885                         echo $OST "is recovered from degraded:"
1886                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1887                                                 obdfilter.$OST.degraded=0
1888                 else
1889                         do_facet $SINGLEMDS lctl --device %$OSC activate
1890                 fi
1891         done
1892
1893         # all osp devices get activated, hence -1 stripe count restored
1894         local stripe_count=0
1895
1896         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1897         # devices get activated.
1898         sleep_maxage
1899         $LFS setstripe -c -1 $DIR/$tfile
1900         stripe_count=$($LFS getstripe -c $DIR/$tfile)
1901         rm -f $DIR/$tfile
1902         [ $stripe_count -ne $OSTCOUNT ] &&
1903                 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
1904         return 0
1905 }
1906 run_test 27y "create files while OST0 is degraded and the rest inactive"
1907
1908 check_seq_oid()
1909 {
1910         log "check file $1"
1911
1912         lmm_count=$($GETSTRIPE -c $1)
1913         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1914         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1915
1916         local old_ifs="$IFS"
1917         IFS=$'[:]'
1918         fid=($($LFS path2fid $1))
1919         IFS="$old_ifs"
1920
1921         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1922         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1923
1924         # compare lmm_seq and lu_fid->f_seq
1925         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1926         # compare lmm_object_id and lu_fid->oid
1927         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1928
1929         # check the trusted.fid attribute of the OST objects of the file
1930         local have_obdidx=false
1931         local stripe_nr=0
1932         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1933                 # skip lines up to and including "obdidx"
1934                 [ -z "$obdidx" ] && break
1935                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1936                 $have_obdidx || continue
1937
1938                 local ost=$((obdidx + 1))
1939                 local dev=$(ostdevname $ost)
1940                 local oid_hex
1941
1942                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1943
1944                 seq=$(echo $seq | sed -e "s/^0x//g")
1945                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1946                         oid_hex=$(echo $oid)
1947                 else
1948                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1949                 fi
1950                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1951
1952                 local ff=""
1953                 #
1954                 # Don't unmount/remount the OSTs if we don't need to do that.
1955                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1956                 # update too, until that use mount/ll_decode_filter_fid/mount.
1957                 # Re-enable when debugfs will understand new filter_fid.
1958                 #
1959                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
1960                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1961                                 $dev 2>/dev/null" | grep "parent=")
1962                 fi
1963                 if [ -z "$ff" ]; then
1964                         stop ost$ost
1965                         mount_fstype ost$ost
1966                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1967                                 $(facet_mntpt ost$ost)/$obj_file)
1968                         unmount_fstype ost$ost
1969                         start ost$ost $dev $OST_MOUNT_OPTS
1970                         clients_up
1971                 fi
1972
1973                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1974
1975                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1976
1977                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1978                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1979                 #
1980                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
1981                 #       stripe_size=1048576 component_id=1 component_start=0 \
1982                 #       component_end=33554432
1983                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
1984                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
1985                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
1986                 local ff_pstripe
1987                 if grep -q 'stripe=' <<<$ff; then
1988                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
1989                 else
1990                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1991                         # into f_ver in this case.  See comment on ff_parent.
1992                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
1993                 fi
1994
1995                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1996                 [ $ff_pseq = $lmm_seq ] ||
1997                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1998                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1999                 [ $ff_poid = $lmm_oid ] ||
2000                         error "FF parent OID $ff_poid != $lmm_oid"
2001                 (($ff_pstripe == $stripe_nr)) ||
2002                         error "FF stripe $ff_pstripe != $stripe_nr"
2003
2004                 stripe_nr=$((stripe_nr + 1))
2005                 [ $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2006                         continue
2007                 if grep -q 'stripe_count=' <<<$ff; then
2008                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
2009                                             -e 's/ .*//' <<<$ff)
2010                         [ $lmm_count = $ff_scnt ] ||
2011                                 error "FF stripe count $lmm_count != $ff_scnt"
2012                 fi
2013         done
2014 }
2015
2016 test_27z() {
2017         remote_ost_nodsh && skip "remote OST with nodsh" && return
2018         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2019         test_mkdir $DIR/$tdir
2020
2021         $LFS setstripe -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
2022                 { error "setstripe -c -1 failed"; return 1; }
2023         # We need to send a write to every object to get parent FID info set.
2024         # This _should_ also work for setattr, but does not currently.
2025         # touch $DIR/$tdir/$tfile-1 ||
2026         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
2027                 { error "dd $tfile-1 failed"; return 2; }
2028         $LFS setstripe -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
2029                 { error "setstripe -c -1 failed"; return 3; }
2030         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
2031                 { error "dd $tfile-2 failed"; return 4; }
2032
2033         # make sure write RPCs have been sent to OSTs
2034         sync; sleep 5; sync
2035
2036         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
2037         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
2038 }
2039 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
2040
2041 test_27A() { # b=19102
2042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2043
2044         save_layout_restore_at_exit $MOUNT
2045
2046         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
2047         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
2048                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
2049         local default_size=$($GETSTRIPE -S $MOUNT)
2050         local default_offset=$($GETSTRIPE -i $MOUNT)
2051         local dsize=$(do_facet $SINGLEMDS \
2052                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
2053         [ $default_size -eq $dsize ] ||
2054                 error "stripe size $default_size != $dsize"
2055         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
2056 }
2057 run_test 27A "check filesystem-wide default LOV EA values"
2058
2059 test_27B() { # LU-2523
2060         test_mkdir $DIR/$tdir
2061         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
2062         touch $DIR/$tdir/f0
2063         # open f1 with O_LOV_DELAY_CREATE
2064         # rename f0 onto f1
2065         # call setstripe ioctl on open file descriptor for f1
2066         # close
2067         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
2068                 $DIR/$tdir/f0
2069
2070         rm -f $DIR/$tdir/f1
2071         # open f1 with O_LOV_DELAY_CREATE
2072         # unlink f1
2073         # call setstripe ioctl on open file descriptor for f1
2074         # close
2075         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2076
2077         # Allow multiop to fail in imitation of NFS's busted semantics.
2078         true
2079 }
2080 run_test 27B "call setstripe on open unlinked file/rename victim"
2081
2082 test_27C() { #LU-2871
2083         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2084
2085         declare -a ost_idx
2086         local index
2087         local found
2088         local i
2089         local j
2090
2091         test_mkdir $DIR/$tdir
2092         cd $DIR/$tdir
2093         for i in $(seq 0 $((OSTCOUNT - 1))); do
2094                 # set stripe across all OSTs starting from OST$i
2095                 $SETSTRIPE -i $i -c -1 $tfile$i
2096                 # get striping information
2097                 ost_idx=($($GETSTRIPE $tfile$i |
2098                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2099                 echo ${ost_idx[@]}
2100
2101                 # check the layout
2102                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2103                         error "${#ost_idx[@]} != $OSTCOUNT"
2104
2105                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2106                         found=0
2107                         for j in $(echo ${ost_idx[@]}); do
2108                                 if [ $index -eq $j ]; then
2109                                         found=1
2110                                         break
2111                                 fi
2112                         done
2113                         [ $found = 1 ] ||
2114                                 error "Can not find $index in ${ost_idx[@]}"
2115                 done
2116         done
2117 }
2118 run_test 27C "check full striping across all OSTs"
2119
2120 test_27D() {
2121         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2122         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2123         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2124         local POOL=${POOL:-testpool}
2125         local first_ost=0
2126         local last_ost=$(($OSTCOUNT - 1))
2127         local ost_step=1
2128         local ost_list=$(seq $first_ost $ost_step $last_ost)
2129         local ost_range="$first_ost $last_ost $ost_step"
2130
2131         if ! combined_mgs_mds ; then
2132                 mount_mgs_client
2133         fi
2134
2135         test_mkdir $DIR/$tdir
2136         pool_add $POOL || error "pool_add failed"
2137         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2138
2139         local skip27D
2140         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
2141                 skip27D+="-s 29"
2142         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) -o \
2143           $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2144                 skip27D+=" -s 30,31"
2145         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2146                 error "llapi_layout_test failed"
2147
2148         destroy_test_pools || error "destroy test pools failed"
2149
2150         if ! combined_mgs_mds ; then
2151                 umount_mgs_client
2152         fi
2153 }
2154 run_test 27D "validate llapi_layout API"
2155
2156 # Verify that default_easize is increased from its initial value after
2157 # accessing a widely striped file.
2158 test_27E() {
2159         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2160         [ $(lustre_version_code client) -lt $(version_code 2.5.57) ] &&
2161                 skip "client does not have LU-3338 fix" && return
2162
2163         # 72 bytes is the minimum space required to store striping
2164         # information for a file striped across one OST:
2165         # (sizeof(struct lov_user_md_v3) +
2166         #  sizeof(struct lov_user_ost_data_v1))
2167         local min_easize=72
2168         $LCTL set_param -n llite.*.default_easize $min_easize ||
2169                 error "lctl set_param failed"
2170         local easize=$($LCTL get_param -n llite.*.default_easize)
2171
2172         [ $easize -eq $min_easize ] ||
2173                 error "failed to set default_easize"
2174
2175         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2176                 error "setstripe failed"
2177         cat $DIR/$tfile
2178         rm $DIR/$tfile
2179
2180         easize=$($LCTL get_param -n llite.*.default_easize)
2181
2182         [ $easize -gt $min_easize ] ||
2183                 error "default_easize not updated"
2184 }
2185 run_test 27E "check that default extended attribute size properly increases"
2186
2187 test_27F() { # LU-5346/LU-7975
2188         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2189         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2190         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
2191                 skip "Need MDS version at least 2.8.51" && return
2192         remote_ost_nodsh && skip "remote OST with nodsh" && return
2193
2194         test_mkdir $DIR/$tdir
2195         rm -f $DIR/$tdir/f0
2196         $SETSTRIPE -c 2 $DIR/$tdir
2197
2198         # stop all OSTs to reproduce situation for LU-7975 ticket
2199         for num in $(seq $OSTCOUNT); do
2200                 stop ost$num
2201         done
2202
2203         # open/create f0 with O_LOV_DELAY_CREATE
2204         # truncate f0 to a non-0 size
2205         # close
2206         multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2207
2208         $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2209         # open/write it again to force delayed layout creation
2210         cat /etc/hosts > $DIR/$tdir/f0 &
2211         catpid=$!
2212
2213         # restart OSTs
2214         for num in $(seq $OSTCOUNT); do
2215                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2216                         error "ost$num failed to start"
2217         done
2218
2219         wait $catpid || error "cat failed"
2220
2221         cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2222         [[ $($GETSTRIPE -c $DIR/$tdir/f0) == 2 ]] || error "wrong stripecount"
2223
2224 }
2225 run_test 27F "Client resend delayed layout creation with non-zero size"
2226
2227 # createtest also checks that device nodes are created and
2228 # then visible correctly (#2091)
2229 test_28() { # bug 2091
2230         test_mkdir $DIR/d28
2231         $CREATETEST $DIR/d28/ct || error "createtest failed"
2232 }
2233 run_test 28 "create/mknod/mkdir with bad file types ============"
2234
2235 test_29() {
2236         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
2237         sync; sleep 1; sync # flush out any dirty pages from previous tests
2238         cancel_lru_locks
2239         test_mkdir $DIR/d29
2240         touch $DIR/d29/foo
2241         log 'first d29'
2242         ls -l $DIR/d29
2243
2244         declare -i LOCKCOUNTORIG=0
2245         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2246                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2247         done
2248         [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
2249
2250         declare -i LOCKUNUSEDCOUNTORIG=0
2251         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2252                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2253         done
2254
2255         log 'second d29'
2256         ls -l $DIR/d29
2257         log 'done'
2258
2259         declare -i LOCKCOUNTCURRENT=0
2260         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2261                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2262         done
2263
2264         declare -i LOCKUNUSEDCOUNTCURRENT=0
2265         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2266                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2267         done
2268
2269         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2270                 $LCTL set_param -n ldlm.dump_namespaces ""
2271                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2272                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2273                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2274                 return 2
2275         fi
2276         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2277                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2278                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2279                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2280                 return 3
2281         fi
2282 }
2283 run_test 29 "IT_GETATTR regression  ============================"
2284
2285 test_30a() { # was test_30
2286         cp $(which ls) $DIR || cp /bin/ls $DIR
2287         $DIR/ls / || error "Can't execute binary from lustre"
2288         rm $DIR/ls
2289 }
2290 run_test 30a "execute binary from Lustre (execve) =============="
2291
2292 test_30b() {
2293         cp `which ls` $DIR || cp /bin/ls $DIR
2294         chmod go+rx $DIR/ls
2295         $RUNAS $DIR/ls / || error "Can't execute binary from lustre as non-root"
2296         rm $DIR/ls
2297 }
2298 run_test 30b "execute binary from Lustre as non-root ==========="
2299
2300 test_30c() { # b=22376
2301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2302         cp `which ls` $DIR || cp /bin/ls $DIR
2303         chmod a-rw $DIR/ls
2304         cancel_lru_locks mdc
2305         cancel_lru_locks osc
2306         $RUNAS $DIR/ls / || error "Can't execute binary from lustre"
2307         rm -f $DIR/ls
2308 }
2309 run_test 30c "execute binary from Lustre without read perms ===="
2310
2311 test_31a() {
2312         $OPENUNLINK $DIR/f31 $DIR/f31 || error "openunlink failed"
2313         $CHECKSTAT -a $DIR/f31 || error "$DIR/f31 exists"
2314 }
2315 run_test 31a "open-unlink file =================================="
2316
2317 test_31b() {
2318         touch $DIR/f31 || error "touch $DIR/f31 failed"
2319         ln $DIR/f31 $DIR/f31b || error "ln failed"
2320         $MULTIOP $DIR/f31b Ouc || error "multiop failed"
2321         $CHECKSTAT -t file $DIR/f31 || error "$DIR/f31 not file type"
2322 }
2323 run_test 31b "unlink file with multiple links while open ======="
2324
2325 test_31c() {
2326         touch $DIR/f31 || error "touch $DIR/f31 failed"
2327         ln $DIR/f31 $DIR/f31c || error "ln failed"
2328         multiop_bg_pause $DIR/f31 O_uc ||
2329                 error "multiop_bg_pause for $DIR/f31 failed"
2330         MULTIPID=$!
2331         $MULTIOP $DIR/f31c Ouc
2332         kill -USR1 $MULTIPID
2333         wait $MULTIPID
2334 }
2335 run_test 31c "open-unlink file with multiple links ============="
2336
2337 test_31d() {
2338         opendirunlink $DIR/d31d $DIR/d31d || error "opendirunlink failed"
2339         $CHECKSTAT -a $DIR/d31d || error "$DIR/d31d exists"
2340 }
2341 run_test 31d "remove of open directory ========================="
2342
2343 test_31e() { # bug 2904
2344         openfilleddirunlink $DIR/d31e || error "openfilleddirunlink failed"
2345 }
2346 run_test 31e "remove of open non-empty directory ==============="
2347
2348 test_31f() { # bug 4554
2349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2350         set -vx
2351         test_mkdir $DIR/d31f
2352         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2353         cp /etc/hosts $DIR/d31f
2354         ls -l $DIR/d31f
2355         $GETSTRIPE $DIR/d31f/hosts
2356         multiop_bg_pause $DIR/d31f D_c || return 1
2357         MULTIPID=$!
2358
2359         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2360         test_mkdir $DIR/d31f
2361         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2362         cp /etc/hosts $DIR/d31f
2363         ls -l $DIR/d31f
2364         $GETSTRIPE $DIR/d31f/hosts
2365         multiop_bg_pause $DIR/d31f D_c || return 1
2366         MULTIPID2=$!
2367
2368         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2369         wait $MULTIPID || error "first opendir $MULTIPID failed"
2370
2371         sleep 6
2372
2373         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2374         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2375         set +vx
2376 }
2377 run_test 31f "remove of open directory with open-unlink file ==="
2378
2379 test_31g() {
2380         echo "-- cross directory link --"
2381         test_mkdir -c1 $DIR/${tdir}ga
2382         test_mkdir -c1 $DIR/${tdir}gb
2383         touch $DIR/${tdir}ga/f
2384         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2385         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2386         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2387         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2388         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2389 }
2390 run_test 31g "cross directory link==============="
2391
2392 test_31h() {
2393         echo "-- cross directory link --"
2394         test_mkdir -c1 $DIR/${tdir}
2395         test_mkdir -c1 $DIR/${tdir}/dir
2396         touch $DIR/${tdir}/f
2397         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2398         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2399         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2400         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2401         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2402 }
2403 run_test 31h "cross directory link under child==============="
2404
2405 test_31i() {
2406         echo "-- cross directory link --"
2407         test_mkdir -c1 $DIR/$tdir
2408         test_mkdir -c1 $DIR/$tdir/dir
2409         touch $DIR/$tdir/dir/f
2410         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2411         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2412         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2413         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2414         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2415 }
2416 run_test 31i "cross directory link under parent==============="
2417
2418 test_31j() {
2419         test_mkdir -c1 -p $DIR/$tdir
2420         test_mkdir -c1 -p $DIR/$tdir/dir1
2421         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2422         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2423         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2424         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2425         return 0
2426 }
2427 run_test 31j "link for directory==============="
2428
2429 test_31k() {
2430         test_mkdir -c1 -p $DIR/$tdir
2431         touch $DIR/$tdir/s
2432         touch $DIR/$tdir/exist
2433         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2434         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2435         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2436         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2437         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2438         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2439         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2440         return 0
2441 }
2442 run_test 31k "link to file: the same, non-existing, dir==============="
2443
2444 test_31m() {
2445         mkdir $DIR/d31m
2446         touch $DIR/d31m/s
2447         mkdir $DIR/d31m2
2448         touch $DIR/d31m2/exist
2449         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2450         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2451         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2452         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2453         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2454         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2455         return 0
2456 }
2457 run_test 31m "link to file: the same, non-existing, dir==============="
2458
2459 test_31n() {
2460         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2461         nlink=$(stat --format=%h $DIR/$tfile)
2462         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2463         local fd=$(free_fd)
2464         local cmd="exec $fd<$DIR/$tfile"
2465         eval $cmd
2466         cmd="exec $fd<&-"
2467         trap "eval $cmd" EXIT
2468         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2469         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2470         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2471         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2472         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2473         eval $cmd
2474 }
2475 run_test 31n "check link count of unlinked file"
2476
2477 link_one() {
2478         local TEMPNAME=$(mktemp $1_XXXXXX)
2479         mlink $TEMPNAME $1 2> /dev/null &&
2480                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2481         munlink $TEMPNAME
2482 }
2483
2484 test_31o() { # LU-2901
2485         test_mkdir $DIR/$tdir
2486         for LOOP in $(seq 100); do
2487                 rm -f $DIR/$tdir/$tfile*
2488                 for THREAD in $(seq 8); do
2489                         link_one $DIR/$tdir/$tfile.$LOOP &
2490                 done
2491                 wait
2492                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2493                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2494                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2495                         break || true
2496         done
2497 }
2498 run_test 31o "duplicate hard links with same filename"
2499
2500 test_31p() {
2501         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2502
2503         test_mkdir $DIR/$tdir
2504         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2505         $LFS setdirstripe -D -c2 -H all_char $DIR/$tdir/striped_dir
2506
2507         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2508                 error "open unlink test1 failed"
2509         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2510                 error "open unlink test2 failed"
2511
2512         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2513                 error "test1 still exists"
2514         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2515                 error "test2 still exists"
2516 }
2517 run_test 31p "remove of open striped directory"
2518
2519 cleanup_test32_mount() {
2520         local rc=0
2521         trap 0
2522         local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
2523         $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
2524         losetup -d $loopdev || true
2525         rm -rf $DIR/$tdir
2526         return $rc
2527 }
2528
2529 test_32a() {
2530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2531         echo "== more mountpoints and symlinks ================="
2532         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2533         trap cleanup_test32_mount EXIT
2534         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2535         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2536                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2537         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. ||
2538                 error "$DIR/$tdir/ext2-mountpoint/.. not dir type"
2539         cleanup_test32_mount
2540 }
2541 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2542
2543 test_32b() {
2544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2545         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2546         trap cleanup_test32_mount EXIT
2547         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2548         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2549                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2550         ls -al $DIR/$tdir/ext2-mountpoint/.. ||
2551                 error "Can't list $DIR/$tdir/ext2-mountpoint/.."
2552         cleanup_test32_mount
2553 }
2554 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2555
2556 test_32c() {
2557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2558         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2559         trap cleanup_test32_mount EXIT
2560         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2561         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2562                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2563         test_mkdir -p $DIR/$tdir/d2/test_dir
2564         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
2565                 error "$DIR/$tdir/ext2-mountpoint/../d2/test_dir not dir type"
2566         cleanup_test32_mount
2567 }
2568 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2569
2570 test_32d() {
2571         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2572         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2573         trap cleanup_test32_mount EXIT
2574         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2575         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2576                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2577         test_mkdir -p $DIR/$tdir/d2/test_dir
2578         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
2579                 error "Can't list $DIR/$tdir/ext2-mountpoint/../d2/test_dir"
2580         cleanup_test32_mount
2581 }
2582 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir"
2583
2584 test_32e() {
2585         rm -fr $DIR/$tdir
2586         test_mkdir -p $DIR/$tdir/tmp
2587         local tmp_dir=$DIR/$tdir/tmp
2588         ln -s $DIR/$tdir $tmp_dir/symlink11
2589         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2590         $CHECKSTAT -t link $DIR/$tdir/tmp/symlink11 || error "symlink11 bad"
2591         $CHECKSTAT -t link $DIR/$tdir/symlink01 || error "symlink01 bad"
2592 }
2593 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir"
2594
2595 test_32f() {
2596         rm -fr $DIR/$tdir
2597         test_mkdir -p $DIR/$tdir/tmp
2598         local tmp_dir=$DIR/$tdir/tmp
2599         ln -s $DIR/$tdir $tmp_dir/symlink11
2600         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2601         ls $DIR/$tdir/tmp/symlink11  || error "symlink11 bad"
2602         ls $DIR/$tdir/symlink01 || error "symlink01 bad"
2603 }
2604 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir"
2605
2606 test_32g() {
2607         local tmp_dir=$DIR/$tdir/tmp
2608         test_mkdir -p $tmp_dir
2609         test_mkdir $DIR/${tdir}2
2610         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
2611         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
2612         $CHECKSTAT -t link $tmp_dir/symlink12 || error "symlink12 not a link"
2613         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error "symlink02 not a link"
2614         $CHECKSTAT -t dir -f $tmp_dir/symlink12 || error "symlink12 not a dir"
2615         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error "symlink12 not a dir"
2616 }
2617 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2618
2619 test_32h() {
2620         rm -fr $DIR/$tdir $DIR/${tdir}2
2621         tmp_dir=$DIR/$tdir/tmp
2622         test_mkdir -p $tmp_dir
2623         test_mkdir $DIR/${tdir}2
2624         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
2625         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
2626         ls $tmp_dir/symlink12 || error "listing symlink12"
2627         ls $DIR/$tdir/symlink02  || error "listing symlink02"
2628 }
2629 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2630
2631 test_32i() {
2632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2633         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2634         trap cleanup_test32_mount EXIT
2635         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2636         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2637                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2638         touch $DIR/$tdir/test_file
2639         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file ||
2640                 error "$DIR/$tdir/ext2-mountpoint/../test_file not file type"
2641         cleanup_test32_mount
2642 }
2643 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2644
2645 test_32j() {
2646         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2647         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2648         trap cleanup_test32_mount EXIT
2649         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2650         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2651                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2652         touch $DIR/$tdir/test_file
2653         cat $DIR/$tdir/ext2-mountpoint/../test_file ||
2654                 error "Can't open $DIR/$tdir/ext2-mountpoint/../test_file"
2655         cleanup_test32_mount
2656 }
2657 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2658
2659 test_32k() {
2660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2661         rm -fr $DIR/$tdir
2662         trap cleanup_test32_mount EXIT
2663         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2664         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2665                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2666         test_mkdir -p $DIR/$tdir/d2
2667         touch $DIR/$tdir/d2/test_file || error "touch failed"
2668         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
2669                 error "$DIR/$tdir/ext2-mountpoint/../d2/test_file not file type"
2670         cleanup_test32_mount
2671 }
2672 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2673
2674 test_32l() {
2675         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2676         rm -fr $DIR/$tdir
2677         trap cleanup_test32_mount EXIT
2678         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2679         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2680                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2681         test_mkdir -p $DIR/$tdir/d2
2682         touch $DIR/$tdir/d2/test_file || error "touch failed"
2683         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
2684                 error "Can't open $DIR/$tdir/ext2-mountpoint/../d2/test_file"
2685         cleanup_test32_mount
2686 }
2687 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2688
2689 test_32m() {
2690         rm -fr $DIR/d32m
2691         test_mkdir -p $DIR/d32m/tmp
2692         TMP_DIR=$DIR/d32m/tmp
2693         ln -s $DIR $TMP_DIR/symlink11
2694         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2695         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 ||
2696                 error "symlink11 not a link"
2697         $CHECKSTAT -t link $DIR/d32m/symlink01 ||
2698                 error "symlink01 not a link"
2699 }
2700 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2701
2702 test_32n() {
2703         rm -fr $DIR/d32n
2704         test_mkdir -p $DIR/d32n/tmp
2705         TMP_DIR=$DIR/d32n/tmp
2706         ln -s $DIR $TMP_DIR/symlink11
2707         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2708         ls -l $DIR/d32n/tmp/symlink11  || error "listing symlink11"
2709         ls -l $DIR/d32n/symlink01 || error "listing symlink01"
2710 }
2711 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2712
2713 test_32o() {
2714         touch $DIR/$tfile
2715         test_mkdir -p $DIR/d32o/tmp
2716         TMP_DIR=$DIR/d32o/tmp
2717         ln -s $DIR/$tfile $TMP_DIR/symlink12
2718         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2719         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 ||
2720                 error "symlink12 not a link"
2721         $CHECKSTAT -t link $DIR/d32o/symlink02 || error "symlink02 not a link"
2722         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 ||
2723                 error "$DIR/d32o/tmp/symlink12 not file type"
2724         $CHECKSTAT -t file -f $DIR/d32o/symlink02 ||
2725                 error "$DIR/d32o/symlink02 not file type"
2726 }
2727 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2728
2729 test_32p() {
2730         log 32p_1
2731         rm -fr $DIR/d32p
2732         log 32p_2
2733         rm -f $DIR/$tfile
2734         log 32p_3
2735         touch $DIR/$tfile
2736         log 32p_4
2737         test_mkdir -p $DIR/d32p/tmp
2738         log 32p_5
2739         TMP_DIR=$DIR/d32p/tmp
2740         log 32p_6
2741         ln -s $DIR/$tfile $TMP_DIR/symlink12
2742         log 32p_7
2743         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2744         log 32p_8
2745         cat $DIR/d32p/tmp/symlink12 ||
2746                 error "Can't open $DIR/d32p/tmp/symlink12"
2747         log 32p_9
2748         cat $DIR/d32p/symlink02 || error "Can't open $DIR/d32p/symlink02"
2749         log 32p_10
2750 }
2751 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2752
2753 test_32q() {
2754         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2755         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2756         trap cleanup_test32_mount EXIT
2757         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2758         touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
2759         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2760                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2761         ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
2762         cleanup_test32_mount
2763 }
2764 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2765
2766 test_32r() {
2767         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2768         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2769         trap cleanup_test32_mount EXIT
2770         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2771         touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
2772         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2773                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2774         ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
2775         cleanup_test32_mount
2776 }
2777 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2778
2779 test_33aa() {
2780         rm -f $DIR/$tfile
2781         touch $DIR/$tfile
2782         chmod 444 $DIR/$tfile
2783         chown $RUNAS_ID $DIR/$tfile
2784         log 33_1
2785         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2786         log 33_2
2787 }
2788 run_test 33aa "write file with mode 444 (should return error)"
2789
2790 test_33a() {
2791         rm -fr $DIR/$tdir
2792         test_mkdir $DIR/$tdir
2793         chown $RUNAS_ID $DIR/$tdir
2794         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile ||
2795                 error "$RUNAS create $tdir/$tfile failed"
2796         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile &&
2797                 error "open RDWR" || true
2798 }
2799 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2800
2801 test_33b() {
2802         rm -fr $DIR/$tdir
2803         test_mkdir $DIR/$tdir
2804         chown $RUNAS_ID $DIR/$tdir
2805         $RUNAS $OPENFILE -f 1286739555 $DIR/$tdir/$tfile || true
2806 }
2807 run_test 33b "test open file with malformed flags (No panic)"
2808
2809 test_33c() {
2810         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2811         local ostnum
2812         local ostname
2813         local write_bytes
2814         local all_zeros
2815
2816         remote_ost_nodsh && skip "remote OST with nodsh" && return
2817         all_zeros=:
2818         rm -fr $DIR/$tdir
2819         test_mkdir $DIR/$tdir
2820         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2821
2822         sync
2823         for ostnum in $(seq $OSTCOUNT); do
2824                 # test-framework's OST numbering is one-based, while Lustre's
2825                 # is zero-based
2826                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2827                 # Parsing llobdstat's output sucks; we could grep the /proc
2828                 # path, but that's likely to not be as portable as using the
2829                 # llobdstat utility.  So we parse lctl output instead.
2830                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2831                         obdfilter/$ostname/stats |
2832                         awk '/^write_bytes/ {print $7}' )
2833                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2834                 if (( ${write_bytes:-0} > 0 ))
2835                 then
2836                         all_zeros=false
2837                         break;
2838                 fi
2839         done
2840
2841         $all_zeros || return 0
2842
2843         # Write four bytes
2844         echo foo > $DIR/$tdir/bar
2845         # Really write them
2846         sync
2847
2848         # Total up write_bytes after writing.  We'd better find non-zeros.
2849         for ostnum in $(seq $OSTCOUNT); do
2850                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2851                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2852                         obdfilter/$ostname/stats |
2853                         awk '/^write_bytes/ {print $7}' )
2854                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2855                 if (( ${write_bytes:-0} > 0 ))
2856                 then
2857                         all_zeros=false
2858                         break;
2859                 fi
2860         done
2861
2862         if $all_zeros
2863         then
2864                 for ostnum in $(seq $OSTCOUNT); do
2865                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2866                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2867                         do_facet ost$ostnum lctl get_param -n \
2868                                 obdfilter/$ostname/stats
2869                 done
2870                 error "OST not keeping write_bytes stats (b22312)"
2871         fi
2872 }
2873 run_test 33c "test llobdstat and write_bytes"
2874
2875 test_33d() {
2876         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2877         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2878         local MDTIDX=1
2879         local remote_dir=$DIR/$tdir/remote_dir
2880
2881         test_mkdir $DIR/$tdir
2882         $LFS mkdir -i $MDTIDX $remote_dir ||
2883                 error "create remote directory failed"
2884
2885         touch $remote_dir/$tfile
2886         chmod 444 $remote_dir/$tfile
2887         chown $RUNAS_ID $remote_dir/$tfile
2888
2889         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2890
2891         chown $RUNAS_ID $remote_dir
2892         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2893                                         error "create" || true
2894         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2895                                     error "open RDWR" || true
2896         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2897 }
2898 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2899
2900 test_33e() {
2901         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2902
2903         mkdir $DIR/$tdir
2904
2905         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2906         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2907         mkdir $DIR/$tdir/local_dir
2908
2909         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2910         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2911         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2912
2913         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2914                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2915
2916         rmdir $DIR/$tdir/* || error "rmdir failed"
2917
2918         umask 777
2919         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2920         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2921         mkdir $DIR/$tdir/local_dir
2922
2923         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2924         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2925         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2926
2927         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2928                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2929
2930         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2931
2932         umask 000
2933         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2934         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2935         mkdir $DIR/$tdir/local_dir
2936
2937         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2938         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2939         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2940
2941         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2942                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2943 }
2944 run_test 33e "mkdir and striped directory should have same mode"
2945
2946 cleanup_33f() {
2947         trap 0
2948         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2949 }
2950
2951 test_33f() {
2952         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2953         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2954
2955         mkdir $DIR/$tdir
2956         chmod go+rwx $DIR/$tdir
2957         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2958         trap cleanup_33f EXIT
2959
2960         $RUNAS lfs mkdir -i 0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2961                 error "cannot create striped directory"
2962
2963         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2964                 error "cannot create files in striped directory"
2965
2966         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2967                 error "cannot remove files in striped directory"
2968
2969         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2970                 error "cannot remove striped directory"
2971
2972         cleanup_33f
2973 }
2974 run_test 33f "nonroot user can create, access, and remove a striped directory"
2975
2976 test_33g() {
2977         mkdir -p $DIR/$tdir/dir2
2978
2979         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
2980         echo $err
2981         [[ $err =~ "exists" ]] || error "Not exists error"
2982 }
2983 run_test 33g "nonroot user create already existing root created file"
2984
2985 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2986 test_34a() {
2987         rm -f $DIR/f34
2988         $MCREATE $DIR/f34 || error "mcreate failed"
2989         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
2990                 error "getstripe failed"
2991         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error "truncate failed"
2992         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
2993                 error "getstripe failed"
2994         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
2995                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
2996 }
2997 run_test 34a "truncate file that has not been opened ==========="
2998
2999 test_34b() {
3000         [ ! -f $DIR/f34 ] && test_34a
3001         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3002                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3003         $OPENFILE -f O_RDONLY $DIR/f34
3004         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
3005                 error "getstripe failed"
3006         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3007                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3008 }
3009 run_test 34b "O_RDONLY opening file doesn't create objects ====="
3010
3011 test_34c() {
3012         [ ! -f $DIR/f34 ] && test_34a
3013         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3014                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3015         $OPENFILE -f O_RDWR $DIR/f34
3016         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
3017         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3018                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3019 }
3020 run_test 34c "O_RDWR opening file-with-size works =============="
3021
3022 test_34d() {
3023         [ ! -f $DIR/f34 ] && test_34a
3024         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 ||
3025                 error "dd failed"
3026         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3027                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3028         rm $DIR/f34
3029 }
3030 run_test 34d "write to sparse file ============================="
3031
3032 test_34e() {
3033         rm -f $DIR/f34e
3034         $MCREATE $DIR/f34e || error "mcreate failed"
3035         $TRUNCATE $DIR/f34e 1000 || error "truncate failed"
3036         $CHECKSTAT -s 1000 $DIR/f34e ||
3037                 error "Size of $DIR/f34e not equal to 1000 bytes"
3038         $OPENFILE -f O_RDWR $DIR/f34e
3039         $CHECKSTAT -s 1000 $DIR/f34e ||
3040                 error "Size of $DIR/f34e not equal to 1000 bytes"
3041 }
3042 run_test 34e "create objects, some with size and some without =="
3043
3044 test_34f() { # bug 6242, 6243
3045         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3046         SIZE34F=48000
3047         rm -f $DIR/f34f
3048         $MCREATE $DIR/f34f || error "mcreate failed"
3049         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
3050         dd if=$DIR/f34f of=$TMP/f34f
3051         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
3052         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
3053         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
3054         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
3055         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
3056 }
3057 run_test 34f "read from a file with no objects until EOF ======="
3058
3059 test_34g() {
3060         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3061         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE ||
3062                 error "dd failed"
3063         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error "truncate failed"
3064         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3065                 error "Size of $DIR/$tfile not equal to $((TEST_34_SIZE / 2))"
3066         cancel_lru_locks osc
3067         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3068                 error "wrong size after lock cancel"
3069
3070         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error "truncate failed"
3071         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3072                 error "expanding truncate failed"
3073         cancel_lru_locks osc
3074         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3075                 error "wrong expanded size after lock cancel"
3076 }
3077 run_test 34g "truncate long file ==============================="
3078
3079 test_34h() {
3080         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3081         local gid=10
3082         local sz=1000
3083
3084         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error "dd failed"
3085         sync # Flush the cache so that multiop below does not block on cache
3086              # flush when getting the group lock
3087         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
3088         MULTIPID=$!
3089
3090         # Since just timed wait is not good enough, let's do a sync write
3091         # that way we are sure enough time for a roundtrip + processing
3092         # passed + 2 seconds of extra margin.
3093         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
3094         rm $DIR/${tfile}-1
3095         sleep 2
3096
3097         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
3098                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
3099                 kill -9 $MULTIPID
3100         fi
3101         wait $MULTIPID
3102         local nsz=`stat -c %s $DIR/$tfile`
3103         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
3104 }
3105 run_test 34h "ftruncate file under grouplock should not block"
3106
3107 test_35a() {
3108         cp /bin/sh $DIR/f35a
3109         chmod 444 $DIR/f35a
3110         chown $RUNAS_ID $DIR/f35a
3111         $RUNAS $DIR/f35a && error || true
3112         rm $DIR/f35a
3113 }
3114 run_test 35a "exec file with mode 444 (should return and not leak)"
3115
3116 test_36a() {
3117         rm -f $DIR/f36
3118         utime $DIR/f36 || error "utime failed for MDS"
3119 }
3120 run_test 36a "MDS utime check (mknod, utime)"
3121
3122 test_36b() {
3123         echo "" > $DIR/f36
3124         utime $DIR/f36 || error "utime failed for OST"
3125 }
3126 run_test 36b "OST utime check (open, utime)"
3127
3128 test_36c() {
3129         rm -f $DIR/d36/f36
3130         test_mkdir $DIR/d36
3131         chown $RUNAS_ID $DIR/d36
3132         $RUNAS utime $DIR/d36/f36 || error "utime failed for MDS as non-root"
3133 }
3134 run_test 36c "non-root MDS utime check (mknod, utime)"
3135
3136 test_36d() {
3137         [ ! -d $DIR/d36 ] && test_36c
3138         echo "" > $DIR/d36/f36
3139         $RUNAS utime $DIR/d36/f36 || error "utime failed for OST as non-root"
3140 }
3141 run_test 36d "non-root OST utime check (open, utime)"
3142
3143 test_36e() {
3144         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3145         test_mkdir $DIR/$tdir
3146         touch $DIR/$tdir/$tfile
3147         $RUNAS utime $DIR/$tdir/$tfile &&
3148                 error "utime worked, expected failure" || true
3149 }
3150 run_test 36e "utime on non-owned file (should return error)"
3151
3152 subr_36fh() {
3153         local fl="$1"
3154         local LANG_SAVE=$LANG
3155         local LC_LANG_SAVE=$LC_LANG
3156         export LANG=C LC_LANG=C # for date language
3157
3158         DATESTR="Dec 20  2000"
3159         test_mkdir $DIR/$tdir
3160         lctl set_param fail_loc=$fl
3161         date; date +%s
3162         cp /etc/hosts $DIR/$tdir/$tfile
3163         sync & # write RPC generated with "current" inode timestamp, but delayed
3164         sleep 1
3165         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
3166         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
3167         cancel_lru_locks osc
3168         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
3169         date; date +%s
3170         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
3171                 echo "BEFORE: $LS_BEFORE" && \
3172                 echo "AFTER : $LS_AFTER" && \
3173                 echo "WANT  : $DATESTR" && \
3174                 error "$DIR/$tdir/$tfile timestamps changed" || true
3175
3176         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
3177 }
3178
3179 test_36f() {
3180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3181         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3182         subr_36fh "0x80000214"
3183 }
3184 run_test 36f "utime on file racing with OST BRW write =========="
3185
3186 test_36g() {
3187         remote_ost_nodsh && skip "remote OST with nodsh" && return
3188         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3189         local fmd_max_age
3190         local fmd_before
3191         local fmd_after
3192
3193         test_mkdir $DIR/$tdir
3194         fmd_max_age=$(do_facet ost1 \
3195                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
3196                 head -n 1")
3197
3198         fmd_before=$(do_facet ost1 \
3199                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3200         touch $DIR/$tdir/$tfile
3201         sleep $((fmd_max_age + 12))
3202         fmd_after=$(do_facet ost1 \
3203                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3204
3205         echo "fmd_before: $fmd_before"
3206         echo "fmd_after: $fmd_after"
3207         [[ $fmd_after -gt $fmd_before ]] &&
3208                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3209                 error "fmd didn't expire after ping" || true
3210 }
3211 run_test 36g "filter mod data cache expiry ====================="
3212
3213 test_36h() {
3214         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3215         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3216         subr_36fh "0x80000227"
3217 }
3218 run_test 36h "utime on file racing with OST BRW write =========="
3219
3220 test_36i() {
3221         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3222
3223         test_mkdir $DIR/$tdir
3224         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3225
3226         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3227         local new_mtime=$((mtime + 200))
3228
3229         #change Modify time of striped dir
3230         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3231                         error "change mtime failed"
3232
3233         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3234
3235         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3236 }
3237 run_test 36i "change mtime on striped directory"
3238
3239 # test_37 - duplicate with tests 32q 32r
3240
3241 test_38() {
3242         local file=$DIR/$tfile
3243         touch $file
3244         openfile -f O_DIRECTORY $file
3245         local RC=$?
3246         local ENOTDIR=20
3247         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3248         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3249 }
3250 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3251
3252 test_39a() { # was test_39
3253         touch $DIR/$tfile
3254         touch $DIR/${tfile}2
3255 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3256 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3257 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3258         sleep 2
3259         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3260         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3261                 echo "mtime"
3262                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3263                 echo "atime"
3264                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3265                 echo "ctime"
3266                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3267                 error "O_TRUNC didn't change timestamps"
3268         fi
3269 }
3270 run_test 39a "mtime changed on create"
3271
3272 test_39b() {
3273         test_mkdir -c1 $DIR/$tdir
3274         cp -p /etc/passwd $DIR/$tdir/fopen
3275         cp -p /etc/passwd $DIR/$tdir/flink
3276         cp -p /etc/passwd $DIR/$tdir/funlink
3277         cp -p /etc/passwd $DIR/$tdir/frename
3278         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3279
3280         sleep 1
3281         echo "aaaaaa" >> $DIR/$tdir/fopen
3282         echo "aaaaaa" >> $DIR/$tdir/flink
3283         echo "aaaaaa" >> $DIR/$tdir/funlink
3284         echo "aaaaaa" >> $DIR/$tdir/frename
3285
3286         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3287         local link_new=`stat -c %Y $DIR/$tdir/flink`
3288         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3289         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3290
3291         cat $DIR/$tdir/fopen > /dev/null
3292         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3293         rm -f $DIR/$tdir/funlink2
3294         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3295
3296         for (( i=0; i < 2; i++ )) ; do
3297                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3298                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3299                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3300                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3301
3302                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3303                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3304                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3305                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3306
3307                 cancel_lru_locks osc
3308                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3309         done
3310 }
3311 run_test 39b "mtime change on open, link, unlink, rename  ======"
3312
3313 # this should be set to past
3314 TEST_39_MTIME=`date -d "1 year ago" +%s`
3315
3316 # bug 11063
3317 test_39c() {
3318         touch $DIR1/$tfile
3319         sleep 2
3320         local mtime0=`stat -c %Y $DIR1/$tfile`
3321
3322         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3323         local mtime1=`stat -c %Y $DIR1/$tfile`
3324         [ "$mtime1" = $TEST_39_MTIME ] || \
3325                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3326
3327         local d1=`date +%s`
3328         echo hello >> $DIR1/$tfile
3329         local d2=`date +%s`
3330         local mtime2=`stat -c %Y $DIR1/$tfile`
3331         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3332                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3333
3334         mv $DIR1/$tfile $DIR1/$tfile-1
3335
3336         for (( i=0; i < 2; i++ )) ; do
3337                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3338                 [ "$mtime2" = "$mtime3" ] || \
3339                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3340
3341                 cancel_lru_locks osc
3342                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3343         done
3344 }
3345 run_test 39c "mtime change on rename ==========================="
3346
3347 # bug 21114
3348 test_39d() {
3349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3350         touch $DIR1/$tfile
3351
3352         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3353
3354         for (( i=0; i < 2; i++ )) ; do
3355                 local mtime=`stat -c %Y $DIR1/$tfile`
3356                 [ $mtime = $TEST_39_MTIME ] || \
3357                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3358
3359                 cancel_lru_locks osc
3360                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3361         done
3362 }
3363 run_test 39d "create, utime, stat =============================="
3364
3365 # bug 21114
3366 test_39e() {
3367         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3368         touch $DIR1/$tfile
3369         local mtime1=`stat -c %Y $DIR1/$tfile`
3370
3371         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3372
3373         for (( i=0; i < 2; i++ )) ; do
3374                 local mtime2=`stat -c %Y $DIR1/$tfile`
3375                 [ $mtime2 = $TEST_39_MTIME ] || \
3376                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3377
3378                 cancel_lru_locks osc
3379                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3380         done
3381 }
3382 run_test 39e "create, stat, utime, stat ========================"
3383
3384 # bug 21114
3385 test_39f() {
3386         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3387         touch $DIR1/$tfile
3388         mtime1=`stat -c %Y $DIR1/$tfile`
3389
3390         sleep 2
3391         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3392
3393         for (( i=0; i < 2; i++ )) ; do
3394                 local mtime2=`stat -c %Y $DIR1/$tfile`
3395                 [ $mtime2 = $TEST_39_MTIME ] || \
3396                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3397
3398                 cancel_lru_locks osc
3399                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3400         done
3401 }
3402 run_test 39f "create, stat, sleep, utime, stat ================="
3403
3404 # bug 11063
3405 test_39g() {
3406         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3407         echo hello >> $DIR1/$tfile
3408         local mtime1=`stat -c %Y $DIR1/$tfile`
3409
3410         sleep 2
3411         chmod o+r $DIR1/$tfile
3412
3413         for (( i=0; i < 2; i++ )) ; do
3414                 local mtime2=`stat -c %Y $DIR1/$tfile`
3415                 [ "$mtime1" = "$mtime2" ] || \
3416                         error "lost mtime: $mtime2, should be $mtime1"
3417
3418                 cancel_lru_locks osc
3419                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3420         done
3421 }
3422 run_test 39g "write, chmod, stat ==============================="
3423
3424 # bug 11063
3425 test_39h() {
3426         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3427         touch $DIR1/$tfile
3428         sleep 1
3429
3430         local d1=`date`
3431         echo hello >> $DIR1/$tfile
3432         local mtime1=`stat -c %Y $DIR1/$tfile`
3433
3434         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3435         local d2=`date`
3436         if [ "$d1" != "$d2" ]; then
3437                 echo "write and touch not within one second"
3438         else
3439                 for (( i=0; i < 2; i++ )) ; do
3440                         local mtime2=`stat -c %Y $DIR1/$tfile`
3441                         [ "$mtime2" = $TEST_39_MTIME ] || \
3442                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3443
3444                         cancel_lru_locks osc
3445                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3446                 done
3447         fi
3448 }
3449 run_test 39h "write, utime within one second, stat ============="
3450
3451 test_39i() {
3452         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3453         touch $DIR1/$tfile
3454         sleep 1
3455
3456         echo hello >> $DIR1/$tfile
3457         local mtime1=`stat -c %Y $DIR1/$tfile`
3458
3459         mv $DIR1/$tfile $DIR1/$tfile-1
3460
3461         for (( i=0; i < 2; i++ )) ; do
3462                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3463
3464                 [ "$mtime1" = "$mtime2" ] || \
3465                         error "lost mtime: $mtime2, should be $mtime1"
3466
3467                 cancel_lru_locks osc
3468                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3469         done
3470 }
3471 run_test 39i "write, rename, stat =============================="
3472
3473 test_39j() {
3474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3475         start_full_debug_logging
3476         touch $DIR1/$tfile
3477         sleep 1
3478
3479         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3480         lctl set_param fail_loc=0x80000412
3481         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3482                 error "multiop failed"
3483         local multipid=$!
3484         local mtime1=`stat -c %Y $DIR1/$tfile`
3485
3486         mv $DIR1/$tfile $DIR1/$tfile-1
3487
3488         kill -USR1 $multipid
3489         wait $multipid || error "multiop close failed"
3490
3491         for (( i=0; i < 2; i++ )) ; do
3492                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3493                 [ "$mtime1" = "$mtime2" ] ||
3494                         error "mtime is lost on close: $mtime2, " \
3495                               "should be $mtime1"
3496
3497                 cancel_lru_locks osc
3498                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3499         done
3500         lctl set_param fail_loc=0
3501         stop_full_debug_logging
3502 }
3503 run_test 39j "write, rename, close, stat ======================="
3504
3505 test_39k() {
3506         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3507         touch $DIR1/$tfile
3508         sleep 1
3509
3510         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3511         local multipid=$!
3512         local mtime1=`stat -c %Y $DIR1/$tfile`
3513
3514         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3515
3516         kill -USR1 $multipid
3517         wait $multipid || error "multiop close failed"
3518
3519         for (( i=0; i < 2; i++ )) ; do
3520                 local mtime2=`stat -c %Y $DIR1/$tfile`
3521
3522                 [ "$mtime2" = $TEST_39_MTIME ] || \
3523                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3524
3525                 cancel_lru_locks osc
3526                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3527         done
3528 }
3529 run_test 39k "write, utime, close, stat ========================"
3530
3531 # this should be set to future
3532 TEST_39_ATIME=`date -d "1 year" +%s`
3533
3534 test_39l() {
3535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3536         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3537         local atime_diff=$(do_facet $SINGLEMDS \
3538                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3539         rm -rf $DIR/$tdir
3540         mkdir -p $DIR/$tdir
3541
3542         # test setting directory atime to future
3543         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3544         local atime=$(stat -c %X $DIR/$tdir)
3545         [ "$atime" = $TEST_39_ATIME ] ||
3546                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3547
3548         # test setting directory atime from future to now
3549         local now=$(date +%s)
3550         touch -a -d @$now $DIR/$tdir
3551
3552         atime=$(stat -c %X $DIR/$tdir)
3553         [ "$atime" -eq "$now"  ] ||
3554                 error "atime is not updated from future: $atime, $now"
3555
3556         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3557         sleep 3
3558
3559         # test setting directory atime when now > dir atime + atime_diff
3560         local d1=$(date +%s)
3561         ls $DIR/$tdir
3562         local d2=$(date +%s)
3563         cancel_lru_locks mdc
3564         atime=$(stat -c %X $DIR/$tdir)
3565         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3566                 error "atime is not updated  : $atime, should be $d2"
3567
3568         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3569         sleep 3
3570
3571         # test not setting directory atime when now < dir atime + atime_diff
3572         ls $DIR/$tdir
3573         cancel_lru_locks mdc
3574         atime=$(stat -c %X $DIR/$tdir)
3575         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3576                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3577
3578         do_facet $SINGLEMDS \
3579                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3580 }
3581 run_test 39l "directory atime update ==========================="
3582
3583 test_39m() {
3584         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3585         touch $DIR1/$tfile
3586         sleep 2
3587         local far_past_mtime=$(date -d "May 29 1953" +%s)
3588         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3589
3590         touch -m -d @$far_past_mtime $DIR1/$tfile
3591         touch -a -d @$far_past_atime $DIR1/$tfile
3592
3593         for (( i=0; i < 2; i++ )) ; do
3594                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3595                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3596                         error "atime or mtime set incorrectly"
3597
3598                 cancel_lru_locks osc
3599                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3600         done
3601 }
3602 run_test 39m "test atime and mtime before 1970"
3603
3604 test_39n() { # LU-3832
3605         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3606         local atime_diff=$(do_facet $SINGLEMDS \
3607                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3608         local atime0
3609         local atime1
3610         local atime2
3611
3612         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3613
3614         rm -rf $DIR/$tfile
3615         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3616         atime0=$(stat -c %X $DIR/$tfile)
3617
3618         sleep 5
3619         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3620         atime1=$(stat -c %X $DIR/$tfile)
3621
3622         sleep 5
3623         cancel_lru_locks mdc
3624         cancel_lru_locks osc
3625         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3626         atime2=$(stat -c %X $DIR/$tfile)
3627
3628         do_facet $SINGLEMDS \
3629                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3630
3631         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3632         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3633 }
3634 run_test 39n "check that O_NOATIME is honored"
3635
3636 test_39o() {
3637         TESTDIR=$DIR/$tdir/$tfile
3638         [ -e $TESTDIR ] && rm -rf $TESTDIR
3639         mkdir -p $TESTDIR
3640         cd $TESTDIR
3641         links1=2
3642         ls
3643         mkdir a b
3644         ls
3645         links2=$(stat -c %h .)
3646         [ $(($links1 + 2)) != $links2 ] &&
3647                 error "wrong links count $(($links1 + 2)) != $links2"
3648         rmdir b
3649         links3=$(stat -c %h .)
3650         [ $(($links1 + 1)) != $links3 ] &&
3651                 error "wrong links count $links1 != $links3"
3652         return 0
3653 }
3654 run_test 39o "directory cached attributes updated after create"
3655
3656 test_39p() {
3657         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3658         local MDTIDX=1
3659         TESTDIR=$DIR/$tdir/$tdir
3660         [ -e $TESTDIR ] && rm -rf $TESTDIR
3661         test_mkdir -p $TESTDIR
3662         cd $TESTDIR
3663         links1=2
3664         ls
3665         test_mkdir -i $MDTIDX $TESTDIR/remote_dir1
3666         test_mkdir -i $MDTIDX $TESTDIR/remote_dir2
3667         ls
3668         links2=$(stat -c %h .)
3669         [ $(($links1 + 2)) != $links2 ] &&
3670                 error "wrong links count $(($links1 + 2)) != $links2"
3671         rmdir remote_dir2
3672         links3=$(stat -c %h .)
3673         [ $(($links1 + 1)) != $links3 ] &&
3674                 error "wrong links count $links1 != $links3"
3675         return 0
3676 }
3677 run_test 39p "remote directory cached attributes updated after create ========"
3678
3679
3680 test_39q() { # LU-8041
3681         local testdir=$DIR/$tdir
3682         mkdir -p $testdir
3683         multiop_bg_pause $testdir D_c || error "multiop failed"
3684         local multipid=$!
3685         cancel_lru_locks mdc
3686         kill -USR1 $multipid
3687         local atime=$(stat -c %X $testdir)
3688         [ "$atime" -ne 0 ] || error "atime is zero"
3689 }
3690 run_test 39q "close won't zero out atime"
3691
3692 test_40() {
3693         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3694         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3695                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3696         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3697                 error "$tfile is not 4096 bytes in size"
3698 }
3699 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3700
3701 test_41() {
3702         # bug 1553
3703         small_write $DIR/f41 18
3704 }
3705 run_test 41 "test small file write + fstat ====================="
3706
3707 count_ost_writes() {
3708         lctl get_param -n ${OSC}.*.stats |
3709                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3710                         END { printf("%0.0f", writes) }'
3711 }
3712
3713 # decent default
3714 WRITEBACK_SAVE=500
3715 DIRTY_RATIO_SAVE=40
3716 MAX_DIRTY_RATIO=50
3717 BG_DIRTY_RATIO_SAVE=10
3718 MAX_BG_DIRTY_RATIO=25
3719
3720 start_writeback() {
3721         trap 0
3722         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3723         # dirty_ratio, dirty_background_ratio
3724         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3725                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3726                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3727                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3728         else
3729                 # if file not here, we are a 2.4 kernel
3730                 kill -CONT `pidof kupdated`
3731         fi
3732 }
3733
3734 stop_writeback() {
3735         # setup the trap first, so someone cannot exit the test at the
3736         # exact wrong time and mess up a machine
3737         trap start_writeback EXIT
3738         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3739         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3740                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3741                 sysctl -w vm.dirty_writeback_centisecs=0
3742                 sysctl -w vm.dirty_writeback_centisecs=0
3743                 # save and increase /proc/sys/vm/dirty_ratio
3744                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3745                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3746                 # save and increase /proc/sys/vm/dirty_background_ratio
3747                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3748                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3749         else
3750                 # if file not here, we are a 2.4 kernel
3751                 kill -STOP `pidof kupdated`
3752         fi
3753 }
3754
3755 # ensure that all stripes have some grant before we test client-side cache
3756 setup_test42() {
3757         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3758                 dd if=/dev/zero of=$i bs=4k count=1
3759                 rm $i
3760         done
3761 }
3762
3763 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3764 # file truncation, and file removal.
3765 test_42a() {
3766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3767         setup_test42
3768         cancel_lru_locks $OSC
3769         stop_writeback
3770         sync; sleep 1; sync # just to be safe
3771         BEFOREWRITES=`count_ost_writes`
3772         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3773         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3774         AFTERWRITES=`count_ost_writes`
3775         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3776                 error "$BEFOREWRITES < $AFTERWRITES"
3777         start_writeback
3778 }
3779 run_test 42a "ensure that we don't flush on close"
3780
3781 test_42b() {
3782         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3783         setup_test42
3784         cancel_lru_locks $OSC
3785         stop_writeback
3786         sync
3787         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3788         BEFOREWRITES=$(count_ost_writes)
3789         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3790         AFTERWRITES=$(count_ost_writes)
3791         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3792                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3793         fi
3794         BEFOREWRITES=$(count_ost_writes)
3795         sync || error "sync: $?"
3796         AFTERWRITES=$(count_ost_writes)
3797         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3798                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3799         fi
3800         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3801         start_writeback
3802         return 0
3803 }
3804 run_test 42b "test destroy of file with cached dirty data ======"
3805
3806 # if these tests just want to test the effect of truncation,
3807 # they have to be very careful.  consider:
3808 # - the first open gets a {0,EOF}PR lock
3809 # - the first write conflicts and gets a {0, count-1}PW
3810 # - the rest of the writes are under {count,EOF}PW
3811 # - the open for truncate tries to match a {0,EOF}PR
3812 #   for the filesize and cancels the PWs.
3813 # any number of fixes (don't get {0,EOF} on open, match
3814 # composite locks, do smarter file size management) fix
3815 # this, but for now we want these tests to verify that
3816 # the cancellation with truncate intent works, so we
3817 # start the file with a full-file pw lock to match against
3818 # until the truncate.
3819 trunc_test() {
3820         test=$1
3821         file=$DIR/$test
3822         offset=$2
3823         cancel_lru_locks $OSC
3824         stop_writeback
3825         # prime the file with 0,EOF PW to match
3826         touch $file
3827         $TRUNCATE $file 0
3828         sync; sync
3829         # now the real test..
3830         dd if=/dev/zero of=$file bs=1024 count=100
3831         BEFOREWRITES=`count_ost_writes`
3832         $TRUNCATE $file $offset
3833         cancel_lru_locks $OSC
3834         AFTERWRITES=`count_ost_writes`
3835         start_writeback
3836 }
3837
3838 test_42c() {
3839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3840         trunc_test 42c 1024
3841         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3842             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3843         rm $file
3844 }
3845 run_test 42c "test partial truncate of file with cached dirty data"
3846
3847 test_42d() {
3848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3849         trunc_test 42d 0
3850         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3851             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3852         rm $file
3853 }
3854 run_test 42d "test complete truncate of file with cached dirty data"
3855
3856 test_42e() { # bug22074
3857         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3858         local TDIR=$DIR/${tdir}e
3859         local pagesz=$(page_size)
3860         local pages=16 # hardcoded 16 pages, don't change it.
3861         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3862         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3863         local max_dirty_mb
3864         local warmup_files
3865
3866         test_mkdir $DIR/${tdir}e
3867         $SETSTRIPE -c 1 $TDIR
3868         createmany -o $TDIR/f $files
3869
3870         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3871
3872         # we assume that with $OSTCOUNT files, at least one of them will
3873         # be allocated on OST0.
3874         warmup_files=$((OSTCOUNT * max_dirty_mb))
3875         createmany -o $TDIR/w $warmup_files
3876
3877         # write a large amount of data into one file and sync, to get good
3878         # avail_grant number from OST.
3879         for ((i=0; i<$warmup_files; i++)); do
3880                 idx=$($GETSTRIPE -i $TDIR/w$i)
3881                 [ $idx -ne 0 ] && continue
3882                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3883                 break
3884         done
3885         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3886         sync
3887         $LCTL get_param $proc_osc0/cur_dirty_bytes
3888         $LCTL get_param $proc_osc0/cur_grant_bytes
3889
3890         # create as much dirty pages as we can while not to trigger the actual
3891         # RPCs directly. but depends on the env, VFS may trigger flush during this
3892         # period, hopefully we are good.
3893         for ((i=0; i<$warmup_files; i++)); do
3894                 idx=$($GETSTRIPE -i $TDIR/w$i)
3895                 [ $idx -ne 0 ] && continue
3896                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3897         done
3898         $LCTL get_param $proc_osc0/cur_dirty_bytes
3899         $LCTL get_param $proc_osc0/cur_grant_bytes
3900
3901         # perform the real test
3902         $LCTL set_param $proc_osc0/rpc_stats 0
3903         for ((;i<$files; i++)); do
3904                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3905                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3906         done
3907         sync
3908         $LCTL get_param $proc_osc0/rpc_stats
3909
3910         local percent=0
3911         local have_ppr=false
3912         $LCTL get_param $proc_osc0/rpc_stats |
3913                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3914                         # skip lines until we are at the RPC histogram data
3915                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3916                         $have_ppr || continue
3917
3918                         # we only want the percent stat for < 16 pages
3919                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3920
3921                         percent=$((percent + WPCT))
3922                         if [[ $percent -gt 15 ]]; then
3923                                 error "less than 16-pages write RPCs" \
3924                                       "$percent% > 15%"
3925                                 break
3926                         fi
3927                 done
3928         rm -rf $TDIR
3929 }
3930 run_test 42e "verify sub-RPC writes are not done synchronously"
3931
3932 test_43A() { # was test_43
3933         test_mkdir $DIR/$tdir
3934         cp -p /bin/ls $DIR/$tdir/$tfile
3935         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3936         pid=$!
3937         # give multiop a chance to open
3938         sleep 1
3939
3940         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
3941         kill -USR1 $pid
3942 }
3943 run_test 43A "execution of file opened for write should return -ETXTBSY"
3944
3945 test_43a() {
3946         test_mkdir $DIR/$tdir
3947         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3948                 cp -p multiop $DIR/$tdir/multiop
3949         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3950                 error "multiop open $TMP/$tfile.junk failed"
3951         rm $TMP/$tfile.junk     # delete junk file on close (not part of test)
3952         MULTIOP_PID=$!
3953         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3954         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3955         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3956 }
3957 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3958
3959 test_43b() {
3960         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3961         test_mkdir $DIR/$tdir
3962         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3963                 cp -p multiop $DIR/$tdir/multiop
3964         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3965                 error "multiop open $TMP/$tfile.junk failed"
3966         rm $TMP/$tfile.junk     # delete junk file on close (not part of test)
3967         MULTIOP_PID=$!
3968         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3969         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3970         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3971 }
3972 run_test 43b "truncate of file being executed should return -ETXTBSY"
3973
3974 test_43c() {
3975         local testdir="$DIR/$tdir"
3976         test_mkdir $testdir
3977         cp $SHELL $testdir/
3978         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
3979                 ( cd $testdir && md5sum -c )
3980 }
3981 run_test 43c "md5sum of copy into lustre"
3982
3983 test_44A() { # was test_44
3984         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
3985         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3986         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3987 }
3988 run_test 44A "zero length read from a sparse stripe"
3989
3990 test_44a() {
3991         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3992                 awk '{ print $2 }')
3993         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3994         [[ $nstripe -gt $OSTCOUNT ]] &&
3995             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3996             return
3997         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3998                 awk '{ print $2 }')
3999         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
4000                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
4001                         awk '{ print $2 }')
4002         fi
4003
4004         OFFSETS="0 $((stride/2)) $((stride-1))"
4005         for offset in $OFFSETS; do
4006                 for i in $(seq 0 $((nstripe-1))); do
4007                         local GLOBALOFFSETS=""
4008                         # size in Bytes
4009                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
4010                         local myfn=$DIR/d44a-$size
4011                         echo "--------writing $myfn at $size"
4012                         ll_sparseness_write $myfn $size ||
4013                                 error "ll_sparseness_write"
4014                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
4015                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
4016                                 error "ll_sparseness_verify $GLOBALOFFSETS"
4017
4018                         for j in $(seq 0 $((nstripe-1))); do
4019                                 # size in Bytes
4020                                 size=$((((j + $nstripe )*$stride + $offset)))
4021                                 ll_sparseness_write $myfn $size ||
4022                                         error "ll_sparseness_write"
4023                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
4024                         done
4025                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
4026                                 error "ll_sparseness_verify $GLOBALOFFSETS"
4027                         rm -f $myfn
4028                 done
4029         done
4030 }
4031 run_test 44a "test sparse pwrite ==============================="
4032
4033 dirty_osc_total() {
4034         tot=0
4035         for d in `lctl get_param -n ${OSC}.*.cur_dirty_bytes`; do
4036                 tot=$(($tot + $d))
4037         done
4038         echo $tot
4039 }
4040 do_dirty_record() {
4041         before=`dirty_osc_total`
4042         echo executing "\"$*\""
4043         eval $*
4044         after=`dirty_osc_total`
4045         echo before $before, after $after
4046 }
4047 test_45() {
4048         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4049         f="$DIR/f45"
4050         # Obtain grants from OST if it supports it
4051         echo blah > ${f}_grant
4052         stop_writeback
4053         sync
4054         do_dirty_record "echo blah > $f"
4055         [[ $before -eq $after ]] && error "write wasn't cached"
4056         do_dirty_record "> $f"
4057         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
4058         do_dirty_record "echo blah > $f"
4059         [[ $before -eq $after ]] && error "write wasn't cached"
4060         do_dirty_record "sync"
4061         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
4062         do_dirty_record "echo blah > $f"
4063         [[ $before -eq $after ]] && error "write wasn't cached"
4064         do_dirty_record "cancel_lru_locks osc"
4065         [[ $before -gt $after ]] ||
4066                 error "lock cancellation didn't lower dirty count"
4067         start_writeback
4068 }
4069 run_test 45 "osc io page accounting ============================"
4070
4071 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
4072 # test tickles a bug where re-dirtying a page was failing to be mapped to the
4073 # objects offset and an assert hit when an rpc was built with 1023's mapped
4074 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
4075 test_46() {
4076         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4077         f="$DIR/f46"
4078         stop_writeback
4079         sync
4080         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
4081         sync
4082         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
4083         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
4084         sync
4085         start_writeback
4086 }
4087 run_test 46 "dirtying a previously written page ================"
4088
4089 # test_47 is removed "Device nodes check" is moved to test_28
4090
4091 test_48a() { # bug 2399
4092         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
4093         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
4094                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
4095                 return
4096         test_mkdir $DIR/$tdir
4097         cd $DIR/$tdir
4098         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
4099         test_mkdir $DIR/$tdir
4100         touch foo || error "'touch foo' failed after recreating cwd"
4101         test_mkdir bar
4102         touch .foo || error "'touch .foo' failed after recreating cwd"
4103         test_mkdir .bar
4104         ls . > /dev/null || error "'ls .' failed after recreating cwd"
4105         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4106         cd . || error "'cd .' failed after recreating cwd"
4107         mkdir . && error "'mkdir .' worked after recreating cwd"
4108         rmdir . && error "'rmdir .' worked after recreating cwd"
4109         ln -s . baz || error "'ln -s .' failed after recreating cwd"
4110         cd .. || error "'cd ..' failed after recreating cwd"
4111 }
4112 run_test 48a "Access renamed working dir (should return errors)="
4113
4114 test_48b() { # bug 2399
4115         rm -rf $DIR/$tdir
4116         test_mkdir $DIR/$tdir
4117         cd $DIR/$tdir
4118         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
4119         touch foo && error "'touch foo' worked after removing cwd"
4120         mkdir foo && error "'mkdir foo' worked after removing cwd"
4121         touch .foo && error "'touch .foo' worked after removing cwd"
4122         mkdir .foo && error "'mkdir .foo' worked after removing cwd"
4123         ls . > /dev/null && error "'ls .' worked after removing cwd"
4124         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4125         mkdir . && error "'mkdir .' worked after removing cwd"
4126         rmdir . && error "'rmdir .' worked after removing cwd"
4127         ln -s . foo && error "'ln -s .' worked after removing cwd"
4128         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
4129 }
4130 run_test 48b "Access removed working dir (should return errors)="
4131
4132 test_48c() { # bug 2350
4133         #lctl set_param debug=-1
4134         #set -vx
4135         rm -rf $DIR/$tdir
4136         test_mkdir -p $DIR/$tdir/dir
4137         cd $DIR/$tdir/dir
4138         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4139         $TRACE touch foo && error "touch foo worked after removing cwd"
4140         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
4141         touch .foo && error "touch .foo worked after removing cwd"
4142         mkdir .foo && error "mkdir .foo worked after removing cwd"
4143         $TRACE ls . && error "'ls .' worked after removing cwd"
4144         $TRACE ls .. || error "'ls ..' failed after removing cwd"
4145         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
4146         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
4147         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
4148         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
4149 }
4150 run_test 48c "Access removed working subdir (should return errors)"
4151
4152 test_48d() { # bug 2350
4153         #lctl set_param debug=-1
4154         #set -vx
4155         rm -rf $DIR/$tdir
4156         test_mkdir -p $DIR/$tdir/dir
4157         cd $DIR/$tdir/dir
4158         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4159         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4160         $TRACE touch foo && error "'touch foo' worked after removing parent"
4161         $TRACE mkdir foo && error "mkdir foo worked after removing parent"
4162         touch .foo && error "'touch .foo' worked after removing parent"
4163         mkdir .foo && error "mkdir .foo worked after removing parent"
4164         $TRACE ls . && error "'ls .' worked after removing parent"
4165         $TRACE ls .. && error "'ls ..' worked after removing parent"
4166         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
4167         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
4168         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
4169         true
4170 }
4171 run_test 48d "Access removed parent subdir (should return errors)"
4172
4173 test_48e() { # bug 4134
4174         #lctl set_param debug=-1
4175         #set -vx
4176         rm -rf $DIR/$tdir
4177         test_mkdir -p $DIR/$tdir/dir
4178         cd $DIR/$tdir/dir
4179         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4180         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4181         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
4182         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
4183         # On a buggy kernel addition of "touch foo" after cd .. will
4184         # produce kernel oops in lookup_hash_it
4185         touch ../foo && error "'cd ..' worked after recreate parent"
4186         cd $DIR
4187         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
4188 }
4189 run_test 48e "Access to recreated parent subdir (should return errors)"
4190
4191 test_49() { # LU-1030
4192         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4193         remote_ost_nodsh && skip "remote OST with nodsh" && return
4194         # get ost1 size - lustre-OST0000
4195         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
4196                 awk '{ print $4 }')
4197         # write 800M at maximum
4198         [[ $ost1_size -lt 2 ]] && ost1_size=2
4199         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
4200
4201         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
4202         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
4203         local dd_pid=$!
4204
4205         # change max_pages_per_rpc while writing the file
4206         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
4207         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
4208         # loop until dd process exits
4209         while ps ax -opid | grep -wq $dd_pid; do
4210                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4211                 sleep $((RANDOM % 5 + 1))
4212         done
4213         # restore original max_pages_per_rpc
4214         $LCTL set_param $osc1_mppc=$orig_mppc
4215         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4216 }
4217 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4218
4219 test_50() {
4220         # bug 1485
4221         test_mkdir $DIR/$tdir
4222         cd $DIR/$tdir
4223         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4224 }
4225 run_test 50 "special situations: /proc symlinks  ==============="
4226
4227 test_51a() {    # was test_51
4228         # bug 1516 - create an empty entry right after ".." then split dir
4229         test_mkdir -c1 $DIR/$tdir
4230         touch $DIR/$tdir/foo
4231         $MCREATE $DIR/$tdir/bar
4232         rm $DIR/$tdir/foo
4233         createmany -m $DIR/$tdir/longfile 201
4234         FNUM=202
4235         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4236                 $MCREATE $DIR/$tdir/longfile$FNUM
4237                 FNUM=$(($FNUM + 1))
4238                 echo -n "+"
4239         done
4240         echo
4241         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4242 }
4243 run_test 51a "special situations: split htree with empty entry =="
4244
4245 cleanup_print_lfs_df () {
4246         trap 0
4247         $LFS df
4248         $LFS df -i
4249 }
4250
4251 test_51b() {
4252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4253         local dir=$DIR/$tdir
4254
4255         local nrdirs=$((65536 + 100))
4256
4257         # cleanup the directory
4258         rm -fr $dir
4259
4260         test_mkdir -c1 $dir
4261
4262         $LFS df
4263         $LFS df -i
4264         local mdtidx=$(printf "%04x" $($LFS getstripe -M $dir))
4265         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4266         [[ $numfree -lt $nrdirs ]] &&
4267                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4268                 return
4269
4270         # need to check free space for the directories as well
4271         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4272         numfree=$(( blkfree / $(fs_inode_ksize) ))
4273         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
4274                 return
4275
4276         trap cleanup_print_lfs_df EXIT
4277
4278         # create files
4279         createmany -d $dir/d $nrdirs || {
4280                 unlinkmany $dir/d $nrdirs
4281                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
4282         }
4283
4284         # really created :
4285         nrdirs=$(ls -U $dir | wc -l)
4286
4287         # unlink all but 100 subdirectories, then check it still works
4288         local left=100
4289         local delete=$((nrdirs - left))
4290
4291         $LFS df
4292         $LFS df -i
4293
4294         # for ldiskfs the nlink count should be 1, but this is OSD specific
4295         # and so this is listed for informational purposes only
4296         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
4297         unlinkmany -d $dir/d $delete ||
4298                 error "unlink of first $delete subdirs failed"
4299
4300         echo "nlink between: $(stat -c %h $dir)"
4301         local found=$(ls -U $dir | wc -l)
4302         [ $found -ne $left ] &&
4303                 error "can't find subdirs: found only $found, expected $left"
4304
4305         unlinkmany -d $dir/d $delete $left ||
4306                 error "unlink of second $left subdirs failed"
4307         # regardless of whether the backing filesystem tracks nlink accurately
4308         # or not, the nlink count shouldn't be more than "." and ".." here
4309         local after=$(stat -c %h $dir)
4310         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
4311                 echo "nlink after: $after"
4312
4313         cleanup_print_lfs_df
4314 }
4315 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
4316
4317 test_51d() {
4318         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4319         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
4320         test_mkdir $DIR/$tdir
4321         createmany -o $DIR/$tdir/t- 1000
4322         $LFS getstripe $DIR/$tdir > $TMP/$tfile
4323         for N in $(seq 0 $((OSTCOUNT - 1))); do
4324                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4325                         END { printf("%0.0f", objs) }' $TMP/$tfile)
4326                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
4327                         '($1 == '$N') { objs += 1 } \
4328                         END { printf("%0.0f", objs) }')
4329                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4330         done
4331         unlinkmany $DIR/$tdir/t- 1000
4332
4333         NLAST=0
4334         for N in $(seq 1 $((OSTCOUNT - 1))); do
4335                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4336                         error "OST $N has less objects vs OST $NLAST" \
4337                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4338                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4339                         error "OST $N has less objects vs OST $NLAST" \
4340                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4341
4342                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4343                         error "OST $N has less #0 objects vs OST $NLAST" \
4344                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4345                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4346                         error "OST $N has less #0 objects vs OST $NLAST" \
4347                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4348                 NLAST=$N
4349         done
4350         rm -f $TMP/$tfile
4351 }
4352 run_test 51d "check object distribution"
4353
4354 test_51e() {
4355         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4356                 skip "ldiskfs only test"
4357                 return
4358         fi
4359
4360         test_mkdir -c1 $DIR/$tdir
4361         test_mkdir -c1 $DIR/$tdir/d0
4362
4363         touch $DIR/$tdir/d0/foo
4364         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4365                 error "file exceed 65000 nlink limit!"
4366         unlinkmany $DIR/$tdir/d0/f- 65001
4367         return 0
4368 }
4369 run_test 51e "check file nlink limit"
4370
4371 test_51f() {
4372         test_mkdir $DIR/$tdir
4373
4374         local max=100000
4375         local ulimit_old=$(ulimit -n)
4376         local spare=20 # number of spare fd's for scripts/libraries, etc.
4377         local mdt=$(lfs getstripe -M $DIR/$tdir)
4378         local numfree=$(lfs df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
4379
4380         echo "MDT$mdt numfree=$numfree, max=$max"
4381         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
4382         if [ $((numfree + spare)) -gt $ulimit_old ]; then
4383                 while ! ulimit -n $((numfree + spare)); do
4384                         numfree=$((numfree * 3 / 4))
4385                 done
4386                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
4387         else
4388                 echo "left ulimit at $ulimit_old"
4389         fi
4390
4391         createmany -o -k -t 120 $DIR/$tdir/f $numfree || {
4392                 unlinkmany $DIR/$tdir/f $numfree
4393                 error "create+open $numfree files in $DIR/$tdir failed"
4394         }
4395         ulimit -n $ulimit_old
4396
4397         # if createmany exits at 120s there will be fewer than $numfree files
4398         unlinkmany $DIR/$tdir/f $numfree || true
4399 }
4400 run_test 51f "check many open files limit"
4401
4402 test_52a() {
4403         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4404         test_mkdir $DIR/$tdir
4405         touch $DIR/$tdir/foo
4406         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4407         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4408         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4409         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4410         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4411                                         error "link worked"
4412         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4413         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4414         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4415                                                      error "lsattr"
4416         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4417         cp -r $DIR/$tdir $TMP/
4418         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
4419 }
4420 run_test 52a "append-only flag test (should return errors)"
4421
4422 test_52b() {
4423         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4424         test_mkdir $DIR/$tdir
4425         touch $DIR/$tdir/foo
4426         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4427         cat test > $DIR/$tdir/foo && error "cat test worked"
4428         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4429         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4430         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4431                                         error "link worked"
4432         echo foo >> $DIR/$tdir/foo && error "echo worked"
4433         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4434         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4435         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4436         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4437                                                         error "lsattr"
4438         chattr -i $DIR/$tdir/foo || error "chattr failed"
4439
4440         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4441 }
4442 run_test 52b "immutable flag test (should return errors) ======="
4443
4444 test_53() {
4445         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4446         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4447         remote_ost_nodsh && skip "remote OST with nodsh" && return
4448
4449         local param
4450         local param_seq
4451         local ostname
4452         local mds_last
4453         local mds_last_seq
4454         local ost_last
4455         local ost_last_seq
4456         local ost_last_id
4457         local ostnum
4458         local node
4459         local found=false
4460         local support_last_seq=true
4461
4462         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4463                 support_last_seq=false
4464
4465         # only test MDT0000
4466         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4467         local value
4468         for value in $(do_facet $SINGLEMDS \
4469                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4470                 param=$(echo ${value[0]} | cut -d "=" -f1)
4471                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4472
4473                 if $support_last_seq; then
4474                         param_seq=$(echo $param |
4475                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4476                         mds_last_seq=$(do_facet $SINGLEMDS \
4477                                        $LCTL get_param -n $param_seq)
4478                 fi
4479                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4480
4481                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4482                 node=$(facet_active_host ost$((ostnum+1)))
4483                 param="obdfilter.$ostname.last_id"
4484                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4485                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4486                         ost_last_id=$ost_last
4487
4488                         if $support_last_seq; then
4489                                 ost_last_id=$(echo $ost_last |
4490                                               awk -F':' '{print $2}' |
4491                                               sed -e "s/^0x//g")
4492                                 ost_last_seq=$(echo $ost_last |
4493                                                awk -F':' '{print $1}')
4494                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4495                         fi
4496
4497                         if [[ $ost_last_id != $mds_last ]]; then
4498                                 error "$ost_last_id != $mds_last"
4499                         else
4500                                 found=true
4501                                 break
4502                         fi
4503                 done
4504         done
4505         $found || error "can not match last_seq/last_id for $mdtosc"
4506         return 0
4507 }
4508 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4509
4510 test_54a() {
4511         perl -MSocket -e ';' || { skip "no Socket perl module installed" && return; }
4512
4513         $SOCKETSERVER $DIR/socket ||
4514                 error "$SOCKETSERVER $DIR/socket failed: $?"
4515         $SOCKETCLIENT $DIR/socket ||
4516                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4517         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4518 }
4519 run_test 54a "unix domain socket test =========================="
4520
4521 test_54b() {
4522         f="$DIR/f54b"
4523         mknod $f c 1 3
4524         chmod 0666 $f
4525         dd if=/dev/zero of=$f bs=$(page_size) count=1
4526 }
4527 run_test 54b "char device works in lustre ======================"
4528
4529 find_loop_dev() {
4530         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4531         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4532         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4533
4534         for i in $(seq 3 7); do
4535                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4536                 LOOPDEV=$LOOPBASE$i
4537                 LOOPNUM=$i
4538                 break
4539         done
4540 }
4541
4542 cleanup_54c() {
4543         local rc=0
4544         loopdev="$DIR/loop54c"
4545
4546         trap 0
4547         $UMOUNT $DIR/$tdir || rc=$?
4548         losetup -d $loopdev || true
4549         losetup -d $LOOPDEV || true
4550         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4551         return $rc
4552 }
4553
4554 test_54c() {
4555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4556         loopdev="$DIR/loop54c"
4557
4558         find_loop_dev
4559         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4560         trap cleanup_54c EXIT
4561         mknod $loopdev b 7 $LOOPNUM
4562         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4563         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4564         losetup $loopdev $DIR/$tfile ||
4565                 error "can't set up $loopdev for $DIR/$tfile"
4566         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4567         test_mkdir $DIR/$tdir
4568         mount -t ext2 $loopdev $DIR/$tdir ||
4569                 error "error mounting $loopdev on $DIR/$tdir"
4570         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4571                 error "dd write"
4572         df $DIR/$tdir
4573         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4574                 error "dd read"
4575         cleanup_54c
4576 }
4577 run_test 54c "block device works in lustre ====================="
4578
4579 test_54d() {
4580         f="$DIR/f54d"
4581         string="aaaaaa"
4582         mknod $f p
4583         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4584 }
4585 run_test 54d "fifo device works in lustre ======================"
4586
4587 test_54e() {
4588         f="$DIR/f54e"
4589         string="aaaaaa"
4590         cp -aL /dev/console $f
4591         echo $string > $f || error "echo $string to $f failed"
4592 }
4593 run_test 54e "console/tty device works in lustre ======================"
4594
4595 test_56a() {
4596         local numfiles=3
4597         local dir=$DIR/$tdir
4598
4599         rm -rf $dir
4600         test_mkdir -p $dir/dir
4601         for i in $(seq $numfiles); do
4602                 touch $dir/file$i
4603                 touch $dir/dir/file$i
4604         done
4605
4606         local numcomp=$($LFS getstripe --component-count $dir)
4607
4608         [[ $numcomp == 0 ]] && numcomp=1
4609
4610         # test lfs getstripe with --recursive
4611         local filenum=$($LFS getstripe -r $dir | egrep -c "obdidx|l_ost_idx")
4612
4613         [[ $filenum -eq $((numfiles * 2)) ]] ||
4614                 error "$LFS getstripe -r: found $filenum != $((numfiles * 2))"
4615         filenum=$($LFS getstripe $dir | egrep -c "obdidx|l_ost_idx")
4616         [[ $filenum -eq $numfiles ]] ||
4617                 error "$LFS getstripe $dir: found $filenum, not $numfiles"
4618         echo "$LFS getstripe showed obdidx or l_ost_idx"
4619
4620         # test lfs getstripe with file instead of dir
4621         filenum=$($LFS getstripe $dir/file1 | egrep -c "obdidx|l_ost_idx")
4622         [[ $filenum -eq 1 ]] ||
4623                 error "$LFS getstripe $dir/file1: found $filenum, not 1"
4624         echo "$LFS getstripe file1 passed"
4625
4626         #test lfs getstripe with --verbose
4627         filenum=$($LFS getstripe --verbose $dir | grep -c lmm_magic)
4628         [[ $filenum -eq $((numfiles * numcomp)) ]] ||
4629                 error "$LFS getstripe --verbose $dir: "\
4630                       "got $filenum want $((numfiles * numcomp)) lmm_magic"
4631         [[ $($LFS getstripe $dir | grep -c lmm_magic) -eq 0 ]] ||
4632                 error "$LFS getstripe $dir: showed lmm_magic"
4633
4634         #test lfs getstripe with -v prints lmm_fid
4635         filenum=$($LFS getstripe -v $dir | grep -c lmm_fid)
4636         [[ $filenum -eq $((numfiles * numcomp)) ]] ||
4637                 error "$LFS getstripe -v $dir: "\
4638                       "got $filenum want $((numfiles * numcomp)) lmm_fid"
4639         [[ $($LFS getstripe $dir | grep -c lmm_fid) -eq 0 ]] ||
4640                 error "$LFS getstripe $dir: showed lmm_fid by default"
4641         echo "$LFS getstripe --verbose passed"
4642
4643         #check for FID information
4644         local fid1=$($LFS getstripe --fid $dir/file1)
4645         local fid2=$($LFS getstripe --verbose $dir/file1 |
4646                      awk '/lmm_fid: / { print $2; exit; }')
4647         local fid3=$($LFS path2fid $dir/file1)
4648
4649         [ "$fid1" != "$fid2" ] &&
4650                 error "getstripe --fid '$fid1' != getstripe --verbose '$fid2'"
4651         [ "$fid1" != "$fid3" ] &&
4652                 error "getstripe --fid '$fid1' != lfs path2fid '$fid3'"
4653         echo "$LFS getstripe --fid passed"
4654
4655         #test lfs getstripe with --obd
4656         $LFS getstripe --obd wrong_uuid $dir 2>&1 | grep -q "unknown obduuid" ||
4657                 error "$LFS getstripe --obd wrong_uuid: should return error"
4658
4659         [[ $OSTCOUNT -lt 2 ]] &&
4660                 skip_env "skip '$LFS getstripe --obd' tests: $OSTCOUNT < 2" &&
4661                 return
4662
4663         local ostidx=1
4664         local obduuid=$(ostuuid_from_index $ostidx)
4665         local found=$($LFS getstripe -r --obd $obduuid $dir |
4666                 grep 'lmm_stripe_offset:' | grep -c " $ostidx\$")
4667
4668         filenum=$($LFS getstripe -ir $dir | grep -c "^$ostidx\$")
4669         [[ $($LFS getstripe -id $dir) -ne $ostidx ]] ||
4670                 ((filenum--))
4671         [[ $($LFS getstripe -id $dir/dir) -ne $ostidx ]] ||
4672                 ((filenum--))
4673
4674         [[ $found -eq $filenum ]] ||
4675                 error "$LFS getstripe --obd: found $found expect $filenum"
4676         [[ $($LFS getstripe -r -v --obd $obduuid $dir |
4677                 sed '/^[         ]*'${ostidx}'[  ]/d' |
4678                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4679                 error "$LFS getstripe --obd: should not show file on other obd"
4680         echo "$LFS getstripe --obd passed"
4681 }
4682 run_test 56a "check $LFS getstripe"
4683
4684 test_56b() {
4685         local dir=$DIR/$tdir
4686         local numdirs=3
4687
4688         test_mkdir $dir
4689         for i in $(seq $numdirs); do
4690                 test_mkdir $dir/dir$i
4691         done
4692
4693         # test lfs getdirstripe default mode is non-recursion, which is
4694         # different from lfs getstripe
4695         local dircnt=$($LFS getdirstripe $dir | grep -c lmv_stripe_count)
4696
4697         [[ $dircnt -eq 1 ]] ||
4698                 error "$LFS getdirstripe: found $dircnt, not 1"
4699         dircnt=$($LFS getdirstripe --recursive $dir |
4700                 grep -c lmv_stripe_count)
4701         [[ $dircnt -eq $((numdirs + 1)) ]] ||
4702                 error "$LFS getdirstripe -r: $dircnt, != $((numdirs + 1))"
4703 }
4704 run_test 56b "check $LFS getdirstripe"
4705
4706 test_56c() {
4707         remote_ost_nodsh && skip "remote OST with nodsh" && return
4708
4709         local ost_idx=0
4710         local ost_name=$(ostname_from_index $ost_idx)
4711         local old_status=$(ost_dev_status $ost_idx)
4712
4713         [[ -z "$old_status" ]] ||
4714                 { skip_env "OST $ost_name is in $old_status status"; return 0; }
4715
4716         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
4717         sleep_maxage
4718
4719         local new_status=$(ost_dev_status $ost_idx)
4720
4721         [[ "$new_status" = "D" ]] ||
4722                 error "OST $ost_name is in status of '$new_status', not 'D'"
4723
4724         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
4725         sleep_maxage
4726
4727         new_status=$(ost_dev_status $ost_idx)
4728         [[ -z "$new_status" ]] ||
4729                 error "OST $ost_name is in status of '$new_status', not ''"
4730 }
4731 run_test 56c "check 'lfs df' showing device status"
4732
4733 NUMFILES=3
4734 NUMDIRS=3
4735 setup_56() {
4736         local local_tdir="$1"
4737         local local_numfiles="$2"
4738         local local_numdirs="$3"
4739         local dir_params="$4"
4740         local dir_stripe_params="$5"
4741
4742         if [ ! -d "$local_tdir" ] ; then
4743                 test_mkdir -p $dir_stripe_params $local_tdir
4744                 [ "$dir_params" ] && $LFS setstripe $dir_params $local_tdir
4745                 for i in $(seq $local_numfiles) ; do
4746                         touch $local_tdir/file$i
4747                 done
4748                 for i in $(seq $local_numdirs) ; do
4749                         test_mkdir $dir_stripe_params $local_tdir/dir$i
4750                         for j in $(seq $local_numfiles) ; do
4751                                 touch $local_tdir/dir$i/file$j
4752                         done
4753                 done
4754         fi
4755 }
4756
4757 setup_56_special() {
4758         local local_tdir=$1
4759         local local_numfiles=$2
4760         local local_numdirs=$3
4761
4762         setup_56 $local_tdir $local_numfiles $local_numdirs
4763
4764         if [ ! -e "$local_tdir/loop${local_numfiles}b" ] ; then
4765                 for i in $(seq $local_numfiles) ; do
4766                         mknod $local_tdir/loop${i}b b 7 $i
4767                         mknod $local_tdir/null${i}c c 1 3
4768                         ln -s $local_tdir/file1 $local_tdir/link${i}
4769                 done
4770                 for i in $(seq $local_numdirs) ; do
4771                         mknod $local_tdir/dir$i/loop${i}b b 7 $i
4772                         mknod $local_tdir/dir$i/null${i}c c 1 3
4773                         ln -s $local_tdir/dir$i/file1 $local_tdir/dir$i/link${i}
4774                 done
4775         fi
4776 }
4777
4778 test_56g() {
4779         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4780         local expected=$(($NUMDIRS + 2))
4781
4782         setup_56 $dir $NUMFILES $NUMDIRS
4783
4784         # test lfs find with -name
4785         for i in $(seq $NUMFILES) ; do
4786                 local nums=$($LFS find -name "*$i" $dir | wc -l)
4787
4788                 [ $nums -eq $expected ] ||
4789                         error "lfs find -name '*$i' $dir wrong: "\
4790                               "found $nums, expected $expected"
4791         done
4792 }
4793 run_test 56g "check lfs find -name"
4794
4795 test_56h() {
4796         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4797         local expected=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4798
4799         setup_56 $dir $NUMFILES $NUMDIRS
4800
4801         # test lfs find with ! -name
4802         for i in $(seq $NUMFILES) ; do
4803                 local nums=$($LFS find ! -name "*$i" $dir | wc -l)
4804
4805                 [ $nums -eq $expected ] ||
4806                         error "lfs find ! -name '*$i' $dir wrong: "\
4807                               "found $nums, expected $expected"
4808         done
4809 }
4810 run_test 56h "check lfs find ! -name"
4811
4812 test_56i() {
4813         local dir=$DIR/$tdir
4814
4815         test_mkdir $dir
4816
4817         local cmd="$LFS find -ost $(ostuuid_from_index 0 $dir) $dir"
4818         local out=$($cmd)
4819
4820         [ -z "$out" ] || error "'$cmd' returned directory '$out'"
4821 }
4822 run_test 56i "check 'lfs find -ost UUID' skips directories"
4823
4824 test_56j() {
4825         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4826
4827         setup_56_special $dir $NUMFILES $NUMDIRS
4828
4829         local expected=$((NUMDIRS + 1))
4830         local cmd="$LFS find -type d $dir"
4831         local nums=$($cmd | wc -l)
4832
4833         [ $nums -eq $expected ] ||
4834                 error "'$cmd' wrong: found $nums, expected $expected"
4835 }
4836 run_test 56j "check lfs find -type d"
4837
4838 test_56k() {
4839         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4840
4841         setup_56_special $dir $NUMFILES $NUMDIRS
4842
4843         local expected=$(((NUMDIRS + 1) * NUMFILES))
4844         local cmd="$LFS find -type f $dir"
4845         local nums=$($cmd | wc -l)
4846
4847         [ $nums -eq $expected ] ||
4848                 error "'$cmd' wrong: found $nums, expected $expected"
4849 }
4850 run_test 56k "check lfs find -type f"
4851
4852 test_56l() {
4853         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4854
4855         setup_56_special $dir $NUMFILES $NUMDIRS
4856
4857         local expected=$((NUMDIRS + NUMFILES))
4858         local cmd="$LFS find -type b $dir"
4859         local nums=$($cmd | wc -l)
4860
4861         [ $nums -eq $expected ] ||
4862                 error "'$cmd' wrong: found $nums, expected $expected"
4863 }
4864 run_test 56l "check lfs find -type b"
4865
4866 test_56m() {
4867         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4868
4869         setup_56_special $dir $NUMFILES $NUMDIRS
4870
4871         local expected=$((NUMDIRS + NUMFILES))
4872         local cmd="$LFS find -type c $dir"
4873         local nums=$($cmd | wc -l)
4874         [ $nums -eq $expected ] ||
4875                 error "'$cmd' wrong: found $nums, expected $expected"
4876 }
4877 run_test 56m "check lfs find -type c"
4878
4879 test_56n() {
4880         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
4881         setup_56_special $dir $NUMFILES $NUMDIRS
4882
4883         local expected=$((NUMDIRS + NUMFILES))
4884         local cmd="$LFS find -type l $dir"
4885         local nums=$($cmd | wc -l)
4886
4887         [ $nums -eq $expected ] ||
4888                 error "'$cmd' wrong: found $nums, expected $expected"
4889 }
4890 run_test 56n "check lfs find -type l"
4891
4892 test_56o() {
4893         local dir=$DIR/$tdir
4894
4895         setup_56 $dir $NUMFILES $NUMDIRS
4896         utime $dir/file1 > /dev/null || error "utime (1)"
4897         utime $dir/file2 > /dev/null || error "utime (2)"
4898         utime $dir/dir1 > /dev/null || error "utime (3)"
4899         utime $dir/dir2 > /dev/null || error "utime (4)"
4900         utime $dir/dir1/file1 > /dev/null || error "utime (5)"
4901         dd if=/dev/zero count=1 >> $dir/dir1/file1 && sync
4902
4903         local expected=4
4904         local nums=$($LFS find -mtime +0 $dir | wc -l)
4905
4906         [ $nums -eq $expected ] ||
4907                 error "lfs find -mtime +0 $dir: found $nums expect $expected"
4908
4909         expected=12
4910         cmd="$LFS find -mtime 0 $dir"
4911         nums=$($cmd | wc -l)
4912         [ $nums -eq $expected ] ||
4913                 error "'$cmd' wrong: found $nums, expected $expected"
4914 }
4915 run_test 56o "check lfs find -mtime for old files"
4916
4917 test_56p() {
4918         [ $RUNAS_ID -eq $UID ] &&
4919                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4920
4921         local dir=$DIR/$tdir
4922
4923         setup_56 $dir $NUMFILES $NUMDIRS
4924         chown $RUNAS_ID $dir/file* || error "chown $DIR/${tdir}g/file$i failed"
4925
4926         local expected=$NUMFILES
4927         local cmd="$LFS find -uid $RUNAS_ID $dir"
4928         local nums=$($cmd | wc -l)
4929
4930         [ $nums -eq $expected ] ||
4931                 error "'$cmd' wrong: found $nums, expected $expected"
4932
4933         expected=$(((NUMFILES + 1) * NUMDIRS + 1))
4934         cmd="$LFS find ! -uid $RUNAS_ID $dir"
4935         nums=$($cmd | wc -l)
4936         [ $nums -eq $expected ] ||
4937                 error "'$cmd' wrong: found $nums, expected $expected"
4938 }
4939 run_test 56p "check lfs find -uid and ! -uid"
4940
4941 test_56q() {
4942         [ $RUNAS_ID -eq $UID ] &&
4943                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4944
4945         local dir=$DIR/$tdir
4946
4947         setup_56 $dir $NUMFILES $NUMDIRS
4948         chgrp $RUNAS_GID $dir/file* || error "chown $dir/file$i failed"
4949
4950         local expected=$NUMFILES
4951         local cmd="$LFS find -gid $RUNAS_GID $dir"
4952         local nums=$($cmd | wc -l)
4953
4954         [ $nums -eq $expected ] ||
4955                 error "'$cmd' wrong: found $nums, expected $expected"
4956
4957         expected=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4958         cmd="$LFS find ! -gid $RUNAS_GID $dir"
4959         nums=$($cmd | wc -l)
4960         [ $nums -eq $expected ] ||
4961                 error "'$cmd' wrong: found $nums, expected $expected"
4962 }
4963 run_test 56q "check lfs find -gid and ! -gid"
4964
4965 test_56r() {
4966         local dir=$DIR/$tdir
4967
4968         setup_56 $dir $NUMFILES $NUMDIRS
4969
4970         local expected=12
4971         local cmd="$LFS find -size 0 -type f $dir"
4972         local nums=$($cmd | wc -l)
4973
4974         [ $nums -eq $expected ] ||
4975                 error "'$cmd' wrong: found $nums, expected $expected"
4976         expected=0
4977         cmd="$LFS find ! -size 0 -type f $dir"
4978         nums=$($cmd | wc -l)
4979         [ $nums -eq $expected ] ||
4980                 error "'$cmd' wrong: found $nums, expected $expected"
4981         echo "test" > $dir/$tfile
4982         echo "test2" > $dir/$tfile.2 && sync
4983         expected=1
4984         cmd="$LFS find -size 5 -type f $dir"
4985         nums=$($cmd | wc -l)
4986         [ $nums -eq $expected ] ||
4987                 error "'$cmd' wrong: found $nums, expected $expected"
4988         expected=1
4989         cmd="$LFS find -size +5 -type f $dir"
4990         nums=$($cmd | wc -l)
4991         [ $nums -eq $expected ] ||
4992                 error "'$cmd' wrong: found $nums, expected $expected"
4993         expected=2
4994         cmd="$LFS find -size +0 -type f $dir"
4995         nums=$($cmd | wc -l)
4996         [ $nums -eq $expected ] ||
4997                 error "'$cmd' wrong: found $nums, expected $expected"
4998         expected=2
4999         cmd="$LFS find ! -size -5 -type f $dir"
5000         nums=$($cmd | wc -l)
5001         [ $nums -eq $expected ] ||
5002                 error "'$cmd' wrong: found $nums, expected $expected"
5003         expected=12
5004         cmd="$LFS find -size -5 -type f $dir"
5005         nums=$($cmd | wc -l)
5006         [ $nums -eq $expected ] ||
5007                 error "'$cmd' wrong: found $nums, expected $expected"
5008 }
5009 run_test 56r "check lfs find -size works"
5010
5011 test_56s() { # LU-611 #LU-9369
5012         [[ $OSTCOUNT -lt 2 ]] && skip "need at least 2 OSTs" && return 0
5013
5014         local dir=$DIR/$tdir
5015         local onestripe=$(((NUMDIRS + 1) * NUMFILES))
5016
5017         setup_56 $dir $NUMFILES $NUMDIRS "-c 1"
5018         for i in $(seq $NUMDIRS); do
5019                 $LFS setstripe -c $((OSTCOUNT + 1)) $dir/dir$i/$tfile
5020         done
5021
5022         local expected=$NUMDIRS
5023         local cmd="$LFS find -c $OSTCOUNT $dir"
5024         local nums=$($cmd | wc -l)
5025
5026         [ $nums -eq $expected ] || {
5027                 $LFS getstripe -R $dir
5028                 error "'$cmd' wrong: found $nums, expected $expected"
5029         }
5030
5031         expected=$((NUMDIRS + onestripe))
5032         cmd="$LFS find -stripe-count +0 -type f $dir"
5033         nums=$($cmd | wc -l)
5034         [ $nums -eq $expected ] || {
5035                 $LFS getstripe -R $dir
5036                 error "'$cmd' wrong: found $nums, expected $expected"
5037         }
5038
5039         expected=$onestripe
5040         cmd="$LFS find -stripe-count 1 -type f $dir"
5041         nums=$($cmd | wc -l)
5042         [ $nums -eq $expected ] || {
5043                 $LFS getstripe -R $dir
5044                 error "'$cmd' wrong: found $nums, expected $expected"
5045         }
5046
5047         cmd="$LFS find -stripe-count -2 -type f $dir"
5048         nums=$($cmd | wc -l)
5049         [ $nums -eq $expected ] || {
5050                 $LFS getstripe -R $dir
5051                 error "'$cmd' wrong: found $nums, expected $expected"
5052         }
5053
5054         expected=0
5055         cmd="$LFS find -stripe-count $((OSTCOUNT + 1)) -type f $dir"
5056         nums=$($cmd | wc -l)
5057         [ $nums -eq $expected ] || {
5058                 $LFS getstripe -R $dir
5059                 error "'$cmd' wrong: found $nums, expected $expected"
5060         }
5061 }
5062 run_test 56s "check lfs find -stripe-count works"
5063
5064 test_56t() { # LU-611 #LU-9369
5065         local dir=$DIR/$tdir
5066
5067         setup_56 $dir 0 $NUMDIRS
5068         for i in $(seq $NUMDIRS); do
5069                 $LFS setstripe -S 8M $dir/dir$i/$tfile
5070         done
5071
5072         local expected=$NUMDIRS
5073         local cmd="$LFS find -S 8M $dir"
5074         local nums=$($cmd | wc -l)
5075
5076         [ $nums -eq $expected ] || {
5077                 $LFS getstripe -R $dir
5078                 error "'$cmd' wrong: found $nums, expected $expected"
5079         }
5080         rm -rf $dir
5081
5082         setup_56 $dir $NUMFILES $NUMDIRS "--stripe-size 512k"
5083
5084         $LFS setstripe -S 256k $dir/$tfile.{0,1,2,3}
5085
5086         expected=$(((NUMDIRS + 1) * NUMFILES))
5087         cmd="$LFS find -stripe-size 512k -type f $dir"
5088         nums=$($cmd | wc -l)
5089         [ $nums -eq $expected ] ||
5090                 error "'$cmd' wrong: found $nums, expected $expected"
5091
5092         cmd="$LFS find -stripe-size +320k -type f $dir"
5093         nums=$($cmd | wc -l)
5094         [ $nums -eq $expected ] ||
5095                 error "'$cmd' wrong: found $nums, expected $expected"
5096
5097         expected=$(((NUMDIRS + 1) * NUMFILES + 4))
5098         cmd="$LFS find -stripe-size +200k -type f $dir"
5099         nums=$($cmd | wc -l)
5100         [ $nums -eq $expected ] ||
5101                 error "'$cmd' wrong: found $nums, expected $expected"
5102
5103         cmd="$LFS find -stripe-size -640k -type f $dir"
5104         nums=$($cmd | wc -l)
5105         [ $nums -eq $expected ] ||
5106                 error "'$cmd' wrong: found $nums, expected $expected"
5107
5108         expected=4
5109         cmd="$LFS find -stripe-size 256k -type f $dir"
5110         nums=$($cmd | wc -l)
5111         [ $nums -eq $expected ] ||
5112                 error "'$cmd' wrong: found $nums, expected $expected"
5113
5114         cmd="$LFS find -stripe-size -320k -type f $dir"
5115         nums=$($cmd | wc -l)
5116         [ $nums -eq $expected ] ||
5117                 error "'$cmd' wrong: found $nums, expected $expected"
5118
5119         expected=0
5120         cmd="$LFS find -stripe-size 1024k -type f $dir"
5121         nums=$($cmd | wc -l)
5122         [ $nums -eq $expected ] ||
5123                 error "'$cmd' wrong: found $nums, expected $expected"
5124 }
5125 run_test 56t "check lfs find -stripe-size works"
5126
5127 test_56u() { # LU-611
5128         local dir=$DIR/$tdir
5129
5130         setup_56 $dir $NUMFILES $NUMDIRS "-i 0 -c 1"
5131
5132         if [[ $OSTCOUNT -gt 1 ]]; then
5133                 $LFS setstripe -i 1 -c 1 $dir/$tfile.{0,1,2,3}
5134                 onestripe=4
5135         else
5136                 onestripe=0
5137         fi
5138
5139         local expected=$(((NUMDIRS + 1) * NUMFILES))
5140         local cmd="$LFS find -stripe-index 0 -type f $dir"
5141         local nums=$($cmd | wc -l)
5142
5143         [ $nums -eq $expected ] ||
5144                 error "'$cmd' wrong: found $nums, expected $expected"
5145
5146         expected=$onestripe
5147         cmd="$LFS find -stripe-index 1 -type f $dir"
5148         nums=$($cmd | wc -l)
5149         [ $nums -eq $expected ] ||
5150                 error "'$cmd' wrong: found $nums, expected $expected"
5151
5152         cmd="$LFS find ! -stripe-index 0 -type f $dir"
5153         nums=$($cmd | wc -l)
5154         [ $nums -eq $expected ] ||
5155                 error "'$cmd' wrong: found $nums, expected $expected"
5156
5157         expected=0
5158         # This should produce an error and not return any files
5159         cmd="$LFS find -stripe-index $OSTCOUNT -type f $dir"
5160         nums=$($cmd 2>/dev/null | wc -l)
5161         [ $nums -eq $expected ] ||
5162                 error "'$cmd' wrong: found $nums, expected $expected"
5163
5164         if [[ $OSTCOUNT -gt 1 ]]; then
5165                 expected=$(((NUMDIRS + 1) * NUMFILES + onestripe))
5166                 cmd="$LFS find -stripe-index 0,1 -type f $dir"
5167                 nums=$($cmd | wc -l)
5168                 [ $nums -eq $expected ] ||
5169                         error "'$cmd' wrong: found $nums, expected $expected"
5170         fi
5171 }
5172 run_test 56u "check lfs find -stripe-index works"
5173
5174 test_56v() {
5175         local MDT_IDX=0
5176         local dir=$DIR/$tdir
5177
5178         setup_56 $dir $NUMFILES $NUMDIRS
5179
5180         UUID=$(mdtuuid_from_index $MDT_IDX $dir)
5181         [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT $MDT_IDX"
5182
5183         for file in $($LFS find -mdt $UUID $dir); do
5184                 file_mdt_idx=$($LFS getstripe -M $file)
5185                 [ $file_mdt_idx -eq $MDT_IDX ] ||
5186                         error "lfind -mdt $UUID != getstripe -M $file_mdt_idx"
5187         done
5188 }
5189 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
5190
5191 test_56w() {
5192         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5193         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5194         local dir=$DIR/$tdir
5195
5196         setup_56 $dir $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
5197
5198         local stripe_size=$($LFS getstripe -S -d $dir) ||
5199                 error "$LFS getstripe -S -d $dir failed"
5200         stripe_size=${stripe_size%% *}
5201
5202         local file_size=$((stripe_size * OSTCOUNT))
5203         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
5204         local required_space=$((file_num * file_size))
5205         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
5206                            head -n1)
5207         [[ $free_space -le $((required_space / 1024)) ]] &&
5208                 skip_env "need $required_space, have $free_space kbytes" &&
5209                 return
5210
5211         local dd_bs=65536
5212         local dd_count=$((file_size / dd_bs))
5213
5214         # write data into the files
5215         local i
5216         local j
5217         local file
5218
5219         for i in $(seq $NUMFILES); do
5220                 file=$dir/file$i
5221                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5222                         error "write data into $file failed"
5223         done
5224         for i in $(seq $NUMDIRS); do
5225                 for j in $(seq $NUMFILES); do
5226                         file=$dir/dir$i/file$j
5227                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5228                                 error "write data into $file failed"
5229                 done
5230         done
5231
5232         # $LFS_MIGRATE will fail if hard link migration is unsupported
5233         if [[ $(lustre_version_code mds1) -gt $(version_code 2.5.55) ]]; then
5234                 createmany -l$dir/dir1/file1 $dir/dir1/link 200 ||
5235                         error "creating links to $dir/dir1/file1 failed"
5236         fi
5237
5238         local expected=-1
5239
5240         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
5241
5242         # lfs_migrate file
5243         local cmd="$LFS_MIGRATE -y -c $expected $dir/file1"
5244
5245         echo "$cmd"
5246         eval $cmd || error "$cmd failed"
5247
5248         check_stripe_count $dir/file1 $expected
5249
5250         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
5251         then
5252                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
5253                 # OST 1 if it is on OST 0. This file is small enough to
5254                 # be on only one stripe.
5255                 file=$dir/migr_1_ost
5256                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
5257                         error "write data into $file failed"
5258                 local obdidx=$($LFS getstripe -i $file)
5259                 local oldmd5=$(md5sum $file)
5260                 local newobdidx=0
5261
5262                 [[ $obdidx -eq 0 ]] && newobdidx=1
5263                 cmd="$LFS migrate -i $newobdidx $file"
5264                 echo $cmd
5265                 eval $cmd || error "$cmd failed"
5266
5267                 local realobdix=$($LFS getstripe -i $file)
5268                 local newmd5=$(md5sum $file)
5269
5270                 [[ $newobdidx -ne $realobdix ]] &&
5271                         error "new OST is different (was=$obdidx, "\
5272                               "wanted=$newobdidx, got=$realobdix)"
5273                 [[ "$oldmd5" != "$newmd5" ]] &&
5274                         error "md5sum differ: $oldmd5, $newmd5"
5275         fi
5276
5277         # lfs_migrate dir
5278         cmd="$LFS_MIGRATE -y -c $expected $dir/dir1"
5279         echo "$cmd"
5280         eval $cmd || error "$cmd failed"
5281
5282         for j in $(seq $NUMFILES); do
5283                 check_stripe_count $dir/dir1/file$j $expected
5284         done
5285
5286         # lfs_migrate works with lfs find
5287         cmd="$LFS find -stripe_count $OSTCOUNT -type f $dir |
5288              $LFS_MIGRATE -y -c $expected"
5289         echo "$cmd"
5290         eval $cmd || error "$cmd failed"
5291
5292         for i in $(seq 2 $NUMFILES); do
5293                 check_stripe_count $dir/file$i $expected
5294         done
5295         for i in $(seq 2 $NUMDIRS); do
5296                 for j in $(seq $NUMFILES); do
5297                 check_stripe_count $dir/dir$i/file$j $expected
5298                 done
5299         done
5300 }
5301 run_test 56w "check lfs_migrate -c stripe_count works"
5302
5303 test_56wb() {
5304         local file1=$DIR/$tdir/file1
5305         local create_pool=false
5306         local initial_pool=$($LFS getstripe -p $DIR)
5307         local pool_list=()
5308         local pool=""
5309
5310         echo -n "Creating test dir..."
5311         test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
5312         echo "done."
5313
5314         echo -n "Creating test file..."
5315         touch $file1 || error "cannot create file"
5316         echo "done."
5317
5318         echo -n "Detecting existing pools..."
5319         pool_list=($($LFS pool_list $FSNAME | grep "$FSNAME\." | cut -d. -f2))
5320
5321         if [ ${#pool_list[@]} -gt 0 ]; then
5322                 echo "${pool_list[@]}"
5323                 for thispool in "${pool_list[@]}"; do
5324                         if [[ -z "$initial_pool" ||
5325                               "$initial_pool" != "$thispool" ]]; then
5326                                 pool="$thispool"
5327                                 echo "Using existing pool '$pool'"
5328                                 break
5329                         fi
5330                 done
5331         else
5332                 echo "none detected."
5333         fi
5334         if [ -z "$pool" ]; then
5335                 pool=${POOL:-testpool}
5336                 [ "$initial_pool" = "$pool" ] && pool="testpool2"
5337                 echo -n "Creating pool '$pool'..."
5338                 create_pool=true
5339                 pool_add $pool &> /dev/null ||
5340                         error "pool_add failed"
5341                 echo "done."
5342
5343                 echo -n "Adding target to pool..."
5344                 pool_add_targets $pool 0 0 1 &> /dev/null ||
5345                         error "pool_add_targets failed"
5346                 echo "done."
5347         fi
5348
5349         echo -n "Setting pool using -p option..."
5350         $LFS_MIGRATE -y -q --no-rsync -p $pool $file1 &> /dev/null ||
5351                 error "migrate failed rc = $?"
5352         echo "done."
5353
5354         echo -n "Verifying test file is in pool after migrating..."
5355         [ "$($LFS getstripe -p $file1)" = $pool ] ||
5356                 error "file was not migrated to pool $pool"
5357         echo "done."
5358
5359         echo -n "Removing test file from pool '$pool'..."
5360         $LFS migrate $file1 &> /dev/null ||
5361                 error "cannot remove from pool"
5362         [ "$($LFS getstripe -p $file1)" ] &&
5363                 error "pool still set"
5364         echo "done."
5365
5366         echo -n "Setting pool using --pool option..."
5367         $LFS_MIGRATE -y -q --no-rsync --pool $pool $file1 &> /dev/null ||
5368                 error "migrate failed rc = $?"
5369         echo "done."
5370
5371         # Clean up
5372         rm -f $file1
5373         if $create_pool; then
5374                 destroy_test_pools 2> /dev/null ||
5375                         error "destroy test pools failed"
5376         fi
5377 }
5378 run_test 56wb "check lfs_migrate pool support"
5379
5380 test_56wc() {
5381         local file1="$DIR/$tdir/file 1"
5382
5383         echo -n "Creating test dir..."
5384         test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
5385         local def_stripe_size=$($LFS getstripe -S $DIR/$tdir 2>/dev/null)
5386         $LFS setstripe -S 1M -c 1 "$DIR/$tdir" &> /dev/null ||
5387                 error "cannot set stripe"
5388         echo "done"
5389
5390         echo -n "Setting initial stripe for test file..."
5391         $LFS setstripe -S 512K -c 1 "$file1" &> /dev/null ||
5392                 error "cannot set stripe"
5393         [ $($LFS getstripe -S "$file1") -eq 524288 ] ||
5394                 error "stripe size not set"
5395         echo "done."
5396
5397         # File currently set to -S 512K -c 1
5398
5399         # Ensure -c and -S options are rejected when -R is set
5400         echo -n "Verifying incompatible options are detected..."
5401         $LFS_MIGRATE -y -R -c 1 "$file1" &> /dev/null &&
5402                 error "incompatible -c and -R options not detected"
5403         $LFS_MIGRATE -y -R -S 1M "$file1" &> /dev/null &&
5404                 error "incompatible -S and -R options not detected"
5405         echo "done."
5406
5407         # Ensure unrecognized options are passed through to 'lfs migrate'
5408         echo -n "Verifying -S option is passed through to lfs migrate..."
5409         $LFS_MIGRATE -y -S 1M "$file1" &> /dev/null ||
5410                 error "migration failed"
5411         [ $($LFS getstripe -S "$file1") -eq 1048576 ] ||
5412                 error "file was not restriped"
5413         echo "done."
5414
5415         # File currently set to -S 1M -c 1
5416
5417         # Ensure long options are supported
5418         echo -n "Verifying long options supported..."
5419         $LFS_MIGRATE -y --non-block "$file1" &> /dev/null ||
5420                 error "long option without argument not supported"
5421         $LFS_MIGRATE -y --stripe-size 512K "$file1" &> /dev/null ||
5422                 error "long option with argument not supported"
5423         [ $($LFS getstripe -S "$file1") -eq 524288 ] ||
5424                 error "file not restriped with --stripe-size option"
5425         echo "done."
5426
5427         # File currently set to -S 512K -c 1
5428
5429         if [ "$OSTCOUNT" -gt 1 ]; then
5430                 echo -n "Verifying explicit stripe count can be set..."
5431                 $LFS_MIGRATE -y -c 2 "$file1" &> /dev/null ||
5432                         error "migrate failed"
5433                 [ $($LFS getstripe -c "$file1") -eq 2 ] ||
5434                         error "file not restriped to explicit count"
5435                 echo "done."
5436         fi
5437
5438         # File currently set to -S 512K -c 1 or -S 512K -c 2
5439
5440         # Ensure parent striping is used if -R is set, and no stripe
5441         # count or size is specified
5442         echo -n "Setting stripe for parent directory..."
5443         $LFS setstripe -S 1M -c 1 "$DIR/$tdir" &> /dev/null ||
5444                 error "cannot set stripe"
5445         echo "done."
5446
5447         echo -n "Verifying restripe option uses parent stripe settings..."
5448         $LFS_MIGRATE -y -R "$file1" &> /dev/null ||
5449                 error "migrate failed"
5450         [ $($LFS getstripe -S "$file1") -eq $def_stripe_size ] ||
5451                 error "file not restriped to parent settings"
5452         [ $($LFS getstripe -c "$file1") -eq 1 ] ||
5453                 error "file not restriped to parent settings"
5454         echo "done."
5455
5456         # File currently set to -S 1M -c 1
5457
5458         # Ensure striping is preserved if -R is not set, and no stripe
5459         # count or size is specified
5460         echo -n "Verifying striping size preserved when not specified..."
5461         local orig_stripe_size=$($LFS getstripe -S "$file1" 2>/dev/null)
5462         $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
5463                 error "cannot set stripe on parent directory"
5464         $LFS_MIGRATE -y "$file1" &> /dev/null ||
5465                 error "migrate failed"
5466         [ $($LFS getstripe -S "$file1") -eq $orig_stripe_size ] ||
5467                 error "file was restriped"
5468         echo "done."
5469
5470         # Ensure file name properly detected when final option has no argument
5471         echo -n "Verifying file name properly detected..."
5472         $LFS_MIGRATE -y "$file1" &> /dev/null ||
5473                 error "file name interpreted as option argument"
5474         echo "done."
5475
5476         # Clean up
5477         rm -f "$file1"
5478 }
5479 run_test 56wc "check unrecognized options for lfs_migrate are passed through"
5480
5481 test_56wd() {
5482         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5483         local file1=$DIR/$tdir/file1
5484
5485         echo -n "Creating test dir..."
5486         test_mkdir $DIR/$tdir || error "cannot create dir"
5487         echo "done."
5488
5489         echo -n "Creating test file..."
5490         touch $file1
5491         echo "done."
5492
5493         # Ensure 'lfs migrate' will fail by using a non-existent option,
5494         # and make sure rsync is not called to recover
5495         echo -n "Make sure --no-rsync option works..."
5496         $LFS_MIGRATE -y --no-rsync --invalid-opt $file1 2>&1 |
5497                 grep -q 'refusing to fall back to rsync' ||
5498                 error "rsync was called with --no-rsync set"
5499         echo "done."
5500
5501         # Ensure rsync is called without trying 'lfs migrate' first
5502         echo -n "Make sure --rsync option works..."
5503         $LFS_MIGRATE -y --rsync --invalid-opt $file1 2>&1 |
5504                 grep -q 'falling back to rsync' &&
5505                 error "lfs migrate was called with --rsync set"
5506         echo "done."
5507
5508         echo -n "Make sure --rsync and --no-rsync options are exclusive..."
5509         $LFS_MIGRATE -y --rsync --no-rsync $file1 2>&1 |
5510                 grep -q 'at the same time' ||
5511                 error "--rsync and --no-rsync accepted concurrently"
5512         echo "done."
5513
5514         # Clean up
5515         rm -f $file1
5516 }
5517 run_test 56wd "check lfs_migrate --rsync and --no-rsync work"
5518
5519 test_56x() {
5520         check_swap_layouts_support && return 0
5521         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5522
5523         local dir=$DIR/$tdir
5524         local ref1=/etc/passwd
5525         local file1=$dir/file1
5526
5527         test_mkdir $dir || error "creating dir $dir"
5528         $LFS setstripe -c 2 $file1
5529         cp $ref1 $file1
5530         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
5531         stripe=$($LFS getstripe -c $file1)
5532         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5533         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5534
5535         # clean up
5536         rm -f $file1
5537 }
5538 run_test 56x "lfs migration support"
5539
5540 test_56xa() {
5541         check_swap_layouts_support && return 0
5542         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5543
5544         local dir=$DIR/$tdir/$testnum
5545
5546         test_mkdir -p $dir
5547
5548         local ref1=/etc/passwd
5549         local file1=$dir/file1
5550
5551         $LFS setstripe -c 2 $file1
5552         cp $ref1 $file1
5553         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
5554
5555         local stripe=$($LFS getstripe -c $file1)
5556
5557         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5558         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5559
5560         # clean up
5561         rm -f $file1
5562 }
5563 run_test 56xa "lfs migration --block support"
5564
5565 check_migrate_links() {
5566         local dir="$1"
5567         local file1="$dir/file1"
5568         local begin="$2"
5569         local count="$3"
5570         local total_count=$(($begin + $count - 1))
5571         local symlink_count=10
5572         local uniq_count=10
5573
5574         if [ ! -f "$file1" ]; then
5575                 echo -n "creating initial file..."
5576                 $LFS setstripe -c 1 -S "512k" "$file1" ||
5577                         error "cannot setstripe initial file"
5578                 echo "done"
5579
5580                 echo -n "creating symlinks..."
5581                 for s in $(seq 1 $symlink_count); do
5582                         ln -s "$file1" "$dir/slink$s" ||
5583                                 error "cannot create symlinks"
5584                 done
5585                 echo "done"
5586
5587                 echo -n "creating nonlinked files..."
5588                 createmany -o "$dir/uniq" 1 10 &> /dev/null ||
5589                         error "cannot create nonlinked files"
5590                 echo "done"
5591         fi
5592
5593         # create hard links
5594         if [ ! -f "$dir/file$total_count" ]; then
5595                 echo -n "creating hard links $begin:$total_count..."
5596                 createmany -l"$file1" "$dir/file" "$begin" "$count" &>  \
5597                         /dev/null || error "cannot create hard links"
5598                 echo "done"
5599         fi
5600
5601         echo -n "checking number of hard links listed in xattrs..."
5602         local fid=$($LFS getstripe -F "$file1")
5603         local paths=($($LFS fid2path "$MOUNT" "$fid" 2> /dev/null))
5604
5605         echo "${#paths[*]}"
5606         if [ ${#paths[*]} -lt $total_count -a "$begin" -eq 2  ]; then
5607                         echo "hard link list has unexpected size, skipping test"
5608                         return 0
5609         fi
5610         if [ ${#paths[*]} -ge $total_count -a "$begin" -ne 2  ]; then
5611                         error "link names should exceed xattrs size"
5612         fi
5613
5614         echo -n "migrating files..."
5615         local migrate_out=$($LFS_MIGRATE -y -S '1m' $dir)
5616         local rc=$?
5617         [ $rc -eq 0 ] || error "migrate failed rc = $rc"
5618         echo "done"
5619
5620         # make sure all links have been properly migrated
5621         echo -n "verifying files..."
5622         fid=$($LFS getstripe -F "$file1") ||
5623                 error "cannot get fid for file $file1"
5624         for i in $(seq 2 $total_count); do
5625                 local fid2=$($LFS getstripe -F $dir/file$i)
5626
5627                 [ "$fid2" == "$fid" ] ||
5628                         error "migrated hard link has mismatched FID"
5629         done
5630
5631         # make sure hard links were properly detected, and migration was
5632         # performed only once for the entire link set; nonlinked files should
5633         # also be migrated
5634         local actual=$(grep -c 'done migrate' <<< "$migrate_out")
5635         local expected=$(($uniq_count + 1))
5636
5637         [ "$actual" -eq  "$expected" ] ||
5638                 error "hard links individually migrated ($actual != $expected)"
5639
5640         # make sure the correct number of hard links are present
5641         local hardlinks=$(stat -c '%h' "$file1")
5642
5643         [ $hardlinks -eq $total_count ] ||
5644                 error "num hard links $hardlinks != $total_count"
5645         echo "done"
5646
5647         return 0
5648 }
5649
5650 test_56xb() {
5651         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
5652                 skip "Need MDS version at least 2.10.55" && return
5653
5654         local dir="$DIR/$tdir"
5655
5656         test_mkdir "$dir" || error "cannot create dir $dir"
5657
5658         echo "testing lfs migrate mode when all links fit within xattrs"
5659         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir" 2 99
5660
5661         echo "testing rsync mode when all links fit within xattrs"
5662         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir" 2 99
5663
5664         echo "testing lfs migrate mode when all links do not fit within xattrs"
5665         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir" 101 100
5666
5667         echo "testing rsync mode when all links do not fit within xattrs"
5668         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir" 101 100
5669
5670         # clean up
5671         rm -rf $dir
5672 }
5673 run_test 56xb "lfs migration hard link support"
5674
5675 test_56y() {
5676         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
5677                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
5678                 return
5679
5680         local res=""
5681         local dir=$DIR/$tdir
5682         local f1=$dir/file1
5683         local f2=$dir/file2
5684
5685         test_mkdir -p $dir || error "creating dir $dir"
5686         touch $f1 || error "creating std file $f1"
5687         $MULTIOP $f2 H2c || error "creating released file $f2"
5688
5689         # a directory can be raid0, so ask only for files
5690         res=$($LFS find $dir -L raid0 -type f | wc -l)
5691         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5692
5693         res=$($LFS find $dir \! -L raid0 -type f | wc -l)
5694         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5695
5696         # only files can be released, so no need to force file search
5697         res=$($LFS find $dir -L released)
5698         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5699
5700         res=$($LFS find $dir -type f \! -L released)
5701         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5702 }
5703 run_test 56y "lfs find -L raid0|released"
5704
5705 test_56z() { # LU-4824
5706         # This checks to make sure 'lfs find' continues after errors
5707         # There are two classes of errors that should be caught:
5708         # - If multiple paths are provided, all should be searched even if one
5709         #   errors out
5710         # - If errors are encountered during the search, it should not terminate
5711         #   early
5712         local dir=$DIR/$tdir
5713         local i
5714
5715         test_mkdir $dir
5716         for i in d{0..9}; do
5717                 test_mkdir $dir/$i
5718         done
5719         touch $dir/d{0..9}/$tfile
5720         $LFS find $DIR/non_existent_dir $dir &&
5721                 error "$LFS find did not return an error"
5722         # Make a directory unsearchable. This should NOT be the last entry in
5723         # directory order.  Arbitrarily pick the 6th entry
5724         chmod 700 $($LFS find $dir -type d | sed '6!d')
5725
5726         local count=$($RUNAS $LFS find $DIR/non_existent $dir | wc -l)
5727
5728         # The user should be able to see 10 directories and 9 files
5729         [ $count == 19 ] || error "$LFS find did not continue after error"
5730 }
5731 run_test 56z "lfs find should continue after an error"
5732
5733 test_56aa() { # LU-5937
5734         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5735
5736         local dir=$DIR/$tdir
5737
5738         mkdir $dir
5739         $LFS setdirstripe -c$MDSCOUNT $dir/striped_dir
5740
5741         createmany -o $dir/striped_dir/${tfile}- 1024
5742         local dirs=$($LFS find --size +8k $dir/)
5743
5744         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5745 }
5746 run_test 56aa "lfs find --size under striped dir"
5747
5748 test_56ab() { # LU-10705
5749         test_mkdir $DIR/$tdir
5750         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=8k count=1 seek=2k
5751         dd if=/dev/zero of=$DIR/$tdir/$tfile.2 bs=4k count=1 seek=4k
5752         dd if=/dev/zero of=$DIR/$tdir/$tfile.3 bs=1M count=2 seek=16
5753         # Flush writes to ensure valid blocks.  Need to be more thorough for
5754         # ZFS, since blocks are not allocated/returned to client immediately.
5755         sync_all_data
5756         wait_zfs_commit ost1 2
5757         cancel_lru_locks osc
5758         ls -ls $DIR/$tdir
5759
5760         local files=$($LFS find --size +16M $DIR/$tdir | wc -l)
5761
5762         [[ $files == 3 ]] || error ">16M size files $files isn't 3 as expected"
5763
5764         files=$($LFS find --blocks +1M $DIR/$tdir | wc -l)
5765         [[ $files == 1 ]] || error ">1M blocks files $files isn't 1 as expected"
5766
5767         rm -f $DIR/$tdir/$tfile.[123]
5768 }
5769 run_test 56ab "lfs find --blocks"
5770
5771 test_56ba() {
5772         # Create composite files with one component
5773         local dir=$DIR/$tdir
5774
5775         setup_56 $dir/1Mfiles 5 1 "-S 1M --component-end 1M"
5776         # Create composite files with three components
5777         setup_56 $dir/2Mfiles 5 2 "-E 2M -S 1M -E 4M -E 6M"
5778         # Create non-composite files
5779         createmany -o $dir/${tfile}- 10
5780
5781         local nfiles=$($LFS find --component-end 1M --type f $dir | wc -l)
5782
5783         [[ $nfiles == 10 ]] ||
5784                 error "lfs find -E 1M found $nfiles != 10 files"
5785
5786         nfiles=$($LFS find ! -E 1M --type f $dir | wc -l)
5787         [[ $nfiles == 25 ]] ||
5788                 error "lfs find ! -E 1M found $nfiles != 25 files"
5789
5790         # All files have a component that starts at 0
5791         nfiles=$($LFS find --component-start 0 --type f $dir | wc -l)
5792         [[ $nfiles == 35 ]] ||
5793                 error "lfs find --component-start 0 - $nfiles != 35 files"
5794
5795         nfiles=$($LFS find --component-start 2M --type f $dir | wc -l)
5796         [[ $nfiles == 15 ]] ||
5797                 error "lfs find --component-start 2M - $nfiles != 15 files"
5798
5799         # All files created here have a componenet that does not starts at 2M
5800         nfiles=$($LFS find ! --component-start 2M --type f $dir | wc -l)
5801         [[ $nfiles == 35 ]] ||
5802                 error "lfs find ! --component-start 2M - $nfiles != 35 files"
5803
5804         # Find files with a specified number of components
5805         local nfiles=$($LFS find --component-count 3 --type f $dir | wc -l)
5806         [[ $nfiles == 15 ]] ||
5807                 error "lfs find --component-count 3 - $nfiles != 15 files"
5808
5809         # Remember non-composite files have a component count of zero
5810         local nfiles=$($LFS find --component-count 0 --type f $dir | wc -l)
5811         [[ $nfiles == 10 ]] ||
5812                 error "lfs find --component-count 0 - $nfiles != 10 files"
5813
5814         nfiles=$($LFS find ! --component-count 3 --type f $dir | wc -l)
5815         [[ $nfiles == 20 ]] ||
5816                 error "lfs find ! --component-count 3 - $nfiles != 20 files"
5817
5818         # All files have a flag called "init"
5819         local nfiles=$($LFS find --component-flags init --type f $dir | wc -l)
5820         [[ $nfiles == 35 ]] ||
5821                 error "lfs find --component-flags init - $nfiles != 35 files"
5822
5823         # Multi-component files will have a component not initialized
5824         local nfiles=$($LFS find ! --component-flags init --type f $dir | wc -l)
5825         [[ $nfiles == 15 ]] ||
5826                 error "lfs find !--component-flags init - $nfiles != 15 files"
5827
5828         rm -rf $dir
5829
5830 }
5831 run_test 56ba "test lfs find --component-end, -start, -count, and -flags"
5832
5833 test_56ca() {
5834         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
5835                 { skip "Need MDS version at least 2.10.57"; return 0; }
5836
5837         local td=$DIR/$tdir
5838         local tf=$td/$tfile
5839         local dir
5840         local nfiles
5841         local cmd
5842         local i
5843         local j
5844
5845         # create mirrored directories and mirrored files
5846         mkdir $td || error "mkdir $td failed"
5847         $LFS mirror create -N3 $td || error "create mirrored dir $td failed"
5848         createmany -o $tf- 10 || error "create $tf- failed"
5849
5850         for i in $(seq 2); do
5851                 dir=$td/dir$i
5852                 mkdir $dir || error "mkdir $dir failed"
5853                 $LFS mirror create -N$((3 + i)) $dir ||
5854                         error "create mirrored dir $dir failed"
5855                 createmany -o $dir/$tfile- 10 ||
5856                         error "create $dir/$tfile- failed"
5857         done
5858
5859         # change the states of some mirrored files
5860         echo foo > $tf-6
5861         for i in $(seq 2); do
5862                 dir=$td/dir$i
5863                 for j in $(seq 4 9); do
5864                         echo foo > $dir/$tfile-$j
5865                 done
5866         done
5867
5868         # find mirrored files with specific mirror count
5869         cmd="$LFS find --mirror-count 3 --type f $td"
5870         nfiles=$($cmd | wc -l)
5871         [[ $nfiles = 10 ]] || error "$cmd: $nfiles != 10 files"
5872
5873         cmd="$LFS find ! --mirror-count 3 --type f $td"
5874         nfiles=$($cmd | wc -l)
5875         [[ $nfiles = 20 ]] || error "$cmd: $nfiles != 20 files"
5876
5877         cmd="$LFS find --mirror-count +2 --type f $td"
5878         nfiles=$($cmd | wc -l)
5879         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
5880
5881         cmd="$LFS find --mirror-count -6 --type f $td"
5882         nfiles=$($cmd | wc -l)
5883         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
5884
5885         # find mirrored files with specific file state
5886         cmd="$LFS find --maxdepth 1 --mirror-state=^ro --type f $td"
5887         [[ $($cmd) = $tf-6 ]] || error "$cmd: didn't return $tf-6"
5888
5889         cmd="$LFS find --mirror-state=ro --type f $td"
5890         nfiles=$($cmd | wc -l)
5891         [[ $nfiles = 17 ]] || error "$cmd: $nfiles != 17 files"
5892
5893         cmd="$LFS find ! --mirror-state=ro --type f $td"
5894         nfiles=$($cmd | wc -l)
5895         [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
5896
5897         cmd="$LFS find --mirror-state=wp --type f $td"
5898         nfiles=$($cmd | wc -l)
5899         [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
5900
5901         cmd="$LFS find ! --mirror-state=sp --type f $td"
5902         nfiles=$($cmd | wc -l)
5903         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
5904 }
5905 run_test 56ca "check lfs find --mirror-count|-N and --mirror-state"
5906
5907 test_57a() {
5908         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5909         # note test will not do anything if MDS is not local
5910         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5911                 skip "ldiskfs only test"
5912                 return
5913         fi
5914
5915         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5916         local MNTDEV="osd*.*MDT*.mntdev"
5917         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5918         [ -z "$DEV" ] && error "can't access $MNTDEV"
5919         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5920                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5921                         error "can't access $DEV"
5922                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5923                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5924                 rm $TMP/t57a.dump
5925         done
5926 }
5927 run_test 57a "verify MDS filesystem created with large inodes =="
5928
5929 test_57b() {
5930         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5931         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5932                 skip "ldiskfs only test"
5933                 return
5934         fi
5935
5936         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5937         local dir=$DIR/$tdir
5938
5939         local FILECOUNT=100
5940         local FILE1=$dir/f1
5941         local FILEN=$dir/f$FILECOUNT
5942
5943         rm -rf $dir || error "removing $dir"
5944         test_mkdir -c1 $dir
5945         local mdtidx=$($LFS getstripe -M $dir)
5946         local mdtname=MDT$(printf %04x $mdtidx)
5947         local facet=mds$((mdtidx + 1))
5948
5949         echo "mcreating $FILECOUNT files"
5950         createmany -m $dir/f 1 $FILECOUNT || \
5951                 error "creating files in $dir"
5952
5953         # verify that files do not have EAs yet
5954         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5955         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5956
5957         sync
5958         sleep 1
5959         df $dir  #make sure we get new statfs data
5960         local MDSFREE=$(do_facet $facet \
5961                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5962         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5963         echo "opening files to create objects/EAs"
5964         local FILE
5965         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5966                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5967         done
5968
5969         # verify that files have EAs now
5970         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5971         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5972
5973         sleep 1  #make sure we get new statfs data
5974         df $dir
5975         local MDSFREE2=$(do_facet $facet \
5976                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5977         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5978         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5979                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5980                         error "MDC before $MDCFREE != after $MDCFREE2"
5981                 else
5982                         echo "MDC before $MDCFREE != after $MDCFREE2"
5983                         echo "unable to confirm if MDS has large inodes"
5984                 fi
5985         fi
5986         rm -rf $dir
5987 }
5988 run_test 57b "default LOV EAs are stored inside large inodes ==="
5989
5990 test_58() {
5991         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5992         [ -z "$(which wiretest 2>/dev/null)" ] &&
5993                         skip_env "could not find wiretest" && return
5994         wiretest
5995 }
5996 run_test 58 "verify cross-platform wire constants =============="
5997
5998 test_59() {
5999         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6000         echo "touch 130 files"
6001         createmany -o $DIR/f59- 130
6002         echo "rm 130 files"
6003         unlinkmany $DIR/f59- 130
6004         sync
6005         # wait for commitment of removal
6006         wait_delete_completed
6007 }
6008 run_test 59 "verify cancellation of llog records async ========="
6009
6010 TEST60_HEAD="test_60 run $RANDOM"
6011 test_60a() {
6012         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6013         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6014         do_facet mgs "! which run-llog.sh &> /dev/null" &&
6015                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
6016                         skip_env "missing subtest run-llog.sh" && return
6017
6018         log "$TEST60_HEAD - from kernel mode"
6019         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
6020         do_facet mgs "sh run-llog.sh" || error "run-llog.sh failed"
6021         do_facet mgs $LCTL dk > $TMP/$tfile
6022
6023         # LU-6388: test llog_reader
6024         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
6025         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
6026         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
6027                         skip_env "missing llog_reader" && return
6028         local fstype=$(facet_fstype mgs)
6029         [ $fstype != ldiskfs -a $fstype != zfs ] &&
6030                 skip_env "Only for ldiskfs or zfs type mgs" && return
6031
6032         local mntpt=$(facet_mntpt mgs)
6033         local mgsdev=$(mgsdevname 1)
6034         local fid_list
6035         local fid
6036         local rec_list
6037         local rec
6038         local rec_type
6039         local obj_file
6040         local path
6041         local seq
6042         local oid
6043         local pass=true
6044
6045         #get fid and record list
6046         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
6047                 tail -n 4))
6048         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
6049                 tail -n 4))
6050         #remount mgs as ldiskfs or zfs type
6051         stop mgs || error "stop mgs failed"
6052         mount_fstype mgs || error "remount mgs failed"
6053         for ((i = 0; i < ${#fid_list[@]}; i++)); do
6054                 fid=${fid_list[i]}
6055                 rec=${rec_list[i]}
6056                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
6057                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
6058                 oid=$((16#$oid))
6059
6060                 case $fstype in
6061                         ldiskfs )
6062                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
6063                         zfs )
6064                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
6065                 esac
6066                 echo "obj_file is $obj_file"
6067                 do_facet mgs $llog_reader $obj_file
6068
6069                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
6070                         awk '{ print $3 }' | sed -e "s/^type=//g")
6071                 if [ $rec_type != $rec ]; then
6072                         echo "FAILED test_60a wrong record type $rec_type," \
6073                               "should be $rec"
6074                         pass=false
6075                         break
6076                 fi
6077
6078                 #check obj path if record type is LLOG_LOGID_MAGIC
6079                 if [ "$rec" == "1064553b" ]; then
6080                         path=$(do_facet mgs $llog_reader $obj_file |
6081                                 grep "path=" | awk '{ print $NF }' |
6082                                 sed -e "s/^path=//g")
6083                         if [ $obj_file != $mntpt/$path ]; then
6084                                 echo "FAILED test_60a wrong obj path" \
6085                                       "$montpt/$path, should be $obj_file"
6086                                 pass=false
6087                                 break
6088                         fi
6089                 fi
6090         done
6091         rm -f $TMP/$tfile
6092         #restart mgs before "error", otherwise it will block the next test
6093         stop mgs || error "stop mgs failed"
6094         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
6095         $pass || error "test failed, see FAILED test_60a messages for specifics"
6096 }
6097 run_test 60a "llog_test run from kernel module and test llog_reader"
6098
6099 test_60aa() {
6100         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
6101
6102         # test old logid format
6103         if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
6104                 do_facet mgs $LCTL dl | grep MGS
6105                 do_facet mgs "$LCTL --device %MGS llog_print \\\\\\\$$FSNAME-client" ||
6106                         error "old llog_print failed"
6107         fi
6108
6109         # test new logid format
6110         if [ $(lustre_version_code mgs) -ge $(version_code 2.9.53) ]; then
6111                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
6112                         error "new llog_print failed"
6113         fi
6114 }
6115 run_test 60aa "llog_print works with FIDs and simple names"
6116
6117 test_60b() { # bug 6411
6118         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6119         dmesg > $DIR/$tfile
6120         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
6121                                 /llog.test/ {
6122                                         if (marker)
6123                                                 from_marker++
6124                                         from_begin++
6125                                 }
6126                                 END {
6127                                         if (marker)
6128                                                 print from_marker
6129                                         else
6130                                                 print from_begin
6131                                 }")
6132         [[ $LLOG_COUNT -gt 100 ]] &&
6133                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
6134 }
6135 run_test 60b "limit repeated messages from CERROR/CWARN ========"
6136
6137 test_60c() {
6138         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6139         echo "create 5000 files"
6140         createmany -o $DIR/f60c- 5000
6141 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
6142         lctl set_param fail_loc=0x80000137
6143         unlinkmany $DIR/f60c- 5000
6144         lctl set_param fail_loc=0
6145 }
6146 run_test 60c "unlink file when mds full"
6147
6148 test_60d() {
6149         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6150         SAVEPRINTK=$(lctl get_param -n printk)
6151
6152         # verify "lctl mark" is even working"
6153         MESSAGE="test message ID $RANDOM $$"
6154         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
6155         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
6156
6157         lctl set_param printk=0 || error "set lnet.printk failed"
6158         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
6159         MESSAGE="new test message ID $RANDOM $$"
6160         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
6161         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
6162         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
6163
6164         lctl set_param -n printk="$SAVEPRINTK"
6165 }
6166 run_test 60d "test printk console message masking"
6167
6168 test_60e() {
6169         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6170         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6171         touch $DIR/$tfile
6172 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
6173         do_facet mds1 lctl set_param fail_loc=0x15b
6174         rm $DIR/$tfile
6175 }
6176 run_test 60e "no space while new llog is being created"
6177
6178 test_61() {
6179         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6180         f="$DIR/f61"
6181         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
6182         cancel_lru_locks osc
6183         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
6184         sync
6185 }
6186 run_test 61 "mmap() writes don't make sync hang ================"
6187
6188 # bug 2330 - insufficient obd_match error checking causes LBUG
6189 test_62() {
6190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6191         f="$DIR/f62"
6192         echo foo > $f
6193         cancel_lru_locks osc
6194         lctl set_param fail_loc=0x405
6195         cat $f && error "cat succeeded, expect -EIO"
6196         lctl set_param fail_loc=0
6197 }
6198 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
6199 # match every page all of the time.
6200 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
6201
6202 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
6203 # Though this test is irrelevant anymore, it helped to reveal some
6204 # other grant bugs (LU-4482), let's keep it.
6205 test_63a() {   # was test_63
6206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6207         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
6208         for i in `seq 10` ; do
6209                 dd if=/dev/zero of=$DIR/f63 bs=8k &
6210                 sleep 5
6211                 kill $!
6212                 sleep 1
6213         done
6214
6215         rm -f $DIR/f63 || true
6216 }
6217 run_test 63a "Verify oig_wait interruption does not crash ======="
6218
6219 # bug 2248 - async write errors didn't return to application on sync
6220 # bug 3677 - async write errors left page locked
6221 test_63b() {
6222         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6223         debugsave
6224         lctl set_param debug=-1
6225
6226         # ensure we have a grant to do async writes
6227         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
6228         rm $DIR/$tfile
6229
6230         sync    # sync lest earlier test intercept the fail_loc
6231
6232         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
6233         lctl set_param fail_loc=0x80000406
6234         $MULTIOP $DIR/$tfile Owy && \
6235                 error "sync didn't return ENOMEM"
6236         sync; sleep 2; sync     # do a real sync this time to flush page
6237         lctl get_param -n llite.*.dump_page_cache | grep locked && \
6238                 error "locked page left in cache after async error" || true
6239         debugrestore
6240 }
6241 run_test 63b "async write errors should be returned to fsync ==="
6242
6243 test_64a () {
6244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6245         df $DIR
6246         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
6247 }
6248 run_test 64a "verify filter grant calculations (in kernel) ====="
6249
6250 test_64b () {
6251         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6252         sh oos.sh $MOUNT || error "oos.sh failed: $?"
6253 }
6254 run_test 64b "check out-of-space detection on client"
6255
6256 test_64c() {
6257         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
6258 }
6259 run_test 64c "verify grant shrink"
6260
6261 # this does exactly what osc_request.c:osc_announce_cached() does in
6262 # order to calculate max amount of grants to ask from server
6263 want_grant() {
6264         local tgt=$1
6265
6266         local page_size=$(get_page_size client)
6267
6268         local nrpages=$($LCTL get_param -n osc.${tgt}.max_pages_per_rpc)
6269         local rpc_in_flight=$($LCTL get_param -n osc.${tgt}.max_rpcs_in_flight)
6270
6271         ((rpc_in_flight ++));
6272         nrpages=$((nrpages * rpc_in_flight))
6273
6274         local dirty_max_pages=$($LCTL get_param -n osc.${tgt}.max_dirty_mb)
6275
6276         dirty_max_pages=$((dirty_max_pages * 1024 * 1024 / page_size))
6277
6278         [[ $dirty_max_pages -gt $nrpages ]] && nrpages=$dirty_max_pages
6279         local undirty=$((nrpages * page_size))
6280
6281         local max_extent_pages
6282         max_extent_pages=$($LCTL get_param osc.${tgt}.import |
6283             grep grant_max_extent_size | awk '{print $2}')
6284         max_extent_pages=$((max_extent_pages / page_size))
6285         local nrextents=$(((nrpages + max_extent_pages - 1) / max_extent_pages))
6286         local grant_extent_tax
6287         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
6288             grep grant_extent_tax | awk '{print $2}')
6289
6290         undirty=$((undirty + nrextents * grant_extent_tax))
6291
6292         echo $undirty
6293 }
6294
6295 # this is size of unit for grant allocation. It should be equal to
6296 # what tgt_grant.c:tgt_grant_chunk() calculates
6297 grant_chunk() {
6298         local tgt=$1
6299         local max_brw_size
6300         local grant_extent_tax
6301
6302         max_brw_size=$($LCTL get_param osc.${tgt}.import |
6303             grep max_brw_size | awk '{print $2}')
6304
6305         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
6306             grep grant_extent_tax | awk '{print $2}')
6307
6308         echo $(((max_brw_size + grant_extent_tax) * 2))
6309 }
6310
6311 test_64d() {
6312         [ $(lustre_version_code ost1) -lt $(version_code 2.10.56) ] &&
6313                 skip "OST < 2.10.55 doesn't limit grants enough" && return 0
6314
6315         local tgt=$($LCTL dl | grep "0000-osc-[^mM]" | awk '{print $4}')
6316         local file=$DIR/$tfile
6317
6318         [[ $($LCTL get_param osc.${tgt}.import |
6319                     grep "connect_flags:.*grant_param") ]] || \
6320                         { skip "no grant_param connect flag"; return; }
6321
6322         local olddebug=$($LCTL get_param -n debug 2> /dev/null)
6323
6324         $LCTL set_param debug="$OLDDEBUG" 2> /dev/null || true
6325
6326         local max_cur_granted=$(($(want_grant $tgt) + $(grant_chunk $tgt)))
6327         stack_trap "rm -f $file" EXIT
6328
6329         $SETSTRIPE $file -i 0 -c 1
6330         dd if=/dev/zero of=$file bs=1M count=1000 &
6331         ddpid=$!
6332
6333         while true
6334         do
6335                 local cur_grant=$($LCTL get_param -n osc.${tgt}.cur_grant_bytes)
6336                 if [[ $cur_grant -gt $max_cur_granted ]]
6337                 then
6338                         kill $ddpid
6339                         error "cur_grant $cur_grant > $max_cur_granted"
6340                 fi
6341                 kill -0 $ddpid
6342                 [[ $? -ne 0 ]] && break;
6343                 sleep 2
6344         done
6345
6346         rm -f $DIR/$tfile
6347         wait_delete_completed
6348         $LCTL set_param debug="$olddebug" 2> /dev/null || true
6349 }
6350 run_test 64d "check grant limit exceed"
6351
6352 # bug 1414 - set/get directories' stripe info
6353 test_65a() {
6354         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6355         test_mkdir $DIR/$tdir
6356         touch $DIR/$tdir/f1
6357         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
6358 }
6359 run_test 65a "directory with no stripe info"
6360
6361 test_65b() {
6362         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6363         test_mkdir $DIR/$tdir
6364         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
6365
6366         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
6367                                                 error "setstripe"
6368         touch $DIR/$tdir/f2
6369         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
6370 }
6371 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
6372
6373 test_65c() {
6374         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6375         [ $OSTCOUNT -lt 2 ] && skip "need at least 2 OSTs" && return
6376         test_mkdir $DIR/$tdir
6377         local stripesize=$($GETSTRIPE -S $DIR/$tdir)
6378
6379         $LFS setstripe -S $((stripesize * 4)) -i 1 \
6380                 -c $((OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
6381         touch $DIR/$tdir/f3
6382         $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
6383 }
6384 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
6385
6386 test_65d() {
6387         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6388         test_mkdir $DIR/$tdir
6389         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
6390         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
6391
6392         if [[ $STRIPECOUNT -le 0 ]]; then
6393                 sc=1
6394         elif [[ $STRIPECOUNT -gt 2000 ]]; then
6395 #LOV_MAX_STRIPE_COUNT is 2000
6396                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
6397         else
6398                 sc=$(($STRIPECOUNT - 1))
6399         fi
6400         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
6401         touch $DIR/$tdir/f4 $DIR/$tdir/f5
6402         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
6403                 error "lverify failed"
6404 }
6405 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
6406
6407 test_65e() {
6408         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6409         test_mkdir $DIR/$tdir
6410
6411         $SETSTRIPE $DIR/$tdir || error "setstripe"
6412         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
6413                                         error "no stripe info failed"
6414         touch $DIR/$tdir/f6
6415         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
6416 }
6417 run_test 65e "directory setstripe defaults"
6418
6419 test_65f() {
6420         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6421         test_mkdir $DIR/${tdir}f
6422         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
6423 }
6424 run_test 65f "dir setstripe permission (should return error) ==="
6425
6426 test_65g() {
6427         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6428         test_mkdir $DIR/$tdir
6429         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
6430
6431         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
6432                 error "setstripe -S failed"
6433         $LFS setstripe -d $DIR/$tdir || error "setstripe -d failed"
6434         $LFS getstripe -v $DIR/$tdir | grep "Default" ||
6435                 error "delete default stripe failed"
6436 }
6437 run_test 65g "directory setstripe -d"
6438
6439 test_65h() {
6440         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6441         test_mkdir $DIR/$tdir
6442         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
6443
6444         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
6445                 error "setstripe -S failed"
6446         test_mkdir $DIR/$tdir/dd1
6447         [ $($LFS getstripe -c $DIR/$tdir) = $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
6448                 error "stripe info inherit failed"
6449 }
6450 run_test 65h "directory stripe info inherit ===================="
6451
6452 test_65i() {
6453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6454
6455         save_layout_restore_at_exit $MOUNT
6456
6457         # bug6367: set non-default striping on root directory
6458         $LFS setstripe -S 65536 -c -1 $MOUNT || error "error setting stripe"
6459
6460         # bug12836: getstripe on -1 default directory striping
6461         $LFS getstripe $MOUNT || error "getstripe $MOUNT failed"
6462
6463         # bug12836: getstripe -v on -1 default directory striping
6464         $LFS getstripe -v $MOUNT || error "getstripe -v $MOUNT failed"
6465
6466         # bug12836: new find on -1 default directory striping
6467         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
6468 }
6469 run_test 65i "various tests to set root directory striping"
6470
6471 test_65j() { # bug6367
6472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6473
6474         sync; sleep 1
6475
6476         # if we aren't already remounting for each test, do so for this test
6477         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
6478                 cleanup || error "failed to unmount"
6479                 setup
6480         fi
6481
6482         save_layout_restore_at_exit $MOUNT
6483
6484         $SETSTRIPE -d $MOUNT || error "setstripe failed"
6485 }
6486 run_test 65j "set default striping on root directory (bug 6367)="
6487
6488 cleaup_65k() {
6489         rm -rf $DIR/$tdir
6490         wait_delete_completed
6491         do_facet $SINGLEMDS "lctl set_param -n \
6492                 osp.$ost*MDT0000.max_create_count=$max_count"
6493         do_facet $SINGLEMDS "lctl set_param -n \
6494                 osp.$ost*MDT0000.create_count=$count"
6495         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
6496         echo $INACTIVE_OSC "is Activate"
6497
6498         wait_osc_import_state mds ost$ostnum FULL
6499 }
6500
6501 test_65k() { # bug11679
6502         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6503         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
6504         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6505
6506         local disable_precreate=true
6507         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.8.54) ] &&
6508                 disable_precreate=false
6509
6510         echo "Check OST status: "
6511         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
6512                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
6513
6514         for OSC in $MDS_OSCS; do
6515                 echo $OSC "is active"
6516                 do_facet $SINGLEMDS lctl --device %$OSC activate
6517         done
6518
6519         for INACTIVE_OSC in $MDS_OSCS; do
6520                 local ost=$(osc_to_ost $INACTIVE_OSC)
6521                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
6522                                lov.*md*.target_obd |
6523                                awk -F: /$ost/'{ print $1 }' | head -n 1)
6524
6525                 mkdir -p $DIR/$tdir
6526                 $SETSTRIPE -i $ostnum -c 1 $DIR/$tdir
6527                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
6528
6529                 echo "Deactivate: " $INACTIVE_OSC
6530                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
6531
6532                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
6533                               osp.$ost*MDT0000.create_count")
6534                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
6535                                   osp.$ost*MDT0000.max_create_count")
6536                 $disable_precreate &&
6537                         do_facet $SINGLEMDS "lctl set_param -n \
6538                                 osp.$ost*MDT0000.max_create_count=0"
6539
6540                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
6541                         [ -f $DIR/$tdir/$idx ] && continue
6542                         echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
6543                         $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
6544                                 { cleanup_65k;
6545                                   error "setstripe $idx should succeed"; }
6546                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
6547                 done
6548                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
6549                 rmdir $DIR/$tdir
6550
6551                 do_facet $SINGLEMDS "lctl set_param -n \
6552                         osp.$ost*MDT0000.max_create_count=$max_count"
6553                 do_facet $SINGLEMDS "lctl set_param -n \
6554                         osp.$ost*MDT0000.create_count=$count"
6555                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
6556                 echo $INACTIVE_OSC "is Activate"
6557
6558                 wait_osc_import_state mds ost$ostnum FULL
6559         done
6560 }
6561 run_test 65k "validate manual striping works properly with deactivated OSCs"
6562
6563 test_65l() { # bug 12836
6564         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6565         test_mkdir -p $DIR/$tdir/test_dir
6566         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
6567         $LFS find -mtime -1 $DIR/$tdir >/dev/null
6568 }
6569 run_test 65l "lfs find on -1 stripe dir ========================"
6570
6571 test_65m() {
6572         local layout=$(save_layout $MOUNT)
6573         $RUNAS $SETSTRIPE -c 2 $MOUNT && {
6574                 restore_layout $MOUNT $layout
6575                 error "setstripe should fail by non-root users"
6576         }
6577         true
6578 }
6579 run_test 65m "normal user can't set filesystem default stripe"
6580
6581 # bug 2543 - update blocks count on client
6582 test_66() {
6583         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6584         COUNT=${COUNT:-8}
6585         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
6586         sync; sync_all_data; sync; sync_all_data
6587         cancel_lru_locks osc
6588         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
6589         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
6590 }
6591 run_test 66 "update inode blocks count on client ==============="
6592
6593 meminfo() {
6594         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
6595 }
6596
6597 swap_used() {
6598         swapon -s | awk '($1 == "'$1'") { print $4 }'
6599 }
6600
6601 # bug5265, obdfilter oa2dentry return -ENOENT
6602 # #define OBD_FAIL_SRV_ENOENT 0x217
6603 test_69() {
6604         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6605         remote_ost_nodsh && skip "remote OST with nodsh" && return
6606
6607         f="$DIR/$tfile"
6608         $SETSTRIPE -c 1 -i 0 $f
6609
6610         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
6611
6612         do_facet ost1 lctl set_param fail_loc=0x217
6613         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
6614         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
6615
6616         do_facet ost1 lctl set_param fail_loc=0
6617         $DIRECTIO write $f 0 2 || error "write error"
6618
6619         cancel_lru_locks osc
6620         $DIRECTIO read $f 0 1 || error "read error"
6621
6622         do_facet ost1 lctl set_param fail_loc=0x217
6623         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
6624
6625         do_facet ost1 lctl set_param fail_loc=0
6626         rm -f $f
6627 }
6628 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
6629
6630 test_71() {
6631         test_mkdir $DIR/$tdir
6632         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
6633         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
6634 }
6635 run_test 71 "Running dbench on lustre (don't segment fault) ===="
6636
6637 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
6638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6639         [ "$RUNAS_ID" = "$UID" ] &&
6640                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6641
6642         # Check that testing environment is properly set up. Skip if not
6643         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
6644                 skip_env "User $RUNAS_ID does not exist - skipping"
6645                 return 0
6646         }
6647         touch $DIR/$tfile
6648         chmod 777 $DIR/$tfile
6649         chmod ug+s $DIR/$tfile
6650         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
6651                 error "$RUNAS dd $DIR/$tfile failed"
6652         # See if we are still setuid/sgid
6653         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6654                 error "S/gid is not dropped on write"
6655         # Now test that MDS is updated too
6656         cancel_lru_locks mdc
6657         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6658                 error "S/gid is not dropped on MDS"
6659         rm -f $DIR/$tfile
6660 }
6661 run_test 72a "Test that remove suid works properly (bug5695) ===="
6662
6663 test_72b() { # bug 24226 -- keep mode setting when size is not changing
6664         local perm
6665
6666         [ "$RUNAS_ID" = "$UID" ] && \
6667                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6668         [ "$RUNAS_ID" -eq 0 ] && \
6669                 skip_env "RUNAS_ID = 0 -- skipping" && return
6670
6671         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6672         # Check that testing environment is properly set up. Skip if not
6673         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
6674                 skip_env "User $RUNAS_ID does not exist - skipping"
6675                 return 0
6676         }
6677         touch $DIR/${tfile}-f{g,u}
6678         test_mkdir $DIR/${tfile}-dg
6679         test_mkdir $DIR/${tfile}-du
6680         chmod 770 $DIR/${tfile}-{f,d}{g,u}
6681         chmod g+s $DIR/${tfile}-{f,d}g
6682         chmod u+s $DIR/${tfile}-{f,d}u
6683         for perm in 777 2777 4777; do
6684                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
6685                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
6686                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
6687                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
6688         done
6689         true
6690 }
6691 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
6692
6693 # bug 3462 - multiple simultaneous MDC requests
6694 test_73() {
6695         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6696         test_mkdir $DIR/d73-1
6697         test_mkdir $DIR/d73-2
6698         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
6699         pid1=$!
6700
6701         lctl set_param fail_loc=0x80000129
6702         $MULTIOP $DIR/d73-1/f73-2 Oc &
6703         sleep 1
6704         lctl set_param fail_loc=0
6705
6706         $MULTIOP $DIR/d73-2/f73-3 Oc &
6707         pid3=$!
6708
6709         kill -USR1 $pid1
6710         wait $pid1 || return 1
6711
6712         sleep 25
6713
6714         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
6715         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
6716         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
6717
6718         rm -rf $DIR/d73-*
6719 }
6720 run_test 73 "multiple MDC requests (should not deadlock)"
6721
6722 test_74a() { # bug 6149, 6184
6723         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6724         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6725         #
6726         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6727         # will spin in a tight reconnection loop
6728         touch $DIR/f74a
6729         $LCTL set_param fail_loc=0x8000030e
6730         # get any lock that won't be difficult - lookup works.
6731         ls $DIR/f74a
6732         $LCTL set_param fail_loc=0
6733         rm -f $DIR/f74a
6734         true
6735 }
6736 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
6737
6738 test_74b() { # bug 13310
6739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6740         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6741         #
6742         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6743         # will spin in a tight reconnection loop
6744         $LCTL set_param fail_loc=0x8000030e
6745         # get a "difficult" lock
6746         touch $DIR/f74b
6747         $LCTL set_param fail_loc=0
6748         rm -f $DIR/f74b
6749         true
6750 }
6751 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
6752
6753 test_74c() {
6754         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6755         #define OBD_FAIL_LDLM_NEW_LOCK
6756         $LCTL set_param fail_loc=0x319
6757         touch $DIR/$tfile && error "touch successful"
6758         $LCTL set_param fail_loc=0
6759         true
6760 }
6761 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
6762
6763 num_inodes() {
6764         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
6765 }
6766
6767 test_76() { # Now for bug 20433, added originally in bug 1443
6768         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6769         local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
6770         cancel_lru_locks osc
6771         BEFORE_INODES=$(num_inodes)
6772         echo "before inodes: $BEFORE_INODES"
6773         local COUNT=1000
6774         [ "$SLOW" = "no" ] && COUNT=100
6775         for i in $(seq $COUNT); do
6776                 touch $DIR/$tfile
6777                 rm -f $DIR/$tfile
6778         done
6779         cancel_lru_locks osc
6780         AFTER_INODES=$(num_inodes)
6781         echo "after inodes: $AFTER_INODES"
6782         local wait=0
6783         while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
6784                 sleep 2
6785                 AFTER_INODES=$(num_inodes)
6786                 wait=$((wait+2))
6787                 echo "wait $wait seconds inodes: $AFTER_INODES"
6788                 if [ $wait -gt 30 ]; then
6789                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
6790                 fi
6791         done
6792 }
6793 run_test 76 "confirm clients recycle inodes properly ===="
6794
6795
6796 export ORIG_CSUM=""
6797 set_checksums()
6798 {
6799         # Note: in sptlrpc modes which enable its own bulk checksum, the
6800         # original crc32_le bulk checksum will be automatically disabled,
6801         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
6802         # will be checked by sptlrpc code against sptlrpc bulk checksum.
6803         # In this case set_checksums() will not be no-op, because sptlrpc
6804         # bulk checksum will be enabled all through the test.
6805
6806         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
6807         lctl set_param -n osc.*.checksums $1
6808         return 0
6809 }
6810
6811 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6812                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
6813 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
6814 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
6815 set_checksum_type()
6816 {
6817         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
6818         log "set checksum type to $1"
6819         return 0
6820 }
6821 F77_TMP=$TMP/f77-temp
6822 F77SZ=8
6823 setup_f77() {
6824         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
6825                 error "error writing to $F77_TMP"
6826 }
6827
6828 test_77a() { # bug 10889
6829         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6830         $GSS && skip "could not run with gss" && return
6831         [ ! -f $F77_TMP ] && setup_f77
6832         set_checksums 1
6833         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
6834         set_checksums 0
6835         rm -f $DIR/$tfile
6836 }
6837 run_test 77a "normal checksum read/write operation"
6838
6839 test_77b() { # bug 10889
6840         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6841         $GSS && skip "could not run with gss" && return
6842         [ ! -f $F77_TMP ] && setup_f77
6843         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6844         $LCTL set_param fail_loc=0x80000409
6845         set_checksums 1
6846
6847         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6848                 error "dd error: $?"
6849         $LCTL set_param fail_loc=0
6850
6851         for algo in $CKSUM_TYPES; do
6852                 cancel_lru_locks osc
6853                 set_checksum_type $algo
6854                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6855                 $LCTL set_param fail_loc=0x80000408
6856                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6857                 $LCTL set_param fail_loc=0
6858         done
6859         set_checksums 0
6860         set_checksum_type $ORIG_CSUM_TYPE
6861         rm -f $DIR/$tfile
6862 }
6863 run_test 77b "checksum error on client write, read"
6864
6865 cleanup_77c() {
6866         trap 0
6867         set_checksums 0
6868         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
6869         $check_ost &&
6870                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
6871         [ -n $osc_file_prefix ] && rm -f ${osc_file_prefix}*
6872         $check_ost && [ -n $ost_file_prefix ] &&
6873                 do_facet ost1 rm -f ${ost_file_prefix}\*
6874 }
6875
6876 test_77c() {
6877         remote_ost_nodsh && skip "remote OST with nodsh" && return
6878
6879         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6880         $GSS && skip "could not run with gss" && return
6881
6882         local bad1
6883         local osc_file_prefix
6884         local osc_file
6885         local check_ost=false
6886         local ost_file_prefix
6887         local ost_file
6888         local orig_cksum
6889         local dump_cksum
6890         local fid
6891
6892         # ensure corruption will occur on first OSS/OST
6893         $LFS setstripe -i 0 $DIR/$tfile
6894
6895         [ ! -f $F77_TMP ] && setup_f77
6896         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6897                 error "dd write error: $?"
6898         fid=$($LFS path2fid $DIR/$tfile)
6899
6900         if [ $(lustre_version_code ost1) -ge $(version_code 2.9.57) ]
6901         then
6902                 check_ost=true
6903                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
6904                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
6905         else
6906                 echo "OSS do not support bulk pages dump upon error"
6907         fi
6908
6909         osc_file_prefix=$($LCTL get_param -n debug_path)
6910         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
6911
6912         trap cleanup_77c EXIT
6913
6914         set_checksums 1
6915         # enable bulk pages dump upon error on Client
6916         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
6917         # enable bulk pages dump upon error on OSS
6918         $check_ost &&
6919                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
6920
6921         # flush Client cache to allow next read to reach OSS
6922         cancel_lru_locks osc
6923
6924         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
6925         $LCTL set_param fail_loc=0x80000408
6926         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
6927         $LCTL set_param fail_loc=0
6928
6929         rm -f $DIR/$tfile
6930
6931         # check cksum dump on Client
6932         osc_file=$(ls ${osc_file_prefix}*)
6933         [ -n "$osc_file" ] || error "no checksum dump file on Client"
6934         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
6935         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
6936         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
6937         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
6938                      cksum)
6939         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
6940         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6941                 error "dump content does not match on Client"
6942
6943         $check_ost || { skip "No need to check cksum dump on OSS"; return 0; }
6944
6945         # check cksum dump on OSS
6946         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
6947         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
6948         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
6949         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
6950         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6951                 error "dump content does not match on OSS"
6952
6953         cleanup_77c
6954 }
6955 run_test 77c "checksum error on client read with debug"
6956
6957 test_77d() { # bug 10889
6958         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6959         $GSS && skip "could not run with gss" && return
6960         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6961         $LCTL set_param fail_loc=0x80000409
6962         set_checksums 1
6963         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6964                 error "direct write: rc=$?"
6965         $LCTL set_param fail_loc=0
6966         set_checksums 0
6967
6968         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6969         $LCTL set_param fail_loc=0x80000408
6970         set_checksums 1
6971         cancel_lru_locks osc
6972         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6973                 error "direct read: rc=$?"
6974         $LCTL set_param fail_loc=0
6975         set_checksums 0
6976 }
6977 run_test 77d "checksum error on OST direct write, read"
6978
6979 test_77f() { # bug 10889
6980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6981         $GSS && skip "could not run with gss" && return
6982         set_checksums 1
6983         for algo in $CKSUM_TYPES; do
6984                 cancel_lru_locks osc
6985                 set_checksum_type $algo
6986                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6987                 $LCTL set_param fail_loc=0x409
6988                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
6989                         error "direct write succeeded"
6990                 $LCTL set_param fail_loc=0
6991         done
6992         set_checksum_type $ORIG_CSUM_TYPE
6993         set_checksums 0
6994 }
6995 run_test 77f "repeat checksum error on write (expect error)"
6996
6997 test_77g() { # bug 10889
6998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6999         $GSS && skip "could not run with gss" && return
7000         remote_ost_nodsh && skip "remote OST with nodsh" && return
7001
7002         [ ! -f $F77_TMP ] && setup_f77
7003
7004         local file=$DIR/$tfile
7005         stack_trap "rm -f $file" EXIT
7006
7007         $SETSTRIPE -c 1 -i 0 $file
7008         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
7009         do_facet ost1 lctl set_param fail_loc=0x8000021a
7010         set_checksums 1
7011         dd if=$F77_TMP of=$file bs=1M count=$F77SZ ||
7012                 error "write error: rc=$?"
7013         do_facet ost1 lctl set_param fail_loc=0
7014         set_checksums 0
7015
7016         cancel_lru_locks osc
7017         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
7018         do_facet ost1 lctl set_param fail_loc=0x8000021b
7019         set_checksums 1
7020         cmp $F77_TMP $file || error "file compare failed"
7021         do_facet ost1 lctl set_param fail_loc=0
7022         set_checksums 0
7023 }
7024 run_test 77g "checksum error on OST write, read"
7025
7026 test_77j() { # bug 13805
7027         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7028         $GSS && skip "could not run with gss" && return
7029         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
7030         lctl set_param fail_loc=0x40c
7031         remount_client $MOUNT
7032         lctl set_param fail_loc=0
7033         # wait async osc connect to finish and reflect updated state value
7034         local i
7035         for (( i=0; i < OSTCOUNT; i++ )) ; do
7036                 wait_osc_import_state client ost$((i+1)) FULL
7037         done
7038
7039         for VALUE in $(lctl get_param osc.*osc-[^mM]*.checksum_type); do
7040                 PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
7041                 algo=$(lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g')
7042                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
7043         done
7044         remount_client $MOUNT
7045 }
7046 run_test 77j "client only supporting ADLER32"
7047
7048 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
7049 rm -f $F77_TMP
7050 unset F77_TMP
7051
7052 cleanup_test_78() {
7053         trap 0
7054         rm -f $DIR/$tfile
7055 }
7056
7057 test_78() { # bug 10901
7058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7059         remote_ost || { skip_env "local OST" && return; }
7060
7061         NSEQ=5
7062         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
7063         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
7064         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
7065         echo "MemTotal: $MEMTOTAL"
7066
7067         # reserve 256MB of memory for the kernel and other running processes,
7068         # and then take 1/2 of the remaining memory for the read/write buffers.
7069         if [ $MEMTOTAL -gt 512 ] ;then
7070                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
7071         else
7072                 # for those poor memory-starved high-end clusters...
7073                 MEMTOTAL=$((MEMTOTAL / 2))
7074         fi
7075         echo "Mem to use for directio: $MEMTOTAL"
7076
7077         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
7078         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
7079         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
7080         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
7081                 head -n1)
7082         echo "Smallest OST: $SMALLESTOST"
7083         [[ $SMALLESTOST -lt 10240 ]] &&
7084                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
7085
7086         trap cleanup_test_78 EXIT
7087
7088         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
7089                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
7090
7091         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
7092         echo "File size: $F78SIZE"
7093         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
7094         for i in $(seq 1 $NSEQ); do
7095                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
7096                 echo directIO rdwr round $i of $NSEQ
7097                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
7098         done
7099
7100         cleanup_test_78
7101 }
7102 run_test 78 "handle large O_DIRECT writes correctly ============"
7103
7104 test_79() { # bug 12743
7105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7106         wait_delete_completed
7107
7108         BKTOTAL=$(calc_osc_kbytes kbytestotal)
7109         BKFREE=$(calc_osc_kbytes kbytesfree)
7110         BKAVAIL=$(calc_osc_kbytes kbytesavail)
7111
7112         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
7113         DFTOTAL=`echo $STRING | cut -d, -f1`
7114         DFUSED=`echo $STRING  | cut -d, -f2`
7115         DFAVAIL=`echo $STRING | cut -d, -f3`
7116         DFFREE=$(($DFTOTAL - $DFUSED))
7117
7118         ALLOWANCE=$((64 * $OSTCOUNT))
7119
7120         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
7121            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
7122                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
7123         fi
7124         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
7125            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
7126                 error "df free($DFFREE) mismatch OST free($BKFREE)"
7127         fi
7128         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
7129            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
7130                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
7131         fi
7132 }
7133 run_test 79 "df report consistency check ======================="
7134
7135 test_80() { # bug 10718
7136         remote_ost_nodsh && skip "remote OST with nodsh" && return
7137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7138         # relax strong synchronous semantics for slow backends like ZFS
7139         local soc="obdfilter.*.sync_on_lock_cancel"
7140         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
7141         local hosts=
7142         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
7143                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
7144                           facet_active_host $host; done | sort -u)
7145                 do_nodes $hosts lctl set_param $soc=never
7146         fi
7147
7148         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
7149         sync; sleep 1; sync
7150         local BEFORE=`date +%s`
7151         cancel_lru_locks osc
7152         local AFTER=`date +%s`
7153         local DIFF=$((AFTER-BEFORE))
7154         if [ $DIFF -gt 1 ] ; then
7155                 error "elapsed for 1M@1T = $DIFF"
7156         fi
7157
7158         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
7159
7160         rm -f $DIR/$tfile
7161 }
7162 run_test 80 "Page eviction is equally fast at high offsets too  ===="
7163
7164 test_81a() { # LU-456
7165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7166         remote_ost_nodsh && skip "remote OST with nodsh" && return
7167         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
7168         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
7169         do_facet ost1 lctl set_param fail_loc=0x80000228
7170
7171         # write should trigger a retry and success
7172         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
7173         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7174         RC=$?
7175         if [ $RC -ne 0 ] ; then
7176                 error "write should success, but failed for $RC"
7177         fi
7178 }
7179 run_test 81a "OST should retry write when get -ENOSPC ==============="
7180
7181 test_81b() { # LU-456
7182         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7183         remote_ost_nodsh && skip "remote OST with nodsh" && return
7184         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
7185         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
7186         do_facet ost1 lctl set_param fail_loc=0x228
7187
7188         # write should retry several times and return -ENOSPC finally
7189         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
7190         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7191         RC=$?
7192         ENOSPC=28
7193         if [ $RC -ne $ENOSPC ] ; then
7194                 error "dd should fail for -ENOSPC, but succeed."
7195         fi
7196 }
7197 run_test 81b "OST should return -ENOSPC when retry still fails ======="
7198
7199 test_82() { # LU-1031
7200         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
7201         local gid1=14091995
7202         local gid2=16022000
7203
7204         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
7205         local MULTIPID1=$!
7206         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
7207         local MULTIPID2=$!
7208         kill -USR1 $MULTIPID2
7209         sleep 2
7210         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
7211                 error "First grouplock does not block second one"
7212         else
7213                 echo "Second grouplock blocks first one"
7214         fi
7215         kill -USR1 $MULTIPID1
7216         wait $MULTIPID1
7217         wait $MULTIPID2
7218 }
7219 run_test 82 "Basic grouplock test"
7220
7221 test_83() {
7222         local sfile="/boot/System.map-$(uname -r)"
7223         [ ! -f $sfile ] && skip "No $sfile found" && return
7224         # define OBD_FAIL_LLITE_PTASK_IO_FAIL 0x140d
7225         $LCTL set_param fail_loc=0x140d
7226         cp $sfile $DIR/$tfile || error "write failed"
7227         diff -c $sfile $DIR/$tfile || error "files are different"
7228         $LCTL set_param fail_loc=0
7229         rm -f $DIR/$tfile
7230 }
7231 run_test 83 "Short write in ptask ==============================="
7232
7233 test_99() {
7234         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
7235                 return
7236         test_mkdir $DIR/$tdir.cvsroot
7237         chown $RUNAS_ID $DIR/$tdir.cvsroot
7238
7239         cd $TMP
7240         $RUNAS cvs -d $DIR/$tdir.cvsroot init || error "cvs init failed"
7241
7242         cd /etc/init.d
7243         # some versions of cvs import exit(1) when asked to import links or
7244         # files they can't read.  ignore those files.
7245         local toignore=$(find . -type l -printf '-I %f\n' -o \
7246                          ! -perm /4 -printf '-I %f\n')
7247         $RUNAS cvs -d $DIR/$tdir.cvsroot import -m "nomesg" $toignore \
7248                 $tdir.reposname vtag rtag
7249
7250         cd $DIR
7251         test_mkdir $DIR/$tdir.reposname
7252         chown $RUNAS_ID $DIR/$tdir.reposname
7253         $RUNAS cvs -d $DIR/$tdir.cvsroot co $tdir.reposname
7254
7255         cd $DIR/$tdir.reposname
7256         $RUNAS touch foo99
7257         $RUNAS cvs add -m 'addmsg' foo99
7258         $RUNAS cvs update
7259         $RUNAS cvs commit -m 'nomsg' foo99
7260         rm -fr $DIR/$tdir.cvsroot
7261 }
7262 run_test 99 "cvs strange file/directory operations"
7263
7264 test_100() {
7265         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7266         [[ "$NETTYPE" =~ tcp ]] ||
7267                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" &&
7268                         return ; }
7269
7270         remote_ost_nodsh && skip "remote OST with nodsh" && return
7271         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7272         remote_servers ||
7273                 { skip "useless for local single node setup" && return; }
7274
7275         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
7276                 [ "$PROT" != "tcp" ] && continue
7277                 RPORT=$(echo $REMOTE | cut -d: -f2)
7278                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
7279
7280                 rc=0
7281                 LPORT=`echo $LOCAL | cut -d: -f2`
7282                 if [ $LPORT -ge 1024 ]; then
7283                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
7284                         netstat -tna
7285                         error_exit "local: $LPORT > 1024, remote: $RPORT"
7286                 fi
7287         done
7288         [ "$rc" = 0 ] || error_exit "privileged port not found" )
7289 }
7290 run_test 100 "check local port using privileged port ==========="
7291
7292 function get_named_value()
7293 {
7294     local tag
7295
7296     tag=$1
7297     while read ;do
7298         line=$REPLY
7299         case $line in
7300         $tag*)
7301             echo $line | sed "s/^$tag[ ]*//"
7302             break
7303             ;;
7304         esac
7305     done
7306 }
7307
7308 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
7309                    awk '/^max_cached_mb/ { print $2 }')
7310
7311 cleanup_101a() {
7312         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
7313         trap 0
7314 }
7315
7316 test_101a() {
7317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7318         [ $MDSCOUNT -ge 2 ] && skip "needs < 2 MDTs" && return #LU-4322
7319         local s
7320         local discard
7321         local nreads=10000
7322         local cache_limit=32
7323
7324         $LCTL set_param -n osc.*-osc*.rpc_stats 0
7325         trap cleanup_101a EXIT
7326         $LCTL set_param -n llite.*.read_ahead_stats 0
7327         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
7328
7329         #
7330         # randomly read 10000 of 64K chunks from file 3x 32MB in size
7331         #
7332         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
7333         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
7334
7335         discard=0
7336         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
7337                 get_named_value 'read but discarded' | cut -d" " -f1); do
7338                         discard=$(($discard + $s))
7339         done
7340         cleanup_101a
7341
7342         if [[ $(($discard * 10)) -gt $nreads ]]; then
7343                 $LCTL get_param osc.*-osc*.rpc_stats
7344                 $LCTL get_param llite.*.read_ahead_stats
7345                 error "too many ($discard) discarded pages"
7346         fi
7347         rm -f $DIR/$tfile || true
7348 }
7349 run_test 101a "check read-ahead for random reads"
7350
7351 setup_test101bc() {
7352         test_mkdir $DIR/$tdir
7353         local STRIPE_SIZE=$1
7354         local FILE_LENGTH=$2
7355         STRIPE_OFFSET=0
7356
7357         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
7358
7359         local list=$(comma_list $(osts_nodes))
7360         set_osd_param $list '' read_cache_enable 0
7361         set_osd_param $list '' writethrough_cache_enable 0
7362
7363         trap cleanup_test101bc EXIT
7364         # prepare the read-ahead file
7365         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
7366
7367         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
7368                                 count=$FILE_SIZE_MB 2> /dev/null
7369
7370 }
7371
7372 cleanup_test101bc() {
7373         trap 0
7374         rm -rf $DIR/$tdir
7375         rm -f $DIR/$tfile
7376
7377         local list=$(comma_list $(osts_nodes))
7378         set_osd_param $list '' read_cache_enable 1
7379         set_osd_param $list '' writethrough_cache_enable 1
7380 }
7381
7382 calc_total() {
7383         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
7384 }
7385
7386 ra_check_101() {
7387         local READ_SIZE=$1
7388         local STRIPE_SIZE=$2
7389         local FILE_LENGTH=$3
7390         local RA_INC=1048576
7391         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
7392         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
7393                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
7394         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
7395                         get_named_value 'read but discarded' |
7396                         cut -d" " -f1 | calc_total)
7397         if [[ $DISCARD -gt $discard_limit ]]; then
7398                 $LCTL get_param llite.*.read_ahead_stats
7399                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
7400         else
7401                 echo "Read-ahead success for size ${READ_SIZE}"
7402         fi
7403 }
7404
7405 test_101b() {
7406         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7407         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7408         local STRIPE_SIZE=1048576
7409         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
7410         if [ $SLOW == "yes" ]; then
7411                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
7412         else
7413                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
7414         fi
7415
7416         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
7417
7418         # prepare the read-ahead file
7419         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
7420         cancel_lru_locks osc
7421         for BIDX in 2 4 8 16 32 64 128 256
7422         do
7423                 local BSIZE=$((BIDX*4096))
7424                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
7425                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
7426                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
7427                 $LCTL set_param -n llite.*.read_ahead_stats 0
7428                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
7429                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
7430                 cancel_lru_locks osc
7431                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
7432         done
7433         cleanup_test101bc
7434         true
7435 }
7436 run_test 101b "check stride-io mode read-ahead ================="
7437
7438 test_101c() {
7439         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7440         local STRIPE_SIZE=1048576
7441         local FILE_LENGTH=$((STRIPE_SIZE*100))
7442         local nreads=10000
7443         local osc_rpc_stats
7444
7445         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
7446
7447         cancel_lru_locks osc
7448         $LCTL set_param osc.*.rpc_stats 0
7449         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
7450         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
7451                 local stats=$($LCTL get_param -n $osc_rpc_stats)
7452                 local lines=$(echo "$stats" | awk 'END {print NR;}')
7453                 local size
7454
7455                 if [ $lines -le 20 ]; then
7456                         continue
7457                 fi
7458                 for size in 1 2 4 8; do
7459                         local rpc=$(echo "$stats" |
7460                                     awk '($1 == "'$size':") {print $2; exit; }')
7461                         [ $rpc != 0 ] &&
7462                                 error "Small $((size*4))k read IO $rpc !"
7463                 done
7464                 echo "$osc_rpc_stats check passed!"
7465         done
7466         cleanup_test101bc
7467         true
7468 }
7469 run_test 101c "check stripe_size aligned read-ahead ================="
7470
7471 set_read_ahead() {
7472         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
7473         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
7474 }
7475
7476 test_101d() {
7477         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7478         local file=$DIR/$tfile
7479         local sz_MB=${FILESIZE_101d:-500}
7480         local ra_MB=${READAHEAD_MB:-40}
7481
7482         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
7483         [ $free_MB -lt $sz_MB ] &&
7484                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
7485
7486         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
7487         $SETSTRIPE -c -1 $file || error "setstripe failed"
7488
7489         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
7490         echo Cancel LRU locks on lustre client to flush the client cache
7491         cancel_lru_locks osc
7492
7493         echo Disable read-ahead
7494         local old_READAHEAD=$(set_read_ahead 0)
7495
7496         echo Reading the test file $file with read-ahead disabled
7497         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
7498
7499         echo Cancel LRU locks on lustre client to flush the client cache
7500         cancel_lru_locks osc
7501         echo Enable read-ahead with ${ra_MB}MB
7502         set_read_ahead $ra_MB
7503
7504         echo Reading the test file $file with read-ahead enabled
7505         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
7506
7507         echo "read-ahead disabled time read $raOFF"
7508         echo "read-ahead enabled  time read $raON"
7509
7510         set_read_ahead $old_READAHEAD
7511         rm -f $file
7512         wait_delete_completed
7513
7514         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
7515                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
7516 }
7517 run_test 101d "file read with and without read-ahead enabled"
7518
7519 test_101e() {
7520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7521         local file=$DIR/$tfile
7522         local size_KB=500  #KB
7523         local count=100
7524         local bsize=1024
7525
7526         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
7527         local need_KB=$((count * size_KB))
7528         [[ $free_KB -le $need_KB ]] &&
7529                 skip_env "Need free space $need_KB, have $free_KB" && return
7530
7531         echo "Creating $count ${size_KB}K test files"
7532         for ((i = 0; i < $count; i++)); do
7533                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
7534         done
7535
7536         echo "Cancel LRU locks on lustre client to flush the client cache"
7537         cancel_lru_locks $OSC
7538
7539         echo "Reset readahead stats"
7540         $LCTL set_param -n llite.*.read_ahead_stats 0
7541
7542         for ((i = 0; i < $count; i++)); do
7543                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
7544         done
7545
7546         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
7547                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
7548
7549         for ((i = 0; i < $count; i++)); do
7550                 rm -rf $file.$i 2>/dev/null
7551         done
7552
7553         #10000 means 20% reads are missing in readahead
7554         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
7555 }
7556 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
7557
7558 test_101f() {
7559         which iozone || { skip "no iozone installed" && return; }
7560
7561         local old_debug=$($LCTL get_param debug)
7562         old_debug=${old_debug#*=}
7563         $LCTL set_param debug="reada mmap"
7564
7565         # create a test file
7566         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
7567
7568         echo Cancel LRU locks on lustre client to flush the client cache
7569         cancel_lru_locks osc
7570
7571         echo Reset readahead stats
7572         $LCTL set_param -n llite.*.read_ahead_stats 0
7573
7574         echo mmap read the file with small block size
7575         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
7576                 > /dev/null 2>&1
7577
7578         echo checking missing pages
7579         $LCTL get_param llite.*.read_ahead_stats
7580         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
7581                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
7582
7583         $LCTL set_param debug="$old_debug"
7584         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
7585         rm -f $DIR/$tfile
7586 }
7587 run_test 101f "check mmap read performance"
7588
7589 test_101g_brw_size_test() {
7590         local mb=$1
7591         local pages=$((mb * 1048576 / $(page_size)))
7592         local file=$DIR/$tfile
7593
7594         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
7595                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
7596         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
7597                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
7598                         return 2
7599         done
7600
7601         stack_trap "rm -f $file" EXIT
7602         $LCTL set_param -n osc.*.rpc_stats=0
7603
7604         # 10 RPCs should be enough for the test
7605         local count=10
7606         dd if=/dev/zero of=$file bs=${mb}M count=$count ||
7607                 { error "dd write ${mb} MB blocks failed"; return 3; }
7608         cancel_lru_locks osc
7609         dd of=/dev/null if=$file bs=${mb}M count=$count ||
7610                 { error "dd write ${mb} MB blocks failed"; return 4; }
7611
7612         # calculate number of full-sized read and write RPCs
7613         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
7614                 sed -n '/pages per rpc/,/^$/p' |
7615                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
7616                 END { print reads,writes }'))
7617         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
7618                 return 5
7619         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
7620                 return 6
7621
7622         return 0
7623 }
7624
7625 test_101g() {
7626         remote_ost_nodsh && skip "remote OST with nodsh" && return
7627
7628         local rpcs
7629         local osts=$(get_facets OST)
7630         local list=$(comma_list $(osts_nodes))
7631         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
7632         local brw_size="obdfilter.*.brw_size"
7633         local ostver=$(lustre_version_code ost1)
7634         local cliver=$(lustre_version_code client)
7635
7636         $LFS setstripe -i 0 -c 1 $DIR/$tfile
7637
7638         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
7639         if [ $ostver -ge $(version_code 2.8.52) -o \
7640              \( $ostver -ge $(version_code 2.7.17) -a \
7641                 $ostver -lt $(version_code 2.7.50) \) ] &&
7642            [ $cliver -ge $(version_code 2.8.52) -o \
7643              \( $cliver -ge $(version_code 2.7.17) -a \
7644                 $cliver -lt $(version_code 2.7.50) \) ]; then
7645                 [ $ostver -ge $(version_code 2.9.52) ] && suffix="M"
7646                 if [[ $orig_mb -lt 16 ]]; then
7647                         save_lustre_params $osts "$brw_size" > $p
7648                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
7649                                 error "set 16MB RPC size failed"
7650
7651                         echo "remount client to enable new RPC size"
7652                         remount_client $MOUNT || error "remount_client failed"
7653                 fi
7654
7655                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
7656                 # should be able to set brw_size=12, but no rpc_stats for that
7657                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
7658         fi
7659
7660         test_101g_brw_size_test 4 || error "4MB RPC test failed"
7661
7662         if [[ $orig_mb -lt 16 ]]; then
7663                 restore_lustre_params < $p
7664                 remount_client $MOUNT || error "remount_client restore failed"
7665         fi
7666
7667         rm -f $p $DIR/$tfile
7668 }
7669 run_test 101g "Big bulk(4/16 MiB) readahead"
7670
7671 setup_test102() {
7672         test_mkdir $DIR/$tdir
7673         chown $RUNAS_ID $DIR/$tdir
7674         STRIPE_SIZE=65536
7675         STRIPE_OFFSET=1
7676         STRIPE_COUNT=$OSTCOUNT
7677         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
7678
7679         trap cleanup_test102 EXIT
7680         cd $DIR
7681         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
7682         cd $DIR/$tdir
7683         for num in 1 2 3 4; do
7684                 for count in $(seq 1 $STRIPE_COUNT); do
7685                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
7686                                 local size=`expr $STRIPE_SIZE \* $num`
7687                                 local file=file"$num-$idx-$count"
7688                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
7689                         done
7690                 done
7691         done
7692
7693         cd $DIR
7694         $1 tar cf $TMP/f102.tar $tdir --xattrs
7695 }
7696
7697 cleanup_test102() {
7698         trap 0
7699         rm -f $TMP/f102.tar
7700         rm -rf $DIR/d0.sanity/d102
7701 }
7702
7703 test_102a() {
7704         local testfile=$DIR/$tfile
7705
7706         touch $testfile
7707
7708         [ "$UID" != 0 ] && skip_env "must run as root" && return
7709         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
7710                 skip_env "must have user_xattr" && return
7711
7712         [ -z "$(which setfattr 2>/dev/null)" ] &&
7713                 skip_env "could not find setfattr" && return
7714
7715         echo "set/get xattr..."
7716         setfattr -n trusted.name1 -v value1 $testfile ||
7717                 error "setfattr -n trusted.name1=value1 $testfile failed"
7718         getfattr -n trusted.name1 $testfile 2> /dev/null |
7719           grep "trusted.name1=.value1" ||
7720                 error "$testfile missing trusted.name1=value1"
7721
7722         setfattr -n user.author1 -v author1 $testfile ||
7723                 error "setfattr -n user.author1=author1 $testfile failed"
7724         getfattr -n user.author1 $testfile 2> /dev/null |
7725           grep "user.author1=.author1" ||
7726                 error "$testfile missing trusted.author1=author1"
7727
7728         echo "listxattr..."
7729         setfattr -n trusted.name2 -v value2 $testfile ||
7730                 error "$testfile unable to set trusted.name2"
7731         setfattr -n trusted.name3 -v value3 $testfile ||
7732                 error "$testfile unable to set trusted.name3"
7733         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
7734             grep "trusted.name" | wc -l) -eq 3 ] ||
7735                 error "$testfile missing 3 trusted.name xattrs"
7736
7737         setfattr -n user.author2 -v author2 $testfile ||
7738                 error "$testfile unable to set user.author2"
7739         setfattr -n user.author3 -v author3 $testfile ||
7740                 error "$testfile unable to set user.author3"
7741         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
7742             grep "user.author" | wc -l) -eq 3 ] ||
7743                 error "$testfile missing 3 user.author xattrs"
7744
7745         echo "remove xattr..."
7746         setfattr -x trusted.name1 $testfile ||
7747                 error "$testfile error deleting trusted.name1"
7748         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
7749                 error "$testfile did not delete trusted.name1 xattr"
7750
7751         setfattr -x user.author1 $testfile ||
7752                 error "$testfile error deleting user.author1"
7753         echo "set lustre special xattr ..."
7754         $LFS setstripe -c1 $testfile
7755         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
7756                 awk -F "=" '/trusted.lov/ { print $2 }' )
7757         setfattr -n "trusted.lov" -v $lovea $testfile ||
7758                 error "$testfile doesn't ignore setting trusted.lov again"
7759         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
7760                 error "$testfile allow setting invalid trusted.lov"
7761         rm -f $testfile
7762 }
7763 run_test 102a "user xattr test =================================="
7764
7765 test_102b() {
7766         [ -z "$(which setfattr 2>/dev/null)" ] &&
7767                 skip_env "could not find setfattr" && return
7768
7769         # b10930: get/set/list trusted.lov xattr
7770         echo "get/set/list trusted.lov xattr ..."
7771         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7772         local testfile=$DIR/$tfile
7773         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7774                 error "setstripe failed"
7775         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
7776                 error "getstripe failed"
7777         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
7778                 error "can't get trusted.lov from $testfile"
7779
7780         local testfile2=${testfile}2
7781         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
7782                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
7783
7784         $MCREATE $testfile2
7785         setfattr -n trusted.lov -v $value $testfile2
7786         local stripe_size=$($GETSTRIPE -S $testfile2)
7787         local stripe_count=$($GETSTRIPE -c $testfile2)
7788         [[ $stripe_size -eq 65536 ]] ||
7789                 error "stripe size $stripe_size != 65536"
7790         [[ $stripe_count -eq $STRIPECOUNT ]] ||
7791                 error "stripe count $stripe_count != $STRIPECOUNT"
7792         rm -f $DIR/$tfile
7793 }
7794 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
7795
7796 test_102c() {
7797         [ -z "$(which setfattr 2>/dev/null)" ] &&
7798                 skip_env "could not find setfattr" && return
7799
7800         # b10930: get/set/list lustre.lov xattr
7801         echo "get/set/list lustre.lov xattr ..."
7802         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7803         test_mkdir $DIR/$tdir
7804         chown $RUNAS_ID $DIR/$tdir
7805         local testfile=$DIR/$tdir/$tfile
7806         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7807                 error "setstripe failed"
7808         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
7809                 error "getstripe failed"
7810         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
7811         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
7812
7813         local testfile2=${testfile}2
7814         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
7815                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
7816
7817         $RUNAS $MCREATE $testfile2
7818         $RUNAS setfattr -n lustre.lov -v $value $testfile2
7819         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
7820         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
7821         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
7822         [ $stripe_count -eq $STRIPECOUNT ] ||
7823                 error "stripe count $stripe_count != $STRIPECOUNT"
7824 }
7825 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
7826
7827 compare_stripe_info1() {
7828         local stripe_index_all_zero=true
7829
7830         for num in 1 2 3 4; do
7831                 for count in $(seq 1 $STRIPE_COUNT); do
7832                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
7833                                 local size=$((STRIPE_SIZE * num))
7834                                 local file=file"$num-$offset-$count"
7835                                 stripe_size=$($LFS getstripe -S $PWD/$file)
7836                                 [[ $stripe_size -ne $size ]] &&
7837                                     error "$file: size $stripe_size != $size"
7838                                 stripe_count=$($LFS getstripe -c $PWD/$file)
7839                                 # allow fewer stripes to be created, ORI-601
7840                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
7841                                     error "$file: count $stripe_count != $count"
7842                                 stripe_index=$($LFS getstripe -i $PWD/$file)
7843                                 [[ $stripe_index -ne 0 ]] &&
7844                                         stripe_index_all_zero=false
7845                         done
7846                 done
7847         done
7848         $stripe_index_all_zero &&
7849                 error "all files are being extracted starting from OST index 0"
7850         return 0
7851 }
7852
7853 have_xattrs_include() {
7854         tar --help | grep -q xattrs-include &&
7855                 echo --xattrs-include="lustre.*"
7856 }
7857
7858 test_102d() {
7859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7860         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7861         XINC=$(have_xattrs_include)
7862         setup_test102
7863         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
7864         cd $DIR/$tdir/$tdir
7865         compare_stripe_info1
7866 }
7867 run_test 102d "tar restore stripe info from tarfile,not keep osts"
7868
7869 test_102f() {
7870         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7871         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7872         XINC=$(have_xattrs_include)
7873         setup_test102
7874         test_mkdir $DIR/$tdir.restore
7875         cd $DIR
7876         tar cf - --xattrs $tdir | tar xf - \
7877                 -C $DIR/$tdir.restore --xattrs $XINC
7878         cd $DIR/$tdir.restore/$tdir
7879         compare_stripe_info1
7880 }
7881 run_test 102f "tar copy files, not keep osts"
7882
7883 grow_xattr() {
7884         local xsize=${1:-1024}  # in bytes
7885         local file=$DIR/$tfile
7886
7887         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
7888                 skip "must have user_xattr" && return 0
7889         [ -z "$(which setfattr 2>/dev/null)" ] &&
7890                 skip_env "could not find setfattr" && return 0
7891         [ -z "$(which getfattr 2>/dev/null)" ] &&
7892                 skip_env "could not find getfattr" && return 0
7893
7894         touch $file
7895
7896         local value="$(generate_string $xsize)"
7897
7898         local xbig=trusted.big
7899         log "save $xbig on $file"
7900         setfattr -n $xbig -v $value $file ||
7901                 error "saving $xbig on $file failed"
7902
7903         local orig=$(get_xattr_value $xbig $file)
7904         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
7905
7906         local xsml=trusted.sml
7907         log "save $xsml on $file"
7908         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
7909
7910         local new=$(get_xattr_value $xbig $file)
7911         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
7912
7913         log "grow $xsml on $file"
7914         setfattr -n $xsml -v "$value" $file ||
7915                 error "growing $xsml on $file failed"
7916
7917         new=$(get_xattr_value $xbig $file)
7918         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
7919         log "$xbig still valid after growing $xsml"
7920
7921         rm -f $file
7922 }
7923
7924 test_102h() { # bug 15777
7925         grow_xattr 1024
7926 }
7927 run_test 102h "grow xattr from inside inode to external block"
7928
7929 test_102ha() {
7930         large_xattr_enabled || { skip "large_xattr disabled" && return; }
7931         grow_xattr $(max_xattr_size)
7932 }
7933 run_test 102ha "grow xattr from inside inode to external inode"
7934
7935 test_102i() { # bug 17038
7936         [ -z "$(which getfattr 2>/dev/null)" ] &&
7937                 skip "could not find getfattr" && return
7938         touch $DIR/$tfile
7939         ln -s $DIR/$tfile $DIR/${tfile}link
7940         getfattr -n trusted.lov $DIR/$tfile ||
7941                 error "lgetxattr on $DIR/$tfile failed"
7942         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
7943                 grep -i "no such attr" ||
7944                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
7945         rm -f $DIR/$tfile $DIR/${tfile}link
7946 }
7947 run_test 102i "lgetxattr test on symbolic link ============"
7948
7949 test_102j() {
7950         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7951         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7952         XINC=$(have_xattrs_include)
7953         setup_test102 "$RUNAS"
7954         chown $RUNAS_ID $DIR/$tdir
7955         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
7956         cd $DIR/$tdir/$tdir
7957         compare_stripe_info1 "$RUNAS"
7958 }
7959 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
7960
7961 test_102k() {
7962         [ -z "$(which setfattr 2>/dev/null)" ] &&
7963                 skip "could not find setfattr" && return
7964         touch $DIR/$tfile
7965         # b22187 just check that does not crash for regular file.
7966         setfattr -n trusted.lov $DIR/$tfile
7967         # b22187 'setfattr -n trusted.lov' should remove LOV EA for directories
7968         local test_kdir=$DIR/$tdir
7969         test_mkdir $test_kdir
7970         local default_size=$($LFS getstripe -S $test_kdir)
7971         local default_count=$($LFS getstripe -c $test_kdir)
7972         local default_offset=$($LFS getstripe -i $test_kdir)
7973         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
7974                 error 'dir setstripe failed'
7975         setfattr -n trusted.lov $test_kdir
7976         local stripe_size=$($LFS getstripe -S $test_kdir)
7977         local stripe_count=$($LFS getstripe -c $test_kdir)
7978         local stripe_offset=$($LFS getstripe -i $test_kdir)
7979         [ $stripe_size -eq $default_size ] ||
7980                 error "stripe size $stripe_size != $default_size"
7981         [ $stripe_count -eq $default_count ] ||
7982                 error "stripe count $stripe_count != $default_count"
7983         [ $stripe_offset -eq $default_offset ] ||
7984                 error "stripe offset $stripe_offset != $default_offset"
7985         rm -rf $DIR/$tfile $test_kdir
7986 }
7987 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
7988
7989 test_102l() {
7990         [ -z "$(which getfattr 2>/dev/null)" ] &&
7991                 skip "could not find getfattr" && return
7992
7993         # LU-532 trusted. xattr is invisible to non-root
7994         local testfile=$DIR/$tfile
7995
7996         touch $testfile
7997
7998         echo "listxattr as user..."
7999         chown $RUNAS_ID $testfile
8000         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
8001             grep -q "trusted" &&
8002                 error "$testfile trusted xattrs are user visible"
8003
8004         return 0;
8005 }
8006 run_test 102l "listxattr size test =================================="
8007
8008 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
8009         local path=$DIR/$tfile
8010         touch $path
8011
8012         listxattr_size_check $path || error "listattr_size_check $path failed"
8013 }
8014 run_test 102m "Ensure listxattr fails on small bufffer ========"
8015
8016 cleanup_test102
8017
8018 getxattr() { # getxattr path name
8019         # Return the base64 encoding of the value of xattr name on path.
8020         local path=$1
8021         local name=$2
8022
8023         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
8024         # file: $path
8025         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
8026         #
8027         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
8028
8029         getfattr --absolute-names --encoding=base64 --name=$name $path |
8030                 awk -F= -v name=$name '$1 == name {
8031                         print substr($0, index($0, "=") + 1);
8032         }'
8033 }
8034
8035 test_102n() { # LU-4101 mdt: protect internal xattrs
8036         [ -z "$(which setfattr 2>/dev/null)" ] &&
8037                 skip "could not find setfattr" && return
8038         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
8039         then
8040                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
8041                 return
8042         fi
8043
8044         local file0=$DIR/$tfile.0
8045         local file1=$DIR/$tfile.1
8046         local xattr0=$TMP/$tfile.0
8047         local xattr1=$TMP/$tfile.1
8048         local namelist="lov lma lmv link fid version som hsm"
8049         local name
8050         local value
8051
8052         rm -rf $file0 $file1 $xattr0 $xattr1
8053         touch $file0 $file1
8054
8055         # Get 'before' xattrs of $file1.
8056         getfattr --absolute-names --dump --match=- $file1 > $xattr0
8057
8058         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
8059                 namelist+=" lfsck_namespace"
8060         for name in $namelist; do
8061                 # Try to copy xattr from $file0 to $file1.
8062                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
8063
8064                 setfattr --name=trusted.$name --value="$value" $file1 ||
8065                         error "setxattr 'trusted.$name' failed"
8066
8067                 # Try to set a garbage xattr.
8068                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
8069
8070                 if [[ x$name == "xlov" ]]; then
8071                         setfattr --name=trusted.lov --value="$value" $file1 &&
8072                         error "setxattr invalid 'trusted.lov' success"
8073                 else
8074                         setfattr --name=trusted.$name --value="$value" $file1 ||
8075                                 error "setxattr invalid 'trusted.$name' failed"
8076                 fi
8077
8078                 # Try to remove the xattr from $file1. We don't care if this
8079                 # appears to succeed or fail, we just don't want there to be
8080                 # any changes or crashes.
8081                 setfattr --remove=$trusted.$name $file1 2> /dev/null
8082         done
8083
8084         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
8085         then
8086                 name="lfsck_ns"
8087                 # Try to copy xattr from $file0 to $file1.
8088                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
8089
8090                 setfattr --name=trusted.$name --value="$value" $file1 ||
8091                         error "setxattr 'trusted.$name' failed"
8092
8093                 # Try to set a garbage xattr.
8094                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
8095
8096                 setfattr --name=trusted.$name --value="$value" $file1 ||
8097                         error "setxattr 'trusted.$name' failed"
8098
8099                 # Try to remove the xattr from $file1. We don't care if this
8100                 # appears to succeed or fail, we just don't want there to be
8101                 # any changes or crashes.
8102                 setfattr --remove=$trusted.$name $file1 2> /dev/null
8103         fi
8104
8105         # Get 'after' xattrs of file1.
8106         getfattr --absolute-names --dump --match=- $file1 > $xattr1
8107
8108         if ! diff $xattr0 $xattr1; then
8109                 error "before and after xattrs of '$file1' differ"
8110         fi
8111
8112         rm -rf $file0 $file1 $xattr0 $xattr1
8113
8114         return 0
8115 }
8116 run_test 102n "silently ignore setxattr on internal trusted xattrs"
8117
8118 test_102p() { # LU-4703 setxattr did not check ownership
8119         local testfile=$DIR/$tfile
8120
8121         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
8122                 skip "MDS needs to be at least 2.5.56" && return
8123
8124         touch $testfile
8125
8126         echo "setfacl as user..."
8127         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
8128         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
8129
8130         echo "setfattr as user..."
8131         setfacl -m "u:$RUNAS_ID:---" $testfile
8132         $RUNAS setfattr -x system.posix_acl_access $testfile
8133         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
8134 }
8135 run_test 102p "check setxattr(2) correctly fails without permission"
8136
8137 test_102q() {
8138         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
8139                 skip "MDS needs to be at least 2.6.92" && return
8140         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
8141 }
8142 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
8143
8144 test_102r() {
8145         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
8146                 skip "MDS needs to be at least 2.6.93" && return
8147         touch $DIR/$tfile || error "touch"
8148         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
8149         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
8150         rm $DIR/$tfile || error "rm"
8151
8152         #normal directory
8153         mkdir -p $DIR/$tdir || error "mkdir"
8154         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
8155         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
8156         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
8157                 error "$testfile error deleting user.author1"
8158         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
8159                 grep "user.$(basename $tdir)" &&
8160                 error "$tdir did not delete user.$(basename $tdir)"
8161         rmdir $DIR/$tdir || error "rmdir"
8162
8163         #striped directory
8164         test_mkdir $DIR/$tdir
8165         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
8166         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
8167         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
8168                 error "$testfile error deleting user.author1"
8169         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
8170                 grep "user.$(basename $tdir)" &&
8171                 error "$tdir did not delete user.$(basename $tdir)"
8172         rmdir $DIR/$tdir || error "rm striped dir"
8173 }
8174 run_test 102r "set EAs with empty values"
8175
8176 run_acl_subtest()
8177 {
8178     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
8179     return $?
8180 }
8181
8182 test_103a() {
8183         [ "$UID" != 0 ] && skip_env "must run as root" && return
8184         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
8185                 skip "must have acl enabled" && return
8186         [ -z "$(which setfacl 2>/dev/null)" ] &&
8187                 skip_env "could not find setfacl" && return
8188         $GSS && skip "could not run under gss" && return
8189         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8190
8191         gpasswd -a daemon bin                           # LU-5641
8192         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
8193
8194         declare -a identity_old
8195
8196         for num in $(seq $MDSCOUNT); do
8197                 switch_identity $num true || identity_old[$num]=$?
8198         done
8199
8200         SAVE_UMASK=$(umask)
8201         umask 0022
8202         mkdir -p $DIR/$tdir
8203         cd $DIR/$tdir
8204
8205         echo "performing cp ..."
8206         run_acl_subtest cp || error "run_acl_subtest cp failed"
8207         echo "performing getfacl-noacl..."
8208         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
8209         echo "performing misc..."
8210         run_acl_subtest misc || error  "misc test failed"
8211         echo "performing permissions..."
8212         run_acl_subtest permissions || error "permissions failed"
8213         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
8214         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
8215              \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
8216              $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
8217         then
8218                 echo "performing permissions xattr..."
8219                 run_acl_subtest permissions_xattr ||
8220                         error "permissions_xattr failed"
8221         fi
8222         echo "performing setfacl..."
8223         run_acl_subtest setfacl || error  "setfacl test failed"
8224
8225         # inheritance test got from HP
8226         echo "performing inheritance..."
8227         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
8228         chmod +x make-tree || error "chmod +x failed"
8229         run_acl_subtest inheritance || error "inheritance test failed"
8230         rm -f make-tree
8231
8232         echo "LU-974 ignore umask when acl is enabled..."
8233         run_acl_subtest 974 || error "LU-974 umask test failed"
8234         if [ $MDSCOUNT -ge 2 ]; then
8235                 run_acl_subtest 974_remote ||
8236                         error "LU-974 umask test failed under remote dir"
8237         fi
8238
8239         echo "LU-2561 newly created file is same size as directory..."
8240         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
8241                 run_acl_subtest 2561 || error "LU-2561 test failed"
8242         else
8243                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
8244         fi
8245
8246         run_acl_subtest 4924 || error "LU-4924 test failed"
8247
8248         cd $SAVE_PWD
8249         umask $SAVE_UMASK
8250
8251         for num in $(seq $MDSCOUNT); do
8252                 if [ "${identity_old[$num]}" = 1 ]; then
8253                         switch_identity $num false || identity_old[$num]=$?
8254                 fi
8255         done
8256 }
8257 run_test 103a "acl test ========================================="
8258
8259 test_103c() {
8260         mkdir -p $DIR/$tdir
8261         cp -rp $DIR/$tdir $DIR/$tdir.bak
8262
8263         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
8264                 error "$DIR/$tdir shouldn't contain default ACL"
8265         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
8266                 error "$DIR/$tdir.bak shouldn't contain default ACL"
8267         true
8268 }
8269 run_test 103c "'cp -rp' won't set empty acl"
8270
8271 test_104a() {
8272         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8273         touch $DIR/$tfile
8274         lfs df || error "lfs df failed"
8275         lfs df -ih || error "lfs df -ih failed"
8276         lfs df -h $DIR || error "lfs df -h $DIR failed"
8277         lfs df -i $DIR || error "lfs df -i $DIR failed"
8278         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
8279         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
8280
8281         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
8282         lctl --device %$OSC deactivate
8283         lfs df || error "lfs df with deactivated OSC failed"
8284         lctl --device %$OSC activate
8285         # wait the osc back to normal
8286         wait_osc_import_state client ost FULL
8287
8288         lfs df || error "lfs df with reactivated OSC failed"
8289         rm -f $DIR/$tfile
8290 }
8291 run_test 104a "lfs df [-ih] [path] test ========================="
8292
8293 test_104b() {
8294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8295         [ $RUNAS_ID -eq $UID ] &&
8296                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
8297         chmod 666 /dev/obd
8298         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
8299                         grep "Permission denied" | wc -l)))
8300         if [ $denied_cnt -ne 0 ]; then
8301                 error "lfs check servers test failed"
8302         fi
8303 }
8304 run_test 104b "$RUNAS lfs check servers test ===================="
8305
8306 test_105a() {
8307         # doesn't work on 2.4 kernels
8308         touch $DIR/$tfile
8309         if $(flock_is_enabled); then
8310                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
8311         else
8312                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
8313         fi
8314         rm -f $DIR/$tfile
8315 }
8316 run_test 105a "flock when mounted without -o flock test ========"
8317
8318 test_105b() {
8319         touch $DIR/$tfile
8320         if $(flock_is_enabled); then
8321                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
8322         else
8323                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
8324         fi
8325         rm -f $DIR/$tfile
8326 }
8327 run_test 105b "fcntl when mounted without -o flock test ========"
8328
8329 test_105c() {
8330         touch $DIR/$tfile
8331         if $(flock_is_enabled); then
8332                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
8333         else
8334                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
8335         fi
8336         rm -f $DIR/$tfile
8337 }
8338 run_test 105c "lockf when mounted without -o flock test"
8339
8340 test_105d() { # bug 15924
8341         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8342         test_mkdir $DIR/$tdir
8343         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
8344         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
8345         $LCTL set_param fail_loc=0x80000315
8346         flocks_test 2 $DIR/$tdir
8347 }
8348 run_test 105d "flock race (should not freeze) ========"
8349
8350 test_105e() { # bug 22660 && 22040
8351         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
8352         touch $DIR/$tfile
8353         flocks_test 3 $DIR/$tfile
8354 }
8355 run_test 105e "Two conflicting flocks from same process"
8356
8357 test_106() { #bug 10921
8358         test_mkdir $DIR/$tdir
8359         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
8360         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
8361 }
8362 run_test 106 "attempt exec of dir followed by chown of that dir"
8363
8364 test_107() {
8365         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8366         CDIR=`pwd`
8367         cd $DIR
8368
8369         local file=core
8370         rm -f $file
8371
8372         local save_pattern=$(sysctl -n kernel.core_pattern)
8373         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
8374         sysctl -w kernel.core_pattern=$file
8375         sysctl -w kernel.core_uses_pid=0
8376
8377         ulimit -c unlimited
8378         sleep 60 &
8379         SLEEPPID=$!
8380
8381         sleep 1
8382
8383         kill -s 11 $SLEEPPID
8384         wait $SLEEPPID
8385         if [ -e $file ]; then
8386                 size=`stat -c%s $file`
8387                 [ $size -eq 0 ] && error "Fail to create core file $file"
8388         else
8389                 error "Fail to create core file $file"
8390         fi
8391         rm -f $file
8392         sysctl -w kernel.core_pattern=$save_pattern
8393         sysctl -w kernel.core_uses_pid=$save_uses_pid
8394         cd $CDIR
8395 }
8396 run_test 107 "Coredump on SIG"
8397
8398 test_110() {
8399         test_mkdir $DIR/$tdir
8400         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255)
8401         $LFS mkdir -c $MDSCOUNT $DIR/$tdir/$(str_repeat 'b' 256) &&
8402                 error "mkdir with 256 char should fail, but did not"
8403         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
8404                 error "create with 255 char failed"
8405         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
8406                 error "create with 256 char should fail, but did not"
8407
8408         ls -l $DIR/$tdir
8409         rm -rf $DIR/$tdir
8410 }
8411 run_test 110 "filename length checking"
8412
8413 #
8414 # Purpose: To verify dynamic thread (OSS) creation.
8415 #
8416 test_115() {
8417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8418         remote_ost_nodsh && skip "remote OST with nodsh" && return
8419
8420         # Lustre does not stop service threads once they are started.
8421         # Reset number of running threads to default.
8422         stopall
8423         setupall
8424
8425         local OSTIO_pre
8426         local save_params="$TMP/sanity-$TESTNAME.parameters"
8427
8428         # Get ll_ost_io count before I/O
8429         OSTIO_pre=$(do_facet ost1 \
8430                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
8431         # Exit if lustre is not running (ll_ost_io not running).
8432         [ -z "$OSTIO_pre" ] && error "no OSS threads"
8433
8434         echo "Starting with $OSTIO_pre threads"
8435         local thread_max=$((OSTIO_pre * 2))
8436         local rpc_in_flight=$((thread_max * 2))
8437         # Number of I/O Process proposed to be started.
8438         local nfiles
8439         local facets=$(get_facets OST)
8440
8441         save_lustre_params client "osc.*OST*.max_rpcs_in_flight" > $save_params
8442         save_lustre_params $facets "ost.OSS.ost_io.threads_max" >> $save_params
8443
8444         # Set in_flight to $rpc_in_flight
8445         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
8446                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
8447         nfiles=${rpc_in_flight}
8448         # Set ost thread_max to $thread_max
8449         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
8450
8451         # 5 Minutes should be sufficient for max number of OSS
8452         # threads(thread_max) to be created.
8453         local timeout=300
8454
8455         # Start I/O.
8456         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
8457         test_mkdir $DIR/$tdir
8458         for i in $(seq $nfiles); do
8459                 local file=$DIR/$tdir/${tfile}-$i
8460                 $LFS setstripe -c -1 -i 0 $file
8461                 ($WTL $file $timeout)&
8462         done
8463
8464         # I/O Started - Wait for thread_started to reach thread_max or report
8465         # error if thread_started is more than thread_max.
8466         echo "Waiting for thread_started to reach thread_max"
8467         local thread_started=0
8468         local end_time=$((SECONDS + timeout))
8469
8470         while [ $SECONDS -le $end_time ] ; do
8471                 echo -n "."
8472                 # Get ost i/o thread_started count.
8473                 thread_started=$(do_facet ost1 \
8474                         "$LCTL get_param \
8475                         ost.OSS.ost_io.threads_started | cut -d= -f2")
8476                 # Break out if thread_started is equal/greater than thread_max
8477                 if [[ $thread_started -ge $thread_max ]]; then
8478                         echo ll_ost_io thread_started $thread_started, \
8479                                 equal/greater than thread_max $thread_max
8480                         break
8481                 fi
8482                 sleep 1
8483         done
8484
8485         # Cleanup - We have the numbers, Kill i/o jobs if running.
8486         jobcount=($(jobs -p))
8487         for i in $(seq 0 $((${#jobcount[@]}-1)))
8488         do
8489                 kill -9 ${jobcount[$i]}
8490                 if [ $? -ne 0 ] ; then
8491                         echo Warning: \
8492                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
8493                 fi
8494         done
8495
8496         # Cleanup files left by WTL binary.
8497         for i in $(seq $nfiles); do
8498                 local file=$DIR/$tdir/${tfile}-$i
8499                 rm -rf $file
8500                 if [ $? -ne 0 ] ; then
8501                         echo "Warning: Failed to delete file $file"
8502                 fi
8503         done
8504
8505         restore_lustre_params <$save_params
8506         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
8507
8508         # Error out if no new thread has started or Thread started is greater
8509         # than thread max.
8510         if [[ $thread_started -le $OSTIO_pre ||
8511                         $thread_started -gt $thread_max ]]; then
8512                 error "ll_ost_io: thread_started $thread_started" \
8513                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
8514                       "No new thread started or thread started greater " \
8515                       "than thread_max."
8516         fi
8517 }
8518 run_test 115 "verify dynamic thread creation===================="
8519
8520 free_min_max () {
8521         wait_delete_completed
8522         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8523         echo "OST kbytes available: ${AVAIL[@]}"
8524         MAXV=${AVAIL[0]}
8525         MAXI=0
8526         MINV=${AVAIL[0]}
8527         MINI=0
8528         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8529                 #echo OST $i: ${AVAIL[i]}kb
8530                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8531                         MAXV=${AVAIL[i]}
8532                         MAXI=$i
8533                 fi
8534                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8535                         MINV=${AVAIL[i]}
8536                         MINI=$i
8537                 fi
8538         done
8539         echo "Min free space: OST $MINI: $MINV"
8540         echo "Max free space: OST $MAXI: $MAXV"
8541 }
8542
8543 test_116a() { # was previously test_116()
8544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8545         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8546
8547         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8548
8549         echo -n "Free space priority "
8550         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
8551                 head -n1
8552         declare -a AVAIL
8553         free_min_max
8554
8555         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
8556         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
8557                 && return
8558         trap simple_cleanup_common EXIT
8559
8560
8561         # Check if we need to generate uneven OSTs
8562         test_mkdir -p $DIR/$tdir/OST${MINI}
8563         local FILL=$((MINV / 4))
8564         local DIFF=$((MAXV - MINV))
8565         local DIFF2=$((DIFF * 100 / MINV))
8566
8567         local threshold=$(do_facet $SINGLEMDS \
8568                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
8569         threshold=${threshold%%%}
8570         echo -n "Check for uneven OSTs: "
8571         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
8572
8573         if [[ $DIFF2 -gt $threshold ]]; then
8574                 echo "ok"
8575                 echo "Don't need to fill OST$MINI"
8576         else
8577                 # generate uneven OSTs. Write 2% over the QOS threshold value
8578                 echo "no"
8579                 DIFF=$((threshold - DIFF2 + 2))
8580                 DIFF2=$((MINV * DIFF / 100))
8581                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
8582                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
8583                         error "setstripe failed"
8584                 DIFF=$((DIFF2 / 2048))
8585                 i=0
8586                 while [ $i -lt $DIFF ]; do
8587                         i=$((i + 1))
8588                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
8589                                 bs=2M count=1 2>/dev/null
8590                         echo -n .
8591                 done
8592                 echo .
8593                 sync
8594                 sleep_maxage
8595                 free_min_max
8596         fi
8597
8598         DIFF=$((MAXV - MINV))
8599         DIFF2=$((DIFF * 100 / MINV))
8600         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
8601         if [ $DIFF2 -gt $threshold ]; then
8602                 echo "ok"
8603         else
8604                 echo "failed - QOS mode won't be used"
8605                 skip "QOS imbalance criteria not met"
8606                 simple_cleanup_common
8607                 return
8608         fi
8609
8610         MINI1=$MINI
8611         MINV1=$MINV
8612         MAXI1=$MAXI
8613         MAXV1=$MAXV
8614
8615         # now fill using QOS
8616         $SETSTRIPE -c 1 $DIR/$tdir
8617         FILL=$((FILL / 200))
8618         if [ $FILL -gt 600 ]; then
8619                 FILL=600
8620         fi
8621         echo "writing $FILL files to QOS-assigned OSTs"
8622         i=0
8623         while [ $i -lt $FILL ]; do
8624                 i=$((i + 1))
8625                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
8626                         count=1 2>/dev/null
8627                 echo -n .
8628         done
8629         echo "wrote $i 200k files"
8630         sync
8631         sleep_maxage
8632
8633         echo "Note: free space may not be updated, so measurements might be off"
8634         free_min_max
8635         DIFF2=$((MAXV - MINV))
8636         echo "free space delta: orig $DIFF final $DIFF2"
8637         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
8638         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
8639         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
8640         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
8641         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
8642         if [[ $DIFF -gt 0 ]]; then
8643                 FILL=$((DIFF2 * 100 / DIFF - 100))
8644                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
8645         fi
8646
8647         # Figure out which files were written where
8648         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8649                awk '/'$MINI1': / {print $2; exit}')
8650         echo $UUID
8651         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8652         echo "$MINC files created on smaller OST $MINI1"
8653         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8654                awk '/'$MAXI1': / {print $2; exit}')
8655         echo $UUID
8656         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8657         echo "$MAXC files created on larger OST $MAXI1"
8658         if [[ $MINC -gt 0 ]]; then
8659                 FILL=$((MAXC * 100 / MINC - 100))
8660                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
8661         fi
8662         [[ $MAXC -gt $MINC ]] ||
8663                 error_ignore LU-9 "stripe QOS didn't balance free space"
8664         simple_cleanup_common
8665 }
8666 run_test 116a "stripe QOS: free space balance ==================="
8667
8668 test_116b() { # LU-2093
8669         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8670         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8671
8672 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
8673         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
8674                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
8675         [ -z "$old_rr" ] && skip "no QOS" && return 0
8676         do_facet $SINGLEMDS lctl set_param \
8677                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
8678         mkdir -p $DIR/$tdir
8679         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
8680         createmany -o $DIR/$tdir/f- 20 || error "can't create"
8681         do_facet $SINGLEMDS lctl set_param fail_loc=0
8682         rm -rf $DIR/$tdir
8683         do_facet $SINGLEMDS lctl set_param \
8684                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
8685 }
8686 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
8687
8688 test_117() # bug 10891
8689 {
8690         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8691         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
8692         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
8693         lctl set_param fail_loc=0x21e
8694         > $DIR/$tfile || error "truncate failed"
8695         lctl set_param fail_loc=0
8696         echo "Truncate succeeded."
8697         rm -f $DIR/$tfile
8698 }
8699 run_test 117 "verify osd extend =========="
8700
8701 NO_SLOW_RESENDCOUNT=4
8702 export OLD_RESENDCOUNT=""
8703 set_resend_count () {
8704         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
8705         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
8706         lctl set_param -n $PROC_RESENDCOUNT $1
8707         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
8708 }
8709
8710 # for reduce test_118* time (b=14842)
8711 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8712
8713 # Reset async IO behavior after error case
8714 reset_async() {
8715         FILE=$DIR/reset_async
8716
8717         # Ensure all OSCs are cleared
8718         $SETSTRIPE -c -1 $FILE
8719         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
8720         sync
8721         rm $FILE
8722 }
8723
8724 test_118a() #bug 11710
8725 {
8726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8727         reset_async
8728
8729         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8730         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8731         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8732
8733         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8734                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8735                 return 1;
8736         fi
8737         rm -f $DIR/$tfile
8738 }
8739 run_test 118a "verify O_SYNC works =========="
8740
8741 test_118b()
8742 {
8743         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8744         remote_ost_nodsh && skip "remote OST with nodsh" && return
8745
8746         reset_async
8747
8748         #define OBD_FAIL_SRV_ENOENT 0x217
8749         set_nodes_failloc "$(osts_nodes)" 0x217
8750         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8751         RC=$?
8752         set_nodes_failloc "$(osts_nodes)" 0
8753         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8754         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8755                     grep -c writeback)
8756
8757         if [[ $RC -eq 0 ]]; then
8758                 error "Must return error due to dropped pages, rc=$RC"
8759                 return 1;
8760         fi
8761
8762         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8763                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8764                 return 1;
8765         fi
8766
8767         echo "Dirty pages not leaked on ENOENT"
8768
8769         # Due to the above error the OSC will issue all RPCs syncronously
8770         # until a subsequent RPC completes successfully without error.
8771         $MULTIOP $DIR/$tfile Ow4096yc
8772         rm -f $DIR/$tfile
8773
8774         return 0
8775 }
8776 run_test 118b "Reclaim dirty pages on fatal error =========="
8777
8778 test_118c()
8779 {
8780         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8781
8782         # for 118c, restore the original resend count, LU-1940
8783         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
8784                                 set_resend_count $OLD_RESENDCOUNT
8785         remote_ost_nodsh && skip "remote OST with nodsh" && return
8786
8787         reset_async
8788
8789         #define OBD_FAIL_OST_EROFS               0x216
8790         set_nodes_failloc "$(osts_nodes)" 0x216
8791
8792         # multiop should block due to fsync until pages are written
8793         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8794         MULTIPID=$!
8795         sleep 1
8796
8797         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8798                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8799         fi
8800
8801         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8802                     grep -c writeback)
8803         if [[ $WRITEBACK -eq 0 ]]; then
8804                 error "No page in writeback, writeback=$WRITEBACK"
8805         fi
8806
8807         set_nodes_failloc "$(osts_nodes)" 0
8808         wait $MULTIPID
8809         RC=$?
8810         if [[ $RC -ne 0 ]]; then
8811                 error "Multiop fsync failed, rc=$RC"
8812         fi
8813
8814         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8815         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8816                     grep -c writeback)
8817         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8818                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8819         fi
8820
8821         rm -f $DIR/$tfile
8822         echo "Dirty pages flushed via fsync on EROFS"
8823         return 0
8824 }
8825 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
8826
8827 # continue to use small resend count to reduce test_118* time (b=14842)
8828 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8829
8830 test_118d()
8831 {
8832         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8833         remote_ost_nodsh && skip "remote OST with nodsh" && return
8834
8835         reset_async
8836
8837         #define OBD_FAIL_OST_BRW_PAUSE_BULK
8838         set_nodes_failloc "$(osts_nodes)" 0x214
8839         # multiop should block due to fsync until pages are written
8840         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8841         MULTIPID=$!
8842         sleep 1
8843
8844         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8845                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8846         fi
8847
8848         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8849                     grep -c writeback)
8850         if [[ $WRITEBACK -eq 0 ]]; then
8851                 error "No page in writeback, writeback=$WRITEBACK"
8852         fi
8853
8854         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
8855         set_nodes_failloc "$(osts_nodes)" 0
8856
8857         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8858         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8859                     grep -c writeback)
8860         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8861                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8862         fi
8863
8864         rm -f $DIR/$tfile
8865         echo "Dirty pages gaurenteed flushed via fsync"
8866         return 0
8867 }
8868 run_test 118d "Fsync validation inject a delay of the bulk =========="
8869
8870 test_118f() {
8871         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8872         reset_async
8873
8874         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
8875         lctl set_param fail_loc=0x8000040a
8876
8877         # Should simulate EINVAL error which is fatal
8878         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8879         RC=$?
8880         if [[ $RC -eq 0 ]]; then
8881                 error "Must return error due to dropped pages, rc=$RC"
8882         fi
8883
8884         lctl set_param fail_loc=0x0
8885
8886         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8887         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8888         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8889                     grep -c writeback)
8890         if [[ $LOCKED -ne 0 ]]; then
8891                 error "Locked pages remain in cache, locked=$LOCKED"
8892         fi
8893
8894         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8895                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8896         fi
8897
8898         rm -f $DIR/$tfile
8899         echo "No pages locked after fsync"
8900
8901         reset_async
8902         return 0
8903 }
8904 run_test 118f "Simulate unrecoverable OSC side error =========="
8905
8906 test_118g() {
8907         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8908         reset_async
8909
8910         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
8911         lctl set_param fail_loc=0x406
8912
8913         # simulate local -ENOMEM
8914         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8915         RC=$?
8916
8917         lctl set_param fail_loc=0
8918         if [[ $RC -eq 0 ]]; then
8919                 error "Must return error due to dropped pages, rc=$RC"
8920         fi
8921
8922         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8923         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8924         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8925                         grep -c writeback)
8926         if [[ $LOCKED -ne 0 ]]; then
8927                 error "Locked pages remain in cache, locked=$LOCKED"
8928         fi
8929
8930         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8931                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8932         fi
8933
8934         rm -f $DIR/$tfile
8935         echo "No pages locked after fsync"
8936
8937         reset_async
8938         return 0
8939 }
8940 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
8941
8942 test_118h() {
8943         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8944         remote_ost_nodsh && skip "remote OST with nodsh" && return
8945
8946         reset_async
8947
8948         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8949         set_nodes_failloc "$(osts_nodes)" 0x20e
8950         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8951         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8952         RC=$?
8953
8954         set_nodes_failloc "$(osts_nodes)" 0
8955         if [[ $RC -eq 0 ]]; then
8956                 error "Must return error due to dropped pages, rc=$RC"
8957         fi
8958
8959         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8960         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8961         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8962                     grep -c writeback)
8963         if [[ $LOCKED -ne 0 ]]; then
8964                 error "Locked pages remain in cache, locked=$LOCKED"
8965         fi
8966
8967         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8968                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8969         fi
8970
8971         rm -f $DIR/$tfile
8972         echo "No pages locked after fsync"
8973
8974         return 0
8975 }
8976 run_test 118h "Verify timeout in handling recoverables errors  =========="
8977
8978 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8979
8980 test_118i() {
8981         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8982         remote_ost_nodsh && skip "remote OST with nodsh" && return
8983
8984         reset_async
8985
8986         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8987         set_nodes_failloc "$(osts_nodes)" 0x20e
8988
8989         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8990         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8991         PID=$!
8992         sleep 5
8993         set_nodes_failloc "$(osts_nodes)" 0
8994
8995         wait $PID
8996         RC=$?
8997         if [[ $RC -ne 0 ]]; then
8998                 error "got error, but should be not, rc=$RC"
8999         fi
9000
9001         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
9002         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9003         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
9004         if [[ $LOCKED -ne 0 ]]; then
9005                 error "Locked pages remain in cache, locked=$LOCKED"
9006         fi
9007
9008         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9009                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9010         fi
9011
9012         rm -f $DIR/$tfile
9013         echo "No pages locked after fsync"
9014
9015         return 0
9016 }
9017 run_test 118i "Fix error before timeout in recoverable error  =========="
9018
9019 [ "$SLOW" = "no" ] && set_resend_count 4
9020
9021 test_118j() {
9022         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9023         remote_ost_nodsh && skip "remote OST with nodsh" && return
9024
9025         reset_async
9026
9027         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
9028         set_nodes_failloc "$(osts_nodes)" 0x220
9029
9030         # return -EIO from OST
9031         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
9032         RC=$?
9033         set_nodes_failloc "$(osts_nodes)" 0x0
9034         if [[ $RC -eq 0 ]]; then
9035                 error "Must return error due to dropped pages, rc=$RC"
9036         fi
9037
9038         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
9039         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
9040         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
9041         if [[ $LOCKED -ne 0 ]]; then
9042                 error "Locked pages remain in cache, locked=$LOCKED"
9043         fi
9044
9045         # in recoverable error on OST we want resend and stay until it finished
9046         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
9047                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
9048         fi
9049
9050         rm -f $DIR/$tfile
9051         echo "No pages locked after fsync"
9052
9053         return 0
9054 }
9055 run_test 118j "Simulate unrecoverable OST side error =========="
9056
9057 test_118k()
9058 {
9059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9060         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
9061
9062         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
9063         set_nodes_failloc "$(osts_nodes)" 0x20e
9064         test_mkdir $DIR/$tdir
9065
9066         for ((i=0;i<10;i++)); do
9067                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
9068                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
9069                 SLEEPPID=$!
9070                 sleep 0.500s
9071                 kill $SLEEPPID
9072                 wait $SLEEPPID
9073         done
9074
9075         set_nodes_failloc "$(osts_nodes)" 0
9076         rm -rf $DIR/$tdir
9077 }
9078 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
9079
9080 test_118l()
9081 {
9082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9083         # LU-646
9084         test_mkdir $DIR/$tdir
9085         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
9086         rm -rf $DIR/$tdir
9087 }
9088 run_test 118l "fsync dir"
9089
9090 test_118m() # LU-3066
9091 {
9092         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9093         test_mkdir $DIR/$tdir
9094         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
9095         rm -rf $DIR/$tdir
9096 }
9097 run_test 118m "fdatasync dir ========="
9098
9099 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
9100
9101 test_118n()
9102 {
9103         local begin
9104         local end
9105
9106         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9107         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
9108
9109         # Sleep to avoid a cached response.
9110         #define OBD_STATFS_CACHE_SECONDS 1
9111         sleep 2
9112
9113         # Inject a 10 second delay in the OST_STATFS handler.
9114         #define OBD_FAIL_OST_STATFS_DELAY 0x242
9115         set_nodes_failloc "$(osts_nodes)" 0x242
9116
9117         begin=$SECONDS
9118         stat --file-system $MOUNT > /dev/null
9119         end=$SECONDS
9120
9121         set_nodes_failloc "$(osts_nodes)" 0
9122
9123         if ((end - begin > 20)); then
9124             error "statfs took $((end - begin)) seconds, expected 10"
9125         fi
9126 }
9127 run_test 118n "statfs() sends OST_STATFS requests in parallel"
9128
9129 test_119a() # bug 11737
9130 {
9131         BSIZE=$((512 * 1024))
9132         directio write $DIR/$tfile 0 1 $BSIZE
9133         # We ask to read two blocks, which is more than a file size.
9134         # directio will indicate an error when requested and actual
9135         # sizes aren't equeal (a normal situation in this case) and
9136         # print actual read amount.
9137         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
9138         if [ "$NOB" != "$BSIZE" ]; then
9139                 error "read $NOB bytes instead of $BSIZE"
9140         fi
9141         rm -f $DIR/$tfile
9142 }
9143 run_test 119a "Short directIO read must return actual read amount"
9144
9145 test_119b() # bug 11737
9146 {
9147         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9148
9149         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
9150         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
9151         sync
9152         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
9153                 error "direct read failed"
9154         rm -f $DIR/$tfile
9155 }
9156 run_test 119b "Sparse directIO read must return actual read amount"
9157
9158 test_119c() # bug 13099
9159 {
9160         BSIZE=1048576
9161         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
9162         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
9163         rm -f $DIR/$tfile
9164 }
9165 run_test 119c "Testing for direct read hitting hole"
9166
9167 test_119d() # bug 15950
9168 {
9169         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9170         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
9171         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
9172         BSIZE=1048576
9173         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
9174         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
9175         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
9176         lctl set_param fail_loc=0x40d
9177         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
9178         pid_dio=$!
9179         sleep 1
9180         cat $DIR/$tfile > /dev/null &
9181         lctl set_param fail_loc=0
9182         pid_reads=$!
9183         wait $pid_dio
9184         log "the DIO writes have completed, now wait for the reads (should not block very long)"
9185         sleep 2
9186         [ -n "`ps h -p $pid_reads -o comm`" ] && \
9187         error "the read rpcs have not completed in 2s"
9188         rm -f $DIR/$tfile
9189         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
9190 }
9191 run_test 119d "The DIO path should try to send a new rpc once one is completed"
9192
9193 test_120a() {
9194         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9195         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9196         test_mkdir $DIR/$tdir
9197         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9198                 { skip "no early lock cancel on server"; return 0; }
9199
9200         lru_resize_disable mdc
9201         lru_resize_disable osc
9202         cancel_lru_locks mdc
9203         # asynchronous object destroy at MDT could cause bl ast to client
9204         cancel_lru_locks osc
9205
9206         stat $DIR/$tdir > /dev/null
9207         can1=$(do_facet $SINGLEMDS \
9208                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9209                awk '/ldlm_cancel/ {print $2}')
9210         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9211                awk '/ldlm_bl_callback/ {print $2}')
9212         test_mkdir -c1 $DIR/$tdir/d1
9213         can2=$(do_facet $SINGLEMDS \
9214                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9215                awk '/ldlm_cancel/ {print $2}')
9216         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9217                awk '/ldlm_bl_callback/ {print $2}')
9218         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9219         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9220         lru_resize_enable mdc
9221         lru_resize_enable osc
9222 }
9223 run_test 120a "Early Lock Cancel: mkdir test"
9224
9225 test_120b() {
9226         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9227         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9228         test_mkdir $DIR/$tdir
9229         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9230                 { skip "no early lock cancel on server"; return 0; }
9231         lru_resize_disable mdc
9232         lru_resize_disable osc
9233         cancel_lru_locks mdc
9234         stat $DIR/$tdir > /dev/null
9235         can1=$(do_facet $SINGLEMDS \
9236                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9237                awk '/ldlm_cancel/ {print $2}')
9238         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9239                awk '/ldlm_bl_callback/ {print $2}')
9240         touch $DIR/$tdir/f1
9241         can2=$(do_facet $SINGLEMDS \
9242                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9243                awk '/ldlm_cancel/ {print $2}')
9244         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9245                awk '/ldlm_bl_callback/ {print $2}')
9246         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9247         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9248         lru_resize_enable mdc
9249         lru_resize_enable osc
9250 }
9251 run_test 120b "Early Lock Cancel: create test"
9252
9253 test_120c() {
9254         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9255         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9256         test_mkdir -c1 $DIR/$tdir
9257         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9258                 { skip "no early lock cancel on server"; return 0; }
9259         lru_resize_disable mdc
9260         lru_resize_disable osc
9261         test_mkdir -c1 $DIR/$tdir/d1
9262         test_mkdir -c1 $DIR/$tdir/d2
9263         touch $DIR/$tdir/d1/f1
9264         cancel_lru_locks mdc
9265         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
9266         can1=$(do_facet $SINGLEMDS \
9267                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9268                awk '/ldlm_cancel/ {print $2}')
9269         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9270                awk '/ldlm_bl_callback/ {print $2}')
9271         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
9272         can2=$(do_facet $SINGLEMDS \
9273                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9274                awk '/ldlm_cancel/ {print $2}')
9275         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9276                awk '/ldlm_bl_callback/ {print $2}')
9277         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9278         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9279         lru_resize_enable mdc
9280         lru_resize_enable osc
9281 }
9282 run_test 120c "Early Lock Cancel: link test"
9283
9284 test_120d() {
9285         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9286         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9287         test_mkdir -c1 $DIR/$tdir
9288         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9289                 { skip "no early lock cancel on server"; return 0; }
9290         lru_resize_disable mdc
9291         lru_resize_disable osc
9292         touch $DIR/$tdir
9293         cancel_lru_locks mdc
9294         stat $DIR/$tdir > /dev/null
9295         can1=$(do_facet $SINGLEMDS \
9296                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9297                awk '/ldlm_cancel/ {print $2}')
9298         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9299                awk '/ldlm_bl_callback/ {print $2}')
9300         chmod a+x $DIR/$tdir
9301         can2=$(do_facet $SINGLEMDS \
9302                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9303                awk '/ldlm_cancel/ {print $2}')
9304         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9305                awk '/ldlm_bl_callback/ {print $2}')
9306         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9307         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9308         lru_resize_enable mdc
9309         lru_resize_enable osc
9310 }
9311 run_test 120d "Early Lock Cancel: setattr test"
9312
9313 test_120e() {
9314         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9315         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9316                 { skip "no early lock cancel on server"; return 0; }
9317         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9318         local dlmtrace_set=false
9319
9320         test_mkdir -c1 $DIR/$tdir
9321         lru_resize_disable mdc
9322         lru_resize_disable osc
9323         ! $LCTL get_param debug | grep -q dlmtrace &&
9324                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
9325         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
9326         cancel_lru_locks mdc
9327         cancel_lru_locks osc
9328         dd if=$DIR/$tdir/f1 of=/dev/null
9329         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
9330         # XXX client can not do early lock cancel of OST lock
9331         # during unlink (LU-4206), so cancel osc lock now.
9332         sleep 2
9333         cancel_lru_locks osc
9334         can1=$(do_facet $SINGLEMDS \
9335                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9336                awk '/ldlm_cancel/ {print $2}')
9337         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9338                awk '/ldlm_bl_callback/ {print $2}')
9339         unlink $DIR/$tdir/f1
9340         sleep 5
9341         can2=$(do_facet $SINGLEMDS \
9342                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9343                awk '/ldlm_cancel/ {print $2}')
9344         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9345                awk '/ldlm_bl_callback/ {print $2}')
9346         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
9347                 $LCTL dk $TMP/cancel.debug.txt
9348         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
9349                 $LCTL dk $TMP/blocking.debug.txt
9350         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
9351         lru_resize_enable mdc
9352         lru_resize_enable osc
9353 }
9354 run_test 120e "Early Lock Cancel: unlink test"
9355
9356 test_120f() {
9357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9358         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9359                 { skip "no early lock cancel on server"; return 0; }
9360         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9361         test_mkdir -c1 $DIR/$tdir
9362         lru_resize_disable mdc
9363         lru_resize_disable osc
9364         test_mkdir -c1 $DIR/$tdir/d1
9365         test_mkdir -c1 $DIR/$tdir/d2
9366         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
9367         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
9368         cancel_lru_locks mdc
9369         cancel_lru_locks osc
9370         dd if=$DIR/$tdir/d1/f1 of=/dev/null
9371         dd if=$DIR/$tdir/d2/f2 of=/dev/null
9372         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
9373         # XXX client can not do early lock cancel of OST lock
9374         # during rename (LU-4206), so cancel osc lock now.
9375         sleep 2
9376         cancel_lru_locks osc
9377         can1=$(do_facet $SINGLEMDS \
9378                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9379                awk '/ldlm_cancel/ {print $2}')
9380         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9381                awk '/ldlm_bl_callback/ {print $2}')
9382         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
9383         sleep 5
9384         can2=$(do_facet $SINGLEMDS \
9385                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9386                awk '/ldlm_cancel/ {print $2}')
9387         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9388                awk '/ldlm_bl_callback/ {print $2}')
9389         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
9390         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
9391         lru_resize_enable mdc
9392         lru_resize_enable osc
9393 }
9394 run_test 120f "Early Lock Cancel: rename test"
9395
9396 test_120g() {
9397         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9398         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
9399                 { skip "no early lock cancel on server"; return 0; }
9400         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9401         lru_resize_disable mdc
9402         lru_resize_disable osc
9403         count=10000
9404         echo create $count files
9405         test_mkdir $DIR/$tdir
9406         cancel_lru_locks mdc
9407         cancel_lru_locks osc
9408         t0=$(date +%s)
9409
9410         can0=$(do_facet $SINGLEMDS \
9411                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9412                awk '/ldlm_cancel/ {print $2}')
9413         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9414                awk '/ldlm_bl_callback/ {print $2}')
9415         createmany -o $DIR/$tdir/f $count
9416         sync
9417         can1=$(do_facet $SINGLEMDS \
9418                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9419                awk '/ldlm_cancel/ {print $2}')
9420         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9421                awk '/ldlm_bl_callback/ {print $2}')
9422         t1=$(date +%s)
9423         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
9424         echo rm $count files
9425         rm -r $DIR/$tdir
9426         sync
9427         can2=$(do_facet $SINGLEMDS \
9428                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
9429                awk '/ldlm_cancel/ {print $2}')
9430         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
9431                awk '/ldlm_bl_callback/ {print $2}')
9432         t2=$(date +%s)
9433         echo total: $count removes in $((t2-t1))
9434         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
9435         sleep 2
9436         # wait for commitment of removal
9437         lru_resize_enable mdc
9438         lru_resize_enable osc
9439 }
9440 run_test 120g "Early Lock Cancel: performance test"
9441
9442 test_121() { #bug #10589
9443         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9444         rm -rf $DIR/$tfile
9445         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
9446 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
9447         lctl set_param fail_loc=0x310
9448         cancel_lru_locks osc > /dev/null
9449         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
9450         lctl set_param fail_loc=0
9451         [[ $reads -eq $writes ]] ||
9452                 error "read $reads blocks, must be $writes blocks"
9453 }
9454 run_test 121 "read cancel race ========="
9455
9456 test_123a() { # was test 123, statahead(bug 11401)
9457         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9458         SLOWOK=0
9459         if ! grep -q "processor.*: 1" /proc/cpuinfo; then
9460                 log "testing UP system. Performance may be lower than expected."
9461                 SLOWOK=1
9462         fi
9463
9464         rm -rf $DIR/$tdir
9465         test_mkdir $DIR/$tdir
9466         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
9467         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
9468         MULT=10
9469         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
9470                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
9471
9472                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
9473                 lctl set_param -n llite.*.statahead_max 0
9474                 lctl get_param llite.*.statahead_max
9475                 cancel_lru_locks mdc
9476                 cancel_lru_locks osc
9477                 stime=`date +%s`
9478                 time ls -l $DIR/$tdir | wc -l
9479                 etime=`date +%s`
9480                 delta=$((etime - stime))
9481                 log "ls $i files without statahead: $delta sec"
9482                 lctl set_param llite.*.statahead_max=$max
9483
9484                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
9485                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
9486                 cancel_lru_locks mdc
9487                 cancel_lru_locks osc
9488                 stime=`date +%s`
9489                 time ls -l $DIR/$tdir | wc -l
9490                 etime=`date +%s`
9491                 delta_sa=$((etime - stime))
9492                 log "ls $i files with statahead: $delta_sa sec"
9493                 lctl get_param -n llite.*.statahead_stats
9494                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
9495
9496                 [[ $swrong -lt $ewrong ]] &&
9497                         log "statahead was stopped, maybe too many locks held!"
9498                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
9499
9500                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
9501                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
9502                     lctl set_param -n llite.*.statahead_max 0
9503                     lctl get_param llite.*.statahead_max
9504                     cancel_lru_locks mdc
9505                     cancel_lru_locks osc
9506                     stime=`date +%s`
9507                     time ls -l $DIR/$tdir | wc -l
9508                     etime=`date +%s`
9509                     delta=$((etime - stime))
9510                     log "ls $i files again without statahead: $delta sec"
9511                     lctl set_param llite.*.statahead_max=$max
9512                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
9513                         if [  $SLOWOK -eq 0 ]; then
9514                                 error "ls $i files is slower with statahead!"
9515                         else
9516                                 log "ls $i files is slower with statahead!"
9517                         fi
9518                         break
9519                     fi
9520                 fi
9521
9522                 [ $delta -gt 20 ] && break
9523                 [ $delta -gt 8 ] && MULT=$((50 / delta))
9524                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
9525         done
9526         log "ls done"
9527
9528         stime=`date +%s`
9529         rm -r $DIR/$tdir
9530         sync
9531         etime=`date +%s`
9532         delta=$((etime - stime))
9533         log "rm -r $DIR/$tdir/: $delta seconds"
9534         log "rm done"
9535         lctl get_param -n llite.*.statahead_stats
9536 }
9537 run_test 123a "verify statahead work"
9538
9539 test_123b () { # statahead(bug 15027)
9540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9541         test_mkdir $DIR/$tdir
9542         createmany -o $DIR/$tdir/$tfile-%d 1000
9543
9544         cancel_lru_locks mdc
9545         cancel_lru_locks osc
9546
9547 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
9548         lctl set_param fail_loc=0x80000803
9549         ls -lR $DIR/$tdir > /dev/null
9550         log "ls done"
9551         lctl set_param fail_loc=0x0
9552         lctl get_param -n llite.*.statahead_stats
9553         rm -r $DIR/$tdir
9554         sync
9555
9556 }
9557 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
9558
9559 test_124a() {
9560         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9561         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
9562                 { skip "no lru resize on server"; return 0; }
9563         local NR=2000
9564         test_mkdir $DIR/$tdir
9565
9566         log "create $NR files at $DIR/$tdir"
9567         createmany -o $DIR/$tdir/f $NR ||
9568                 error "failed to create $NR files in $DIR/$tdir"
9569
9570         cancel_lru_locks mdc
9571         ls -l $DIR/$tdir > /dev/null
9572
9573         local NSDIR=""
9574         local LRU_SIZE=0
9575         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
9576                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
9577                 LRU_SIZE=$($LCTL get_param -n $PARAM)
9578                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
9579                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
9580                         log "NSDIR=$NSDIR"
9581                         log "NS=$(basename $NSDIR)"
9582                         break
9583                 fi
9584         done
9585
9586         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
9587                 skip "Not enough cached locks created!"
9588                 return 0
9589         fi
9590         log "LRU=$LRU_SIZE"
9591
9592         local SLEEP=30
9593
9594         # We know that lru resize allows one client to hold $LIMIT locks
9595         # for 10h. After that locks begin to be killed by client.
9596         local MAX_HRS=10
9597         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
9598         log "LIMIT=$LIMIT"
9599         if [ $LIMIT -lt $LRU_SIZE ]; then
9600             skip "Limit is too small $LIMIT"
9601             return 0
9602         fi
9603
9604         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
9605         # killing locks. Some time was spent for creating locks. This means
9606         # that up to the moment of sleep finish we must have killed some of
9607         # them (10-100 locks). This depends on how fast ther were created.
9608         # Many of them were touched in almost the same moment and thus will
9609         # be killed in groups.
9610         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
9611
9612         # Use $LRU_SIZE_B here to take into account real number of locks
9613         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
9614         local LRU_SIZE_B=$LRU_SIZE
9615         log "LVF=$LVF"
9616         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
9617         log "OLD_LVF=$OLD_LVF"
9618         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
9619
9620         # Let's make sure that we really have some margin. Client checks
9621         # cached locks every 10 sec.
9622         SLEEP=$((SLEEP+20))
9623         log "Sleep ${SLEEP} sec"
9624         local SEC=0
9625         while ((SEC<$SLEEP)); do
9626                 echo -n "..."
9627                 sleep 5
9628                 SEC=$((SEC+5))
9629                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
9630                 echo -n "$LRU_SIZE"
9631         done
9632         echo ""
9633         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
9634         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
9635
9636         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
9637                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
9638                 unlinkmany $DIR/$tdir/f $NR
9639                 return
9640         }
9641
9642         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
9643         log "unlink $NR files at $DIR/$tdir"
9644         unlinkmany $DIR/$tdir/f $NR
9645 }
9646 run_test 124a "lru resize ======================================="
9647
9648 get_max_pool_limit()
9649 {
9650         local limit=$($LCTL get_param \
9651                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
9652         local max=0
9653         for l in $limit; do
9654                 if [[ $l -gt $max ]]; then
9655                         max=$l
9656                 fi
9657         done
9658         echo $max
9659 }
9660
9661 test_124b() {
9662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9663         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
9664                 { skip "no lru resize on server"; return 0; }
9665
9666         LIMIT=$(get_max_pool_limit)
9667
9668         NR=$(($(default_lru_size)*20))
9669         if [[ $NR -gt $LIMIT ]]; then
9670                 log "Limit lock number by $LIMIT locks"
9671                 NR=$LIMIT
9672         fi
9673
9674         IFree=$(mdsrate_inodes_available)
9675         if [ $IFree -lt $NR ]; then
9676                 log "Limit lock number by $IFree inodes"
9677                 NR=$IFree
9678         fi
9679
9680         lru_resize_disable mdc
9681         test_mkdir -p $DIR/$tdir/disable_lru_resize
9682
9683         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
9684         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
9685         cancel_lru_locks mdc
9686         stime=`date +%s`
9687         PID=""
9688         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9689         PID="$PID $!"
9690         sleep 2
9691         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9692         PID="$PID $!"
9693         sleep 2
9694         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9695         PID="$PID $!"
9696         wait $PID
9697         etime=`date +%s`
9698         nolruresize_delta=$((etime-stime))
9699         log "ls -la time: $nolruresize_delta seconds"
9700         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9701         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
9702
9703         lru_resize_enable mdc
9704         test_mkdir -p $DIR/$tdir/enable_lru_resize
9705
9706         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
9707         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
9708         cancel_lru_locks mdc
9709         stime=`date +%s`
9710         PID=""
9711         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9712         PID="$PID $!"
9713         sleep 2
9714         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9715         PID="$PID $!"
9716         sleep 2
9717         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9718         PID="$PID $!"
9719         wait $PID
9720         etime=`date +%s`
9721         lruresize_delta=$((etime-stime))
9722         log "ls -la time: $lruresize_delta seconds"
9723         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9724
9725         if [ $lruresize_delta -gt $nolruresize_delta ]; then
9726                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
9727         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
9728                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
9729         else
9730                 log "lru resize performs the same with no lru resize"
9731         fi
9732         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
9733 }
9734 run_test 124b "lru resize (performance test) ======================="
9735
9736 test_124c() {
9737         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9738         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
9739                 { skip "no lru resize on server"; return 0; }
9740
9741         # cache ununsed locks on client
9742         local nr=100
9743         cancel_lru_locks mdc
9744         test_mkdir $DIR/$tdir
9745         createmany -o $DIR/$tdir/f $nr ||
9746                 error "failed to create $nr files in $DIR/$tdir"
9747         ls -l $DIR/$tdir > /dev/null
9748
9749         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9750         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9751         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
9752         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
9753         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
9754
9755         # set lru_max_age to 1 sec
9756         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
9757         echo "sleep $((recalc_p * 2)) seconds..."
9758         sleep $((recalc_p * 2))
9759
9760         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
9761         # restore lru_max_age
9762         $LCTL set_param -n $nsdir.lru_max_age $max_age
9763         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
9764         unlinkmany $DIR/$tdir/f $nr
9765 }
9766 run_test 124c "LRUR cancel very aged locks"
9767
9768 test_125() { # 13358
9769         $LCTL get_param -n llite.*.client_type | grep -q local ||
9770                 { skip "must run as local client"; return; }
9771         $LCTL get_param -n mdc.*-mdc-*.connect_flags | grep -q acl ||
9772                 { skip "must have acl enabled"; return; }
9773         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9774         test_mkdir $DIR/$tdir
9775         $LFS setstripe -S 65536 -c -1 $DIR/$tdir || error "setstripe failed"
9776         setfacl -R -m u:bin:rwx $DIR/$tdir || error "setfacl $DIR/$tdir failed"
9777         ls -ld $DIR/$tdir || error "cannot access $DIR/$tdir"
9778 }
9779 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
9780
9781 test_126() { # bug 12829/13455
9782         $LCTL get_param -n llite.*.client_type | grep -q local ||
9783                 { skip "must run as local client"; return; }
9784         [ "$UID" != 0 ] && skip_env "$TESTNAME (must run as root)" && return
9785         $GSS && skip "must run as gss disabled" && return
9786
9787         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
9788         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
9789         rm -f $DIR/$tfile
9790         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
9791 }
9792 run_test 126 "check that the fsgid provided by the client is taken into account"
9793
9794 test_127a() { # bug 15521
9795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9796         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
9797         $LCTL set_param osc.*.stats=0
9798         FSIZE=$((2048 * 1024))
9799         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9800         cancel_lru_locks osc
9801         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
9802
9803         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
9804         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9805                 echo "got $COUNT $NAME"
9806                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
9807                 eval $NAME=$COUNT || error "Wrong proc format"
9808
9809                 case $NAME in
9810                         read_bytes|write_bytes)
9811                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
9812                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
9813                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
9814                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
9815                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
9816                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
9817                                 error "sumsquare is too small: $SUMSQ"
9818                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
9819                                 error "sumsquare is too big: $SUMSQ"
9820                         ;;
9821                         *) ;;
9822                 esac
9823         done < $DIR/${tfile}.tmp
9824
9825         #check that we actually got some stats
9826         [ "$read_bytes" ] || error "Missing read_bytes stats"
9827         [ "$write_bytes" ] || error "Missing write_bytes stats"
9828         [ "$read_bytes" != 0 ] || error "no read done"
9829         [ "$write_bytes" != 0 ] || error "no write done"
9830 }
9831 run_test 127a "verify the client stats are sane"
9832
9833 test_127b() { # bug LU-333
9834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9835         $LCTL set_param llite.*.stats=0
9836         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
9837         # perform 2 reads and writes so MAX is different from SUM.
9838         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9839         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9840         cancel_lru_locks osc
9841         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9842         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9843
9844         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
9845         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9846                 echo "got $COUNT $NAME"
9847                 eval $NAME=$COUNT || error "Wrong proc format"
9848
9849         case $NAME in
9850                 read_bytes)
9851                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9852                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9853                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9854                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9855                         ;;
9856                 write_bytes)
9857                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9858                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9859                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9860                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9861                         ;;
9862                         *) ;;
9863                 esac
9864         done < $TMP/${tfile}.tmp
9865
9866         #check that we actually got some stats
9867         [ "$read_bytes" ] || error "Missing read_bytes stats"
9868         [ "$write_bytes" ] || error "Missing write_bytes stats"
9869         [ "$read_bytes" != 0 ] || error "no read done"
9870         [ "$write_bytes" != 0 ] || error "no write done"
9871
9872         rm -f $TMP/${tfile}.tmp
9873 }
9874 run_test 127b "verify the llite client stats are sane"
9875
9876 test_128() { # bug 15212
9877         touch $DIR/$tfile
9878         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
9879                 find $DIR/$tfile
9880                 find $DIR/$tfile
9881         EOF
9882
9883         result=$(grep error $TMP/$tfile.log)
9884         rm -f $DIR/$tfile $TMP/$tfile.log
9885         [ -z "$result" ] ||
9886                 error "consecutive find's under interactive lfs failed"
9887 }
9888 run_test 128 "interactive lfs for 2 consecutive find's"
9889
9890 set_dir_limits () {
9891         local mntdev
9892         local canondev
9893         local node
9894
9895         local ldproc=/proc/fs/ldiskfs
9896         local facets=$(get_facets MDS)
9897
9898         for facet in ${facets//,/ }; do
9899                 canondev=$(ldiskfs_canon \
9900                            *.$(convert_facet2label $facet).mntdev $facet)
9901                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
9902                         ldproc=/sys/fs/ldiskfs
9903                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
9904                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
9905         done
9906 }
9907
9908 check_mds_dmesg() {
9909         local facets=$(get_facets MDS)
9910         for facet in ${facets//,/ }; do
9911                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
9912         done
9913         return 1
9914 }
9915
9916 test_129() {
9917         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
9918                 { skip "Need MDS version with at least 2.5.56"; return 0; }
9919
9920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9921         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
9922                 skip "ldiskfs only test"
9923                 return
9924         fi
9925         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9926         local ENOSPC=28
9927         local EFBIG=27
9928         local has_warning=false
9929
9930         rm -rf $DIR/$tdir
9931         mkdir -p $DIR/$tdir
9932
9933         # block size of mds1
9934         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
9935         set_dir_limits $maxsize $maxsize
9936         local dirsize=$(stat -c%s "$DIR/$tdir")
9937         local nfiles=0
9938         while [[ $dirsize -le $maxsize ]]; do
9939                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
9940                 rc=$?
9941                 if ! $has_warning; then
9942                         check_mds_dmesg '"is approaching"' && has_warning=true
9943                 fi
9944                 # check two errors:
9945                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
9946                 # EFBIG for previous versions included in ldiskfs series
9947                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
9948                         set_dir_limits 0 0
9949                         echo "return code $rc received as expected"
9950
9951                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
9952                                 error_exit "create failed w/o dir size limit"
9953
9954                         check_mds_dmesg '"has reached"' ||
9955                                 error_exit "reached message should be output"
9956
9957                         [ $has_warning = "false" ] &&
9958                                 error_exit "warning message should be output"
9959
9960                         dirsize=$(stat -c%s "$DIR/$tdir")
9961
9962                         [[ $dirsize -ge $maxsize ]] && return 0
9963                         error_exit "current dir size $dirsize, " \
9964                                    "previous limit $maxsize"
9965                 elif [ $rc -ne 0 ]; then
9966                         set_dir_limits 0 0
9967                         error_exit "return $rc received instead of expected " \
9968                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
9969                 fi
9970                 nfiles=$((nfiles + 1))
9971                 dirsize=$(stat -c%s "$DIR/$tdir")
9972         done
9973
9974         set_dir_limits 0 0
9975         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
9976 }
9977 run_test 129 "test directory size limit ========================"
9978
9979 OLDIFS="$IFS"
9980 cleanup_130() {
9981         trap 0
9982         IFS="$OLDIFS"
9983 }
9984
9985 test_130a() {
9986         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9987         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9988                 return
9989
9990         trap cleanup_130 EXIT RETURN
9991
9992         local fm_file=$DIR/$tfile
9993         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
9994         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
9995                 error "dd failed for $fm_file"
9996
9997         # LU-1795: test filefrag/FIEMAP once, even if unsupported
9998         filefrag -ves $fm_file
9999         RC=$?
10000         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10001                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
10002         [ $RC != 0 ] && error "filefrag $fm_file failed"
10003
10004         filefrag_op=$(filefrag -ve -k $fm_file |
10005                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10006         lun=$($GETSTRIPE -i $fm_file)
10007
10008         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
10009         IFS=$'\n'
10010         tot_len=0
10011         for line in $filefrag_op
10012         do
10013                 frag_lun=`echo $line | cut -d: -f5`
10014                 ext_len=`echo $line | cut -d: -f4`
10015                 if (( $frag_lun != $lun )); then
10016                         cleanup_130
10017                         error "FIEMAP on 1-stripe file($fm_file) failed"
10018                         return
10019                 fi
10020                 (( tot_len += ext_len ))
10021         done
10022
10023         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
10024                 cleanup_130
10025                 error "FIEMAP on 1-stripe file($fm_file) failed;"
10026                 return
10027         fi
10028
10029         cleanup_130
10030
10031         echo "FIEMAP on single striped file succeeded"
10032 }
10033 run_test 130a "FIEMAP (1-stripe file)"
10034
10035 test_130b() {
10036         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
10037
10038         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10039         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
10040                 return
10041
10042         trap cleanup_130 EXIT RETURN
10043
10044         local fm_file=$DIR/$tfile
10045         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
10046                         error "setstripe on $fm_file"
10047         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10048                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
10049
10050         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
10051                 error "dd failed on $fm_file"
10052
10053         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10054         filefrag_op=$(filefrag -ve -k $fm_file |
10055                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10056
10057         last_lun=$(echo $filefrag_op | cut -d: -f5 |
10058                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10059
10060         IFS=$'\n'
10061         tot_len=0
10062         num_luns=1
10063         for line in $filefrag_op
10064         do
10065                 frag_lun=$(echo $line | cut -d: -f5 |
10066                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10067                 ext_len=$(echo $line | cut -d: -f4)
10068                 if (( $frag_lun != $last_lun )); then
10069                         if (( tot_len != 1024 )); then
10070                                 cleanup_130
10071                                 error "FIEMAP on $fm_file failed; returned " \
10072                                 "len $tot_len for OST $last_lun instead of 1024"
10073                                 return
10074                         else
10075                                 (( num_luns += 1 ))
10076                                 tot_len=0
10077                         fi
10078                 fi
10079                 (( tot_len += ext_len ))
10080                 last_lun=$frag_lun
10081         done
10082         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
10083                 cleanup_130
10084                 error "FIEMAP on $fm_file failed; returned wrong number of " \
10085                         "luns or wrong len for OST $last_lun"
10086                 return
10087         fi
10088
10089         cleanup_130
10090
10091         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
10092 }
10093 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
10094
10095 test_130c() {
10096         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
10097
10098         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10099         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
10100                 return
10101
10102         trap cleanup_130 EXIT RETURN
10103
10104         local fm_file=$DIR/$tfile
10105         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
10106         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10107                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
10108
10109         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
10110                         error "dd failed on $fm_file"
10111
10112         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10113         filefrag_op=$(filefrag -ve -k $fm_file |
10114                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10115
10116         last_lun=$(echo $filefrag_op | cut -d: -f5 |
10117                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10118
10119         IFS=$'\n'
10120         tot_len=0
10121         num_luns=1
10122         for line in $filefrag_op
10123         do
10124                 frag_lun=$(echo $line | cut -d: -f5 |
10125                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10126                 ext_len=$(echo $line | cut -d: -f4)
10127                 if (( $frag_lun != $last_lun )); then
10128                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
10129                         if (( logical != 512 )); then
10130                                 cleanup_130
10131                                 error "FIEMAP on $fm_file failed; returned " \
10132                                 "logical start for lun $logical instead of 512"
10133                                 return
10134                         fi
10135                         if (( tot_len != 512 )); then
10136                                 cleanup_130
10137                                 error "FIEMAP on $fm_file failed; returned " \
10138                                 "len $tot_len for OST $last_lun instead of 1024"
10139                                 return
10140                         else
10141                                 (( num_luns += 1 ))
10142                                 tot_len=0
10143                         fi
10144                 fi
10145                 (( tot_len += ext_len ))
10146                 last_lun=$frag_lun
10147         done
10148         if (( num_luns != 2 || tot_len != 512 )); then
10149                 cleanup_130
10150                 error "FIEMAP on $fm_file failed; returned wrong number of " \
10151                         "luns or wrong len for OST $last_lun"
10152                 return
10153         fi
10154
10155         cleanup_130
10156
10157         echo "FIEMAP on 2-stripe file with hole succeeded"
10158 }
10159 run_test 130c "FIEMAP (2-stripe file with hole)"
10160
10161 test_130d() {
10162         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
10163
10164         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10165         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
10166                 return
10167
10168         trap cleanup_130 EXIT RETURN
10169
10170         local fm_file=$DIR/$tfile
10171         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
10172                         error "setstripe on $fm_file"
10173         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10174                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
10175
10176         local actual_stripe_count=$($GETSTRIPE -c $fm_file)
10177         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripe_count ||
10178                 error "dd failed on $fm_file"
10179
10180         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10181         filefrag_op=$(filefrag -ve -k $fm_file |
10182                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10183
10184         last_lun=$(echo $filefrag_op | cut -d: -f5 |
10185                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10186
10187         IFS=$'\n'
10188         tot_len=0
10189         num_luns=1
10190         for line in $filefrag_op
10191         do
10192                 frag_lun=$(echo $line | cut -d: -f5 |
10193                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10194                 ext_len=$(echo $line | cut -d: -f4)
10195                 if (( $frag_lun != $last_lun )); then
10196                         if (( tot_len != 1024 )); then
10197                                 cleanup_130
10198                                 error "FIEMAP on $fm_file failed; returned " \
10199                                 "len $tot_len for OST $last_lun instead of 1024"
10200                                 return
10201                         else
10202                                 (( num_luns += 1 ))
10203                                 tot_len=0
10204                         fi
10205                 fi
10206                 (( tot_len += ext_len ))
10207                 last_lun=$frag_lun
10208         done
10209         if (( num_luns != actual_stripe_count || tot_len != 1024 )); then
10210                 cleanup_130
10211                 error "FIEMAP on $fm_file failed; returned wrong number of " \
10212                         "luns or wrong len for OST $last_lun"
10213                 return
10214         fi
10215
10216         cleanup_130
10217
10218         echo "FIEMAP on N-stripe file succeeded"
10219 }
10220 run_test 130d "FIEMAP (N-stripe file)"
10221
10222 test_130e() {
10223         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
10224
10225         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10226         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
10227
10228         trap cleanup_130 EXIT RETURN
10229
10230         local fm_file=$DIR/$tfile
10231         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
10232         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
10233                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
10234
10235         NUM_BLKS=512
10236         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
10237         for ((i = 0; i < $NUM_BLKS; i++))
10238         do
10239                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
10240         done
10241
10242         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10243         filefrag_op=$(filefrag -ve -k $fm_file |
10244                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
10245
10246         last_lun=$(echo $filefrag_op | cut -d: -f5 |
10247                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10248
10249         IFS=$'\n'
10250         tot_len=0
10251         num_luns=1
10252         for line in $filefrag_op
10253         do
10254                 frag_lun=$(echo $line | cut -d: -f5 |
10255                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
10256                 ext_len=$(echo $line | cut -d: -f4)
10257                 if (( $frag_lun != $last_lun )); then
10258                         if (( tot_len != $EXPECTED_LEN )); then
10259                                 cleanup_130
10260                                 error "FIEMAP on $fm_file failed; returned " \
10261                                 "len $tot_len for OST $last_lun instead " \
10262                                 "of $EXPECTED_LEN"
10263                                 return
10264                         else
10265                                 (( num_luns += 1 ))
10266                                 tot_len=0
10267                         fi
10268                 fi
10269                 (( tot_len += ext_len ))
10270                 last_lun=$frag_lun
10271         done
10272         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
10273                 cleanup_130
10274                 error "FIEMAP on $fm_file failed; returned wrong number " \
10275                         "of luns or wrong len for OST $last_lun"
10276                 return
10277         fi
10278
10279         cleanup_130
10280
10281         echo "FIEMAP with continuation calls succeeded"
10282 }
10283 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
10284
10285 test_130f() {
10286         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
10287         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
10288                 return
10289
10290         local fm_file=$DIR/$tfile
10291         $MULTIOP $fm_file oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T33554432c ||
10292                 error "multiop create with lov_delay_create on $fm_file"
10293
10294         filefrag -ves $fm_file || error "filefrag $fm_file failed"
10295         filefrag_extents=$(filefrag -vek $fm_file |
10296                            awk '/extents? found/ { print $2 }')
10297         if [[ "$filefrag_extents" != "0" ]]; then
10298                 error "FIEMAP on $fm_file failed; " \
10299                       "returned $filefrag_extents expected 0"
10300         fi
10301
10302         rm -f $fm_file
10303 }
10304 run_test 130f "FIEMAP (unstriped file)"
10305
10306 # Test for writev/readv
10307 test_131a() {
10308         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
10309                 error "writev test failed"
10310         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
10311                 error "readv failed"
10312         rm -f $DIR/$tfile
10313 }
10314 run_test 131a "test iov's crossing stripe boundary for writev/readv"
10315
10316 test_131b() {
10317         local fsize=$((524288 + 1048576 + 1572864))
10318         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
10319                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
10320                         error "append writev test failed"
10321
10322         ((fsize += 1572864 + 1048576))
10323         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
10324                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
10325                         error "append writev test failed"
10326         rm -f $DIR/$tfile
10327 }
10328 run_test 131b "test append writev"
10329
10330 test_131c() {
10331         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
10332         error "NOT PASS"
10333 }
10334 run_test 131c "test read/write on file w/o objects"
10335
10336 test_131d() {
10337         rwv -f $DIR/$tfile -w -n 1 1572864
10338         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
10339         if [ "$NOB" != 1572864 ]; then
10340                 error "Short read filed: read $NOB bytes instead of 1572864"
10341         fi
10342         rm -f $DIR/$tfile
10343 }
10344 run_test 131d "test short read"
10345
10346 test_131e() {
10347         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
10348         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
10349         error "read hitting hole failed"
10350         rm -f $DIR/$tfile
10351 }
10352 run_test 131e "test read hitting hole"
10353
10354 check_stats() {
10355         local facet=$1
10356         local op=$2
10357         local want=${3:-0}
10358         local res
10359
10360         case $facet in
10361         mds*) res=$(do_facet $facet \
10362                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
10363                  ;;
10364         ost*) res=$(do_facet $facet \
10365                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
10366                  ;;
10367         *) error "Wrong facet '$facet'" ;;
10368         esac
10369         echo $res
10370         [ "$res" ] || error "The counter for $op on $facet was not incremented"
10371         # if the argument $3 is zero, it means any stat increment is ok.
10372         if [[ $want -gt 0 ]]; then
10373                 local count=$(echo $res | awk '{ print $2 }')
10374                 [[ $count -ne $want ]] &&
10375                         error "The $op counter on $facet is $count, not $want"
10376         fi
10377 }
10378
10379 test_133a() {
10380         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10381         remote_ost_nodsh && skip "remote OST with nodsh" && return
10382         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10383
10384         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
10385                 { skip "MDS doesn't support rename stats"; return; }
10386         local testdir=$DIR/${tdir}/stats_testdir
10387         mkdir -p $DIR/${tdir}
10388
10389         # clear stats.
10390         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10391         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10392
10393         # verify mdt stats first.
10394         mkdir ${testdir} || error "mkdir failed"
10395         check_stats $SINGLEMDS "mkdir" 1
10396         touch ${testdir}/${tfile} || error "touch failed"
10397         check_stats $SINGLEMDS "open" 1
10398         check_stats $SINGLEMDS "close" 1
10399         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
10400                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
10401                 check_stats $SINGLEMDS "mknod" 2
10402         }
10403         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
10404         check_stats $SINGLEMDS "unlink" 1
10405         rm -f ${testdir}/${tfile} || error "file remove failed"
10406         check_stats $SINGLEMDS "unlink" 2
10407
10408         # remove working dir and check mdt stats again.
10409         rmdir ${testdir} || error "rmdir failed"
10410         check_stats $SINGLEMDS "rmdir" 1
10411
10412         local testdir1=$DIR/${tdir}/stats_testdir1
10413         mkdir -p ${testdir}
10414         mkdir -p ${testdir1}
10415         touch ${testdir1}/test1
10416         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
10417         check_stats $SINGLEMDS "crossdir_rename" 1
10418
10419         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
10420         check_stats $SINGLEMDS "samedir_rename" 1
10421
10422         rm -rf $DIR/${tdir}
10423 }
10424 run_test 133a "Verifying MDT stats ========================================"
10425
10426 test_133b() {
10427         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10428         remote_ost_nodsh && skip "remote OST with nodsh" && return
10429         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10430         local testdir=$DIR/${tdir}/stats_testdir
10431         mkdir -p ${testdir} || error "mkdir failed"
10432         touch ${testdir}/${tfile} || error "touch failed"
10433         cancel_lru_locks mdc
10434
10435         # clear stats.
10436         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10437         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10438
10439         # extra mdt stats verification.
10440         chmod 444 ${testdir}/${tfile} || error "chmod failed"
10441         check_stats $SINGLEMDS "setattr" 1
10442         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10443         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
10444         then            # LU-1740
10445                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
10446                 check_stats $SINGLEMDS "getattr" 1
10447         fi
10448         $LFS df || error "lfs failed"
10449         check_stats $SINGLEMDS "statfs" 1
10450
10451         rm -rf $DIR/${tdir}
10452 }
10453 run_test 133b "Verifying extra MDT stats =================================="
10454
10455 test_133c() {
10456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10457         remote_ost_nodsh && skip "remote OST with nodsh" && return
10458         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10459         local testdir=$DIR/$tdir/stats_testdir
10460         test_mkdir -p $testdir
10461
10462         # verify obdfilter stats.
10463         $SETSTRIPE -c 1 -i 0 $testdir/$tfile
10464         sync
10465         cancel_lru_locks osc
10466         wait_delete_completed
10467
10468         # clear stats.
10469         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10470         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10471
10472         dd if=/dev/zero of=$testdir/$tfile conv=notrunc bs=512k count=1 ||
10473                 error "dd failed"
10474         sync
10475         cancel_lru_locks osc
10476         check_stats ost1 "write" 1
10477
10478         dd if=$testdir/$tfile of=/dev/null bs=1k count=1 || error "dd failed"
10479         check_stats ost1 "read" 1
10480
10481         > $testdir/$tfile || error "truncate failed"
10482         check_stats ost1 "punch" 1
10483
10484         rm -f $testdir/$tfile || error "file remove failed"
10485         wait_delete_completed
10486         check_stats ost1 "destroy" 1
10487
10488         rm -rf $DIR/$tdir
10489 }
10490 run_test 133c "Verifying OST stats ========================================"
10491
10492 order_2() {
10493         local value=$1
10494         local orig=$value
10495         local order=1
10496
10497         while [ $value -ge 2 ]; do
10498                 order=$((order*2))
10499                 value=$((value/2))
10500         done
10501
10502         if [ $orig -gt $order ]; then
10503                 order=$((order*2))
10504         fi
10505         echo $order
10506 }
10507
10508 size_in_KMGT() {
10509     local value=$1
10510     local size=('K' 'M' 'G' 'T');
10511     local i=0
10512     local size_string=$value
10513
10514     while [ $value -ge 1024 ]; do
10515         if [ $i -gt 3 ]; then
10516             #T is the biggest unit we get here, if that is bigger,
10517             #just return XXXT
10518             size_string=${value}T
10519             break
10520         fi
10521         value=$((value >> 10))
10522         if [ $value -lt 1024 ]; then
10523             size_string=${value}${size[$i]}
10524             break
10525         fi
10526         i=$((i + 1))
10527     done
10528
10529     echo $size_string
10530 }
10531
10532 get_rename_size() {
10533         local size=$1
10534         local context=${2:-.}
10535         local sample=$(do_facet $SINGLEMDS $LCTL \
10536                 get_param mdt.$FSNAME-MDT0000.rename_stats |
10537                 grep -A1 $context |
10538                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
10539         echo $sample
10540 }
10541
10542 test_133d() {
10543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10544         remote_ost_nodsh && skip "remote OST with nodsh" && return
10545         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10546         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
10547         { skip "MDS doesn't support rename stats"; return; }
10548
10549         local testdir1=$DIR/${tdir}/stats_testdir1
10550         local testdir2=$DIR/${tdir}/stats_testdir2
10551         mkdir -p $DIR/${tdir}
10552
10553         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10554
10555         lfs mkdir -i 0 -c 1 ${testdir1} || error "mkdir failed"
10556         lfs mkdir -i 0 -c 1 ${testdir2} || error "mkdir failed"
10557
10558         createmany -o $testdir1/test 512 || error "createmany failed"
10559
10560         # check samedir rename size
10561         mv ${testdir1}/test0 ${testdir1}/test_0
10562
10563         local testdir1_size=$(ls -l $DIR/${tdir} |
10564                 awk '/stats_testdir1/ {print $5}')
10565         local testdir2_size=$(ls -l $DIR/${tdir} |
10566                 awk '/stats_testdir2/ {print $5}')
10567
10568         testdir1_size=$(order_2 $testdir1_size)
10569         testdir2_size=$(order_2 $testdir2_size)
10570
10571         testdir1_size=$(size_in_KMGT $testdir1_size)
10572         testdir2_size=$(size_in_KMGT $testdir2_size)
10573
10574         echo "source rename dir size: ${testdir1_size}"
10575         echo "target rename dir size: ${testdir2_size}"
10576
10577         local cmd="do_facet $SINGLEMDS $LCTL "
10578         cmd+="get_param mdt.$FSNAME-MDT0000.rename_stats"
10579
10580         eval $cmd || error "$cmd failed"
10581         local samedir=$($cmd | grep 'same_dir')
10582         local same_sample=$(get_rename_size $testdir1_size)
10583         [ -z "$samedir" ] && error "samedir_rename_size count error"
10584         [[ $same_sample -eq 1 ]] ||
10585                 error "samedir_rename_size error $same_sample"
10586         echo "Check same dir rename stats success"
10587
10588         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10589
10590         # check crossdir rename size
10591         mv ${testdir1}/test_0 ${testdir2}/test_0
10592
10593         testdir1_size=$(ls -l $DIR/${tdir} |
10594                 awk '/stats_testdir1/ {print $5}')
10595         testdir2_size=$(ls -l $DIR/${tdir} |
10596                 awk '/stats_testdir2/ {print $5}')
10597
10598         testdir1_size=$(order_2 $testdir1_size)
10599         testdir2_size=$(order_2 $testdir2_size)
10600
10601         testdir1_size=$(size_in_KMGT $testdir1_size)
10602         testdir2_size=$(size_in_KMGT $testdir2_size)
10603
10604         echo "source rename dir size: ${testdir1_size}"
10605         echo "target rename dir size: ${testdir2_size}"
10606
10607         eval $cmd || error "$cmd failed"
10608         local crossdir=$($cmd | grep 'crossdir')
10609         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
10610         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
10611         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
10612         [[ $src_sample -eq 1 ]] ||
10613                 error "crossdir_rename_size error $src_sample"
10614         [[ $tgt_sample -eq 1 ]] ||
10615                 error "crossdir_rename_size error $tgt_sample"
10616         echo "Check cross dir rename stats success"
10617         rm -rf $DIR/${tdir}
10618 }
10619 run_test 133d "Verifying rename_stats ========================================"
10620
10621 test_133e() {
10622         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10623         remote_ost_nodsh && skip "remote OST with nodsh" && return
10624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10625         local testdir=$DIR/${tdir}/stats_testdir
10626         local ctr f0 f1 bs=32768 count=42 sum
10627
10628         mkdir -p ${testdir} || error "mkdir failed"
10629
10630         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
10631
10632         for ctr in {write,read}_bytes; do
10633                 sync
10634                 cancel_lru_locks osc
10635
10636                 do_facet ost1 $LCTL set_param -n \
10637                         "obdfilter.*.exports.clear=clear"
10638
10639                 if [ $ctr = write_bytes ]; then
10640                         f0=/dev/zero
10641                         f1=${testdir}/${tfile}
10642                 else
10643                         f0=${testdir}/${tfile}
10644                         f1=/dev/null
10645                 fi
10646
10647                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
10648                         error "dd failed"
10649                 sync
10650                 cancel_lru_locks osc
10651
10652                 sum=$(do_facet ost1 $LCTL get_param \
10653                         "obdfilter.*.exports.*.stats" |
10654                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
10655                                 $1 == ctr { sum += $7 }
10656                                 END { printf("%0.0f", sum) }')
10657
10658                 if ((sum != bs * count)); then
10659                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
10660                 fi
10661         done
10662
10663         rm -rf $DIR/${tdir}
10664 }
10665 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
10666
10667 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
10668
10669 test_133f() {
10670         # First without trusting modes.
10671         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10672         echo "proc_dirs='$proc_dirs'"
10673         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10674         find $proc_dirs -exec cat '{}' \; &> /dev/null
10675
10676         # Second verifying readability.
10677         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
10678
10679         # Verifing writability with badarea_io.
10680         find $proc_dirs \
10681                 -ignore_readdir_race \
10682                 -type f \
10683                 -not -name force_lbug \
10684                 -not -name changelog_mask \
10685                 -exec badarea_io '{}' \; ||
10686                         error "find $proc_dirs failed"
10687 }
10688 run_test 133f "Check reads/writes of client lustre proc files with bad area io"
10689
10690 test_133g() {
10691         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10692         remote_ost_nodsh && skip "remote OST with nodsh" && return
10693
10694         # eventually, this can also be replaced with "lctl get_param -R",
10695         # but not until that option is always available on the server
10696         local facet
10697         for facet in mds1 ost1; do
10698                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
10699                         skip "Too old lustre on $facet" && continue
10700                 local facet_proc_dirs=$(do_facet $facet \
10701                                         \\\ls -d $proc_regexp 2>/dev/null)
10702                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10703                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10704                 do_facet $facet find $facet_proc_dirs \
10705                         ! -name req_history \
10706                         -exec cat '{}' \\\; &> /dev/null
10707
10708                 do_facet $facet find $facet_proc_dirs \
10709                         ! -name req_history \
10710                         -type f \
10711                         -exec cat '{}' \\\; &> /dev/null ||
10712                                 error "proc file read failed"
10713
10714                 do_facet $facet find $facet_proc_dirs \
10715                         -ignore_readdir_race \
10716                         -type f \
10717                         -not -name force_lbug \
10718                         -not -name changelog_mask \
10719                         -exec badarea_io '{}' \\\; ||
10720                                 error "$facet find $facet_proc_dirs failed"
10721         done
10722
10723         # remount the FS in case writes/reads /proc break the FS
10724         cleanup || error "failed to unmount"
10725         setup || error "failed to setup"
10726         true
10727 }
10728 run_test 133g "Check reads/writes of server lustre proc files with bad area io"
10729
10730 test_133h() {
10731         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10732         remote_ost_nodsh && skip "remote OST with nodsh" && return
10733         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
10734                 skip "Need MDS version at least 2.9.54" && return
10735
10736         local facet
10737         for facet in client mds1 ost1; do
10738                 local facet_proc_dirs=$(do_facet $facet \
10739                                         \\\ls -d $proc_regexp 2> /dev/null)
10740                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10741                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10742                 # Get the list of files that are missing the terminating newline
10743                 local missing=($(do_facet $facet \
10744                         find ${facet_proc_dirs} -type f \|              \
10745                                 while read F\; do                       \
10746                                         awk -v FS='\v' -v RS='\v\v'     \
10747                                         "'END { if(NR>0 &&              \
10748                                         \\\$NF !~ /.*\\\n\$/)           \
10749                                                 print FILENAME}'"       \
10750                                         '\$F'\;                         \
10751                                 done 2>/dev/null))
10752                 [ ${#missing[*]} -eq 0 ] ||
10753                         error "files do not end with newline: ${missing[*]}"
10754         done
10755 }
10756 run_test 133h "Proc files should end with newlines"
10757
10758 test_134a() {
10759         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10760         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10761                 skip "Need MDS version at least 2.7.54" && return
10762
10763         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10764         cancel_lru_locks mdc
10765
10766         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
10767         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10768         [ $unused -eq 0 ] || error "$unused locks are not cleared"
10769
10770         local nr=1000
10771         createmany -o $DIR/$tdir/f $nr ||
10772                 error "failed to create $nr files in $DIR/$tdir"
10773         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10774
10775         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
10776         do_facet mds1 $LCTL set_param fail_loc=0x327
10777         do_facet mds1 $LCTL set_param fail_val=500
10778         touch $DIR/$tdir/m
10779
10780         echo "sleep 10 seconds ..."
10781         sleep 10
10782         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
10783
10784         do_facet mds1 $LCTL set_param fail_loc=0
10785         do_facet mds1 $LCTL set_param fail_val=0
10786         [ $lck_cnt -lt $unused ] ||
10787                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
10788
10789         rm $DIR/$tdir/m
10790         unlinkmany $DIR/$tdir/f $nr
10791 }
10792 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
10793
10794 test_134b() {
10795         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10796         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10797                 skip "Need MDS version at least 2.7.54" && return
10798
10799         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10800         cancel_lru_locks mdc
10801
10802         local low_wm=$(do_facet mds1 $LCTL get_param -n \
10803                         ldlm.lock_reclaim_threshold_mb)
10804         # disable reclaim temporarily
10805         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
10806
10807         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
10808         do_facet mds1 $LCTL set_param fail_loc=0x328
10809         do_facet mds1 $LCTL set_param fail_val=500
10810
10811         $LCTL set_param debug=+trace
10812
10813         local nr=600
10814         createmany -o $DIR/$tdir/f $nr &
10815         local create_pid=$!
10816
10817         echo "Sleep $TIMEOUT seconds ..."
10818         sleep $TIMEOUT
10819         if ! ps -p $create_pid  > /dev/null 2>&1; then
10820                 do_facet mds1 $LCTL set_param fail_loc=0
10821                 do_facet mds1 $LCTL set_param fail_val=0
10822                 do_facet mds1 $LCTL set_param \
10823                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
10824                 error "createmany finished incorrectly!"
10825         fi
10826         do_facet mds1 $LCTL set_param fail_loc=0
10827         do_facet mds1 $LCTL set_param fail_val=0
10828         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
10829         wait $create_pid || return 1
10830
10831         unlinkmany $DIR/$tdir/f $nr
10832 }
10833 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
10834
10835 test_140() { #bug-17379
10836         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10837         test_mkdir $DIR/$tdir
10838         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
10839         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
10840
10841         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
10842         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
10843         local i=0
10844         while i=$((i + 1)); do
10845                 test_mkdir $i
10846                 cd $i || error "Changing to $i"
10847                 ln -s ../stat stat || error "Creating stat symlink"
10848                 # Read the symlink until ELOOP present,
10849                 # not LBUGing the system is considered success,
10850                 # we didn't overrun the stack.
10851                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
10852                 if [ $ret -ne 0 ]; then
10853                         if [ $ret -eq 40 ]; then
10854                                 break  # -ELOOP
10855                         else
10856                                 error "Open stat symlink"
10857                                         return
10858                         fi
10859                 fi
10860         done
10861         i=$((i - 1))
10862         echo "The symlink depth = $i"
10863         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
10864                                         error "Invalid symlink depth"
10865
10866         # Test recursive symlink
10867         ln -s symlink_self symlink_self
10868         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
10869         echo "open symlink_self returns $ret"
10870         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
10871 }
10872 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
10873
10874 test_150() {
10875         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10876         local TF="$TMP/$tfile"
10877
10878         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10879         cp $TF $DIR/$tfile
10880         cancel_lru_locks $OSC
10881         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
10882         remount_client $MOUNT
10883         df -P $MOUNT
10884         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
10885
10886         $TRUNCATE $TF 6000
10887         $TRUNCATE $DIR/$tfile 6000
10888         cancel_lru_locks $OSC
10889         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
10890
10891         echo "12345" >>$TF
10892         echo "12345" >>$DIR/$tfile
10893         cancel_lru_locks $OSC
10894         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
10895
10896         echo "12345" >>$TF
10897         echo "12345" >>$DIR/$tfile
10898         cancel_lru_locks $OSC
10899         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
10900
10901         rm -f $TF
10902         true
10903 }
10904 run_test 150 "truncate/append tests"
10905
10906 #LU-2902 roc_hit was not able to read all values from lproc
10907 function roc_hit_init() {
10908         local list=$(comma_list $(osts_nodes))
10909         local dir=$DIR/$tdir-check
10910         local file=$dir/$tfile
10911         local BEFORE
10912         local AFTER
10913         local idx
10914
10915         test_mkdir $dir
10916         #use setstripe to do a write to every ost
10917         for i in $(seq 0 $((OSTCOUNT-1))); do
10918                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
10919                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
10920                 idx=$(printf %04x $i)
10921                 BEFORE=$(get_osd_param $list *OST*$idx stats |
10922                         awk '$1 == "cache_access" {sum += $7}
10923                                 END { printf("%0.0f", sum) }')
10924
10925                 cancel_lru_locks osc
10926                 cat $file >/dev/null
10927
10928                 AFTER=$(get_osd_param $list *OST*$idx stats |
10929                         awk '$1 == "cache_access" {sum += $7}
10930                                 END { printf("%0.0f", sum) }')
10931
10932                 echo BEFORE:$BEFORE AFTER:$AFTER
10933                 if ! let "AFTER - BEFORE == 4"; then
10934                         rm -rf $dir
10935                         error "roc_hit is not safe to use"
10936                 fi
10937                 rm $file
10938         done
10939
10940         rm -rf $dir
10941 }
10942
10943 function roc_hit() {
10944         local list=$(comma_list $(osts_nodes))
10945         echo $(get_osd_param $list '' stats |
10946                 awk '$1 == "cache_hit" {sum += $7}
10947                         END { printf("%0.0f", sum) }')
10948 }
10949
10950 function set_cache() {
10951         local on=1
10952
10953         if [ "$2" == "off" ]; then
10954                 on=0;
10955         fi
10956         local list=$(comma_list $(osts_nodes))
10957         set_osd_param $list '' $1_cache_enable $on
10958
10959         cancel_lru_locks osc
10960 }
10961
10962 test_151() {
10963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10964         remote_ost_nodsh && skip "remote OST with nodsh" && return
10965
10966         local CPAGES=3
10967         local list=$(comma_list $(osts_nodes))
10968
10969         # check whether obdfilter is cache capable at all
10970         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
10971                 echo "not cache-capable obdfilter"
10972                 return 0
10973         fi
10974
10975         # check cache is enabled on all obdfilters
10976         if get_osd_param $list '' read_cache_enable | grep 0; then
10977                 echo "oss cache is disabled"
10978                 return 0
10979         fi
10980
10981         set_osd_param $list '' writethrough_cache_enable 1
10982
10983         # check write cache is enabled on all obdfilters
10984         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
10985                 echo "oss write cache is NOT enabled"
10986                 return 0
10987         fi
10988
10989         roc_hit_init
10990
10991         #define OBD_FAIL_OBD_NO_LRU  0x609
10992         do_nodes $list $LCTL set_param fail_loc=0x609
10993
10994         # pages should be in the case right after write
10995         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
10996                 error "dd failed"
10997
10998         local BEFORE=$(roc_hit)
10999         cancel_lru_locks osc
11000         cat $DIR/$tfile >/dev/null
11001         local AFTER=$(roc_hit)
11002
11003         do_nodes $list $LCTL set_param fail_loc=0
11004
11005         if ! let "AFTER - BEFORE == CPAGES"; then
11006                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11007         fi
11008
11009         # the following read invalidates the cache
11010         cancel_lru_locks osc
11011         set_osd_param $list '' read_cache_enable 0
11012         cat $DIR/$tfile >/dev/null
11013
11014         # now data shouldn't be found in the cache
11015         BEFORE=$(roc_hit)
11016         cancel_lru_locks osc
11017         cat $DIR/$tfile >/dev/null
11018         AFTER=$(roc_hit)
11019         if let "AFTER - BEFORE != 0"; then
11020                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11021         fi
11022
11023         set_osd_param $list '' read_cache_enable 1
11024         rm -f $DIR/$tfile
11025 }
11026 run_test 151 "test cache on oss and controls ==============================="
11027
11028 test_152() {
11029         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11030         local TF="$TMP/$tfile"
11031
11032         # simulate ENOMEM during write
11033 #define OBD_FAIL_OST_NOMEM      0x226
11034         lctl set_param fail_loc=0x80000226
11035         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
11036         cp $TF $DIR/$tfile
11037         sync || error "sync failed"
11038         lctl set_param fail_loc=0
11039
11040         # discard client's cache
11041         cancel_lru_locks osc
11042
11043         # simulate ENOMEM during read
11044         lctl set_param fail_loc=0x80000226
11045         cmp $TF $DIR/$tfile || error "cmp failed"
11046         lctl set_param fail_loc=0
11047
11048         rm -f $TF
11049 }
11050 run_test 152 "test read/write with enomem ============================"
11051
11052 test_153() {
11053         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
11054 }
11055 run_test 153 "test if fdatasync does not crash ======================="
11056
11057 dot_lustre_fid_permission_check() {
11058         local fid=$1
11059         local ffid=$MOUNT/.lustre/fid/$fid
11060         local test_dir=$2
11061
11062         echo "stat fid $fid"
11063         stat $ffid > /dev/null || error "stat $ffid failed."
11064         echo "touch fid $fid"
11065         touch $ffid || error "touch $ffid failed."
11066         echo "write to fid $fid"
11067         cat /etc/hosts > $ffid || error "write $ffid failed."
11068         echo "read fid $fid"
11069         diff /etc/hosts $ffid || error "read $ffid failed."
11070         echo "append write to fid $fid"
11071         cat /etc/hosts >> $ffid || error "append write $ffid failed."
11072         echo "rename fid $fid"
11073         mv $ffid $test_dir/$tfile.1 &&
11074                 error "rename $ffid to $tfile.1 should fail."
11075         touch $test_dir/$tfile.1
11076         mv $test_dir/$tfile.1 $ffid &&
11077                 error "rename $tfile.1 to $ffid should fail."
11078         rm -f $test_dir/$tfile.1
11079         echo "truncate fid $fid"
11080         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
11081         echo "link fid $fid"
11082         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
11083         if [[ $($LCTL get_param -n mdc.*-mdc-*.connect_flags) =~ acl ]]; then
11084                 echo "setfacl fid $fid"
11085                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
11086                 echo "getfacl fid $fid"
11087                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
11088         fi
11089         echo "unlink fid $fid"
11090         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
11091         echo "mknod fid $fid"
11092         mknod $ffid c 1 3 && error "mknod $ffid should fail."
11093
11094         fid=[0xf00000400:0x1:0x0]
11095         ffid=$MOUNT/.lustre/fid/$fid
11096
11097         echo "stat non-exist fid $fid"
11098         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
11099         echo "write to non-exist fid $fid"
11100         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
11101         echo "link new fid $fid"
11102         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
11103
11104         mkdir -p $test_dir/$tdir
11105         touch $test_dir/$tdir/$tfile
11106         fid=$($LFS path2fid $test_dir/$tdir)
11107         rc=$?
11108         [ $rc -ne 0 ] &&
11109                 error "error: could not get fid for $test_dir/$dir/$tfile."
11110
11111         ffid=$MOUNT/.lustre/fid/$fid
11112
11113         echo "ls $fid"
11114         ls $ffid > /dev/null || error "ls $ffid failed."
11115         echo "touch $fid/$tfile.1"
11116         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
11117
11118         echo "touch $MOUNT/.lustre/fid/$tfile"
11119         touch $MOUNT/.lustre/fid/$tfile && \
11120                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
11121
11122         echo "setxattr to $MOUNT/.lustre/fid"
11123         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
11124
11125         echo "listxattr for $MOUNT/.lustre/fid"
11126         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
11127
11128         echo "delxattr from $MOUNT/.lustre/fid"
11129         setfattr -x trusted.name1 $MOUNT/.lustre/fid
11130
11131         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
11132         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
11133                 error "touch invalid fid should fail."
11134
11135         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
11136         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
11137                 error "touch non-normal fid should fail."
11138
11139         echo "rename $tdir to $MOUNT/.lustre/fid"
11140         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
11141                 error "rename to $MOUNT/.lustre/fid should fail."
11142
11143         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
11144         then            # LU-3547
11145                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
11146                 local new_obf_mode=777
11147
11148                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
11149                 chmod $new_obf_mode $DIR/.lustre/fid ||
11150                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
11151
11152                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
11153                 [ $obf_mode -eq $new_obf_mode ] ||
11154                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
11155
11156                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
11157                 chmod $old_obf_mode $DIR/.lustre/fid ||
11158                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
11159         fi
11160
11161         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
11162         fid=$($LFS path2fid $test_dir/$tfile-2)
11163
11164         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
11165         then # LU-5424
11166                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
11167                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
11168                         error "create lov data thru .lustre failed"
11169         fi
11170         echo "cp /etc/passwd $test_dir/$tfile-2"
11171         cp /etc/passwd $test_dir/$tfile-2 ||
11172                 error "copy to $test_dir/$tfile-2 failed."
11173         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
11174         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
11175                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
11176
11177         rm -rf $test_dir/tfile.lnk
11178         rm -rf $test_dir/$tfile-2
11179 }
11180
11181 test_154A() {
11182         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11183                 skip "Need MDS version at least 2.4.1" && return
11184
11185         local tf=$DIR/$tfile
11186         touch $tf
11187
11188         local fid=$($LFS path2fid $tf)
11189         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
11190
11191         # check that we get the same pathname back
11192         local found=$($LFS fid2path $MOUNT "$fid")
11193         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
11194         [ "$found" == "$tf" ] ||
11195                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
11196 }
11197 run_test 154A "lfs path2fid and fid2path basic checks"
11198
11199 test_154B() {
11200         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11201                 skip "Need MDS version at least 2.4.1" && return
11202
11203         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
11204         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
11205         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
11206         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
11207
11208         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
11209         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
11210
11211         # check that we get the same pathname
11212         echo "PFID: $PFID, name: $name"
11213         local FOUND=$($LFS fid2path $MOUNT "$PFID")
11214         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
11215         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
11216                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
11217
11218         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
11219 }
11220 run_test 154B "verify the ll_decode_linkea tool"
11221
11222 test_154a() {
11223         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11224         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
11225                 { skip "Need MDS version at least 2.2.51"; return 0; }
11226         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
11227         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
11228
11229         cp /etc/hosts $DIR/$tfile
11230
11231         fid=$($LFS path2fid $DIR/$tfile)
11232         rc=$?
11233         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
11234
11235         dot_lustre_fid_permission_check "$fid" $DIR ||
11236                 error "dot lustre permission check $fid failed"
11237
11238         ls -a $MOUNT | grep "\.lustre" && error ".lustre should not be listed"
11239
11240         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
11241
11242         touch $MOUNT/.lustre/file &&
11243                 error "creation is not allowed under .lustre"
11244
11245         mkdir $MOUNT/.lustre/dir &&
11246                 error "mkdir is not allowed under .lustre"
11247
11248         rm -rf $DIR/$tfile
11249 }
11250 run_test 154a "Open-by-FID"
11251
11252 test_154b() {
11253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11254         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
11255                 { skip "Need MDS version at least 2.2.51"; return 0; }
11256         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
11257
11258         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11259
11260         local remote_dir=$DIR/$tdir/remote_dir
11261         local MDTIDX=1
11262         local rc=0
11263
11264         mkdir -p $DIR/$tdir
11265         $LFS mkdir -i $MDTIDX $remote_dir ||
11266                 error "create remote directory failed"
11267
11268         cp /etc/hosts $remote_dir/$tfile
11269
11270         fid=$($LFS path2fid $remote_dir/$tfile)
11271         rc=$?
11272         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
11273
11274         dot_lustre_fid_permission_check "$fid" $remote_dir ||
11275                 error "dot lustre permission check $fid failed"
11276         rm -rf $DIR/$tdir
11277 }
11278 run_test 154b "Open-by-FID for remote directory"
11279
11280 test_154c() {
11281         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
11282                 skip "Need MDS version at least 2.4.1" && return
11283
11284         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
11285         local FID1=$($LFS path2fid $DIR/$tfile.1)
11286         local FID2=$($LFS path2fid $DIR/$tfile.2)
11287         local FID3=$($LFS path2fid $DIR/$tfile.3)
11288
11289         local N=1
11290         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
11291                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
11292                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
11293                 local want=FID$N
11294                 [ "$FID" = "${!want}" ] ||
11295                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
11296                 N=$((N + 1))
11297         done
11298
11299         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
11300         do
11301                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
11302                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
11303                 N=$((N + 1))
11304         done
11305 }
11306 run_test 154c "lfs path2fid and fid2path multiple arguments"
11307
11308 test_154d() {
11309         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11310         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
11311                 skip "Need MDS version at least 2.5.53" && return
11312
11313         if remote_mds; then
11314                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
11315         else
11316                 nid="0@lo"
11317         fi
11318         local proc_ofile="mdt.*.exports.'$nid'.open_files"
11319         local fd
11320         local cmd
11321
11322         rm -f $DIR/$tfile
11323         touch $DIR/$tfile
11324
11325         local fid=$($LFS path2fid $DIR/$tfile)
11326         # Open the file
11327         fd=$(free_fd)
11328         cmd="exec $fd<$DIR/$tfile"
11329         eval $cmd
11330         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
11331         echo "$fid_list" | grep "$fid"
11332         rc=$?
11333
11334         cmd="exec $fd>/dev/null"
11335         eval $cmd
11336         if [ $rc -ne 0 ]; then
11337                 error "FID $fid not found in open files list $fid_list"
11338         fi
11339 }
11340 run_test 154d "Verify open file fid"
11341
11342 test_154e()
11343 {
11344         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
11345                 skip "Need MDS version at least 2.6.50" && return
11346
11347         if ls -a $MOUNT | grep -q '^\.lustre$'; then
11348                 error ".lustre returned by readdir"
11349         fi
11350 }
11351 run_test 154e ".lustre is not returned by readdir"
11352
11353 test_154f() {
11354         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
11355         # create parent directory on a single MDT to avoid cross-MDT hardlinks
11356         test_mkdir -p -c1 $DIR/$tdir/d
11357         # test dirs inherit from its stripe
11358         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
11359         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
11360         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
11361         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
11362         touch $DIR/f
11363
11364         # get fid of parents
11365         local FID0=$($LFS path2fid $DIR/$tdir/d)
11366         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
11367         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
11368         local FID3=$($LFS path2fid $DIR)
11369
11370         # check that path2fid --parents returns expected <parent_fid>/name
11371         # 1) test for a directory (single parent)
11372         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
11373         [ "$parent" == "$FID0/foo1" ] ||
11374                 error "expected parent: $FID0/foo1, got: $parent"
11375
11376         # 2) test for a file with nlink > 1 (multiple parents)
11377         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
11378         echo "$parent" | grep -F "$FID1/$tfile" ||
11379                 error "$FID1/$tfile not returned in parent list"
11380         echo "$parent" | grep -F "$FID2/link" ||
11381                 error "$FID2/link not returned in parent list"
11382
11383         # 3) get parent by fid
11384         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
11385         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11386         echo "$parent" | grep -F "$FID1/$tfile" ||
11387                 error "$FID1/$tfile not returned in parent list (by fid)"
11388         echo "$parent" | grep -F "$FID2/link" ||
11389                 error "$FID2/link not returned in parent list (by fid)"
11390
11391         # 4) test for entry in root directory
11392         parent=$($LFS path2fid --parents $DIR/f)
11393         echo "$parent" | grep -F "$FID3/f" ||
11394                 error "$FID3/f not returned in parent list"
11395
11396         # 5) test it on root directory
11397         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
11398                 error "$MOUNT should not have parents"
11399
11400         # enable xattr caching and check that linkea is correctly updated
11401         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
11402         save_lustre_params client "llite.*.xattr_cache" > $save
11403         lctl set_param llite.*.xattr_cache 1
11404
11405         # 6.1) linkea update on rename
11406         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
11407
11408         # get parents by fid
11409         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11410         # foo1 should no longer be returned in parent list
11411         echo "$parent" | grep -F "$FID1" &&
11412                 error "$FID1 should no longer be in parent list"
11413         # the new path should appear
11414         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
11415                 error "$FID2/$tfile.moved is not in parent list"
11416
11417         # 6.2) linkea update on unlink
11418         rm -f $DIR/$tdir/d/foo2/link
11419         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
11420         # foo2/link should no longer be returned in parent list
11421         echo "$parent" | grep -F "$FID2/link" &&
11422                 error "$FID2/link should no longer be in parent list"
11423         true
11424
11425         rm -f $DIR/f
11426         restore_lustre_params < $save
11427         rm -f $save
11428 }
11429 run_test 154f "get parent fids by reading link ea"
11430
11431 test_154g()
11432 {
11433         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) && \
11434            $(lustre_version_code client) -gt $(version_code 2.6.99) ]] ||
11435                 { skip "Need MDS version at least 2.6.92"; return 0; }
11436         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
11437
11438         mkdir -p $DIR/$tdir
11439         llapi_fid_test -d $DIR/$tdir
11440 }
11441 run_test 154g "various llapi FID tests"
11442
11443 test_155_small_load() {
11444     local temp=$TMP/$tfile
11445     local file=$DIR/$tfile
11446
11447     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
11448         error "dd of=$temp bs=6096 count=1 failed"
11449     cp $temp $file
11450     cancel_lru_locks $OSC
11451     cmp $temp $file || error "$temp $file differ"
11452
11453     $TRUNCATE $temp 6000
11454     $TRUNCATE $file 6000
11455     cmp $temp $file || error "$temp $file differ (truncate1)"
11456
11457     echo "12345" >>$temp
11458     echo "12345" >>$file
11459     cmp $temp $file || error "$temp $file differ (append1)"
11460
11461     echo "12345" >>$temp
11462     echo "12345" >>$file
11463     cmp $temp $file || error "$temp $file differ (append2)"
11464
11465     rm -f $temp $file
11466     true
11467 }
11468
11469 test_155_big_load() {
11470     remote_ost_nodsh && skip "remote OST with nodsh" && return
11471     local temp=$TMP/$tfile
11472     local file=$DIR/$tfile
11473
11474     free_min_max
11475     local cache_size=$(do_facet ost$((MAXI+1)) \
11476         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
11477     local large_file_size=$((cache_size * 2))
11478
11479     echo "OSS cache size: $cache_size KB"
11480     echo "Large file size: $large_file_size KB"
11481
11482     [ $MAXV -le $large_file_size ] && \
11483         skip_env "max available OST size needs > $large_file_size KB" && \
11484         return 0
11485
11486     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
11487
11488     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
11489         error "dd of=$temp bs=$large_file_size count=1k failed"
11490     cp $temp $file
11491     ls -lh $temp $file
11492     cancel_lru_locks osc
11493     cmp $temp $file || error "$temp $file differ"
11494
11495     rm -f $temp $file
11496     true
11497 }
11498
11499 save_writethrough() {
11500         local facets=$(get_facets OST)
11501
11502         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
11503         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
11504 }
11505
11506 test_155a() {
11507         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11508         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11509         save_writethrough $p
11510
11511         set_cache read on
11512         set_cache writethrough on
11513         test_155_small_load
11514         restore_lustre_params < $p
11515         rm -f $p
11516 }
11517 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
11518
11519 test_155b() {
11520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11521         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11522         save_writethrough $p
11523
11524         set_cache read on
11525         set_cache writethrough off
11526         test_155_small_load
11527         restore_lustre_params < $p
11528         rm -f $p
11529 }
11530 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
11531
11532 test_155c() {
11533         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11534         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11535         save_writethrough $p
11536
11537         set_cache read off
11538         set_cache writethrough on
11539         test_155_small_load
11540         restore_lustre_params < $p
11541         rm -f $p
11542 }
11543 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
11544
11545 test_155d() {
11546         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11547         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11548         save_writethrough $p
11549
11550         set_cache read off
11551         set_cache writethrough off
11552         test_155_small_load
11553         restore_lustre_params < $p
11554         rm -f $p
11555 }
11556 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
11557
11558 test_155e() {
11559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11560         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11561         save_writethrough $p
11562
11563         set_cache read on
11564         set_cache writethrough on
11565         test_155_big_load
11566         restore_lustre_params < $p
11567         rm -f $p
11568 }
11569 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
11570
11571 test_155f() {
11572         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11573         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11574         save_writethrough $p
11575
11576         set_cache read on
11577         set_cache writethrough off
11578         test_155_big_load
11579         restore_lustre_params < $p
11580         rm -f $p
11581 }
11582 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
11583
11584 test_155g() {
11585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11586         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11587         save_writethrough $p
11588
11589         set_cache read off
11590         set_cache writethrough on
11591         test_155_big_load
11592         restore_lustre_params < $p
11593         rm -f $p
11594 }
11595 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
11596
11597 test_155h() {
11598         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11599         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11600         save_writethrough $p
11601
11602         set_cache read off
11603         set_cache writethrough off
11604         test_155_big_load
11605         restore_lustre_params < $p
11606         rm -f $p
11607 }
11608 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
11609
11610 test_156() {
11611         remote_ost_nodsh && skip "remote OST with nodsh" && return
11612         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11613         local CPAGES=3
11614         local BEFORE
11615         local AFTER
11616         local file="$DIR/$tfile"
11617         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11618
11619         [ "$(facet_fstype ost1)" = "zfs" -a \
11620            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
11621                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
11622                 return
11623
11624         save_writethrough $p
11625         roc_hit_init
11626
11627         log "Turn on read and write cache"
11628         set_cache read on
11629         set_cache writethrough on
11630
11631         log "Write data and read it back."
11632         log "Read should be satisfied from the cache."
11633         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11634         BEFORE=$(roc_hit)
11635         cancel_lru_locks osc
11636         cat $file >/dev/null
11637         AFTER=$(roc_hit)
11638         if ! let "AFTER - BEFORE == CPAGES"; then
11639                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11640         else
11641                 log "cache hits:: before: $BEFORE, after: $AFTER"
11642         fi
11643
11644         log "Read again; it should be satisfied from the cache."
11645         BEFORE=$AFTER
11646         cancel_lru_locks osc
11647         cat $file >/dev/null
11648         AFTER=$(roc_hit)
11649         if ! let "AFTER - BEFORE == CPAGES"; then
11650                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11651         else
11652                 log "cache hits:: before: $BEFORE, after: $AFTER"
11653         fi
11654
11655         log "Turn off the read cache and turn on the write cache"
11656         set_cache read off
11657         set_cache writethrough on
11658
11659         log "Read again; it should be satisfied from the cache."
11660         BEFORE=$(roc_hit)
11661         cancel_lru_locks osc
11662         cat $file >/dev/null
11663         AFTER=$(roc_hit)
11664         if ! let "AFTER - BEFORE == CPAGES"; then
11665                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11666         else
11667                 log "cache hits:: before: $BEFORE, after: $AFTER"
11668         fi
11669
11670         log "Read again; it should not be satisfied from the cache."
11671         BEFORE=$AFTER
11672         cancel_lru_locks osc
11673         cat $file >/dev/null
11674         AFTER=$(roc_hit)
11675         if ! let "AFTER - BEFORE == 0"; then
11676                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11677         else
11678                 log "cache hits:: before: $BEFORE, after: $AFTER"
11679         fi
11680
11681         log "Write data and read it back."
11682         log "Read should be satisfied from the cache."
11683         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11684         BEFORE=$(roc_hit)
11685         cancel_lru_locks osc
11686         cat $file >/dev/null
11687         AFTER=$(roc_hit)
11688         if ! let "AFTER - BEFORE == CPAGES"; then
11689                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11690         else
11691                 log "cache hits:: before: $BEFORE, after: $AFTER"
11692         fi
11693
11694         log "Read again; it should not be satisfied from the cache."
11695         BEFORE=$AFTER
11696         cancel_lru_locks osc
11697         cat $file >/dev/null
11698         AFTER=$(roc_hit)
11699         if ! let "AFTER - BEFORE == 0"; then
11700                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11701         else
11702                 log "cache hits:: before: $BEFORE, after: $AFTER"
11703         fi
11704
11705         log "Turn off read and write cache"
11706         set_cache read off
11707         set_cache writethrough off
11708
11709         log "Write data and read it back"
11710         log "It should not be satisfied from the cache."
11711         rm -f $file
11712         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11713         cancel_lru_locks osc
11714         BEFORE=$(roc_hit)
11715         cat $file >/dev/null
11716         AFTER=$(roc_hit)
11717         if ! let "AFTER - BEFORE == 0"; then
11718                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11719         else
11720                 log "cache hits:: before: $BEFORE, after: $AFTER"
11721         fi
11722
11723         log "Turn on the read cache and turn off the write cache"
11724         set_cache read on
11725         set_cache writethrough off
11726
11727         log "Write data and read it back"
11728         log "It should not be satisfied from the cache."
11729         rm -f $file
11730         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11731         BEFORE=$(roc_hit)
11732         cancel_lru_locks osc
11733         cat $file >/dev/null
11734         AFTER=$(roc_hit)
11735         if ! let "AFTER - BEFORE == 0"; then
11736                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11737         else
11738                 log "cache hits:: before: $BEFORE, after: $AFTER"
11739         fi
11740
11741         log "Read again; it should be satisfied from the cache."
11742         BEFORE=$(roc_hit)
11743         cancel_lru_locks osc
11744         cat $file >/dev/null
11745         AFTER=$(roc_hit)
11746         if ! let "AFTER - BEFORE == CPAGES"; then
11747                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11748         else
11749                 log "cache hits:: before: $BEFORE, after: $AFTER"
11750         fi
11751
11752         restore_lustre_params < $p
11753         rm -f $p $file
11754 }
11755 run_test 156 "Verification of tunables"
11756
11757 test_160a() {
11758         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11759         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11760         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11761                 { skip "Need MDS version at least 2.2.0"; return; }
11762
11763         changelog_register || error "changelog_register failed"
11764         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
11765         changelog_users $SINGLEMDS | grep -q $cl_user ||
11766                 error "User $cl_user not found in changelog_users"
11767
11768         # change something
11769         test_mkdir -p $DIR/$tdir/pics/2008/zachy
11770         changelog_clear 0 || error "changelog_clear failed"
11771         touch $DIR/$tdir/pics/2008/zachy/$tfile                 # open 1
11772         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg       # open 2
11773         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
11774         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
11775         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
11776         rm $DIR/$tdir/pics/desktop.jpg
11777
11778         changelog_dump | tail -10
11779
11780         echo "verifying changelog mask"
11781         changelog_chmask "-MKDIR"
11782         changelog_chmask "-CLOSE"
11783
11784         test_mkdir -p $DIR/$tdir/pics/zach/sofia                # not logged
11785         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # not logged
11786
11787         changelog_chmask "+MKDIR"
11788         changelog_chmask "+CLOSE"
11789
11790         test_mkdir -p $DIR/$tdir/pics/2008/sofia                # mkdir 1
11791         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # open 3
11792
11793         changelog_dump | tail -10
11794         MKDIRS=$(changelog_dump | grep -c "MKDIR")
11795         CLOSES=$(changelog_dump | grep -c "CLOSE")
11796         [ $MKDIRS -eq 1 ] || error "MKDIR changelog mask count $MKDIRS != 1"
11797         [ $CLOSES -eq 3 ] || error "CLOSE changelog mask count $CLOSES != 3"
11798
11799         # verify contents
11800         echo "verifying target fid"
11801         local fidc=$(changelog_extract_field "CREAT" "$tfile" "t=")
11802         local fidf=$($LFS path2fid $DIR/$tdir/pics/zach/$tfile)
11803         [ "$fidc" == "$fidf" ] ||
11804                 error "changelog '$tfile' fid $fidc != file fid $fidf"
11805         echo "verifying parent fid"
11806         # The FID returned from the Changelog may be the directory shard on
11807         # a different MDT, and not the FID returned by path2fid on the parent.
11808         # Instead of comparing FIDs, verify that fid2path(fidp) is correct,
11809         # since this is what will matter when recreating this file in the tree.
11810         local fidp=$(changelog_extract_field "CREAT" "$tfile" "p=")
11811         local pathp=$($LFS fid2path $MOUNT "$fidp")
11812         [ "${pathp%/}" == "$DIR/$tdir/pics/zach" ] ||
11813                 error "changelog fid2path($fidc) $pathp != $DIR/$tdir/pics/zach"
11814
11815         echo "getting records for $cl_user"
11816         changelog_users $SINGLEMDS
11817         local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user)
11818         local nclr=3
11819         __changelog_clear $SINGLEMDS $cl_user +$nclr ||
11820                 error "changelog_clear failed"
11821         local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user)
11822         echo "verifying user clear: $user_rec1 + $nclr == $user_rec2"
11823         [ $user_rec2 == $((user_rec1 + nclr)) ] ||
11824                 error "user index expect $user_rec1 + $nclr != $user_rec2"
11825
11826         local min0_rec=$(changelog_users $SINGLEMDS |
11827                 awk 'min == "" || $2 < min { min = $2 }; END { print min }')
11828         local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
11829                           awk '{ print $1; exit; }')
11830
11831         changelog_dump | tail -n 5
11832         echo "verifying user min purge: $min0_rec + 1 == $first_rec"
11833         [ $first_rec == $((min0_rec + 1)) ] ||
11834                 error "first index should be $min0_rec + 1 not $first_rec"
11835
11836         # LU-3446 changelog index reset on MDT restart
11837         local cur_rec1=$(changelog_users $SINGLEMDS |
11838                          awk '/^current.index:/ { print $NF }')
11839         changelog_clear 0 ||
11840                 error "clear all changelog records for $cl_user failed"
11841         stop $SINGLEMDS || error "Fail to stop $SINGLEMDS"
11842         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
11843                 error "Fail to start $SINGLEMDS"
11844         local cur_rec2=$(changelog_users $SINGLEMDS |
11845                          awk '/^current.index:/ { print $NF }')
11846         echo "verifying index survives MDT restart: $cur_rec1 == $cur_rec2"
11847         [ $cur_rec1 == $cur_rec2 ] ||
11848                 error "current index should be $cur_rec1 not $cur_rec2"
11849
11850         echo "verifying users from this test are deregistered"
11851         changelog_deregister || error "changelog_deregister failed"
11852         changelog_users $SINGLEMDS | grep -q $cl_user &&
11853                 error "User '$cl_user' still in changelog_users"
11854
11855         # lctl get_param -n mdd.*.changelog_users
11856         # current index: 144
11857         # ID    index (idle seconds)
11858         # cl3   144 (2)
11859         if ! changelog_users $SINGLEMDS | grep "^cl"; then
11860                 # this is the normal case where all users were deregistered
11861                 # make sure no new records are added when no users are present
11862                 local last_rec1=$(changelog_users $SINGLEMDS |
11863                                   awk '/^current.index:/ { print $NF }')
11864                 touch $DIR/$tdir/chloe
11865                 local last_rec2=$(changelog_users $SINGLEMDS |
11866                                   awk '/^current.index:/ { print $NF }')
11867                 echo "verify changelogs are off: $last_rec1 == $last_rec2"
11868                 [ $last_rec1 == $last_rec2 ] || error "changelogs not off"
11869         else
11870                 # any changelog users must be leftovers from a previous test
11871                 changelog_users $SINGLEMDS
11872                 echo "other changelog users; can't verify off"
11873         fi
11874 }
11875 run_test 160a "changelog sanity"
11876
11877 test_160b() { # LU-3587
11878         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11879         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11880         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11881                 { skip "Need MDS version at least 2.2.0"; return; }
11882
11883         changelog_register || error "changelog_register failed"
11884         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
11885         changelog_users $SINGLEMDS | grep -q $cl_user ||
11886                 error "User '$cl_user' not found in changelog_users"
11887
11888         local longname1=$(str_repeat a 255)
11889         local longname2=$(str_repeat b 255)
11890
11891         cd $DIR
11892         echo "creating very long named file"
11893         touch $longname1 || error "create of '$longname1' failed"
11894         echo "renaming very long named file"
11895         mv $longname1 $longname2
11896
11897         changelog_dump | grep RENME | tail -n 5
11898         rm -f $longname2
11899 }
11900 run_test 160b "Verify that very long rename doesn't crash in changelog"
11901
11902 test_160c() {
11903         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11904
11905         local rc=0
11906         local server_version=$(lustre_version_code $SINGLEMDS)
11907
11908         [[ $server_version -gt $(version_code 2.5.57) ]] ||
11909                 [[ $server_version -gt $(version_code 2.5.1) &&
11910                    $server_version -lt $(version_code 2.5.50) ]] ||
11911                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
11912         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11913
11914         # Registration step
11915         changelog_register || error "changelog_register failed"
11916
11917         rm -rf $DIR/$tdir
11918         mkdir -p $DIR/$tdir
11919         $MCREATE $DIR/$tdir/foo_160c
11920         changelog_chmask "-TRUNC"
11921         $TRUNCATE $DIR/$tdir/foo_160c 200
11922         changelog_chmask "+TRUNC"
11923         $TRUNCATE $DIR/$tdir/foo_160c 199
11924         changelog_dump | tail -n 5
11925         local truncs=$(changelog_dump | tail -n 5 | grep -c TRUNC)
11926         [ $truncs -eq 1 ] || error "TRUNC changelog mask count $truncs != 1"
11927 }
11928 run_test 160c "verify that changelog log catch the truncate event"
11929
11930 test_160d() {
11931         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11932         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11933
11934         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.60) ]] ||
11935                 { skip "Need MDS version at least 2.7.60+"; return; }
11936         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11937
11938         # Registration step
11939         changelog_register || error "changelog_register failed"
11940
11941         mkdir -p $DIR/$tdir/migrate_dir
11942         changelog_clear 0 || error "changelog_clear failed"
11943
11944         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
11945         changelog_dump | tail -n 5
11946         local migrates=$(changelog_dump | grep -c "MIGRT")
11947         [ $migrates -eq 1 ] || error "MIGRATE changelog count $migrates != 1"
11948 }
11949 run_test 160d "verify that changelog log catch the migrate event"
11950
11951 test_160e() {
11952         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11953
11954         # Create a user
11955         changelog_register || error "changelog_register failed"
11956
11957         # Delete a future user (expect fail)
11958         local MDT0=$(facet_svc $SINGLEMDS)
11959         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister "cl77"
11960         local rc=$?
11961
11962         if [ $rc -eq 0 ]; then
11963                 error "Deleted non-existant user cl77"
11964         elif [ $rc -ne 2 ]; then
11965                 error "changelog_deregister failed with $rc, expect 2 (ENOENT)"
11966         fi
11967
11968         # Clear to a bad index (1 billion should be safe)
11969         $LFS changelog_clear $MDT0 "${CL_USERS[$SINGLEMDS]%% *}" 1000000000
11970         rc=$?
11971
11972         if [ $rc -eq 0 ]; then
11973                 error "Successfully cleared to invalid CL index"
11974         elif [ $rc -ne 22 ]; then
11975                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
11976         fi
11977 }
11978 run_test 160e "changelog negative testing (should return errors)"
11979
11980 test_160f() {
11981         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11982         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
11983                 { skip "Need MDS version at least 2.10.56"; return 0; }
11984
11985         local mdts=$(comma_list $(mdts_nodes))
11986
11987         # Create a user
11988         changelog_register || error "first changelog_register failed"
11989         changelog_register || error "second changelog_register failed"
11990         local cl_users=(${CL_USERS[$SINGLEMDS]})
11991         local cl_user1="${cl_users[0]}"
11992         local cl_user2="${cl_users[1]}"
11993
11994         # generate some changelog records to accumulate on each MDT
11995         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "test_mkdir $tdir failed"
11996         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
11997                 error "create $DIR/$tdir/$tfile failed"
11998
11999         # check changelogs have been generated
12000         nbcl=$(changelog_dump | wc -l)
12001         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12002
12003         # changelog_gc=1 should be set by default
12004         for param in "changelog_max_idle_time=10" \
12005                      "changelog_min_gc_interval=2" \
12006                      "changelog_min_free_cat_entries=3"; do
12007                 local MDT0=$(facet_svc $SINGLEMDS)
12008                 local var="${param%=*}"
12009                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
12010
12011                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
12012                 do_nodes $mdts $LCTL set_param mdd.*.$param
12013         done
12014
12015         # simulate changelog catalog almost full
12016         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
12017         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
12018
12019         sleep 6
12020         local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user1)
12021         [ -n "$user_rec1" ] ||
12022                 error "User $cl_user1 not found in changelog_users"
12023         __changelog_clear $SINGLEMDS $cl_user1 +2
12024         local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user1)
12025         [ -n "$user_rec2" ] ||
12026                 error "User $cl_user1 not found in changelog_users"
12027         echo "verifying user clear: $user_rec1 + 2 == $user_rec2"
12028         [ $((user_rec1 + 2)) == $user_rec2 ] ||
12029                 error "user index expected $user_rec1 + 2, but is $user_rec2"
12030         sleep 5
12031
12032         # generate one more changelog to trigger fail_loc
12033         rm -rf $DIR/$tdir || error "rm -rf $tdir failed"
12034
12035         # ensure gc thread is done
12036         wait_update_facet $SINGLEMDS \
12037                           "ps -e -o comm= | grep chlg_gc_thread" "" 20
12038
12039         # check user still registered
12040         changelog_users $SINGLEMDS | grep -q "$cl_user1" ||
12041                 error "User $cl_user1 not found in changelog_users"
12042         # check user2 unregistered
12043         changelog_users $SINGLEMDS | grep -q "$cl_user2" &&
12044                 error "User $cl_user2 still found in changelog_users"
12045
12046         # check changelogs are present and starting at $user_rec2 + 1
12047         local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
12048                           awk '{ print $1; exit; }')
12049
12050         echo "verifying min purge: $user_rec2 + 1 == $first_rec"
12051         [ $((user_rec2 + 1)) == $first_rec ] ||
12052                 error "first index should be $user_rec2 + 1, but is $first_rec"
12053 }
12054 run_test 160f "changelog garbage collect (timestamped users)"
12055
12056 test_160g() {
12057         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12058         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
12059                 { skip "Need MDS version at least 2.10.56"; return 0; }
12060
12061         local mdts=$(comma_list $(mdts_nodes))
12062
12063         #define OBD_FAIL_TIME_IN_CHLOG_USER     0x1314
12064         do_nodes $mdts $LCTL set_param fail_loc=0x1314
12065
12066         # Create a user
12067         changelog_register || error "first changelog_register failed"
12068         changelog_register || error "second changelog_register failed"
12069         local cl_users=(${CL_USERS[$SINGLEMDS]})
12070         local cl_user1="${cl_users[0]}"
12071         local cl_user2="${cl_users[1]}"
12072
12073         # generate some changelog records to accumulate on each MDT
12074         test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
12075         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
12076                 error "create $DIR/$tdir/$tfile failed"
12077
12078         # check changelogs have been generated
12079         nbcl=$(changelog_dump | wc -l)
12080         [[ $nbcl -eq 0 ]] && error "no changelogs found"
12081
12082         # changelog_gc=1 should be set by default
12083         for param in "changelog_max_idle_indexes=$((nbcl / 2))" \
12084                      "changelog_min_gc_interval=2" \
12085                      "changelog_min_free_cat_entries=3"; do
12086                 local MDT0=$(facet_svc $SINGLEMDS)
12087                 local var="${param%=*}"
12088                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
12089
12090                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
12091                 do_nodes $mdts $LCTL set_param mdd.*.$param ||
12092                         error "unable to set mdd.*.$param"
12093         done
12094
12095         # simulate changelog catalog almost full
12096         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
12097         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
12098
12099         local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user1)
12100
12101         __changelog_clear $SINGLEMDS $cl_user1 +3
12102
12103         local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user1)
12104
12105         echo "verifying user clear: $user_rec1 + 3 == $user_rec2"
12106         [ $((user_rec1 + 3)) == $user_rec2 ] ||
12107                 error "user index expected $user_rec1 + 3, but is $user_rec2"
12108
12109         # generate one more changelog to trigger fail_loc
12110         rm -rf $DIR/$tdir || error "rm -rf $tdir failed"
12111
12112         # ensure gc thread is done
12113         wait_update_facet $SINGLEMDS \
12114                           "ps -e -o comm= | grep chlg_gc_thread" "" 20
12115
12116         # check user still registered
12117         [ -n "$(changelog_user_rec $SINGLEMDS $cl_user1)" ] ||
12118                 error "User $cl_user1 not found in changelog_users"
12119         # check user2 unregistered
12120         [ -z "$(changelog_user_rec $SINGLEMDS $cl_user2)" ] ||
12121                 error "User $cl_user2 still found in changelog_users"
12122
12123         # check changelogs are present and starting at $user_rec2 + 1
12124         local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
12125                           awk '{ print $1; exit; }')
12126
12127         echo "verifying min purge: $user_rec2 + 1 == $first_rec"
12128         [ $((user_rec2 + 1)) == $first_rec ] ||
12129                 error "first index should be $user_rec2 + 1, but is $first_rec"
12130 }
12131 run_test 160g "changelog garbage collect (old users)"
12132
12133 test_161a() {
12134         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12135         test_mkdir -c1 $DIR/$tdir
12136         cp /etc/hosts $DIR/$tdir/$tfile
12137         test_mkdir -c1 $DIR/$tdir/foo1
12138         test_mkdir -c1 $DIR/$tdir/foo2
12139         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
12140         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
12141         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
12142         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
12143         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
12144         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
12145                 $LFS fid2path $DIR $FID
12146                 error "bad link ea"
12147         fi
12148         # middle
12149         rm $DIR/$tdir/foo2/zachary
12150         # last
12151         rm $DIR/$tdir/foo2/thor
12152         # first
12153         rm $DIR/$tdir/$tfile
12154         # rename
12155         mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
12156         [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ] &&
12157                 { $LFS fid2path $DIR $FID; error "bad link rename"; }
12158         rm $DIR/$tdir/foo2/maggie
12159
12160         # overflow the EA
12161         local longname=$tfile.avg_len_is_thirty_two_
12162         stack_trap "unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
12163                 error_noexit 'failed to unlink many hardlinks'" EXIT
12164         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
12165                 error "failed to hardlink many files"
12166         links=$($LFS fid2path $DIR $FID | wc -l)
12167         echo -n "${links}/1000 links in link EA"
12168         [[ $links -gt 60 ]] || error "expected at least 60 links in link EA"
12169 }
12170 run_test 161a "link ea sanity"
12171
12172 test_161b() {
12173         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12174         [ $MDSCOUNT -lt 2 ] && skip "skipping remote directory test" && return
12175         local MDTIDX=1
12176         local remote_dir=$DIR/$tdir/remote_dir
12177
12178         mkdir -p $DIR/$tdir
12179         $LFS mkdir -i $MDTIDX $remote_dir ||
12180                 error "create remote directory failed"
12181
12182         cp /etc/hosts $remote_dir/$tfile
12183         mkdir -p $remote_dir/foo1
12184         mkdir -p $remote_dir/foo2
12185         ln $remote_dir/$tfile $remote_dir/foo1/sofia
12186         ln $remote_dir/$tfile $remote_dir/foo2/zachary
12187         ln $remote_dir/$tfile $remote_dir/foo1/luna
12188         ln $remote_dir/$tfile $remote_dir/foo2/thor
12189
12190         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
12191                      tr -d ']')
12192         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
12193                 $LFS fid2path $DIR $FID
12194                 error "bad link ea"
12195         fi
12196         # middle
12197         rm $remote_dir/foo2/zachary
12198         # last
12199         rm $remote_dir/foo2/thor
12200         # first
12201         rm $remote_dir/$tfile
12202         # rename
12203         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
12204         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
12205         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
12206                 $LFS fid2path $DIR $FID
12207                 error "bad link rename"
12208         fi
12209         rm $remote_dir/foo2/maggie
12210
12211         # overflow the EA
12212         local longname=filename_avg_len_is_thirty_two_
12213         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
12214                 error "failed to hardlink many files"
12215         links=$($LFS fid2path $DIR $FID | wc -l)
12216         echo -n "${links}/1000 links in link EA"
12217         [[ ${links} -gt 60 ]] ||
12218                 error "expected at least 60 links in link EA"
12219         unlinkmany $remote_dir/foo2/$longname 1000 ||
12220         error "failed to unlink many hardlinks"
12221 }
12222 run_test 161b "link ea sanity under remote directory"
12223
12224 test_161c() {
12225         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12226         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12227         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
12228                 skip "Need MDS version at least 2.1.5" && return
12229
12230         # define CLF_RENAME_LAST 0x0001
12231         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
12232         changelog_register || error "changelog_register failed"
12233
12234         rm -rf $DIR/$tdir
12235         test_mkdir -i $((MDSCOUNT - 1)) $DIR/$tdir
12236         touch $DIR/$tdir/foo_161c
12237         touch $DIR/$tdir/bar_161c
12238         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
12239         changelog_dump | grep RENME | tail -n 5
12240         local flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
12241         changelog_clear 0 || error "changelog_clear failed"
12242         if [ x$flags != "x0x1" ]; then
12243                 error "flag $flags is not 0x1"
12244         fi
12245
12246         echo "rename overwrite target with nlink = 1, changelog flags=$flags"
12247         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
12248         touch $DIR/$tdir/foo_161c
12249         touch $DIR/$tdir/bar_161c
12250         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
12251         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
12252         changelog_dump | grep RENME | tail -n 5
12253         flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
12254         changelog_clear 0 || error "changelog_clear failed"
12255         if [ x$flags != "x0x0" ]; then
12256                 error "flag $flags is not 0x0"
12257         fi
12258         echo "rename overwrite a target having nlink > 1," \
12259                 "changelog record has flags of $flags"
12260
12261         # rename doesn't overwrite a target (changelog flag 0x0)
12262         touch $DIR/$tdir/foo_161c
12263         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
12264         changelog_dump | grep RENME | tail -n 5
12265         flags=$(changelog_dump | grep RENME | tail -1 | cut -f5 -d' ')
12266         changelog_clear 0 || error "changelog_clear failed"
12267         if [ x$flags != "x0x0" ]; then
12268                 error "flag $flags is not 0x0"
12269         fi
12270         echo "rename doesn't overwrite a target," \
12271                 "changelog record has flags of $flags"
12272
12273         # define CLF_UNLINK_LAST 0x0001
12274         # unlink a file having nlink = 1 (changelog flag 0x1)
12275         rm -f $DIR/$tdir/foo2_161c
12276         changelog_dump | grep UNLNK | tail -n 5
12277         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
12278         changelog_clear 0 || error "changelog_clear failed"
12279         if [ x$flags != "x0x1" ]; then
12280                 error "flag $flags is not 0x1"
12281         fi
12282         echo "unlink a file having nlink = 1," \
12283                 "changelog record has flags of $flags"
12284
12285         # unlink a file having nlink > 1 (changelog flag 0x0)
12286         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
12287         rm -f $DIR/$tdir/foobar_161c
12288         changelog_dump | grep UNLNK | tail -n 5
12289         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
12290         changelog_clear 0 || error "changelog_clear failed"
12291         if [ x$flags != "x0x0" ]; then
12292                 error "flag $flags is not 0x0"
12293         fi
12294         echo "unlink a file having nlink > 1, changelog record flags '$flags'"
12295 }
12296 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
12297
12298 test_161d() {
12299         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12300
12301         local pid
12302         local fid
12303
12304         changelog_register || error "changelog_register failed"
12305
12306         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
12307         # interfer with $MOUNT/.lustre/fid/ access
12308         mkdir $DIR/$tdir
12309         [[ $? -eq 0 ]] || error "mkdir failed"
12310
12311         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
12312         $LCTL set_param fail_loc=0x8000140c
12313         # 5s pause
12314         $LCTL set_param fail_val=5
12315
12316         # create file
12317         echo foofoo > $DIR/$tdir/$tfile &
12318         pid=$!
12319
12320         # wait for create to be delayed
12321         sleep 2
12322
12323         ps -p $pid
12324         [[ $? -eq 0 ]] || error "create should be blocked"
12325
12326         local tempfile=$(mktemp)
12327         fid=$(changelog_extract_field "CREAT" "$tfile" "t=")
12328         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
12329         # some delay may occur during ChangeLog publishing and file read just
12330         # above, that could allow file write to happen finally
12331         [[ -s $tempfile ]] && echo "file should be empty"
12332
12333         $LCTL set_param fail_loc=0
12334
12335         wait $pid
12336         [[ $? -eq 0 ]] || error "create failed"
12337 }
12338 run_test 161d "create with concurrent .lustre/fid access"
12339
12340 check_path() {
12341         local expected="$1"
12342         shift
12343         local fid="$2"
12344
12345         local path
12346         path=$($LFS fid2path "$@")
12347         local rc=$?
12348
12349         if [ $rc -ne 0 ]; then
12350                 error "path looked up of '$expected' failed: rc=$rc"
12351         elif [ "$path" != "$expected" ]; then
12352                 error "path looked up '$path' instead of '$expected'"
12353         else
12354                 echo "FID '$fid' resolves to path '$path' as expected"
12355         fi
12356 }
12357
12358 test_162a() { # was test_162
12359         test_mkdir -p -c1 $DIR/$tdir/d2
12360         touch $DIR/$tdir/d2/$tfile
12361         touch $DIR/$tdir/d2/x1
12362         touch $DIR/$tdir/d2/x2
12363         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
12364         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
12365         # regular file
12366         local fid=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
12367         check_path "$tdir/d2/$tfile" $FSNAME "$fid" --link 0
12368
12369         # softlink
12370         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
12371         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
12372         check_path "$tdir/d2/p/q/r/slink" $FSNAME "$fid" --link 0
12373
12374         # softlink to wrong file
12375         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
12376         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
12377         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME "$fid" --link 0
12378
12379         # hardlink
12380         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
12381         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
12382         fid=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
12383         # fid2path dir/fsname should both work
12384         check_path "$tdir/d2/a/b/c/new_file" $FSNAME "$fid" --link 1
12385         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR "$fid" --link 0
12386
12387         # hardlink count: check that there are 2 links
12388         local nlinks=$($LFS fid2path $DIR "$fid" | wc -l)
12389         [ $nlinks -eq 2 ] || error "expect 2 links, found $nlinks"
12390
12391         # hardlink indexing: remove the first link
12392         rm $DIR/$tdir/d2/p/q/r/hlink
12393         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $fid --link 0
12394 }
12395 run_test 162a "path lookup sanity"
12396
12397 test_162b() {
12398         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12399         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12400
12401         mkdir $DIR/$tdir
12402         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
12403                                 error "create striped dir failed"
12404
12405         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
12406                                         tail -n 1 | awk '{print $2}')
12407         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
12408
12409         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
12410         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
12411
12412         # regular file
12413         for ((i=0;i<5;i++)); do
12414                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
12415                         error "get fid for f$i failed"
12416                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0
12417
12418                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
12419                         error "get fid for d$i failed"
12420                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0
12421         done
12422
12423         return 0
12424 }
12425 run_test 162b "striped directory path lookup sanity"
12426
12427 # LU-4239: Verify fid2path works with paths 100 or more directories deep
12428 test_162c() {
12429         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
12430                 skip "Need MDS version at least 2.7.51" && return
12431         test_mkdir $DIR/$tdir.local
12432         test_mkdir $DIR/$tdir.remote
12433         local lpath=$tdir.local
12434         local rpath=$tdir.remote
12435
12436         for ((i = 0; i <= 101; i++)); do
12437                 lpath="$lpath/$i"
12438                 mkdir $DIR/$lpath
12439                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
12440                         error "get fid for local directory $DIR/$lpath failed"
12441                 check_path "$DIR/$lpath" $MOUNT $FID --link 0
12442
12443                 rpath="$rpath/$i"
12444                 test_mkdir $DIR/$rpath
12445                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
12446                         error "get fid for remote directory $DIR/$rpath failed"
12447                 check_path "$DIR/$rpath" $MOUNT $FID --link 0
12448         done
12449
12450         return 0
12451 }
12452 run_test 162c "fid2path works with paths 100 or more directories deep"
12453
12454 test_169() {
12455         # do directio so as not to populate the page cache
12456         log "creating a 10 Mb file"
12457         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12458         log "starting reads"
12459         dd if=$DIR/$tfile of=/dev/null bs=4096 &
12460         log "truncating the file"
12461         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12462         log "killing dd"
12463         kill %+ || true # reads might have finished
12464         echo "wait until dd is finished"
12465         wait
12466         log "removing the temporary file"
12467         rm -rf $DIR/$tfile || error "tmp file removal failed"
12468 }
12469 run_test 169 "parallel read and truncate should not deadlock"
12470
12471 test_170() {
12472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12473
12474         $LCTL clear     # bug 18514
12475         $LCTL debug_daemon start $TMP/${tfile}_log_good
12476         touch $DIR/$tfile
12477         $LCTL debug_daemon stop
12478         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
12479                 error "sed failed to read log_good"
12480
12481         $LCTL debug_daemon start $TMP/${tfile}_log_good
12482         rm -rf $DIR/$tfile
12483         $LCTL debug_daemon stop
12484
12485         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
12486                error "lctl df log_bad failed"
12487
12488         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
12489         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
12490
12491         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
12492         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
12493
12494         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
12495                 error "bad_line good_line1 good_line2 are empty"
12496
12497         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
12498         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
12499         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
12500
12501         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
12502         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
12503         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
12504
12505         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
12506                 error "bad_line_new good_line_new are empty"
12507
12508         local expected_good=$((good_line1 + good_line2*2))
12509
12510         rm -f $TMP/${tfile}*
12511         # LU-231, short malformed line may not be counted into bad lines
12512         if [ $bad_line -ne $bad_line_new ] &&
12513                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
12514                 error "expected $bad_line bad lines, but got $bad_line_new"
12515                 return 1
12516         fi
12517
12518         if [ $expected_good -ne $good_line_new ]; then
12519                 error "expected $expected_good good lines, but got $good_line_new"
12520                 return 2
12521         fi
12522         true
12523 }
12524 run_test 170 "test lctl df to handle corrupted log ====================="
12525
12526 test_171() { # bug20592
12527         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12528 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
12529         $LCTL set_param fail_loc=0x50e
12530         $LCTL set_param fail_val=3000
12531         multiop_bg_pause $DIR/$tfile O_s || true
12532         local MULTIPID=$!
12533         kill -USR1 $MULTIPID
12534         # cause log dump
12535         sleep 3
12536         wait $MULTIPID
12537         if dmesg | grep "recursive fault"; then
12538                 error "caught a recursive fault"
12539         fi
12540         $LCTL set_param fail_loc=0
12541         true
12542 }
12543 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
12544
12545 # it would be good to share it with obdfilter-survey/iokit-libecho code
12546 setup_obdecho_osc () {
12547         local rc=0
12548         local ost_nid=$1
12549         local obdfilter_name=$2
12550         echo "Creating new osc for $obdfilter_name on $ost_nid"
12551         # make sure we can find loopback nid
12552         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
12553
12554         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
12555                            ${obdfilter_name}_osc_UUID || rc=2; }
12556         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
12557                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
12558         return $rc
12559 }
12560
12561 cleanup_obdecho_osc () {
12562         local obdfilter_name=$1
12563         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
12564         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
12565         return 0
12566 }
12567
12568 obdecho_test() {
12569         local OBD=$1
12570         local node=$2
12571         local pages=${3:-64}
12572         local rc=0
12573         local id
12574
12575         local count=10
12576         local obd_size=$(get_obd_size $node $OBD)
12577         local page_size=$(get_page_size $node)
12578         if [[ -n "$obd_size" ]]; then
12579                 local new_count=$((obd_size / (pages * page_size / 1024)))
12580                 [[ $new_count -ge $count ]] || count=$new_count
12581         fi
12582
12583         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
12584         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
12585                            rc=2; }
12586         if [ $rc -eq 0 ]; then
12587             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
12588             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
12589         fi
12590         echo "New object id is $id"
12591         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
12592                            rc=4; }
12593         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
12594                            "test_brw $count w v $pages $id" || rc=4; }
12595         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
12596                            rc=4; }
12597         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
12598                                         "cleanup" || rc=5; }
12599         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
12600                                         "detach" || rc=6; }
12601         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
12602         return $rc
12603 }
12604
12605 test_180a() {
12606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12607         remote_ost_nodsh && skip "remote OST with nodsh" && return
12608         local rc=0
12609         local rmmod_local=0
12610
12611         if ! module_loaded obdecho; then
12612             load_module obdecho/obdecho
12613             rmmod_local=1
12614         fi
12615
12616         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
12617         local host=$(lctl get_param -n osc.$osc.import |
12618                              awk '/current_connection:/ {print $2}' )
12619         local target=$(lctl get_param -n osc.$osc.import |
12620                              awk '/target:/ {print $2}' )
12621         target=${target%_UUID}
12622
12623         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
12624         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
12625         [[ -n $target ]] && cleanup_obdecho_osc $target
12626         [ $rmmod_local -eq 1 ] && rmmod obdecho
12627         return $rc
12628 }
12629 run_test 180a "test obdecho on osc"
12630
12631 test_180b() {
12632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12633         remote_ost_nodsh && skip "remote OST with nodsh" && return
12634         local rc=0
12635         local rmmod_remote=0
12636
12637         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
12638                 rmmod_remote=true || error "failed to load module obdecho"
12639         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
12640         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
12641         $rmmod_remote && do_facet ost1 "rmmod obdecho"
12642         return $rc
12643 }
12644 run_test 180b "test obdecho directly on obdfilter"
12645
12646 test_180c() { # LU-2598
12647         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12648         remote_ost_nodsh && skip "remote OST with nodsh" && return
12649         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
12650                 skip "Need MDS version at least 2.4.0" && return
12651
12652         local rc=0
12653         local rmmod_remote=false
12654         local pages=16384 # 64MB bulk I/O RPC size
12655         local target
12656
12657         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
12658                 rmmod_remote=true || error "failed to load module obdecho"
12659
12660         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4; exit; }')
12661         if [ -n "$target" ]; then
12662                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
12663         else
12664                 echo "there is no obdfilter target on ost1"
12665                 rc=2
12666         fi
12667         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
12668         return $rc
12669 }
12670 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
12671
12672 test_181() { # bug 22177
12673         test_mkdir $DIR/$tdir
12674         # create enough files to index the directory
12675         createmany -o $DIR/$tdir/foobar 4000
12676         # print attributes for debug purpose
12677         lsattr -d .
12678         # open dir
12679         multiop_bg_pause $DIR/$tdir D_Sc || return 1
12680         MULTIPID=$!
12681         # remove the files & current working dir
12682         unlinkmany $DIR/$tdir/foobar 4000
12683         rmdir $DIR/$tdir
12684         kill -USR1 $MULTIPID
12685         wait $MULTIPID
12686         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
12687         return 0
12688 }
12689 run_test 181 "Test open-unlinked dir ========================"
12690
12691 test_182() {
12692         local fcount=1000
12693         local tcount=10
12694
12695         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12696
12697         $LCTL set_param mdc.*.rpc_stats=clear
12698
12699         for (( i = 0; i < $tcount; i++ )) ; do
12700                 mkdir $DIR/$tdir/$i
12701         done
12702
12703         for (( i = 0; i < $tcount; i++ )) ; do
12704                 createmany -o $DIR/$tdir/$i/f- $fcount &
12705         done
12706         wait
12707
12708         for (( i = 0; i < $tcount; i++ )) ; do
12709                 unlinkmany $DIR/$tdir/$i/f- $fcount &
12710         done
12711         wait
12712
12713         $LCTL get_param mdc.*.rpc_stats
12714
12715         rm -rf $DIR/$tdir
12716 }
12717 run_test 182 "Test parallel modify metadata operations ================"
12718
12719 test_183() { # LU-2275
12720         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12721         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
12722                 skip "Need MDS version at least 2.3.56" && return
12723
12724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12725         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12726         echo aaa > $DIR/$tdir/$tfile
12727
12728 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
12729         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
12730
12731         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
12732         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
12733
12734         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
12735
12736         # Flush negative dentry cache
12737         touch $DIR/$tdir/$tfile
12738
12739         # We are not checking for any leaked references here, they'll
12740         # become evident next time we do cleanup with module unload.
12741         rm -rf $DIR/$tdir
12742 }
12743 run_test 183 "No crash or request leak in case of strange dispositions ========"
12744
12745 # test suite 184 is for LU-2016, LU-2017
12746 test_184a() {
12747         check_swap_layouts_support && return 0
12748
12749         dir0=$DIR/$tdir/$testnum
12750         test_mkdir -p -c1 $dir0
12751         ref1=/etc/passwd
12752         ref2=/etc/group
12753         file1=$dir0/f1
12754         file2=$dir0/f2
12755         $SETSTRIPE -c1 $file1
12756         cp $ref1 $file1
12757         $SETSTRIPE -c2 $file2
12758         cp $ref2 $file2
12759         gen1=$($GETSTRIPE -g $file1)
12760         gen2=$($GETSTRIPE -g $file2)
12761
12762         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
12763         gen=$($GETSTRIPE -g $file1)
12764         [[ $gen1 != $gen ]] ||
12765                 "Layout generation on $file1 does not change"
12766         gen=$($GETSTRIPE -g $file2)
12767         [[ $gen2 != $gen ]] ||
12768                 "Layout generation on $file2 does not change"
12769
12770         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
12771         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12772
12773         lfsck_verify_pfid $file1 $file2 || error "PFID are not transferred"
12774 }
12775 run_test 184a "Basic layout swap"
12776
12777 test_184b() {
12778         check_swap_layouts_support && return 0
12779
12780         dir0=$DIR/$tdir/$testnum
12781         mkdir -p $dir0 || error "creating dir $dir0"
12782         file1=$dir0/f1
12783         file2=$dir0/f2
12784         file3=$dir0/f3
12785         dir1=$dir0/d1
12786         dir2=$dir0/d2
12787         mkdir $dir1 $dir2
12788         $SETSTRIPE -c1 $file1
12789         $SETSTRIPE -c2 $file2
12790         $SETSTRIPE -c1 $file3
12791         chown $RUNAS_ID $file3
12792         gen1=$($GETSTRIPE -g $file1)
12793         gen2=$($GETSTRIPE -g $file2)
12794
12795         $LFS swap_layouts $dir1 $dir2 &&
12796                 error "swap of directories layouts should fail"
12797         $LFS swap_layouts $dir1 $file1 &&
12798                 error "swap of directory and file layouts should fail"
12799         $RUNAS $LFS swap_layouts $file1 $file2 &&
12800                 error "swap of file we cannot write should fail"
12801         $LFS swap_layouts $file1 $file3 &&
12802                 error "swap of file with different owner should fail"
12803         /bin/true # to clear error code
12804 }
12805 run_test 184b "Forbidden layout swap (will generate errors)"
12806
12807 test_184c() {
12808         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
12809         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n" && return
12810         check_swap_layouts_support && return 0
12811
12812         local dir0=$DIR/$tdir/$testnum
12813         mkdir -p $dir0 || error "creating dir $dir0"
12814
12815         local ref1=$dir0/ref1
12816         local ref2=$dir0/ref2
12817         local file1=$dir0/file1
12818         local file2=$dir0/file2
12819         # create a file large enough for the concurrent test
12820         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
12821         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
12822         echo "ref file size: ref1($(stat -c %s $ref1))," \
12823              "ref2($(stat -c %s $ref2))"
12824
12825         cp $ref2 $file2
12826         dd if=$ref1 of=$file1 bs=16k &
12827         local DD_PID=$!
12828
12829         # Make sure dd starts to copy file
12830         while [ ! -f $file1 ]; do sleep 0.1; done
12831
12832         $LFS swap_layouts $file1 $file2
12833         local rc=$?
12834         wait $DD_PID
12835         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
12836         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
12837
12838         # how many bytes copied before swapping layout
12839         local copied=$(stat -c %s $file2)
12840         local remaining=$(stat -c %s $ref1)
12841         remaining=$((remaining - copied))
12842         echo "Copied $copied bytes before swapping layout..."
12843
12844         cmp -n $copied $file1 $ref2 | grep differ &&
12845                 error "Content mismatch [0, $copied) of ref2 and file1"
12846         cmp -n $copied $file2 $ref1 ||
12847                 error "Content mismatch [0, $copied) of ref1 and file2"
12848         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
12849                 error "Content mismatch [$copied, EOF) of ref1 and file1"
12850
12851         # clean up
12852         rm -f $ref1 $ref2 $file1 $file2
12853 }
12854 run_test 184c "Concurrent write and layout swap"
12855
12856 test_184d() {
12857         check_swap_layouts_support && return 0
12858         [ -z "$(which getfattr 2>/dev/null)" ] &&
12859                 skip "no getfattr command" && return 0
12860
12861         local file1=$DIR/$tdir/$tfile-1
12862         local file2=$DIR/$tdir/$tfile-2
12863         local file3=$DIR/$tdir/$tfile-3
12864         local lovea1
12865         local lovea2
12866
12867         mkdir -p $DIR/$tdir
12868         touch $file1 || error "create $file1 failed"
12869         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12870                 error "create $file2 failed"
12871         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12872                 error "create $file3 failed"
12873         lovea1=$(get_layout_param $file1)
12874
12875         $LFS swap_layouts $file2 $file3 ||
12876                 error "swap $file2 $file3 layouts failed"
12877         $LFS swap_layouts $file1 $file2 ||
12878                 error "swap $file1 $file2 layouts failed"
12879
12880         lovea2=$(get_layout_param $file2)
12881         echo "$lovea1"
12882         echo "$lovea2"
12883         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
12884
12885         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12886         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
12887 }
12888 run_test 184d "allow stripeless layouts swap"
12889
12890 test_184e() {
12891         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
12892                 { skip "Need MDS version at least 2.6.94"; return 0; }
12893         check_swap_layouts_support && return 0
12894         [ -z "$(which getfattr 2>/dev/null)" ] &&
12895                 skip "no getfattr command" && return 0
12896
12897         local file1=$DIR/$tdir/$tfile-1
12898         local file2=$DIR/$tdir/$tfile-2
12899         local file3=$DIR/$tdir/$tfile-3
12900         local lovea
12901
12902         mkdir -p $DIR/$tdir
12903         touch $file1 || error "create $file1 failed"
12904         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12905                 error "create $file2 failed"
12906         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12907                 error "create $file3 failed"
12908
12909         $LFS swap_layouts $file1 $file2 ||
12910                 error "swap $file1 $file2 layouts failed"
12911
12912         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12913         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
12914
12915         echo 123 > $file1 || error "Should be able to write into $file1"
12916
12917         $LFS swap_layouts $file1 $file3 ||
12918                 error "swap $file1 $file3 layouts failed"
12919
12920         echo 123 > $file1 || error "Should be able to write into $file1"
12921
12922         rm -rf $file1 $file2 $file3
12923 }
12924 run_test 184e "Recreate layout after stripeless layout swaps"
12925
12926 test_185() { # LU-2441
12927         # LU-3553 - no volatile file support in old servers
12928         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
12929                 { skip "Need MDS version at least 2.3.60"; return 0; }
12930
12931         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12932         touch $DIR/$tdir/spoo
12933         local mtime1=$(stat -c "%Y" $DIR/$tdir)
12934         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
12935                 error "cannot create/write a volatile file"
12936         [ "$FILESET" == "" ] &&
12937         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
12938                 error "FID is still valid after close"
12939
12940         multiop_bg_pause $DIR/$tdir vVw4096_c
12941         local multi_pid=$!
12942
12943         local OLD_IFS=$IFS
12944         IFS=":"
12945         local fidv=($fid)
12946         IFS=$OLD_IFS
12947         # assume that the next FID for this client is sequential, since stdout
12948         # is unfortunately eaten by multiop_bg_pause
12949         local n=$((${fidv[1]} + 1))
12950         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
12951         if [ "$FILESET" == "" ]; then
12952                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
12953                         error "FID is missing before close"
12954         fi
12955         kill -USR1 $multi_pid
12956         # 1 second delay, so if mtime change we will see it
12957         sleep 1
12958         local mtime2=$(stat -c "%Y" $DIR/$tdir)
12959         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
12960 }
12961 run_test 185 "Volatile file support"
12962
12963 test_187a() {
12964         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12965         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12966                 skip "Need MDS version at least 2.3.0" && return
12967
12968         local dir0=$DIR/$tdir/$testnum
12969         mkdir -p $dir0 || error "creating dir $dir0"
12970
12971         local file=$dir0/file1
12972         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
12973         local dv1=$($LFS data_version $file)
12974         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
12975         local dv2=$($LFS data_version $file)
12976         [[ $dv1 != $dv2 ]] ||
12977                 error "data version did not change on write $dv1 == $dv2"
12978
12979         # clean up
12980         rm -f $file1
12981 }
12982 run_test 187a "Test data version change"
12983
12984 test_187b() {
12985         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12986         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12987                 skip "Need MDS version at least 2.3.0" && return
12988
12989         local dir0=$DIR/$tdir/$testnum
12990         mkdir -p $dir0 || error "creating dir $dir0"
12991
12992         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
12993         [[ ${DV[0]} != ${DV[1]} ]] ||
12994                 error "data version did not change on write"\
12995                       " ${DV[0]} == ${DV[1]}"
12996
12997         # clean up
12998         rm -f $file1
12999 }
13000 run_test 187b "Test data version change on volatile file"
13001
13002 test_200() {
13003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13004         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
13005         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13006
13007         local POOL=${POOL:-cea1}
13008         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
13009         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
13010         # Pool OST targets
13011         local first_ost=0
13012         local last_ost=$(($OSTCOUNT - 1))
13013         local ost_step=2
13014         local ost_list=$(seq $first_ost $ost_step $last_ost)
13015         local ost_range="$first_ost $last_ost $ost_step"
13016         local test_path=$POOL_ROOT/$POOL_DIR_NAME
13017         local file_dir=$POOL_ROOT/file_tst
13018         local subdir=$test_path/subdir
13019         local rc=0
13020
13021         if ! combined_mgs_mds ; then
13022                 mount_mgs_client
13023         fi
13024
13025         while : ; do
13026                 # former test_200a test_200b
13027                 pool_add $POOL                          || { rc=$? ; break; }
13028                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
13029                 # former test_200c test_200d
13030                 mkdir -p $test_path
13031                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
13032                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
13033                 mkdir -p $subdir
13034                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
13035                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
13036                                                         || { rc=$? ; break; }
13037                 # former test_200e test_200f
13038                 local files=$((OSTCOUNT*3))
13039                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
13040                                                         || { rc=$? ; break; }
13041                 pool_create_files $POOL $file_dir $files "$ost_list" \
13042                                                         || { rc=$? ; break; }
13043                 # former test_200g test_200h
13044                 pool_lfs_df $POOL                       || { rc=$? ; break; }
13045                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
13046
13047                 # former test_201a test_201b test_201c
13048                 pool_remove_first_target $POOL          || { rc=$? ; break; }
13049
13050                 local f=$test_path/$tfile
13051                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
13052                 pool_remove $POOL $f                    || { rc=$? ; break; }
13053                 break
13054         done
13055
13056         destroy_test_pools
13057
13058         if ! combined_mgs_mds ; then
13059                 umount_mgs_client
13060         fi
13061         return $rc
13062 }
13063 run_test 200 "OST pools"
13064
13065 # usage: default_attr <count | size | offset>
13066 default_attr() {
13067         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
13068 }
13069
13070 # usage: check_default_stripe_attr
13071 check_default_stripe_attr() {
13072         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
13073         case $1 in
13074         --stripe-count|-c)
13075                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
13076         --stripe-size|-S)
13077                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
13078         --stripe-index|-i)
13079                 EXPECTED=-1;;
13080         *)
13081                 error "unknown getstripe attr '$1'"
13082         esac
13083
13084         [ $ACTUAL == $EXPECTED ] ||
13085                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
13086 }
13087
13088 test_204a() {
13089         test_mkdir $DIR/$tdir
13090         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
13091
13092         check_default_stripe_attr --stripe-count
13093         check_default_stripe_attr --stripe-size
13094         check_default_stripe_attr --stripe-index
13095 }
13096 run_test 204a "Print default stripe attributes"
13097
13098 test_204b() {
13099         test_mkdir $DIR/$tdir
13100         $SETSTRIPE --stripe-count 1 $DIR/$tdir
13101
13102         check_default_stripe_attr --stripe-size
13103         check_default_stripe_attr --stripe-index
13104 }
13105 run_test 204b "Print default stripe size and offset"
13106
13107 test_204c() {
13108         test_mkdir $DIR/$tdir
13109         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
13110
13111         check_default_stripe_attr --stripe-count
13112         check_default_stripe_attr --stripe-index
13113 }
13114 run_test 204c "Print default stripe count and offset"
13115
13116 test_204d() {
13117         test_mkdir $DIR/$tdir
13118         $SETSTRIPE --stripe-index 0 $DIR/$tdir
13119
13120         check_default_stripe_attr --stripe-count
13121         check_default_stripe_attr --stripe-size
13122 }
13123 run_test 204d "Print default stripe count and size"
13124
13125 test_204e() {
13126         test_mkdir $DIR/$tdir
13127         $SETSTRIPE -d $DIR/$tdir
13128
13129         check_default_stripe_attr --stripe-count --raw
13130         check_default_stripe_attr --stripe-size --raw
13131         check_default_stripe_attr --stripe-index --raw
13132 }
13133 run_test 204e "Print raw stripe attributes"
13134
13135 test_204f() {
13136         test_mkdir $DIR/$tdir
13137         $SETSTRIPE --stripe-count 1 $DIR/$tdir
13138
13139         check_default_stripe_attr --stripe-size --raw
13140         check_default_stripe_attr --stripe-index --raw
13141 }
13142 run_test 204f "Print raw stripe size and offset"
13143
13144 test_204g() {
13145         test_mkdir $DIR/$tdir
13146         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
13147
13148         check_default_stripe_attr --stripe-count --raw
13149         check_default_stripe_attr --stripe-index --raw
13150 }
13151 run_test 204g "Print raw stripe count and offset"
13152
13153 test_204h() {
13154         test_mkdir $DIR/$tdir
13155         $SETSTRIPE --stripe-index 0 $DIR/$tdir
13156
13157         check_default_stripe_attr --stripe-count --raw
13158         check_default_stripe_attr --stripe-size --raw
13159 }
13160 run_test 204h "Print raw stripe count and size"
13161
13162 # Figure out which job scheduler is being used, if any,
13163 # or use a fake one
13164 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
13165         JOBENV=SLURM_JOB_ID
13166 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
13167         JOBENV=LSB_JOBID
13168 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
13169         JOBENV=PBS_JOBID
13170 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
13171         JOBENV=LOADL_STEP_ID
13172 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
13173         JOBENV=JOB_ID
13174 else
13175         $LCTL list_param jobid_name > /dev/null 2>&1
13176         if [ $? -eq 0 ]; then
13177                 JOBENV=nodelocal
13178         else
13179                 JOBENV=FAKE_JOBID
13180         fi
13181 fi
13182
13183 verify_jobstats() {
13184         local cmd=($1)
13185         shift
13186         local facets="$@"
13187
13188 # we don't really need to clear the stats for this test to work, since each
13189 # command has a unique jobid, but it makes debugging easier if needed.
13190 #       for facet in $facets; do
13191 #               local dev=$(convert_facet2label $facet)
13192 #               # clear old jobstats
13193 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
13194 #       done
13195
13196         # use a new JobID for each test, or we might see an old one
13197         [ "$JOBENV" = "FAKE_JOBID" ] &&
13198                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
13199
13200         JOBVAL=${!JOBENV}
13201
13202         [ "$JOBENV" = "nodelocal" ] && {
13203                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
13204                 $LCTL set_param jobid_name=$FAKE_JOBID
13205                 JOBVAL=$FAKE_JOBID
13206         }
13207
13208         log "Test: ${cmd[*]}"
13209         log "Using JobID environment variable $JOBENV=$JOBVAL"
13210
13211         if [ $JOBENV = "FAKE_JOBID" ]; then
13212                 FAKE_JOBID=$JOBVAL ${cmd[*]}
13213         else
13214                 ${cmd[*]}
13215         fi
13216
13217         # all files are created on OST0000
13218         for facet in $facets; do
13219                 local stats="*.$(convert_facet2label $facet).job_stats"
13220                 if [ $(do_facet $facet lctl get_param $stats |
13221                        grep -c $JOBVAL) -ne 1 ]; then
13222                         do_facet $facet lctl get_param $stats
13223                         error "No jobstats for $JOBVAL found on $facet::$stats"
13224                 fi
13225         done
13226 }
13227
13228 jobstats_set() {
13229         local new_jobenv=$1
13230
13231         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$new_jobenv
13232         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $new_jobenv
13233 }
13234
13235 test_205() { # Job stats
13236         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
13237                 { skip "Need MDS version with at least 2.7.1"; return 0; }
13238
13239         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13240         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
13241         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13242         remote_ost_nodsh && skip "remote OST with nodsh" && return
13243
13244         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
13245                 skip "Server doesn't support jobstats" && return 0
13246         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
13247
13248         local old_jobenv=$($LCTL get_param -n jobid_var)
13249         if [ $old_jobenv != $JOBENV ]; then
13250                 jobstats_set $JOBENV
13251                 stack_trap "do_facet mgs \
13252                         $LCTL conf_param $FSNAME.sys.jobid_var=$old_jobenv" EXIT
13253         fi
13254
13255         changelog_register
13256
13257         local old_interval=$(do_facet $SINGLEMDS lctl get_param -n \
13258                                 mdt.*.job_cleanup_interval | head -n 1)
13259         local new_interval=5
13260         do_facet $SINGLEMDS \
13261                 $LCTL set_param mdt.*.job_cleanup_interval=$new_interval
13262         stack_trap "do_facet $SINGLEMDS \
13263                 $LCTL set_param mdt.*.job_cleanup_interval=$old_interval" EXIT
13264         local start=$SECONDS
13265
13266         local cmd
13267         # mkdir
13268         cmd="mkdir $DIR/$tdir"
13269         verify_jobstats "$cmd" "$SINGLEMDS"
13270         # rmdir
13271         cmd="rmdir $DIR/$tdir"
13272         verify_jobstats "$cmd" "$SINGLEMDS"
13273         # mkdir on secondary MDT
13274         if [ $MDSCOUNT -gt 1 ]; then
13275                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
13276                 verify_jobstats "$cmd" "mds2"
13277         fi
13278         # mknod
13279         cmd="mknod $DIR/$tfile c 1 3"
13280         verify_jobstats "$cmd" "$SINGLEMDS"
13281         # unlink
13282         cmd="rm -f $DIR/$tfile"
13283         verify_jobstats "$cmd" "$SINGLEMDS"
13284         # create all files on OST0000 so verify_jobstats can find OST stats
13285         # open & close
13286         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
13287         verify_jobstats "$cmd" "$SINGLEMDS"
13288         # setattr
13289         cmd="touch $DIR/$tfile"
13290         verify_jobstats "$cmd" "$SINGLEMDS ost1"
13291         # write
13292         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
13293         verify_jobstats "$cmd" "ost1"
13294         # read
13295         cancel_lru_locks osc
13296         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
13297         verify_jobstats "$cmd" "ost1"
13298         # truncate
13299         cmd="$TRUNCATE $DIR/$tfile 0"
13300         verify_jobstats "$cmd" "$SINGLEMDS ost1"
13301         # rename
13302         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
13303         verify_jobstats "$cmd" "$SINGLEMDS"
13304         # jobstats expiry - sleep until old stats should be expired
13305         local left=$((new_interval + 5 - (SECONDS - start)))
13306         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
13307                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
13308                         "0" $left
13309         cmd="mkdir $DIR/$tdir.expire"
13310         verify_jobstats "$cmd" "$SINGLEMDS"
13311         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
13312             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
13313
13314         # Ensure that jobid are present in changelog (if supported by MDS)
13315         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ];then
13316                 changelog_dump | tail -10
13317                 jobids=$(changelog_dump | tail -9 | grep -c "j=")
13318                 [ $jobids -eq 9 ] ||
13319                         error "Wrong changelog jobid count $jobids != 9"
13320
13321                 # LU-5862
13322                 JOBENV="disable"
13323                 jobstats_set $JOBENV
13324                 touch $DIR/$tfile
13325                 changelog_dump | grep $tfile
13326                 jobids=$(changelog_dump | grep $tfile | tail -1 | grep -c "j=")
13327                 [ $jobids -eq 0 ] ||
13328                         error "Unexpected jobids when jobid_var=$JOBENV"
13329         fi
13330 }
13331 run_test 205 "Verify job stats"
13332
13333 # LU-1480, LU-1773 and LU-1657
13334 test_206() {
13335         mkdir -p $DIR/$tdir
13336         $SETSTRIPE -c -1 $DIR/$tdir
13337 #define OBD_FAIL_LOV_INIT 0x1403
13338         $LCTL set_param fail_loc=0xa0001403
13339         $LCTL set_param fail_val=1
13340         touch $DIR/$tdir/$tfile || true
13341 }
13342 run_test 206 "fail lov_init_raid0() doesn't lbug"
13343
13344 test_207a() {
13345         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
13346         local fsz=`stat -c %s $DIR/$tfile`
13347         cancel_lru_locks mdc
13348
13349         # do not return layout in getattr intent
13350 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
13351         $LCTL set_param fail_loc=0x170
13352         local sz=`stat -c %s $DIR/$tfile`
13353
13354         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
13355
13356         rm -rf $DIR/$tfile
13357 }
13358 run_test 207a "can refresh layout at glimpse"
13359
13360 test_207b() {
13361         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
13362         local cksum=`md5sum $DIR/$tfile`
13363         local fsz=`stat -c %s $DIR/$tfile`
13364         cancel_lru_locks mdc
13365         cancel_lru_locks osc
13366
13367         # do not return layout in getattr intent
13368 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
13369         $LCTL set_param fail_loc=0x171
13370
13371         # it will refresh layout after the file is opened but before read issues
13372         echo checksum is "$cksum"
13373         echo "$cksum" |md5sum -c --quiet || error "file differs"
13374
13375         rm -rf $DIR/$tfile
13376 }
13377 run_test 207b "can refresh layout at open"
13378
13379 test_208() {
13380         # FIXME: in this test suite, only RD lease is used. This is okay
13381         # for now as only exclusive open is supported. After generic lease
13382         # is done, this test suite should be revised. - Jinshan
13383
13384         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13385         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
13386                 { skip "Need MDS version at least 2.4.52"; return 0; }
13387
13388         echo "==== test 1: verify get lease work"
13389         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
13390
13391         echo "==== test 2: verify lease can be broken by upcoming open"
13392         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
13393         local PID=$!
13394         sleep 1
13395
13396         $MULTIOP $DIR/$tfile oO_RDONLY:c
13397         kill -USR1 $PID && wait $PID || error "break lease error"
13398
13399         echo "==== test 3: verify lease can't be granted if an open already exists"
13400         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
13401         local PID=$!
13402         sleep 1
13403
13404         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
13405         kill -USR1 $PID && wait $PID || error "open file error"
13406
13407         echo "==== test 4: lease can sustain over recovery"
13408         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
13409         PID=$!
13410         sleep 1
13411
13412         fail mds1
13413
13414         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
13415
13416         echo "==== test 5: lease broken can't be regained by replay"
13417         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
13418         PID=$!
13419         sleep 1
13420
13421         # open file to break lease and then recovery
13422         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
13423         fail mds1
13424
13425         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
13426
13427         rm -f $DIR/$tfile
13428 }
13429 run_test 208 "Exclusive open"
13430
13431 test_209() {
13432         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
13433                 skip_env "must have disp_stripe" && return
13434
13435         touch $DIR/$tfile
13436         sync; sleep 5; sync;
13437
13438         echo 3 > /proc/sys/vm/drop_caches
13439         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
13440
13441         # open/close 500 times
13442         for i in $(seq 500); do
13443                 cat $DIR/$tfile
13444         done
13445
13446         echo 3 > /proc/sys/vm/drop_caches
13447         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
13448
13449         echo "before: $req_before, after: $req_after"
13450         [ $((req_after - req_before)) -ge 300 ] &&
13451                 error "open/close requests are not freed"
13452         return 0
13453 }
13454 run_test 209 "read-only open/close requests should be freed promptly"
13455
13456 test_212() {
13457         size=`date +%s`
13458         size=$((size % 8192 + 1))
13459         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
13460         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
13461         rm -f $DIR/f212 $DIR/f212.xyz
13462 }
13463 run_test 212 "Sendfile test ============================================"
13464
13465 test_213() {
13466         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
13467         cancel_lru_locks osc
13468         lctl set_param fail_loc=0x8000040f
13469         # generate a read lock
13470         cat $DIR/$tfile > /dev/null
13471         # write to the file, it will try to cancel the above read lock.
13472         cat /etc/hosts >> $DIR/$tfile
13473 }
13474 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
13475
13476 test_214() { # for bug 20133
13477         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
13478         for (( i=0; i < 340; i++ )) ; do
13479                 touch $DIR/$tdir/d214c/a$i
13480         done
13481
13482         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
13483         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
13484         ls $DIR/d214c || error "ls $DIR/d214c failed"
13485         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
13486         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
13487 }
13488 run_test 214 "hash-indexed directory test - bug 20133"
13489
13490 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
13491 create_lnet_proc_files() {
13492         lctl get_param -n $1 >$TMP/lnet_$1.sys || error "cannot read lnet.$1"
13493 }
13494
13495 # counterpart of create_lnet_proc_files
13496 remove_lnet_proc_files() {
13497         rm -f $TMP/lnet_$1.sys
13498 }
13499
13500 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
13501 # 3rd arg as regexp for body
13502 check_lnet_proc_stats() {
13503         local l=$(cat "$TMP/lnet_$1" |wc -l)
13504         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
13505
13506         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
13507 }
13508
13509 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
13510 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
13511 # optional and can be regexp for 2nd line (lnet.routes case)
13512 check_lnet_proc_entry() {
13513         local blp=2          # blp stands for 'position of 1st line of body'
13514         [ -z "$5" ] || blp=3 # lnet.routes case
13515
13516         local l=$(cat "$TMP/lnet_$1" |wc -l)
13517         # subtracting one from $blp because the body can be empty
13518         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
13519
13520         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
13521                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
13522
13523         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
13524                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
13525
13526         # bail out if any unexpected line happened
13527         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
13528         [ "$?" != 0 ] || error "$2 misformatted"
13529 }
13530
13531 test_215() { # for bugs 18102, 21079, 21517
13532         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13533         local N='(0|[1-9][0-9]*)'       # non-negative numeric
13534         local P='[1-9][0-9]*'           # positive numeric
13535         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
13536         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
13537         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
13538         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
13539
13540         local L1 # regexp for 1st line
13541         local L2 # regexp for 2nd line (optional)
13542         local BR # regexp for the rest (body)
13543
13544         # lnet.stats should look as 11 space-separated non-negative numerics
13545         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
13546         create_lnet_proc_files "stats"
13547         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
13548         remove_lnet_proc_files "stats"
13549
13550         # lnet.routes should look like this:
13551         # Routing disabled/enabled
13552         # net hops priority state router
13553         # where net is a string like tcp0, hops > 0, priority >= 0,
13554         # state is up/down,
13555         # router is a string like 192.168.1.1@tcp2
13556         L1="^Routing (disabled|enabled)$"
13557         L2="^net +hops +priority +state +router$"
13558         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
13559         create_lnet_proc_files "routes"
13560         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
13561         remove_lnet_proc_files "routes"
13562
13563         # lnet.routers should look like this:
13564         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
13565         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
13566         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
13567         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
13568         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
13569         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
13570         create_lnet_proc_files "routers"
13571         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
13572         remove_lnet_proc_files "routers"
13573
13574         # lnet.peers should look like this:
13575         # nid refs state last max rtr min tx min queue
13576         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
13577         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
13578         # numeric (0 or >0 or <0), queue >= 0.
13579         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
13580         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
13581         create_lnet_proc_files "peers"
13582         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
13583         remove_lnet_proc_files "peers"
13584
13585         # lnet.buffers  should look like this:
13586         # pages count credits min
13587         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
13588         L1="^pages +count +credits +min$"
13589         BR="^ +$N +$N +$I +$I$"
13590         create_lnet_proc_files "buffers"
13591         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
13592         remove_lnet_proc_files "buffers"
13593
13594         # lnet.nis should look like this:
13595         # nid status alive refs peer rtr max tx min
13596         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
13597         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
13598         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
13599         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
13600         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
13601         create_lnet_proc_files "nis"
13602         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
13603         remove_lnet_proc_files "nis"
13604
13605         # can we successfully write to lnet.stats?
13606         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
13607 }
13608 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
13609
13610 test_216() { # bug 20317
13611         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13612         remote_ost_nodsh && skip "remote OST with nodsh" && return
13613
13614         local node
13615         local facets=$(get_facets OST)
13616         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13617
13618         save_lustre_params client "osc.*.contention_seconds" > $p
13619         save_lustre_params $facets \
13620                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
13621         save_lustre_params $facets \
13622                 "ldlm.namespaces.filter-*.contended_locks" >> $p
13623         save_lustre_params $facets \
13624                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
13625         clear_stats osc.*.osc_stats
13626
13627         # agressive lockless i/o settings
13628         do_nodes $(comma_list $(osts_nodes)) \
13629                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
13630                         ldlm.namespaces.filter-*.contended_locks=0 \
13631                         ldlm.namespaces.filter-*.contention_seconds=60"
13632         lctl set_param -n osc.*.contention_seconds=60
13633
13634         $DIRECTIO write $DIR/$tfile 0 10 4096
13635         $CHECKSTAT -s 40960 $DIR/$tfile
13636
13637         # disable lockless i/o
13638         do_nodes $(comma_list $(osts_nodes)) \
13639                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
13640                         ldlm.namespaces.filter-*.contended_locks=32 \
13641                         ldlm.namespaces.filter-*.contention_seconds=0"
13642         lctl set_param -n osc.*.contention_seconds=0
13643         clear_stats osc.*.osc_stats
13644
13645         dd if=/dev/zero of=$DIR/$tfile count=0
13646         $CHECKSTAT -s 0 $DIR/$tfile
13647
13648         restore_lustre_params <$p
13649         rm -f $p
13650         rm $DIR/$tfile
13651 }
13652 run_test 216 "check lockless direct write updates file size and kms correctly"
13653
13654 test_217() { # bug 22430
13655         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13656         local node
13657         local nid
13658
13659         for node in $(nodes_list); do
13660                 nid=$(host_nids_address $node $NETTYPE)
13661                 if [[ $nid = *-* ]] ; then
13662                         echo "lctl ping $(h2nettype $nid)"
13663                         lctl ping $(h2nettype $nid)
13664                 else
13665                         echo "skipping $node (no hyphen detected)"
13666                 fi
13667         done
13668 }
13669 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
13670
13671 test_218() {
13672        # do directio so as not to populate the page cache
13673        log "creating a 10 Mb file"
13674        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
13675        log "starting reads"
13676        dd if=$DIR/$tfile of=/dev/null bs=4096 &
13677        log "truncating the file"
13678        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
13679        log "killing dd"
13680        kill %+ || true # reads might have finished
13681        echo "wait until dd is finished"
13682        wait
13683        log "removing the temporary file"
13684        rm -rf $DIR/$tfile || error "tmp file removal failed"
13685 }
13686 run_test 218 "parallel read and truncate should not deadlock ======================="
13687
13688 test_219() {
13689         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13690         # write one partial page
13691         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
13692         # set no grant so vvp_io_commit_write will do sync write
13693         $LCTL set_param fail_loc=0x411
13694         # write a full page at the end of file
13695         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
13696
13697         $LCTL set_param fail_loc=0
13698         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
13699         $LCTL set_param fail_loc=0x411
13700         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
13701
13702         # LU-4201
13703         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
13704         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
13705 }
13706 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
13707
13708 test_220() { #LU-325
13709         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13710         remote_ost_nodsh && skip "remote OST with nodsh" && return
13711         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13712         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
13713         local OSTIDX=0
13714
13715         # create on MDT0000 so the last_id and next_id are correct
13716         mkdir $DIR/$tdir
13717         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
13718         OST=${OST%_UUID}
13719
13720         # on the mdt's osc
13721         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
13722         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
13723                         osc.$mdtosc_proc1.prealloc_last_id)
13724         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
13725                         osc.$mdtosc_proc1.prealloc_next_id)
13726
13727         $LFS df -i
13728
13729         if ! combined_mgs_mds ; then
13730                 mount_mgs_client
13731         fi
13732
13733         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
13734         #define OBD_FAIL_OST_ENOINO              0x229
13735         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
13736         create_pool $FSNAME.$TESTNAME || return 1
13737         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
13738
13739         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
13740
13741         MDSOBJS=$((last_id - next_id))
13742         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
13743
13744         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
13745         echo "OST still has $count kbytes free"
13746
13747         echo "create $MDSOBJS files @next_id..."
13748         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
13749
13750         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
13751                         osc.$mdtosc_proc1.prealloc_last_id)
13752         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
13753                         osc.$mdtosc_proc1.prealloc_next_id)
13754
13755         echo "after creation, last_id=$last_id2, next_id=$next_id2"
13756         $LFS df -i
13757
13758         echo "cleanup..."
13759
13760         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
13761         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
13762
13763         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST ||
13764                 error "$LCTL pool_remove $FSNAME.$TESTNAME $OST failed"
13765         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
13766                 error "$LCTL pool_destroy $FSNAME.$TESTNAME failed"
13767         echo "unlink $MDSOBJS files @$next_id..."
13768         unlinkmany $DIR/$tdir/f $MDSOBJS || error "unlinkmany failed"
13769
13770         if ! combined_mgs_mds ; then
13771                 umount_mgs_client
13772         fi
13773 }
13774 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
13775
13776 test_221() {
13777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13778         dd if=`which date` of=$MOUNT/date oflag=sync
13779         chmod +x $MOUNT/date
13780
13781         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
13782         $LCTL set_param fail_loc=0x80001401
13783
13784         $MOUNT/date > /dev/null
13785         rm -f $MOUNT/date
13786 }
13787 run_test 221 "make sure fault and truncate race to not cause OOM"
13788
13789 test_222a () {
13790         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13791         rm -rf $DIR/$tdir
13792         test_mkdir $DIR/$tdir
13793         $LFS setstripe -c 1 -i 0 $DIR/$tdir
13794         createmany -o $DIR/$tdir/$tfile 10
13795         cancel_lru_locks mdc
13796         cancel_lru_locks osc
13797         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13798         $LCTL set_param fail_loc=0x31a
13799         ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
13800         $LCTL set_param fail_loc=0
13801         rm -r $DIR/$tdir
13802 }
13803 run_test 222a "AGL for ls should not trigger CLIO lock failure"
13804
13805 test_222b () {
13806         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13807         rm -rf $DIR/$tdir
13808         test_mkdir $DIR/$tdir
13809         $LFS setstripe -c 1 -i 0 $DIR/$tdir
13810         createmany -o $DIR/$tdir/$tfile 10
13811         cancel_lru_locks mdc
13812         cancel_lru_locks osc
13813         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13814         $LCTL set_param fail_loc=0x31a
13815         rm -r $DIR/$tdir || error "AGL for rmdir failed"
13816         $LCTL set_param fail_loc=0
13817 }
13818 run_test 222b "AGL for rmdir should not trigger CLIO lock failure"
13819
13820 test_223 () {
13821         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13822         rm -rf $DIR/$tdir
13823         test_mkdir $DIR/$tdir
13824         $LFS setstripe -c 1 -i 0 $DIR/$tdir
13825         createmany -o $DIR/$tdir/$tfile 10
13826         cancel_lru_locks mdc
13827         cancel_lru_locks osc
13828         #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
13829         $LCTL set_param fail_loc=0x31b
13830         ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
13831         $LCTL set_param fail_loc=0
13832         rm -r $DIR/$tdir
13833 }
13834 run_test 223 "osc reenqueue if without AGL lock granted ======================="
13835
13836 test_224a() { # LU-1039, MRP-303
13837         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13838         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
13839         $LCTL set_param fail_loc=0x508
13840         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
13841         $LCTL set_param fail_loc=0
13842         df $DIR
13843 }
13844 run_test 224a "Don't panic on bulk IO failure"
13845
13846 test_224b() { # LU-1039, MRP-303
13847         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13848         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
13849         cancel_lru_locks osc
13850         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
13851         $LCTL set_param fail_loc=0x515
13852         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
13853         $LCTL set_param fail_loc=0
13854         df $DIR
13855 }
13856 run_test 224b "Don't panic on bulk IO failure"
13857
13858 test_224c() { # LU-6441
13859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13860         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13861
13862         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13863         save_writethrough $p
13864         set_cache writethrough on
13865
13866         local pages_per_rpc=$($LCTL get_param \
13867                                 osc.*.max_pages_per_rpc)
13868         local at_max=$($LCTL get_param -n at_max)
13869         local timeout=$($LCTL get_param -n timeout)
13870         local test_at="$LCTL get_param -n at_max"
13871         local param_at="$FSNAME.sys.at_max"
13872         local test_timeout="$LCTL get_param -n timeout"
13873         local param_timeout="$FSNAME.sys.timeout"
13874
13875         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
13876
13877         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
13878                 error "conf_param at_max=0 failed"
13879         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
13880                 error "conf_param timeout=5 failed"
13881
13882         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
13883         do_facet ost1 $LCTL set_param fail_loc=0x520
13884         $LFS setstripe -c 1 -i 0 $DIR/$tfile
13885         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
13886         sync
13887         do_facet ost1 $LCTL set_param fail_loc=0
13888
13889         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
13890                 error "conf_param at_max=$at_max failed"
13891         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
13892                 $timeout || error "conf_param timeout=$timeout failed"
13893
13894         $LCTL set_param -n $pages_per_rpc
13895         restore_lustre_params < $p
13896         rm -f $p
13897 }
13898 run_test 224c "Don't hang if one of md lost during large bulk RPC"
13899
13900 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
13901 test_225a () {
13902         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13903         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13904         if [ -z ${MDSSURVEY} ]; then
13905               skip_env "mds-survey not found" && return
13906         fi
13907
13908         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13909                 { skip "Need MDS version at least 2.2.51"; return; }
13910
13911         local mds=$(facet_host $SINGLEMDS)
13912         local target=$(do_nodes $mds 'lctl dl' |
13913                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
13914
13915         local cmd1="file_count=1000 thrhi=4"
13916         local cmd2="dir_count=2 layer=mdd stripe_count=0"
13917         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13918         local cmd="$cmd1 $cmd2 $cmd3"
13919
13920         rm -f ${TMP}/mds_survey*
13921         echo + $cmd
13922         eval $cmd || error "mds-survey with zero-stripe failed"
13923         cat ${TMP}/mds_survey*
13924         rm -f ${TMP}/mds_survey*
13925 }
13926 run_test 225a "Metadata survey sanity with zero-stripe"
13927
13928 test_225b () {
13929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13930         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13931         if [ -z ${MDSSURVEY} ]; then
13932               skip_env "mds-survey not found" && return
13933         fi
13934         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13935             { skip "Need MDS version at least 2.2.51"; return; }
13936
13937         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
13938               skip_env "Need to mount OST to test" && return
13939         fi
13940
13941         local mds=$(facet_host $SINGLEMDS)
13942         local target=$(do_nodes $mds 'lctl dl' |
13943                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
13944
13945         local cmd1="file_count=1000 thrhi=4"
13946         local cmd2="dir_count=2 layer=mdd stripe_count=1"
13947         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13948         local cmd="$cmd1 $cmd2 $cmd3"
13949
13950         rm -f ${TMP}/mds_survey*
13951         echo + $cmd
13952         eval $cmd || error "mds-survey with stripe_count failed"
13953         cat ${TMP}/mds_survey*
13954         rm -f ${TMP}/mds_survey*
13955 }
13956 run_test 225b "Metadata survey sanity with stripe_count = 1"
13957
13958 mcreate_path2fid () {
13959         local mode=$1
13960         local major=$2
13961         local minor=$3
13962         local name=$4
13963         local desc=$5
13964         local path=$DIR/$tdir/$name
13965         local fid
13966         local rc
13967         local fid_path
13968
13969         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
13970                 error "cannot create $desc"
13971
13972         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
13973         rc=$?
13974         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
13975
13976         fid_path=$($LFS fid2path $MOUNT $fid)
13977         rc=$?
13978         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
13979
13980         [ "$path" == "$fid_path" ] ||
13981                 error "fid2path returned $fid_path, expected $path"
13982
13983         echo "pass with $path and $fid"
13984 }
13985
13986 test_226a () {
13987         rm -rf $DIR/$tdir
13988         mkdir -p $DIR/$tdir
13989
13990         mcreate_path2fid 0010666 0 0 fifo "FIFO"
13991         mcreate_path2fid 0020666 1 3 null "character special file (null)"
13992         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
13993         mcreate_path2fid 0040666 0 0 dir "directory"
13994         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
13995         mcreate_path2fid 0100666 0 0 file "regular file"
13996         mcreate_path2fid 0120666 0 0 link "symbolic link"
13997         mcreate_path2fid 0140666 0 0 sock "socket"
13998 }
13999 run_test 226a "call path2fid and fid2path on files of all type"
14000
14001 test_226b () {
14002         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14003         rm -rf $DIR/$tdir
14004         local MDTIDX=1
14005
14006         mkdir -p $DIR/$tdir
14007         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
14008                 error "create remote directory failed"
14009         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
14010         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
14011                                 "character special file (null)"
14012         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
14013                                 "character special file (no device)"
14014         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
14015         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
14016                                 "block special file (loop)"
14017         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
14018         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
14019         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
14020 }
14021 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
14022
14023 # LU-1299 Executing or running ldd on a truncated executable does not
14024 # cause an out-of-memory condition.
14025 test_227() {
14026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14027         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
14028         dd if=$(which date) of=$MOUNT/date bs=1k count=1
14029         chmod +x $MOUNT/date
14030
14031         $MOUNT/date > /dev/null
14032         ldd $MOUNT/date > /dev/null
14033         rm -f $MOUNT/date
14034 }
14035 run_test 227 "running truncated executable does not cause OOM"
14036
14037 # LU-1512 try to reuse idle OI blocks
14038 test_228a() {
14039         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14040         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14041         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14042                 skip "ldiskfs only test" && return
14043
14044         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14045         local myDIR=$DIR/$tdir
14046
14047         mkdir -p $myDIR
14048         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14049         $LCTL set_param fail_loc=0x80001002
14050         createmany -o $myDIR/t- 10000
14051         $LCTL set_param fail_loc=0
14052         # The guard is current the largest FID holder
14053         touch $myDIR/guard
14054         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14055                     tr -d '[')
14056         local IDX=$(($SEQ % 64))
14057
14058         do_facet $SINGLEMDS sync
14059         # Make sure journal flushed.
14060         sleep 6
14061         local blk1=$(do_facet $SINGLEMDS \
14062                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14063                      grep Blockcount | awk '{print $4}')
14064
14065         # Remove old files, some OI blocks will become idle.
14066         unlinkmany $myDIR/t- 10000
14067         # Create new files, idle OI blocks should be reused.
14068         createmany -o $myDIR/t- 2000
14069         do_facet $SINGLEMDS sync
14070         # Make sure journal flushed.
14071         sleep 6
14072         local blk2=$(do_facet $SINGLEMDS \
14073                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14074                      grep Blockcount | awk '{print $4}')
14075
14076         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14077 }
14078 run_test 228a "try to reuse idle OI blocks"
14079
14080 test_228b() {
14081         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14082         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14083         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14084                 skip "ldiskfs only test" && return
14085
14086         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14087         local myDIR=$DIR/$tdir
14088
14089         mkdir -p $myDIR
14090         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14091         $LCTL set_param fail_loc=0x80001002
14092         createmany -o $myDIR/t- 10000
14093         $LCTL set_param fail_loc=0
14094         # The guard is current the largest FID holder
14095         touch $myDIR/guard
14096         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14097                     tr -d '[')
14098         local IDX=$(($SEQ % 64))
14099
14100         do_facet $SINGLEMDS sync
14101         # Make sure journal flushed.
14102         sleep 6
14103         local blk1=$(do_facet $SINGLEMDS \
14104                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14105                      grep Blockcount | awk '{print $4}')
14106
14107         # Remove old files, some OI blocks will become idle.
14108         unlinkmany $myDIR/t- 10000
14109
14110         # stop the MDT
14111         stop $SINGLEMDS || error "Fail to stop MDT."
14112         # remount the MDT
14113         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
14114
14115         df $MOUNT || error "Fail to df."
14116         # Create new files, idle OI blocks should be reused.
14117         createmany -o $myDIR/t- 2000
14118         do_facet $SINGLEMDS sync
14119         # Make sure journal flushed.
14120         sleep 6
14121         local blk2=$(do_facet $SINGLEMDS \
14122                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14123                      grep Blockcount | awk '{print $4}')
14124
14125         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14126 }
14127 run_test 228b "idle OI blocks can be reused after MDT restart"
14128
14129 #LU-1881
14130 test_228c() {
14131         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14132         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14133         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
14134                 skip "ldiskfs only test" && return
14135
14136         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
14137         local myDIR=$DIR/$tdir
14138
14139         mkdir -p $myDIR
14140         #define OBD_FAIL_SEQ_EXHAUST             0x1002
14141         $LCTL set_param fail_loc=0x80001002
14142         # 20000 files can guarantee there are index nodes in the OI file
14143         createmany -o $myDIR/t- 20000
14144         $LCTL set_param fail_loc=0
14145         # The guard is current the largest FID holder
14146         touch $myDIR/guard
14147         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
14148                     tr -d '[')
14149         local IDX=$(($SEQ % 64))
14150
14151         do_facet $SINGLEMDS sync
14152         # Make sure journal flushed.
14153         sleep 6
14154         local blk1=$(do_facet $SINGLEMDS \
14155                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14156                      grep Blockcount | awk '{print $4}')
14157
14158         # Remove old files, some OI blocks will become idle.
14159         unlinkmany $myDIR/t- 20000
14160         rm -f $myDIR/guard
14161         # The OI file should become empty now
14162
14163         # Create new files, idle OI blocks should be reused.
14164         createmany -o $myDIR/t- 2000
14165         do_facet $SINGLEMDS sync
14166         # Make sure journal flushed.
14167         sleep 6
14168         local blk2=$(do_facet $SINGLEMDS \
14169                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
14170                      grep Blockcount | awk '{print $4}')
14171
14172         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
14173 }
14174 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
14175
14176 test_229() { # LU-2482, LU-3448
14177         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
14178                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
14179                 return
14180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14181         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
14182
14183         rm -f $DIR/$tfile
14184
14185         # Create a file with a released layout and stripe count 2.
14186         $MULTIOP $DIR/$tfile H2c ||
14187                 error "failed to create file with released layout"
14188
14189         $GETSTRIPE -v $DIR/$tfile
14190
14191         local pattern=$($GETSTRIPE -L $DIR/$tfile)
14192         [ X"$pattern" = X"released" ] || error "pattern error ($pattern)"
14193
14194         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
14195         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
14196         stat $DIR/$tfile || error "failed to stat released file"
14197
14198         chown $RUNAS_ID $DIR/$tfile ||
14199                 error "chown $RUNAS_ID $DIR/$tfile failed"
14200
14201         chgrp $RUNAS_ID $DIR/$tfile ||
14202                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
14203
14204         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
14205         rm $DIR/$tfile || error "failed to remove released file"
14206 }
14207 run_test 229 "getstripe/stat/rm/attr changes work on released files"
14208
14209 test_230a() {
14210         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14211         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14212         local MDTIDX=1
14213
14214         test_mkdir $DIR/$tdir
14215         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
14216         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
14217         [ $mdt_idx -ne 0 ] &&
14218                 error "create local directory on wrong MDT $mdt_idx"
14219
14220         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
14221                         error "create remote directory failed"
14222         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
14223         [ $mdt_idx -ne $MDTIDX ] &&
14224                 error "create remote directory on wrong MDT $mdt_idx"
14225
14226         createmany -o $DIR/$tdir/test_230/t- 10 ||
14227                 error "create files on remote directory failed"
14228         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
14229         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
14230         rm -r $DIR/$tdir || error "unlink remote directory failed"
14231 }
14232 run_test 230a "Create remote directory and files under the remote directory"
14233
14234 test_230b() {
14235         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14236         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14237         local MDTIDX=1
14238         local mdt_index
14239         local i
14240         local file
14241         local pid
14242         local stripe_count
14243         local migrate_dir=$DIR/$tdir/migrate_dir
14244         local other_dir=$DIR/$tdir/other_dir
14245
14246         test_mkdir $DIR/$tdir
14247         test_mkdir -i0 -c1 $migrate_dir
14248         test_mkdir -i0 -c1 $other_dir
14249         for ((i=0; i<10; i++)); do
14250                 mkdir -p $migrate_dir/dir_${i}
14251                 createmany -o $migrate_dir/dir_${i}/f 10 ||
14252                         error "create files under remote dir failed $i"
14253         done
14254
14255         cp /etc/passwd $migrate_dir/$tfile
14256         cp /etc/passwd $other_dir/$tfile
14257         chattr +SAD $migrate_dir
14258         chattr +SAD $migrate_dir/$tfile
14259
14260         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14261         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14262         local old_dir_mode=$(stat -c%f $migrate_dir)
14263         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
14264
14265         mkdir -p $migrate_dir/dir_default_stripe2
14266         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
14267         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
14268
14269         mkdir -p $other_dir
14270         ln $migrate_dir/$tfile $other_dir/luna
14271         ln $migrate_dir/$tfile $migrate_dir/sofia
14272         ln $other_dir/$tfile $migrate_dir/david
14273         ln -s $migrate_dir/$tfile $other_dir/zachary
14274         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
14275         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
14276
14277         $LFS migrate -m $MDTIDX $migrate_dir ||
14278                 error "fails on migrating remote dir to MDT1"
14279
14280         echo "migratate to MDT1, then checking.."
14281         for ((i = 0; i < 10; i++)); do
14282                 for file in $(find $migrate_dir/dir_${i}); do
14283                         mdt_index=$($LFS getstripe -M $file)
14284                         [ $mdt_index == $MDTIDX ] ||
14285                                 error "$file is not on MDT${MDTIDX}"
14286                 done
14287         done
14288
14289         # the multiple link file should still in MDT0
14290         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
14291         [ $mdt_index == 0 ] ||
14292                 error "$file is not on MDT${MDTIDX}"
14293
14294         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14295         [ "$old_dir_flag" = "$new_dir_flag" ] ||
14296                 error " expect $old_dir_flag get $new_dir_flag"
14297
14298         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14299         [ "$old_file_flag" = "$new_file_flag" ] ||
14300                 error " expect $old_file_flag get $new_file_flag"
14301
14302         local new_dir_mode=$(stat -c%f $migrate_dir)
14303         [ "$old_dir_mode" = "$new_dir_mode" ] ||
14304                 error "expect mode $old_dir_mode get $new_dir_mode"
14305
14306         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
14307         [ "$old_file_mode" = "$new_file_mode" ] ||
14308                 error "expect mode $old_file_mode get $new_file_mode"
14309
14310         diff /etc/passwd $migrate_dir/$tfile ||
14311                 error "$tfile different after migration"
14312
14313         diff /etc/passwd $other_dir/luna ||
14314                 error "luna different after migration"
14315
14316         diff /etc/passwd $migrate_dir/sofia ||
14317                 error "sofia different after migration"
14318
14319         diff /etc/passwd $migrate_dir/david ||
14320                 error "david different after migration"
14321
14322         diff /etc/passwd $other_dir/zachary ||
14323                 error "zachary different after migration"
14324
14325         diff /etc/passwd $migrate_dir/${tfile}_ln ||
14326                 error "${tfile}_ln different after migration"
14327
14328         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
14329                 error "${tfile}_ln_other different after migration"
14330
14331         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
14332         [ $stripe_count = 2 ] ||
14333                 error "dir strpe_count $d != 2 after migration."
14334
14335         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
14336         [ $stripe_count = 2 ] ||
14337                 error "file strpe_count $d != 2 after migration."
14338
14339         #migrate back to MDT0
14340         MDTIDX=0
14341
14342         $LFS migrate -m $MDTIDX $migrate_dir ||
14343                 error "fails on migrating remote dir to MDT0"
14344
14345         echo "migrate back to MDT0, checking.."
14346         for file in $(find $migrate_dir); do
14347                 mdt_index=$($LFS getstripe -M $file)
14348                 [ $mdt_index == $MDTIDX ] ||
14349                         error "$file is not on MDT${MDTIDX}"
14350         done
14351
14352         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
14353         [ "$old_dir_flag" = "$new_dir_flag" ] ||
14354                 error " expect $old_dir_flag get $new_dir_flag"
14355
14356         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
14357         [ "$old_file_flag" = "$new_file_flag" ] ||
14358                 error " expect $old_file_flag get $new_file_flag"
14359
14360         local new_dir_mode=$(stat -c%f $migrate_dir)
14361         [ "$old_dir_mode" = "$new_dir_mode" ] ||
14362                 error "expect mode $old_dir_mode get $new_dir_mode"
14363
14364         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
14365         [ "$old_file_mode" = "$new_file_mode" ] ||
14366                 error "expect mode $old_file_mode get $new_file_mode"
14367
14368         diff /etc/passwd ${migrate_dir}/$tfile ||
14369                 error "$tfile different after migration"
14370
14371         diff /etc/passwd ${other_dir}/luna ||
14372                 error "luna different after migration"
14373
14374         diff /etc/passwd ${migrate_dir}/sofia ||
14375                 error "sofia different after migration"
14376
14377         diff /etc/passwd ${other_dir}/zachary ||
14378                 error "zachary different after migration"
14379
14380         diff /etc/passwd $migrate_dir/${tfile}_ln ||
14381                 error "${tfile}_ln different after migration"
14382
14383         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
14384                 error "${tfile}_ln_other different after migration"
14385
14386         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
14387         [ $stripe_count = 2 ] ||
14388                 error "dir strpe_count $d != 2 after migration."
14389
14390         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
14391         [ $stripe_count = 2 ] ||
14392                 error "file strpe_count $d != 2 after migration."
14393
14394         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14395 }
14396 run_test 230b "migrate directory"
14397
14398 test_230c() {
14399         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14400         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14401         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14402         local MDTIDX=1
14403         local mdt_index
14404         local file
14405         local migrate_dir=$DIR/$tdir/migrate_dir
14406
14407         #If migrating directory fails in the middle, all entries of
14408         #the directory is still accessiable.
14409         test_mkdir $DIR/$tdir
14410         test_mkdir -i0 -c1 $migrate_dir
14411         stat $migrate_dir
14412         createmany -o $migrate_dir/f 10 ||
14413                 error "create files under ${migrate_dir} failed"
14414
14415         #failed after migrating 5 entries
14416         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
14417         do_facet mds1 lctl set_param fail_loc=0x20001801
14418         do_facet mds1 lctl  set_param fail_val=5
14419         local t=$(ls $migrate_dir | wc -l)
14420         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
14421                 error "migrate should fail after 5 entries"
14422
14423         mkdir $migrate_dir/dir &&
14424                 error "mkdir succeeds under migrating directory"
14425         touch $migrate_dir/file &&
14426                 error "touch file succeeds under migrating directory"
14427
14428         local u=$(ls $migrate_dir | wc -l)
14429         [ "$u" == "$t" ] || error "$u != $t during migration"
14430
14431         for file in $(find $migrate_dir); do
14432                 stat $file || error "stat $file failed"
14433         done
14434
14435         do_facet mds1 lctl set_param fail_loc=0
14436         do_facet mds1 lctl set_param fail_val=0
14437
14438         $LFS migrate -m $MDTIDX $migrate_dir ||
14439                 error "migrate open files should failed with open files"
14440
14441         echo "Finish migration, then checking.."
14442         for file in $(find $migrate_dir); do
14443                 mdt_index=$($LFS getstripe -M $file)
14444                 [ $mdt_index == $MDTIDX ] ||
14445                         error "$file is not on MDT${MDTIDX}"
14446         done
14447
14448         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14449 }
14450 run_test 230c "check directory accessiblity if migration is failed"
14451
14452 test_230d() {
14453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14454         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14455         local MDTIDX=1
14456         local mdt_index
14457         local migrate_dir=$DIR/$tdir/migrate_dir
14458         local i
14459         local j
14460
14461         test_mkdir $DIR/$tdir
14462         test_mkdir -i0 -c1 $migrate_dir
14463
14464         for ((i=0; i<100; i++)); do
14465                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
14466                 createmany -o $migrate_dir/dir_${i}/f 100 ||
14467                         error "create files under remote dir failed $i"
14468         done
14469
14470         $LFS migrate -m $MDTIDX $migrate_dir ||
14471                 error "migrate remote dir error"
14472
14473         echo "Finish migration, then checking.."
14474         for file in $(find $migrate_dir); do
14475                 mdt_index=$($LFS getstripe -M $file)
14476                 [ $mdt_index == $MDTIDX ] ||
14477                         error "$file is not on MDT${MDTIDX}"
14478         done
14479
14480         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14481 }
14482 run_test 230d "check migrate big directory"
14483
14484 test_230e() {
14485         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14486         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14487         local i
14488         local j
14489         local a_fid
14490         local b_fid
14491
14492         mkdir -p $DIR/$tdir
14493         mkdir $DIR/$tdir/migrate_dir
14494         mkdir $DIR/$tdir/other_dir
14495         touch $DIR/$tdir/migrate_dir/a
14496         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
14497         ls $DIR/$tdir/other_dir
14498
14499         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14500                 error "migrate dir fails"
14501
14502         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14503         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
14504
14505         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14506         [ $mdt_index == 0 ] || error "a is not on MDT0"
14507
14508         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
14509                 error "migrate dir fails"
14510
14511         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
14512         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
14513
14514         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14515         [ $mdt_index == 1 ] || error "a is not on MDT1"
14516
14517         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
14518         [ $mdt_index == 1 ] || error "b is not on MDT1"
14519
14520         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
14521         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
14522
14523         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
14524
14525         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14526 }
14527 run_test 230e "migrate mulitple local link files"
14528
14529 test_230f() {
14530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14531         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14532         local a_fid
14533         local ln_fid
14534
14535         mkdir -p $DIR/$tdir
14536         mkdir $DIR/$tdir/migrate_dir
14537         $LFS mkdir -i1 $DIR/$tdir/other_dir
14538         touch $DIR/$tdir/migrate_dir/a
14539         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
14540         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
14541         ls $DIR/$tdir/other_dir
14542
14543         # a should be migrated to MDT1, since no other links on MDT0
14544         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14545                 error "#1 migrate dir fails"
14546         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14547         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
14548         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14549         [ $mdt_index == 1 ] || error "a is not on MDT1"
14550
14551         # a should stay on MDT1, because it is a mulitple link file
14552         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
14553                 error "#2 migrate dir fails"
14554         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14555         [ $mdt_index == 1 ] || error "a is not on MDT1"
14556
14557         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14558                 error "#3 migrate dir fails"
14559
14560         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
14561         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
14562         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
14563
14564         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
14565         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
14566
14567         # a should be migrated to MDT0, since no other links on MDT1
14568         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
14569                 error "#4 migrate dir fails"
14570         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14571         [ $mdt_index == 0 ] || error "a is not on MDT0"
14572
14573         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14574 }
14575 run_test 230f "migrate mulitple remote link files"
14576
14577 test_230g() {
14578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14579         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14580
14581         mkdir -p $DIR/$tdir/migrate_dir
14582
14583         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
14584                 error "migrating dir to non-exist MDT succeeds"
14585         true
14586 }
14587 run_test 230g "migrate dir to non-exist MDT"
14588
14589 test_230h() {
14590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14591         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14592         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
14593                 skip "Need MDS version at least 2.7.64" && return
14594         local mdt_index
14595
14596         mkdir -p $DIR/$tdir/migrate_dir
14597
14598         $LFS migrate -m1 $DIR &&
14599                 error "migrating mountpoint1 should fail"
14600
14601         $LFS migrate -m1 $DIR/$tdir/.. &&
14602                 error "migrating mountpoint2 should fail"
14603
14604         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
14605                 error "migrating $tdir fail"
14606
14607         mdt_index=$($LFS getstripe -M $DIR/$tdir)
14608         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
14609
14610         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14611         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
14612
14613 }
14614 run_test 230h "migrate .. and root"
14615
14616 test_230i() {
14617         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14618         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14619
14620         mkdir -p $DIR/$tdir/migrate_dir
14621
14622         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
14623                 error "migration fails with a tailing slash"
14624
14625         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
14626                 error "migration fails with two tailing slashes"
14627 }
14628 run_test 230i "lfs migrate -m tolerates trailing slashes"
14629
14630 test_231a()
14631 {
14632         # For simplicity this test assumes that max_pages_per_rpc
14633         # is the same across all OSCs
14634         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
14635         local bulk_size=$((max_pages * 4096))
14636         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
14637                                        head -n 1)
14638
14639         mkdir -p $DIR/$tdir
14640         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
14641                 error "failed to set stripe with -S ${brw_size}M option"
14642
14643         # clear the OSC stats
14644         $LCTL set_param osc.*.stats=0 &>/dev/null
14645         stop_writeback
14646
14647         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
14648         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
14649                 oflag=direct &>/dev/null || error "dd failed"
14650
14651         sync; sleep 1; sync # just to be safe
14652         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
14653         if [ x$nrpcs != "x1" ]; then
14654                 $LCTL get_param osc.*.stats
14655                 error "found $nrpcs ost_write RPCs, not 1 as expected"
14656         fi
14657
14658         start_writeback
14659         # Drop the OSC cache, otherwise we will read from it
14660         cancel_lru_locks osc
14661
14662         # clear the OSC stats
14663         $LCTL set_param osc.*.stats=0 &>/dev/null
14664
14665         # Client reads $bulk_size.
14666         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
14667                 iflag=direct &>/dev/null || error "dd failed"
14668
14669         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
14670         if [ x$nrpcs != "x1" ]; then
14671                 $LCTL get_param osc.*.stats
14672                 error "found $nrpcs ost_read RPCs, not 1 as expected"
14673         fi
14674 }
14675 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
14676
14677 test_231b() {
14678         mkdir -p $DIR/$tdir
14679         local i
14680         for i in {0..1023}; do
14681                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
14682                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
14683                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
14684         done
14685         sync
14686 }
14687 run_test 231b "must not assert on fully utilized OST request buffer"
14688
14689 test_232a() {
14690         mkdir -p $DIR/$tdir
14691         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
14692
14693         #define OBD_FAIL_LDLM_OST_LVB            0x31c
14694         do_facet ost1 $LCTL set_param fail_loc=0x31c
14695
14696         # ignore dd failure
14697         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
14698
14699         do_facet ost1 $LCTL set_param fail_loc=0
14700         umount_client $MOUNT || error "umount failed"
14701         mount_client $MOUNT || error "mount failed"
14702         stop ost1 || error "cannot stop ost1"
14703         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
14704 }
14705 run_test 232a "failed lock should not block umount"
14706
14707 test_232b() {
14708         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.58) ] ||
14709                 { skip "Need MDS version at least 2.10.58"; return; }
14710         mkdir -p $DIR/$tdir
14711         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
14712         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1
14713         sync
14714         cancel_lru_locks osc
14715
14716         #define OBD_FAIL_LDLM_OST_LVB            0x31c
14717         do_facet ost1 $LCTL set_param fail_loc=0x31c
14718
14719         # ignore failure
14720         $LFS data_version $DIR/$tdir/$tfile || true
14721
14722         do_facet ost1 $LCTL set_param fail_loc=0
14723         umount_client $MOUNT || error "umount failed"
14724         mount_client $MOUNT || error "mount failed"
14725         stop ost1 || error "cannot stop ost1"
14726         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
14727 }
14728 run_test 232b "failed data version lock should not block umount"
14729
14730 test_233a() {
14731         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
14732         { skip "Need MDS version at least 2.3.64"; return; }
14733         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
14734
14735         local fid=$($LFS path2fid $MOUNT)
14736         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14737                 error "cannot access $MOUNT using its FID '$fid'"
14738 }
14739 run_test 233a "checking that OBF of the FS root succeeds"
14740
14741 test_233b() {
14742         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
14743         { skip "Need MDS version at least 2.5.90"; return; }
14744         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
14745
14746         local fid=$($LFS path2fid $MOUNT/.lustre)
14747         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14748                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
14749
14750         fid=$($LFS path2fid $MOUNT/.lustre/fid)
14751         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14752                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
14753 }
14754 run_test 233b "checking that OBF of the FS .lustre succeeds"
14755
14756 test_234() {
14757         local p="$TMP/sanityN-$TESTNAME.parameters"
14758         save_lustre_params client "llite.*.xattr_cache" > $p
14759         lctl set_param llite.*.xattr_cache 1 ||
14760                 { skip "xattr cache is not supported"; return 0; }
14761
14762         mkdir -p $DIR/$tdir || error "mkdir failed"
14763         touch $DIR/$tdir/$tfile || error "touch failed"
14764         # OBD_FAIL_LLITE_XATTR_ENOMEM
14765         $LCTL set_param fail_loc=0x1405
14766         getfattr -n user.attr $DIR/$tdir/$tfile &&
14767                 error "getfattr should have failed with ENOMEM"
14768         $LCTL set_param fail_loc=0x0
14769         rm -rf $DIR/$tdir
14770
14771         restore_lustre_params < $p
14772         rm -f $p
14773 }
14774 run_test 234 "xattr cache should not crash on ENOMEM"
14775
14776 test_235() {
14777         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
14778                 skip "Need MDS version at least 2.4.52" && return
14779         flock_deadlock $DIR/$tfile
14780         local RC=$?
14781         case $RC in
14782                 0)
14783                 ;;
14784                 124) error "process hangs on a deadlock"
14785                 ;;
14786                 *) error "error executing flock_deadlock $DIR/$tfile"
14787                 ;;
14788         esac
14789 }
14790 run_test 235 "LU-1715: flock deadlock detection does not work properly"
14791
14792 #LU-2935
14793 test_236() {
14794         check_swap_layouts_support && return 0
14795         test_mkdir -c1 $DIR/$tdir
14796
14797         local ref1=/etc/passwd
14798         local ref2=/etc/group
14799         local file1=$DIR/$tdir/f1
14800         local file2=$DIR/$tdir/f2
14801
14802         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
14803         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
14804         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
14805         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
14806         local fd=$(free_fd)
14807         local cmd="exec $fd<>$file2"
14808         eval $cmd
14809         rm $file2
14810         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
14811                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
14812         cmd="exec $fd>&-"
14813         eval $cmd
14814         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
14815
14816         #cleanup
14817         rm -rf $DIR/$tdir
14818 }
14819 run_test 236 "Layout swap on open unlinked file"
14820
14821 # test to verify file handle related system calls
14822 # (name_to_handle_at/open_by_handle_at)
14823 # The new system calls are supported in glibc >= 2.14.
14824
14825 test_237() {
14826         echo "Test file_handle syscalls" > $DIR/$tfile ||
14827                 error "write failed"
14828         check_fhandle_syscalls $DIR/$tfile ||
14829                 error "check_fhandle_syscalls failed"
14830 }
14831 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
14832
14833 # LU-4659 linkea consistency
14834 test_238() {
14835         local server_version=$(lustre_version_code $SINGLEMDS)
14836
14837         [[ $server_version -gt $(version_code 2.5.57) ]] ||
14838                 [[ $server_version -gt $(version_code 2.5.1) &&
14839                    $server_version -lt $(version_code 2.5.50) ]] ||
14840                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
14841
14842         touch $DIR/$tfile
14843         ln $DIR/$tfile $DIR/$tfile.lnk
14844         touch $DIR/$tfile.new
14845         mv $DIR/$tfile.new $DIR/$tfile
14846         local fid1=$($LFS path2fid $DIR/$tfile)
14847         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
14848         local path1=$($LFS fid2path $FSNAME "$fid1")
14849         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
14850         local path2=$($LFS fid2path $FSNAME "$fid2")
14851         [ $tfile.lnk == $path2 ] ||
14852                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
14853         rm -f $DIR/$tfile*
14854 }
14855 run_test 238 "Verify linkea consistency"
14856
14857 test_239A() { # was test_239
14858         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
14859                 skip "Need MDS version at least 2.5.60" && return
14860         local list=$(comma_list $(mdts_nodes))
14861
14862         mkdir -p $DIR/$tdir
14863         createmany -o $DIR/$tdir/f- 5000
14864         unlinkmany $DIR/$tdir/f- 5000
14865         [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ] &&
14866                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
14867         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
14868                         osp.*MDT*.sync_in_flight" | calc_sum)
14869         [ "$changes" -eq 0 ] || error "$changes not synced"
14870 }
14871 run_test 239A "osp_sync test"
14872
14873 test_239a() { #LU-5297
14874         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14875         touch $DIR/$tfile
14876         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
14877         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
14878         chgrp $RUNAS_GID $DIR/$tfile
14879         wait_delete_completed
14880 }
14881 run_test 239a "process invalid osp sync record correctly"
14882
14883 test_239b() { #LU-5297
14884         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14885         touch $DIR/$tfile1
14886         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
14887         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
14888         chgrp $RUNAS_GID $DIR/$tfile1
14889         wait_delete_completed
14890         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
14891         touch $DIR/$tfile2
14892         chgrp $RUNAS_GID $DIR/$tfile2
14893         wait_delete_completed
14894 }
14895 run_test 239b "process osp sync record with ENOMEM error correctly"
14896
14897 test_240() {
14898         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14899         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14900
14901         mkdir -p $DIR/$tdir
14902
14903         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
14904                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
14905         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
14906                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
14907
14908         umount_client $MOUNT || error "umount failed"
14909         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
14910         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
14911         mount_client $MOUNT || error "failed to mount client"
14912
14913         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
14914         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
14915 }
14916 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
14917
14918 test_241_bio() {
14919         for LOOP in $(seq $1); do
14920                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
14921                 cancel_lru_locks $OSC || true
14922         done
14923 }
14924
14925 test_241_dio() {
14926         for LOOP in $(seq $1); do
14927                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
14928                                                 iflag=direct 2>/dev/null
14929         done
14930 }
14931
14932 test_241a() { # was test_241
14933         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14934         ls -la $DIR/$tfile
14935         cancel_lru_locks $OSC
14936         test_241_bio 1000 &
14937         PID=$!
14938         test_241_dio 1000
14939         wait $PID
14940 }
14941 run_test 241a "bio vs dio"
14942
14943 test_241b() {
14944         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14945         ls -la $DIR/$tfile
14946         test_241_dio 1000 &
14947         PID=$!
14948         test_241_dio 1000
14949         wait $PID
14950 }
14951 run_test 241b "dio vs dio"
14952
14953 test_242() {
14954         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14955         mkdir -p $DIR/$tdir
14956         touch $DIR/$tdir/$tfile
14957
14958         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
14959         do_facet mds1 lctl set_param fail_loc=0x105
14960         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
14961
14962         do_facet mds1 lctl set_param fail_loc=0
14963         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
14964 }
14965 run_test 242 "mdt_readpage failure should not cause directory unreadable"
14966
14967 test_243()
14968 {
14969         test_mkdir $DIR/$tdir
14970         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
14971 }
14972 run_test 243 "various group lock tests"
14973
14974 test_244()
14975 {
14976         test_mkdir $DIR/$tdir
14977         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
14978         sendfile_grouplock $DIR/$tdir/$tfile || \
14979                 error "sendfile+grouplock failed"
14980         rm -rf $DIR/$tdir
14981 }
14982 run_test 244 "sendfile with group lock tests"
14983
14984 test_245() {
14985         local flagname="multi_mod_rpcs"
14986         local connect_data_name="max_mod_rpcs"
14987         local out
14988
14989         # check if multiple modify RPCs flag is set
14990         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
14991                 grep "connect_flags:")
14992         echo "$out"
14993
14994         echo "$out" | grep -qw $flagname
14995         if [ $? -ne 0 ]; then
14996                 echo "connect flag $flagname is not set"
14997                 return
14998         fi
14999
15000         # check if multiple modify RPCs data is set
15001         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
15002         echo "$out"
15003
15004         echo "$out" | grep -qw $connect_data_name ||
15005                 error "import should have connect data $connect_data_name"
15006 }
15007 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
15008
15009 test_246() { # LU-7371
15010         remote_ost_nodsh && skip "remote OST with nodsh" && return
15011         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
15012                 skip "Need OST version >= 2.7.62" && return 0
15013         do_facet ost1 $LCTL set_param fail_val=4095
15014 #define OBD_FAIL_OST_READ_SIZE          0x234
15015         do_facet ost1 $LCTL set_param fail_loc=0x234
15016         $LFS setstripe $DIR/$tfile -i 0 -c 1
15017         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
15018         cancel_lru_locks $FSNAME-OST0000
15019         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
15020 }
15021 run_test 246 "Read file of size 4095 should return right length"
15022
15023 cleanup_247() {
15024         local submount=$1
15025
15026         trap 0
15027         umount_client $submount
15028         rmdir $submount
15029 }
15030
15031 test_247a() {
15032         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
15033                 grep -q subtree ||
15034                 { skip "Fileset feature is not supported"; return; }
15035
15036         local submount=${MOUNT}_$tdir
15037
15038         mkdir $MOUNT/$tdir
15039         mkdir -p $submount || error "mkdir $submount failed"
15040         FILESET="$FILESET/$tdir" mount_client $submount ||
15041                 error "mount $submount failed"
15042         trap "cleanup_247 $submount" EXIT
15043         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
15044         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
15045                 error "read $MOUNT/$tdir/$tfile failed"
15046         cleanup_247 $submount
15047 }
15048 run_test 247a "mount subdir as fileset"
15049
15050 test_247b() {
15051         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15052                 { skip "Fileset feature is not supported"; return; }
15053
15054         local submount=${MOUNT}_$tdir
15055
15056         rm -rf $MOUNT/$tdir
15057         mkdir -p $submount || error "mkdir $submount failed"
15058         SKIP_FILESET=1
15059         FILESET="$FILESET/$tdir" mount_client $submount &&
15060                 error "mount $submount should fail"
15061         rmdir $submount
15062 }
15063 run_test 247b "mount subdir that dose not exist"
15064
15065 test_247c() {
15066         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15067                 { skip "Fileset feature is not supported"; return; }
15068
15069         local submount=${MOUNT}_$tdir
15070
15071         mkdir -p $MOUNT/$tdir/dir1
15072         mkdir -p $submount || error "mkdir $submount failed"
15073         trap "cleanup_247 $submount" EXIT
15074         FILESET="$FILESET/$tdir" mount_client $submount ||
15075                 error "mount $submount failed"
15076         local fid=$($LFS path2fid $MOUNT/)
15077         $LFS fid2path $submount $fid && error "fid2path should fail"
15078         cleanup_247 $submount
15079 }
15080 run_test 247c "running fid2path outside root"
15081
15082 test_247d() {
15083         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
15084                 { skip "Fileset feature is not supported"; return; }
15085
15086         local submount=${MOUNT}_$tdir
15087
15088         mkdir -p $MOUNT/$tdir/dir1
15089         mkdir -p $submount || error "mkdir $submount failed"
15090         FILESET="$FILESET/$tdir" mount_client $submount ||
15091                 error "mount $submount failed"
15092         trap "cleanup_247 $submount" EXIT
15093         local fid=$($LFS path2fid $submount/dir1)
15094         $LFS fid2path $submount $fid || error "fid2path should succeed"
15095         cleanup_247 $submount
15096 }
15097 run_test 247d "running fid2path inside root"
15098
15099 # LU-8037
15100 test_247e() {
15101         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
15102                 grep -q subtree ||
15103                 { skip "Fileset feature is not supported"; return; }
15104
15105         local submount=${MOUNT}_$tdir
15106
15107         mkdir $MOUNT/$tdir
15108         mkdir -p $submount || error "mkdir $submount failed"
15109         FILESET="$FILESET/.." mount_client $submount &&
15110                 error "mount $submount should fail"
15111         rmdir $submount
15112 }
15113 run_test 247e "mount .. as fileset"
15114
15115 test_248() {
15116         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
15117         [ -z "$fast_read_sav" ] && skip "no fast read support" && return
15118
15119         # create a large file for fast read verification
15120         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
15121
15122         # make sure the file is created correctly
15123         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
15124                 { rm -f $DIR/$tfile; skip "file creation error" && return; }
15125
15126         echo "Test 1: verify that fast read is 4 times faster on cache read"
15127
15128         # small read with fast read enabled
15129         $LCTL set_param -n llite.*.fast_read=1
15130         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
15131                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15132                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15133         # small read with fast read disabled
15134         $LCTL set_param -n llite.*.fast_read=0
15135         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
15136                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15137                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15138
15139         # verify that fast read is 4 times faster for cache read
15140         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
15141                 error_not_in_vm "fast read was not 4 times faster: " \
15142                            "$t_fast vs $t_slow"
15143
15144         echo "Test 2: verify the performance between big and small read"
15145         $LCTL set_param -n llite.*.fast_read=1
15146
15147         # 1k non-cache read
15148         cancel_lru_locks osc
15149         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
15150                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15151                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15152
15153         # 1M non-cache read
15154         cancel_lru_locks osc
15155         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
15156                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
15157                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
15158
15159         # verify that big IO is not 4 times faster than small IO
15160         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
15161                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
15162
15163         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
15164         rm -f $DIR/$tfile
15165 }
15166 run_test 248 "fast read verification"
15167
15168 test_249() { # LU-7890
15169         rm -f $DIR/$tfile
15170         $SETSTRIPE -c 1 $DIR/$tfile
15171
15172         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
15173         skip "Need at least version 2.8.54"
15174
15175         # Offset 2T == 4k * 512M
15176         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
15177                 error "dd to 2T offset failed"
15178 }
15179 run_test 249 "Write above 2T file size"
15180
15181 test_250() {
15182         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
15183          && skip "no 16TB file size limit on ZFS" && return
15184
15185         $SETSTRIPE -c 1 $DIR/$tfile
15186         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
15187         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
15188         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
15189         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
15190                 conv=notrunc,fsync && error "append succeeded"
15191         return 0
15192 }
15193 run_test 250 "Write above 16T limit"
15194
15195 test_251() {
15196         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
15197
15198         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
15199         #Skip once - writing the first stripe will succeed
15200         $LCTL set_param fail_loc=0xa0001407 fail_val=1
15201         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
15202                 error "short write happened"
15203
15204         $LCTL set_param fail_loc=0xa0001407 fail_val=1
15205         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
15206                 error "short read happened"
15207
15208         rm -f $DIR/$tfile
15209 }
15210 run_test 251 "Handling short read and write correctly"
15211
15212 test_252() {
15213         local tgt
15214         local dev
15215         local out
15216         local uuid
15217         local num
15218         local gen
15219
15220         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15221         remote_ost_nodsh && skip "remote OST with nodsh" && return
15222         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
15223              "$(facet_fstype mds1)" != "ldiskfs" ]; then
15224                 skip "ldiskfs only test"
15225                 return
15226         fi
15227
15228         # check lr_reader on OST0000
15229         tgt=ost1
15230         dev=$(facet_device $tgt)
15231         out=$(do_facet $tgt $LR_READER $dev)
15232         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15233         echo "$out"
15234         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
15235         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
15236                 error "Invalid uuid returned by $LR_READER on target $tgt"
15237         echo -e "uuid returned by $LR_READER is '$uuid'\n"
15238
15239         # check lr_reader -c on MDT0000
15240         tgt=mds1
15241         dev=$(facet_device $tgt)
15242         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
15243                 echo "$LR_READER does not support additional options"
15244                 return 0
15245         fi
15246         out=$(do_facet $tgt $LR_READER -c $dev)
15247         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15248         echo "$out"
15249         num=$(echo "$out" | grep -c "mdtlov")
15250         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
15251                 error "Invalid number of mdtlov clients returned by $LR_READER"
15252         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
15253
15254         # check lr_reader -cr on MDT0000
15255         out=$(do_facet $tgt $LR_READER -cr $dev)
15256         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
15257         echo "$out"
15258         echo "$out" | grep -q "^reply_data:$" ||
15259                 error "$LR_READER should have returned 'reply_data' section"
15260         num=$(echo "$out" | grep -c "client_generation")
15261         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
15262 }
15263 run_test 252 "check lr_reader tool"
15264
15265 test_253_fill_ost() {
15266         local size_mb #how many MB should we write to pass watermark
15267         local lwm=$3  #low watermark
15268         local free_10mb #10% of free space
15269
15270         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
15271         size_mb=$((free_kb / 1024 - lwm))
15272         free_10mb=$((free_kb / 10240))
15273         #If 10% of free space cross low watermark use it
15274         if (( free_10mb > size_mb )); then
15275                 size_mb=$free_10mb
15276         else
15277                 #At least we need to store 1.1 of difference between
15278                 #free space and low watermark
15279                 size_mb=$((size_mb + size_mb / 10))
15280         fi
15281         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
15282                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
15283                          oflag=append conv=notrunc
15284         fi
15285
15286         sleep_maxage
15287
15288         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
15289         echo "OST still has $((free_kb / 1024)) mbytes free"
15290 }
15291
15292 test_253() {
15293         local ostidx=0
15294         local rc=0
15295
15296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15297         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15298         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
15299
15300         local ost_name=$($LFS osts |
15301                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
15302         # on the mdt's osc
15303         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
15304         do_facet $SINGLEMDS $LCTL get_param -n \
15305                 osp.$mdtosc_proc1.reserved_mb_high ||
15306                 { skip  "remote MDS does not support reserved_mb_high" &&
15307                   return; }
15308
15309         rm -rf $DIR/$tdir
15310         wait_mds_ost_sync
15311         wait_delete_completed
15312         mkdir $DIR/$tdir
15313
15314         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
15315                         osp.$mdtosc_proc1.reserved_mb_high)
15316         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
15317                         osp.$mdtosc_proc1.reserved_mb_low)
15318         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
15319
15320         if ! combined_mgs_mds ; then
15321                 mount_mgs_client
15322         fi
15323         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
15324         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
15325                 error "Adding $ost_name to pool failed"
15326
15327         # Wait for client to see a OST at pool
15328         wait_update $HOSTNAME "$LCTL get_param -n
15329                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
15330                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
15331                 error "Client can not see the pool"
15332         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
15333                 error "Setstripe failed"
15334
15335         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
15336         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
15337         echo "OST still has $((blocks/1024)) mbytes free"
15338
15339         local new_lwm=$((blocks/1024-10))
15340         do_facet $SINGLEMDS $LCTL set_param \
15341                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
15342         do_facet $SINGLEMDS $LCTL set_param \
15343                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
15344
15345         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
15346
15347         #First enospc could execute orphan deletion so repeat.
15348         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
15349
15350         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
15351                         osp.$mdtosc_proc1.prealloc_status)
15352         echo "prealloc_status $oa_status"
15353
15354         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
15355                 error "File creation should fail"
15356         #object allocation was stopped, but we still able to append files
15357         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
15358                 error "Append failed"
15359         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
15360
15361         wait_delete_completed
15362
15363         sleep_maxage
15364
15365         for i in $(seq 10 12); do
15366                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
15367                         error "File creation failed after rm";
15368         done
15369
15370         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
15371                         osp.$mdtosc_proc1.prealloc_status)
15372         echo "prealloc_status $oa_status"
15373
15374         if (( oa_status != 0 )); then
15375                 error "Object allocation still disable after rm"
15376         fi
15377         do_facet $SINGLEMDS $LCTL set_param \
15378                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
15379         do_facet $SINGLEMDS $LCTL set_param \
15380                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
15381
15382
15383         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
15384                 error "Remove $ost_name from pool failed"
15385         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
15386                 error "Pool destroy fialed"
15387
15388         if ! combined_mgs_mds ; then
15389                 umount_mgs_client
15390         fi
15391 }
15392 run_test 253 "Check object allocation limit"
15393
15394 test_254() {
15395         local cl_user
15396
15397         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15398         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15399
15400         local MDT0=$(facet_svc $SINGLEMDS)
15401
15402         do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_size ||
15403                 { skip "MDS does not support changelog_size" && return; }
15404
15405         changelog_register || error "changelog_register failed"
15406
15407         changelog_clear 0 || error "changelog_clear failed"
15408
15409         local size1=$(do_facet $SINGLEMDS \
15410                       $LCTL get_param -n mdd.$MDT0.changelog_size)
15411         echo "Changelog size $size1"
15412
15413         rm -rf $DIR/$tdir
15414         $LFS mkdir -i 0 $DIR/$tdir
15415         # change something
15416         mkdir -p $DIR/$tdir/pics/2008/zachy
15417         touch $DIR/$tdir/pics/2008/zachy/timestamp
15418         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
15419         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
15420         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
15421         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
15422         rm $DIR/$tdir/pics/desktop.jpg
15423
15424         local size2=$(do_facet $SINGLEMDS \
15425                       $LCTL get_param -n mdd.$MDT0.changelog_size)
15426         echo "Changelog size after work $size2"
15427
15428         (( $size2 > $size1 )) ||
15429                 error "new Changelog size=$size2 less than old size=$size1"
15430 }
15431 run_test 254 "Check changelog size"
15432
15433 ladvise_no_type()
15434 {
15435         local type=$1
15436         local file=$2
15437
15438         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
15439                 awk -F: '{print $2}' | grep $type > /dev/null
15440         if [ $? -ne 0 ]; then
15441                 return 0
15442         fi
15443         return 1
15444 }
15445
15446 ladvise_no_ioctl()
15447 {
15448         local file=$1
15449
15450         lfs ladvise -a willread $file > /dev/null 2>&1
15451         if [ $? -eq 0 ]; then
15452                 return 1
15453         fi
15454
15455         lfs ladvise -a willread $file 2>&1 |
15456                 grep "Inappropriate ioctl for device" > /dev/null
15457         if [ $? -eq 0 ]; then
15458                 return 0
15459         fi
15460         return 1
15461 }
15462
15463 percent() {
15464         bc <<<"scale=2; ($1 - $2) * 100 / $2"
15465 }
15466
15467 # run a random read IO workload
15468 # usage: random_read_iops <filename> <filesize> <iosize>
15469 random_read_iops() {
15470         local file=$1
15471         local fsize=$2
15472         local iosize=${3:-4096}
15473
15474         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
15475                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
15476 }
15477
15478 drop_file_oss_cache() {
15479         local file="$1"
15480         local nodes="$2"
15481
15482         $LFS ladvise -a dontneed $file 2>/dev/null ||
15483                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
15484 }
15485
15486 ladvise_willread_performance()
15487 {
15488         local repeat=10
15489         local average_origin=0
15490         local average_cache=0
15491         local average_ladvise=0
15492
15493         for ((i = 1; i <= $repeat; i++)); do
15494                 echo "Iter $i/$repeat: reading without willread hint"
15495                 cancel_lru_locks osc
15496                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
15497                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
15498                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
15499                 average_origin=$(bc <<<"$average_origin + $speed_origin")
15500
15501                 cancel_lru_locks osc
15502                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
15503                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
15504                 average_cache=$(bc <<<"$average_cache + $speed_cache")
15505
15506                 cancel_lru_locks osc
15507                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
15508                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
15509                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
15510                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
15511                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
15512         done
15513         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
15514         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
15515         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
15516
15517         speedup_cache=$(percent $average_cache $average_origin)
15518         speedup_ladvise=$(percent $average_ladvise $average_origin)
15519
15520         echo "Average uncached read: $average_origin"
15521         echo "Average speedup with OSS cached read: " \
15522                 "$average_cache = +$speedup_cache%"
15523         echo "Average speedup with ladvise willread: " \
15524                 "$average_ladvise = +$speedup_ladvise%"
15525
15526         local lowest_speedup=20
15527         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
15528                 echo "Speedup with OSS cached read less than $lowest_speedup%," \
15529                         "got $average_cache%. Skipping ladvise willread check."
15530                 return 0
15531         fi
15532
15533         # the test won't work on ZFS until it supports 'ladvise dontneed', but
15534         # it is still good to run until then to exercise 'ladvise willread'
15535         ! $LFS ladvise -a dontneed $DIR/$tfile &&
15536                 [ "$(facet_fstype ost1)" = "zfs" ] &&
15537                 echo "osd-zfs does not support dontneed or drop_caches" &&
15538                 return 0
15539
15540         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
15541         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
15542                 error_not_in_vm "Speedup with willread is less than " \
15543                         "$lowest_speedup%, got $average_ladvise%"
15544 }
15545
15546 test_255a() {
15547         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15548                 skip "lustre < 2.8.54 does not support ladvise " && return
15549         remote_ost_nodsh && skip "remote OST with nodsh" && return
15550
15551         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
15552
15553         ladvise_no_type willread $DIR/$tfile &&
15554                 skip "willread ladvise is not supported" && return
15555
15556         ladvise_no_ioctl $DIR/$tfile &&
15557                 skip "ladvise ioctl is not supported" && return
15558
15559         local size_mb=100
15560         local size=$((size_mb * 1048576))
15561         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
15562                 error "dd to $DIR/$tfile failed"
15563
15564         lfs ladvise -a willread $DIR/$tfile ||
15565                 error "Ladvise failed with no range argument"
15566
15567         lfs ladvise -a willread -s 0 $DIR/$tfile ||
15568                 error "Ladvise failed with no -l or -e argument"
15569
15570         lfs ladvise -a willread -e 1 $DIR/$tfile ||
15571                 error "Ladvise failed with only -e argument"
15572
15573         lfs ladvise -a willread -l 1 $DIR/$tfile ||
15574                 error "Ladvise failed with only -l argument"
15575
15576         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
15577                 error "End offset should not be smaller than start offset"
15578
15579         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
15580                 error "End offset should not be equal to start offset"
15581
15582         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
15583                 error "Ladvise failed with overflowing -s argument"
15584
15585         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
15586                 error "Ladvise failed with overflowing -e argument"
15587
15588         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
15589                 error "Ladvise failed with overflowing -l argument"
15590
15591         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
15592                 error "Ladvise succeeded with conflicting -l and -e arguments"
15593
15594         echo "Synchronous ladvise should wait"
15595         local delay=4
15596 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
15597         do_nodes $(comma_list $(osts_nodes)) \
15598                 $LCTL set_param fail_val=$delay fail_loc=0x237
15599
15600         local start_ts=$SECONDS
15601         lfs ladvise -a willread $DIR/$tfile ||
15602                 error "Ladvise failed with no range argument"
15603         local end_ts=$SECONDS
15604         local inteval_ts=$((end_ts - start_ts))
15605
15606         if [ $inteval_ts -lt $(($delay - 1)) ]; then
15607                 error "Synchronous advice didn't wait reply"
15608         fi
15609
15610         echo "Asynchronous ladvise shouldn't wait"
15611         local start_ts=$SECONDS
15612         lfs ladvise -a willread -b $DIR/$tfile ||
15613                 error "Ladvise failed with no range argument"
15614         local end_ts=$SECONDS
15615         local inteval_ts=$((end_ts - start_ts))
15616
15617         if [ $inteval_ts -gt $(($delay / 2)) ]; then
15618                 error "Asynchronous advice blocked"
15619         fi
15620
15621         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
15622         ladvise_willread_performance
15623 }
15624 run_test 255a "check 'lfs ladvise -a willread'"
15625
15626 facet_meminfo() {
15627         local facet=$1
15628         local info=$2
15629
15630         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
15631 }
15632
15633 test_255b() {
15634         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15635                 skip "lustre < 2.8.54 does not support ladvise " && return
15636         remote_ost_nodsh && skip "remote OST with nodsh" && return
15637
15638         lfs setstripe -c 1 -i 0 $DIR/$tfile
15639
15640         ladvise_no_type dontneed $DIR/$tfile &&
15641                 skip "dontneed ladvise is not supported" && return
15642
15643         ladvise_no_ioctl $DIR/$tfile &&
15644                 skip "ladvise ioctl is not supported" && return
15645
15646         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15647                 skip "lustre < 2.8.54 does not support ladvise" && return
15648
15649         ! $LFS ladvise -a dontneed $DIR/$tfile &&
15650                 [ "$(facet_fstype ost1)" = "zfs" ] &&
15651                 skip "zfs-osd does not support 'ladvise dontneed'" && return
15652
15653         local size_mb=100
15654         local size=$((size_mb * 1048576))
15655         # In order to prevent disturbance of other processes, only check 3/4
15656         # of the memory usage
15657         local kibibytes=$((size_mb * 1024 * 3 / 4))
15658
15659         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
15660                 error "dd to $DIR/$tfile failed"
15661
15662         local total=$(facet_meminfo ost1 MemTotal)
15663         echo "Total memory: $total KiB"
15664
15665         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
15666         local before_read=$(facet_meminfo ost1 Cached)
15667         echo "Cache used before read: $before_read KiB"
15668
15669         lfs ladvise -a willread $DIR/$tfile ||
15670                 error "Ladvise willread failed"
15671         local after_read=$(facet_meminfo ost1 Cached)
15672         echo "Cache used after read: $after_read KiB"
15673
15674         lfs ladvise -a dontneed $DIR/$tfile ||
15675                 error "Ladvise dontneed again failed"
15676         local no_read=$(facet_meminfo ost1 Cached)
15677         echo "Cache used after dontneed ladvise: $no_read KiB"
15678
15679         if [ $total -lt $((before_read + kibibytes)) ]; then
15680                 echo "Memory is too small, abort checking"
15681                 return 0
15682         fi
15683
15684         if [ $((before_read + kibibytes)) -gt $after_read ]; then
15685                 error "Ladvise willread should use more memory" \
15686                         "than $kibibytes KiB"
15687         fi
15688
15689         if [ $((no_read + kibibytes)) -gt $after_read ]; then
15690                 error "Ladvise dontneed should release more memory" \
15691                         "than $kibibytes KiB"
15692         fi
15693 }
15694 run_test 255b "check 'lfs ladvise -a dontneed'"
15695
15696 test_255c() {
15697         local count
15698         local new_count
15699         local difference
15700         local i
15701         local rc
15702
15703         [ $(lustre_version_code ost1) -lt $(version_code 2.10.50) ] &&
15704                 skip "lustre < 2.10.53 does not support lockahead" && return
15705
15706         test_mkdir -p $DIR/$tdir
15707         $SETSTRIPE -i 0 $DIR/$tdir
15708
15709         #test 10 returns only success/failure
15710         i=10
15711         lockahead_test -d $DIR/$tdir -t $i -f $tfile
15712         rc=$?
15713         if [ $rc -eq 255 ]; then
15714                 error "Ladvise test${i} failed, ${rc}"
15715         fi
15716
15717         #test 11 counts lock enqueue requests, all others count new locks
15718         i=11
15719         count=$(do_facet ost1 \
15720                 $LCTL get_param -n ost.OSS.ost.stats)
15721         count=$(echo "$count" | grep ldlm_extent_enqueue | awk '{ print $2 }')
15722
15723         lockahead_test -d $DIR/$tdir -t $i -f $tfile
15724         rc=$?
15725         if [ $rc -eq 255 ]; then
15726                 error "Ladvise test${i} failed, ${rc}"
15727         fi
15728
15729         new_count=$(do_facet ost1 \
15730                 $LCTL get_param -n ost.OSS.ost.stats)
15731         new_count=$(echo "$new_count" | grep ldlm_extent_enqueue | \
15732                    awk '{ print $2 }')
15733
15734         difference="$((new_count - count))"
15735         if [ $difference -ne $rc ]; then
15736                 error "Ladvise test${i}, bad enqueue count, returned " \
15737                       "${rc}, actual ${difference}"
15738         fi
15739
15740         for i in $(seq 12 21); do
15741                 # If we do not do this, we run the risk of having too many
15742                 # locks and starting lock cancellation while we are checking
15743                 # lock counts.
15744                 cancel_lru_locks osc
15745
15746                 count=$($LCTL get_param -n \
15747                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
15748
15749                 lockahead_test -d $DIR/$tdir -t $i -f $tfile
15750                 rc=$?
15751                 if [ $rc -eq 255 ]; then
15752                         error "Ladvise test ${i} failed, ${rc}"
15753                 fi
15754
15755                 new_count=$($LCTL get_param -n \
15756                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
15757                 difference="$((new_count - count))"
15758
15759                 # Test 15 output is divided by 100 to map down to valid return
15760                 if [ $i -eq 15 ]; then
15761                         rc="$((rc * 100))"
15762                 fi
15763
15764                 if [ $difference -ne $rc ]; then
15765                         error "Ladvise test ${i}, bad lock count, returned " \
15766                               "${rc}, actual ${difference}"
15767                 fi
15768         done
15769
15770         #test 22 returns only success/failure
15771         i=22
15772         lockahead_test -d $DIR/$tdir -t $i -f $tfile
15773         rc=$?
15774         if [ $rc -eq 255 ]; then
15775                 error "Ladvise test${i} failed, ${rc}"
15776         fi
15777 }
15778 run_test 255c "suite of ladvise lockahead tests"
15779
15780 test_256() {
15781         local cl_user
15782         local cat_sl
15783         local mdt_dev
15784
15785         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15786         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15787         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
15788                 skip "ldiskfs only test" && return
15789
15790         mdt_dev=$(mdsdevname 1)
15791         echo $mdt_dev
15792         changelog_users $SINGLEMDS | grep "^cl" &&
15793                 skip "active changelog user" && return
15794
15795         changelog_register || error "changelog_register failed"
15796
15797         rm -rf $DIR/$tdir
15798         mkdir -p $DIR/$tdir
15799
15800         changelog_clear 0 || error "changelog_clear failed"
15801
15802         # change something
15803         touch $DIR/$tdir/{1..10}
15804
15805         # stop the MDT
15806         stop $SINGLEMDS || error "Fail to stop MDT"
15807
15808         # remount the MDT
15809
15810         start $SINGLEMDS $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT"
15811
15812         #after mount new plainllog is used
15813         touch $DIR/$tdir/{11..19}
15814         local tmpfile=$(mktemp -u $tfile.XXXXXX)
15815         cat_sl=$(do_facet $SINGLEMDS "sync; \
15816                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
15817                  llog_reader $tmpfile | grep -c type=1064553b")
15818         do_facet $SINGLEMDS llog_reader $tmpfile
15819
15820         [ $cat_sl != 2 ] && error "Changelog catalog has $cat_sl != 2 slots"
15821
15822         changelog_clear 0 || error "changelog_clear failed"
15823
15824         cat_sl=$(do_facet $SINGLEMDS "sync; \
15825                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
15826                  llog_reader $tmpfile | grep -c type=1064553b; rm -f $tmpfile")
15827
15828         if (( cat_sl == 2 )); then
15829                 error "Empty plain llog was not deleted from changelog catalog"
15830         elif (( cat_sl != 1 )); then
15831                 error "Active plain llog shouldn't be deleted from catalog"
15832         fi
15833 }
15834 run_test 256 "Check llog delete for empty and not full state"
15835
15836 test_257() {
15837         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15838         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
15839                 skip "Need MDS version at least 2.8.55" && return
15840
15841         test_mkdir $DIR/$tdir
15842
15843         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
15844                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
15845         stat $DIR/$tdir
15846
15847 #define OBD_FAIL_MDS_XATTR_REP                  0x161
15848         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
15849         local facet=mds$((mdtidx + 1))
15850         set_nodes_failloc $(facet_active_host $facet) 0x80000161
15851         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
15852
15853         stop $facet || error "stop MDS failed"
15854         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
15855                 error "start MDS fail"
15856 }
15857 run_test 257 "xattr locks are not lost"
15858
15859 # Verify we take the i_mutex when security requires it
15860 test_258a() {
15861 #define OBD_FAIL_IMUTEX_SEC 0x141c
15862         $LCTL set_param fail_loc=0x141c
15863         touch $DIR/$tfile
15864         chmod u+s $DIR/$tfile
15865         chmod a+rwx $DIR/$tfile
15866         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15867         RC=$?
15868         if [ $RC -ne 0 ]; then
15869                 error "error, failed to take i_mutex, rc=$?"
15870         fi
15871         rm -f $DIR/$tfile
15872 }
15873 run_test 258a
15874
15875 # Verify we do NOT take the i_mutex in the normal case
15876 test_258b() {
15877 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
15878         $LCTL set_param fail_loc=0x141d
15879         touch $DIR/$tfile
15880         chmod a+rwx $DIR
15881         chmod a+rw $DIR/$tfile
15882         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15883         RC=$?
15884         if [ $RC -ne 0 ]; then
15885                 error "error, took i_mutex unnecessarily, rc=$?"
15886         fi
15887         rm -f $DIR/$tfile
15888
15889 }
15890 run_test 258b "verify i_mutex security behavior"
15891
15892 test_260() {
15893 #define OBD_FAIL_MDC_CLOSE               0x806
15894         $LCTL set_param fail_loc=0x80000806
15895         touch $DIR/$tfile
15896
15897 }
15898 run_test 260 "Check mdc_close fail"
15899
15900 ### Data-on-MDT sanity tests ###
15901 test_270a() {
15902
15903         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
15904                 skip "Need MDS version at least 2.10.55" && return
15905
15906         # create DoM file
15907         local dom=$DIR/$tdir/dom_file
15908         local tmp=$DIR/$tdir/tmp_file
15909
15910         mkdir -p $DIR/$tdir
15911
15912         # basic checks for DoM component creation
15913         $LFS setstripe -E 1024K -E 1024K -L mdt $dom 2>/dev/null &&
15914                 error "Can set MDT layout to non-first entry"
15915
15916         $LFS setstripe -E 1024K -L mdt -E 1024K -L mdt $dom 2>/dev/null &&
15917                 error "Can define multiple entries as MDT layout"
15918
15919         $LFS setstripe -E 1M -L mdt $dom ||
15920                 error "Can't create DoM layout"
15921
15922         [ $($LFS getstripe -L $dom) == "mdt" ] || error "bad pattern"
15923         [ $($LFS getstripe -c $dom) == 0 ] || error "bad stripe count"
15924         [ $($LFS getstripe -S $dom) == 1048576 ] || error "bad stripe size"
15925
15926         local mdtidx=$($GETSTRIPE -M $dom)
15927         local mdtname=MDT$(printf %04x $mdtidx)
15928         local facet=mds$((mdtidx + 1))
15929         local space_check=1
15930
15931         # Skip free space checks with ZFS
15932         if [ "$(facet_fstype $facet)" == "zfs" ]; then
15933                 space_check=0
15934         fi
15935
15936         # write
15937         sync
15938         local mdtfree1=$(do_facet $facet \
15939                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15940         dd if=/dev/urandom of=$tmp bs=1024 count=100
15941         # check also direct IO along write
15942         dd if=$tmp of=$dom bs=102400 count=1 oflag=direct
15943         sync
15944         cmp $tmp $dom || error "file data is different"
15945         [ $(stat -c%s $dom) == 102400 ] || error "bad size after write"
15946         if [ $space_check == 1 ]; then
15947                 local mdtfree2=$(do_facet $facet \
15948                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15949                 [ $(($mdtfree1 - $mdtfree2)) -ge 102 ] ||
15950                         error "MDT free space is wrong after write"
15951         fi
15952
15953         # truncate
15954         $TRUNCATE $dom 10000
15955         [ $(stat -c%s $dom) == 10000 ] || error "bad size after truncate"
15956         if [ $space_check == 1 ]; then
15957                 mdtfree1=$(do_facet $facet \
15958                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15959                 [ $(($mdtfree1 - $mdtfree2)) -ge 92 ] ||
15960                         error "MDT free space is wrong after truncate"
15961         fi
15962
15963         # append
15964         cat $tmp >> $dom
15965         sync
15966         [ $(stat -c%s $dom) == 112400 ] || error "bad size after append"
15967         if [ $space_check == 1 ]; then
15968                 mdtfree2=$(do_facet $facet \
15969                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15970                 [ $(($mdtfree1 - $mdtfree2)) -ge 102 ] ||
15971                         error "MDT free space is wrong after append"
15972         fi
15973
15974         # delete
15975         rm $dom
15976         if [ $space_check == 1 ]; then
15977                 mdtfree1=$(do_facet $facet \
15978                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
15979                 [ $(($mdtfree1 - $mdtfree2)) -ge 112 ] ||
15980                         error "MDT free space is wrong after removal"
15981         fi
15982
15983         # combined striping
15984         $LFS setstripe -E 1024K -L mdt -E EOF $dom ||
15985                 error "Can't create DoM + OST striping"
15986
15987         dd if=/dev/urandom of=$tmp bs=1024 count=2000
15988         # check also direct IO along write
15989         dd if=$tmp of=$dom bs=102400 count=20 oflag=direct
15990         sync
15991         cmp $tmp $dom || error "file data is different"
15992         [ $(stat -c%s $dom) == 2048000 ] || error "bad size after write"
15993         rm $dom
15994         rm $tmp
15995
15996         return 0
15997 }
15998 run_test 270a "DoM: basic functionality tests"
15999
16000 test_270b() {
16001         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16002                 skip "Need MDS version at least 2.10.55" && return
16003
16004         local dom=$DIR/$tdir/dom_file
16005         local max_size=1048576
16006
16007         mkdir -p $DIR/$tdir
16008         $LFS setstripe -E $max_size -L mdt $dom
16009
16010         # truncate over the limit
16011         $TRUNCATE $dom $(($max_size + 1)) &&
16012                 error "successful truncate over the maximum size"
16013         # write over the limit
16014         dd if=/dev/zero of=$dom bs=$max_size seek=1 count=1 &&
16015                 error "successful write over the maximum size"
16016         # append over the limit
16017         dd if=/dev/zero of=$dom bs=$(($max_size - 3)) count=1
16018         echo "12345" >> $dom && error "successful append over the maximum size"
16019         rm $dom
16020
16021         return 0
16022 }
16023 run_test 270b "DoM: maximum size overflow checks for DoM-only file"
16024
16025 test_270c() {
16026         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16027                 skip "Need MDS version at least 2.10.55" && return
16028
16029         mkdir -p $DIR/$tdir
16030         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16031
16032         # check files inherit DoM EA
16033         touch $DIR/$tdir/first
16034         [ $($GETSTRIPE -L $DIR/$tdir/first) == "mdt" ] ||
16035                 error "bad pattern"
16036         [ $($LFS getstripe -c $DIR/$tdir/first) == 0 ] ||
16037                 error "bad stripe count"
16038         [ $($LFS getstripe -S $DIR/$tdir/first) == 1048576 ] ||
16039                 error "bad stripe size"
16040
16041         # check directory inherits DoM EA and uses it as default
16042         mkdir $DIR/$tdir/subdir
16043         touch $DIR/$tdir/subdir/second
16044         [ $($LFS getstripe -L $DIR/$tdir/subdir/second) == "mdt" ] ||
16045                 error "bad pattern in sub-directory"
16046         [ $($LFS getstripe -c $DIR/$tdir/subdir/second) == 0 ] ||
16047                 error "bad stripe count in sub-directory"
16048         [ $($LFS getstripe -S $DIR/$tdir/subdir/second) == 1048576 ] ||
16049                 error "bad stripe size in sub-directory"
16050         return 0
16051 }
16052 run_test 270c "DoM: DoM EA inheritance tests"
16053
16054 test_270d() {
16055         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16056                 skip "Need MDS version at least 2.10.55" && return
16057
16058         mkdir -p $DIR/$tdir
16059         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16060
16061         # inherit default DoM striping
16062         mkdir $DIR/$tdir/subdir
16063         touch $DIR/$tdir/subdir/f1
16064
16065         # change default directory striping
16066         $LFS setstripe -c 1 $DIR/$tdir/subdir
16067         touch $DIR/$tdir/subdir/f2
16068         [ $($LFS getstripe -c $DIR/$tdir/subdir/f2) == 1 ] ||
16069                 error "wrong default striping in file 2"
16070         [ $($LFS getstripe -L $DIR/$tdir/subdir/f2) == "raid0" ] ||
16071                 error "bad pattern in file 2"
16072         return 0
16073 }
16074 run_test 270d "DoM: change striping from DoM to RAID0"
16075
16076 test_270e() {
16077         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16078                 skip "Need MDS version at least 2.10.55" && return
16079
16080         mkdir -p $DIR/$tdir/dom
16081         mkdir -p $DIR/$tdir/norm
16082         DOMFILES=20
16083         NORMFILES=10
16084         $LFS setstripe -E 1M -L mdt $DIR/$tdir/dom
16085         $LFS setstripe -i 0 -S 2M $DIR/$tdir/norm
16086
16087         createmany -o $DIR/$tdir/dom/dom- $DOMFILES
16088         createmany -o $DIR/$tdir/norm/norm- $NORMFILES
16089
16090         # find DoM files by layout
16091         NUM=$($LFS find -L mdt -type f $DIR/$tdir 2>/dev/null | wc -l)
16092         [ $NUM -eq  $DOMFILES ] ||
16093                 error "lfs find -L: found $NUM, expected $DOMFILES"
16094         echo "Test 1: lfs find 20 DOM files by layout: OK"
16095
16096         # there should be 1 dir with default DOM striping
16097         NUM=$($LFS find -L mdt -type d $DIR/$tdir 2>/dev/null | wc -l)
16098         [ $NUM -eq  1 ] ||
16099                 error "lfs find -L: found $NUM, expected 1 dir"
16100         echo "Test 2: lfs find 1 DOM dir by layout: OK"
16101
16102         # find DoM files by stripe size
16103         NUM=$($LFS find -S -1200K -type f $DIR/$tdir 2>/dev/null | wc -l)
16104         [ $NUM -eq  $DOMFILES ] ||
16105                 error "lfs find -S: found $NUM, expected $DOMFILES"
16106         echo "Test 4: lfs find 20 DOM files by stripe size: OK"
16107
16108         # find files by stripe offset except DoM files
16109         NUM=$($LFS find -i 0 -type f $DIR/$tdir 2>/dev/null | wc -l)
16110         [ $NUM -eq  $NORMFILES ] ||
16111                 error "lfs find -i: found $NUM, expected $NORMFILES"
16112         echo "Test 5: lfs find no DOM files by stripe index: OK"
16113         return 0
16114 }
16115 run_test 270e "DoM: lfs find with DoM files test"
16116
16117 test_270f() {
16118         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16119                 skip "Need MDS version at least 2.10.55" && return
16120
16121         local mdtname=${FSNAME}-MDT0000-mdtlov
16122         local dom=$DIR/$tdir/dom_file
16123         local dom_limit_saved=$(do_facet mds1 $LCTL get_param -n \
16124                                                 lod.$mdtname.dom_stripesize)
16125         local dom_limit=131072
16126
16127         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=$dom_limit
16128         local dom_current=$(do_facet mds1 $LCTL get_param -n \
16129                                                 lod.$mdtname.dom_stripesize)
16130         [ ${dom_limit} -eq ${dom_current} ] ||
16131                 error "Cannot change per-MDT DoM stripe limit to $dom_limit"
16132
16133         $LFS mkdir -i 0 -c 1 $DIR/$tdir
16134         $LFS setstripe -d $DIR/$tdir
16135         $LFS setstripe -E $dom_limit -L mdt $DIR/$tdir ||
16136                 error "Can't set directory default striping"
16137
16138         # exceed maximum stripe size
16139         $LFS setstripe -E $(($dom_limit * 2)) -L mdt $dom &&
16140                 error "Able to create DoM component size more than LOD limit"
16141
16142         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=0
16143         dom_current=$(do_facet mds1 $LCTL get_param -n \
16144                                                 lod.$mdtname.dom_stripesize)
16145         [ 0 -eq ${dom_current} ] ||
16146                 error "Can't set zero DoM stripe limit"
16147
16148         # too low values to be aligned with smallest stripe size 64K
16149         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=30000
16150         dom_current=$(do_facet mds1 $LCTL get_param -n \
16151                                                 lod.$mdtname.dom_stripesize)
16152         [ 30000 -eq ${dom_current} ] &&
16153                 error "Can set too small DoM stripe limit"
16154
16155         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=2147483648
16156         dom_current=$(do_facet mds1 $LCTL get_param -n \
16157                                                 lod.$mdtname.dom_stripesize)
16158         echo $dom_current
16159         [ 2147483648 -eq ${dom_current} ] &&
16160                 error "Can set too large DoM stripe limit"
16161
16162         do_facet mds1 $LCTL set_param -n \
16163                                 lod.$mdtname.dom_stripesize=$((dom_limit * 2))
16164         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
16165                 error "Can't create DoM component size after limit change"
16166         do_facet mds1 $LCTL set_param -n \
16167                                 lod.$mdtname.dom_stripesize=$((dom_limit / 2))
16168         $LFS setstripe -E $dom_limit -L mdt ${dom}_big &&
16169                 error "Can create big DoM component after limit decrease"
16170         touch ${dom}_def ||
16171                 error "Can't create file with old default layout"
16172
16173         do_facet mds1 $LCTL set_param -n lod.*.dom_stripesize=$dom_limit_saved
16174         return 0
16175 }
16176 run_test 270f "DoM: maximum DoM stripe size checks"
16177
16178 test_271a() {
16179         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16180                 skip "Need MDS version at least 2.10.55" && return
16181
16182         local dom=$DIR/$tdir/dom
16183
16184         mkdir -p $DIR/$tdir
16185
16186         $LFS setstripe -E 1024K -L mdt $dom
16187
16188         lctl set_param -n mdc.*.stats=clear
16189         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
16190         cat $dom > /dev/null
16191         local reads=$(lctl get_param -n mdc.*.stats |
16192                         awk '/ost_read/ {print $2}')
16193         [ -z $reads ] || error "Unexpected $reads READ RPCs"
16194         ls $dom
16195         rm -f $dom
16196 }
16197 run_test 271a "DoM: data is cached for read after write"
16198
16199 test_271b() {
16200         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16201                 skip "Need MDS version at least 2.10.55" && return
16202
16203         local dom=$DIR/$tdir/dom
16204
16205         mkdir -p $DIR/$tdir
16206
16207         $LFS setstripe -E 1024K -L mdt -E EOF $dom
16208
16209         lctl set_param -n mdc.*.stats=clear
16210         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
16211         cancel_lru_locks mdc
16212         $CHECKSTAT -t file -s 4096 $dom || error "stat #1 fails"
16213         # second stat to check size is cached on client
16214         $CHECKSTAT -t file -s 4096 $dom || error "stat #2 fails"
16215         local gls=$(lctl get_param -n mdc.*.stats |
16216                         awk '/ldlm_glimpse/ {print $2}')
16217         [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
16218         rm -f $dom
16219 }
16220 run_test 271b "DoM: no glimpse RPC for stat (DoM only file)"
16221
16222 test_271ba() {
16223         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16224                 skip "Need MDS version at least 2.10.55" && return
16225
16226         local dom=$DIR/$tdir/dom
16227
16228         mkdir -p $DIR/$tdir
16229
16230         $LFS setstripe -E 1024K -L mdt -E EOF $dom
16231
16232         lctl set_param -n mdc.*.stats=clear
16233         lctl set_param -n osc.*.stats=clear
16234         dd if=/dev/zero of=$dom bs=2048K count=1 || return 1
16235         cancel_lru_locks mdc
16236         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
16237         # second stat to check size is cached on client
16238         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
16239         local gls=$(lctl get_param -n mdc.*.stats |
16240                         awk '/ldlm_glimpse/ {print $2}')
16241         [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
16242         local gls=$(lctl get_param -n osc.*.stats |
16243                         awk '/ldlm_glimpse/ {print $2}')
16244         [ -z $gls ] || error "Unexpected $gls OSC glimpse RPCs"
16245         rm -f $dom
16246 }
16247 run_test 271ba "DoM: no glimpse RPC for stat (combined file)"
16248
16249 test_271c() {
16250         # test to be enabled with lock_convert
16251         skip "skipped until lock convert will be implemented" && return
16252
16253         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
16254                 skip "Need MDS version at least 2.10.55" && return
16255
16256         local dom=$DIR/$tdir/dom
16257
16258         mkdir -p $DIR/$tdir
16259
16260         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
16261
16262         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
16263         local facet=mds$((mdtidx + 1))
16264
16265         cancel_lru_locks mdc
16266         do_facet $facet lctl set_param -n mdt.*.dom_lock=0
16267         createmany -o $dom 1000
16268         lctl set_param -n mdc.*.stats=clear
16269         smalliomany -w $dom 1000 200
16270         lctl get_param -n mdc.*.stats
16271         local enq=$(lctl get_param -n mdc.*.stats |
16272                         awk '/ldlm_ibits_enqueue/ {print $2}')
16273         # Each file has 1 open, 1 IO enqueues, total 2000
16274         # but now we have also +1 getxattr for security.capability, total 3000
16275         [ $enq -ge 2000 ] || error "Too few enqueues $enq, expected > 2000"
16276         unlinkmany $dom 1000
16277
16278         cancel_lru_locks mdc
16279         do_facet $facet lctl set_param -n mdt.*.dom_lock=1
16280         createmany -o $dom 1000
16281         lctl set_param -n mdc.*.stats=clear
16282         smalliomany -w $dom 1000 200
16283         lctl get_param -n mdc.*.stats
16284         local enq_2=$(lctl get_param -n mdc.*.stats |
16285                         awk '/ldlm_ibits_enqueue/ {print $2}')
16286         # Expect to see reduced amount of RPCs by 1000 due to single enqueue
16287         # for OPEN and IO lock.
16288         [ $((enq - enq_2)) -ge 1000 ] ||
16289                 error "Too many enqueues $enq_2, expected about $((enq - 1000))"
16290         unlinkmany $dom 1000
16291         return 0
16292 }
16293 run_test 271c "DoM: IO lock at open saves enqueue RPCs"
16294
16295 test_275() {
16296         remote_ost_nodsh && skip "remote OST with nodsh" && return
16297         [ $(lustre_version_code ost1) -lt $(version_code 2.10.57) ] &&
16298                 skip "Need OST version >= 2.10.57" && return 0
16299
16300         local file=$DIR/$tfile
16301         local oss
16302
16303         oss=$(comma_list $(osts_nodes))
16304
16305         dd if=/dev/urandom of=$file bs=1M count=2 ||
16306                 error "failed to create a file"
16307         cancel_lru_locks osc
16308
16309         #lock 1
16310         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
16311                 error "failed to read a file"
16312
16313 #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
16314         $LCTL set_param fail_loc=0x8000031f
16315
16316         cancel_lru_locks osc &
16317         sleep 1
16318
16319 #define OBD_FAIL_LDLM_PROLONG_PAUSE      0x32b
16320         do_nodes $oss $LCTL set_param fail_loc=0x8000032b
16321         #IO takes another lock, but matches the PENDING one
16322         #and places it to the IO RPC
16323         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
16324                 error "failed to read a file with PENDING lock"
16325 }
16326 run_test 275 "Read on a canceled duplicate lock"
16327
16328 test_276() {
16329         remote_ost_nodsh && skip "remote OST with nodsh" && return
16330         local pid
16331
16332         do_facet ost1 "(while true; do \
16333                 $LCTL get_param obdfilter.*.filesfree > /dev/null 2>&1; \
16334                 done) & pid=\\\$!; echo \\\$pid > $TMP/sanity_276_pid" &
16335         pid=$!
16336
16337         for LOOP in $(seq 20); do
16338                 stop ost1
16339                 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
16340         done
16341         kill -9 $pid
16342         do_facet ost1 "pid=\\\$(cat $TMP/sanity_276_pid); kill -9 \\\$pid; \
16343                 rm $TMP/sanity_276_pid"
16344 }
16345 run_test 276 "Race between mount and obd_statfs"
16346
16347 cleanup_test_300() {
16348         trap 0
16349         umask $SAVE_UMASK
16350 }
16351 test_striped_dir() {
16352         local mdt_index=$1
16353         local stripe_count
16354         local stripe_index
16355
16356         mkdir -p $DIR/$tdir
16357
16358         SAVE_UMASK=$(umask)
16359         trap cleanup_test_300 RETURN EXIT
16360
16361         $LFS setdirstripe -i $mdt_index -c 2 -H all_char -o 755 \
16362                                                 $DIR/$tdir/striped_dir ||
16363                 error "set striped dir error"
16364
16365         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
16366         [ "$mode" = "755" ] || error "expect 755 got $mode"
16367
16368         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
16369                 error "getdirstripe failed"
16370         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
16371         if [ "$stripe_count" != "2" ]; then
16372                 error "1:stripe_count is $stripe_count, expect 2"
16373         fi
16374         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
16375         if [ "$stripe_count" != "2" ]; then
16376                 error "2:stripe_count is $stripe_count, expect 2"
16377         fi
16378
16379         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
16380         if [ "$stripe_index" != "$mdt_index" ]; then
16381                 error "stripe_index is $stripe_index, expect $mdt_index"
16382         fi
16383
16384         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
16385                 error "nlink error after create striped dir"
16386
16387         mkdir $DIR/$tdir/striped_dir/a
16388         mkdir $DIR/$tdir/striped_dir/b
16389
16390         stat $DIR/$tdir/striped_dir/a ||
16391                 error "create dir under striped dir failed"
16392         stat $DIR/$tdir/striped_dir/b ||
16393                 error "create dir under striped dir failed"
16394
16395         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
16396                 error "nlink error after mkdir"
16397
16398         rmdir $DIR/$tdir/striped_dir/a
16399         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
16400                 error "nlink error after rmdir"
16401
16402         rmdir $DIR/$tdir/striped_dir/b
16403         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
16404                 error "nlink error after rmdir"
16405
16406         chattr +i $DIR/$tdir/striped_dir
16407         createmany -o $DIR/$tdir/striped_dir/f 10 &&
16408                 error "immutable flags not working under striped dir!"
16409         chattr -i $DIR/$tdir/striped_dir
16410
16411         rmdir $DIR/$tdir/striped_dir ||
16412                 error "rmdir striped dir error"
16413
16414         cleanup_test_300
16415
16416         true
16417 }
16418
16419 test_300a() {
16420         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
16421                 skip "skipped for lustre < 2.7.0" && return
16422         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16423         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16424
16425         test_striped_dir 0 || error "failed on striped dir on MDT0"
16426         test_striped_dir 1 || error "failed on striped dir on MDT0"
16427 }
16428 run_test 300a "basic striped dir sanity test"
16429
16430 test_300b() {
16431         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
16432                 skip "skipped for lustre < 2.7.0" && return
16433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16434         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16435         local i
16436         local mtime1
16437         local mtime2
16438         local mtime3
16439
16440         test_mkdir $DIR/$tdir || error "mkdir fail"
16441         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
16442                 error "set striped dir error"
16443         for i in {0..9}; do
16444                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
16445                 sleep 1
16446                 touch $DIR/$tdir/striped_dir/file_$i || error "touch error $i"
16447                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
16448                 [ $mtime1 -eq $mtime2 ] && error "mtime unchanged after create"
16449                 sleep 1
16450                 rm -f $DIR/$tdir/striped_dir/file_$i || error "unlink error $i"
16451                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
16452                 [ $mtime2 -eq $mtime3 ] && error "mtime unchanged after unlink"
16453         done
16454         true
16455 }
16456 run_test 300b "check ctime/mtime for striped dir"
16457
16458 test_300c() {
16459         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
16460                 skip "skipped for lustre < 2.7.0" && return
16461         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16462         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16463         local file_count
16464
16465         mkdir -p $DIR/$tdir
16466         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
16467                 error "set striped dir error"
16468
16469         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
16470                 error "chown striped dir failed"
16471
16472         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
16473                 error "create 5k files failed"
16474
16475         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
16476
16477         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
16478
16479         rm -rf $DIR/$tdir
16480 }
16481 run_test 300c "chown && check ls under striped directory"
16482
16483 test_300d() {
16484         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
16485                 skip "skipped for lustre < 2.7.0" && return
16486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16487         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16488         local stripe_count
16489         local file
16490
16491         mkdir -p $DIR/$tdir
16492         $SETSTRIPE -c 2 $DIR/$tdir
16493
16494         #local striped directory
16495         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
16496                 error "set striped dir error"
16497         createmany -o $DIR/$tdir/striped_dir/f 10 ||
16498                 error "create 10 files failed"
16499
16500         #remote striped directory
16501         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
16502                 error "set striped dir error"
16503         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
16504                 error "create 10 files failed"
16505
16506         for file in $(find $DIR/$tdir); do
16507                 stripe_count=$($GETSTRIPE -c $file)
16508                 [ $stripe_count -eq 2 ] ||
16509                         error "wrong stripe $stripe_count for $file"
16510         done
16511
16512         rm -rf $DIR/$tdir
16513 }
16514 run_test 300d "check default stripe under striped directory"
16515
16516 test_300e() {
16517         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16518                 skip "Need MDS version at least 2.7.55" && return
16519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16520         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16521         local stripe_count
16522         local file
16523
16524         mkdir -p $DIR/$tdir
16525
16526         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
16527                 error "set striped dir error"
16528
16529         touch $DIR/$tdir/striped_dir/a
16530         touch $DIR/$tdir/striped_dir/b
16531         touch $DIR/$tdir/striped_dir/c
16532
16533         mkdir $DIR/$tdir/striped_dir/dir_a
16534         mkdir $DIR/$tdir/striped_dir/dir_b
16535         mkdir $DIR/$tdir/striped_dir/dir_c
16536
16537         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_a ||
16538                 error "set striped adir under striped dir error"
16539
16540         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
16541                 error "set striped bdir under striped dir error"
16542
16543         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_c ||
16544                 error "set striped cdir under striped dir error"
16545
16546         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
16547                 error "rename dir under striped dir fails"
16548
16549         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
16550                 error "rename dir under different stripes fails"
16551
16552         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
16553                 error "rename file under striped dir should succeed"
16554
16555         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
16556                 error "rename dir under striped dir should succeed"
16557
16558         rm -rf $DIR/$tdir
16559 }
16560 run_test 300e "check rename under striped directory"
16561
16562 test_300f() {
16563         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16564                 skip "Need MDS version at least 2.7.55" && return
16565         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16566         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16567         local stripe_count
16568         local file
16569
16570         rm -rf $DIR/$tdir
16571         mkdir -p $DIR/$tdir
16572
16573         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
16574                 error "set striped dir error"
16575
16576         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir1 ||
16577                 error "set striped dir error"
16578
16579         touch $DIR/$tdir/striped_dir/a
16580         mkdir $DIR/$tdir/striped_dir/dir_a
16581         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
16582                 error "create striped dir under striped dir fails"
16583
16584         touch $DIR/$tdir/striped_dir1/b
16585         mkdir $DIR/$tdir/striped_dir1/dir_b
16586         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
16587                 error "create striped dir under striped dir fails"
16588
16589         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
16590                 error "rename dir under different striped dir should fail"
16591
16592         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
16593                 error "rename striped dir under diff striped dir should fail"
16594
16595         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
16596                 error "rename file under diff striped dirs fails"
16597
16598         rm -rf $DIR/$tdir
16599 }
16600 run_test 300f "check rename cross striped directory"
16601
16602 test_300_check_default_striped_dir()
16603 {
16604         local dirname=$1
16605         local default_count=$2
16606         local default_index=$3
16607         local stripe_count
16608         local stripe_index
16609         local dir_stripe_index
16610         local dir
16611
16612         echo "checking $dirname $default_count $default_index"
16613         $LFS setdirstripe -D -c $default_count -i $default_index \
16614                                 -t all_char $DIR/$tdir/$dirname ||
16615                 error "set default stripe on striped dir error"
16616         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
16617         [ $stripe_count -eq $default_count ] ||
16618                 error "expect $default_count get $stripe_count for $dirname"
16619
16620         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
16621         [ $stripe_index -eq $default_index ] ||
16622                 error "expect $default_index get $stripe_index for $dirname"
16623
16624         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
16625                                                 error "create dirs failed"
16626
16627         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
16628         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
16629         for dir in $(find $DIR/$tdir/$dirname/*); do
16630                 stripe_count=$($LFS getdirstripe -c $dir)
16631                 [ $stripe_count -eq $default_count ] ||
16632                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
16633                 error "stripe count $default_count != $stripe_count for $dir"
16634
16635                 stripe_index=$($LFS getdirstripe -i $dir)
16636                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
16637                         error "$stripe_index != $default_index for $dir"
16638
16639                 #check default stripe
16640                 stripe_count=$($LFS getdirstripe -D -c $dir)
16641                 [ $stripe_count -eq $default_count ] ||
16642                 error "default count $default_count != $stripe_count for $dir"
16643
16644                 stripe_index=$($LFS getdirstripe -D -i $dir)
16645                 [ $stripe_index -eq $default_index ] ||
16646                 error "default index $default_index != $stripe_index for $dir"
16647         done
16648         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
16649 }
16650
16651 test_300g() {
16652         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16653                 skip "Need MDS version at least 2.7.55" && return
16654         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16655         local dir
16656         local stripe_count
16657         local stripe_index
16658
16659         mkdir $DIR/$tdir
16660         mkdir $DIR/$tdir/normal_dir
16661
16662         #Checking when client cache stripe index
16663         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
16664         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
16665                 error "create striped_dir failed"
16666
16667         $LFS setdirstripe -i0 $DIR/$tdir/striped_dir/dir0 ||
16668                 error "create dir0 fails"
16669         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir0)
16670         [ $stripe_index -eq 0 ] ||
16671                 error "dir0 expect index 0 got $stripe_index"
16672
16673         mkdir $DIR/$tdir/striped_dir/dir1 ||
16674                 error "create dir1 fails"
16675         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
16676         [ $stripe_index -eq 1 ] ||
16677                 error "dir1 expect index 1 got $stripe_index"
16678
16679         #check default stripe count/stripe index
16680         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
16681         test_300_check_default_striped_dir normal_dir 1 0
16682         test_300_check_default_striped_dir normal_dir 2 1
16683         test_300_check_default_striped_dir normal_dir 2 -1
16684
16685         #delete default stripe information
16686         echo "delete default stripeEA"
16687         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
16688                 error "set default stripe on striped dir error"
16689
16690         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
16691         for dir in $(find $DIR/$tdir/normal_dir/*); do
16692                 stripe_count=$($LFS getdirstripe -c $dir)
16693                 [ $stripe_count -eq 0 ] ||
16694                         error "expect 1 get $stripe_count for $dir"
16695                 stripe_index=$($LFS getdirstripe -i $dir)
16696                 [ $stripe_index -eq 0 ] ||
16697                         error "expect 0 get $stripe_index for $dir"
16698         done
16699 }
16700 run_test 300g "check default striped directory for normal directory"
16701
16702 test_300h() {
16703         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16704                 skip "Need MDS version at least 2.7.55" && return
16705         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16706         local dir
16707         local stripe_count
16708
16709         mkdir $DIR/$tdir
16710         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
16711                 error "set striped dir error"
16712
16713         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
16714         test_300_check_default_striped_dir striped_dir 1 0
16715         test_300_check_default_striped_dir striped_dir 2 1
16716         test_300_check_default_striped_dir striped_dir 2 -1
16717
16718         #delete default stripe information
16719         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
16720                 error "set default stripe on striped dir error"
16721
16722         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
16723         for dir in $(find $DIR/$tdir/striped_dir/*); do
16724                 stripe_count=$($LFS getdirstripe -c $dir)
16725                 [ $stripe_count -eq 0 ] ||
16726                         error "expect 1 get $stripe_count for $dir"
16727         done
16728 }
16729 run_test 300h "check default striped directory for striped directory"
16730
16731 test_300i() {
16732         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16733                 skip "Need MDS version at least 2.7.55" && return
16734         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16735         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16736         local stripe_count
16737         local file
16738
16739         mkdir $DIR/$tdir
16740
16741         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
16742                 error "set striped dir error"
16743
16744         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
16745                 error "create files under striped dir failed"
16746
16747         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
16748                 error "set striped hashdir error"
16749
16750         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
16751                 error "create dir0 under hash dir failed"
16752         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
16753                 error "create dir1 under hash dir failed"
16754
16755         # unfortunately, we need to umount to clear dir layout cache for now
16756         # once we fully implement dir layout, we can drop this
16757         umount_client $MOUNT || error "umount failed"
16758         mount_client $MOUNT || error "mount failed"
16759
16760         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
16761         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
16762         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
16763
16764         #set the stripe to be unknown hash type
16765         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
16766         $LCTL set_param fail_loc=0x1901
16767         for ((i = 0; i < 10; i++)); do
16768                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
16769                         error "stat f-$i failed"
16770                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
16771         done
16772
16773         touch $DIR/$tdir/striped_dir/f0 &&
16774                 error "create under striped dir with unknown hash should fail"
16775
16776         $LCTL set_param fail_loc=0
16777
16778         umount_client $MOUNT || error "umount failed"
16779         mount_client $MOUNT || error "mount failed"
16780
16781         return 0
16782 }
16783 run_test 300i "client handle unknown hash type striped directory"
16784
16785 test_300j() {
16786         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16787         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16788                 skip "Need MDS version at least 2.7.55" && return
16789         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16790         local stripe_count
16791         local file
16792
16793         mkdir $DIR/$tdir
16794
16795         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
16796         $LCTL set_param fail_loc=0x1702
16797         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
16798                 error "set striped dir error"
16799
16800         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
16801                 error "create files under striped dir failed"
16802
16803         $LCTL set_param fail_loc=0
16804
16805         rm -rf $DIR/$tdir || error "unlink striped dir fails"
16806
16807         return 0
16808 }
16809 run_test 300j "test large update record"
16810
16811 test_300k() {
16812         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16813                 skip "Need MDS version at least 2.7.55" && return
16814         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16815         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16816         local stripe_count
16817         local file
16818
16819         mkdir $DIR/$tdir
16820
16821         #define OBD_FAIL_LARGE_STRIPE   0x1703
16822         $LCTL set_param fail_loc=0x1703
16823         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
16824                 error "set striped dir error"
16825         $LCTL set_param fail_loc=0
16826
16827         $LFS getdirstripe $DIR/$tdir/striped_dir ||
16828                 error "getstripeddir fails"
16829         rm -rf $DIR/$tdir/striped_dir ||
16830                 error "unlink striped dir fails"
16831
16832         return 0
16833 }
16834 run_test 300k "test large striped directory"
16835
16836 test_300l() {
16837         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16838                 skip "Need MDS version at least 2.7.55" && return
16839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16840         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16841         local stripe_index
16842
16843         test_mkdir -p $DIR/$tdir/striped_dir
16844         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
16845                         error "chown $RUNAS_ID failed"
16846         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
16847                 error "set default striped dir failed"
16848
16849         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
16850         $LCTL set_param fail_loc=0x80000158
16851         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
16852
16853         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
16854         [ $stripe_index -eq 1 ] ||
16855                 error "expect 1 get $stripe_index for $dir"
16856 }
16857 run_test 300l "non-root user to create dir under striped dir with stale layout"
16858
16859 test_300m() {
16860         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16861                 skip "Need MDS version at least 2.7.55" && return
16862         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16863         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
16864
16865         mkdir -p $DIR/$tdir/striped_dir
16866         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
16867                 error "set default stripes dir error"
16868
16869         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
16870
16871         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
16872         [ $stripe_count -eq 0 ] ||
16873                         error "expect 0 get $stripe_count for a"
16874
16875         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
16876                 error "set default stripes dir error"
16877
16878         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
16879
16880         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
16881         [ $stripe_count -eq 0 ] ||
16882                         error "expect 0 get $stripe_count for b"
16883
16884         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
16885                 error "set default stripes dir error"
16886
16887         mkdir $DIR/$tdir/striped_dir/c &&
16888                 error "default stripe_index is invalid, mkdir c should fails"
16889
16890         rm -rf $DIR/$tdir || error "rmdir fails"
16891 }
16892 run_test 300m "setstriped directory on single MDT FS"
16893
16894 cleanup_300n() {
16895         local list=$(comma_list $(mdts_nodes))
16896
16897         trap 0
16898         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16899 }
16900
16901 test_300n() {
16902         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16903                 skip "Need MDS version at least 2.7.55" && return
16904         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16905         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16906         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16907
16908         local stripe_index
16909         local list=$(comma_list $(mdts_nodes))
16910
16911         trap cleanup_300n RETURN EXIT
16912         mkdir -p $DIR/$tdir
16913         chmod 777 $DIR/$tdir
16914         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
16915                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
16916                 error "create striped dir succeeds with gid=0"
16917
16918         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
16919         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
16920                 error "create striped dir fails with gid=-1"
16921
16922         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16923         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
16924                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
16925                 error "set default striped dir succeeds with gid=0"
16926
16927
16928         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
16929         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
16930                 error "set default striped dir fails with gid=-1"
16931
16932
16933         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
16934         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
16935                                         error "create test_dir fails"
16936         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
16937                                         error "create test_dir1 fails"
16938         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
16939                                         error "create test_dir2 fails"
16940         cleanup_300n
16941 }
16942 run_test 300n "non-root user to create dir under striped dir with default EA"
16943
16944 test_300o() {
16945         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16946                 skip "Need MDS version at least 2.7.55" && return
16947         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16948         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16949         local numfree1
16950         local numfree2
16951
16952         mkdir -p $DIR/$tdir
16953
16954         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
16955         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
16956         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
16957                 skip "not enough free inodes $numfree1 $numfree2"
16958                 return
16959         fi
16960
16961         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
16962         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
16963         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
16964                 skip "not enough free space $numfree1 $numfree2"
16965                 return
16966         fi
16967
16968         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
16969                 error "setdirstripe fails"
16970
16971         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
16972                 error "create dirs fails"
16973
16974         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
16975         ls $DIR/$tdir/striped_dir > /dev/null ||
16976                 error "ls striped dir fails"
16977         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
16978                 error "unlink big striped dir fails"
16979 }
16980 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
16981
16982 test_300p() {
16983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16984         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16985         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16986
16987         mkdir -p $DIR/$tdir
16988
16989         #define OBD_FAIL_OUT_ENOSPC     0x1704
16990         do_facet mds2 lctl set_param fail_loc=0x80001704
16991         $LFS setdirstripe -i 0 -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 \
16992                  && error "create striped directory should fail"
16993
16994         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
16995
16996         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
16997         true
16998 }
16999 run_test 300p "create striped directory without space"
17000
17001 test_300q() {
17002         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17003         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
17004
17005         local fd=$(free_fd)
17006         local cmd="exec $fd<$tdir"
17007         cd $DIR
17008         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
17009         eval $cmd
17010         cmd="exec $fd<&-"
17011         trap "eval $cmd" EXIT
17012         cd $tdir || error "cd $tdir fails"
17013         rmdir  ../$tdir || error "rmdir $tdir fails"
17014         mkdir local_dir && error "create dir succeeds"
17015         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
17016         eval $cmd
17017         return 0
17018 }
17019 run_test 300q "create remote directory under orphan directory"
17020
17021 prepare_remote_file() {
17022         mkdir $DIR/$tdir/src_dir ||
17023                 error "create remote source failed"
17024
17025         cp /etc/hosts $DIR/$tdir/src_dir/a ||
17026                  error "cp to remote source failed"
17027         touch $DIR/$tdir/src_dir/a
17028
17029         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
17030                 error "create remote target dir failed"
17031
17032         touch $DIR/$tdir/tgt_dir/b
17033
17034         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
17035                 error "rename dir cross MDT failed!"
17036
17037         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
17038                 error "src_child still exists after rename"
17039
17040         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
17041                 error "missing file(a) after rename"
17042
17043         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
17044                 error "diff after rename"
17045 }
17046
17047 test_310a() {
17048         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
17049         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17050         local remote_file=$DIR/$tdir/tgt_dir/b
17051
17052         mkdir -p $DIR/$tdir
17053
17054         prepare_remote_file || error "prepare remote file failed"
17055
17056         #open-unlink file
17057         $OPENUNLINK $remote_file $remote_file ||
17058                 error "openunlink $remote_file failed"
17059         $CHECKSTAT -a $remote_file || error "$remote_file exists"
17060 }
17061 run_test 310a "open unlink remote file"
17062
17063 test_310b() {
17064         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
17065         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17066         local remote_file=$DIR/$tdir/tgt_dir/b
17067
17068         mkdir -p $DIR/$tdir
17069
17070         prepare_remote_file || error "prepare remote file failed"
17071
17072         ln $remote_file $DIR/$tfile || error "link failed for remote file"
17073         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
17074         $CHECKSTAT -t file $remote_file || error "check file failed"
17075 }
17076 run_test 310b "unlink remote file with multiple links while open"
17077
17078 test_310c() {
17079         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
17080         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17081         local remote_file=$DIR/$tdir/tgt_dir/b
17082
17083         mkdir -p $DIR/$tdir
17084
17085         prepare_remote_file || error "prepare remote file failed"
17086
17087         ln $remote_file $DIR/$tfile || error "link failed for remote file"
17088         multiop_bg_pause $remote_file O_uc ||
17089                         error "mulitop failed for remote file"
17090         MULTIPID=$!
17091         $MULTIOP $DIR/$tfile Ouc
17092         kill -USR1 $MULTIPID
17093         wait $MULTIPID
17094 }
17095 run_test 310c "open-unlink remote file with multiple links"
17096
17097 #LU-4825
17098 test_311() {
17099         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
17100         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
17101                 skip "lustre < 2.8.54 does not contain LU-4825 fix" && return
17102         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17103         remote_mds_nodsh && skip "remote MDS with nodsh" && return
17104
17105         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
17106
17107         mkdir -p $DIR/$tdir
17108         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
17109         createmany -o $DIR/$tdir/$tfile. 1000
17110
17111         # statfs data is not real time, let's just calculate it
17112         old_iused=$((old_iused + 1000))
17113
17114         local count=$(do_facet $SINGLEMDS "lctl get_param -n \
17115                         osp.*OST0000*MDT0000.create_count")
17116         local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
17117                                 osp.*OST0000*MDT0000.max_create_count")
17118         for idx in $(seq $MDSCOUNT); do
17119                 do_facet mds$idx "lctl set_param -n \
17120                         osp.*OST0000*MDT000?.max_create_count=0"
17121         done
17122
17123         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
17124         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
17125         [ $index -ne 0 ] || error "$tfile stripe index is 0"
17126
17127         unlinkmany $DIR/$tdir/$tfile. 1000
17128
17129         for idx in $(seq $MDSCOUNT); do
17130                 do_facet mds$idx "lctl set_param -n \
17131                         osp.*OST0000*MDT000?.max_create_count=$max_count"
17132                 do_facet mds$idx "lctl set_param -n \
17133                         osp.*OST0000*MDT000?.create_count=$count"
17134         done
17135
17136         local new_iused
17137         for i in $(seq 120); do
17138                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
17139                 # system may be too busy to destroy all objs in time, use
17140                 # a somewhat small value to not fail autotest
17141                 [ $((old_iused - new_iused)) -gt 400 ] && break
17142                 sleep 1
17143         done
17144
17145         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
17146         [ $((old_iused - new_iused)) -gt 400 ] ||
17147                 error "objs not destroyed after unlink"
17148 }
17149 run_test 311 "disable OSP precreate, and unlink should destroy objs"
17150
17151 zfs_oid_to_objid()
17152 {
17153         local ost=$1
17154         local objid=$2
17155
17156         local vdevdir=$(dirname $(facet_vdevice $ost))
17157         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
17158         local zfs_zapid=$(do_facet $ost $cmd |
17159                           grep -w "/O/0/d$((objid%32))" -C 5 |
17160                           awk '/Object/{getline; print $1}')
17161         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
17162                           awk "/$objid = /"'{printf $3}')
17163
17164         echo $zfs_objid
17165 }
17166
17167 zfs_object_blksz() {
17168         local ost=$1
17169         local objid=$2
17170
17171         local vdevdir=$(dirname $(facet_vdevice $ost))
17172         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
17173         local blksz=$(do_facet $ost $cmd $objid |
17174                       awk '/dblk/{getline; printf $4}')
17175
17176         case "${blksz: -1}" in
17177                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
17178                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
17179                 *) ;;
17180         esac
17181
17182         echo $blksz
17183 }
17184
17185 test_312() { # LU-4856
17186         remote_ost_nodsh && skip "remote OST with nodsh" && return
17187
17188         [ $(facet_fstype ost1) = "zfs" ] ||
17189                 { skip "the test only applies to zfs" && return; }
17190
17191         local max_blksz=$(do_facet ost1 \
17192                           $ZFS get -p recordsize $(facet_device ost1) |
17193                           awk '!/VALUE/{print $3}')
17194         local min_blksz=$(getconf PAGE_SIZE)
17195
17196         # to make life a little bit easier
17197         $LFS mkdir -c 1 -i 0 $DIR/$tdir
17198         $LFS setstripe -c 1 -i 0 $DIR/$tdir
17199
17200         local tf=$DIR/$tdir/$tfile
17201         touch $tf
17202         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17203
17204         # Get ZFS object id
17205         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17206
17207         # block size change by sequential over write
17208         local blksz
17209         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
17210                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
17211
17212                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
17213                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
17214         done
17215         rm -f $tf
17216
17217         # block size change by sequential append write
17218         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
17219         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17220         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17221
17222         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
17223                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
17224                         oflag=sync conv=notrunc
17225
17226                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
17227                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
17228                         error "blksz error, actual $blksz, "    \
17229                                 "expected: 2 * $count * $min_blksz"
17230         done
17231         rm -f $tf
17232
17233         # random write
17234         touch $tf
17235         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
17236         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
17237
17238         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
17239         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17240         [ $blksz -eq $min_blksz ] ||
17241                 error "blksz error: $blksz, expected: $min_blksz"
17242
17243         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
17244         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17245         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
17246
17247         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
17248         blksz=$(zfs_object_blksz ost1 $zfs_objid)
17249         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
17250 }
17251 run_test 312 "make sure ZFS adjusts its block size by write pattern"
17252
17253 test_313() {
17254         remote_ost_nodsh && skip "remote OST with nodsh" && return
17255
17256         local file=$DIR/$tfile
17257         rm -f $file
17258         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
17259
17260         # define OBD_FAIL_TGT_RCVD_EIO           0x720
17261         do_facet ost1 "$LCTL set_param fail_loc=0x720"
17262         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
17263                 error "write should failed"
17264         do_facet ost1 "$LCTL set_param fail_loc=0"
17265         rm -f $file
17266 }
17267 run_test 313 "io should fail after last_rcvd update fail"
17268
17269 test_314() {
17270         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
17271
17272         $SETSTRIPE -c 2 -i 0 $DIR/$tfile || error "setstripe failed"
17273         do_facet ost1 "$LCTL set_param fail_loc=0x720"
17274         rm -f $DIR/$tfile
17275         wait_delete_completed
17276         do_facet ost1 "$LCTL set_param fail_loc=0"
17277 }
17278 run_test 314 "OSP shouldn't fail after last_rcvd update failure"
17279
17280 test_315() { # LU-618
17281         local file=$DIR/$tfile
17282         rm -f $file
17283
17284         $MULTIOP $file oO_CREAT:O_DIRECT:O_RDWR:w4096000c
17285         $MULTIOP $file oO_RDONLY:r4096000_c &
17286         PID=$!
17287
17288         sleep 2
17289
17290         local rbytes=$(awk '/read_bytes/ { print $2 }' /proc/$PID/io)
17291         kill -USR1 $PID
17292
17293         [ $rbytes -gt 4000000 ] || error "read is not accounted ($rbytes)"
17294         rm -f $file
17295 }
17296 run_test 315 "read should be accounted"
17297
17298 test_316() {
17299         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
17300         large_xattr_enabled || { skip "large_xattr disabled" && return; }
17301
17302         rm -rf $DIR/$tdir/d
17303         mkdir -p $DIR/$tdir/d
17304         chown nobody $DIR/$tdir/d
17305         touch $DIR/$tdir/d/file
17306
17307         $LFS mv -M1 $DIR/$tdir/d || error "lfs mv failed"
17308 }
17309 run_test 316 "lfs mv"
17310
17311 test_fake_rw() {
17312         local read_write=$1
17313         if [ "$read_write" = "write" ]; then
17314                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
17315         elif [ "$read_write" = "read" ]; then
17316                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
17317         else
17318                 error "argument error"
17319         fi
17320
17321         # turn off debug for performance testing
17322         local saved_debug=$($LCTL get_param -n debug)
17323         $LCTL set_param debug=0
17324
17325         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
17326
17327         # get ost1 size - lustre-OST0000
17328         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
17329         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
17330         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
17331
17332         if [ "$read_write" = "read" ]; then
17333                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
17334         fi
17335
17336         local start_time=$(date +%s.%N)
17337         $dd_cmd bs=1M count=$blocks oflag=sync ||
17338                 error "real dd $read_write error"
17339         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
17340
17341         if [ "$read_write" = "write" ]; then
17342                 rm -f $DIR/$tfile
17343         fi
17344
17345         # define OBD_FAIL_OST_FAKE_RW           0x238
17346         do_facet ost1 $LCTL set_param fail_loc=0x238
17347
17348         local start_time=$(date +%s.%N)
17349         $dd_cmd bs=1M count=$blocks oflag=sync ||
17350                 error "fake dd $read_write error"
17351         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
17352
17353         if [ "$read_write" = "write" ]; then
17354                 # verify file size
17355                 cancel_lru_locks osc
17356                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
17357                         error "$tfile size not $blocks MB"
17358         fi
17359         do_facet ost1 $LCTL set_param fail_loc=0
17360
17361         echo "fake $read_write $duration_fake vs. normal $read_write" \
17362                 "$duration in seconds"
17363         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
17364                 error_not_in_vm "fake write is slower"
17365
17366         $LCTL set_param -n debug="$saved_debug"
17367         rm -f $DIR/$tfile
17368 }
17369 test_399a() { # LU-7655 for OST fake write
17370         remote_ost_nodsh && skip "remote OST with nodsh" && return
17371
17372         test_fake_rw write
17373 }
17374 run_test 399a "fake write should not be slower than normal write"
17375
17376 test_399b() { # LU-8726 for OST fake read
17377         remote_ost_nodsh && skip "remote OST with nodsh" && return
17378
17379         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
17380                 skip "ldiskfs only test" && return 0
17381         fi
17382         test_fake_rw read
17383 }
17384 run_test 399b "fake read should not be slower than normal read"
17385
17386 test_400a() { # LU-1606, was conf-sanity test_74
17387         local extra_flags=''
17388         local out=$TMP/$tfile
17389         local prefix=/usr/include/lustre
17390         local prog
17391
17392         if ! which $CC > /dev/null 2>&1; then
17393                 skip_env "$CC is not installed"
17394                 return 0
17395         fi
17396
17397         if ! [[ -d $prefix ]]; then
17398                 # Assume we're running in tree and fixup the include path.
17399                 extra_flags+=" -I$LUSTRE/include"
17400                 extra_flags+=" -L$LUSTRE/utils"
17401         fi
17402
17403         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
17404                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
17405                         error "client api broken"
17406         done
17407         rm -f $out
17408 }
17409 run_test 400a "Lustre client api program can compile and link"
17410
17411 test_400b() { # LU-1606, LU-5011
17412         local header
17413         local out=$TMP/$tfile
17414         local prefix=/usr/include/linux/lustre
17415
17416         # We use a hard coded prefix so that this test will not fail
17417         # when run in tree. There are headers in lustre/include/lustre/
17418         # that are not packaged (like lustre_idl.h) and have more
17419         # complicated include dependencies (like config.h and lnet/types.h).
17420         # Since this test about correct packaging we just skip them when
17421         # they don't exist (see below) rather than try to fixup cppflags.
17422
17423         if ! which $CC > /dev/null 2>&1; then
17424                 skip_env "$CC is not installed"
17425                 return 0
17426         fi
17427
17428         for header in $prefix/*.h; do
17429                 if ! [[ -f "$header" ]]; then
17430                         continue
17431                 fi
17432
17433                 if [[ "$(basename $header)" == lustre_ioctl.h ]]; then
17434                         continue # lustre_ioctl.h is internal header
17435                 fi
17436
17437                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
17438                         error "cannot compile '$header'"
17439         done
17440         rm -f $out
17441 }
17442 run_test 400b "packaged headers can be compiled"
17443
17444 test_401a() { #LU-7437
17445         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
17446         [ -n "$printf_arg" ] && skip_env "find does not support -printf" &&
17447                 return
17448         #count the number of parameters by "list_param -R"
17449         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
17450         #count the number of parameters by listing proc files
17451         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
17452         echo "proc_dirs='$proc_dirs'"
17453         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
17454         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
17455                       sort -u | wc -l)
17456
17457         [ $params -eq $procs ] ||
17458                 error "found $params parameters vs. $procs proc files"
17459
17460         # test the list_param -D option only returns directories
17461         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
17462         #count the number of parameters by listing proc directories
17463         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
17464                 sort -u | wc -l)
17465
17466         [ $params -eq $procs ] ||
17467                 error "found $params parameters vs. $procs proc files"
17468 }
17469 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
17470
17471 test_401b() {
17472         local save=$($LCTL get_param -n jobid_var)
17473         local tmp=testing
17474
17475         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
17476                 error "no error returned when setting bad parameters"
17477
17478         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
17479         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
17480
17481         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
17482         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
17483         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
17484 }
17485 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
17486
17487 test_401c() {
17488         local jobid_var_old=$($LCTL get_param -n jobid_var)
17489         local jobid_var_new
17490
17491         $LCTL set_param jobid_var= &&
17492                 error "no error returned for 'set_param a='"
17493
17494         jobid_var_new=$($LCTL get_param -n jobid_var)
17495         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
17496                 error "jobid_var was changed by setting without value"
17497
17498         $LCTL set_param jobid_var &&
17499                 error "no error returned for 'set_param a'"
17500
17501         jobid_var_new=$($LCTL get_param -n jobid_var)
17502         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
17503                 error "jobid_var was changed by setting without value"
17504 }
17505 run_test 401c "Verify 'lctl set_param' without value fails in either format."
17506
17507 test_401d() {
17508         local jobid_var_old=$($LCTL get_param -n jobid_var)
17509         local jobid_var_new
17510         local new_value="foo=bar"
17511
17512         $LCTL set_param jobid_var=$new_value ||
17513                 error "'set_param a=b' did not accept a value containing '='"
17514
17515         jobid_var_new=$($LCTL get_param -n jobid_var)
17516         [[ "$jobid_var_new" == "$new_value" ]] ||
17517                 error "'set_param a=b' failed on a value containing '='"
17518
17519         # Reset the jobid_var to test the other format
17520         $LCTL set_param jobid_var=$jobid_var_old
17521         jobid_var_new=$($LCTL get_param -n jobid_var)
17522         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
17523                 error "failed to reset jobid_var"
17524
17525         $LCTL set_param jobid_var $new_value ||
17526                 error "'set_param a b' did not accept a value containing '='"
17527
17528         jobid_var_new=$($LCTL get_param -n jobid_var)
17529         [[ "$jobid_var_new" == "$new_value" ]] ||
17530                 error "'set_param a b' failed on a value containing '='"
17531
17532         $LCTL set_param jobid_var $jobid_var_old
17533         jobid_var_new=$($LCTL get_param -n jobid_var)
17534         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
17535                 error "failed to reset jobid_var"
17536 }
17537 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
17538
17539 test_402() {
17540         local server_version=$(lustre_version_code $SINGLEMDS)
17541         [[ $server_version -ge $(version_code 2.7.66) ]] ||
17542         [[ $server_version -ge $(version_code 2.7.18.4) &&
17543                 $server_version -lt $(version_code 2.7.50) ]] ||
17544         [[ $server_version -ge $(version_code 2.7.2) &&
17545                 $server_version -lt $(version_code 2.7.11) ]] ||
17546                 { skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+";
17547                         return; }
17548         remote_mds_nodsh && skip "remote MDS with nodsh" && return
17549         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
17550 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
17551         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
17552         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
17553                 echo "Touch failed - OK"
17554 }
17555 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
17556
17557 test_403() {
17558         local file1=$DIR/$tfile.1
17559         local file2=$DIR/$tfile.2
17560         local tfile=$TMP/$tfile
17561
17562         rm -f $file1 $file2 $tfile
17563
17564         touch $file1
17565         ln $file1 $file2
17566
17567         # 30 sec OBD_TIMEOUT in ll_getattr()
17568         # right before populating st_nlink
17569         $LCTL set_param fail_loc=0x80001409
17570         stat -c %h $file1 > $tfile &
17571
17572         # create an alias, drop all locks and reclaim the dentry
17573         < $file2
17574         cancel_lru_locks mdc
17575         cancel_lru_locks osc
17576         sysctl -w vm.drop_caches=2
17577
17578         wait
17579
17580         [ $(cat $tfile) -gt 0 ] || error "wrong nlink count: $(cat $tfile)"
17581
17582         rm -f $tfile $file1 $file2
17583 }
17584 run_test 403 "i_nlink should not drop to zero due to aliasing"
17585
17586 test_404() { # LU-6601
17587         local server_version=$(lustre_version_code $SINGLEMDS)
17588         [[ $server_version -ge $(version_code 2.8.53) ]] ||
17589                 { skip "Need server version newer than 2.8.52"; return 0; }
17590
17591         remote_mds_nodsh && skip "remote MDS with nodsh" && return
17592         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
17593                 awk '/osp .*-osc-MDT/ { print $4}')
17594
17595         local osp
17596         for osp in $mosps; do
17597                 echo "Deactivate: " $osp
17598                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
17599                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
17600                         awk -vp=$osp '$4 == p { print $2 }')
17601                 [ $stat = IN ] || {
17602                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
17603                         error "deactivate error"
17604                 }
17605                 echo "Activate: " $osp
17606                 do_facet $SINGLEMDS $LCTL --device %$osp activate
17607                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
17608                         awk -vp=$osp '$4 == p { print $2 }')
17609                 [ $stat = UP ] || {
17610                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
17611                         error "activate error"
17612                 }
17613         done
17614 }
17615 run_test 404 "validate manual {de}activated works properly for OSPs"
17616
17617 test_405() {
17618         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) -o \
17619         [ $(lustre_version_code client) -lt $(version_code 2.6.99) ] &&
17620                 skip "Layout swap lock is not supported" && return
17621
17622         check_swap_layouts_support && return 0
17623
17624         test_mkdir $DIR/$tdir
17625         swap_lock_test -d $DIR/$tdir ||
17626                 error "One layout swap locked test failed"
17627 }
17628 run_test 405 "Various layout swap lock tests"
17629
17630 test_406() {
17631         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
17632         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
17633         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
17634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17635         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
17636                 skip "Need MDS version at least 2.8.50" && return
17637
17638         local def_stripe_size=$($LFS getstripe -S $MOUNT)
17639         local test_pool=$TESTNAME
17640
17641         if ! combined_mgs_mds ; then
17642                 mount_mgs_client
17643         fi
17644         pool_add $test_pool || error "pool_add failed"
17645         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
17646                 error "pool_add_targets failed"
17647
17648         save_layout_restore_at_exit $MOUNT
17649
17650         # parent set default stripe count only, child will stripe from both
17651         # parent and fs default
17652         $LFS setstripe -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
17653                 error "setstripe $MOUNT failed"
17654         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
17655         $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
17656         for i in $(seq 10); do
17657                 local f=$DIR/$tdir/$tfile.$i
17658                 touch $f || error "touch failed"
17659                 local count=$($LFS getstripe -c $f)
17660                 [ $count -eq $OSTCOUNT ] ||
17661                         error "$f stripe count $count != $OSTCOUNT"
17662                 local offset=$($LFS getstripe -i $f)
17663                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
17664                 local size=$($LFS getstripe -S $f)
17665                 [ $size -eq $((def_stripe_size * 2)) ] ||
17666                         error "$f stripe size $size != $((def_stripe_size * 2))"
17667                 local pool=$($LFS getstripe -p $f)
17668                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
17669         done
17670
17671         # change fs default striping, delete parent default striping, now child
17672         # will stripe from new fs default striping only
17673         $LFS setstripe -c 1 -S $def_stripe_size -i 0 $MOUNT ||
17674                 error "change $MOUNT default stripe failed"
17675         $LFS setstripe -c 0 $DIR/$tdir ||
17676                 error "delete $tdir default stripe failed"
17677         for i in $(seq 11 20); do
17678                 local f=$DIR/$tdir/$tfile.$i
17679                 touch $f || error "touch $f failed"
17680                 local count=$($LFS getstripe -c $f)
17681                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
17682                 local offset=$($LFS getstripe -i $f)
17683                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
17684                 local size=$($LFS getstripe -S $f)
17685                 [ $size -eq $def_stripe_size ] ||
17686                         error "$f stripe size $size != $def_stripe_size"
17687                 local pool=$($LFS getstripe -p $f)
17688                 [ $pool == $test_pool ] || error "$f pool $pool isn't set"
17689         done
17690
17691         unlinkmany $DIR/$tdir/$tfile. 1 20
17692
17693         local f=$DIR/$tdir/$tfile
17694         pool_remove_all_targets $test_pool $f
17695         pool_remove $test_pool $f
17696
17697         if ! combined_mgs_mds ; then
17698                 umount_mgs_client
17699         fi
17700 }
17701 run_test 406 "DNE support fs default striping"
17702
17703 test_407() {
17704         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
17705         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
17706                 skip "Need MDS version at least 2.8.55" && return
17707         remote_mds_nodsh && skip "remote MDS with nodsh" && return
17708
17709         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
17710                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
17711         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
17712                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
17713         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
17714
17715         #define OBD_FAIL_DT_TXN_STOP    0x2019
17716         for idx in $(seq $MDSCOUNT); do
17717                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
17718         done
17719         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
17720         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
17721                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
17722         true
17723 }
17724 run_test 407 "transaction fail should cause operation fail"
17725
17726 test_408() {
17727         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
17728
17729         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
17730         lctl set_param fail_loc=0x8000040a
17731         # let ll_prepare_partial_page() fail
17732         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
17733
17734         rm -f $DIR/$tfile
17735
17736         # create at least 100 unused inodes so that
17737         # shrink_icache_memory(0) should not return 0
17738         touch $DIR/$tfile-{0..100}
17739         rm -f $DIR/$tfile-{0..100}
17740         sync
17741
17742         echo 2 > /proc/sys/vm/drop_caches
17743 }
17744 run_test 408 "drop_caches should not hang due to page leaks"
17745
17746 test_409()
17747 {
17748         [ $MDSCOUNT -lt 2 ] &&
17749                 skip "We need at least 2 MDTs for this test" && return
17750
17751         check_mount_and_prep
17752
17753         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
17754         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
17755         touch $DIR/$tdir/guard || error "(2) Fail to create"
17756
17757         local PREFIX=$(str_repeat 'A' 128)
17758         echo "Create 1K hard links start at $(date)"
17759         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
17760                 error "(3) Fail to hard link"
17761
17762         echo "Links count should be right although linkEA overflow"
17763         stat $DIR/$tdir/guard || error "(4) Fail to stat"
17764         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
17765         [ $linkcount -eq 1001 ] ||
17766                 error "(5) Unexpected hard links count: $linkcount"
17767
17768         echo "List all links start at $(date)"
17769         ls -l $DIR/$tdir/foo > /dev/null ||
17770                 error "(6) Fail to list $DIR/$tdir/foo"
17771
17772         echo "Unlink hard links start at $(date)"
17773         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
17774                 error "(7) Fail to unlink"
17775 }
17776 run_test 409 "Large amount of cross-MDTs hard links on the same file"
17777
17778 test_410()
17779 {
17780         [[ $(lustre_version_code client) -lt $(version_code 2.9.59) ]] &&
17781                 skip "Need client version at least 2.9.59" && return
17782
17783         # Create a file, and stat it from the kernel
17784         local testfile=$DIR/$tfile
17785         touch $testfile
17786
17787         local run_id=$RANDOM
17788         local my_ino=$(stat --format "%i" $testfile)
17789
17790         # Try to insert the module. This will always fail as the
17791         # module is designed to not be inserted.
17792         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
17793             &> /dev/null
17794
17795         # Anything but success is a test failure
17796         dmesg | grep -q \
17797             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
17798             error "no inode match"
17799 }
17800 run_test 410 "Test inode number returned from kernel thread"
17801
17802 cleanup_test411_cgroup() {
17803         trap 0
17804         rmdir "$1"
17805 }
17806
17807 test_411() {
17808         local cg_basedir=/sys/fs/cgroup/memory
17809         # LU-9966
17810         test -f "$cg_basedir/memory.kmem.limit_in_bytes" ||
17811                 { skip "no setup for cgroup"; return; }
17812
17813         dd if=/dev/zero of=$DIR/$tfile bs=1M count=100 conv=fsync ||
17814                 error "test file creation failed"
17815         cancel_lru_locks osc
17816
17817         # Create a very small memory cgroup to force a slab allocation error
17818         local cgdir=$cg_basedir/osc_slab_alloc
17819         mkdir $cgdir || error "cgroup mkdir '$cgdir' failed"
17820         trap "cleanup_test411_cgroup $cgdir" EXIT
17821         echo 2M > $cgdir/memory.kmem.limit_in_bytes
17822         echo 1M > $cgdir/memory.limit_in_bytes
17823
17824         # Should not LBUG, just be killed by oom-killer
17825         sh -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null" &&
17826                 error "fail to trigger a memory allocation error"
17827
17828         cleanup_test411_cgroup $cgdir
17829
17830         return 0
17831 }
17832 run_test 411 "Slab allocation error with cgroup does not LBUG"
17833
17834 test_412() {
17835         [ $MDSCOUNT -lt 2 ] &&
17836                 skip "We need at least 2 MDTs for this test" && return
17837
17838         if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
17839                 skip "Need server version at least 2.10.55" && exit 0
17840         fi
17841
17842         $LFS mkdir -i $((MDSCOUNT - 1)),$((MDSCOUNT - 2)) $DIR/$tdir ||
17843                 error "mkdir failed"
17844         $LFS getdirstripe $DIR/$tdir
17845         local stripe_index=$($LFS getdirstripe -i $DIR/$tdir)
17846         [ $stripe_index -eq $((MDSCOUNT - 1)) ] ||
17847                 error "expect $((MDSCOUT - 1)) get $stripe_index"
17848         local stripe_count=$($LFS getdirstripe -T $DIR/$tdir)
17849         [ $stripe_count -eq 2 ] ||
17850                 error "expect 2 get $stripe_count"
17851 }
17852 run_test 412 "mkdir on specific MDTs"
17853
17854 test_413() {
17855         [ $MDSCOUNT -lt 2 ] &&
17856                 skip "We need at least 2 MDTs for this test" && return
17857
17858         if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
17859                 skip "Need server version at least 2.10.55" && exit 0
17860         fi
17861
17862         mkdir $DIR/$tdir || error "mkdir failed"
17863
17864         # find MDT that is the most full
17865         local max=$($LFS df | grep MDT |
17866                 awk 'BEGIN { a=0 }
17867                         { sub("%", "", $5)
17868                           if (0+$5 >= a)
17869                           {
17870                                 a = $5
17871                                 b = $6
17872                           }
17873                         }
17874                      END { split(b, c, ":")
17875                            sub("]", "", c[2])
17876                            print c[2]
17877                          }')
17878
17879         for i in $(seq $((MDSCOUNT - 1))); do
17880                 $LFS mkdir -c $i $DIR/$tdir/d$i ||
17881                         error "mkdir d$i failed"
17882                 $LFS getdirstripe $DIR/$tdir/d$i
17883                 local stripe_index=$($LFS getdirstripe -i $DIR/$tdir/d$i)
17884                 [ $stripe_index -ne $max ] ||
17885                         error "don't expect $max"
17886         done
17887 }
17888 run_test 413 "mkdir on less full MDTs"
17889
17890 prep_801() {
17891         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
17892         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
17893                 skip "Need server version at least 2.9.55" & exit 0
17894         start_full_debug_logging
17895 }
17896
17897 post_801() {
17898         stop_full_debug_logging
17899 }
17900
17901 barrier_stat() {
17902         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
17903                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
17904                            awk '/The barrier for/ { print $7 }')
17905                 echo $st
17906         else
17907                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
17908                 echo \'$st\'
17909         fi
17910 }
17911
17912 barrier_expired() {
17913         local expired
17914
17915         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
17916                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
17917                           awk '/will be expired/ { print $7 }')
17918         else
17919                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
17920         fi
17921
17922         echo $expired
17923 }
17924
17925 test_801a() {
17926         prep_801
17927
17928         echo "Start barrier_freeze at: $(date)"
17929         #define OBD_FAIL_BARRIER_DELAY          0x2202
17930         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
17931         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
17932
17933         sleep 2
17934         local b_status=$(barrier_stat)
17935         echo "Got barrier status at: $(date)"
17936         [ "$b_status" = "'freezing_p1'" ] ||
17937                 error "(1) unexpected barrier status $b_status"
17938
17939         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
17940         wait
17941         b_status=$(barrier_stat)
17942         [ "$b_status" = "'frozen'" ] ||
17943                 error "(2) unexpected barrier status $b_status"
17944
17945         local expired=$(barrier_expired)
17946         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
17947         sleep $((expired + 3))
17948
17949         b_status=$(barrier_stat)
17950         [ "$b_status" = "'expired'" ] ||
17951                 error "(3) unexpected barrier status $b_status"
17952
17953         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
17954                 error "(4) fail to freeze barrier"
17955
17956         b_status=$(barrier_stat)
17957         [ "$b_status" = "'frozen'" ] ||
17958                 error "(5) unexpected barrier status $b_status"
17959
17960         echo "Start barrier_thaw at: $(date)"
17961         #define OBD_FAIL_BARRIER_DELAY          0x2202
17962         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
17963         do_facet mgs $LCTL barrier_thaw $FSNAME &
17964
17965         sleep 2
17966         b_status=$(barrier_stat)
17967         echo "Got barrier status at: $(date)"
17968         [ "$b_status" = "'thawing'" ] ||
17969                 error "(6) unexpected barrier status $b_status"
17970
17971         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
17972         wait
17973         b_status=$(barrier_stat)
17974         [ "$b_status" = "'thawed'" ] ||
17975                 error "(7) unexpected barrier status $b_status"
17976
17977         #define OBD_FAIL_BARRIER_FAILURE        0x2203
17978         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
17979         do_facet mgs $LCTL barrier_freeze $FSNAME
17980
17981         b_status=$(barrier_stat)
17982         [ "$b_status" = "'failed'" ] ||
17983                 error "(8) unexpected barrier status $b_status"
17984
17985         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
17986         do_facet mgs $LCTL barrier_thaw $FSNAME
17987
17988         post_801
17989 }
17990 run_test 801a "write barrier user interfaces and stat machine"
17991
17992 test_801b() {
17993         prep_801
17994
17995         mkdir $DIR/$tdir || error "(1) fail to mkdir"
17996         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
17997         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
17998         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
17999         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
18000
18001         cancel_lru_locks mdc
18002
18003         # 180 seconds should be long enough
18004         do_facet mgs $LCTL barrier_freeze $FSNAME 180
18005
18006         local b_status=$(barrier_stat)
18007         [ "$b_status" = "'frozen'" ] ||
18008                 error "(6) unexpected barrier status $b_status"
18009
18010         mkdir $DIR/$tdir/d0/d10 &
18011         mkdir_pid=$!
18012
18013         touch $DIR/$tdir/d1/f13 &
18014         touch_pid=$!
18015
18016         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
18017         ln_pid=$!
18018
18019         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
18020         mv_pid=$!
18021
18022         rm -f $DIR/$tdir/d4/f12 &
18023         rm_pid=$!
18024
18025         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
18026
18027         # To guarantee taht the 'stat' is not blocked
18028         b_status=$(barrier_stat)
18029         [ "$b_status" = "'frozen'" ] ||
18030                 error "(8) unexpected barrier status $b_status"
18031
18032         # let above commands to run at background
18033         sleep 5
18034
18035         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
18036         ps -p $touch_pid || error "(10) touch should be blocked"
18037         ps -p $ln_pid || error "(11) link should be blocked"
18038         ps -p $mv_pid || error "(12) rename should be blocked"
18039         ps -p $rm_pid || error "(13) unlink should be blocked"
18040
18041         b_status=$(barrier_stat)
18042         [ "$b_status" = "'frozen'" ] ||
18043                 error "(14) unexpected barrier status $b_status"
18044
18045         do_facet mgs $LCTL barrier_thaw $FSNAME
18046         b_status=$(barrier_stat)
18047         [ "$b_status" = "'thawed'" ] ||
18048                 error "(15) unexpected barrier status $b_status"
18049
18050         wait $mkdir_pid || error "(16) mkdir should succeed"
18051         wait $touch_pid || error "(17) touch should succeed"
18052         wait $ln_pid || error "(18) link should succeed"
18053         wait $mv_pid || error "(19) rename should succeed"
18054         wait $rm_pid || error "(20) unlink should succeed"
18055
18056         post_801
18057 }
18058 run_test 801b "modification will be blocked by write barrier"
18059
18060 test_801c() {
18061         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
18062
18063         prep_801
18064
18065         stop mds2 || error "(1) Fail to stop mds2"
18066
18067         do_facet mgs $LCTL barrier_freeze $FSNAME 30
18068
18069         local b_status=$(barrier_stat)
18070         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
18071                 do_facet mgs $LCTL barrier_thaw $FSNAME
18072                 error "(2) unexpected barrier status $b_status"
18073         }
18074
18075         do_facet mgs $LCTL barrier_rescan $FSNAME ||
18076                 error "(3) Fail to rescan barrier bitmap"
18077
18078         do_facet mgs $LCTL barrier_freeze $FSNAME 10
18079
18080         b_status=$(barrier_stat)
18081         [ "$b_status" = "'frozen'" ] ||
18082                 error "(4) unexpected barrier status $b_status"
18083
18084         do_facet mgs $LCTL barrier_thaw $FSNAME
18085         b_status=$(barrier_stat)
18086         [ "$b_status" = "'thawed'" ] ||
18087                 error "(5) unexpected barrier status $b_status"
18088
18089         local devname=$(mdsdevname 2)
18090
18091         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
18092
18093         do_facet mgs $LCTL barrier_rescan $FSNAME ||
18094                 error "(7) Fail to rescan barrier bitmap"
18095
18096         post_801
18097 }
18098 run_test 801c "rescan barrier bitmap"
18099
18100 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
18101 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
18102 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
18103
18104 cleanup_802() {
18105         trap 0
18106
18107         stopall
18108         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
18109         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
18110         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
18111         setupall
18112 }
18113
18114 test_802() {
18115
18116         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
18117         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
18118                 skip "Need server version at least 2.9.55" & exit 0
18119
18120         mkdir $DIR/$tdir || error "(1) fail to mkdir"
18121
18122         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
18123                 error "(2) Fail to copy"
18124
18125         trap cleanup_802 EXIT
18126
18127         # sync by force before remount as readonly
18128         sync; sync_all_data; sleep 3; sync_all_data
18129
18130         stopall
18131
18132         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
18133         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
18134         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
18135
18136         echo "Mount the server as read only"
18137         setupall server_only || error "(3) Fail to start servers"
18138
18139         echo "Mount client without ro should fail"
18140         mount_client $MOUNT &&
18141                 error "(4) Mount client without 'ro' should fail"
18142
18143         echo "Mount client with ro should succeed"
18144         mount_client $MOUNT ro ||
18145                 error "(5) Mount client with 'ro' should succeed"
18146
18147         echo "Modify should be refused"
18148         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
18149
18150         echo "Read should be allowed"
18151         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
18152                 error "(7) Read should succeed under ro mode"
18153
18154         cleanup_802
18155 }
18156 run_test 802 "simulate readonly device"
18157
18158 test_803() {
18159         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
18160         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.54) ] &&
18161                 skip "MDS needs to be newer than 2.10.54" && return
18162
18163         mkdir -p $DIR/$tdir
18164         # Create some objects on all MDTs to trigger related logs objects
18165         for idx in $(seq $MDSCOUNT); do
18166                 $LFS mkdir -c $MDSCOUNT -i $((idx % $MDSCOUNT)) \
18167                         $DIR/$tdir/dir${idx} ||
18168                         error "Fail to create $DIR/$tdir/dir${idx}"
18169         done
18170
18171         sync; sleep 3
18172         echo "before create:"
18173         $LFS df -i $MOUNT
18174         local before_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18175
18176         for ((i=0; i<10; i++)); do
18177                 $LFS mkdir -c 1 -i 1 $DIR/$tdir/foo$i ||
18178                         error "Fail to create $DIR/$tdir/foo$i"
18179         done
18180
18181         sync; sleep 3
18182         echo "after create:"
18183         $LFS df -i $MOUNT
18184         local after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18185
18186         [ $after_used -ge $((before_used + 10)) ] ||
18187                 error "before ($before_used) + 10 > after ($after_used)"
18188
18189         for ((i=0; i<10; i++)); do
18190                 rm -rf $DIR/$tdir/foo$i ||
18191                         error "Fail to remove $DIR/$tdir/foo$i"
18192         done
18193
18194         sleep 3 # avoid MDT return cached statfs
18195         wait_delete_completed
18196         echo "after unlink:"
18197         $LFS df -i $MOUNT
18198         before_used=$after_used
18199         after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
18200
18201         [ $after_used -le $((before_used - 8)) ] ||
18202                 error "before ($before_used) - 8 < after ($after_used)"
18203 }
18204 run_test 803 "verify agent object for remote object"
18205
18206 test_804() {
18207         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
18208         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.54) ] &&
18209                 skip "MDS needs to be newer than 2.10.54" && return
18210
18211         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
18212                 skip "ldiskfs only test" && return 0
18213
18214         mkdir -p $DIR/$tdir
18215         $LFS mkdir -c 1 -i 1 $DIR/$tdir/dir0 ||
18216                 error "Fail to create $DIR/$tdir/dir0"
18217
18218         local fid=$($LFS path2fid $DIR/$tdir/dir0)
18219         local dev=$(mdsdevname 2)
18220
18221         do_facet mds2 "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18222                 grep ${fid} || error "NOT found agent entry for dir0"
18223
18224         $LFS mkdir -c $MDSCOUNT -i 0 $DIR/$tdir/dir1 ||
18225                 error "Fail to create $DIR/$tdir/dir1"
18226
18227         touch $DIR/$tdir/dir1/foo0 ||
18228                 error "Fail to create $DIR/$tdir/dir1/foo0"
18229         fid=$($LFS path2fid $DIR/$tdir/dir1/foo0)
18230         local rc=0
18231
18232         for idx in $(seq $MDSCOUNT); do
18233                 dev=$(mdsdevname $idx)
18234                 do_facet mds${idx} \
18235                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18236                         grep ${fid} && rc=$idx
18237         done
18238
18239         mv $DIR/$tdir/dir1/foo0 $DIR/$tdir/dir1/foo1 ||
18240                 error "Fail to rename foo0 to foo1"
18241         if [ $rc -eq 0 ]; then
18242                 for idx in $(seq $MDSCOUNT); do
18243                         dev=$(mdsdevname $idx)
18244                         do_facet mds${idx} \
18245                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18246                         grep ${fid} && rc=$idx
18247                 done
18248         fi
18249
18250         mv $DIR/$tdir/dir1/foo1 $DIR/$tdir/dir1/foo2 ||
18251                 error "Fail to rename foo1 to foo2"
18252         if [ $rc -eq 0 ]; then
18253                 for idx in $(seq $MDSCOUNT); do
18254                         dev=$(mdsdevname $idx)
18255                         do_facet mds${idx} \
18256                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
18257                         grep ${fid} && rc=$idx
18258                 done
18259         fi
18260
18261         [ $rc -ne 0 ] || error "NOT found agent entry for foo"
18262
18263         ln $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir0/guard ||
18264                 error "Fail to link to $DIR/$tdir/dir1/foo2"
18265         mv $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir1/foo0 ||
18266                 error "Fail to rename foo2 to foo0"
18267         unlink $DIR/$tdir/dir1/foo0 ||
18268                 error "Fail to unlink $DIR/$tdir/dir1/foo0"
18269         rm -rf $DIR/$tdir/dir0 ||
18270                 error "Fail to rm $DIR/$tdir/dir0"
18271
18272         for idx in $(seq $MDSCOUNT); do
18273                 dev=$(mdsdevname $idx)
18274                 rc=0
18275
18276                 stop mds${idx}
18277                 run_e2fsck $(facet_active_host mds$idx) $dev -n ||
18278                         rc=$?
18279                 start mds${idx} $dev $MDS_MOUNT_OPTS ||
18280                         error "mount mds$idx failed"
18281                 df $MOUNT > /dev/null 2>&1
18282
18283                 # e2fsck should not return error
18284                 [ $rc -eq 0 ] ||
18285                         error "e2fsck detected error on MDT${idx}: rc=$rc"
18286         done
18287 }
18288 run_test 804 "verify agent entry for remote entry"
18289
18290 cleanup_805() {
18291         do_facet $SINGLEMDS zfs set quota=$old $fsset
18292         unlinkmany $DIR/$tdir/f- 1000000
18293         trap 0
18294 }
18295
18296 test_805() {
18297         local zfs_version=$(do_node $SINGLEMDS cat /sys/module/zfs/version)
18298         [ "$(facet_fstype mds1)" != "zfs" ] &&
18299                 skip "ZFS specific test" && return
18300         [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
18301                 skip "netfree not implemented before 0.7" && return
18302         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
18303                 { skip "Need MDS version at least 2.10.57" && return 0; }
18304
18305         local fsset
18306         local freekb
18307         local usedkb
18308         local old
18309         local quota
18310         local pref="osd-zfs.lustre-MDT0000."
18311
18312         # limit available space on MDS dataset to meet nospace issue
18313         # quickly. then ZFS 0.7.2 can use reserved space if asked
18314         # properly (using netfree flag in osd_declare_destroy()
18315         fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
18316         old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
18317                 gawk '{print $3}')
18318         freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
18319         usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
18320         let "usedkb=usedkb-freekb"
18321         let "freekb=freekb/2"
18322         if let "freekb > 5000"; then
18323                 let "freekb=5000"
18324         fi
18325         do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
18326         trap cleanup_805 EXIT
18327         mkdir $DIR/$tdir
18328         $LFS setstripe -E 1M -L mdt $DIR/$tdir || error "DoM not working"
18329         createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
18330         rm -rf $DIR/$tdir || error "not able to remove"
18331         do_facet $SINGLEMDS zfs set quota=$old $fsset
18332         trap 0
18333 }
18334 run_test 805 "ZFS can remove from full fs"
18335
18336 #
18337 # tests that do cleanup/setup should be run at the end
18338 #
18339
18340 test_900() {
18341         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
18342         local ls
18343         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
18344         $LCTL set_param fail_loc=0x903
18345
18346         cancel_lru_locks MGC
18347
18348         FAIL_ON_ERROR=true cleanup
18349         FAIL_ON_ERROR=true setup
18350 }
18351 run_test 900 "umount should not race with any mgc requeue thread"
18352
18353 complete $SECONDS
18354 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
18355 check_and_cleanup_lustre
18356 if [ "$I_MOUNTED" != "yes" ]; then
18357         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
18358 fi
18359 exit_status