Whamcloud - gitweb
LU-13138 tests: measure 'dd' time more accurately
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 # Check Grants after these tests
12 GRANT_CHECK_LIST="$GRANT_CHECK_LIST 42a 42b 42c 42d 42e 63a 63b 64a 64b 64c 64d"
13
14 OSC=${OSC:-"osc"}
15
16 CC=${CC:-cc}
17 CREATETEST=${CREATETEST:-createtest}
18 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
19 OPENFILE=${OPENFILE:-openfile}
20 OPENUNLINK=${OPENUNLINK:-openunlink}
21 READS=${READS:-"reads"}
22 MUNLINK=${MUNLINK:-munlink}
23 SOCKETSERVER=${SOCKETSERVER:-socketserver}
24 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
25 MEMHOG=${MEMHOG:-memhog}
26 DIRECTIO=${DIRECTIO:-directio}
27 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
28 DEF_STRIPE_COUNT=-1
29 CHECK_GRANT=${CHECK_GRANT:-"yes"}
30 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
31 export PARALLEL=${PARALLEL:-"no"}
32
33 TRACE=${TRACE:-""}
34 LUSTRE=${LUSTRE:-$(dirname $0)/..}
35 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
36 . $LUSTRE/tests/test-framework.sh
37 init_test_env $@
38
39 init_logging
40
41 ALWAYS_EXCEPT="$SANITY_EXCEPT "
42 # bug number for skipped test: LU-9693 LU-6493 LU-9693
43 ALWAYS_EXCEPT+="               42a     42b     42c "
44 # bug number:    LU-8411 LU-9054 LU-13314
45 ALWAYS_EXCEPT+=" 407     312    56ob"
46
47 if $SHARED_KEY; then
48         # bug number:    LU-9795 LU-9795 LU-9795 LU-9795
49         ALWAYS_EXCEPT+=" 17n     60a     133g    300f"
50 fi
51
52 selinux_status=$(getenforce)
53 if [ "$selinux_status" != "Disabled" ]; then
54         # bug number:
55         ALWAYS_EXCEPT+=""
56 fi
57
58 # skip the grant tests for ARM until they are fixed
59 if [[ $(uname -m) = aarch64 ]]; then
60         # bug number:    LU-11596
61         ALWAYS_EXCEPT+=" $GRANT_CHECK_LIST"
62         # bug number:    LU-11671 LU-11667
63         ALWAYS_EXCEPT+=" 45       317"
64 fi
65
66 # skip nfs tests on kernels >= 4.14.0 until they are fixed
67 if [ $LINUX_VERSION_CODE -ge $(version_code 4.14.0) ]; then
68         # bug number:   LU-12661
69         ALWAYS_EXCEPT+=" 817"
70 fi
71 # skip cgroup tests on RHEL8.1 kernels until they are fixed
72 if (( $LINUX_VERSION_CODE >= $(version_code 4.18.0) &&
73       $LINUX_VERSION_CODE <  $(version_code 5.4.0) )); then
74         # bug number:   LU-13063
75         ALWAYS_EXCEPT+=" 411"
76 fi
77
78 #                                  5          12     8   12  (min)"
79 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 135 136 300o"
80
81 if [ "$mds1_FSTYPE" = "zfs" ]; then
82         # bug number for skipped test:
83         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  "
84         #                                               13    (min)"
85         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
86 fi
87
88 # Get the SLES distro version
89 #
90 # Returns a version string that should only be used in comparing
91 # strings returned by version_code()
92 sles_version_code()
93 {
94         local version=$(grep VERSION_ID /etc/os-release | cut -d'"' -f2)
95
96         # All SuSE Linux versions have one decimal. version_code expects two
97         local sles_version=$version.0
98         version_code $sles_version
99 }
100
101 # Check if we are running on Ubuntu or SLES so we can make decisions on
102 # what tests to run
103 if [ -r /etc/SuSE-release ]; then
104         sles_version=$(sles_version_code)
105         [ $sles_version -lt $(version_code 11.4.0) ] &&
106                 # bug number for skipped test: LU-4341
107                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT  170"
108         [ $sles_version -lt $(version_code 12.0.0) ] &&
109                 # bug number for skipped test: LU-3703
110                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT  234"
111 elif [ -r /etc/os-release ]; then
112         if grep -qi ubuntu /etc/os-release; then
113                 ubuntu_version=$(version_code $(sed -n -e 's/"//g' \
114                                                 -e 's/^VERSION=//p' \
115                                                 /etc/os-release |
116                                                 awk '{ print $1 }'))
117
118                 if [[ $ubuntu_version -gt $(version_code 16.0.0) ]]; then
119                         # bug number for skipped test:
120                         #                LU-10334 LU-10366
121                         ALWAYS_EXCEPT+=" 103a     410"
122                 fi
123         fi
124 fi
125
126 build_test_filter
127 FAIL_ON_ERROR=false
128
129 cleanup() {
130         echo -n "cln.."
131         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
132         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
133 }
134 setup() {
135         echo -n "mnt.."
136         load_modules
137         setupall || exit 10
138         echo "done"
139 }
140
141 check_swap_layouts_support()
142 {
143         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
144                 skip "Does not support layout lock."
145 }
146
147 check_and_setup_lustre
148 DIR=${DIR:-$MOUNT}
149 assert_DIR
150
151 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
152
153 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
154 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
155 rm -rf $DIR/[Rdfs][0-9]*
156
157 # $RUNAS_ID may get set incorrectly somewhere else
158 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
159         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
160
161 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
162
163 if [ "${ONLY}" = "MOUNT" ] ; then
164         echo "Lustre is up, please go on"
165         exit
166 fi
167
168 echo "preparing for tests involving mounts"
169 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
170 touch $EXT2_DEV
171 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
172 echo # add a newline after mke2fs.
173
174 umask 077
175
176 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
177 lctl set_param debug=-1 2> /dev/null || true
178 test_0a() {
179         touch $DIR/$tfile
180         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
181         rm $DIR/$tfile
182         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
183 }
184 run_test 0a "touch; rm ====================="
185
186 test_0b() {
187         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
188         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
189 }
190 run_test 0b "chmod 0755 $DIR ============================="
191
192 test_0c() {
193         $LCTL get_param mdc.*.import | grep "state: FULL" ||
194                 error "import not FULL"
195         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
196                 error "bad target"
197 }
198 run_test 0c "check import proc"
199
200 test_0d() { # LU-3397
201         [ $MGS_VERSION -lt $(version_code 2.10.57) ] &&
202                 skip "proc exports not supported before 2.10.57"
203
204         local mgs_exp="mgs.MGS.exports"
205         local client_uuid=$($LCTL get_param -n mgc.*.uuid)
206         local exp_client_nid
207         local exp_client_version
208         local exp_val
209         local imp_val
210         local temp_imp=$DIR/$tfile.import
211         local temp_exp=$DIR/$tfile.export
212
213         # save mgc import file to $temp_imp
214         $LCTL get_param mgc.*.import | tee $temp_imp
215         # Check if client uuid is found in MGS export
216         for exp_client_nid in $(do_facet mgs $LCTL get_param -N $mgs_exp.*); do
217                 [ $(do_facet mgs $LCTL get_param -n $exp_client_nid.uuid) == \
218                         $client_uuid ] &&
219                         break;
220         done
221         # save mgs export file to $temp_exp
222         do_facet mgs $LCTL get_param $exp_client_nid.export | tee $temp_exp
223
224         # Compare the value of field "connect_flags"
225         imp_val=$(grep "connect_flags" $temp_imp)
226         exp_val=$(grep "connect_flags" $temp_exp)
227         [ "$exp_val" == "$imp_val" ] ||
228                 error "export flags '$exp_val' != import flags '$imp_val'"
229
230         # Compare the value of client version
231         exp_client_version=$(awk '/target_version:/ { print $2 }' $temp_exp)
232         exp_val=$(version_code $exp_client_version)
233         imp_val=$CLIENT_VERSION
234         [ "$exp_val" == "$imp_val" ] ||
235                 error "export client version '$exp_val' != '$imp_val'"
236 }
237 run_test 0d "check export proc ============================="
238
239 test_1() {
240         test_mkdir $DIR/$tdir
241         test_mkdir $DIR/$tdir/d2
242         mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
243         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
244         rmdir $DIR/$tdir/d2
245         rmdir $DIR/$tdir
246         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
247 }
248 run_test 1 "mkdir; remkdir; rmdir"
249
250 test_2() {
251         test_mkdir $DIR/$tdir
252         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
253         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
254         rm -r $DIR/$tdir
255         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
256 }
257 run_test 2 "mkdir; touch; rmdir; check file"
258
259 test_3() {
260         test_mkdir $DIR/$tdir
261         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
262         touch $DIR/$tdir/$tfile
263         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
264         rm -r $DIR/$tdir
265         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
266 }
267 run_test 3 "mkdir; touch; rmdir; check dir"
268
269 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
270 test_4() {
271         test_mkdir -i 1 $DIR/$tdir
272
273         touch $DIR/$tdir/$tfile ||
274                 error "Create file under remote directory failed"
275
276         rmdir $DIR/$tdir &&
277                 error "Expect error removing in-use dir $DIR/$tdir"
278
279         test -d $DIR/$tdir || error "Remote directory disappeared"
280
281         rm -rf $DIR/$tdir || error "remove remote dir error"
282 }
283 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
284
285 test_5() {
286         test_mkdir $DIR/$tdir
287         test_mkdir $DIR/$tdir/d2
288         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
289         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
290         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
291 }
292 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2"
293
294 test_6a() {
295         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
296         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
297         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
298                 error "$tfile does not have perm 0666 or UID $UID"
299         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
300         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
301                 error "$tfile should be 0666 and owned by UID $UID"
302 }
303 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
304
305 test_6c() {
306         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
307
308         touch $DIR/$tfile
309         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
310         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
311                 error "$tfile should be owned by UID $RUNAS_ID"
312         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
313         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
314                 error "$tfile should be owned by UID $RUNAS_ID"
315 }
316 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
317
318 test_6e() {
319         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
320
321         touch $DIR/$tfile
322         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
323         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
324                 error "$tfile should be owned by GID $UID"
325         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
326         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
327                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
328 }
329 run_test 6e "touch+chgrp $tfile; $RUNAS chgrp $tfile (should return error)"
330
331 test_6g() {
332         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
333
334         test_mkdir $DIR/$tdir
335         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
336         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
337         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
338         test_mkdir $DIR/$tdir/d/subdir
339         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
340                 error "$tdir/d/subdir should be GID $RUNAS_GID"
341         if [[ $MDSCOUNT -gt 1 ]]; then
342                 # check remote dir sgid inherite
343                 $LFS mkdir -i 0 $DIR/$tdir.local ||
344                         error "mkdir $tdir.local failed"
345                 chmod g+s $DIR/$tdir.local ||
346                         error "chmod $tdir.local failed"
347                 chgrp $RUNAS_GID $DIR/$tdir.local ||
348                         error "chgrp $tdir.local failed"
349                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
350                         error "mkdir $tdir.remote failed"
351                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
352                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
353                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
354                         error "$tdir.remote should be mode 02755"
355         fi
356 }
357 run_test 6g "verify new dir in sgid dir inherits group"
358
359 test_6h() { # bug 7331
360         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
361
362         touch $DIR/$tfile || error "touch failed"
363         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
364         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
365                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
366         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
367                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
368 }
369 run_test 6h "$RUNAS chown RUNAS_ID.0 .../$tfile (should return error)"
370
371 test_7a() {
372         test_mkdir $DIR/$tdir
373         $MCREATE $DIR/$tdir/$tfile
374         chmod 0666 $DIR/$tdir/$tfile
375         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
376                 error "$tdir/$tfile should be mode 0666"
377 }
378 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
379
380 test_7b() {
381         if [ ! -d $DIR/$tdir ]; then
382                 test_mkdir $DIR/$tdir
383         fi
384         $MCREATE $DIR/$tdir/$tfile
385         echo -n foo > $DIR/$tdir/$tfile
386         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
387         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
388 }
389 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
390
391 test_8() {
392         test_mkdir $DIR/$tdir
393         touch $DIR/$tdir/$tfile
394         chmod 0666 $DIR/$tdir/$tfile
395         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
396                 error "$tfile mode not 0666"
397 }
398 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
399
400 test_9() {
401         test_mkdir $DIR/$tdir
402         test_mkdir $DIR/$tdir/d2
403         test_mkdir $DIR/$tdir/d2/d3
404         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
405 }
406 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
407
408 test_10() {
409         test_mkdir $DIR/$tdir
410         test_mkdir $DIR/$tdir/d2
411         touch $DIR/$tdir/d2/$tfile
412         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
413                 error "$tdir/d2/$tfile not a file"
414 }
415 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
416
417 test_11() {
418         test_mkdir $DIR/$tdir
419         test_mkdir $DIR/$tdir/d2
420         chmod 0666 $DIR/$tdir/d2
421         chmod 0705 $DIR/$tdir/d2
422         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
423                 error "$tdir/d2 mode not 0705"
424 }
425 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
426
427 test_12() {
428         test_mkdir $DIR/$tdir
429         touch $DIR/$tdir/$tfile
430         chmod 0666 $DIR/$tdir/$tfile
431         chmod 0654 $DIR/$tdir/$tfile
432         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
433                 error "$tdir/d2 mode not 0654"
434 }
435 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
436
437 test_13() {
438         test_mkdir $DIR/$tdir
439         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
440         >  $DIR/$tdir/$tfile
441         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
442                 error "$tdir/$tfile size not 0 after truncate"
443 }
444 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
445
446 test_14() {
447         test_mkdir $DIR/$tdir
448         touch $DIR/$tdir/$tfile
449         rm $DIR/$tdir/$tfile
450         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
451 }
452 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
453
454 test_15() {
455         test_mkdir $DIR/$tdir
456         touch $DIR/$tdir/$tfile
457         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
458         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
459                 error "$tdir/${tfile_2} not a file after rename"
460         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
461 }
462 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
463
464 test_16() {
465         test_mkdir $DIR/$tdir
466         touch $DIR/$tdir/$tfile
467         rm -rf $DIR/$tdir/$tfile
468         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
469 }
470 run_test 16 "touch .../d16/f; rm -rf .../d16/f"
471
472 test_17a() {
473         test_mkdir $DIR/$tdir
474         touch $DIR/$tdir/$tfile
475         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
476         ls -l $DIR/$tdir
477         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
478                 error "$tdir/l-exist not a symlink"
479         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
480                 error "$tdir/l-exist not referencing a file"
481         rm -f $DIR/$tdir/l-exist
482         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
483 }
484 run_test 17a "symlinks: create, remove (real)"
485
486 test_17b() {
487         test_mkdir $DIR/$tdir
488         ln -s no-such-file $DIR/$tdir/l-dangle
489         ls -l $DIR/$tdir
490         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
491                 error "$tdir/l-dangle not referencing no-such-file"
492         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
493                 error "$tdir/l-dangle not referencing non-existent file"
494         rm -f $DIR/$tdir/l-dangle
495         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
496 }
497 run_test 17b "symlinks: create, remove (dangling)"
498
499 test_17c() { # bug 3440 - don't save failed open RPC for replay
500         test_mkdir $DIR/$tdir
501         ln -s foo $DIR/$tdir/$tfile
502         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
503 }
504 run_test 17c "symlinks: open dangling (should return error)"
505
506 test_17d() {
507         test_mkdir $DIR/$tdir
508         ln -s foo $DIR/$tdir/$tfile
509         touch $DIR/$tdir/$tfile || error "creating to new symlink"
510 }
511 run_test 17d "symlinks: create dangling"
512
513 test_17e() {
514         test_mkdir $DIR/$tdir
515         local foo=$DIR/$tdir/$tfile
516         ln -s $foo $foo || error "create symlink failed"
517         ls -l $foo || error "ls -l failed"
518         ls $foo && error "ls not failed" || true
519 }
520 run_test 17e "symlinks: create recursive symlink (should return error)"
521
522 test_17f() {
523         test_mkdir $DIR/$tdir
524         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
525         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
526         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
527         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
528         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
529         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
530         ls -l  $DIR/$tdir
531 }
532 run_test 17f "symlinks: long and very long symlink name"
533
534 # str_repeat(S, N) generate a string that is string S repeated N times
535 str_repeat() {
536         local s=$1
537         local n=$2
538         local ret=''
539         while [ $((n -= 1)) -ge 0 ]; do
540                 ret=$ret$s
541         done
542         echo $ret
543 }
544
545 # Long symlinks and LU-2241
546 test_17g() {
547         test_mkdir $DIR/$tdir
548         local TESTS="59 60 61 4094 4095"
549
550         # Fix for inode size boundary in 2.1.4
551         [ $MDS1_VERSION -lt $(version_code 2.1.4) ] &&
552                 TESTS="4094 4095"
553
554         # Patch not applied to 2.2 or 2.3 branches
555         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] &&
556         [ $MDS1_VERSION -le $(version_code 2.3.55) ] &&
557                 TESTS="4094 4095"
558
559         for i in $TESTS; do
560                 local SYMNAME=$(str_repeat 'x' $i)
561                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
562                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
563         done
564 }
565 run_test 17g "symlinks: really long symlink name and inode boundaries"
566
567 test_17h() { #bug 17378
568         [ $PARALLEL == "yes" ] && skip "skip parallel run"
569         remote_mds_nodsh && skip "remote MDS with nodsh"
570
571         local mdt_idx
572
573         test_mkdir $DIR/$tdir
574         mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
575         $LFS setstripe -c -1 $DIR/$tdir
576         #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
577         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
578         touch $DIR/$tdir/$tfile || true
579 }
580 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
581
582 test_17i() { #bug 20018
583         [ $PARALLEL == "yes" ] && skip "skip parallel run"
584         remote_mds_nodsh && skip "remote MDS with nodsh"
585
586         local foo=$DIR/$tdir/$tfile
587         local mdt_idx
588
589         test_mkdir -c1 $DIR/$tdir
590         mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
591         ln -s $foo $foo || error "create symlink failed"
592 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
593         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
594         ls -l $foo && error "error not detected"
595         return 0
596 }
597 run_test 17i "don't panic on short symlink (should return error)"
598
599 test_17k() { #bug 22301
600         [ $PARALLEL == "yes" ] && skip "skip parallel run"
601         [[ -z "$(which rsync 2>/dev/null)" ]] &&
602                 skip "no rsync command"
603         rsync --help | grep -q xattr ||
604                 skip_env "$(rsync --version | head -n1) does not support xattrs"
605         test_mkdir $DIR/$tdir
606         test_mkdir $DIR/$tdir.new
607         touch $DIR/$tdir/$tfile
608         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
609         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
610                 error "rsync failed with xattrs enabled"
611 }
612 run_test 17k "symlinks: rsync with xattrs enabled"
613
614 test_17l() { # LU-279
615         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
616                 skip "no getfattr command"
617
618         test_mkdir $DIR/$tdir
619         touch $DIR/$tdir/$tfile
620         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
621         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
622                 # -h to not follow symlinks. -m '' to list all the xattrs.
623                 # grep to remove first line: '# file: $path'.
624                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
625                 do
626                         lgetxattr_size_check $path $xattr ||
627                                 error "lgetxattr_size_check $path $xattr failed"
628                 done
629         done
630 }
631 run_test 17l "Ensure lgetxattr's returned xattr size is consistent"
632
633 # LU-1540
634 test_17m() {
635         [ $PARALLEL == "yes" ] && skip "skip parallel run"
636         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
637         remote_mds_nodsh && skip "remote MDS with nodsh"
638         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] &&
639         [ $MDS1_VERSION -le $(version_code 2.2.93) ] &&
640                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks"
641
642         local short_sym="0123456789"
643         local wdir=$DIR/$tdir
644         local i
645
646         test_mkdir $wdir
647         long_sym=$short_sym
648         # create a long symlink file
649         for ((i = 0; i < 4; ++i)); do
650                 long_sym=${long_sym}${long_sym}
651         done
652
653         echo "create 512 short and long symlink files under $wdir"
654         for ((i = 0; i < 256; ++i)); do
655                 ln -sf ${long_sym}"a5a5" $wdir/long-$i
656                 ln -sf ${short_sym}"a5a5" $wdir/short-$i
657         done
658
659         echo "erase them"
660         rm -f $wdir/*
661         sync
662         wait_delete_completed
663
664         echo "recreate the 512 symlink files with a shorter string"
665         for ((i = 0; i < 512; ++i)); do
666                 # rewrite the symlink file with a shorter string
667                 ln -sf ${long_sym} $wdir/long-$i || error "long_sym failed"
668                 ln -sf ${short_sym} $wdir/short-$i || error "short_sym failed"
669         done
670
671         local mds_index=$(($($LFS getstripe -m $wdir) + 1))
672         local devname=$(mdsdevname $mds_index)
673
674         echo "stop and checking mds${mds_index}:"
675         # e2fsck should not return error
676         stop mds${mds_index}
677         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
678         rc=$?
679
680         start mds${mds_index} $devname $MDS_MOUNT_OPTS ||
681                 error "start mds${mds_index} failed"
682         df $MOUNT > /dev/null 2>&1
683         [ $rc -eq 0 ] ||
684                 error "e2fsck detected error for short/long symlink: rc=$rc"
685         rm -f $wdir/*
686 }
687 run_test 17m "run e2fsck against MDT which contains short/long symlink"
688
689 check_fs_consistency_17n() {
690         local mdt_index
691         local rc=0
692
693         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
694         # so it only check MDT1/MDT2 instead of all of MDTs.
695         for mdt_index in 1 2; do
696                 local devname=$(mdsdevname $mdt_index)
697                 # e2fsck should not return error
698                 stop mds${mdt_index}
699                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
700                         rc=$((rc + $?))
701
702                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
703                         error "mount mds$mdt_index failed"
704                 df $MOUNT > /dev/null 2>&1
705         done
706         return $rc
707 }
708
709 test_17n() {
710         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
711         [ $PARALLEL == "yes" ] && skip "skip parallel run"
712         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
713         remote_mds_nodsh && skip "remote MDS with nodsh"
714         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] &&
715         [ $MDS1_VERSION -le $(version_code 2.2.93) ] &&
716                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks"
717
718         local i
719
720         test_mkdir $DIR/$tdir
721         for ((i=0; i<10; i++)); do
722                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
723                         error "create remote dir error $i"
724                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
725                         error "create files under remote dir failed $i"
726         done
727
728         check_fs_consistency_17n ||
729                 error "e2fsck report error after create files under remote dir"
730
731         for ((i = 0; i < 10; i++)); do
732                 rm -rf $DIR/$tdir/remote_dir_${i} ||
733                         error "destroy remote dir error $i"
734         done
735
736         check_fs_consistency_17n ||
737                 error "e2fsck report error after unlink files under remote dir"
738
739         [ $MDS1_VERSION -lt $(version_code 2.4.50) ] &&
740                 skip "lustre < 2.4.50 does not support migrate mv"
741
742         for ((i = 0; i < 10; i++)); do
743                 mkdir -p $DIR/$tdir/remote_dir_${i}
744                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
745                         error "create files under remote dir failed $i"
746                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
747                         error "migrate remote dir error $i"
748         done
749         check_fs_consistency_17n || error "e2fsck report error after migration"
750
751         for ((i = 0; i < 10; i++)); do
752                 rm -rf $DIR/$tdir/remote_dir_${i} ||
753                         error "destroy remote dir error $i"
754         done
755
756         check_fs_consistency_17n || error "e2fsck report error after unlink"
757 }
758 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
759
760 test_17o() {
761         remote_mds_nodsh && skip "remote MDS with nodsh"
762         [ $MDS1_VERSION -lt $(version_code 2.3.64) ] &&
763                 skip "Need MDS version at least 2.3.64"
764
765         local wdir=$DIR/${tdir}o
766         local mdt_index
767         local rc=0
768
769         test_mkdir $wdir
770         touch $wdir/$tfile
771         mdt_index=$($LFS getstripe -m $wdir/$tfile)
772         mdt_index=$((mdt_index + 1))
773
774         cancel_lru_locks mdc
775         #fail mds will wait the failover finish then set
776         #following fail_loc to avoid interfer the recovery process.
777         fail mds${mdt_index}
778
779         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
780         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
781         ls -l $wdir/$tfile && rc=1
782         do_facet mds${mdt_index} lctl set_param fail_loc=0
783         [[ $rc -eq 0 ]] || error "stat file should fail"
784 }
785 run_test 17o "stat file with incompat LMA feature"
786
787 test_18() {
788         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
789         ls $DIR || error "Failed to ls $DIR: $?"
790 }
791 run_test 18 "touch .../f ; ls ... =============================="
792
793 test_19a() {
794         touch $DIR/$tfile
795         ls -l $DIR
796         rm $DIR/$tfile
797         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
798 }
799 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
800
801 test_19b() {
802         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
803 }
804 run_test 19b "ls -l .../f19 (should return error) =============="
805
806 test_19c() {
807         [ $RUNAS_ID -eq $UID ] &&
808                 skip_env "RUNAS_ID = UID = $UID -- skipping"
809
810         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
811 }
812 run_test 19c "$RUNAS touch .../f19 (should return error) =="
813
814 test_19d() {
815         cat $DIR/f19 && error || true
816 }
817 run_test 19d "cat .../f19 (should return error) =============="
818
819 test_20() {
820         touch $DIR/$tfile
821         rm $DIR/$tfile
822         touch $DIR/$tfile
823         rm $DIR/$tfile
824         touch $DIR/$tfile
825         rm $DIR/$tfile
826         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
827 }
828 run_test 20 "touch .../f ; ls -l ..."
829
830 test_21() {
831         test_mkdir $DIR/$tdir
832         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
833         ln -s dangle $DIR/$tdir/link
834         echo foo >> $DIR/$tdir/link
835         cat $DIR/$tdir/dangle
836         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
837         $CHECKSTAT -f -t file $DIR/$tdir/link ||
838                 error "$tdir/link not linked to a file"
839 }
840 run_test 21 "write to dangling link"
841
842 test_22() {
843         local wdir=$DIR/$tdir
844         test_mkdir $wdir
845         chown $RUNAS_ID:$RUNAS_GID $wdir
846         (cd $wdir || error "cd $wdir failed";
847                 $RUNAS tar cf - /etc/hosts /etc/sysconfig/network |
848                 $RUNAS tar xf -)
849         ls -lR $wdir/etc || error "ls -lR $wdir/etc failed"
850         $CHECKSTAT -t dir $wdir/etc || error "checkstat -t dir failed"
851         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $wdir/etc ||
852                 error "checkstat -u failed"
853 }
854 run_test 22 "unpack tar archive as non-root user"
855
856 # was test_23
857 test_23a() {
858         test_mkdir $DIR/$tdir
859         local file=$DIR/$tdir/$tfile
860
861         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
862         openfile -f O_CREAT:O_EXCL $file &&
863                 error "$file recreate succeeded" || true
864 }
865 run_test 23a "O_CREAT|O_EXCL in subdir"
866
867 test_23b() { # bug 18988
868         test_mkdir $DIR/$tdir
869         local file=$DIR/$tdir/$tfile
870
871         rm -f $file
872         echo foo > $file || error "write filed"
873         echo bar >> $file || error "append filed"
874         $CHECKSTAT -s 8 $file || error "wrong size"
875         rm $file
876 }
877 run_test 23b "O_APPEND check"
878
879 # LU-9409, size with O_APPEND and tiny writes
880 test_23c() {
881         local file=$DIR/$tfile
882
883         # single dd
884         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800
885         $CHECKSTAT -s 6400 $file || error "wrong size, expected 6400"
886         rm -f $file
887
888         # racing tiny writes
889         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
890         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
891         wait
892         $CHECKSTAT -s 12800 $file || error "wrong size, expected 12800"
893         rm -f $file
894
895         #racing tiny & normal writes
896         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4096 count=4 &
897         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=100 &
898         wait
899         $CHECKSTAT -s 17184 $file || error "wrong size, expected 17184"
900         rm -f $file
901
902         #racing tiny & normal writes 2, ugly numbers
903         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4099 count=11 &
904         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=17 count=173 &
905         wait
906         $CHECKSTAT -s 48030 $file || error "wrong size, expected 48030"
907         rm -f $file
908 }
909 run_test 23c "O_APPEND size checks for tiny writes"
910
911 # LU-11069 file offset is correct after appending writes
912 test_23d() {
913         local file=$DIR/$tfile
914         local offset
915
916         echo CentaurHauls > $file
917         offset=$($MULTIOP $file oO_WRONLY:O_APPEND:w13Zp)
918         if ((offset != 26)); then
919                 error "wrong offset, expected 26, got '$offset'"
920         fi
921 }
922 run_test 23d "file offset is correct after appending writes"
923
924 # rename sanity
925 test_24a() {
926         echo '-- same directory rename'
927         test_mkdir $DIR/$tdir
928         touch $DIR/$tdir/$tfile.1
929         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
930         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
931 }
932 run_test 24a "rename file to non-existent target"
933
934 test_24b() {
935         test_mkdir $DIR/$tdir
936         touch $DIR/$tdir/$tfile.{1,2}
937         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
938         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
939         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
940 }
941 run_test 24b "rename file to existing target"
942
943 test_24c() {
944         test_mkdir $DIR/$tdir
945         test_mkdir $DIR/$tdir/d$testnum.1
946         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
947         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
948         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
949 }
950 run_test 24c "rename directory to non-existent target"
951
952 test_24d() {
953         test_mkdir -c1 $DIR/$tdir
954         test_mkdir -c1 $DIR/$tdir/d$testnum.1
955         test_mkdir -c1 $DIR/$tdir/d$testnum.2
956         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
957         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
958         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
959 }
960 run_test 24d "rename directory to existing target"
961
962 test_24e() {
963         echo '-- cross directory renames --'
964         test_mkdir $DIR/R5a
965         test_mkdir $DIR/R5b
966         touch $DIR/R5a/f
967         mv $DIR/R5a/f $DIR/R5b/g
968         $CHECKSTAT -a $DIR/R5a/f || error "$DIR/R5a/f exists"
969         $CHECKSTAT -t file $DIR/R5b/g || error "$DIR/R5b/g not file type"
970 }
971 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
972
973 test_24f() {
974         test_mkdir $DIR/R6a
975         test_mkdir $DIR/R6b
976         touch $DIR/R6a/f $DIR/R6b/g
977         mv $DIR/R6a/f $DIR/R6b/g
978         $CHECKSTAT -a $DIR/R6a/f || error "$DIR/R6a/f exists"
979         $CHECKSTAT -t file $DIR/R6b/g || error "$DIR/R6b/g not file type"
980 }
981 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
982
983 test_24g() {
984         test_mkdir $DIR/R7a
985         test_mkdir $DIR/R7b
986         test_mkdir $DIR/R7a/d
987         mv $DIR/R7a/d $DIR/R7b/e
988         $CHECKSTAT -a $DIR/R7a/d || error "$DIR/R7a/d exists"
989         $CHECKSTAT -t dir $DIR/R7b/e || error "$DIR/R7b/e not dir type"
990 }
991 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
992
993 test_24h() {
994         test_mkdir -c1 $DIR/R8a
995         test_mkdir -c1 $DIR/R8b
996         test_mkdir -c1 $DIR/R8a/d
997         test_mkdir -c1 $DIR/R8b/e
998         mrename $DIR/R8a/d $DIR/R8b/e
999         $CHECKSTAT -a $DIR/R8a/d || error "$DIR/R8a/d exists"
1000         $CHECKSTAT -t dir $DIR/R8b/e || error "$DIR/R8b/e not dir type"
1001 }
1002 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
1003
1004 test_24i() {
1005         echo "-- rename error cases"
1006         test_mkdir $DIR/R9
1007         test_mkdir $DIR/R9/a
1008         touch $DIR/R9/f
1009         mrename $DIR/R9/f $DIR/R9/a
1010         $CHECKSTAT -t file $DIR/R9/f || error "$DIR/R9/f not file type"
1011         $CHECKSTAT -t dir  $DIR/R9/a || error "$DIR/R9/a not dir type"
1012         $CHECKSTAT -a $DIR/R9/a/f || error "$DIR/R9/a/f exists"
1013 }
1014 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
1015
1016 test_24j() {
1017         test_mkdir $DIR/R10
1018         mrename $DIR/R10/f $DIR/R10/g
1019         $CHECKSTAT -t dir $DIR/R10 || error "$DIR/R10 not dir type"
1020         $CHECKSTAT -a $DIR/R10/f || error "$DIR/R10/f exists"
1021         $CHECKSTAT -a $DIR/R10/g || error "$DIR/R10/g exists"
1022 }
1023 run_test 24j "source does not exist ============================"
1024
1025 test_24k() {
1026         test_mkdir $DIR/R11a
1027         test_mkdir $DIR/R11a/d
1028         touch $DIR/R11a/f
1029         mv $DIR/R11a/f $DIR/R11a/d
1030         $CHECKSTAT -a $DIR/R11a/f || error "$DIR/R11a/f exists"
1031         $CHECKSTAT -t file $DIR/R11a/d/f || error "$DIR/R11a/d/f not file type"
1032 }
1033 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
1034
1035 # bug 2429 - rename foo foo foo creates invalid file
1036 test_24l() {
1037         f="$DIR/f24l"
1038         $MULTIOP $f OcNs || error "rename of ${f} to itself failed"
1039 }
1040 run_test 24l "Renaming a file to itself ========================"
1041
1042 test_24m() {
1043         f="$DIR/f24m"
1044         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
1045         # on ext3 this does not remove either the source or target files
1046         # though the "expected" operation would be to remove the source
1047         $CHECKSTAT -t file ${f} || error "${f} missing"
1048         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
1049 }
1050 run_test 24m "Renaming a file to a hard link to itself ========="
1051
1052 test_24n() {
1053     f="$DIR/f24n"
1054     # this stats the old file after it was renamed, so it should fail
1055     touch ${f}
1056     $CHECKSTAT ${f} || error "${f} missing"
1057     mv ${f} ${f}.rename
1058     $CHECKSTAT ${f}.rename || error "${f}.rename missing"
1059     $CHECKSTAT -a ${f} || error "${f} exists"
1060 }
1061 run_test 24n "Statting the old file after renaming (Posix rename 2)"
1062
1063 test_24o() {
1064         test_mkdir $DIR/$tdir
1065         rename_many -s random -v -n 10 $DIR/$tdir
1066 }
1067 run_test 24o "rename of files during htree split"
1068
1069 test_24p() {
1070         test_mkdir $DIR/R12a
1071         test_mkdir $DIR/R12b
1072         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
1073         mrename $DIR/R12a $DIR/R12b
1074         $CHECKSTAT -a $DIR/R12a || error "$DIR/R12a exists"
1075         $CHECKSTAT -t dir $DIR/R12b || error "$DIR/R12b not dir type"
1076         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
1077         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
1078 }
1079 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
1080
1081 cleanup_multiop_pause() {
1082         trap 0
1083         kill -USR1 $MULTIPID
1084 }
1085
1086 test_24q() {
1087         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1088
1089         test_mkdir $DIR/R13a
1090         test_mkdir $DIR/R13b
1091         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
1092         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
1093         MULTIPID=$!
1094
1095         trap cleanup_multiop_pause EXIT
1096         mrename $DIR/R13a $DIR/R13b
1097         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1098         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1099         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1100         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1101         cleanup_multiop_pause
1102         wait $MULTIPID || error "multiop close failed"
1103 }
1104 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1105
1106 test_24r() { #bug 3789
1107         test_mkdir $DIR/R14a
1108         test_mkdir $DIR/R14a/b
1109         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1110         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1111         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1112 }
1113 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1114
1115 test_24s() {
1116         test_mkdir $DIR/R15a
1117         test_mkdir $DIR/R15a/b
1118         test_mkdir $DIR/R15a/b/c
1119         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1120         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1121         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1122 }
1123 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1124 test_24t() {
1125         test_mkdir $DIR/R16a
1126         test_mkdir $DIR/R16a/b
1127         test_mkdir $DIR/R16a/b/c
1128         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1129         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1130         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1131 }
1132 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1133
1134 test_24u() { # bug12192
1135         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error "multiop failed"
1136         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1137 }
1138 run_test 24u "create stripe file"
1139
1140 simple_cleanup_common() {
1141         local rc=0
1142         trap 0
1143         [ -z "$DIR" ] || [ -z "$tdir" ] && return 0
1144
1145         local start=$SECONDS
1146         rm -rf $DIR/$tdir
1147         rc=$?
1148         wait_delete_completed
1149         echo "cleanup time $((SECONDS - start))"
1150         return $rc
1151 }
1152
1153 max_pages_per_rpc() {
1154         local mdtname="$(printf "MDT%04x" ${1:-0})"
1155         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1156 }
1157
1158 test_24v() {
1159         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1160
1161         local nrfiles=${COUNT:-100000}
1162         local fname="$DIR/$tdir/$tfile"
1163
1164         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1165         [ "$mds1_FSTYPE" = "zfs" ] && nrfiles=${COUNT:-10000}
1166
1167         test_mkdir "$(dirname $fname)"
1168         # assume MDT0000 has the fewest inodes
1169         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1170         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1171         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1172
1173         trap simple_cleanup_common EXIT
1174
1175         createmany -m "$fname" $nrfiles
1176
1177         cancel_lru_locks mdc
1178         lctl set_param mdc.*.stats clear
1179
1180         # was previously test_24D: LU-6101
1181         # readdir() returns correct number of entries after cursor reload
1182         local num_ls=$(ls $DIR/$tdir | wc -l)
1183         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1184         local num_all=$(ls -a $DIR/$tdir | wc -l)
1185         if [ $num_ls -ne $nrfiles ] || [ $num_uniq -ne $nrfiles ] ||
1186                 [ $num_all -ne $((nrfiles + 2)) ]; then
1187                         error "Expected $nrfiles files, got $num_ls " \
1188                                 "($num_uniq unique $num_all .&..)"
1189         fi
1190         # LU-5 large readdir
1191         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1192         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1193         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1194         # take into account of overhead in lu_dirpage header and end mark in
1195         # each page, plus one in rpc_num calculation.
1196         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1197         local page_entries=$(((PAGE_SIZE - 24) / dirent_size))
1198         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1199         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1200         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1201         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1202         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1203         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1204                 error "large readdir doesn't take effect: " \
1205                       "$mds_readpage should be about $rpc_max"
1206
1207         simple_cleanup_common
1208 }
1209 run_test 24v "list large directory (test hash collision, b=17560)"
1210
1211 test_24w() { # bug21506
1212         SZ1=234852
1213         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1214         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1215         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1216         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1217         [[ "$SZ1" -eq "$SZ2" ]] ||
1218                 error "Error reading at the end of the file $tfile"
1219 }
1220 run_test 24w "Reading a file larger than 4Gb"
1221
1222 test_24x() {
1223         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1224         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1225         [[ $MDS1_VERSION -lt $(version_code 2.7.56) ]] &&
1226                 skip "Need MDS version at least 2.7.56"
1227
1228         local MDTIDX=1
1229         local remote_dir=$DIR/$tdir/remote_dir
1230
1231         test_mkdir $DIR/$tdir
1232         $LFS mkdir -i $MDTIDX $remote_dir ||
1233                 error "create remote directory failed"
1234
1235         test_mkdir $DIR/$tdir/src_dir
1236         touch $DIR/$tdir/src_file
1237         test_mkdir $remote_dir/tgt_dir
1238         touch $remote_dir/tgt_file
1239
1240         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1241                 error "rename dir cross MDT failed!"
1242
1243         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1244                 error "rename file cross MDT failed!"
1245
1246         touch $DIR/$tdir/ln_file
1247         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1248                 error "ln file cross MDT failed"
1249
1250         rm -rf $DIR/$tdir || error "Can not delete directories"
1251 }
1252 run_test 24x "cross MDT rename/link"
1253
1254 test_24y() {
1255         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1256         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1257
1258         local remote_dir=$DIR/$tdir/remote_dir
1259         local mdtidx=1
1260
1261         test_mkdir $DIR/$tdir
1262         $LFS mkdir -i $mdtidx $remote_dir ||
1263                 error "create remote directory failed"
1264
1265         test_mkdir $remote_dir/src_dir
1266         touch $remote_dir/src_file
1267         test_mkdir $remote_dir/tgt_dir
1268         touch $remote_dir/tgt_file
1269
1270         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1271                 error "rename subdir in the same remote dir failed!"
1272
1273         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1274                 error "rename files in the same remote dir failed!"
1275
1276         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1277                 error "link files in the same remote dir failed!"
1278
1279         rm -rf $DIR/$tdir || error "Can not delete directories"
1280 }
1281 run_test 24y "rename/link on the same dir should succeed"
1282
1283 test_24z() {
1284         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1285         [[ $MDS1_VERSION -lt $(version_code 2.12.51) ]] &&
1286                 skip "Need MDS version at least 2.12.51"
1287
1288         local index
1289
1290         for index in 0 1; do
1291                 $LFS mkdir -i $index $DIR/$tdir.$index || error "mkdir failed"
1292                 touch $DIR/$tdir.0/$tfile.$index || error "touch failed"
1293         done
1294
1295         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1 || error "mv $tfile.0 failed"
1296
1297         index=$($LFS getstripe -m $DIR/$tdir.1/$tfile.0)
1298         [ $index -eq 0 ] || error "$tfile.0 is on MDT$index"
1299
1300         local mdts=$(comma_list $(mdts_nodes))
1301
1302         do_nodes $mdts $LCTL set_param mdt.*.enable_remote_rename=0
1303         stack_trap "do_nodes $mdts $LCTL \
1304                 set_param mdt.*.enable_remote_rename=1" EXIT
1305
1306         mv $DIR/$tdir.0/$tfile.1 $DIR/$tdir.1 || error "mv $tfile.1 failed"
1307
1308         index=$($LFS getstripe -m $DIR/$tdir.1/$tfile.1)
1309         [ $index -eq 1 ] || error "$tfile.1 is on MDT$index"
1310 }
1311 run_test 24z "cross-MDT rename is done as cp"
1312
1313 test_24A() { # LU-3182
1314         local NFILES=5000
1315
1316         rm -rf $DIR/$tdir
1317         test_mkdir $DIR/$tdir
1318         trap simple_cleanup_common EXIT
1319         createmany -m $DIR/$tdir/$tfile $NFILES
1320         local t=$(ls $DIR/$tdir | wc -l)
1321         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1322         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1323         if [ $t -ne $NFILES ] || [ $u -ne $NFILES ] ||
1324            [ $v -ne $((NFILES + 2)) ] ; then
1325                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1326         fi
1327
1328         simple_cleanup_common || error "Can not delete directories"
1329 }
1330 run_test 24A "readdir() returns correct number of entries."
1331
1332 test_24B() { # LU-4805
1333         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
1334
1335         local count
1336
1337         test_mkdir $DIR/$tdir
1338         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1339                 error "create striped dir failed"
1340
1341         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1342         [ $count -eq 2 ] || error "Expected 2, got $count"
1343
1344         touch $DIR/$tdir/striped_dir/a
1345
1346         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1347         [ $count -eq 3 ] || error "Expected 3, got $count"
1348
1349         touch $DIR/$tdir/striped_dir/.f
1350
1351         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1352         [ $count -eq 4 ] || error "Expected 4, got $count"
1353
1354         rm -rf $DIR/$tdir || error "Can not delete directories"
1355 }
1356 run_test 24B "readdir for striped dir return correct number of entries"
1357
1358 test_24C() {
1359         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
1360
1361         mkdir $DIR/$tdir
1362         mkdir $DIR/$tdir/d0
1363         mkdir $DIR/$tdir/d1
1364
1365         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1366                 error "create striped dir failed"
1367
1368         cd $DIR/$tdir/d0/striped_dir
1369
1370         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1371         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1372         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1373
1374         [ "$d0_ino" = "$parent_ino" ] ||
1375                 error ".. wrong, expect $d0_ino, get $parent_ino"
1376
1377         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1378                 error "mv striped dir failed"
1379
1380         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1381
1382         [ "$d1_ino" = "$parent_ino" ] ||
1383                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1384 }
1385 run_test 24C "check .. in striped dir"
1386
1387 test_24E() {
1388         [[ $MDSCOUNT -lt 4 ]] && skip_env "needs >= 4 MDTs"
1389         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1390
1391         mkdir -p $DIR/$tdir
1392         mkdir $DIR/$tdir/src_dir
1393         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1394                 error "create remote source failed"
1395
1396         touch $DIR/$tdir/src_dir/src_child/a
1397
1398         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1399                 error "create remote target dir failed"
1400
1401         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1402                 error "create remote target child failed"
1403
1404         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1405                 error "rename dir cross MDT failed!"
1406
1407         find $DIR/$tdir
1408
1409         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1410                 error "src_child still exists after rename"
1411
1412         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1413                 error "missing file(a) after rename"
1414
1415         rm -rf $DIR/$tdir || error "Can not delete directories"
1416 }
1417 run_test 24E "cross MDT rename/link"
1418
1419 test_24F () {
1420         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1421
1422         local repeats=1000
1423         [ "$SLOW" = "no" ] && repeats=100
1424
1425         mkdir -p $DIR/$tdir
1426
1427         echo "$repeats repeats"
1428         for ((i = 0; i < repeats; i++)); do
1429                 $LFS mkdir -i0 -c2 $DIR/$tdir/test || error "mkdir fails"
1430                 touch $DIR/$tdir/test/a || error "touch fails"
1431                 mkdir $DIR/$tdir/test/b || error "mkdir fails"
1432                 rm -rf $DIR/$tdir/test || error "rmdir fails"
1433         done
1434
1435         true
1436 }
1437 run_test 24F "hash order vs readdir (LU-11330)"
1438
1439 test_25a() {
1440         echo '== symlink sanity ============================================='
1441
1442         test_mkdir $DIR/d25
1443         ln -s d25 $DIR/s25
1444         touch $DIR/s25/foo ||
1445                 error "File creation in symlinked directory failed"
1446 }
1447 run_test 25a "create file in symlinked directory ==============="
1448
1449 test_25b() {
1450         [ ! -d $DIR/d25 ] && test_25a
1451         $CHECKSTAT -t file $DIR/s25/foo || error "$DIR/s25/foo not file type"
1452 }
1453 run_test 25b "lookup file in symlinked directory ==============="
1454
1455 test_26a() {
1456         test_mkdir $DIR/d26
1457         test_mkdir $DIR/d26/d26-2
1458         ln -s d26/d26-2 $DIR/s26
1459         touch $DIR/s26/foo || error "File creation failed"
1460 }
1461 run_test 26a "multiple component symlink ======================="
1462
1463 test_26b() {
1464         test_mkdir -p $DIR/$tdir/d26-2
1465         ln -s $tdir/d26-2/foo $DIR/s26-2
1466         touch $DIR/s26-2 || error "File creation failed"
1467 }
1468 run_test 26b "multiple component symlink at end of lookup ======"
1469
1470 test_26c() {
1471         test_mkdir $DIR/d26.2
1472         touch $DIR/d26.2/foo
1473         ln -s d26.2 $DIR/s26.2-1
1474         ln -s s26.2-1 $DIR/s26.2-2
1475         ln -s s26.2-2 $DIR/s26.2-3
1476         chmod 0666 $DIR/s26.2-3/foo
1477 }
1478 run_test 26c "chain of symlinks"
1479
1480 # recursive symlinks (bug 439)
1481 test_26d() {
1482         ln -s d26-3/foo $DIR/d26-3
1483 }
1484 run_test 26d "create multiple component recursive symlink"
1485
1486 test_26e() {
1487         [ ! -h $DIR/d26-3 ] && test_26d
1488         rm $DIR/d26-3
1489 }
1490 run_test 26e "unlink multiple component recursive symlink"
1491
1492 # recursive symlinks (bug 7022)
1493 test_26f() {
1494         test_mkdir $DIR/$tdir
1495         test_mkdir $DIR/$tdir/$tfile
1496         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1497         test_mkdir -p lndir/bar1
1498         test_mkdir $DIR/$tdir/$tfile/$tfile
1499         cd $tfile                || error "cd $tfile failed"
1500         ln -s .. dotdot          || error "ln dotdot failed"
1501         ln -s dotdot/lndir lndir || error "ln lndir failed"
1502         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1503         output=`ls $tfile/$tfile/lndir/bar1`
1504         [ "$output" = bar1 ] && error "unexpected output"
1505         rm -r $tfile             || error "rm $tfile failed"
1506         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1507 }
1508 run_test 26f "rm -r of a directory which has recursive symlink"
1509
1510 test_27a() {
1511         test_mkdir $DIR/$tdir
1512         $LFS getstripe $DIR/$tdir
1513         $LFS setstripe -c 1 $DIR/$tdir/$tfile || error "setstripe failed"
1514         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1515         cp /etc/hosts $DIR/$tdir/$tfile || error "Can't copy to one stripe file"
1516 }
1517 run_test 27a "one stripe file"
1518
1519 test_27b() {
1520         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1521
1522         test_mkdir $DIR/$tdir
1523         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1524         $LFS getstripe -c $DIR/$tdir/$tfile
1525         [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
1526                 error "two-stripe file doesn't have two stripes"
1527
1528         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1529 }
1530 run_test 27b "create and write to two stripe file"
1531
1532 # 27c family tests specific striping, setstripe -o
1533 test_27ca() {
1534         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test"
1535         test_mkdir -p $DIR/$tdir
1536         local osts="1"
1537
1538         $LFS setstripe -o $osts $DIR/$tdir/$tfile  || error "setstripe failed"
1539         $LFS getstripe -i $DIR/$tdir/$tfile
1540         [ $($LFS getstripe -i $DIR/$tdir/$tfile ) -eq $osts ] ||
1541                 error "stripe not on specified OST"
1542
1543         dd if=/dev/zero of=$DIR/$tdir/$tfile  bs=1M count=4 || error "dd failed"
1544 }
1545 run_test 27ca "one stripe on specified OST"
1546
1547 test_27cb() {
1548         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test"
1549         test_mkdir -p $DIR/$tdir
1550         local osts="1,0"
1551         $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
1552         local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
1553         echo "$getstripe"
1554
1555         # Strip getstripe output to a space separated list of OSTs
1556         local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
1557                 awk '{print $1}' | tr '\n' '\ ' | sed -e 's/[[:space:]]*$//')
1558         [ "$getstripe_osts" = "${osts//,/ }" ] ||
1559                 error "stripes not on specified OSTs"
1560
1561         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
1562 }
1563 run_test 27cb "two stripes on specified OSTs"
1564
1565 test_27cc() {
1566         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test"
1567         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
1568                 skip "server does not support overstriping"
1569
1570         test_mkdir -p $DIR/$tdir
1571         local osts="0,0"
1572         $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
1573         local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
1574         echo "$getstripe"
1575
1576         # Strip getstripe output to a space separated list of OSTs
1577         local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
1578                 awk '{print $1}' | tr '\n' '\ ' | sed -e 's/[[:space:]]*$//')
1579         [ "$getstripe_osts" = "${osts//,/ }" ] ||
1580                 error "stripes not on specified OSTs"
1581
1582         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
1583 }
1584 run_test 27cc "two stripes on the same OST"
1585
1586 test_27cd() {
1587         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test"
1588         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
1589                 skip "server does not support overstriping"
1590         test_mkdir -p $DIR/$tdir
1591         local osts="0,1,1,0"
1592         $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
1593         local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
1594         echo "$getstripe"
1595
1596         # Strip getstripe output to a space separated list of OSTs
1597         local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
1598                 awk '{print $1}' | tr '\n' '\ ' | sed -e 's/[[:space:]]*$//')
1599         [ "$getstripe_osts" = "${osts//,/ }" ] ||
1600                 error "stripes not on specified OSTs"
1601
1602         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
1603 }
1604 run_test 27cd "four stripes on two OSTs"
1605
1606 test_27ce() {
1607         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
1608                 skip_env "too many osts, skipping"
1609         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
1610                 skip "server does not support overstriping"
1611         # We do one more stripe than we have OSTs
1612         [ $OSTCOUNT -ge 159 ] || large_xattr_enabled ||
1613                 skip_env "ea_inode feature disabled"
1614
1615         test_mkdir -p $DIR/$tdir
1616         local osts=""
1617         for i in $(seq 0 $OSTCOUNT);
1618         do
1619                 osts=$osts"0"
1620                 if [ $i -ne $OSTCOUNT ]; then
1621                         osts=$osts","
1622                 fi
1623         done
1624         $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
1625         local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
1626         echo "$getstripe"
1627
1628         # Strip getstripe output to a space separated list of OSTs
1629         local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
1630                 awk '{print $1}' | tr '\n' '\ ' | sed -e 's/[[:space:]]*$//')
1631         [ "$getstripe_osts" = "${osts//,/ }" ] ||
1632                 error "stripes not on specified OSTs"
1633
1634         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
1635 }
1636 run_test 27ce "more stripes than OSTs with -o"
1637
1638 test_27cf() {
1639         local osp_proc="osp.$FSNAME-OST0000-osc-MDT000*.active"
1640         local pid=0
1641
1642         test_mkdir -p $DIR/$tdir || error "failed to mkdir $DIR/$tdir"
1643         do_facet $SINGLEMDS "$LCTL set_param -n $osp_proc=0"
1644         stack_trap "do_facet $SINGLEMDS $LCTL set_param -n $osp_proc=1" EXIT
1645         wait_update_facet $SINGLEMDS "$LCTL get_param -n $osp_proc | grep 1" ||
1646                 error "failed to set $osp_proc=0"
1647
1648         $LFS setstripe -o 0 $DIR/$tdir/$tfile &
1649         pid=$!
1650         sleep 1
1651         do_facet $SINGLEMDS "$LCTL set_param -n $osp_proc=1"
1652         wait_update_facet $SINGLEMDS "$LCTL get_param -n $osp_proc | grep 0" ||
1653                 error "failed to set $osp_proc=1"
1654         wait $pid
1655         [[ $pid -ne 0 ]] ||
1656                 error "should return error due to $osp_proc=0"
1657 }
1658 run_test 27cf "'setstripe -o' on inactive OSTs should return error"
1659
1660 test_27d() {
1661         test_mkdir $DIR/$tdir
1662         $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile ||
1663                 error "setstripe failed"
1664         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1665         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1666 }
1667 run_test 27d "create file with default settings"
1668
1669 test_27e() {
1670         # LU-5839 adds check for existed layout before setting it
1671         [[ $MDS1_VERSION -lt $(version_code 2.7.56) ]] &&
1672                 skip "Need MDS version at least 2.7.56"
1673
1674         test_mkdir $DIR/$tdir
1675         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1676         $LFS setstripe -c 2 $DIR/$tdir/$tfile && error "setstripe worked twice"
1677         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1678 }
1679 run_test 27e "setstripe existing file (should return error)"
1680
1681 test_27f() {
1682         test_mkdir $DIR/$tdir
1683         $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1684                 error "$LFS setstripe $DIR/$tdir/$tfile failed"
1685         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1686                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1687         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1688         $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1689 }
1690 run_test 27f "setstripe with bad stripe size (should return error)"
1691
1692 test_27g() {
1693         test_mkdir $DIR/$tdir
1694         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1695         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "no stripe info" ||
1696                 error "$DIR/$tdir/$tfile has object"
1697 }
1698 run_test 27g "$LFS getstripe with no objects"
1699
1700 test_27ga() {
1701         test_mkdir $DIR/$tdir
1702         touch $DIR/$tdir/$tfile || error "touch failed"
1703         ln -s bogus $DIR/$tdir/$tfile.2 || error "ln failed"
1704         $LFS getstripe -m $DIR/$tdir/$tfile $DIR/$tdir/$tfile.2
1705         local rc=$?
1706         (( rc == 2 )) || error "getstripe did not return ENOENT"
1707 }
1708 run_test 27ga "$LFS getstripe with missing file (should return error)"
1709
1710 test_27i() {
1711         test_mkdir $DIR/$tdir
1712         touch $DIR/$tdir/$tfile || error "touch failed"
1713         [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1714                 error "missing objects"
1715 }
1716 run_test 27i "$LFS getstripe with some objects"
1717
1718 test_27j() {
1719         test_mkdir $DIR/$tdir
1720         $LFS setstripe -i $OSTCOUNT $DIR/$tdir/$tfile &&
1721                 error "setstripe failed" || true
1722 }
1723 run_test 27j "setstripe with bad stripe offset (should return error)"
1724
1725 test_27k() { # bug 2844
1726         test_mkdir $DIR/$tdir
1727         local file=$DIR/$tdir/$tfile
1728         local ll_max_blksize=$((4 * 1024 * 1024))
1729         $LFS setstripe -S 67108864 $file || error "setstripe failed"
1730         local blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1731         [ $blksize -le $ll_max_blksize ] || error "1:$blksize > $ll_max_blksize"
1732         dd if=/dev/zero of=$file bs=4k count=1
1733         blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1734         [ $blksize -le $ll_max_blksize ] || error "2:$blksize > $ll_max_blksize"
1735 }
1736 run_test 27k "limit i_blksize for broken user apps"
1737
1738 test_27l() {
1739         mcreate $DIR/$tfile || error "creating file"
1740         $RUNAS $LFS setstripe -c 1 $DIR/$tfile &&
1741                 error "setstripe should have failed" || true
1742 }
1743 run_test 27l "check setstripe permissions (should return error)"
1744
1745 test_27m() {
1746         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1747
1748         [ -n "$RCLIENTS" -o -n "$MOUNT_2" ] &&
1749                 skip_env "multiple clients -- skipping"
1750
1751         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1752                    head -n1)
1753         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1754                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1755         fi
1756         trap simple_cleanup_common EXIT
1757         test_mkdir $DIR/$tdir
1758         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.1
1759         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
1760                 error "dd should fill OST0"
1761         i=2
1762         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.$i; do
1763                 i=$((i + 1))
1764                 [ $i -gt 256 ] && break
1765         done
1766         i=$((i + 1))
1767         touch $DIR/$tdir/$tfile.$i
1768         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1769             awk '{print $1}'| grep -w "0") ] &&
1770                 error "OST0 was full but new created file still use it"
1771         i=$((i + 1))
1772         touch $DIR/$tdir/$tfile.$i
1773         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1774             awk '{print $1}'| grep -w "0") ] &&
1775                 error "OST0 was full but new created file still use it"
1776         simple_cleanup_common
1777 }
1778 run_test 27m "create file while OST0 was full"
1779
1780 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1781 # if the OST isn't full anymore.
1782 reset_enospc() {
1783         local OSTIDX=${1:-""}
1784
1785         local list=$(comma_list $(osts_nodes))
1786         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1787
1788         do_nodes $list lctl set_param fail_loc=0
1789         sync    # initiate all OST_DESTROYs from MDS to OST
1790         sleep_maxage
1791 }
1792
1793 exhaust_precreations() {
1794         local OSTIDX=$1
1795         local FAILLOC=$2
1796         local FAILIDX=${3:-$OSTIDX}
1797         local ofacet=ost$((OSTIDX + 1))
1798
1799         test_mkdir -p -c1 $DIR/$tdir
1800         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
1801         local mfacet=mds$((mdtidx + 1))
1802         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1803
1804         local OST=$(ostname_from_index $OSTIDX)
1805
1806         # on the mdt's osc
1807         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1808         local last_id=$(do_facet $mfacet lctl get_param -n \
1809                         osp.$mdtosc_proc1.prealloc_last_id)
1810         local next_id=$(do_facet $mfacet lctl get_param -n \
1811                         osp.$mdtosc_proc1.prealloc_next_id)
1812
1813         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1814         do_facet $mfacet lctl get_param osp.$mdtosc_proc2.prealloc*
1815
1816         test_mkdir -p $DIR/$tdir/${OST}
1817         $LFS setstripe -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1818 #define OBD_FAIL_OST_ENOSPC              0x215
1819         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1820         echo "Creating to objid $last_id on ost $OST..."
1821         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1822         do_facet $mfacet lctl get_param osp.$mdtosc_proc2.prealloc*
1823         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1824         sleep_maxage
1825 }
1826
1827 exhaust_all_precreations() {
1828         local i
1829         for (( i=0; i < OSTCOUNT; i++ )) ; do
1830                 exhaust_precreations $i $1 -1
1831         done
1832 }
1833
1834 test_27n() {
1835         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1836         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1837         remote_mds_nodsh && skip "remote MDS with nodsh"
1838         remote_ost_nodsh && skip "remote OST with nodsh"
1839
1840         reset_enospc
1841         rm -f $DIR/$tdir/$tfile
1842         exhaust_precreations 0 0x80000215
1843         $LFS setstripe -c -1 $DIR/$tdir || error "setstripe failed"
1844         touch $DIR/$tdir/$tfile || error "touch failed"
1845         $LFS getstripe $DIR/$tdir/$tfile
1846         reset_enospc
1847 }
1848 run_test 27n "create file with some full OSTs"
1849
1850 test_27o() {
1851         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1852         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1853         remote_mds_nodsh && skip "remote MDS with nodsh"
1854         remote_ost_nodsh && skip "remote OST with nodsh"
1855
1856         reset_enospc
1857         rm -f $DIR/$tdir/$tfile
1858         exhaust_all_precreations 0x215
1859
1860         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1861
1862         reset_enospc
1863         rm -rf $DIR/$tdir/*
1864 }
1865 run_test 27o "create file with all full OSTs (should error)"
1866
1867 test_27p() {
1868         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1869         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1870         remote_mds_nodsh && skip "remote MDS with nodsh"
1871         remote_ost_nodsh && skip "remote OST with nodsh"
1872
1873         reset_enospc
1874         rm -f $DIR/$tdir/$tfile
1875         test_mkdir $DIR/$tdir
1876
1877         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1878         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1879         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1880
1881         exhaust_precreations 0 0x80000215
1882         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1883         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1884         $LFS getstripe $DIR/$tdir/$tfile
1885
1886         reset_enospc
1887 }
1888 run_test 27p "append to a truncated file with some full OSTs"
1889
1890 test_27q() {
1891         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1892         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1893         remote_mds_nodsh && skip "remote MDS with nodsh"
1894         remote_ost_nodsh && skip "remote OST with nodsh"
1895
1896         reset_enospc
1897         rm -f $DIR/$tdir/$tfile
1898
1899         test_mkdir $DIR/$tdir
1900         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1901         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1902                 error "truncate $DIR/$tdir/$tfile failed"
1903         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1904
1905         exhaust_all_precreations 0x215
1906
1907         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1908         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1909
1910         reset_enospc
1911 }
1912 run_test 27q "append to truncated file with all OSTs full (should error)"
1913
1914 test_27r() {
1915         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1916         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1917         remote_mds_nodsh && skip "remote MDS with nodsh"
1918         remote_ost_nodsh && skip "remote OST with nodsh"
1919
1920         reset_enospc
1921         rm -f $DIR/$tdir/$tfile
1922         exhaust_precreations 0 0x80000215
1923
1924         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1925
1926         reset_enospc
1927 }
1928 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1929
1930 test_27s() { # bug 10725
1931         test_mkdir $DIR/$tdir
1932         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1933         local stripe_count=0
1934         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1935         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1936                 error "stripe width >= 2^32 succeeded" || true
1937
1938 }
1939 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1940
1941 test_27t() { # bug 10864
1942         WDIR=$(pwd)
1943         WLFS=$(which lfs)
1944         cd $DIR
1945         touch $tfile
1946         $WLFS getstripe $tfile
1947         cd $WDIR
1948 }
1949 run_test 27t "check that utils parse path correctly"
1950
1951 test_27u() { # bug 4900
1952         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1953         remote_mds_nodsh && skip "remote MDS with nodsh"
1954
1955         local index
1956         local list=$(comma_list $(mdts_nodes))
1957
1958 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1959         do_nodes $list $LCTL set_param fail_loc=0x139
1960         test_mkdir -p $DIR/$tdir
1961         trap simple_cleanup_common EXIT
1962         createmany -o $DIR/$tdir/t- 1000
1963         do_nodes $list $LCTL set_param fail_loc=0
1964
1965         TLOG=$TMP/$tfile.getstripe
1966         $LFS getstripe $DIR/$tdir > $TLOG
1967         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1968         unlinkmany $DIR/$tdir/t- 1000
1969         trap 0
1970         [[ $OBJS -gt 0 ]] &&
1971                 error "$OBJS objects created on OST-0. See $TLOG" ||
1972                 rm -f $TLOG
1973 }
1974 run_test 27u "skip object creation on OSC w/o objects"
1975
1976 test_27v() { # bug 4900
1977         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1978         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1979         remote_mds_nodsh && skip "remote MDS with nodsh"
1980         remote_ost_nodsh && skip "remote OST with nodsh"
1981
1982         exhaust_all_precreations 0x215
1983         reset_enospc
1984
1985         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
1986
1987         touch $DIR/$tdir/$tfile
1988         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1989         # all except ost1
1990         for (( i=1; i < OSTCOUNT; i++ )); do
1991                 do_facet ost$i lctl set_param fail_loc=0x705
1992         done
1993         local START=`date +%s`
1994         createmany -o $DIR/$tdir/$tfile 32
1995
1996         local FINISH=`date +%s`
1997         local TIMEOUT=`lctl get_param -n timeout`
1998         local PROCESS=$((FINISH - START))
1999         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
2000                error "$FINISH - $START >= $TIMEOUT / 2"
2001         sleep $((TIMEOUT / 2 - PROCESS))
2002         reset_enospc
2003 }
2004 run_test 27v "skip object creation on slow OST"
2005
2006 test_27w() { # bug 10997
2007         test_mkdir $DIR/$tdir
2008         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
2009         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
2010                 error "stripe size $size != 65536" || true
2011         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
2012                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
2013 }
2014 run_test 27w "check $LFS setstripe -S and getstrip -d options"
2015
2016 test_27wa() {
2017         [[ $OSTCOUNT -lt 2 ]] &&
2018                 skip_env "skipping multiple stripe count/offset test"
2019
2020         test_mkdir $DIR/$tdir
2021         for i in $(seq 1 $OSTCOUNT); do
2022                 offset=$((i - 1))
2023                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
2024                         error "setstripe -c $i -i $offset failed"
2025                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
2026                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
2027                 [ $count -ne $i ] && error "stripe count $count != $i" || true
2028                 [ $index -ne $offset ] &&
2029                         error "stripe offset $index != $offset" || true
2030         done
2031 }
2032 run_test 27wa "check $LFS setstripe -c -i options"
2033
2034 test_27x() {
2035         remote_ost_nodsh && skip "remote OST with nodsh"
2036         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2037         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2038
2039         OFFSET=$(($OSTCOUNT - 1))
2040         OSTIDX=0
2041         local OST=$(ostname_from_index $OSTIDX)
2042
2043         test_mkdir $DIR/$tdir
2044         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
2045         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
2046         sleep_maxage
2047         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
2048         for i in $(seq 0 $OFFSET); do
2049                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
2050                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
2051                 error "OST0 was degraded but new created file still use it"
2052         done
2053         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
2054 }
2055 run_test 27x "create files while OST0 is degraded"
2056
2057 test_27y() {
2058         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2059         remote_mds_nodsh && skip "remote MDS with nodsh"
2060         remote_ost_nodsh && skip "remote OST with nodsh"
2061         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2062
2063         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
2064         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
2065                 osp.$mdtosc.prealloc_last_id)
2066         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
2067                 osp.$mdtosc.prealloc_next_id)
2068         local fcount=$((last_id - next_id))
2069         [[ $fcount -eq 0 ]] && skip "not enough space on OST0"
2070         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
2071
2072         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
2073                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
2074         local OST_DEACTIVE_IDX=-1
2075         local OSC
2076         local OSTIDX
2077         local OST
2078
2079         for OSC in $MDS_OSCS; do
2080                 OST=$(osc_to_ost $OSC)
2081                 OSTIDX=$(index_from_ostuuid $OST)
2082                 if [ $OST_DEACTIVE_IDX == -1 ]; then
2083                         OST_DEACTIVE_IDX=$OSTIDX
2084                 fi
2085                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
2086                         echo $OSC "is Deactivated:"
2087                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
2088                 fi
2089         done
2090
2091         OSTIDX=$(index_from_ostuuid $OST)
2092         test_mkdir $DIR/$tdir
2093         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
2094
2095         for OSC in $MDS_OSCS; do
2096                 OST=$(osc_to_ost $OSC)
2097                 OSTIDX=$(index_from_ostuuid $OST)
2098                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
2099                         echo $OST "is degraded:"
2100                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
2101                                                 obdfilter.$OST.degraded=1
2102                 fi
2103         done
2104
2105         sleep_maxage
2106         createmany -o $DIR/$tdir/$tfile $fcount
2107
2108         for OSC in $MDS_OSCS; do
2109                 OST=$(osc_to_ost $OSC)
2110                 OSTIDX=$(index_from_ostuuid $OST)
2111                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
2112                         echo $OST "is recovered from degraded:"
2113                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
2114                                                 obdfilter.$OST.degraded=0
2115                 else
2116                         do_facet $SINGLEMDS lctl --device %$OSC activate
2117                 fi
2118         done
2119
2120         # all osp devices get activated, hence -1 stripe count restored
2121         local stripe_count=0
2122
2123         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
2124         # devices get activated.
2125         sleep_maxage
2126         $LFS setstripe -c -1 $DIR/$tfile
2127         stripe_count=$($LFS getstripe -c $DIR/$tfile)
2128         rm -f $DIR/$tfile
2129         [ $stripe_count -ne $OSTCOUNT ] &&
2130                 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
2131         return 0
2132 }
2133 run_test 27y "create files while OST0 is degraded and the rest inactive"
2134
2135 check_seq_oid()
2136 {
2137         log "check file $1"
2138
2139         lmm_count=$($LFS getstripe -c $1)
2140         lmm_seq=$($LFS getstripe -v $1 | awk '/lmm_seq/ { print $2 }')
2141         lmm_oid=$($LFS getstripe -v $1 | awk '/lmm_object_id/ { print $2 }')
2142
2143         local old_ifs="$IFS"
2144         IFS=$'[:]'
2145         fid=($($LFS path2fid $1))
2146         IFS="$old_ifs"
2147
2148         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
2149         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
2150
2151         # compare lmm_seq and lu_fid->f_seq
2152         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
2153         # compare lmm_object_id and lu_fid->oid
2154         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
2155
2156         # check the trusted.fid attribute of the OST objects of the file
2157         local have_obdidx=false
2158         local stripe_nr=0
2159         $LFS getstripe $1 | while read obdidx oid hex seq; do
2160                 # skip lines up to and including "obdidx"
2161                 [ -z "$obdidx" ] && break
2162                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
2163                 $have_obdidx || continue
2164
2165                 local ost=$((obdidx + 1))
2166                 local dev=$(ostdevname $ost)
2167                 local oid_hex
2168
2169                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
2170
2171                 seq=$(echo $seq | sed -e "s/^0x//g")
2172                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
2173                         oid_hex=$(echo $oid)
2174                 else
2175                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
2176                 fi
2177                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
2178
2179                 local ff=""
2180                 #
2181                 # Don't unmount/remount the OSTs if we don't need to do that.
2182                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
2183                 # update too, until that use mount/ll_decode_filter_fid/mount.
2184                 # Re-enable when debugfs will understand new filter_fid.
2185                 #
2186                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
2187                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
2188                                 $dev 2>/dev/null" | grep "parent=")
2189                 fi
2190                 if [ -z "$ff" ]; then
2191                         stop ost$ost
2192                         mount_fstype ost$ost
2193                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
2194                                 $(facet_mntpt ost$ost)/$obj_file)
2195                         unmount_fstype ost$ost
2196                         start ost$ost $dev $OST_MOUNT_OPTS
2197                         clients_up
2198                 fi
2199
2200                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
2201
2202                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
2203
2204                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
2205                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
2206                 #
2207                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
2208                 #       stripe_size=1048576 component_id=1 component_start=0 \
2209                 #       component_end=33554432
2210                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
2211                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
2212                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
2213                 local ff_pstripe
2214                 if grep -q 'stripe=' <<<$ff; then
2215                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
2216                 else
2217                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
2218                         # into f_ver in this case.  See comment on ff_parent.
2219                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
2220                 fi
2221
2222                 # compare lmm_seq and filter_fid->ff_parent.f_seq
2223                 [ $ff_pseq = $lmm_seq ] ||
2224                         error "FF parent SEQ $ff_pseq != $lmm_seq"
2225                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
2226                 [ $ff_poid = $lmm_oid ] ||
2227                         error "FF parent OID $ff_poid != $lmm_oid"
2228                 (($ff_pstripe == $stripe_nr)) ||
2229                         error "FF stripe $ff_pstripe != $stripe_nr"
2230
2231                 stripe_nr=$((stripe_nr + 1))
2232                 [ $CLIENT_VERSION -lt $(version_code 2.9.55) ] &&
2233                         continue
2234                 if grep -q 'stripe_count=' <<<$ff; then
2235                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
2236                                             -e 's/ .*//' <<<$ff)
2237                         [ $lmm_count = $ff_scnt ] ||
2238                                 error "FF stripe count $lmm_count != $ff_scnt"
2239                 fi
2240         done
2241 }
2242
2243 test_27z() {
2244         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2245         remote_ost_nodsh && skip "remote OST with nodsh"
2246
2247         test_mkdir $DIR/$tdir
2248         $LFS setstripe -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
2249                 { error "setstripe -c -1 failed"; return 1; }
2250         # We need to send a write to every object to get parent FID info set.
2251         # This _should_ also work for setattr, but does not currently.
2252         # touch $DIR/$tdir/$tfile-1 ||
2253         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
2254                 { error "dd $tfile-1 failed"; return 2; }
2255         $LFS setstripe -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
2256                 { error "setstripe -c -1 failed"; return 3; }
2257         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
2258                 { error "dd $tfile-2 failed"; return 4; }
2259
2260         # make sure write RPCs have been sent to OSTs
2261         sync; sleep 5; sync
2262
2263         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
2264         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
2265 }
2266 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
2267
2268 test_27A() { # b=19102
2269         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2270
2271         save_layout_restore_at_exit $MOUNT
2272         $LFS setstripe -c 0 -i -1 -S 0 $MOUNT
2273         wait_update $HOSTNAME "$LFS getstripe -c $MOUNT | sed 's/  *//g'" "1" 20 ||
2274                 error "stripe count $($LFS getstripe -c $MOUNT) != 1"
2275         local default_size=$($LFS getstripe -S $MOUNT)
2276         local default_offset=$($LFS getstripe -i $MOUNT)
2277         local dsize=$(do_facet $SINGLEMDS \
2278                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
2279         [ $default_size -eq $dsize ] ||
2280                 error "stripe size $default_size != $dsize"
2281         [ $default_offset -eq -1 ] ||
2282                 error "stripe offset $default_offset != -1"
2283 }
2284 run_test 27A "check filesystem-wide default LOV EA values"
2285
2286 test_27B() { # LU-2523
2287         test_mkdir $DIR/$tdir
2288         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
2289         touch $DIR/$tdir/f0
2290         # open f1 with O_LOV_DELAY_CREATE
2291         # rename f0 onto f1
2292         # call setstripe ioctl on open file descriptor for f1
2293         # close
2294         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
2295                 $DIR/$tdir/f0
2296
2297         rm -f $DIR/$tdir/f1
2298         # open f1 with O_LOV_DELAY_CREATE
2299         # unlink f1
2300         # call setstripe ioctl on open file descriptor for f1
2301         # close
2302         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2303
2304         # Allow multiop to fail in imitation of NFS's busted semantics.
2305         true
2306 }
2307 run_test 27B "call setstripe on open unlinked file/rename victim"
2308
2309 # 27C family tests full striping and overstriping
2310 test_27Ca() { #LU-2871
2311         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2312
2313         declare -a ost_idx
2314         local index
2315         local found
2316         local i
2317         local j
2318
2319         test_mkdir $DIR/$tdir
2320         cd $DIR/$tdir
2321         for i in $(seq 0 $((OSTCOUNT - 1))); do
2322                 # set stripe across all OSTs starting from OST$i
2323                 $LFS setstripe -i $i -c -1 $tfile$i
2324                 # get striping information
2325                 ost_idx=($($LFS getstripe $tfile$i |
2326                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2327                 echo ${ost_idx[@]}
2328
2329                 # check the layout
2330                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2331                         error "${#ost_idx[@]} != $OSTCOUNT"
2332
2333                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2334                         found=0
2335                         for j in $(echo ${ost_idx[@]}); do
2336                                 if [ $index -eq $j ]; then
2337                                         found=1
2338                                         break
2339                                 fi
2340                         done
2341                         [ $found = 1 ] ||
2342                                 error "Can not find $index in ${ost_idx[@]}"
2343                 done
2344         done
2345 }
2346 run_test 27Ca "check full striping across all OSTs"
2347
2348 test_27Cb() {
2349         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2350                 skip "server does not support overstriping"
2351         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
2352                 skip_env "too many osts, skipping"
2353
2354         test_mkdir -p $DIR/$tdir
2355         local setcount=$(($OSTCOUNT * 2))
2356         [ $setcount -ge 160 ] || large_xattr_enabled ||
2357                 skip_env "ea_inode feature disabled"
2358
2359         $LFS setstripe -C $setcount $DIR/$tdir/$tfile ||
2360                 error "setstripe failed"
2361
2362         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2363         [ $count -eq $setcount ] ||
2364                 error "stripe count $count, should be $setcount"
2365
2366         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" ||
2367                 error "overstriped should be set in pattern"
2368
2369         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2370                 error "dd failed"
2371 }
2372 run_test 27Cb "more stripes than OSTs with -C"
2373
2374 test_27Cc() {
2375         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2376                 skip "server does not support overstriping"
2377         [[ $OSTCOUNT -lt 2 ]] && skip_env "need > 1 OST"
2378
2379         test_mkdir -p $DIR/$tdir
2380         local setcount=$(($OSTCOUNT - 1))
2381
2382         [ $setcount -ge 160 ] || large_xattr_enabled ||
2383                 skip_env "ea_inode feature disabled"
2384
2385         $LFS setstripe -C $setcount $DIR/$tdir/$tfile ||
2386                 error "setstripe failed"
2387
2388         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2389         [ $count -eq $setcount ] ||
2390                 error "stripe count $count, should be $setcount"
2391
2392         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" &&
2393                 error "overstriped should not be set in pattern"
2394
2395         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2396                 error "dd failed"
2397 }
2398 run_test 27Cc "fewer stripes than OSTs does not set overstriping"
2399
2400 test_27Cd() {
2401         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2402                 skip "server does not support overstriping"
2403         [[ $OSTCOUNT -lt 2 ]] && skip_env "need > 1 OST"
2404         large_xattr_enabled || skip_env "ea_inode feature disabled"
2405
2406         test_mkdir -p $DIR/$tdir
2407         local setcount=$LOV_MAX_STRIPE_COUNT
2408
2409         $LFS setstripe -C $setcount $DIR/$tdir/$tfile ||
2410                 error "setstripe failed"
2411
2412         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2413         [ $count -eq $setcount ] ||
2414                 error "stripe count $count, should be $setcount"
2415
2416         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" ||
2417                 error "overstriped should be set in pattern"
2418
2419         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2420                 error "dd failed"
2421
2422         rm -f $DIR/$tdir/$tfile || error "Delete $tfile failed"
2423 }
2424 run_test 27Cd "test maximum stripe count"
2425
2426 test_27Ce() {
2427         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2428                 skip "server does not support overstriping"
2429         test_mkdir -p $DIR/$tdir
2430
2431         pool_add $TESTNAME || error "Pool creation failed"
2432         pool_add_targets $TESTNAME 0 || error "pool_add_targets failed"
2433
2434         local setcount=8
2435
2436         $LFS setstripe  -C $setcount -p "$TESTNAME" $DIR/$tdir/$tfile ||
2437                 error "setstripe failed"
2438
2439         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2440         [ $count -eq $setcount ] ||
2441                 error "stripe count $count, should be $setcount"
2442
2443         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" ||
2444                 error "overstriped should be set in pattern"
2445
2446         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2447                 error "dd failed"
2448
2449         rm -f $DIR/$tdir/$tfile || error "Delete $tfile failed"
2450 }
2451 run_test 27Ce "test pool with overstriping"
2452
2453 test_27Cf() {
2454         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2455                 skip "server does not support overstriping"
2456         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
2457                 skip_env "too many osts, skipping"
2458
2459         test_mkdir -p $DIR/$tdir
2460
2461         local setcount=$(($OSTCOUNT * 2))
2462         [ $setcount -ge 160 ] || large_xattr_enabled ||
2463                 skip_env "ea_inode feature disabled"
2464
2465         $LFS setstripe  -C $setcount $DIR/$tdir/ ||
2466                 error "setstripe failed"
2467
2468         echo 1 > $DIR/$tdir/$tfile
2469
2470         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2471         [ $count -eq $setcount ] ||
2472                 error "stripe count $count, should be $setcount"
2473
2474         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" ||
2475                 error "overstriped should be set in pattern"
2476
2477         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2478                 error "dd failed"
2479
2480         rm -f $DIR/$tdir/$tfile || error "Delete $tfile failed"
2481 }
2482 run_test 27Cf "test default inheritance with overstriping"
2483
2484 test_27D() {
2485         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2486         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
2487         remote_mds_nodsh && skip "remote MDS with nodsh"
2488
2489         local POOL=${POOL:-testpool}
2490         local first_ost=0
2491         local last_ost=$(($OSTCOUNT - 1))
2492         local ost_step=1
2493         local ost_list=$(seq $first_ost $ost_step $last_ost)
2494         local ost_range="$first_ost $last_ost $ost_step"
2495
2496         test_mkdir $DIR/$tdir
2497         pool_add $POOL || error "pool_add failed"
2498         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2499
2500         local skip27D
2501         [ $MDS1_VERSION -lt $(version_code 2.8.55) ] &&
2502                 skip27D+="-s 29"
2503         [ $MDS1_VERSION -lt $(version_code 2.9.55) ] ||
2504                 [ $CLIENT_VERSION -lt $(version_code 2.9.55) ] &&
2505                         skip27D+=" -s 30,31"
2506         [[ ! $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ||
2507           $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
2508                 skip27D+=" -s 32,33"
2509         [[ $MDS_VERSION -lt $(version_code $SEL_VER) ]] &&
2510                 skip27D+=" -s 34"
2511         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2512                 error "llapi_layout_test failed"
2513
2514         destroy_test_pools || error "destroy test pools failed"
2515 }
2516 run_test 27D "validate llapi_layout API"
2517
2518 # Verify that default_easize is increased from its initial value after
2519 # accessing a widely striped file.
2520 test_27E() {
2521         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2522         [ $CLIENT_VERSION -lt $(version_code 2.5.57) ] &&
2523                 skip "client does not have LU-3338 fix"
2524
2525         # 72 bytes is the minimum space required to store striping
2526         # information for a file striped across one OST:
2527         # (sizeof(struct lov_user_md_v3) +
2528         #  sizeof(struct lov_user_ost_data_v1))
2529         local min_easize=72
2530         $LCTL set_param -n llite.*.default_easize $min_easize ||
2531                 error "lctl set_param failed"
2532         local easize=$($LCTL get_param -n llite.*.default_easize)
2533
2534         [ $easize -eq $min_easize ] ||
2535                 error "failed to set default_easize"
2536
2537         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2538                 error "setstripe failed"
2539         # In order to ensure stat() call actually talks to MDS we need to
2540         # do something drastic to this file to shake off all lock, e.g.
2541         # rename it (kills lookup lock forcing cache cleaning)
2542         mv $DIR/$tfile $DIR/${tfile}-1
2543         ls -l $DIR/${tfile}-1
2544         rm $DIR/${tfile}-1
2545
2546         easize=$($LCTL get_param -n llite.*.default_easize)
2547
2548         [ $easize -gt $min_easize ] ||
2549                 error "default_easize not updated"
2550 }
2551 run_test 27E "check that default extended attribute size properly increases"
2552
2553 test_27F() { # LU-5346/LU-7975
2554         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2555         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs"
2556         [[ $MDS1_VERSION -lt $(version_code 2.8.51) ]] &&
2557                 skip "Need MDS version at least 2.8.51"
2558         remote_ost_nodsh && skip "remote OST with nodsh"
2559
2560         test_mkdir $DIR/$tdir
2561         rm -f $DIR/$tdir/f0
2562         $LFS setstripe -c 2 $DIR/$tdir
2563
2564         # stop all OSTs to reproduce situation for LU-7975 ticket
2565         for num in $(seq $OSTCOUNT); do
2566                 stop ost$num
2567         done
2568
2569         # open/create f0 with O_LOV_DELAY_CREATE
2570         # truncate f0 to a non-0 size
2571         # close
2572         multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2573
2574         $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2575         # open/write it again to force delayed layout creation
2576         cat /etc/hosts > $DIR/$tdir/f0 &
2577         catpid=$!
2578
2579         # restart OSTs
2580         for num in $(seq $OSTCOUNT); do
2581                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2582                         error "ost$num failed to start"
2583         done
2584
2585         wait $catpid || error "cat failed"
2586
2587         cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2588         [[ $($LFS getstripe -c $DIR/$tdir/f0) == 2 ]] ||
2589                 error "wrong stripecount"
2590
2591 }
2592 run_test 27F "Client resend delayed layout creation with non-zero size"
2593
2594 test_27G() { #LU-10629
2595         [ $MDS1_VERSION -lt $(version_code 2.11.51) ] &&
2596                 skip "Need MDS version at least 2.11.51"
2597         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
2598         remote_mds_nodsh && skip "remote MDS with nodsh"
2599         local POOL=${POOL:-testpool}
2600         local ostrange="0 0 1"
2601
2602         test_mkdir $DIR/$tdir
2603         pool_add $POOL || error "pool_add failed"
2604         pool_add_targets $POOL $ostrange || error "pool_add_targets failed"
2605         $LFS setstripe -p $POOL $DIR/$tdir
2606
2607         local pool=$($LFS getstripe -p $DIR/$tdir)
2608
2609         [ "$pool" = "$POOL" ] || error "Striping failed got '$pool' not '$POOL'"
2610
2611         $LFS setstripe -d $DIR/$tdir
2612
2613         pool=$($LFS getstripe -p $DIR/$tdir)
2614
2615         rmdir $DIR/$tdir
2616
2617         [ -z "$pool" ] || error "'$pool' is not empty"
2618 }
2619 run_test 27G "Clear OST pool from stripe"
2620
2621 test_27H() {
2622         [[ $MDS1_VERSION -le $(version_code 2.11.54) ]] &&
2623                 skip "Need MDS version newer than 2.11.54"
2624         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs"
2625         test_mkdir $DIR/$tdir
2626         $LFS setstripe -o 0 -o 2 $DIR/$tdir || error "setstripe failed"
2627         touch $DIR/$tdir/$tfile
2628         $LFS getstripe -c $DIR/$tdir/$tfile
2629         [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
2630                 error "two-stripe file doesn't have two stripes"
2631
2632         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
2633         $LFS getstripe -y $DIR/$tdir/$tfile
2634         (( $($LFS getstripe -y $DIR/$tdir/$tfile |
2635              egrep -c "l_ost_idx: [02]$") == "2" )) ||
2636                 error "expected l_ost_idx: [02]$ not matched"
2637
2638         # make sure ost list has been cleared
2639         local stripesize=$($LFS getstripe -S $DIR/$tdir)
2640         $LFS setstripe -S $((stripesize * 4)) -i 1 \
2641                 -c $((OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
2642         touch $DIR/$tdir/f3
2643         $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
2644 }
2645 run_test 27H "Set specific OSTs stripe"
2646
2647 test_27I() {
2648         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2649         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2650         [[ $MDS1_VERSION -gt $(version_code 2.12.52) ]] ||
2651                 skip "Need MDS version newer than 2.12.52"
2652         local pool=$TESTNAME
2653         local ostrange="1 1 1"
2654
2655         save_layout_restore_at_exit $MOUNT
2656         $LFS setstripe -c 2 -i 0 $MOUNT
2657         pool_add $pool || error "pool_add failed"
2658         pool_add_targets $pool $ostrange || "pool_add_targets failed"
2659         test_mkdir $DIR/$tdir
2660         $LFS setstripe -p $pool $DIR/$tdir
2661         $MULTIOP $DIR/$tdir/$tfile Oc || error "multiop failed"
2662         $LFS getstripe $DIR/$tdir/$tfile
2663 }
2664 run_test 27I "check that root dir striping does not break parent dir one"
2665
2666 test_27J() {
2667         [[ $MDS1_VERSION -le $(version_code 2.12.51) ]] &&
2668                 skip "Need MDS version newer than 2.12.51"
2669
2670         test_mkdir $DIR/$tdir
2671         local uuid1=$(cat /proc/sys/kernel/random/uuid)
2672         local uuid2=$(cat /proc/sys/kernel/random/uuid)
2673
2674         # create foreign file (raw way)
2675         create_foreign_file -f $DIR/$tdir/$tfile -x "${uuid1}@${uuid2}" \
2676                 -t 1 -F 0xda08 || error "create_foreign_file failed"
2677
2678         # verify foreign file (raw way)
2679         parse_foreign_file -f $DIR/$tdir/$tfile |
2680                 grep "lov_foreign_magic: 0x0BD70BD0" ||
2681                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign magic"
2682         parse_foreign_file -f $DIR/$tdir/$tfile | grep "lov_xattr_size: 89" ||
2683                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign size"
2684         parse_foreign_file -f $DIR/$tdir/$tfile |
2685                 grep "lov_foreign_size: 73" ||
2686                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign size"
2687         parse_foreign_file -f $DIR/$tdir/$tfile |
2688                 grep "lov_foreign_type: 1" ||
2689                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign type"
2690         parse_foreign_file -f $DIR/$tdir/$tfile |
2691                 grep "lov_foreign_flags: 0x0000DA08" ||
2692                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign flags"
2693         local lov=$(parse_foreign_file -f $DIR/$tdir/$tfile |
2694                 grep "lov_foreign_value: 0x" |
2695                 sed -e 's/lov_foreign_value: 0x//')
2696         local lov2=$(echo -n "${uuid1}@${uuid2}" | od -A n -t x1 -w160)
2697         [[ $lov = ${lov2// /} ]] ||
2698                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign value"
2699
2700         # create foreign file (lfs + API)
2701         $LFS setstripe --foreign=daos --flags 0xda08 \
2702                 -x "${uuid1}@${uuid2}" $DIR/$tdir/${tfile}2 ||
2703                 error "$DIR/$tdir/${tfile}2: create failed"
2704
2705         $LFS getstripe -v $DIR/$tdir/${tfile}2 |
2706                 grep "lfm_magic:.*0x0BD70BD0" ||
2707                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign magic"
2708         # lfm_length is LOV EA size - sizeof(lfm_magic) - sizeof(lfm_length)
2709         $LFS getstripe -v $DIR/$tdir/${tfile}2 | grep "lfm_length:.*73" ||
2710                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign size"
2711         $LFS getstripe -v $DIR/$tdir/${tfile}2 | grep "lfm_type:.*daos" ||
2712                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign type"
2713         $LFS getstripe -v $DIR/$tdir/${tfile}2 |
2714                 grep "lfm_flags:.*0x0000DA08" ||
2715                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign flags"
2716         $LFS getstripe $DIR/$tdir/${tfile}2 |
2717                 grep "lfm_value:.*${uuid1}@${uuid2}" ||
2718                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign value"
2719
2720         # modify striping should fail
2721         $LFS setstripe -c 2 $DIR/$tdir/$tfile &&
2722                 error "$DIR/$tdir/$tfile: setstripe should fail"
2723         $LFS setstripe -c 2 $DIR/$tdir/${tfile}2 &&
2724                 error "$DIR/$tdir/${tfile}2: setstripe should fail"
2725
2726         # R/W should fail
2727         cat $DIR/$tdir/$tfile && error "$DIR/$tdir/$tfile: read should fail"
2728         cat $DIR/$tdir/${tfile}2 &&
2729                 error "$DIR/$tdir/${tfile}2: read should fail"
2730         cat /etc/passwd > $DIR/$tdir/$tfile &&
2731                 error "$DIR/$tdir/$tfile: write should fail"
2732         cat /etc/passwd > $DIR/$tdir/${tfile}2 &&
2733                 error "$DIR/$tdir/${tfile}2: write should fail"
2734
2735         # chmod should work
2736         chmod 222 $DIR/$tdir/$tfile ||
2737                 error "$DIR/$tdir/$tfile: chmod failed"
2738         chmod 222 $DIR/$tdir/${tfile}2 ||
2739                 error "$DIR/$tdir/${tfile}2: chmod failed"
2740
2741         # chown should work
2742         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/$tfile ||
2743                 error "$DIR/$tdir/$tfile: chown failed"
2744         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/${tfile}2 ||
2745                 error "$DIR/$tdir/${tfile}2: chown failed"
2746
2747         # rename should work
2748         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}.new ||
2749                 error "$DIR/$tdir/$tfile: rename of foreign file has failed"
2750         mv $DIR/$tdir/${tfile}2 $DIR/$tdir/${tfile}2.new ||
2751                 error "$DIR/$tdir/${tfile}2: rename of foreign file has failed"
2752
2753         #remove foreign file
2754         rm $DIR/$tdir/${tfile}.new ||
2755                 error "$DIR/$tdir/${tfile}.new: remove of foreign file has failed"
2756         rm $DIR/$tdir/${tfile}2.new ||
2757                 error "$DIR/$tdir/${tfile}2.new: remove of foreign file has failed"
2758 }
2759 run_test 27J "basic ops on file with foreign LOV"
2760
2761 test_27K() {
2762         [[ $MDS1_VERSION -le $(version_code 2.12.49) ]] &&
2763                 skip "Need MDS version newer than 2.12.49"
2764
2765         test_mkdir $DIR/$tdir
2766         local uuid1=$(cat /proc/sys/kernel/random/uuid)
2767         local uuid2=$(cat /proc/sys/kernel/random/uuid)
2768
2769         # create foreign dir (raw way)
2770         create_foreign_dir -d $DIR/$tdir/$tdir -x "${uuid1}@${uuid2}" -t 1 ||
2771                 error "create_foreign_dir FAILED"
2772
2773         # verify foreign dir (raw way)
2774         parse_foreign_dir -d $DIR/$tdir/$tdir |
2775                 grep "lmv_foreign_magic:.*0xcd50cd0" ||
2776                 error "$DIR/$tdir/$tfile: invalid LMV EA magic"
2777         parse_foreign_dir -d $DIR/$tdir/$tdir | grep "lmv_xattr_size:.*89$" ||
2778                 error "$DIR/$tdir/$tdir: invalid LMV EA size"
2779         parse_foreign_dir -d $DIR/$tdir/$tdir | grep "lmv_foreign_type: 1$" ||
2780                 error "$DIR/$tdir/$tdir: invalid LMV EA type"
2781         parse_foreign_dir -d $DIR/$tdir/$tdir | grep "lmv_foreign_flags: 0$" ||
2782                 error "$DIR/$tdir/$tdir: invalid LMV EA flags"
2783         local lmv=$(parse_foreign_dir -d $DIR/$tdir/$tdir |
2784                 grep "lmv_foreign_value: 0x" |
2785                 sed 's/lmv_foreign_value: 0x//')
2786         local lmv2=$(echo -n "${uuid1}@${uuid2}" | od -A n -t x1 -w160 |
2787                 sed 's/ //g')
2788         [[ $lmv == $lmv2 ]] || error "$DIR/$tdir/$tdir: invalid LMV EA value"
2789
2790         # create foreign dir (lfs + API)
2791         $LFS mkdir --foreign=daos --xattr="${uuid1}@${uuid2}" --flags=0xda05 \
2792                 $DIR/$tdir/${tdir}2 ||
2793                 error "$DIR/$tdir/${tdir}2: create failed"
2794
2795         $LFS getdirstripe -v $DIR/$tdir/${tdir}2 |
2796                 grep "lfm_magic:.*0x0CD50CD0" ||
2797                 error "$DIR/$tdir/${tdir}2: invalid LMV EA magic"
2798         # lfm_length is LMV EA size - sizeof(lfm_magic) - sizeof(lfm_length)
2799         # - sizeof(lfm_type) - sizeof(lfm_flags)
2800         $LFS getdirstripe -v $DIR/$tdir/${tdir}2 | grep "lfm_length:.*73" ||
2801                 error "$DIR/$tdir/${tdir}2: invalid LMV EA size"
2802         $LFS getdirstripe -v $DIR/$tdir/${tdir}2 | grep "lfm_type:.*daos" ||
2803                 error "$DIR/$tdir/${tdir}2: invalid LMV EA type"
2804         $LFS getdirstripe -v $DIR/$tdir/${tdir}2 |
2805                 grep "lfm_flags:.*0x0000DA05" ||
2806                 error "$DIR/$tdir/${tdir}2: invalid LMV EA flags"
2807         $LFS getdirstripe $DIR/$tdir/${tdir}2 |
2808                 grep "lfm_value.*${uuid1}@${uuid2}" ||
2809                 error "$DIR/$tdir/${tdir}2: invalid LMV EA value"
2810
2811         # file create in dir should fail
2812         touch $DIR/$tdir/$tdir/$tfile && "$DIR/$tdir: file create should fail"
2813         touch $DIR/$tdir/${tdir}2/$tfile &&
2814                 "$DIR/${tdir}2: file create should fail"
2815
2816         # chmod should work
2817         chmod 777 $DIR/$tdir/$tdir ||
2818                 error "$DIR/$tdir: chmod failed"
2819         chmod 777 $DIR/$tdir/${tdir}2 ||
2820                 error "$DIR/${tdir}2: chmod failed"
2821
2822         # chown should work
2823         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/$tdir ||
2824                 error "$DIR/$tdir: chown failed"
2825         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/${tdir}2 ||
2826                 error "$DIR/${tdir}2: chown failed"
2827
2828         # rename should work
2829         mv $DIR/$tdir/$tdir $DIR/$tdir/${tdir}.new ||
2830                 error "$DIR/$tdir/$tdir: rename of foreign dir has failed"
2831         mv $DIR/$tdir/${tdir}2 $DIR/$tdir/${tdir}2.new ||
2832                 error "$DIR/$tdir/${tdir}2: rename of foreign dir has failed"
2833
2834         #remove foreign dir
2835         rmdir $DIR/$tdir/${tdir}.new ||
2836                 error "$DIR/$tdir/${tdir}.new: remove of foreign dir has failed"
2837         rmdir $DIR/$tdir/${tdir}2.new ||
2838                 error "$DIR/$tdir/${tdir}2.new: remove of foreign dir has failed"
2839 }
2840 run_test 27K "basic ops on dir with foreign LMV"
2841
2842 test_27L() {
2843         remote_mds_nodsh && skip "remote MDS with nodsh"
2844
2845         local POOL=${POOL:-$TESTNAME}
2846
2847         pool_add $POOL || error "pool_add failed"
2848
2849         lfs pool_list $MOUNT | grep -Fx "${FSNAME}.${POOL}" ||
2850                  error "pool_list does not contain ${FSNAME}.${POOL}:" \
2851                        "$(lfs pool_list $MOUNT | grep -F "${POOL}")"
2852 }
2853 run_test 27L "lfs pool_list gives correct pool name"
2854
2855 test_27M() {
2856         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.12.57) ]] &&
2857                 skip "Need MDS version >= than 2.12.57"
2858         remote_mds_nodsh && skip "remote MDS with nodsh"
2859         [[ $OSTCOUNT -lt 2 ]] && skip_env "need > 1 OST"
2860
2861         test_mkdir $DIR/$tdir
2862
2863         # Set default striping on directory
2864         $LFS setstripe -C 4 $DIR/$tdir
2865
2866         echo 1 > $DIR/$tdir/${tfile}.1
2867         local count=$($LFS getstripe -c $DIR/$tdir/${tfile}.1)
2868         local setcount=4
2869         [ $count -eq $setcount ] ||
2870                 error "(1) stripe count $count, should be $setcount"
2871
2872         # Capture existing append_stripe_count setting for restore
2873         local orig_count=$(do_facet mds1 $LCTL get_param -n mdd.$FSNAME-MDT0000.append_stripe_count)
2874         local mdts=$(comma_list $(mdts_nodes))
2875         stack_trap "do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=$orig_count" EXIT
2876
2877         local appendcount=$orig_count
2878         echo 1 >> $DIR/$tdir/${tfile}.2_append
2879         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.2_append)
2880         [ $count -eq $appendcount ] ||
2881                 error "(2)stripe count $count, should be $appendcount for append"
2882
2883         # Disable O_APPEND striping, verify it works
2884         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=0
2885
2886         # Should now get the default striping, which is 4
2887         setcount=4
2888         echo 1 >> $DIR/$tdir/${tfile}.3_append
2889         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.3_append)
2890         [ $count -eq $setcount ] ||
2891                 error "(3) stripe count $count, should be $setcount"
2892
2893         # Try changing the stripe count for append files
2894         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=2
2895
2896         # Append striping is now 2 (directory default is still 4)
2897         appendcount=2
2898         echo 1 >> $DIR/$tdir/${tfile}.4_append
2899         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.4_append)
2900         [ $count -eq $appendcount ] ||
2901                 error "(4) stripe count $count, should be $appendcount for append"
2902
2903         # Test append stripe count of -1
2904         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=-1
2905         appendcount=$OSTCOUNT
2906         echo 1 >> $DIR/$tdir/${tfile}.5
2907         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.5)
2908         [ $count -eq $appendcount ] ||
2909                 error "(5) stripe count $count, should be $appendcount for append"
2910
2911         # Set append striping back to default of 1
2912         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=1
2913
2914         # Try a new default striping, PFL + DOM
2915         $LFS setstripe -L mdt -E 1M -E -1 -c 2 $DIR/$tdir
2916
2917         # Create normal DOM file, DOM returns stripe count == 0
2918         setcount=0
2919         touch $DIR/$tdir/${tfile}.6
2920         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.6)
2921         [ $count -eq $setcount ] ||
2922                 error "(6) stripe count $count, should be $setcount"
2923
2924         # Show
2925         appendcount=1
2926         echo 1 >> $DIR/$tdir/${tfile}.7_append
2927         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.7_append)
2928         [ $count -eq $appendcount ] ||
2929                 error "(7) stripe count $count, should be $appendcount for append"
2930
2931         # Clean up DOM layout
2932         $LFS setstripe -d $DIR/$tdir
2933
2934         # Now test that append striping works when layout is from root
2935         $LFS setstripe -c 2 $MOUNT
2936         # Make a special directory for this
2937         mkdir $DIR/${tdir}/${tdir}.2
2938         stack_trap "$LFS setstripe -d $MOUNT" EXIT
2939
2940         # Verify for normal file
2941         setcount=2
2942         echo 1 > $DIR/${tdir}/${tdir}.2/${tfile}.8
2943         count=$($LFS getstripe -c $DIR/$tdir/${tdir}.2/${tfile}.8)
2944         [ $count -eq $setcount ] ||
2945                 error "(8) stripe count $count, should be $setcount"
2946
2947         appendcount=1
2948         echo 1 >> $DIR/${tdir}/${tdir}.2/${tfile}.9_append
2949         count=$($LFS getstripe -c $DIR/${tdir}/${tdir}.2/${tfile}.9_append)
2950         [ $count -eq $appendcount ] ||
2951                 error "(9) stripe count $count, should be $appendcount for append"
2952
2953         # Now test O_APPEND striping with pools
2954         do_nodes $mdts $LCTL set_param mdd.*.append_pool="$TESTNAME"
2955         stack_trap "do_nodes $mdts $LCTL set_param mdd.*.append_pool='none'" EXIT
2956
2957         # Create the pool
2958         pool_add $TESTNAME || error "pool creation failed"
2959         pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
2960
2961         echo 1 >> $DIR/$tdir/${tfile}.10_append
2962
2963         pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.10_append)
2964         [ "$pool" = "$TESTNAME" ] || error "(10) incorrect pool: $pool"
2965
2966         # Check that count is still correct
2967         appendcount=1
2968         echo 1 >> $DIR/$tdir/${tfile}.11_append
2969         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.11_append)
2970         [ $count -eq $appendcount ] ||
2971                 error "(11) stripe count $count, should be $appendcount for append"
2972
2973         # Disable O_APPEND stripe count, verify pool works separately
2974         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=0
2975
2976         echo 1 >> $DIR/$tdir/${tfile}.12_append
2977
2978         pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.12_append)
2979         [ "$pool" = "$TESTNAME" ] || error "(12) incorrect pool: $pool"
2980
2981         # Remove pool setting, verify it's not applied
2982         do_nodes $mdts $LCTL set_param mdd.*.append_pool='none'
2983
2984         echo 1 >> $DIR/$tdir/${tfile}.13_append
2985
2986         pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.13_append)
2987         [ "$pool" = "" ] || error "(13) pool found: $pool"
2988 }
2989 run_test 27M "test O_APPEND striping"
2990
2991 test_27N() {
2992         combined_mgs_mds && skip "needs separate MGS/MDT"
2993
2994         pool_add $TESTNAME || error "pool_add failed"
2995         do_facet mgs "$LCTL pool_list $FSNAME" |
2996                 grep -Fx "${FSNAME}.${TESTNAME}" ||
2997                 error "lctl pool_list on MGS failed"
2998 }
2999 run_test 27N "lctl pool_list on separate MGS gives correct pool name"
3000
3001 # createtest also checks that device nodes are created and
3002 # then visible correctly (#2091)
3003 test_28() { # bug 2091
3004         test_mkdir $DIR/d28
3005         $CREATETEST $DIR/d28/ct || error "createtest failed"
3006 }
3007 run_test 28 "create/mknod/mkdir with bad file types ============"
3008
3009 test_29() {
3010         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3011
3012         sync; sleep 1; sync # flush out any dirty pages from previous tests
3013         cancel_lru_locks
3014         test_mkdir $DIR/d29
3015         touch $DIR/d29/foo
3016         log 'first d29'
3017         ls -l $DIR/d29
3018
3019         declare -i LOCKCOUNTORIG=0
3020         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
3021                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
3022         done
3023         [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
3024
3025         declare -i LOCKUNUSEDCOUNTORIG=0
3026         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
3027                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
3028         done
3029
3030         log 'second d29'
3031         ls -l $DIR/d29
3032         log 'done'
3033
3034         declare -i LOCKCOUNTCURRENT=0
3035         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
3036                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
3037         done
3038
3039         declare -i LOCKUNUSEDCOUNTCURRENT=0
3040         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
3041                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
3042         done
3043
3044         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
3045                 $LCTL set_param -n ldlm.dump_namespaces ""
3046                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
3047                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
3048                 log "dumped log to $TMP/test_29.dk (bug 5793)"
3049                 return 2
3050         fi
3051         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
3052                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
3053                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
3054                 log "dumped log to $TMP/test_29.dk (bug 5793)"
3055                 return 3
3056         fi
3057 }
3058 run_test 29 "IT_GETATTR regression  ============================"
3059
3060 test_30a() { # was test_30
3061         cp $(which ls) $DIR || cp /bin/ls $DIR
3062         $DIR/ls / || error "Can't execute binary from lustre"
3063         rm $DIR/ls
3064 }
3065 run_test 30a "execute binary from Lustre (execve) =============="
3066
3067 test_30b() {
3068         cp `which ls` $DIR || cp /bin/ls $DIR
3069         chmod go+rx $DIR/ls
3070         $RUNAS $DIR/ls / || error "Can't execute binary from lustre as non-root"
3071         rm $DIR/ls
3072 }
3073 run_test 30b "execute binary from Lustre as non-root ==========="
3074
3075 test_30c() { # b=22376
3076         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3077
3078         cp `which ls` $DIR || cp /bin/ls $DIR
3079         chmod a-rw $DIR/ls
3080         cancel_lru_locks mdc
3081         cancel_lru_locks osc
3082         $RUNAS $DIR/ls / || error "Can't execute binary from lustre"
3083         rm -f $DIR/ls
3084 }
3085 run_test 30c "execute binary from Lustre without read perms ===="
3086
3087 test_31a() {
3088         $OPENUNLINK $DIR/f31 $DIR/f31 || error "openunlink failed"
3089         $CHECKSTAT -a $DIR/f31 || error "$DIR/f31 exists"
3090 }
3091 run_test 31a "open-unlink file =================================="
3092
3093 test_31b() {
3094         touch $DIR/f31 || error "touch $DIR/f31 failed"
3095         ln $DIR/f31 $DIR/f31b || error "ln failed"
3096         $MULTIOP $DIR/f31b Ouc || error "multiop failed"
3097         $CHECKSTAT -t file $DIR/f31 || error "$DIR/f31 not file type"
3098 }
3099 run_test 31b "unlink file with multiple links while open ======="
3100
3101 test_31c() {
3102         touch $DIR/f31 || error "touch $DIR/f31 failed"
3103         ln $DIR/f31 $DIR/f31c || error "ln failed"
3104         multiop_bg_pause $DIR/f31 O_uc ||
3105                 error "multiop_bg_pause for $DIR/f31 failed"
3106         MULTIPID=$!
3107         $MULTIOP $DIR/f31c Ouc
3108         kill -USR1 $MULTIPID
3109         wait $MULTIPID
3110 }
3111 run_test 31c "open-unlink file with multiple links ============="
3112
3113 test_31d() {
3114         opendirunlink $DIR/d31d $DIR/d31d || error "opendirunlink failed"
3115         $CHECKSTAT -a $DIR/d31d || error "$DIR/d31d exists"
3116 }
3117 run_test 31d "remove of open directory ========================="
3118
3119 test_31e() { # bug 2904
3120         openfilleddirunlink $DIR/d31e || error "openfilleddirunlink failed"
3121 }
3122 run_test 31e "remove of open non-empty directory ==============="
3123
3124 test_31f() { # bug 4554
3125         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3126
3127         set -vx
3128         test_mkdir $DIR/d31f
3129         $LFS setstripe -S 1048576 -c 1 $DIR/d31f
3130         cp /etc/hosts $DIR/d31f
3131         ls -l $DIR/d31f
3132         $LFS getstripe $DIR/d31f/hosts
3133         multiop_bg_pause $DIR/d31f D_c || return 1
3134         MULTIPID=$!
3135
3136         rm -rv $DIR/d31f || error "first of $DIR/d31f"
3137         test_mkdir $DIR/d31f
3138         $LFS setstripe -S 1048576 -c 1 $DIR/d31f
3139         cp /etc/hosts $DIR/d31f
3140         ls -l $DIR/d31f
3141         $LFS getstripe $DIR/d31f/hosts
3142         multiop_bg_pause $DIR/d31f D_c || return 1
3143         MULTIPID2=$!
3144
3145         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
3146         wait $MULTIPID || error "first opendir $MULTIPID failed"
3147
3148         sleep 6
3149
3150         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
3151         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
3152         set +vx
3153 }
3154 run_test 31f "remove of open directory with open-unlink file ==="
3155
3156 test_31g() {
3157         echo "-- cross directory link --"
3158         test_mkdir -c1 $DIR/${tdir}ga
3159         test_mkdir -c1 $DIR/${tdir}gb
3160         touch $DIR/${tdir}ga/f
3161         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
3162         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
3163         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
3164         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
3165         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
3166 }
3167 run_test 31g "cross directory link==============="
3168
3169 test_31h() {
3170         echo "-- cross directory link --"
3171         test_mkdir -c1 $DIR/${tdir}
3172         test_mkdir -c1 $DIR/${tdir}/dir
3173         touch $DIR/${tdir}/f
3174         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
3175         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
3176         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
3177         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
3178         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
3179 }
3180 run_test 31h "cross directory link under child==============="
3181
3182 test_31i() {
3183         echo "-- cross directory link --"
3184         test_mkdir -c1 $DIR/$tdir
3185         test_mkdir -c1 $DIR/$tdir/dir
3186         touch $DIR/$tdir/dir/f
3187         ln $DIR/$tdir/dir/f $DIR/$tdir/g
3188         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
3189         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
3190         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
3191         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
3192 }
3193 run_test 31i "cross directory link under parent==============="
3194
3195 test_31j() {
3196         test_mkdir -c1 -p $DIR/$tdir
3197         test_mkdir -c1 -p $DIR/$tdir/dir1
3198         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
3199         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
3200         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
3201         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
3202         return 0
3203 }
3204 run_test 31j "link for directory==============="
3205
3206 test_31k() {
3207         test_mkdir -c1 -p $DIR/$tdir
3208         touch $DIR/$tdir/s
3209         touch $DIR/$tdir/exist
3210         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
3211         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
3212         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
3213         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
3214         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
3215         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
3216         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
3217         return 0
3218 }
3219 run_test 31k "link to file: the same, non-existing, dir==============="
3220
3221 test_31m() {
3222         mkdir $DIR/d31m
3223         touch $DIR/d31m/s
3224         mkdir $DIR/d31m2
3225         touch $DIR/d31m2/exist
3226         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
3227         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
3228         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
3229         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
3230         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
3231         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
3232         return 0
3233 }
3234 run_test 31m "link to file: the same, non-existing, dir==============="
3235
3236 test_31n() {
3237         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
3238         nlink=$(stat --format=%h $DIR/$tfile)
3239         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
3240         local fd=$(free_fd)
3241         local cmd="exec $fd<$DIR/$tfile"
3242         eval $cmd
3243         cmd="exec $fd<&-"
3244         trap "eval $cmd" EXIT
3245         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
3246         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
3247         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
3248         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
3249         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
3250         eval $cmd
3251 }
3252 run_test 31n "check link count of unlinked file"
3253
3254 link_one() {
3255         local tempfile=$(mktemp $1_XXXXXX)
3256         mlink $tempfile $1 2> /dev/null &&
3257                 echo "$BASHPID: link $tempfile to $1 succeeded"
3258         munlink $tempfile
3259 }
3260
3261 test_31o() { # LU-2901
3262         test_mkdir $DIR/$tdir
3263         for LOOP in $(seq 100); do
3264                 rm -f $DIR/$tdir/$tfile*
3265                 for THREAD in $(seq 8); do
3266                         link_one $DIR/$tdir/$tfile.$LOOP &
3267                 done
3268                 wait
3269                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
3270                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
3271                         error "$LINKS duplicate links to $tfile.$LOOP" &&
3272                         break || true
3273         done
3274 }
3275 run_test 31o "duplicate hard links with same filename"
3276
3277 test_31p() {
3278         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3279
3280         test_mkdir $DIR/$tdir
3281         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3282         $LFS setdirstripe -D -c2 -H all_char $DIR/$tdir/striped_dir
3283
3284         opendirunlink $DIR/$tdir/striped_dir/test1 ||
3285                 error "open unlink test1 failed"
3286         opendirunlink $DIR/$tdir/striped_dir/test2 ||
3287                 error "open unlink test2 failed"
3288
3289         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
3290                 error "test1 still exists"
3291         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
3292                 error "test2 still exists"
3293 }
3294 run_test 31p "remove of open striped directory"
3295
3296 cleanup_test32_mount() {
3297         local rc=0
3298         trap 0
3299         local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
3300         $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
3301         losetup -d $loopdev || true
3302         rm -rf $DIR/$tdir
3303         return $rc
3304 }
3305
3306 test_32a() {
3307         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3308
3309         echo "== more mountpoints and symlinks ================="
3310         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3311         trap cleanup_test32_mount EXIT
3312         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3313         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3314                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3315         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. ||
3316                 error "$DIR/$tdir/ext2-mountpoint/.. not dir type"
3317         cleanup_test32_mount
3318 }
3319 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
3320
3321 test_32b() {
3322         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3323
3324         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3325         trap cleanup_test32_mount EXIT
3326         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3327         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3328                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3329         ls -al $DIR/$tdir/ext2-mountpoint/.. ||
3330                 error "Can't list $DIR/$tdir/ext2-mountpoint/.."
3331         cleanup_test32_mount
3332 }
3333 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
3334
3335 test_32c() {
3336         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3337
3338         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3339         trap cleanup_test32_mount EXIT
3340         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3341         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3342                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3343         test_mkdir -p $DIR/$tdir/d2/test_dir
3344         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
3345                 error "$DIR/$tdir/ext2-mountpoint/../d2/test_dir not dir type"
3346         cleanup_test32_mount
3347 }
3348 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
3349
3350 test_32d() {
3351         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3352
3353         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3354         trap cleanup_test32_mount EXIT
3355         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3356         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3357                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3358         test_mkdir -p $DIR/$tdir/d2/test_dir
3359         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
3360                 error "Can't list $DIR/$tdir/ext2-mountpoint/../d2/test_dir"
3361         cleanup_test32_mount
3362 }
3363 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir"
3364
3365 test_32e() {
3366         rm -fr $DIR/$tdir
3367         test_mkdir -p $DIR/$tdir/tmp
3368         local tmp_dir=$DIR/$tdir/tmp
3369         ln -s $DIR/$tdir $tmp_dir/symlink11
3370         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
3371         $CHECKSTAT -t link $DIR/$tdir/tmp/symlink11 || error "symlink11 bad"
3372         $CHECKSTAT -t link $DIR/$tdir/symlink01 || error "symlink01 bad"
3373 }
3374 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir"
3375
3376 test_32f() {
3377         rm -fr $DIR/$tdir
3378         test_mkdir -p $DIR/$tdir/tmp
3379         local tmp_dir=$DIR/$tdir/tmp
3380         ln -s $DIR/$tdir $tmp_dir/symlink11
3381         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
3382         ls $DIR/$tdir/tmp/symlink11  || error "symlink11 bad"
3383         ls $DIR/$tdir/symlink01 || error "symlink01 bad"
3384 }
3385 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir"
3386
3387 test_32g() {
3388         local tmp_dir=$DIR/$tdir/tmp
3389         test_mkdir -p $tmp_dir
3390         test_mkdir $DIR/${tdir}2
3391         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
3392         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
3393         $CHECKSTAT -t link $tmp_dir/symlink12 || error "symlink12 not a link"
3394         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error "symlink02 not a link"
3395         $CHECKSTAT -t dir -f $tmp_dir/symlink12 || error "symlink12 not a dir"
3396         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error "symlink12 not a dir"
3397 }
3398 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
3399
3400 test_32h() {
3401         rm -fr $DIR/$tdir $DIR/${tdir}2
3402         tmp_dir=$DIR/$tdir/tmp
3403         test_mkdir -p $tmp_dir
3404         test_mkdir $DIR/${tdir}2
3405         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
3406         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
3407         ls $tmp_dir/symlink12 || error "listing symlink12"
3408         ls $DIR/$tdir/symlink02  || error "listing symlink02"
3409 }
3410 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
3411
3412 test_32i() {
3413         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3414
3415         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3416         trap cleanup_test32_mount EXIT
3417         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3418         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3419                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3420         touch $DIR/$tdir/test_file
3421         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file ||
3422                 error "$DIR/$tdir/ext2-mountpoint/../test_file not file type"
3423         cleanup_test32_mount
3424 }
3425 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
3426
3427 test_32j() {
3428         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3429
3430         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3431         trap cleanup_test32_mount EXIT
3432         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3433         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3434                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3435         touch $DIR/$tdir/test_file
3436         cat $DIR/$tdir/ext2-mountpoint/../test_file ||
3437                 error "Can't open $DIR/$tdir/ext2-mountpoint/../test_file"
3438         cleanup_test32_mount
3439 }
3440 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
3441
3442 test_32k() {
3443         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3444
3445         rm -fr $DIR/$tdir
3446         trap cleanup_test32_mount EXIT
3447         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3448         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3449                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3450         test_mkdir -p $DIR/$tdir/d2
3451         touch $DIR/$tdir/d2/test_file || error "touch failed"
3452         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
3453                 error "$DIR/$tdir/ext2-mountpoint/../d2/test_file not file type"
3454         cleanup_test32_mount
3455 }
3456 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
3457
3458 test_32l() {
3459         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3460
3461         rm -fr $DIR/$tdir
3462         trap cleanup_test32_mount EXIT
3463         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3464         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3465                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3466         test_mkdir -p $DIR/$tdir/d2
3467         touch $DIR/$tdir/d2/test_file || error "touch failed"
3468         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
3469                 error "Can't open $DIR/$tdir/ext2-mountpoint/../d2/test_file"
3470         cleanup_test32_mount
3471 }
3472 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
3473
3474 test_32m() {
3475         rm -fr $DIR/d32m
3476         test_mkdir -p $DIR/d32m/tmp
3477         TMP_DIR=$DIR/d32m/tmp
3478         ln -s $DIR $TMP_DIR/symlink11
3479         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
3480         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 ||
3481                 error "symlink11 not a link"
3482         $CHECKSTAT -t link $DIR/d32m/symlink01 ||
3483                 error "symlink01 not a link"
3484 }
3485 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
3486
3487 test_32n() {
3488         rm -fr $DIR/d32n
3489         test_mkdir -p $DIR/d32n/tmp
3490         TMP_DIR=$DIR/d32n/tmp
3491         ln -s $DIR $TMP_DIR/symlink11
3492         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
3493         ls -l $DIR/d32n/tmp/symlink11  || error "listing symlink11"
3494         ls -l $DIR/d32n/symlink01 || error "listing symlink01"
3495 }
3496 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
3497
3498 test_32o() {
3499         touch $DIR/$tfile
3500         test_mkdir -p $DIR/d32o/tmp
3501         TMP_DIR=$DIR/d32o/tmp
3502         ln -s $DIR/$tfile $TMP_DIR/symlink12
3503         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
3504         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 ||
3505                 error "symlink12 not a link"
3506         $CHECKSTAT -t link $DIR/d32o/symlink02 || error "symlink02 not a link"
3507         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 ||
3508                 error "$DIR/d32o/tmp/symlink12 not file type"
3509         $CHECKSTAT -t file -f $DIR/d32o/symlink02 ||
3510                 error "$DIR/d32o/symlink02 not file type"
3511 }
3512 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
3513
3514 test_32p() {
3515         log 32p_1
3516         rm -fr $DIR/d32p
3517         log 32p_2
3518         rm -f $DIR/$tfile
3519         log 32p_3
3520         touch $DIR/$tfile
3521         log 32p_4
3522         test_mkdir -p $DIR/d32p/tmp
3523         log 32p_5
3524         TMP_DIR=$DIR/d32p/tmp
3525         log 32p_6
3526         ln -s $DIR/$tfile $TMP_DIR/symlink12
3527         log 32p_7
3528         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
3529         log 32p_8
3530         cat $DIR/d32p/tmp/symlink12 ||
3531                 error "Can't open $DIR/d32p/tmp/symlink12"
3532         log 32p_9
3533         cat $DIR/d32p/symlink02 || error "Can't open $DIR/d32p/symlink02"
3534         log 32p_10
3535 }
3536 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
3537
3538 test_32q() {
3539         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3540
3541         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3542         trap cleanup_test32_mount EXIT
3543         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3544         touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
3545         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3546                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3547         ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
3548         cleanup_test32_mount
3549 }
3550 run_test 32q "stat follows mountpoints in Lustre (should return error)"
3551
3552 test_32r() {
3553         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3554
3555         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3556         trap cleanup_test32_mount EXIT
3557         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3558         touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
3559         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3560                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3561         ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
3562         cleanup_test32_mount
3563 }
3564 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
3565
3566 test_33aa() {
3567         rm -f $DIR/$tfile
3568         touch $DIR/$tfile
3569         chmod 444 $DIR/$tfile
3570         chown $RUNAS_ID $DIR/$tfile
3571         log 33_1
3572         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
3573         log 33_2
3574 }
3575 run_test 33aa "write file with mode 444 (should return error)"
3576
3577 test_33a() {
3578         rm -fr $DIR/$tdir
3579         test_mkdir $DIR/$tdir
3580         chown $RUNAS_ID $DIR/$tdir
3581         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile ||
3582                 error "$RUNAS create $tdir/$tfile failed"
3583         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile &&
3584                 error "open RDWR" || true
3585 }
3586 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
3587
3588 test_33b() {
3589         rm -fr $DIR/$tdir
3590         test_mkdir $DIR/$tdir
3591         chown $RUNAS_ID $DIR/$tdir
3592         $RUNAS $OPENFILE -f 1286739555 $DIR/$tdir/$tfile || true
3593 }
3594 run_test 33b "test open file with malformed flags (No panic)"
3595
3596 test_33c() {
3597         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3598         remote_ost_nodsh && skip "remote OST with nodsh"
3599
3600         local ostnum
3601         local ostname
3602         local write_bytes
3603         local all_zeros
3604
3605         all_zeros=:
3606         rm -fr $DIR/$tdir
3607         test_mkdir $DIR/$tdir
3608         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
3609
3610         sync
3611         for ostnum in $(seq $OSTCOUNT); do
3612                 # test-framework's OST numbering is one-based, while Lustre's
3613                 # is zero-based
3614                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
3615                 # Parsing llobdstat's output sucks; we could grep the /proc
3616                 # path, but that's likely to not be as portable as using the
3617                 # llobdstat utility.  So we parse lctl output instead.
3618                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
3619                         obdfilter/$ostname/stats |
3620                         awk '/^write_bytes/ {print $7}' )
3621                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
3622                 if (( ${write_bytes:-0} > 0 ))
3623                 then
3624                         all_zeros=false
3625                         break;
3626                 fi
3627         done
3628
3629         $all_zeros || return 0
3630
3631         # Write four bytes
3632         echo foo > $DIR/$tdir/bar
3633         # Really write them
3634         sync
3635
3636         # Total up write_bytes after writing.  We'd better find non-zeros.
3637         for ostnum in $(seq $OSTCOUNT); do
3638                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
3639                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
3640                         obdfilter/$ostname/stats |
3641                         awk '/^write_bytes/ {print $7}' )
3642                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
3643                 if (( ${write_bytes:-0} > 0 ))
3644                 then
3645                         all_zeros=false
3646                         break;
3647                 fi
3648         done
3649
3650         if $all_zeros
3651         then
3652                 for ostnum in $(seq $OSTCOUNT); do
3653                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
3654                         echo "Check that write_bytes is present in obdfilter/*/stats:"
3655                         do_facet ost$ostnum lctl get_param -n \
3656                                 obdfilter/$ostname/stats
3657                 done
3658                 error "OST not keeping write_bytes stats (b22312)"
3659         fi
3660 }
3661 run_test 33c "test llobdstat and write_bytes"
3662
3663 test_33d() {
3664         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
3665         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3666
3667         local MDTIDX=1
3668         local remote_dir=$DIR/$tdir/remote_dir
3669
3670         test_mkdir $DIR/$tdir
3671         $LFS mkdir -i $MDTIDX $remote_dir ||
3672                 error "create remote directory failed"
3673
3674         touch $remote_dir/$tfile
3675         chmod 444 $remote_dir/$tfile
3676         chown $RUNAS_ID $remote_dir/$tfile
3677
3678         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
3679
3680         chown $RUNAS_ID $remote_dir
3681         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
3682                                         error "create" || true
3683         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
3684                                     error "open RDWR" || true
3685         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
3686 }
3687 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
3688
3689 test_33e() {
3690         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3691
3692         mkdir $DIR/$tdir
3693
3694         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3695         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
3696         mkdir $DIR/$tdir/local_dir
3697
3698         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
3699         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
3700         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
3701
3702         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3703                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
3704
3705         rmdir $DIR/$tdir/* || error "rmdir failed"
3706
3707         umask 777
3708         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3709         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
3710         mkdir $DIR/$tdir/local_dir
3711
3712         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
3713         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
3714         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
3715
3716         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3717                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
3718
3719         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
3720
3721         umask 000
3722         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3723         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
3724         mkdir $DIR/$tdir/local_dir
3725
3726         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
3727         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
3728         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
3729
3730         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3731                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
3732 }
3733 run_test 33e "mkdir and striped directory should have same mode"
3734
3735 cleanup_33f() {
3736         trap 0
3737         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
3738 }
3739
3740 test_33f() {
3741         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3742         remote_mds_nodsh && skip "remote MDS with nodsh"
3743
3744         mkdir $DIR/$tdir
3745         chmod go+rwx $DIR/$tdir
3746         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
3747         trap cleanup_33f EXIT
3748
3749         $RUNAS lfs mkdir -i 0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
3750                 error "cannot create striped directory"
3751
3752         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
3753                 error "cannot create files in striped directory"
3754
3755         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
3756                 error "cannot remove files in striped directory"
3757
3758         $RUNAS rmdir $DIR/$tdir/striped_dir ||
3759                 error "cannot remove striped directory"
3760
3761         cleanup_33f
3762 }
3763 run_test 33f "nonroot user can create, access, and remove a striped directory"
3764
3765 test_33g() {
3766         mkdir -p $DIR/$tdir/dir2
3767
3768         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
3769         echo $err
3770         [[ $err =~ "exists" ]] || error "Not exists error"
3771 }
3772 run_test 33g "nonroot user create already existing root created file"
3773
3774 test_33h() {
3775         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3776         [ $MDS1_VERSION -lt $(version_code 2.13.50) ] &&
3777                 skip "Need MDS version at least 2.13.50"
3778
3779         test_mkdir -c $MDSCOUNT -H crush $DIR/$tdir ||
3780                 error "mkdir $tdir failed"
3781         touch $DIR/$tdir/$tfile || error "touch $tfile failed"
3782
3783         local index=$($LFS getstripe -m $DIR/$tdir/$tfile)
3784         local index2
3785
3786         for fname in $DIR/$tdir/$tfile.bak \
3787                      $DIR/$tdir/$tfile.SAV \
3788                      $DIR/$tdir/$tfile.orig \
3789                      $DIR/$tdir/$tfile~; do
3790                 touch $fname  || error "touch $fname failed"
3791                 index2=$($LFS getstripe -m $fname)
3792                 [ $index -eq $index2 ] ||
3793                         error "$fname MDT index mismatch $index != $index2"
3794         done
3795
3796         local failed=0
3797         for i in {1..50}; do
3798                 for fname in $(mktemp -u $DIR/$tdir/.$tfile.XXXXXX) \
3799                              $(mktemp $DIR/$tdir/$tfile.XXXXXXXX); do
3800                         touch $fname  || error "touch $fname failed"
3801                         index2=$($LFS getstripe -m $fname)
3802                         if [[ $index != $index2 ]]; then
3803                                 failed=$((failed + 1))
3804                                 echo "$fname MDT index mismatch $index != $index2"
3805                         fi
3806                 done
3807         done
3808         echo "$failed MDT index mismatches"
3809         (( failed < 4 )) || error "MDT index mismatch $failed times"
3810
3811 }
3812 run_test 33h "temp file is located on the same MDT as target"
3813
3814 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
3815 test_34a() {
3816         rm -f $DIR/f34
3817         $MCREATE $DIR/f34 || error "mcreate failed"
3818         $LFS getstripe $DIR/f34 2>&1 | grep -q "no stripe info" ||
3819                 error "getstripe failed"
3820         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error "truncate failed"
3821         $LFS getstripe $DIR/f34 2>&1 | grep -q "no stripe info" ||
3822                 error "getstripe failed"
3823         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3824                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3825 }
3826 run_test 34a "truncate file that has not been opened ==========="
3827
3828 test_34b() {
3829         [ ! -f $DIR/f34 ] && test_34a
3830         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3831                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3832         $OPENFILE -f O_RDONLY $DIR/f34
3833         $LFS getstripe $DIR/f34 2>&1 | grep -q "no stripe info" ||
3834                 error "getstripe failed"
3835         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3836                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3837 }
3838 run_test 34b "O_RDONLY opening file doesn't create objects ====="
3839
3840 test_34c() {
3841         [ ! -f $DIR/f34 ] && test_34a
3842         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3843                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3844         $OPENFILE -f O_RDWR $DIR/f34
3845         $LFS getstripe $DIR/f34 2>&1 | grep -q "no stripe info" &&
3846                 error "$LFS getstripe failed"
3847         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3848                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3849 }
3850 run_test 34c "O_RDWR opening file-with-size works =============="
3851
3852 test_34d() {
3853         [ ! -f $DIR/f34 ] && test_34a
3854         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 ||
3855                 error "dd failed"
3856         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3857                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3858         rm $DIR/f34
3859 }
3860 run_test 34d "write to sparse file ============================="
3861
3862 test_34e() {
3863         rm -f $DIR/f34e
3864         $MCREATE $DIR/f34e || error "mcreate failed"
3865         $TRUNCATE $DIR/f34e 1000 || error "truncate failed"
3866         $CHECKSTAT -s 1000 $DIR/f34e ||
3867                 error "Size of $DIR/f34e not equal to 1000 bytes"
3868         $OPENFILE -f O_RDWR $DIR/f34e
3869         $CHECKSTAT -s 1000 $DIR/f34e ||
3870                 error "Size of $DIR/f34e not equal to 1000 bytes"
3871 }
3872 run_test 34e "create objects, some with size and some without =="
3873
3874 test_34f() { # bug 6242, 6243
3875         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3876
3877         SIZE34F=48000
3878         rm -f $DIR/f34f
3879         $MCREATE $DIR/f34f || error "mcreate failed"
3880         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
3881         dd if=$DIR/f34f of=$TMP/f34f
3882         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
3883         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
3884         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
3885         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
3886         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
3887 }
3888 run_test 34f "read from a file with no objects until EOF ======="
3889
3890 test_34g() {
3891         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3892
3893         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE ||
3894                 error "dd failed"
3895         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error "truncate failed"
3896         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3897                 error "Size of $DIR/$tfile not equal to $((TEST_34_SIZE / 2))"
3898         cancel_lru_locks osc
3899         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3900                 error "wrong size after lock cancel"
3901
3902         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error "truncate failed"
3903         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3904                 error "expanding truncate failed"
3905         cancel_lru_locks osc
3906         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3907                 error "wrong expanded size after lock cancel"
3908 }
3909 run_test 34g "truncate long file ==============================="
3910
3911 test_34h() {
3912         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3913
3914         local gid=10
3915         local sz=1000
3916
3917         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error "dd failed"
3918         sync # Flush the cache so that multiop below does not block on cache
3919              # flush when getting the group lock
3920         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
3921         MULTIPID=$!
3922
3923         # Since just timed wait is not good enough, let's do a sync write
3924         # that way we are sure enough time for a roundtrip + processing
3925         # passed + 2 seconds of extra margin.
3926         dd if=/dev/zero of=$DIR/${tfile}-1 bs=$PAGE_SIZE oflag=direct count=1
3927         rm $DIR/${tfile}-1
3928         sleep 2
3929
3930         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
3931                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
3932                 kill -9 $MULTIPID
3933         fi
3934         wait $MULTIPID
3935         local nsz=`stat -c %s $DIR/$tfile`
3936         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
3937 }
3938 run_test 34h "ftruncate file under grouplock should not block"
3939
3940 test_35a() {
3941         cp /bin/sh $DIR/f35a
3942         chmod 444 $DIR/f35a
3943         chown $RUNAS_ID $DIR/f35a
3944         $RUNAS $DIR/f35a && error || true
3945         rm $DIR/f35a
3946 }
3947 run_test 35a "exec file with mode 444 (should return and not leak)"
3948
3949 test_36a() {
3950         rm -f $DIR/f36
3951         utime $DIR/f36 || error "utime failed for MDS"
3952 }
3953 run_test 36a "MDS utime check (mknod, utime)"
3954
3955 test_36b() {
3956         echo "" > $DIR/f36
3957         utime $DIR/f36 || error "utime failed for OST"
3958 }
3959 run_test 36b "OST utime check (open, utime)"
3960
3961 test_36c() {
3962         rm -f $DIR/d36/f36
3963         test_mkdir $DIR/d36
3964         chown $RUNAS_ID $DIR/d36
3965         $RUNAS utime $DIR/d36/f36 || error "utime failed for MDS as non-root"
3966 }
3967 run_test 36c "non-root MDS utime check (mknod, utime)"
3968
3969 test_36d() {
3970         [ ! -d $DIR/d36 ] && test_36c
3971         echo "" > $DIR/d36/f36
3972         $RUNAS utime $DIR/d36/f36 || error "utime failed for OST as non-root"
3973 }
3974 run_test 36d "non-root OST utime check (open, utime)"
3975
3976 test_36e() {
3977         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping"
3978
3979         test_mkdir $DIR/$tdir
3980         touch $DIR/$tdir/$tfile
3981         $RUNAS utime $DIR/$tdir/$tfile &&
3982                 error "utime worked, expected failure" || true
3983 }
3984 run_test 36e "utime on non-owned file (should return error)"
3985
3986 subr_36fh() {
3987         local fl="$1"
3988         local LANG_SAVE=$LANG
3989         local LC_LANG_SAVE=$LC_LANG
3990         export LANG=C LC_LANG=C # for date language
3991
3992         DATESTR="Dec 20  2000"
3993         test_mkdir $DIR/$tdir
3994         lctl set_param fail_loc=$fl
3995         date; date +%s
3996         cp /etc/hosts $DIR/$tdir/$tfile
3997         sync & # write RPC generated with "current" inode timestamp, but delayed
3998         sleep 1
3999         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
4000         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
4001         cancel_lru_locks $OSC
4002         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
4003         date; date +%s
4004         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
4005                 echo "BEFORE: $LS_BEFORE" && \
4006                 echo "AFTER : $LS_AFTER" && \
4007                 echo "WANT  : $DATESTR" && \
4008                 error "$DIR/$tdir/$tfile timestamps changed" || true
4009
4010         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
4011 }
4012
4013 test_36f() {
4014         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4015
4016         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4017         subr_36fh "0x80000214"
4018 }
4019 run_test 36f "utime on file racing with OST BRW write =========="
4020
4021 test_36g() {
4022         remote_ost_nodsh && skip "remote OST with nodsh"
4023         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4024         [ $MDS1_VERSION -lt $(version_code 2.12.51) ] &&
4025                 skip "Need MDS version at least 2.12.51"
4026
4027         local fmd_max_age
4028         local fmd
4029         local facet="ost1"
4030         local tgt="obdfilter"
4031
4032         [[ $OSC == "mdc" ]] && tgt="mdt" && facet="mds1"
4033
4034         test_mkdir $DIR/$tdir
4035         fmd_max_age=$(do_facet $facet \
4036                 "lctl get_param -n $tgt.*.tgt_fmd_seconds 2> /dev/null | \
4037                 head -n 1")
4038
4039         echo "FMD max age: ${fmd_max_age}s"
4040         touch $DIR/$tdir/$tfile
4041         fmd=$(do_facet $facet "lctl get_param -n $tgt.*.exports.*.fmd_count" |
4042                 gawk '{cnt=cnt+$1}  END{print cnt}')
4043         echo "FMD before: $fmd"
4044         [[ $fmd == 0 ]] &&
4045                 error "FMD wasn't create by touch"
4046         sleep $((fmd_max_age + 12))
4047         fmd=$(do_facet $facet "lctl get_param -n $tgt.*.exports.*.fmd_count" |
4048                 gawk '{cnt=cnt+$1}  END{print cnt}')
4049         echo "FMD after: $fmd"
4050         [[ $fmd == 0 ]] ||
4051                 error "FMD wasn't expired by ping"
4052 }
4053 run_test 36g "FMD cache expiry ====================="
4054
4055 test_36h() {
4056         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4057
4058         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
4059         subr_36fh "0x80000227"
4060 }
4061 run_test 36h "utime on file racing with OST BRW write =========="
4062
4063 test_36i() {
4064         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
4065
4066         test_mkdir $DIR/$tdir
4067         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
4068
4069         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
4070         local new_mtime=$((mtime + 200))
4071
4072         #change Modify time of striped dir
4073         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
4074                         error "change mtime failed"
4075
4076         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
4077
4078         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
4079 }
4080 run_test 36i "change mtime on striped directory"
4081
4082 # test_37 - duplicate with tests 32q 32r
4083
4084 test_38() {
4085         local file=$DIR/$tfile
4086         touch $file
4087         openfile -f O_DIRECTORY $file
4088         local RC=$?
4089         local ENOTDIR=20
4090         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
4091         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
4092 }
4093 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
4094
4095 test_39a() { # was test_39
4096         touch $DIR/$tfile
4097         touch $DIR/${tfile}2
4098 #       ls -l  $DIR/$tfile $DIR/${tfile}2
4099 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
4100 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
4101         sleep 2
4102         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
4103         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
4104                 echo "mtime"
4105                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
4106                 echo "atime"
4107                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
4108                 echo "ctime"
4109                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
4110                 error "O_TRUNC didn't change timestamps"
4111         fi
4112 }
4113 run_test 39a "mtime changed on create"
4114
4115 test_39b() {
4116         test_mkdir -c1 $DIR/$tdir
4117         cp -p /etc/passwd $DIR/$tdir/fopen
4118         cp -p /etc/passwd $DIR/$tdir/flink
4119         cp -p /etc/passwd $DIR/$tdir/funlink
4120         cp -p /etc/passwd $DIR/$tdir/frename
4121         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
4122
4123         sleep 1
4124         echo "aaaaaa" >> $DIR/$tdir/fopen
4125         echo "aaaaaa" >> $DIR/$tdir/flink
4126         echo "aaaaaa" >> $DIR/$tdir/funlink
4127         echo "aaaaaa" >> $DIR/$tdir/frename
4128
4129         local open_new=`stat -c %Y $DIR/$tdir/fopen`
4130         local link_new=`stat -c %Y $DIR/$tdir/flink`
4131         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
4132         local rename_new=`stat -c %Y $DIR/$tdir/frename`
4133
4134         cat $DIR/$tdir/fopen > /dev/null
4135         ln $DIR/$tdir/flink $DIR/$tdir/flink2
4136         rm -f $DIR/$tdir/funlink2
4137         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
4138
4139         for (( i=0; i < 2; i++ )) ; do
4140                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
4141                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
4142                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
4143                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
4144
4145                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
4146                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
4147                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
4148                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
4149
4150                 cancel_lru_locks $OSC
4151                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4152         done
4153 }
4154 run_test 39b "mtime change on open, link, unlink, rename  ======"
4155
4156 # this should be set to past
4157 TEST_39_MTIME=`date -d "1 year ago" +%s`
4158
4159 # bug 11063
4160 test_39c() {
4161         touch $DIR1/$tfile
4162         sleep 2
4163         local mtime0=`stat -c %Y $DIR1/$tfile`
4164
4165         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4166         local mtime1=`stat -c %Y $DIR1/$tfile`
4167         [ "$mtime1" = $TEST_39_MTIME ] || \
4168                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
4169
4170         local d1=`date +%s`
4171         echo hello >> $DIR1/$tfile
4172         local d2=`date +%s`
4173         local mtime2=`stat -c %Y $DIR1/$tfile`
4174         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
4175                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
4176
4177         mv $DIR1/$tfile $DIR1/$tfile-1
4178
4179         for (( i=0; i < 2; i++ )) ; do
4180                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
4181                 [ "$mtime2" = "$mtime3" ] || \
4182                         error "mtime ($mtime2) changed (to $mtime3) on rename"
4183
4184                 cancel_lru_locks $OSC
4185                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4186         done
4187 }
4188 run_test 39c "mtime change on rename ==========================="
4189
4190 # bug 21114
4191 test_39d() {
4192         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4193
4194         touch $DIR1/$tfile
4195         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4196
4197         for (( i=0; i < 2; i++ )) ; do
4198                 local mtime=`stat -c %Y $DIR1/$tfile`
4199                 [ $mtime = $TEST_39_MTIME ] || \
4200                         error "mtime($mtime) is not set to $TEST_39_MTIME"
4201
4202                 cancel_lru_locks $OSC
4203                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4204         done
4205 }
4206 run_test 39d "create, utime, stat =============================="
4207
4208 # bug 21114
4209 test_39e() {
4210         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4211
4212         touch $DIR1/$tfile
4213         local mtime1=`stat -c %Y $DIR1/$tfile`
4214
4215         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4216
4217         for (( i=0; i < 2; i++ )) ; do
4218                 local mtime2=`stat -c %Y $DIR1/$tfile`
4219                 [ $mtime2 = $TEST_39_MTIME ] || \
4220                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
4221
4222                 cancel_lru_locks $OSC
4223                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4224         done
4225 }
4226 run_test 39e "create, stat, utime, stat ========================"
4227
4228 # bug 21114
4229 test_39f() {
4230         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4231
4232         touch $DIR1/$tfile
4233         mtime1=`stat -c %Y $DIR1/$tfile`
4234
4235         sleep 2
4236         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4237
4238         for (( i=0; i < 2; i++ )) ; do
4239                 local mtime2=`stat -c %Y $DIR1/$tfile`
4240                 [ $mtime2 = $TEST_39_MTIME ] || \
4241                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
4242
4243                 cancel_lru_locks $OSC
4244                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4245         done
4246 }
4247 run_test 39f "create, stat, sleep, utime, stat ================="
4248
4249 # bug 11063
4250 test_39g() {
4251         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4252
4253         echo hello >> $DIR1/$tfile
4254         local mtime1=`stat -c %Y $DIR1/$tfile`
4255
4256         sleep 2
4257         chmod o+r $DIR1/$tfile
4258
4259         for (( i=0; i < 2; i++ )) ; do
4260                 local mtime2=`stat -c %Y $DIR1/$tfile`
4261                 [ "$mtime1" = "$mtime2" ] || \
4262                         error "lost mtime: $mtime2, should be $mtime1"
4263
4264                 cancel_lru_locks $OSC
4265                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4266         done
4267 }
4268 run_test 39g "write, chmod, stat ==============================="
4269
4270 # bug 11063
4271 test_39h() {
4272         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4273
4274         touch $DIR1/$tfile
4275         sleep 1
4276
4277         local d1=`date`
4278         echo hello >> $DIR1/$tfile
4279         local mtime1=`stat -c %Y $DIR1/$tfile`
4280
4281         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4282         local d2=`date`
4283         if [ "$d1" != "$d2" ]; then
4284                 echo "write and touch not within one second"
4285         else
4286                 for (( i=0; i < 2; i++ )) ; do
4287                         local mtime2=`stat -c %Y $DIR1/$tfile`
4288                         [ "$mtime2" = $TEST_39_MTIME ] || \
4289                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
4290
4291                         cancel_lru_locks $OSC
4292                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4293                 done
4294         fi
4295 }
4296 run_test 39h "write, utime within one second, stat ============="
4297
4298 test_39i() {
4299         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4300
4301         touch $DIR1/$tfile
4302         sleep 1
4303
4304         echo hello >> $DIR1/$tfile
4305         local mtime1=`stat -c %Y $DIR1/$tfile`
4306
4307         mv $DIR1/$tfile $DIR1/$tfile-1
4308
4309         for (( i=0; i < 2; i++ )) ; do
4310                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
4311
4312                 [ "$mtime1" = "$mtime2" ] || \
4313                         error "lost mtime: $mtime2, should be $mtime1"
4314
4315                 cancel_lru_locks $OSC
4316                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4317         done
4318 }
4319 run_test 39i "write, rename, stat =============================="
4320
4321 test_39j() {
4322         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4323
4324         start_full_debug_logging
4325         touch $DIR1/$tfile
4326         sleep 1
4327
4328         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
4329         lctl set_param fail_loc=0x80000412
4330         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
4331                 error "multiop failed"
4332         local multipid=$!
4333         local mtime1=`stat -c %Y $DIR1/$tfile`
4334
4335         mv $DIR1/$tfile $DIR1/$tfile-1
4336
4337         kill -USR1 $multipid
4338         wait $multipid || error "multiop close failed"
4339
4340         for (( i=0; i < 2; i++ )) ; do
4341                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
4342                 [ "$mtime1" = "$mtime2" ] ||
4343                         error "mtime is lost on close: $mtime2, " \
4344                               "should be $mtime1"
4345
4346                 cancel_lru_locks
4347                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4348         done
4349         lctl set_param fail_loc=0
4350         stop_full_debug_logging
4351 }
4352 run_test 39j "write, rename, close, stat ======================="
4353
4354 test_39k() {
4355         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4356
4357         touch $DIR1/$tfile
4358         sleep 1
4359
4360         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
4361         local multipid=$!
4362         local mtime1=`stat -c %Y $DIR1/$tfile`
4363
4364         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4365
4366         kill -USR1 $multipid
4367         wait $multipid || error "multiop close failed"
4368
4369         for (( i=0; i < 2; i++ )) ; do
4370                 local mtime2=`stat -c %Y $DIR1/$tfile`
4371
4372                 [ "$mtime2" = $TEST_39_MTIME ] || \
4373                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
4374
4375                 cancel_lru_locks
4376                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4377         done
4378 }
4379 run_test 39k "write, utime, close, stat ========================"
4380
4381 # this should be set to future
4382 TEST_39_ATIME=`date -d "1 year" +%s`
4383
4384 test_39l() {
4385         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4386         remote_mds_nodsh && skip "remote MDS with nodsh"
4387
4388         local atime_diff=$(do_facet $SINGLEMDS \
4389                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
4390         rm -rf $DIR/$tdir
4391         mkdir -p $DIR/$tdir
4392
4393         # test setting directory atime to future
4394         touch -a -d @$TEST_39_ATIME $DIR/$tdir
4395         local atime=$(stat -c %X $DIR/$tdir)
4396         [ "$atime" = $TEST_39_ATIME ] ||
4397                 error "atime is not set to future: $atime, $TEST_39_ATIME"
4398
4399         # test setting directory atime from future to now
4400         local now=$(date +%s)
4401         touch -a -d @$now $DIR/$tdir
4402
4403         atime=$(stat -c %X $DIR/$tdir)
4404         [ "$atime" -eq "$now"  ] ||
4405                 error "atime is not updated from future: $atime, $now"
4406
4407         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
4408         sleep 3
4409
4410         # test setting directory atime when now > dir atime + atime_diff
4411         local d1=$(date +%s)
4412         ls $DIR/$tdir
4413         local d2=$(date +%s)
4414         cancel_lru_locks mdc
4415         atime=$(stat -c %X $DIR/$tdir)
4416         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
4417                 error "atime is not updated  : $atime, should be $d2"
4418
4419         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
4420         sleep 3
4421
4422         # test not setting directory atime when now < dir atime + atime_diff
4423         ls $DIR/$tdir
4424         cancel_lru_locks mdc
4425         atime=$(stat -c %X $DIR/$tdir)
4426         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
4427                 error "atime is updated to $atime, should remain $d1<atime<$d2"
4428
4429         do_facet $SINGLEMDS \
4430                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
4431 }
4432 run_test 39l "directory atime update ==========================="
4433
4434 test_39m() {
4435         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4436
4437         touch $DIR1/$tfile
4438         sleep 2
4439         local far_past_mtime=$(date -d "May 29 1953" +%s)
4440         local far_past_atime=$(date -d "Dec 17 1903" +%s)
4441
4442         touch -m -d @$far_past_mtime $DIR1/$tfile
4443         touch -a -d @$far_past_atime $DIR1/$tfile
4444
4445         for (( i=0; i < 2; i++ )) ; do
4446                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
4447                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
4448                         error "atime or mtime set incorrectly"
4449
4450                 cancel_lru_locks $OSC
4451                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4452         done
4453 }
4454 run_test 39m "test atime and mtime before 1970"
4455
4456 test_39n() { # LU-3832
4457         remote_mds_nodsh && skip "remote MDS with nodsh"
4458
4459         local atime_diff=$(do_facet $SINGLEMDS \
4460                 lctl get_param -n mdd.*MDT0000*.atime_diff)
4461         local atime0
4462         local atime1
4463         local atime2
4464
4465         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
4466
4467         rm -rf $DIR/$tfile
4468         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
4469         atime0=$(stat -c %X $DIR/$tfile)
4470
4471         sleep 5
4472         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
4473         atime1=$(stat -c %X $DIR/$tfile)
4474
4475         sleep 5
4476         cancel_lru_locks mdc
4477         cancel_lru_locks osc
4478         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
4479         atime2=$(stat -c %X $DIR/$tfile)
4480
4481         do_facet $SINGLEMDS \
4482                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
4483
4484         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
4485         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
4486 }
4487 run_test 39n "check that O_NOATIME is honored"
4488
4489 test_39o() {
4490         TESTDIR=$DIR/$tdir/$tfile
4491         [ -e $TESTDIR ] && rm -rf $TESTDIR
4492         mkdir -p $TESTDIR
4493         cd $TESTDIR
4494         links1=2
4495         ls
4496         mkdir a b
4497         ls
4498         links2=$(stat -c %h .)
4499         [ $(($links1 + 2)) != $links2 ] &&
4500                 error "wrong links count $(($links1 + 2)) != $links2"
4501         rmdir b
4502         links3=$(stat -c %h .)
4503         [ $(($links1 + 1)) != $links3 ] &&
4504                 error "wrong links count $links1 != $links3"
4505         return 0
4506 }
4507 run_test 39o "directory cached attributes updated after create"
4508
4509 test_39p() {
4510         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
4511
4512         local MDTIDX=1
4513         TESTDIR=$DIR/$tdir/$tdir
4514         [ -e $TESTDIR ] && rm -rf $TESTDIR
4515         test_mkdir -p $TESTDIR
4516         cd $TESTDIR
4517         links1=2
4518         ls
4519         test_mkdir -i $MDTIDX $TESTDIR/remote_dir1
4520         test_mkdir -i $MDTIDX $TESTDIR/remote_dir2
4521         ls
4522         links2=$(stat -c %h .)
4523         [ $(($links1 + 2)) != $links2 ] &&
4524                 error "wrong links count $(($links1 + 2)) != $links2"
4525         rmdir remote_dir2
4526         links3=$(stat -c %h .)
4527         [ $(($links1 + 1)) != $links3 ] &&
4528                 error "wrong links count $links1 != $links3"
4529         return 0
4530 }
4531 run_test 39p "remote directory cached attributes updated after create ========"
4532
4533 test_39r() {
4534         [ $OST1_VERSION -ge $(version_code 2.13.52) ] ||
4535                 skip "no atime update on old OST"
4536         if [ "$ost1_FSTYPE" != ldiskfs ]; then
4537                 skip_env "ldiskfs only test"
4538         fi
4539
4540         local saved_adiff
4541         saved_adiff=$(do_facet ost1 \
4542                 lctl get_param -n obdfilter.*OST0000.atime_diff)
4543         stack_trap "do_facet ost1 \
4544                 lctl set_param obdfilter.*.atime_diff=$saved_adiff"
4545
4546         do_facet ost1 "lctl set_param obdfilter.*.atime_diff=5"
4547
4548         $LFS setstripe -i 0 $DIR/$tfile
4549         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 ||
4550                 error "can't write initial file"
4551         cancel_lru_locks osc
4552
4553         # exceed atime_diff and access file
4554         sleep 6
4555         dd if=$DIR/$tfile of=/dev/null || error "can't udpate atime"
4556
4557         local atime_cli=$(stat -c %X $DIR/$tfile)
4558         echo "client atime: $atime_cli"
4559         # allow atime update to be written to device
4560         do_facet ost1 "$LCTL set_param -n osd*.*OST*.force_sync 1"
4561         sleep 5
4562
4563         local ostdev=$(ostdevname 1)
4564         local fid=($(lfs getstripe -y $DIR/$tfile |
4565                         awk '/l_fid:/ { print $2 }' | tr ':' ' '))
4566         local objpath="O/0/d$((${fid[1]} % 32))/$((${fid[1]}))"
4567         local cmd="debugfs -c -R \\\"stat $objpath\\\" $ostdev"
4568
4569         echo "OST atime: $(do_facet ost1 "$cmd" |& grep atime)"
4570         local atime_ost=$(do_facet ost1 "$cmd" |&
4571                           awk -F'[: ]' '/atime:/ { print $4 }')
4572         (( atime_cli == atime_ost )) ||
4573                 error "atime on client $atime_cli != ost $atime_ost"
4574 }
4575 run_test 39r "lazy atime update on OST"
4576
4577 test_39q() { # LU-8041
4578         local testdir=$DIR/$tdir
4579         mkdir -p $testdir
4580         multiop_bg_pause $testdir D_c || error "multiop failed"
4581         local multipid=$!
4582         cancel_lru_locks mdc
4583         kill -USR1 $multipid
4584         local atime=$(stat -c %X $testdir)
4585         [ "$atime" -ne 0 ] || error "atime is zero"
4586 }
4587 run_test 39q "close won't zero out atime"
4588
4589 test_40() {
4590         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
4591         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
4592                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
4593         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
4594                 error "$tfile is not 4096 bytes in size"
4595 }
4596 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
4597
4598 test_41() {
4599         # bug 1553
4600         small_write $DIR/f41 18
4601 }
4602 run_test 41 "test small file write + fstat ====================="
4603
4604 count_ost_writes() {
4605         lctl get_param -n ${OSC}.*.stats |
4606                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
4607                         END { printf("%0.0f", writes) }'
4608 }
4609
4610 # decent default
4611 WRITEBACK_SAVE=500
4612 DIRTY_RATIO_SAVE=40
4613 MAX_DIRTY_RATIO=50
4614 BG_DIRTY_RATIO_SAVE=10
4615 MAX_BG_DIRTY_RATIO=25
4616
4617 start_writeback() {
4618         trap 0
4619         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
4620         # dirty_ratio, dirty_background_ratio
4621         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
4622                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
4623                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
4624                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
4625         else
4626                 # if file not here, we are a 2.4 kernel
4627                 kill -CONT `pidof kupdated`
4628         fi
4629 }
4630
4631 stop_writeback() {
4632         # setup the trap first, so someone cannot exit the test at the
4633         # exact wrong time and mess up a machine
4634         trap start_writeback EXIT
4635         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
4636         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
4637                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
4638                 sysctl -w vm.dirty_writeback_centisecs=0
4639                 sysctl -w vm.dirty_writeback_centisecs=0
4640                 # save and increase /proc/sys/vm/dirty_ratio
4641                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
4642                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
4643                 # save and increase /proc/sys/vm/dirty_background_ratio
4644                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
4645                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
4646         else
4647                 # if file not here, we are a 2.4 kernel
4648                 kill -STOP `pidof kupdated`
4649         fi
4650 }
4651
4652 # ensure that all stripes have some grant before we test client-side cache
4653 setup_test42() {
4654         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
4655                 dd if=/dev/zero of=$i bs=4k count=1
4656                 rm $i
4657         done
4658 }
4659
4660 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
4661 # file truncation, and file removal.
4662 test_42a() {
4663         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4664
4665         setup_test42
4666         cancel_lru_locks $OSC
4667         stop_writeback
4668         sync; sleep 1; sync # just to be safe
4669         BEFOREWRITES=`count_ost_writes`
4670         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
4671         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
4672         AFTERWRITES=`count_ost_writes`
4673         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
4674                 error "$BEFOREWRITES < $AFTERWRITES"
4675         start_writeback
4676 }
4677 run_test 42a "ensure that we don't flush on close"
4678
4679 test_42b() {
4680         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4681
4682         setup_test42
4683         cancel_lru_locks $OSC
4684         stop_writeback
4685         sync
4686         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
4687         BEFOREWRITES=$(count_ost_writes)
4688         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
4689         AFTERWRITES=$(count_ost_writes)
4690         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
4691                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
4692         fi
4693         BEFOREWRITES=$(count_ost_writes)
4694         sync || error "sync: $?"
4695         AFTERWRITES=$(count_ost_writes)
4696         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
4697                 error "$BEFOREWRITES < $AFTERWRITES on sync"
4698         fi
4699         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
4700         start_writeback
4701         return 0
4702 }
4703 run_test 42b "test destroy of file with cached dirty data ======"
4704
4705 # if these tests just want to test the effect of truncation,
4706 # they have to be very careful.  consider:
4707 # - the first open gets a {0,EOF}PR lock
4708 # - the first write conflicts and gets a {0, count-1}PW
4709 # - the rest of the writes are under {count,EOF}PW
4710 # - the open for truncate tries to match a {0,EOF}PR
4711 #   for the filesize and cancels the PWs.
4712 # any number of fixes (don't get {0,EOF} on open, match
4713 # composite locks, do smarter file size management) fix
4714 # this, but for now we want these tests to verify that
4715 # the cancellation with truncate intent works, so we
4716 # start the file with a full-file pw lock to match against
4717 # until the truncate.
4718 trunc_test() {
4719         test=$1
4720         file=$DIR/$test
4721         offset=$2
4722         cancel_lru_locks $OSC
4723         stop_writeback
4724         # prime the file with 0,EOF PW to match
4725         touch $file
4726         $TRUNCATE $file 0
4727         sync; sync
4728         # now the real test..
4729         dd if=/dev/zero of=$file bs=1024 count=100
4730         BEFOREWRITES=`count_ost_writes`
4731         $TRUNCATE $file $offset
4732         cancel_lru_locks $OSC
4733         AFTERWRITES=`count_ost_writes`
4734         start_writeback
4735 }
4736
4737 test_42c() {
4738         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4739
4740         trunc_test 42c 1024
4741         [ $BEFOREWRITES -eq $AFTERWRITES ] &&
4742                 error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
4743         rm $file
4744 }
4745 run_test 42c "test partial truncate of file with cached dirty data"
4746
4747 test_42d() {
4748         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4749
4750         trunc_test 42d 0
4751         [ $BEFOREWRITES -eq $AFTERWRITES ] ||
4752                 error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
4753         rm $file
4754 }
4755 run_test 42d "test complete truncate of file with cached dirty data"
4756
4757 test_42e() { # bug22074
4758         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4759
4760         local TDIR=$DIR/${tdir}e
4761         local pages=16 # hardcoded 16 pages, don't change it.
4762         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
4763         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
4764         local max_dirty_mb
4765         local warmup_files
4766
4767         test_mkdir $DIR/${tdir}e
4768         $LFS setstripe -c 1 $TDIR
4769         createmany -o $TDIR/f $files
4770
4771         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
4772
4773         # we assume that with $OSTCOUNT files, at least one of them will
4774         # be allocated on OST0.
4775         warmup_files=$((OSTCOUNT * max_dirty_mb))
4776         createmany -o $TDIR/w $warmup_files
4777
4778         # write a large amount of data into one file and sync, to get good
4779         # avail_grant number from OST.
4780         for ((i=0; i<$warmup_files; i++)); do
4781                 idx=$($LFS getstripe -i $TDIR/w$i)
4782                 [ $idx -ne 0 ] && continue
4783                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
4784                 break
4785         done
4786         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
4787         sync
4788         $LCTL get_param $proc_osc0/cur_dirty_bytes
4789         $LCTL get_param $proc_osc0/cur_grant_bytes
4790
4791         # create as much dirty pages as we can while not to trigger the actual
4792         # RPCs directly. but depends on the env, VFS may trigger flush during this
4793         # period, hopefully we are good.
4794         for ((i=0; i<$warmup_files; i++)); do
4795                 idx=$($LFS getstripe -i $TDIR/w$i)
4796                 [ $idx -ne 0 ] && continue
4797                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
4798         done
4799         $LCTL get_param $proc_osc0/cur_dirty_bytes
4800         $LCTL get_param $proc_osc0/cur_grant_bytes
4801
4802         # perform the real test
4803         $LCTL set_param $proc_osc0/rpc_stats 0
4804         for ((;i<$files; i++)); do
4805                 [ $($LFS getstripe -i $TDIR/f$i) -eq 0 ] || continue
4806                 dd if=/dev/zero of=$TDIR/f$i bs=$PAGE_SIZE count=$pages 2>/dev/null
4807         done
4808         sync
4809         $LCTL get_param $proc_osc0/rpc_stats
4810
4811         local percent=0
4812         local have_ppr=false
4813         $LCTL get_param $proc_osc0/rpc_stats |
4814                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
4815                         # skip lines until we are at the RPC histogram data
4816                         [ "$PPR" == "pages" ] && have_ppr=true && continue
4817                         $have_ppr || continue
4818
4819                         # we only want the percent stat for < 16 pages
4820                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
4821
4822                         percent=$((percent + WPCT))
4823                         if [[ $percent -gt 15 ]]; then
4824                                 error "less than 16-pages write RPCs" \
4825                                       "$percent% > 15%"
4826                                 break
4827                         fi
4828                 done
4829         rm -rf $TDIR
4830 }
4831 run_test 42e "verify sub-RPC writes are not done synchronously"
4832
4833 test_43A() { # was test_43
4834         test_mkdir $DIR/$tdir
4835         cp -p /bin/ls $DIR/$tdir/$tfile
4836         $MULTIOP $DIR/$tdir/$tfile Ow_c &
4837         pid=$!
4838         # give multiop a chance to open
4839         sleep 1
4840
4841         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
4842         kill -USR1 $pid
4843 }
4844 run_test 43A "execution of file opened for write should return -ETXTBSY"
4845
4846 test_43a() {
4847         test_mkdir $DIR/$tdir
4848         cp -p $(which sleep) $DIR/$tdir/sleep || error "can't copy"
4849         $DIR/$tdir/sleep 60 &
4850         SLEEP_PID=$!
4851         # Make sure exec of $tdir/sleep wins race with truncate
4852         sleep 1
4853         $MULTIOP $DIR/$tdir/sleep Oc && error "expected error, got success"
4854         kill $SLEEP_PID
4855 }
4856 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
4857
4858 test_43b() {
4859         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4860
4861         test_mkdir $DIR/$tdir
4862         cp -p $(which sleep) $DIR/$tdir/sleep || error "can't copy"
4863         $DIR/$tdir/sleep 60 &
4864         SLEEP_PID=$!
4865         # Make sure exec of $tdir/sleep wins race with truncate
4866         sleep 1
4867         $TRUNCATE $DIR/$tdir/sleep 0 && error "expected error, got success"
4868         kill $SLEEP_PID
4869 }
4870 run_test 43b "truncate of file being executed should return -ETXTBSY"
4871
4872 test_43c() {
4873         local testdir="$DIR/$tdir"
4874         test_mkdir $testdir
4875         cp $SHELL $testdir/
4876         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
4877                 ( cd $testdir && md5sum -c )
4878 }
4879 run_test 43c "md5sum of copy into lustre"
4880
4881 test_44A() { # was test_44
4882         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4883
4884         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
4885         dd if=$DIR/f1 bs=4k count=1 > /dev/null
4886 }
4887 run_test 44A "zero length read from a sparse stripe"
4888
4889 test_44a() {
4890         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
4891                 awk '{ print $2 }')
4892         [ -z "$nstripe" ] && skip "can't get stripe info"
4893         [[ $nstripe -gt $OSTCOUNT ]] &&
4894                 skip "Wrong default_stripe_count: $nstripe OSTCOUNT: $OSTCOUNT"
4895
4896         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
4897                 awk '{ print $2 }')
4898         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
4899                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
4900                         awk '{ print $2 }')
4901         fi
4902
4903         OFFSETS="0 $((stride/2)) $((stride-1))"
4904         for offset in $OFFSETS; do
4905                 for i in $(seq 0 $((nstripe-1))); do
4906                         local GLOBALOFFSETS=""
4907                         # size in Bytes
4908                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
4909                         local myfn=$DIR/d44a-$size
4910                         echo "--------writing $myfn at $size"
4911                         ll_sparseness_write $myfn $size ||
4912                                 error "ll_sparseness_write"
4913                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
4914                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
4915                                 error "ll_sparseness_verify $GLOBALOFFSETS"
4916
4917                         for j in $(seq 0 $((nstripe-1))); do
4918                                 # size in Bytes
4919                                 size=$((((j + $nstripe )*$stride + $offset)))
4920                                 ll_sparseness_write $myfn $size ||
4921                                         error "ll_sparseness_write"
4922                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
4923                         done
4924                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
4925                                 error "ll_sparseness_verify $GLOBALOFFSETS"
4926                         rm -f $myfn
4927                 done
4928         done
4929 }
4930 run_test 44a "test sparse pwrite ==============================="
4931
4932 dirty_osc_total() {
4933         tot=0
4934         for d in `lctl get_param -n ${OSC}.*.cur_dirty_bytes`; do
4935                 tot=$(($tot + $d))
4936         done
4937         echo $tot
4938 }
4939 do_dirty_record() {
4940         before=`dirty_osc_total`
4941         echo executing "\"$*\""
4942         eval $*
4943         after=`dirty_osc_total`
4944         echo before $before, after $after
4945 }
4946 test_45() {
4947         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4948
4949         f="$DIR/f45"
4950         # Obtain grants from OST if it supports it
4951         echo blah > ${f}_grant
4952         stop_writeback
4953         sync
4954         do_dirty_record "echo blah > $f"
4955         [[ $before -eq $after ]] && error "write wasn't cached"
4956         do_dirty_record "> $f"
4957         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
4958         do_dirty_record "echo blah > $f"
4959         [[ $before -eq $after ]] && error "write wasn't cached"
4960         do_dirty_record "sync"
4961         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
4962         do_dirty_record "echo blah > $f"
4963         [[ $before -eq $after ]] && error "write wasn't cached"
4964         do_dirty_record "cancel_lru_locks osc"
4965         [[ $before -gt $after ]] ||
4966                 error "lock cancellation didn't lower dirty count"
4967         start_writeback
4968 }
4969 run_test 45 "osc io page accounting ============================"
4970
4971 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
4972 # test tickles a bug where re-dirtying a page was failing to be mapped to the
4973 # objects offset and an assert hit when an rpc was built with 1023's mapped
4974 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
4975 test_46() {
4976         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4977
4978         f="$DIR/f46"
4979         stop_writeback
4980         sync
4981         dd if=/dev/zero of=$f bs=$PAGE_SIZE seek=511 count=1
4982         sync
4983         dd conv=notrunc if=/dev/zero of=$f bs=$PAGE_SIZE seek=1023 count=1
4984         dd conv=notrunc if=/dev/zero of=$f bs=$PAGE_SIZE seek=511 count=1
4985         sync
4986         start_writeback
4987 }
4988 run_test 46 "dirtying a previously written page ================"
4989
4990 # test_47 is removed "Device nodes check" is moved to test_28
4991
4992 test_48a() { # bug 2399
4993         [ "$mds1_FSTYPE" = "zfs" ] &&
4994         [ $MDS1_VERSION -lt $(version_code 2.3.63) ] &&
4995                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly"
4996
4997         test_mkdir $DIR/$tdir
4998         cd $DIR/$tdir
4999         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
5000         test_mkdir $DIR/$tdir
5001         touch foo || error "'touch foo' failed after recreating cwd"
5002         test_mkdir bar
5003         touch .foo || error "'touch .foo' failed after recreating cwd"
5004         test_mkdir .bar
5005         ls . > /dev/null || error "'ls .' failed after recreating cwd"
5006         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
5007         cd . || error "'cd .' failed after recreating cwd"
5008         mkdir . && error "'mkdir .' worked after recreating cwd"
5009         rmdir . && error "'rmdir .' worked after recreating cwd"
5010         ln -s . baz || error "'ln -s .' failed after recreating cwd"
5011         cd .. || error "'cd ..' failed after recreating cwd"
5012 }
5013 run_test 48a "Access renamed working dir (should return errors)="
5014
5015 test_48b() { # bug 2399
5016         rm -rf $DIR/$tdir
5017         test_mkdir $DIR/$tdir
5018         cd $DIR/$tdir
5019         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
5020         touch foo && error "'touch foo' worked after removing cwd"
5021         mkdir foo && error "'mkdir foo' worked after removing cwd"
5022         touch .foo && error "'touch .foo' worked after removing cwd"
5023         mkdir .foo && error "'mkdir .foo' worked after removing cwd"
5024         ls . > /dev/null && error "'ls .' worked after removing cwd"
5025         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
5026         mkdir . && error "'mkdir .' worked after removing cwd"
5027         rmdir . && error "'rmdir .' worked after removing cwd"
5028         ln -s . foo && error "'ln -s .' worked after removing cwd"
5029         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
5030 }
5031 run_test 48b "Access removed working dir (should return errors)="
5032
5033 test_48c() { # bug 2350
5034         #lctl set_param debug=-1
5035         #set -vx
5036         rm -rf $DIR/$tdir
5037         test_mkdir -p $DIR/$tdir/dir
5038         cd $DIR/$tdir/dir
5039         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
5040         $TRACE touch foo && error "touch foo worked after removing cwd"
5041         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
5042         touch .foo && error "touch .foo worked after removing cwd"
5043         mkdir .foo && error "mkdir .foo worked after removing cwd"
5044         $TRACE ls . && error "'ls .' worked after removing cwd"
5045         $TRACE ls .. || error "'ls ..' failed after removing cwd"
5046         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
5047         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
5048         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
5049         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
5050 }
5051 run_test 48c "Access removed working subdir (should return errors)"
5052
5053 test_48d() { # bug 2350
5054         #lctl set_param debug=-1
5055         #set -vx
5056         rm -rf $DIR/$tdir
5057         test_mkdir -p $DIR/$tdir/dir
5058         cd $DIR/$tdir/dir
5059         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
5060         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
5061         $TRACE touch foo && error "'touch foo' worked after removing parent"
5062         $TRACE mkdir foo && error "mkdir foo worked after removing parent"
5063         touch .foo && error "'touch .foo' worked after removing parent"
5064         mkdir .foo && error "mkdir .foo worked after removing parent"
5065         $TRACE ls . && error "'ls .' worked after removing parent"
5066         $TRACE ls .. && error "'ls ..' worked after removing parent"
5067         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
5068         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
5069         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
5070         true
5071 }
5072 run_test 48d "Access removed parent subdir (should return errors)"
5073
5074 test_48e() { # bug 4134
5075         #lctl set_param debug=-1
5076         #set -vx
5077         rm -rf $DIR/$tdir
5078         test_mkdir -p $DIR/$tdir/dir
5079         cd $DIR/$tdir/dir
5080         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
5081         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
5082         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
5083         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
5084         # On a buggy kernel addition of "touch foo" after cd .. will
5085         # produce kernel oops in lookup_hash_it
5086         touch ../foo && error "'cd ..' worked after recreate parent"
5087         cd $DIR
5088         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
5089 }
5090 run_test 48e "Access to recreated parent subdir (should return errors)"
5091
5092 test_49() { # LU-1030
5093         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5094         remote_ost_nodsh && skip "remote OST with nodsh"
5095
5096         # get ost1 size - $FSNAME-OST0000
5097         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
5098                 awk '{ print $4 }')
5099         # write 800M at maximum
5100         [[ $ost1_size -lt 2 ]] && ost1_size=2
5101         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
5102
5103         $LFS setstripe -c 1 -i 0 $DIR/$tfile
5104         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
5105         local dd_pid=$!
5106
5107         # change max_pages_per_rpc while writing the file
5108         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
5109         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
5110         # loop until dd process exits
5111         while ps ax -opid | grep -wq $dd_pid; do
5112                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
5113                 sleep $((RANDOM % 5 + 1))
5114         done
5115         # restore original max_pages_per_rpc
5116         $LCTL set_param $osc1_mppc=$orig_mppc
5117         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
5118 }
5119 run_test 49 "Change max_pages_per_rpc won't break osc extent"
5120
5121 test_50() {
5122         # bug 1485
5123         test_mkdir $DIR/$tdir
5124         cd $DIR/$tdir
5125         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
5126 }
5127 run_test 50 "special situations: /proc symlinks  ==============="
5128
5129 test_51a() {    # was test_51
5130         # bug 1516 - create an empty entry right after ".." then split dir
5131         test_mkdir -c1 $DIR/$tdir
5132         touch $DIR/$tdir/foo
5133         $MCREATE $DIR/$tdir/bar
5134         rm $DIR/$tdir/foo
5135         createmany -m $DIR/$tdir/longfile 201
5136         FNUM=202
5137         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
5138                 $MCREATE $DIR/$tdir/longfile$FNUM
5139                 FNUM=$(($FNUM + 1))
5140                 echo -n "+"
5141         done
5142         echo
5143         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
5144 }
5145 run_test 51a "special situations: split htree with empty entry =="
5146
5147 cleanup_print_lfs_df () {
5148         trap 0
5149         $LFS df
5150         $LFS df -i
5151 }
5152
5153 test_51b() {
5154         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5155
5156         local dir=$DIR/$tdir
5157         local nrdirs=$((65536 + 100))
5158
5159         # cleanup the directory
5160         rm -fr $dir
5161
5162         test_mkdir -c1 $dir
5163
5164         $LFS df
5165         $LFS df -i
5166         local mdtidx=$(printf "%04x" $($LFS getstripe -m $dir))
5167         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
5168         [[ $numfree -lt $nrdirs ]] &&
5169                 skip "not enough free inodes ($numfree) on MDT$mdtidx"
5170
5171         # need to check free space for the directories as well
5172         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
5173         numfree=$(( blkfree / $(fs_inode_ksize) ))
5174         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)"
5175
5176         trap cleanup_print_lfs_df EXIT
5177
5178         # create files
5179         createmany -d $dir/d $nrdirs || {
5180                 unlinkmany $dir/d $nrdirs
5181                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
5182         }
5183
5184         # really created :
5185         nrdirs=$(ls -U $dir | wc -l)
5186
5187         # unlink all but 100 subdirectories, then check it still works
5188         local left=100
5189         local delete=$((nrdirs - left))
5190
5191         $LFS df
5192         $LFS df -i
5193
5194         # for ldiskfs the nlink count should be 1, but this is OSD specific
5195         # and so this is listed for informational purposes only
5196         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
5197         unlinkmany -d $dir/d $delete ||
5198                 error "unlink of first $delete subdirs failed"
5199
5200         echo "nlink between: $(stat -c %h $dir)"
5201         local found=$(ls -U $dir | wc -l)
5202         [ $found -ne $left ] &&
5203                 error "can't find subdirs: found only $found, expected $left"
5204
5205         unlinkmany -d $dir/d $delete $left ||
5206                 error "unlink of second $left subdirs failed"
5207         # regardless of whether the backing filesystem tracks nlink accurately
5208         # or not, the nlink count shouldn't be more than "." and ".." here
5209         local after=$(stat -c %h $dir)
5210         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
5211                 echo "nlink after: $after"
5212
5213         cleanup_print_lfs_df
5214 }
5215 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
5216
5217 test_51d() {
5218         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5219         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs"
5220
5221         test_mkdir $DIR/$tdir
5222         createmany -o $DIR/$tdir/t- 1000
5223         $LFS getstripe $DIR/$tdir > $TMP/$tfile
5224         for N in $(seq 0 $((OSTCOUNT - 1))); do
5225                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
5226                         END { printf("%0.0f", objs) }' $TMP/$tfile)
5227                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
5228                         '($1 == '$N') { objs += 1 } \
5229                         END { printf("%0.0f", objs) }')
5230                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
5231         done
5232         unlinkmany $DIR/$tdir/t- 1000
5233
5234         NLAST=0
5235         for N in $(seq 1 $((OSTCOUNT - 1))); do
5236                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
5237                         error "OST $N has less objects vs OST $NLAST" \
5238                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
5239                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
5240                         error "OST $N has less objects vs OST $NLAST" \
5241                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
5242
5243                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
5244                         error "OST $N has less #0 objects vs OST $NLAST" \
5245                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
5246                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
5247                         error "OST $N has less #0 objects vs OST $NLAST" \
5248                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
5249                 NLAST=$N
5250         done
5251         rm -f $TMP/$tfile
5252 }
5253 run_test 51d "check object distribution"
5254
5255 test_51e() {
5256         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5257                 skip_env "ldiskfs only test"
5258         fi
5259
5260         test_mkdir -c1 $DIR/$tdir
5261         test_mkdir -c1 $DIR/$tdir/d0
5262
5263         touch $DIR/$tdir/d0/foo
5264         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
5265                 error "file exceed 65000 nlink limit!"
5266         unlinkmany $DIR/$tdir/d0/f- 65001
5267         return 0
5268 }
5269 run_test 51e "check file nlink limit"
5270
5271 test_51f() {
5272         test_mkdir $DIR/$tdir
5273
5274         local max=100000
5275         local ulimit_old=$(ulimit -n)
5276         local spare=20 # number of spare fd's for scripts/libraries, etc.
5277         local mdt=$($LFS getstripe -m $DIR/$tdir)
5278         local numfree=$($LFS df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
5279
5280         echo "MDT$mdt numfree=$numfree, max=$max"
5281         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
5282         if [ $((numfree + spare)) -gt $ulimit_old ]; then
5283                 while ! ulimit -n $((numfree + spare)); do
5284                         numfree=$((numfree * 3 / 4))
5285                 done
5286                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
5287         else
5288                 echo "left ulimit at $ulimit_old"
5289         fi
5290
5291         createmany -o -k -t 120 $DIR/$tdir/f $numfree || {
5292                 unlinkmany $DIR/$tdir/f $numfree
5293                 error "create+open $numfree files in $DIR/$tdir failed"
5294         }
5295         ulimit -n $ulimit_old
5296
5297         # if createmany exits at 120s there will be fewer than $numfree files
5298         unlinkmany $DIR/$tdir/f $numfree || true
5299 }
5300 run_test 51f "check many open files limit"
5301
5302 test_52a() {
5303         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
5304         test_mkdir $DIR/$tdir
5305         touch $DIR/$tdir/foo
5306         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
5307         echo bar >> $DIR/$tdir/foo || error "append bar failed"
5308         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
5309         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
5310         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
5311                                         error "link worked"
5312         echo foo >> $DIR/$tdir/foo || error "append foo failed"
5313         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
5314         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
5315                                                      error "lsattr"
5316         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
5317         cp -r $DIR/$tdir $TMP/
5318         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
5319 }
5320 run_test 52a "append-only flag test (should return errors)"
5321
5322 test_52b() {
5323         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
5324         test_mkdir $DIR/$tdir
5325         touch $DIR/$tdir/foo
5326         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
5327         cat test > $DIR/$tdir/foo && error "cat test worked"
5328         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
5329         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
5330         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
5331                                         error "link worked"
5332         echo foo >> $DIR/$tdir/foo && error "echo worked"
5333         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
5334         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
5335         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
5336         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
5337                                                         error "lsattr"
5338         chattr -i $DIR/$tdir/foo || error "chattr failed"
5339
5340         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
5341 }
5342 run_test 52b "immutable flag test (should return errors) ======="
5343
5344 test_53() {
5345         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5346         remote_mds_nodsh && skip "remote MDS with nodsh"
5347         remote_ost_nodsh && skip "remote OST with nodsh"
5348
5349         local param
5350         local param_seq
5351         local ostname
5352         local mds_last
5353         local mds_last_seq
5354         local ost_last
5355         local ost_last_seq
5356         local ost_last_id
5357         local ostnum
5358         local node
5359         local found=false
5360         local support_last_seq=true
5361
5362         [[ $MDS1_VERSION -ge $(version_code 2.3.60) ]] ||
5363                 support_last_seq=false
5364
5365         # only test MDT0000
5366         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
5367         local value
5368         for value in $(do_facet $SINGLEMDS \
5369                        $LCTL get_param osp.$mdtosc.prealloc_last_id) ; do
5370                 param=$(echo ${value[0]} | cut -d "=" -f1)
5371                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
5372
5373                 if $support_last_seq; then
5374                         param_seq=$(echo $param |
5375                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
5376                         mds_last_seq=$(do_facet $SINGLEMDS \
5377                                        $LCTL get_param -n $param_seq)
5378                 fi
5379                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
5380
5381                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
5382                 node=$(facet_active_host ost$((ostnum+1)))
5383                 param="obdfilter.$ostname.last_id"
5384                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
5385                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
5386                         ost_last_id=$ost_last
5387
5388                         if $support_last_seq; then
5389                                 ost_last_id=$(echo $ost_last |
5390                                               awk -F':' '{print $2}' |
5391                                               sed -e "s/^0x//g")
5392                                 ost_last_seq=$(echo $ost_last |
5393                                                awk -F':' '{print $1}')
5394                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
5395                         fi
5396
5397                         if [[ $ost_last_id != $mds_last ]]; then
5398                                 error "$ost_last_id != $mds_last"
5399                         else
5400                                 found=true
5401                                 break
5402                         fi
5403                 done
5404         done
5405         $found || error "can not match last_seq/last_id for $mdtosc"
5406         return 0
5407 }
5408 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
5409
5410 test_54a() {
5411         perl -MSocket -e ';' || skip "no Socket perl module installed"
5412
5413         $SOCKETSERVER $DIR/socket ||
5414                 error "$SOCKETSERVER $DIR/socket failed: $?"
5415         $SOCKETCLIENT $DIR/socket ||
5416                 error "$SOCKETCLIENT $DIR/socket failed: $?"
5417         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
5418 }
5419 run_test 54a "unix domain socket test =========================="
5420
5421 test_54b() {
5422         f="$DIR/f54b"
5423         mknod $f c 1 3
5424         chmod 0666 $f
5425         dd if=/dev/zero of=$f bs=$PAGE_SIZE count=1
5426 }
5427 run_test 54b "char device works in lustre ======================"
5428
5429 find_loop_dev() {
5430         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
5431         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
5432         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
5433
5434         for i in $(seq 3 7); do
5435                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
5436                 LOOPDEV=$LOOPBASE$i
5437                 LOOPNUM=$i
5438                 break
5439         done
5440 }
5441
5442 cleanup_54c() {
5443         local rc=0
5444         loopdev="$DIR/loop54c"
5445
5446         trap 0
5447         $UMOUNT $DIR/$tdir || rc=$?
5448         losetup -d $loopdev || true
5449         losetup -d $LOOPDEV || true
5450         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
5451         return $rc
5452 }
5453
5454 test_54c() {
5455         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5456
5457         loopdev="$DIR/loop54c"
5458
5459         find_loop_dev
5460         [ -z "$LOOPNUM" ] && skip_env "couldn't find empty loop device"
5461         trap cleanup_54c EXIT
5462         mknod $loopdev b 7 $LOOPNUM
5463         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
5464         dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE seek=1024 count=1 > /dev/null
5465         losetup $loopdev $DIR/$tfile ||
5466                 error "can't set up $loopdev for $DIR/$tfile"
5467         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
5468         test_mkdir $DIR/$tdir
5469         mount -t ext2 $loopdev $DIR/$tdir ||
5470                 error "error mounting $loopdev on $DIR/$tdir"
5471         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$PAGE_SIZE count=30 ||
5472                 error "dd write"
5473         df $DIR/$tdir
5474         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$PAGE_SIZE count=30 ||
5475                 error "dd read"
5476         cleanup_54c
5477 }
5478 run_test 54c "block device works in lustre ====================="
5479
5480 test_54d() {
5481         f="$DIR/f54d"
5482         string="aaaaaa"
5483         mknod $f p
5484         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
5485 }
5486 run_test 54d "fifo device works in lustre ======================"
5487
5488 test_54e() {
5489         f="$DIR/f54e"
5490         string="aaaaaa"
5491         cp -aL /dev/console $f
5492         echo $string > $f || error "echo $string to $f failed"
5493 }
5494 run_test 54e "console/tty device works in lustre ======================"
5495
5496 test_56a() {
5497         local numfiles=3
5498         local dir=$DIR/$tdir
5499
5500         rm -rf $dir
5501         test_mkdir -p $dir/dir
5502         for i in $(seq $numfiles); do
5503                 touch $dir/file$i
5504                 touch $dir/dir/file$i
5505         done
5506
5507         local numcomp=$($LFS getstripe --component-count $dir)
5508
5509         [[ $numcomp == 0 ]] && numcomp=1
5510
5511         # test lfs getstripe with --recursive
5512         local filenum=$($LFS getstripe -r $dir | egrep -c "obdidx|l_ost_idx")
5513
5514         [[ $filenum -eq $((numfiles * 2)) ]] ||
5515                 error "$LFS getstripe -r: found $filenum != $((numfiles * 2))"
5516         filenum=$($LFS getstripe $dir | egrep -c "obdidx|l_ost_idx")
5517         [[ $filenum -eq $numfiles ]] ||
5518                 error "$LFS getstripe $dir: found $filenum, not $numfiles"
5519         echo "$LFS getstripe showed obdidx or l_ost_idx"
5520
5521         # test lfs getstripe with file instead of dir
5522         filenum=$($LFS getstripe $dir/file1 | egrep -c "obdidx|l_ost_idx")
5523         [[ $filenum -eq 1 ]] ||
5524                 error "$LFS getstripe $dir/file1: found $filenum, not 1"
5525         echo "$LFS getstripe file1 passed"
5526
5527         #test lfs getstripe with --verbose
5528         filenum=$($LFS getstripe --verbose $dir | grep -c lmm_magic)
5529         [[ $filenum -eq $((numfiles * numcomp)) ]] ||
5530                 error "$LFS getstripe --verbose $dir: "\
5531                       "got $filenum want $((numfiles * numcomp)) lmm_magic"
5532         [[ $($LFS getstripe $dir | grep -c lmm_magic) -eq 0 ]] ||
5533                 error "$LFS getstripe $dir: showed lmm_magic"
5534
5535         #test lfs getstripe with -v prints lmm_fid
5536         filenum=$($LFS getstripe -v $dir | grep -c lmm_fid)
5537         [[ $filenum -eq $((numfiles * numcomp)) ]] ||
5538                 error "$LFS getstripe -v $dir: "\
5539                       "got $filenum want $((numfiles * numcomp)) lmm_fid"
5540         [[ $($LFS getstripe $dir | grep -c lmm_fid) -eq 0 ]] ||
5541                 error "$LFS getstripe $dir: showed lmm_fid by default"
5542         echo "$LFS getstripe --verbose passed"
5543
5544         #check for FID information
5545         local fid1=$($LFS getstripe --fid $dir/file1)
5546         local fid2=$($LFS getstripe --verbose $dir/file1 |
5547                      awk '/lmm_fid: / { print $2; exit; }')
5548         local fid3=$($LFS path2fid $dir/file1)
5549
5550         [ "$fid1" != "$fid2" ] &&
5551                 error "getstripe --fid '$fid1' != getstripe --verbose '$fid2'"
5552         [ "$fid1" != "$fid3" ] &&
5553                 error "getstripe --fid '$fid1' != lfs path2fid '$fid3'"
5554         echo "$LFS getstripe --fid passed"
5555
5556         #test lfs getstripe with --obd
5557         $LFS getstripe --obd wrong_uuid $dir 2>&1 | grep -q "unknown obduuid" ||
5558                 error "$LFS getstripe --obd wrong_uuid: should return error"
5559
5560         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
5561
5562         local ostidx=1
5563         local obduuid=$(ostuuid_from_index $ostidx)
5564         local found=$($LFS getstripe -r --obd $obduuid $dir |
5565                 grep 'lmm_stripe_offset:' | grep -c " $ostidx\$")
5566
5567         filenum=$($LFS getstripe -ir $dir | grep -c "^$ostidx\$")
5568         [[ $($LFS getstripe -id $dir) -ne $ostidx ]] ||
5569                 ((filenum--))
5570         [[ $($LFS getstripe -id $dir/dir) -ne $ostidx ]] ||
5571                 ((filenum--))
5572
5573         [[ $found -eq $filenum ]] ||
5574                 error "$LFS getstripe --obd: found $found expect $filenum"
5575         [[ $($LFS getstripe -r -v --obd $obduuid $dir |
5576                 sed '/^[         ]*'${ostidx}'[  ]/d' |
5577                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
5578                 error "$LFS getstripe --obd: should not show file on other obd"
5579         echo "$LFS getstripe --obd passed"
5580 }
5581 run_test 56a "check $LFS getstripe"
5582
5583 test_56b() {
5584         local dir=$DIR/$tdir
5585         local numdirs=3
5586
5587         test_mkdir $dir
5588         for i in $(seq $numdirs); do
5589                 test_mkdir $dir/dir$i
5590         done
5591
5592         # test lfs getdirstripe default mode is non-recursion, which is
5593         # different from lfs getstripe
5594         local dircnt=$($LFS getdirstripe $dir | grep -c lmv_stripe_count)
5595
5596         [[ $dircnt -eq 1 ]] ||
5597                 error "$LFS getdirstripe: found $dircnt, not 1"
5598         dircnt=$($LFS getdirstripe --recursive $dir |
5599                 grep -c lmv_stripe_count)
5600         [[ $dircnt -eq $((numdirs + 1)) ]] ||
5601                 error "$LFS getdirstripe -r: $dircnt, != $((numdirs + 1))"
5602 }
5603 run_test 56b "check $LFS getdirstripe"
5604
5605 test_56c() {
5606         remote_ost_nodsh && skip "remote OST with nodsh"
5607
5608         local ost_idx=0
5609         local ost_name=$(ostname_from_index $ost_idx)
5610         local old_status=$(ost_dev_status $ost_idx)
5611
5612         [[ -z "$old_status" ]] ||
5613                 skip_env "OST $ost_name is in $old_status status"
5614
5615         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
5616         [[ $OST1_VERSION -ge $(version_code 2.12.55) ]] && do_facet ost1 \
5617                 $LCTL set_param -n obdfilter.$ost_name.no_precreate=1
5618         sleep_maxage
5619
5620         local new_status=$(ost_dev_status $ost_idx)
5621
5622         [[ "$new_status" =~ "D" ]] ||
5623                 error "$ost_name status is '$new_status', missing 'D'"
5624         if [[ $OST1_VERSION -ge $(version_code 2.12.55) ]]; then
5625                 [[ "$new_status" =~ "N" ]] ||
5626                         error "$ost_name status is '$new_status', missing 'N'"
5627         fi
5628
5629         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
5630         [[ $OST1_VERSION -ge $(version_code 2.12.55) ]] && do_facet ost1 \
5631                 $LCTL set_param -n obdfilter.$ost_name.no_precreate=0
5632         sleep_maxage
5633
5634         new_status=$(ost_dev_status $ost_idx)
5635         [[ ! "$new_status" =~ "D" && ! "$new_status" =~ "N" ]] ||
5636                 error "$ost_name status is '$new_status', has 'D' and/or 'N'"
5637 }
5638 run_test 56c "check 'lfs df' showing device status"
5639
5640 NUMFILES=3
5641 NUMDIRS=3
5642 setup_56() {
5643         local local_tdir="$1"
5644         local local_numfiles="$2"
5645         local local_numdirs="$3"
5646         local dir_params="$4"
5647         local dir_stripe_params="$5"
5648
5649         if [ ! -d "$local_tdir" ] ; then
5650                 test_mkdir -p $dir_stripe_params $local_tdir
5651                 [ "$dir_params" ] && $LFS setstripe $dir_params $local_tdir
5652                 for i in $(seq $local_numfiles) ; do
5653                         touch $local_tdir/file$i
5654                 done
5655                 for i in $(seq $local_numdirs) ; do
5656                         test_mkdir $dir_stripe_params $local_tdir/dir$i
5657                         for j in $(seq $local_numfiles) ; do
5658                                 touch $local_tdir/dir$i/file$j
5659                         done
5660                 done
5661         fi
5662 }
5663
5664 setup_56_special() {
5665         local local_tdir=$1
5666         local local_numfiles=$2
5667         local local_numdirs=$3
5668
5669         setup_56 $local_tdir $local_numfiles $local_numdirs
5670
5671         if [ ! -e "$local_tdir/loop${local_numfiles}b" ] ; then
5672                 for i in $(seq $local_numfiles) ; do
5673                         mknod $local_tdir/loop${i}b b 7 $i
5674                         mknod $local_tdir/null${i}c c 1 3
5675                         ln -s $local_tdir/file1 $local_tdir/link${i}
5676                 done
5677                 for i in $(seq $local_numdirs) ; do
5678                         mknod $local_tdir/dir$i/loop${i}b b 7 $i
5679                         mknod $local_tdir/dir$i/null${i}c c 1 3
5680                         ln -s $local_tdir/dir$i/file1 $local_tdir/dir$i/link${i}
5681                 done
5682         fi
5683 }
5684
5685 test_56g() {
5686         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5687         local expected=$(($NUMDIRS + 2))
5688
5689         setup_56 $dir $NUMFILES $NUMDIRS
5690
5691         # test lfs find with -name
5692         for i in $(seq $NUMFILES) ; do
5693                 local nums=$($LFS find -name "*$i" $dir | wc -l)
5694
5695                 [ $nums -eq $expected ] ||
5696                         error "lfs find -name '*$i' $dir wrong: "\
5697                               "found $nums, expected $expected"
5698         done
5699 }
5700 run_test 56g "check lfs find -name"
5701
5702 test_56h() {
5703         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5704         local expected=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
5705
5706         setup_56 $dir $NUMFILES $NUMDIRS
5707
5708         # test lfs find with ! -name
5709         for i in $(seq $NUMFILES) ; do
5710                 local nums=$($LFS find ! -name "*$i" $dir | wc -l)
5711
5712                 [ $nums -eq $expected ] ||
5713                         error "lfs find ! -name '*$i' $dir wrong: "\
5714                               "found $nums, expected $expected"
5715         done
5716 }
5717 run_test 56h "check lfs find ! -name"
5718
5719 test_56i() {
5720         local dir=$DIR/$tdir
5721
5722         test_mkdir $dir
5723
5724         local cmd="$LFS find -ost $(ostuuid_from_index 0 $dir) $dir"
5725         local out=$($cmd)
5726
5727         [ -z "$out" ] || error "'$cmd' returned directory '$out'"
5728 }
5729 run_test 56i "check 'lfs find -ost UUID' skips directories"
5730
5731 test_56j() {
5732         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5733
5734         setup_56_special $dir $NUMFILES $NUMDIRS
5735
5736         local expected=$((NUMDIRS + 1))
5737         local cmd="$LFS find -type d $dir"
5738         local nums=$($cmd | wc -l)
5739
5740         [ $nums -eq $expected ] ||
5741                 error "'$cmd' wrong: found $nums, expected $expected"
5742 }
5743 run_test 56j "check lfs find -type d"
5744
5745 test_56k() {
5746         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5747
5748         setup_56_special $dir $NUMFILES $NUMDIRS
5749
5750         local expected=$(((NUMDIRS + 1) * NUMFILES))
5751         local cmd="$LFS find -type f $dir"
5752         local nums=$($cmd | wc -l)
5753
5754         [ $nums -eq $expected ] ||
5755                 error "'$cmd' wrong: found $nums, expected $expected"
5756 }
5757 run_test 56k "check lfs find -type f"
5758
5759 test_56l() {
5760         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5761
5762         setup_56_special $dir $NUMFILES $NUMDIRS
5763
5764         local expected=$((NUMDIRS + NUMFILES))
5765         local cmd="$LFS find -type b $dir"
5766         local nums=$($cmd | wc -l)
5767
5768         [ $nums -eq $expected ] ||
5769                 error "'$cmd' wrong: found $nums, expected $expected"
5770 }
5771 run_test 56l "check lfs find -type b"
5772
5773 test_56m() {
5774         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5775
5776         setup_56_special $dir $NUMFILES $NUMDIRS
5777
5778         local expected=$((NUMDIRS + NUMFILES))
5779         local cmd="$LFS find -type c $dir"
5780         local nums=$($cmd | wc -l)
5781         [ $nums -eq $expected ] ||
5782                 error "'$cmd' wrong: found $nums, expected $expected"
5783 }
5784 run_test 56m "check lfs find -type c"
5785
5786 test_56n() {
5787         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5788         setup_56_special $dir $NUMFILES $NUMDIRS
5789
5790         local expected=$((NUMDIRS + NUMFILES))
5791         local cmd="$LFS find -type l $dir"
5792         local nums=$($cmd | wc -l)
5793
5794         [ $nums -eq $expected ] ||
5795                 error "'$cmd' wrong: found $nums, expected $expected"
5796 }
5797 run_test 56n "check lfs find -type l"
5798
5799 test_56o() {
5800         local dir=$DIR/$tdir
5801
5802         setup_56 $dir $NUMFILES $NUMDIRS
5803         utime $dir/file1 > /dev/null || error "utime (1)"
5804         utime $dir/file2 > /dev/null || error "utime (2)"
5805         utime $dir/dir1 > /dev/null || error "utime (3)"
5806         utime $dir/dir2 > /dev/null || error "utime (4)"
5807         utime $dir/dir1/file1 > /dev/null || error "utime (5)"
5808         dd if=/dev/zero count=1 >> $dir/dir1/file1 && sync
5809
5810         local expected=4
5811         local nums=$($LFS find -mtime +0 $dir | wc -l)
5812
5813         [ $nums -eq $expected ] ||
5814                 error "lfs find -mtime +0 $dir: found $nums expect $expected"
5815
5816         expected=12
5817         cmd="$LFS find -mtime 0 $dir"
5818         nums=$($cmd | wc -l)
5819         [ $nums -eq $expected ] ||
5820                 error "'$cmd' wrong: found $nums, expected $expected"
5821 }
5822 run_test 56o "check lfs find -mtime for old files"
5823
5824 test_56ob() {
5825         local dir=$DIR/$tdir
5826         local expected=1
5827         local count=0
5828
5829         # just to make sure there is something that won't be found
5830         test_mkdir $dir
5831         touch $dir/$tfile.now
5832
5833         for age in year week day hour min; do
5834                 count=$((count + 1))
5835
5836                 touch $dir/$tfile-a.$age $dir/$tfile-m.$age
5837                 touch --date="$count $age ago" -a $dir/$tfile-a.$age
5838                 touch --date="$count $age ago" -m $dir/$tfile-m.$age
5839
5840                 local cmd="$LFS find $dir -mtime $count${age:0:1}"
5841                 local nums=$($cmd | wc -l)
5842                 [ $nums -eq $expected ] ||
5843                         error "'$cmd' wrong: found $nums, expected $expected"
5844
5845                 cmd="$LFS find $dir -atime $count${age:0:1}"
5846                 nums=$($cmd | wc -l)
5847                 [ $nums -eq $expected ] ||
5848                         error "'$cmd' wrong: found $nums, expected $expected"
5849         done
5850
5851         sleep 2
5852         cmd="$LFS find $dir -ctime +1s -type f"
5853         nums=$($cmd | wc -l)
5854         (( $nums == $count * 2 + 1)) ||
5855                 error "'$cmd' wrong: found $nums, expected $((expected*2+1))"
5856 }
5857 run_test 56ob "check lfs find -atime -mtime -ctime with units"
5858
5859 test_newerXY_base() {
5860         local x=$1
5861         local y=$2
5862         local dir=$DIR/$tdir
5863         local ref
5864         local negref
5865
5866         if [ $y == "t" ]; then
5867                 ref="\"$(date +"%Y-%m-%d %H:%M:%S")\""
5868         else
5869                 ref=$DIR/$tfile.newer
5870                 touch $ref || error "touch $ref failed"
5871         fi
5872         sleep 2
5873         setup_56 $dir $NUMFILES $NUMDIRS "-i0 -c1" "-i0 -c1"
5874         sleep 2
5875         if [ $y == "t" ]; then
5876                 negref="\"$(date +"%Y-%m-%d %H:%M:%S")\""
5877         else
5878                 negref=$DIR/$tfile.newerneg
5879                 touch $negref || error "touch $negref failed"
5880         fi
5881
5882         local cmd="$LFS find $dir -newer$x$y $ref"
5883         local nums=$(eval $cmd | wc -l)
5884         local expected=$(((NUMFILES + 2) * NUMDIRS + 1))
5885
5886         [ $nums -eq $expected ] ||
5887                 error "'$cmd' wrong: found $nums, expected $expected"
5888
5889         cmd="$LFS find $dir ! -newer$x$y $negref"
5890         nums=$(eval $cmd | wc -l)
5891         [ $nums -eq $expected ] ||
5892                 error "'$cmd' wrong: found $nums, expected $expected"
5893
5894         cmd="$LFS find $dir -newer$x$y $ref ! -newer$x$y $negref"
5895         nums=$(eval $cmd | wc -l)
5896         [ $nums -eq $expected ] ||
5897                 error "'$cmd' wrong: found $nums, expected $expected"
5898
5899         rm -rf $DIR/*
5900 }
5901
5902 test_56oc() {
5903         test_newerXY_base "a" "a"
5904         test_newerXY_base "a" "m"
5905         test_newerXY_base "a" "c"
5906         test_newerXY_base "m" "a"
5907         test_newerXY_base "m" "m"
5908         test_newerXY_base "m" "c"
5909         test_newerXY_base "c" "a"
5910         test_newerXY_base "c" "m"
5911         test_newerXY_base "c" "c"
5912         test_newerXY_base "a" "t"
5913         test_newerXY_base "m" "t"
5914         test_newerXY_base "c" "t"
5915 }
5916 run_test 56oc "check lfs find -newerXY work"
5917
5918 test_56p() {
5919         [ $RUNAS_ID -eq $UID ] &&
5920                 skip_env "RUNAS_ID = UID = $UID -- skipping"
5921
5922         local dir=$DIR/$tdir
5923
5924         setup_56 $dir $NUMFILES $NUMDIRS
5925         chown $RUNAS_ID $dir/file* || error "chown $DIR/${tdir}g/file$i failed"
5926
5927         local expected=$NUMFILES
5928         local cmd="$LFS find -uid $RUNAS_ID $dir"
5929         local nums=$($cmd | wc -l)
5930
5931         [ $nums -eq $expected ] ||
5932                 error "'$cmd' wrong: found $nums, expected $expected"
5933
5934         expected=$(((NUMFILES + 1) * NUMDIRS + 1))
5935         cmd="$LFS find ! -uid $RUNAS_ID $dir"
5936         nums=$($cmd | wc -l)
5937         [ $nums -eq $expected ] ||
5938                 error "'$cmd' wrong: found $nums, expected $expected"
5939 }
5940 run_test 56p "check lfs find -uid and ! -uid"
5941
5942 test_56q() {
5943         [ $RUNAS_ID -eq $UID ] &&
5944                 skip_env "RUNAS_ID = UID = $UID -- skipping"
5945
5946         local dir=$DIR/$tdir
5947
5948         setup_56 $dir $NUMFILES $NUMDIRS
5949         chgrp $RUNAS_GID $dir/file* || error "chown $dir/file$i failed"
5950
5951         local expected=$NUMFILES
5952         local cmd="$LFS find -gid $RUNAS_GID $dir"
5953         local nums=$($cmd | wc -l)
5954
5955         [ $nums -eq $expected ] ||
5956                 error "'$cmd' wrong: found $nums, expected $expected"
5957
5958         expected=$(( ($NUMFILES+1) * $NUMDIRS + 1))
5959         cmd="$LFS find ! -gid $RUNAS_GID $dir"
5960         nums=$($cmd | wc -l)
5961         [ $nums -eq $expected ] ||
5962                 error "'$cmd' wrong: found $nums, expected $expected"
5963 }
5964 run_test 56q "check lfs find -gid and ! -gid"
5965
5966 test_56r() {
5967         local dir=$DIR/$tdir
5968
5969         setup_56 $dir $NUMFILES $NUMDIRS
5970
5971         local expected=12
5972         local cmd="$LFS find -size 0 -type f -lazy $dir"
5973         local nums=$($cmd | wc -l)
5974
5975         [ $nums -eq $expected ] ||
5976                 error "'$cmd' wrong: found $nums, expected $expected"
5977         cmd="$LFS find -size 0 -type f $dir"
5978         nums=$($cmd | wc -l)
5979         [ $nums -eq $expected ] ||
5980                 error "'$cmd' wrong: found $nums, expected $expected"
5981
5982         expected=0
5983         cmd="$LFS find ! -size 0 -type f -lazy $dir"
5984         nums=$($cmd | wc -l)
5985         [ $nums -eq $expected ] ||
5986                 error "'$cmd' wrong: found $nums, expected $expected"
5987         cmd="$LFS find ! -size 0 -type f $dir"
5988         nums=$($cmd | wc -l)
5989         [ $nums -eq $expected ] ||
5990                 error "'$cmd' wrong: found $nums, expected $expected"
5991
5992         echo "test" > $dir/$tfile
5993         echo "test2" > $dir/$tfile.2 && sync
5994         expected=1
5995         cmd="$LFS find -size 5 -type f -lazy $dir"
5996         nums=$($cmd | wc -l)
5997         [ $nums -eq $expected ] ||
5998                 error "'$cmd' wrong: found $nums, expected $expected"
5999         cmd="$LFS find -size 5 -type f $dir"
6000         nums=$($cmd | wc -l)
6001         [ $nums -eq $expected ] ||
6002                 error "'$cmd' wrong: found $nums, expected $expected"
6003
6004         expected=1
6005         cmd="$LFS find -size +5 -type f -lazy $dir"
6006         nums=$($cmd | wc -l)
6007         [ $nums -eq $expected ] ||
6008                 error "'$cmd' wrong: found $nums, expected $expected"
6009         cmd="$LFS find -size +5 -type f $dir"
6010         nums=$($cmd | wc -l)
6011         [ $nums -eq $expected ] ||
6012                 error "'$cmd' wrong: found $nums, expected $expected"
6013
6014         expected=2
6015         cmd="$LFS find -size +0 -type f -lazy $dir"
6016         nums=$($cmd | wc -l)
6017         [ $nums -eq $expected ] ||
6018                 error "'$cmd' wrong: found $nums, expected $expected"
6019         cmd="$LFS find -size +0 -type f $dir"
6020         nums=$($cmd | wc -l)
6021         [ $nums -eq $expected ] ||
6022                 error "'$cmd' wrong: found $nums, expected $expected"
6023
6024         expected=2
6025         cmd="$LFS find ! -size -5 -type f -lazy $dir"
6026         nums=$($cmd | wc -l)
6027         [ $nums -eq $expected ] ||
6028                 error "'$cmd' wrong: found $nums, expected $expected"
6029         cmd="$LFS find ! -size -5 -type f $dir"
6030         nums=$($cmd | wc -l)
6031         [ $nums -eq $expected ] ||
6032                 error "'$cmd' wrong: found $nums, expected $expected"
6033
6034         expected=12
6035         cmd="$LFS find -size -5 -type f -lazy $dir"
6036         nums=$($cmd | wc -l)
6037         [ $nums -eq $expected ] ||
6038                 error "'$cmd' wrong: found $nums, expected $expected"
6039         cmd="$LFS find -size -5 -type f $dir"
6040         nums=$($cmd | wc -l)
6041         [ $nums -eq $expected ] ||
6042                 error "'$cmd' wrong: found $nums, expected $expected"
6043 }
6044 run_test 56r "check lfs find -size works"
6045
6046 test_56ra() {
6047         [[ $MDS1_VERSION -gt $(version_code 2.12.58) ]] ||
6048                 skip "MDS < 2.12.58 doesn't return LSOM data"
6049         local dir=$DIR/$tdir
6050
6051         [[ $OSC == "mdc" ]] && skip "DoM files" && return
6052
6053         setup_56 $dir $NUMFILES $NUMDIRS "-c 1"
6054
6055         cancel_lru_locks $OSC
6056
6057         local rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6058         local expected=12
6059         local cmd="$LFS find -size 0 -type f -lazy $dir"
6060         local nums=$($cmd | wc -l)
6061
6062         [ $nums -eq $expected ] ||
6063                 error "'$cmd' wrong: found $nums, expected $expected"
6064
6065         local rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6066         [ $rpcs_before -eq $rpcs_after ] ||
6067                 error "'$cmd' should not send glimpse RPCs to OST"
6068         cmd="$LFS find -size 0 -type f $dir"
6069         nums=$($cmd | wc -l)
6070         [ $nums -eq $expected ] ||
6071                 error "'$cmd' wrong: found $nums, expected $expected"
6072         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6073         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6074         $LCTL get_param osc.*.stats
6075         [ $rpcs_after -eq $((rpcs_before + 12)) ] ||
6076                 error "'$cmd' should send 12 glimpse RPCs to OST"
6077
6078         cancel_lru_locks $OSC
6079         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6080         expected=0
6081         cmd="$LFS find ! -size 0 -type f -lazy $dir"
6082         nums=$($cmd | wc -l)
6083         [ $nums -eq $expected ] ||
6084                 error "'$cmd' wrong: found $nums, expected $expected"
6085         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6086         $LCTL get_param mdc.*.stats
6087         [ $rpcs_before -eq $rpcs_after ] ||
6088                 error "'$cmd' should not send glimpse RPCs to OST"
6089         cmd="$LFS find ! -size 0 -type f $dir"
6090         nums=$($cmd | wc -l)
6091         [ $nums -eq $expected ] ||
6092                 error "'$cmd' wrong: found $nums, expected $expected"
6093         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6094         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6095         [ $rpcs_after -eq $((rpcs_before + 12)) ] ||
6096                 error "'$cmd' should send 12 glimpse RPCs to OST"
6097
6098         echo "test" > $dir/$tfile
6099         echo "test2" > $dir/$tfile.2 && sync
6100         cancel_lru_locks $OSC
6101         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6102         expected=1
6103         cmd="$LFS find -size 5 -type f -lazy $dir"
6104         nums=$($cmd | wc -l)
6105         [ $nums -eq $expected ] ||
6106                 error "'$cmd' wrong: found $nums, expected $expected"
6107         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6108         [ $rpcs_before -eq $rpcs_after ] ||
6109                 error "'$cmd' should not send glimpse RPCs to OST"
6110         cmd="$LFS find -size 5 -type f $dir"
6111         nums=$($cmd | wc -l)
6112         [ $nums -eq $expected ] ||
6113                 error "'$cmd' wrong: found $nums, expected $expected"
6114         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6115         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6116         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6117                 error "'$cmd' should send 14 glimpse RPCs to OST"
6118
6119         cancel_lru_locks $OSC
6120         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6121         expected=1
6122         cmd="$LFS find -size +5 -type f -lazy $dir"
6123         nums=$($cmd | wc -l)
6124         [ $nums -eq $expected ] ||
6125                 error "'$cmd' wrong: found $nums, expected $expected"
6126         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6127         [ $rpcs_before -eq $rpcs_after ] ||
6128                 error "'$cmd' should not send glimpse RPCs to OST"
6129         cmd="$LFS find -size +5 -type f $dir"
6130         nums=$($cmd | wc -l)
6131         [ $nums -eq $expected ] ||
6132                 error "'$cmd' wrong: found $nums, expected $expected"
6133         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6134         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6135         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6136                 error "'$cmd' should send 14 glimpse RPCs to OST"
6137
6138         cancel_lru_locks $OSC
6139         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6140         expected=2
6141         cmd="$LFS find -size +0 -type f -lazy $dir"
6142         nums=$($cmd | wc -l)
6143         [ $nums -eq $expected ] ||
6144                 error "'$cmd' wrong: found $nums, expected $expected"
6145         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6146         [ $rpcs_before -eq $rpcs_after ] ||
6147                 error "'$cmd' should not send glimpse RPCs to OST"
6148         cmd="$LFS find -size +0 -type f $dir"
6149         nums=$($cmd | wc -l)
6150         [ $nums -eq $expected ] ||
6151                 error "'$cmd' wrong: found $nums, expected $expected"
6152         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6153         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6154         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6155                 error "'$cmd' should send 14 glimpse RPCs to OST"
6156
6157         cancel_lru_locks $OSC
6158         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6159         expected=2
6160         cmd="$LFS find ! -size -5 -type f -lazy $dir"
6161         nums=$($cmd | wc -l)
6162         [ $nums -eq $expected ] ||
6163                 error "'$cmd' wrong: found $nums, expected $expected"
6164         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6165         [ $rpcs_before -eq $rpcs_after ] ||
6166                 error "'$cmd' should not send glimpse RPCs to OST"
6167         cmd="$LFS find ! -size -5 -type f $dir"
6168         nums=$($cmd | wc -l)
6169         [ $nums -eq $expected ] ||
6170                 error "'$cmd' wrong: found $nums, expected $expected"
6171         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6172         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6173         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6174                 error "'$cmd' should send 14 glimpse RPCs to OST"
6175
6176         cancel_lru_locks $OSC
6177         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6178         expected=12
6179         cmd="$LFS find -size -5 -type f -lazy $dir"
6180         nums=$($cmd | wc -l)
6181         [ $nums -eq $expected ] ||
6182                 error "'$cmd' wrong: found $nums, expected $expected"
6183         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6184         [ $rpcs_before -eq $rpcs_after ] ||
6185                 error "'$cmd' should not send glimpse RPCs to OST"
6186         cmd="$LFS find -size -5 -type f $dir"
6187         nums=$($cmd | wc -l)
6188         [ $nums -eq $expected ] ||
6189                 error "'$cmd' wrong: found $nums, expected $expected"
6190         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6191         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6192         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6193                 error "'$cmd' should send 14 glimpse RPCs to OST"
6194 }
6195 run_test 56ra "check lfs find -size -lazy works for data on OSTs"
6196
6197 test_56rb() {
6198         local dir=$DIR/$tdir
6199         local tmp=$TMP/$tfile.log
6200         local mdt_idx;
6201
6202         test_mkdir -p $dir || error "failed to mkdir $dir"
6203         $LFS setstripe -c 1 -i 0 $dir/$tfile ||
6204                 error "failed to setstripe $dir/$tfile"
6205         dd if=/dev/zero of=$dir/$tfile bs=1M count=1
6206
6207         stack_trap "rm -f $tmp" EXIT
6208         $LFS find --size +100K --ost 0 $dir 2>&1 | tee $tmp
6209         [ -z "$(cat $tmp | grep "obd_uuid: ")" ] ||
6210                 error "failed to find --size +100K --ost 0 $dir"
6211         $LFS find --size +100K --mdt $mdt_idx $dir 2>&1 | tee $tmp
6212         [ -z "$(cat $tmp | grep "obd_uuid: ")" ] ||
6213                 error "failed to find --size +100K --mdt $mdt_idx $dir"
6214 }
6215 run_test 56rb "check lfs find --size --ost/--mdt works"
6216
6217 test_56s() { # LU-611 #LU-9369
6218         [[ $OSTCOUNT -lt 2 ]] && skip_env "need at least 2 OSTs"
6219
6220         local dir=$DIR/$tdir
6221         local onestripe=$(((NUMDIRS + 1) * NUMFILES))
6222
6223         setup_56 $dir $NUMFILES $NUMDIRS "-c 1"
6224         for i in $(seq $NUMDIRS); do
6225                 $LFS setstripe -c $((OSTCOUNT + 1)) $dir/dir$i/$tfile
6226         done
6227
6228         local expected=$NUMDIRS
6229         local cmd="$LFS find -c $OSTCOUNT $dir"
6230         local nums=$($cmd | wc -l)
6231
6232         [ $nums -eq $expected ] || {
6233                 $LFS getstripe -R $dir
6234                 error "'$cmd' wrong: found $nums, expected $expected"
6235         }
6236
6237         expected=$((NUMDIRS + onestripe))
6238         cmd="$LFS find -stripe-count +0 -type f $dir"
6239         nums=$($cmd | wc -l)
6240         [ $nums -eq $expected ] || {
6241                 $LFS getstripe -R $dir
6242                 error "'$cmd' wrong: found $nums, expected $expected"
6243         }
6244
6245         expected=$onestripe
6246         cmd="$LFS find -stripe-count 1 -type f $dir"
6247         nums=$($cmd | wc -l)
6248         [ $nums -eq $expected ] || {
6249                 $LFS getstripe -R $dir
6250                 error "'$cmd' wrong: found $nums, expected $expected"
6251         }
6252
6253         cmd="$LFS find -stripe-count -2 -type f $dir"
6254         nums=$($cmd | wc -l)
6255         [ $nums -eq $expected ] || {
6256                 $LFS getstripe -R $dir
6257                 error "'$cmd' wrong: found $nums, expected $expected"
6258         }
6259
6260         expected=0
6261         cmd="$LFS find -stripe-count $((OSTCOUNT + 1)) -type f $dir"
6262         nums=$($cmd | wc -l)
6263         [ $nums -eq $expected ] || {
6264                 $LFS getstripe -R $dir
6265                 error "'$cmd' wrong: found $nums, expected $expected"
6266         }
6267 }
6268 run_test 56s "check lfs find -stripe-count works"
6269
6270 test_56t() { # LU-611 #LU-9369
6271         local dir=$DIR/$tdir
6272
6273         setup_56 $dir 0 $NUMDIRS
6274         for i in $(seq $NUMDIRS); do
6275                 $LFS setstripe -S 8M $dir/dir$i/$tfile
6276         done
6277
6278         local expected=$NUMDIRS
6279         local cmd="$LFS find -S 8M $dir"
6280         local nums=$($cmd | wc -l)
6281
6282         [ $nums -eq $expected ] || {
6283                 $LFS getstripe -R $dir
6284                 error "'$cmd' wrong: found $nums, expected $expected"
6285         }
6286         rm -rf $dir
6287
6288         setup_56 $dir $NUMFILES $NUMDIRS "--stripe-size 512k"
6289
6290         $LFS setstripe -S 256k $dir/$tfile.{0,1,2,3}
6291
6292         expected=$(((NUMDIRS + 1) * NUMFILES))
6293         cmd="$LFS find -stripe-size 512k -type f $dir"
6294         nums=$($cmd | wc -l)
6295         [ $nums -eq $expected ] ||
6296                 error "'$cmd' wrong: found $nums, expected $expected"
6297
6298         cmd="$LFS find -stripe-size +320k -type f $dir"
6299         nums=$($cmd | wc -l)
6300         [ $nums -eq $expected ] ||
6301                 error "'$cmd' wrong: found $nums, expected $expected"
6302
6303         expected=$(((NUMDIRS + 1) * NUMFILES + 4))
6304         cmd="$LFS find -stripe-size +200k -type f $dir"
6305         nums=$($cmd | wc -l)
6306         [ $nums -eq $expected ] ||
6307                 error "'$cmd' wrong: found $nums, expected $expected"
6308
6309         cmd="$LFS find -stripe-size -640k -type f $dir"
6310         nums=$($cmd | wc -l)
6311         [ $nums -eq $expected ] ||
6312                 error "'$cmd' wrong: found $nums, expected $expected"
6313
6314         expected=4
6315         cmd="$LFS find -stripe-size 256k -type f $dir"
6316         nums=$($cmd | wc -l)
6317         [ $nums -eq $expected ] ||
6318                 error "'$cmd' wrong: found $nums, expected $expected"
6319
6320         cmd="$LFS find -stripe-size -320k -type f $dir"
6321         nums=$($cmd | wc -l)
6322         [ $nums -eq $expected ] ||
6323                 error "'$cmd' wrong: found $nums, expected $expected"
6324
6325         expected=0
6326         cmd="$LFS find -stripe-size 1024k -type f $dir"
6327         nums=$($cmd | wc -l)
6328         [ $nums -eq $expected ] ||
6329                 error "'$cmd' wrong: found $nums, expected $expected"
6330 }
6331 run_test 56t "check lfs find -stripe-size works"
6332
6333 test_56u() { # LU-611
6334         local dir=$DIR/$tdir
6335
6336         setup_56 $dir $NUMFILES $NUMDIRS "-i 0 -c 1"
6337
6338         if [[ $OSTCOUNT -gt 1 ]]; then
6339                 $LFS setstripe -i 1 -c 1 $dir/$tfile.{0,1,2,3}
6340                 onestripe=4
6341         else
6342                 onestripe=0
6343         fi
6344
6345         local expected=$(((NUMDIRS + 1) * NUMFILES))
6346         local cmd="$LFS find -stripe-index 0 -type f $dir"
6347         local nums=$($cmd | wc -l)
6348
6349         [ $nums -eq $expected ] ||
6350                 error "'$cmd' wrong: found $nums, expected $expected"
6351
6352         expected=$onestripe
6353         cmd="$LFS find -stripe-index 1 -type f $dir"
6354         nums=$($cmd | wc -l)
6355         [ $nums -eq $expected ] ||
6356                 error "'$cmd' wrong: found $nums, expected $expected"
6357
6358         cmd="$LFS find ! -stripe-index 0 -type f $dir"
6359         nums=$($cmd | wc -l)
6360         [ $nums -eq $expected ] ||
6361                 error "'$cmd' wrong: found $nums, expected $expected"
6362
6363         expected=0
6364         # This should produce an error and not return any files
6365         cmd="$LFS find -stripe-index $OSTCOUNT -type f $dir"
6366         nums=$($cmd 2>/dev/null | wc -l)
6367         [ $nums -eq $expected ] ||
6368                 error "'$cmd' wrong: found $nums, expected $expected"
6369
6370         if [[ $OSTCOUNT -gt 1 ]]; then
6371                 expected=$(((NUMDIRS + 1) * NUMFILES + onestripe))
6372                 cmd="$LFS find -stripe-index 0,1 -type f $dir"
6373                 nums=$($cmd | wc -l)
6374                 [ $nums -eq $expected ] ||
6375                         error "'$cmd' wrong: found $nums, expected $expected"
6376         fi
6377 }
6378 run_test 56u "check lfs find -stripe-index works"
6379
6380 test_56v() {
6381         local mdt_idx=0
6382         local dir=$DIR/$tdir
6383
6384         setup_56 $dir $NUMFILES $NUMDIRS
6385
6386         UUID=$(mdtuuid_from_index $mdt_idx $dir)
6387         [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT $mdt_idx"
6388
6389         for file in $($LFS find -m $UUID $dir); do
6390                 file_midx=$($LFS getstripe -m $file)
6391                 [ $file_midx -eq $mdt_idx ] ||
6392                         error "lfs find -m $UUID != getstripe -m $file_midx"
6393         done
6394 }
6395 run_test 56v "check 'lfs find -m match with lfs getstripe -m'"
6396
6397 test_56w() {
6398         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6399         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6400
6401         local dir=$DIR/$tdir
6402
6403         setup_56 $dir $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
6404
6405         local stripe_size=$($LFS getstripe -S -d $dir) ||
6406                 error "$LFS getstripe -S -d $dir failed"
6407         stripe_size=${stripe_size%% *}
6408
6409         local file_size=$((stripe_size * OSTCOUNT))
6410         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
6411         local required_space=$((file_num * file_size))
6412         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
6413                            head -n1)
6414         [[ $free_space -le $((required_space / 1024)) ]] &&
6415                 skip_env "need $required_space, have $free_space kbytes"
6416
6417         local dd_bs=65536
6418         local dd_count=$((file_size / dd_bs))
6419
6420         # write data into the files
6421         local i
6422         local j
6423         local file
6424
6425         for i in $(seq $NUMFILES); do
6426                 file=$dir/file$i
6427                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
6428                         error "write data into $file failed"
6429         done
6430         for i in $(seq $NUMDIRS); do
6431                 for j in $(seq $NUMFILES); do
6432                         file=$dir/dir$i/file$j
6433                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
6434                                 error "write data into $file failed"
6435                 done
6436         done
6437
6438         # $LFS_MIGRATE will fail if hard link migration is unsupported
6439         if [[ $MDS1_VERSION -gt $(version_code 2.5.55) ]]; then
6440                 createmany -l$dir/dir1/file1 $dir/dir1/link 200 ||
6441                         error "creating links to $dir/dir1/file1 failed"
6442         fi
6443
6444         local expected=-1
6445
6446         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
6447
6448         # lfs_migrate file
6449         local cmd="$LFS_MIGRATE -y -c $expected $dir/file1"
6450
6451         echo "$cmd"
6452         eval $cmd || error "$cmd failed"
6453
6454         check_stripe_count $dir/file1 $expected
6455
6456         if [ $MDS1_VERSION -ge $(version_code 2.6.90) ];
6457         then
6458                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
6459                 # OST 1 if it is on OST 0. This file is small enough to
6460                 # be on only one stripe.
6461                 file=$dir/migr_1_ost
6462                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
6463                         error "write data into $file failed"
6464                 local obdidx=$($LFS getstripe -i $file)
6465                 local oldmd5=$(md5sum $file)
6466                 local newobdidx=0
6467
6468                 [[ $obdidx -eq 0 ]] && newobdidx=1
6469                 cmd="$LFS migrate -i $newobdidx $file"
6470                 echo $cmd
6471                 eval $cmd || error "$cmd failed"
6472
6473                 local realobdix=$($LFS getstripe -i $file)
6474                 local newmd5=$(md5sum $file)
6475
6476                 [[ $newobdidx -ne $realobdix ]] &&
6477                         error "new OST is different (was=$obdidx, "\
6478                               "wanted=$newobdidx, got=$realobdix)"
6479                 [[ "$oldmd5" != "$newmd5" ]] &&
6480                         error "md5sum differ: $oldmd5, $newmd5"
6481         fi
6482
6483         # lfs_migrate dir
6484         cmd="$LFS_MIGRATE -y -c $expected $dir/dir1"
6485         echo "$cmd"
6486         eval $cmd || error "$cmd failed"
6487
6488         for j in $(seq $NUMFILES); do
6489                 check_stripe_count $dir/dir1/file$j $expected
6490         done
6491
6492         # lfs_migrate works with lfs find
6493         cmd="$LFS find -stripe_count $OSTCOUNT -type f $dir |
6494              $LFS_MIGRATE -y -c $expected"
6495         echo "$cmd"
6496         eval $cmd || error "$cmd failed"
6497
6498         for i in $(seq 2 $NUMFILES); do
6499                 check_stripe_count $dir/file$i $expected
6500         done
6501         for i in $(seq 2 $NUMDIRS); do
6502                 for j in $(seq $NUMFILES); do
6503                 check_stripe_count $dir/dir$i/file$j $expected
6504                 done
6505         done
6506 }
6507 run_test 56w "check lfs_migrate -c stripe_count works"
6508
6509 test_56wb() {
6510         local file1=$DIR/$tdir/file1
6511         local create_pool=false
6512         local initial_pool=$($LFS getstripe -p $DIR)
6513         local pool_list=()
6514         local pool=""
6515
6516         echo -n "Creating test dir..."
6517         test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
6518         echo "done."
6519
6520         echo -n "Creating test file..."
6521         touch $file1 || error "cannot create file"
6522         echo "done."
6523
6524         echo -n "Detecting existing pools..."
6525         pool_list=($($LFS pool_list $FSNAME | grep "$FSNAME\." | cut -d. -f2))
6526
6527         if [ ${#pool_list[@]} -gt 0 ]; then
6528                 echo "${pool_list[@]}"
6529                 for thispool in "${pool_list[@]}"; do
6530                         if [[ -z "$initial_pool" ||
6531                               "$initial_pool" != "$thispool" ]]; then
6532                                 pool="$thispool"
6533                                 echo "Using existing pool '$pool'"
6534                                 break
6535                         fi
6536                 done
6537         else
6538                 echo "none detected."
6539         fi
6540         if [ -z "$pool" ]; then
6541                 pool=${POOL:-testpool}
6542                 [ "$initial_pool" = "$pool" ] && pool="testpool2"
6543                 echo -n "Creating pool '$pool'..."
6544                 create_pool=true
6545                 pool_add $pool &> /dev/null ||
6546                         error "pool_add failed"
6547                 echo "done."
6548
6549                 echo -n "Adding target to pool..."
6550                 pool_add_targets $pool 0 0 1 &> /dev/null ||
6551                         error "pool_add_targets failed"
6552                 echo "done."
6553         fi
6554
6555         echo -n "Setting pool using -p option..."
6556         $LFS_MIGRATE -y -q --no-rsync -p $pool $file1 &> /dev/null ||
6557                 error "migrate failed rc = $?"
6558         echo "done."
6559
6560         echo -n "Verifying test file is in pool after migrating..."
6561         [ "$($LFS getstripe -p $file1)" = $pool ] ||
6562                 error "file was not migrated to pool $pool"
6563         echo "done."
6564
6565         echo -n "Removing test file from pool '$pool'..."
6566         # "lfs migrate $file" won't remove the file from the pool
6567         # until some striping information is changed.
6568         $LFS migrate -c 1 $file1 &> /dev/null ||
6569                 error "cannot remove from pool"
6570         [ "$($LFS getstripe -p $file1)" ] &&
6571                 error "pool still set"
6572         echo "done."
6573
6574         echo -n "Setting pool using --pool option..."
6575         $LFS_MIGRATE -y -q --no-rsync --pool $pool $file1 &> /dev/null ||
6576                 error "migrate failed rc = $?"
6577         echo "done."
6578
6579         # Clean up
6580         rm -f $file1
6581         if $create_pool; then
6582                 destroy_test_pools 2> /dev/null ||
6583                         error "destroy test pools failed"
6584         fi
6585 }
6586 run_test 56wb "check lfs_migrate pool support"
6587
6588 test_56wc() {
6589         local file1="$DIR/$tdir/file1"
6590         local parent_ssize
6591         local parent_scount
6592         local cur_ssize
6593         local cur_scount
6594         local orig_ssize
6595
6596         echo -n "Creating test dir..."
6597         test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
6598         $LFS setstripe -S 1M -c 1 "$DIR/$tdir" &> /dev/null ||
6599                 error "cannot set stripe by '-S 1M -c 1'"
6600         echo "done"
6601
6602         echo -n "Setting initial stripe for test file..."
6603         $LFS setstripe -S 512K -c 1 "$file1" &> /dev/null ||
6604                 error "cannot set stripe"
6605         cur_ssize=$($LFS getstripe -S "$file1")
6606         [ $cur_ssize -eq 524288 ] || error "setstripe -S $cur_ssize != 524288"
6607         echo "done."
6608
6609         # File currently set to -S 512K -c 1
6610
6611         # Ensure -c and -S options are rejected when -R is set
6612         echo -n "Verifying incompatible options are detected..."
6613         $LFS_MIGRATE -y -R -c 1 "$file1" &> /dev/null &&
6614                 error "incompatible -c and -R options not detected"
6615         $LFS_MIGRATE -y -R -S 1M "$file1" &> /dev/null &&
6616                 error "incompatible -S and -R options not detected"
6617         echo "done."
6618
6619         # Ensure unrecognized options are passed through to 'lfs migrate'
6620         echo -n "Verifying -S option is passed through to lfs migrate..."
6621         $LFS_MIGRATE -y -S 1M "$file1" &> /dev/null ||
6622                 error "migration failed"
6623         cur_ssize=$($LFS getstripe -S "$file1")
6624         [ $cur_ssize -eq 1048576 ] || error "migrate -S $cur_ssize != 1048576"
6625         echo "done."
6626
6627         # File currently set to -S 1M -c 1
6628
6629         # Ensure long options are supported
6630         echo -n "Verifying long options supported..."
6631         $LFS_MIGRATE -y --non-block "$file1" &> /dev/null ||
6632                 error "long option without argument not supported"
6633         $LFS_MIGRATE -y --stripe-size 512K "$file1" &> /dev/null ||
6634                 error "long option with argument not supported"
6635         cur_ssize=$($LFS getstripe -S "$file1")
6636         [ $cur_ssize -eq 524288 ] ||
6637                 error "migrate --stripe-size $cur_ssize != 524288"
6638         echo "done."
6639
6640         # File currently set to -S 512K -c 1
6641
6642         if [ "$OSTCOUNT" -gt 1 ]; then
6643                 echo -n "Verifying explicit stripe count can be set..."
6644                 $LFS_MIGRATE -y -c 2 "$file1" &> /dev/null ||
6645                         error "migrate failed"
6646                 cur_scount=$($LFS getstripe -c "$file1")
6647                 [ $cur_scount -eq 2 ] || error "migrate -c $cur_scount != 2"
6648                 echo "done."
6649         fi
6650
6651         # File currently set to -S 512K -c 1 or -S 512K -c 2
6652
6653         # Ensure parent striping is used if -R is set, and no stripe
6654         # count or size is specified
6655         echo -n "Setting stripe for parent directory..."
6656         $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
6657                 error "cannot set stripe '-S 2M -c 1'"
6658         echo "done."
6659
6660         echo -n "Verifying restripe option uses parent stripe settings..."
6661         parent_ssize=$($LFS getstripe -S $DIR/$tdir 2>/dev/null)
6662         parent_scount=$($LFS getstripe -c $DIR/$tdir 2>/dev/null)
6663         $LFS_MIGRATE -y -R "$file1" &> /dev/null ||
6664                 error "migrate failed"
6665         cur_ssize=$($LFS getstripe -S "$file1")
6666         [ $cur_ssize -eq $parent_ssize ] ||
6667                 error "migrate -R stripe_size $cur_ssize != $parent_ssize"
6668         cur_scount=$($LFS getstripe -c "$file1")
6669         [ $cur_scount -eq $parent_scount ] ||
6670                 error "migrate -R stripe_count $cur_scount != $parent_scount"
6671         echo "done."
6672
6673         # File currently set to -S 1M -c 1
6674
6675         # Ensure striping is preserved if -R is not set, and no stripe
6676         # count or size is specified
6677         echo -n "Verifying striping size preserved when not specified..."
6678         orig_ssize=$($LFS getstripe -S "$file1" 2>/dev/null)
6679         $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
6680                 error "cannot set stripe on parent directory"
6681         $LFS_MIGRATE -y "$file1" &> /dev/null ||
6682                 error "migrate failed"
6683         cur_ssize=$($LFS getstripe -S "$file1")
6684         [ $cur_ssize -eq $orig_ssize ] ||
6685                 error "migrate by default $cur_ssize != $orig_ssize"
6686         echo "done."
6687
6688         # Ensure file name properly detected when final option has no argument
6689         echo -n "Verifying file name properly detected..."
6690         $LFS_MIGRATE -y "$file1" &> /dev/null ||
6691                 error "file name interpreted as option argument"
6692         echo "done."
6693
6694         # Clean up
6695         rm -f "$file1"
6696 }
6697 run_test 56wc "check unrecognized options for lfs_migrate are passed through"
6698
6699 test_56wd() {
6700         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6701
6702         local file1=$DIR/$tdir/file1
6703
6704         echo -n "Creating test dir..."
6705         test_mkdir $DIR/$tdir || error "cannot create dir"
6706         echo "done."
6707
6708         echo -n "Creating test file..."
6709         touch $file1
6710         echo "done."
6711
6712         # Ensure 'lfs migrate' will fail by using a non-existent option,
6713         # and make sure rsync is not called to recover
6714         echo -n "Make sure --no-rsync option works..."
6715         $LFS_MIGRATE -y --no-rsync --invalid-opt $file1 2>&1 |
6716                 grep -q 'refusing to fall back to rsync' ||
6717                 error "rsync was called with --no-rsync set"
6718         echo "done."
6719
6720         # Ensure rsync is called without trying 'lfs migrate' first
6721         echo -n "Make sure --rsync option works..."
6722         $LFS_MIGRATE -y --rsync --invalid-opt $file1 2>&1 |
6723                 grep -q 'falling back to rsync' &&
6724                 error "lfs migrate was called with --rsync set"
6725         echo "done."
6726
6727         echo -n "Make sure --rsync and --no-rsync options are exclusive..."
6728         $LFS_MIGRATE -y --rsync --no-rsync $file1 2>&1 |
6729                 grep -q 'at the same time' ||
6730                 error "--rsync and --no-rsync accepted concurrently"
6731         echo "done."
6732
6733         # Clean up
6734         rm -f $file1
6735 }
6736 run_test 56wd "check lfs_migrate --rsync and --no-rsync work"
6737
6738 test_56x() {
6739         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6740         check_swap_layouts_support
6741
6742         local dir=$DIR/$tdir
6743         local ref1=/etc/passwd
6744         local file1=$dir/file1
6745
6746         test_mkdir $dir || error "creating dir $dir"
6747         $LFS setstripe -c 2 $file1
6748         cp $ref1 $file1
6749         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
6750         stripe=$($LFS getstripe -c $file1)
6751         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
6752         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
6753
6754         # clean up
6755         rm -f $file1
6756 }
6757 run_test 56x "lfs migration support"
6758
6759 test_56xa() {
6760         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6761         check_swap_layouts_support
6762
6763         local dir=$DIR/$tdir/$testnum
6764
6765         test_mkdir -p $dir
6766
6767         local ref1=/etc/passwd
6768         local file1=$dir/file1
6769
6770         $LFS setstripe -c 2 $file1
6771         cp $ref1 $file1
6772         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
6773
6774         local stripe=$($LFS getstripe -c $file1)
6775
6776         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
6777         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
6778
6779         # clean up
6780         rm -f $file1
6781 }
6782 run_test 56xa "lfs migration --block support"
6783
6784 check_migrate_links() {
6785         local dir="$1"
6786         local file1="$dir/file1"
6787         local begin="$2"
6788         local count="$3"
6789         local runas="$4"
6790         local total_count=$(($begin + $count - 1))
6791         local symlink_count=10
6792         local uniq_count=10
6793
6794         if [ ! -f "$file1" ]; then
6795                 echo -n "creating initial file..."
6796                 $LFS setstripe -c 1 -S "512k" "$file1" ||
6797                         error "cannot setstripe initial file"
6798                 echo "done"
6799
6800                 echo -n "creating symlinks..."
6801                 for s in $(seq 1 $symlink_count); do
6802                         ln -s "$file1" "$dir/slink$s" ||
6803                                 error "cannot create symlinks"
6804                 done
6805                 echo "done"
6806
6807                 echo -n "creating nonlinked files..."
6808                 createmany -o "$dir/uniq" 1 10 &> /dev/null ||
6809                         error "cannot create nonlinked files"
6810                 echo "done"
6811         fi
6812
6813         # create hard links
6814         if [ ! -f "$dir/file$total_count" ]; then
6815                 echo -n "creating hard links $begin:$total_count..."
6816                 createmany -l"$file1" "$dir/file" "$begin" "$count" &>  \
6817                         /dev/null || error "cannot create hard links"
6818                 echo "done"
6819         fi
6820
6821         echo -n "checking number of hard links listed in xattrs..."
6822         local fid=$($LFS getstripe -F "$file1")
6823         local paths=($($LFS fid2path "$MOUNT" "$fid" 2> /dev/null))
6824
6825         echo "${#paths[*]}"
6826         if [ ${#paths[*]} -lt $total_count -a "$begin" -eq 2  ]; then
6827                         skip "hard link list has unexpected size, skipping test"
6828         fi
6829         if [ ${#paths[*]} -ge $total_count -a "$begin" -ne 2  ]; then
6830                         error "link names should exceed xattrs size"
6831         fi
6832
6833         echo -n "migrating files..."
6834         local migrate_out=$($runas $LFS_MIGRATE -y -S '1m' $dir)
6835         local rc=$?
6836         [ $rc -eq 0 ] || error "migrate failed rc = $rc"
6837         echo "done"
6838
6839         # make sure all links have been properly migrated
6840         echo -n "verifying files..."
6841         fid=$($LFS getstripe -F "$file1") ||
6842                 error "cannot get fid for file $file1"
6843         for i in $(seq 2 $total_count); do
6844                 local fid2=$($LFS getstripe -F $dir/file$i)
6845
6846                 [ "$fid2" == "$fid" ] ||
6847                         error "migrated hard link has mismatched FID"
6848         done
6849
6850         # make sure hard links were properly detected, and migration was
6851         # performed only once for the entire link set; nonlinked files should
6852         # also be migrated
6853         local actual=$(grep -c 'done' <<< "$migrate_out")
6854         local expected=$(($uniq_count + 1))
6855
6856         [ "$actual" -eq  "$expected" ] ||
6857                 error "hard links individually migrated ($actual != $expected)"
6858
6859         # make sure the correct number of hard links are present
6860         local hardlinks=$(stat -c '%h' "$file1")
6861
6862         [ $hardlinks -eq $total_count ] ||
6863                 error "num hard links $hardlinks != $total_count"
6864         echo "done"
6865
6866         return 0
6867 }
6868
6869 test_56xb() {
6870         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
6871                 skip "Need MDS version at least 2.10.55"
6872
6873         local dir="$DIR/$tdir"
6874
6875         test_mkdir "$dir" || error "cannot create dir $dir"
6876
6877         echo "testing lfs migrate mode when all links fit within xattrs"
6878         LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 2 99
6879
6880         echo "testing rsync mode when all links fit within xattrs"
6881         LFS_MIGRATE_RSYNC_MODE=true check_migrate_links "$dir" 2 99
6882
6883         echo "testing lfs migrate mode when all links do not fit within xattrs"
6884         LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 101 100
6885
6886         echo "testing rsync mode when all links do not fit within xattrs"
6887         LFS_MIGRATE_RSYNC_MODE=true check_migrate_links "$dir" 101 100
6888
6889         chown -R $RUNAS_ID $dir
6890         echo "testing non-root lfs migrate mode when not all links are in xattr"
6891         LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 101 100 "$RUNAS"
6892
6893         # clean up
6894         rm -rf $dir
6895 }
6896 run_test 56xb "lfs migration hard link support"
6897
6898 test_56xc() {
6899         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6900
6901         local dir="$DIR/$tdir"
6902
6903         test_mkdir "$dir" || error "cannot create dir $dir"
6904
6905         # Test 1: ensure file < 1 GB is always migrated with 1 stripe
6906         echo -n "Setting initial stripe for 20MB test file..."
6907         $LFS setstripe -c 2 -i 0 "$dir/20mb" ||
6908                 error "cannot setstripe 20MB file"
6909         echo "done"
6910         echo -n "Sizing 20MB test file..."
6911         truncate "$dir/20mb" 20971520 || error "cannot create 20MB test file"
6912         echo "done"
6913         echo -n "Verifying small file autostripe count is 1..."
6914         $LFS_MIGRATE -y -A -C 1 "$dir/20mb" ||
6915                 error "cannot migrate 20MB file"
6916         local stripe_count=$($LFS getstripe -c "$dir/20mb") ||
6917                 error "cannot get stripe for $dir/20mb"
6918         [ $stripe_count -eq 1 ] ||
6919                 error "unexpected stripe count $stripe_count for 20MB file"
6920         rm -f "$dir/20mb"
6921         echo "done"
6922
6923         # Test 2: File is small enough to fit within the available space on
6924         # sqrt(size_in_gb) + 1 OSTs but is larger than 1GB.  The file must
6925         # have at least an additional 1KB for each desired stripe for test 3
6926         echo -n "Setting stripe for 1GB test file..."
6927         $LFS setstripe -c 1 -i 0 "$dir/1gb" || error "cannot setstripe 1GB file"
6928         echo "done"
6929         echo -n "Sizing 1GB test file..."
6930         # File size is 1GB + 3KB
6931         truncate "$dir/1gb" 1073744896 || error "cannot create 1GB test file"
6932         echo "done"
6933
6934         # need at least 512MB per OST for 1GB file to fit in 2 stripes
6935         local avail=$($LCTL get_param -n llite.$FSNAME*.kbytesavail)
6936         if (( avail > 524288 * OSTCOUNT )); then
6937                 echo -n "Migrating 1GB file..."
6938                 $LFS_MIGRATE -y -A -C 1 "$dir/1gb" ||
6939                         error "cannot migrate 1GB file"
6940                 echo "done"
6941                 echo -n "Verifying autostripe count is sqrt(n) + 1..."
6942                 stripe_count=$($LFS getstripe -c "$dir/1gb") ||
6943                         error "cannot getstripe for 1GB file"
6944                 [ $stripe_count -eq 2 ] ||
6945                         error "unexpected stripe count $stripe_count != 2"
6946                 echo "done"
6947         fi
6948
6949         # Test 3: File is too large to fit within the available space on
6950         # sqrt(n) + 1 OSTs.  Simulate limited available space with -X
6951         if [ $OSTCOUNT -ge 3 ]; then
6952                 # The required available space is calculated as
6953                 # file size (1GB + 3KB) / OST count (3).
6954                 local kb_per_ost=349526
6955
6956                 echo -n "Migrating 1GB file with limit..."
6957                 $LFS_MIGRATE -y -A -C 1 -X $kb_per_ost "$dir/1gb" ||
6958                         error "cannot migrate 1GB file with limit"
6959                 echo "done"
6960
6961                 stripe_count=$($LFS getstripe -c "$dir/1gb")
6962                 echo -n "Verifying 1GB autostripe count with limited space..."
6963                 [ "$stripe_count" -a $stripe_count -ge 3 ] ||
6964                         error "unexpected stripe count $stripe_count (min 3)"
6965                 echo "done"
6966         fi
6967
6968         # clean up
6969         rm -rf $dir
6970 }
6971 run_test 56xc "lfs migration autostripe"
6972
6973 test_56xd() {
6974         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6975
6976         local dir=$DIR/$tdir
6977         local f_mgrt=$dir/$tfile.mgrt
6978         local f_yaml=$dir/$tfile.yaml
6979         local f_copy=$dir/$tfile.copy
6980         local layout_yaml="-E 1M -S 512K -c 1 -E -1 -S 1M -c 2 -i 0"
6981         local layout_copy="-c 2 -S 2M -i 1"
6982         local yamlfile=$dir/yamlfile
6983         local layout_before;
6984         local layout_after;
6985
6986         test_mkdir "$dir" || error "cannot create dir $dir"
6987         $LFS setstripe $layout_yaml $f_yaml ||
6988                 error "cannot setstripe $f_yaml with layout $layout_yaml"
6989         $LFS getstripe --yaml $f_yaml > $yamlfile
6990         $LFS setstripe $layout_copy $f_copy ||
6991                 error "cannot setstripe $f_copy with layout $layout_copy"
6992         touch $f_mgrt
6993         dd if=/dev/zero of=$f_mgrt bs=1M count=4
6994
6995         # 1. test option --yaml
6996         $LFS_MIGRATE -y --yaml $yamlfile $f_mgrt ||
6997                 error "cannot migrate $f_mgrt with --yaml $yamlfile"
6998         layout_before=$(get_layout_param $f_yaml)
6999         layout_after=$(get_layout_param $f_mgrt)
7000         [ "$layout_after" == "$layout_before" ] ||
7001                 error "lfs_migrate --yaml: $layout_after != $layout_before"
7002
7003         # 2. test option --copy
7004         $LFS_MIGRATE -y --copy $f_copy $f_mgrt ||
7005                 error "cannot migrate $f_mgrt with --copy $f_copy"
7006         layout_before=$(get_layout_param $f_copy)
7007         layout_after=$(get_layout_param $f_mgrt)
7008         [ "$layout_after" == "$layout_before" ] ||
7009                 error "lfs_migrate --copy: $layout_after != $layout_before"
7010 }
7011 run_test 56xd "check lfs_migrate --yaml and --copy support"
7012
7013 test_56xe() {
7014         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
7015
7016         local dir=$DIR/$tdir
7017         local f_comp=$dir/$tfile
7018         local layout="-E 1M -S 512K -c 1 -E -1 -S 1M -c 2 -i 0"
7019         local layout_before=""
7020         local layout_after=""
7021
7022         test_mkdir "$dir" || error "cannot create dir $dir"
7023         $LFS setstripe $layout $f_comp ||
7024                 error "cannot setstripe $f_comp with layout $layout"
7025         layout_before=$(get_layout_param $f_comp)
7026         dd if=/dev/zero of=$f_comp bs=1M count=4
7027
7028         # 1. migrate a comp layout file by lfs_migrate
7029         $LFS_MIGRATE -y $f_comp || error "cannot migrate $f_comp by lfs_migrate"
7030         layout_after=$(get_layout_param $f_comp)
7031         [ "$layout_before" == "$layout_after" ] ||
7032                 error "lfs_migrate: $layout_before != $layout_after"
7033
7034         # 2. migrate a comp layout file by lfs migrate
7035         $LFS migrate $f_comp || error "cannot migrate $f_comp by lfs migrate"
7036         layout_after=$(get_layout_param $f_comp)
7037         [ "$layout_before" == "$layout_after" ] ||
7038                 error "lfs migrate: $layout_before != $layout_after"
7039 }
7040 run_test 56xe "migrate a composite layout file"
7041
7042 test_56y() {
7043         [ $MDS1_VERSION -lt $(version_code 2.4.53) ] &&
7044                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53"
7045
7046         local res=""
7047         local dir=$DIR/$tdir
7048         local f1=$dir/file1
7049         local f2=$dir/file2
7050
7051         test_mkdir -p $dir || error "creating dir $dir"
7052         touch $f1 || error "creating std file $f1"
7053         $MULTIOP $f2 H2c || error "creating released file $f2"
7054
7055         # a directory can be raid0, so ask only for files
7056         res=$($LFS find $dir -L raid0 -type f | wc -l)
7057         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
7058
7059         res=$($LFS find $dir \! -L raid0 -type f | wc -l)
7060         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
7061
7062         # only files can be released, so no need to force file search
7063         res=$($LFS find $dir -L released)
7064         [[ $res == $f2 ]] || error "search released: found $res != $f2"
7065
7066         res=$($LFS find $dir -type f \! -L released)
7067         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
7068 }
7069 run_test 56y "lfs find -L raid0|released"
7070
7071 test_56z() { # LU-4824
7072         # This checks to make sure 'lfs find' continues after errors
7073         # There are two classes of errors that should be caught:
7074         # - If multiple paths are provided, all should be searched even if one
7075         #   errors out
7076         # - If errors are encountered during the search, it should not terminate
7077         #   early
7078         local dir=$DIR/$tdir
7079         local i
7080
7081         test_mkdir $dir
7082         for i in d{0..9}; do
7083                 test_mkdir $dir/$i
7084                 touch $dir/$i/$tfile
7085         done
7086         $LFS find $DIR/non_existent_dir $dir &&
7087                 error "$LFS find did not return an error"
7088         # Make a directory unsearchable. This should NOT be the last entry in
7089         # directory order.  Arbitrarily pick the 6th entry
7090         chmod 700 $($LFS find $dir -type d | sed '6!d')
7091
7092         $RUNAS $LFS find $DIR/non_existent $dir
7093         local count=$($RUNAS $LFS find $DIR/non_existent $dir | wc -l)
7094
7095         # The user should be able to see 10 directories and 9 files
7096         (( count == 19 )) ||
7097                 error "$LFS find found $count != 19 entries after error"
7098 }
7099 run_test 56z "lfs find should continue after an error"
7100
7101 test_56aa() { # LU-5937
7102         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
7103
7104         local dir=$DIR/$tdir
7105
7106         mkdir $dir
7107         $LFS setdirstripe -c$MDSCOUNT $dir/striped_dir
7108
7109         createmany -o $dir/striped_dir/${tfile}- 1024
7110         local dirs=$($LFS find --size +8k $dir/)
7111
7112         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
7113 }
7114 run_test 56aa "lfs find --size under striped dir"
7115
7116 test_56ab() { # LU-10705
7117         test_mkdir $DIR/$tdir
7118         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=8k count=1 seek=2k
7119         dd if=/dev/zero of=$DIR/$tdir/$tfile.2 bs=4k count=1 seek=4k
7120         dd if=/dev/zero of=$DIR/$tdir/$tfile.3 bs=1M count=2 seek=16
7121         # Flush writes to ensure valid blocks.  Need to be more thorough for
7122         # ZFS, since blocks are not allocated/returned to client immediately.
7123         sync_all_data
7124         wait_zfs_commit ost1 2
7125         cancel_lru_locks osc
7126         ls -ls $DIR/$tdir
7127
7128         local files=$($LFS find --size +16M $DIR/$tdir | wc -l)
7129
7130         [[ $files == 3 ]] || error ">16M size files $files isn't 3 as expected"
7131
7132         files=$($LFS find --blocks +1M $DIR/$tdir | wc -l)
7133         [[ $files == 1 ]] || error ">1M blocks files $files isn't 1 as expected"
7134
7135         rm -f $DIR/$tdir/$tfile.[123]
7136 }
7137 run_test 56ab "lfs find --blocks"
7138
7139 test_56ba() {
7140         [ $MDS1_VERSION -lt $(version_code 2.10.50) ] &&
7141                 skip "Need MDS version at least 2.10.50"
7142
7143         # Create composite files with one component
7144         local dir=$DIR/$tdir
7145
7146         setup_56 $dir/1Mfiles 5 1 "-S 1M --component-end 1M"
7147         # Create composite files with three components
7148         setup_56 $dir/2Mfiles 5 2 "-E 2M -S 1M -E 4M -E 6M"
7149         # Create non-composite files
7150         createmany -o $dir/${tfile}- 10
7151
7152         local nfiles=$($LFS find --component-end 1M --type f $dir | wc -l)
7153
7154         [[ $nfiles == 10 ]] ||
7155                 error "lfs find -E 1M found $nfiles != 10 files"
7156
7157         nfiles=$($LFS find ! -E 1M --type f $dir | wc -l)
7158         [[ $nfiles == 25 ]] ||
7159                 error "lfs find ! -E 1M found $nfiles != 25 files"
7160
7161         # All files have a component that starts at 0
7162         nfiles=$($LFS find --component-start 0 --type f $dir | wc -l)
7163         [[ $nfiles == 35 ]] ||
7164                 error "lfs find --component-start 0 - $nfiles != 35 files"
7165
7166         nfiles=$($LFS find --component-start 2M --type f $dir | wc -l)
7167         [[ $nfiles == 15 ]] ||
7168                 error "lfs find --component-start 2M - $nfiles != 15 files"
7169
7170         # All files created here have a componenet that does not starts at 2M
7171         nfiles=$($LFS find ! --component-start 2M --type f $dir | wc -l)
7172         [[ $nfiles == 35 ]] ||
7173                 error "lfs find ! --component-start 2M - $nfiles != 35 files"
7174
7175         # Find files with a specified number of components
7176         local nfiles=$($LFS find --component-count 3 --type f $dir | wc -l)
7177         [[ $nfiles == 15 ]] ||
7178                 error "lfs find --component-count 3 - $nfiles != 15 files"
7179
7180         # Remember non-composite files have a component count of zero
7181         local nfiles=$($LFS find --component-count 0 --type f $dir | wc -l)
7182         [[ $nfiles == 10 ]] ||
7183                 error "lfs find --component-count 0 - $nfiles != 10 files"
7184
7185         nfiles=$($LFS find ! --component-count 3 --type f $dir | wc -l)
7186         [[ $nfiles == 20 ]] ||
7187                 error "lfs find ! --component-count 3 - $nfiles != 20 files"
7188
7189         # All files have a flag called "init"
7190         local nfiles=$($LFS find --component-flags init --type f $dir | wc -l)
7191         [[ $nfiles == 35 ]] ||
7192                 error "lfs find --component-flags init - $nfiles != 35 files"
7193
7194         # Multi-component files will have a component not initialized
7195         local nfiles=$($LFS find ! --component-flags init --type f $dir | wc -l)
7196         [[ $nfiles == 15 ]] ||
7197                 error "lfs find !--component-flags init - $nfiles != 15 files"
7198
7199         rm -rf $dir
7200
7201 }
7202 run_test 56ba "test lfs find --component-end, -start, -count, and -flags"
7203
7204 test_56ca() {
7205         [[ $MDS1_VERSION -ge $(version_code 2.10.57) ]] ||
7206                 skip "Need MDS version at least 2.10.57"
7207
7208         local td=$DIR/$tdir
7209         local tf=$td/$tfile
7210         local dir
7211         local nfiles
7212         local cmd
7213         local i
7214         local j
7215
7216         # create mirrored directories and mirrored files
7217         mkdir $td || error "mkdir $td failed"
7218         $LFS mirror create -N3 $td || error "create mirrored dir $td failed"
7219         createmany -o $tf- 10 || error "create $tf- failed"
7220
7221         for i in $(seq 2); do
7222                 dir=$td/dir$i
7223                 mkdir $dir || error "mkdir $dir failed"
7224                 $LFS mirror create -N$((3 + i)) $dir ||
7225                         error "create mirrored dir $dir failed"
7226                 createmany -o $dir/$tfile- 10 ||
7227                         error "create $dir/$tfile- failed"
7228         done
7229
7230         # change the states of some mirrored files
7231         echo foo > $tf-6
7232         for i in $(seq 2); do
7233                 dir=$td/dir$i
7234                 for j in $(seq 4 9); do
7235                         echo foo > $dir/$tfile-$j
7236                 done
7237         done
7238
7239         # find mirrored files with specific mirror count
7240         cmd="$LFS find --mirror-count 3 --type f $td"
7241         nfiles=$($cmd | wc -l)
7242         [[ $nfiles = 10 ]] || error "$cmd: $nfiles != 10 files"
7243
7244         cmd="$LFS find ! --mirror-count 3 --type f $td"
7245         nfiles=$($cmd | wc -l)
7246         [[ $nfiles = 20 ]] || error "$cmd: $nfiles != 20 files"
7247
7248         cmd="$LFS find --mirror-count +2 --type f $td"
7249         nfiles=$($cmd | wc -l)
7250         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
7251
7252         cmd="$LFS find --mirror-count -6 --type f $td"
7253         nfiles=$($cmd | wc -l)
7254         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
7255
7256         # find mirrored files with specific file state
7257         cmd="$LFS find --maxdepth 1 --mirror-state=^ro --type f $td"
7258         [[ $($cmd) = $tf-6 ]] || error "$cmd: didn't return $tf-6"
7259
7260         cmd="$LFS find --mirror-state=ro --type f $td"
7261         nfiles=$($cmd | wc -l)
7262         [[ $nfiles = 17 ]] || error "$cmd: $nfiles != 17 files"
7263
7264         cmd="$LFS find ! --mirror-state=ro --type f $td"
7265         nfiles=$($cmd | wc -l)
7266         [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
7267
7268         cmd="$LFS find --mirror-state=wp --type f $td"
7269         nfiles=$($cmd | wc -l)
7270         [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
7271
7272         cmd="$LFS find ! --mirror-state=sp --type f $td"
7273         nfiles=$($cmd | wc -l)
7274         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
7275 }
7276 run_test 56ca "check lfs find --mirror-count|-N and --mirror-state"
7277
7278 test_57a() {
7279         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7280         # note test will not do anything if MDS is not local
7281         if [ "$mds1_FSTYPE" != ldiskfs ]; then
7282                 skip_env "ldiskfs only test"
7283         fi
7284         remote_mds_nodsh && skip "remote MDS with nodsh"
7285
7286         local MNTDEV="osd*.*MDT*.mntdev"
7287         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
7288         [ -z "$DEV" ] && error "can't access $MNTDEV"
7289         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
7290                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
7291                         error "can't access $DEV"
7292                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
7293                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
7294                 rm $TMP/t57a.dump
7295         done
7296 }
7297 run_test 57a "verify MDS filesystem created with large inodes =="
7298
7299 test_57b() {
7300         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7301         if [ "$mds1_FSTYPE" != ldiskfs ]; then
7302                 skip_env "ldiskfs only test"
7303         fi
7304         remote_mds_nodsh && skip "remote MDS with nodsh"
7305
7306         local dir=$DIR/$tdir
7307         local filecount=100
7308         local file1=$dir/f1
7309         local fileN=$dir/f$filecount
7310
7311         rm -rf $dir || error "removing $dir"
7312         test_mkdir -c1 $dir
7313         local mdtidx=$($LFS getstripe -m $dir)
7314         local mdtname=MDT$(printf %04x $mdtidx)
7315         local facet=mds$((mdtidx + 1))
7316
7317         echo "mcreating $filecount files"
7318         createmany -m $dir/f 1 $filecount || error "creating files in $dir"
7319
7320         # verify that files do not have EAs yet
7321         $LFS getstripe $file1 2>&1 | grep -q "no stripe" ||
7322                 error "$file1 has an EA"
7323         $LFS getstripe $fileN 2>&1 | grep -q "no stripe" ||
7324                 error "$fileN has an EA"
7325
7326         sync
7327         sleep 1
7328         df $dir  #make sure we get new statfs data
7329         local mdsfree=$(do_facet $facet \
7330                         lctl get_param -n osd*.*$mdtname.kbytesfree)
7331         local mdcfree=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
7332         local file
7333
7334         echo "opening files to create objects/EAs"
7335         for file in $(seq -f $dir/f%g 1 $filecount); do
7336                 $OPENFILE -f O_RDWR $file > /dev/null 2>&1 ||
7337                         error "opening $file"
7338         done
7339
7340         # verify that files have EAs now
7341         $LFS getstripe $file1 | grep -q "obdidx" || error "$file1 missing EA"
7342         $LFS getstripe $fileN | grep -q "obdidx" || error "$fileN missing EA"
7343
7344         sleep 1  #make sure we get new statfs data
7345         df $dir
7346         local mdsfree2=$(do_facet $facet \
7347                          lctl get_param -n osd*.*$mdtname.kbytesfree)
7348         local mdcfree2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
7349
7350         if [[ $mdcfree2 -lt $((mdcfree - 16)) ]]; then
7351                 if [ "$mdsfree" != "$mdsfree2" ]; then
7352                         error "MDC before $mdcfree != after $mdcfree2"
7353                 else
7354                         echo "MDC before $mdcfree != after $mdcfree2"
7355                         echo "unable to confirm if MDS has large inodes"
7356                 fi
7357         fi
7358         rm -rf $dir
7359 }
7360 run_test 57b "default LOV EAs are stored inside large inodes ==="
7361
7362 test_58() {
7363         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7364         [ -z "$(which wiretest 2>/dev/null)" ] &&
7365                         skip_env "could not find wiretest"
7366
7367         wiretest
7368 }
7369 run_test 58 "verify cross-platform wire constants =============="
7370
7371 test_59() {
7372         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7373
7374         echo "touch 130 files"
7375         createmany -o $DIR/f59- 130
7376         echo "rm 130 files"
7377         unlinkmany $DIR/f59- 130
7378         sync
7379         # wait for commitment of removal
7380         wait_delete_completed
7381 }
7382 run_test 59 "verify cancellation of llog records async ========="
7383
7384 TEST60_HEAD="test_60 run $RANDOM"
7385 test_60a() {
7386         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7387         remote_mgs_nodsh && skip "remote MGS with nodsh"
7388         do_facet mgs "! which run-llog.sh &> /dev/null" &&
7389                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
7390                         skip_env "missing subtest run-llog.sh"
7391
7392         log "$TEST60_HEAD - from kernel mode"
7393         do_facet mgs "$LCTL dk > /dev/null"
7394         do_facet mgs "bash run-llog.sh" || error "run-llog.sh failed"
7395         do_facet mgs $LCTL dk > $TMP/$tfile
7396
7397         # LU-6388: test llog_reader
7398         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
7399         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
7400         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
7401                         skip_env "missing llog_reader"
7402         local fstype=$(facet_fstype mgs)
7403         [ $fstype != ldiskfs -a $fstype != zfs ] &&
7404                 skip_env "Only for ldiskfs or zfs type mgs"
7405
7406         local mntpt=$(facet_mntpt mgs)
7407         local mgsdev=$(mgsdevname 1)
7408         local fid_list
7409         local fid
7410         local rec_list
7411         local rec
7412         local rec_type
7413         local obj_file
7414         local path
7415         local seq
7416         local oid
7417         local pass=true
7418
7419         #get fid and record list
7420         fid_list=($(awk '/9_sub.*record/ { print $NF }' $TMP/$tfile |
7421                 tail -n 4))
7422         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' $TMP/$tfile |
7423                 tail -n 4))
7424         #remount mgs as ldiskfs or zfs type
7425         stop mgs || error "stop mgs failed"
7426         mount_fstype mgs || error "remount mgs failed"
7427         for ((i = 0; i < ${#fid_list[@]}; i++)); do
7428                 fid=${fid_list[i]}
7429                 rec=${rec_list[i]}
7430                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
7431                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
7432                 oid=$((16#$oid))
7433
7434                 case $fstype in
7435                         ldiskfs )
7436                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
7437                         zfs )
7438                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
7439                 esac
7440                 echo "obj_file is $obj_file"
7441                 do_facet mgs $llog_reader $obj_file
7442
7443                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
7444                         awk '{ print $3 }' | sed -e "s/^type=//g")
7445                 if [ $rec_type != $rec ]; then
7446                         echo "FAILED test_60a wrong record type $rec_type," \
7447                               "should be $rec"
7448                         pass=false
7449                         break
7450                 fi
7451
7452                 #check obj path if record type is LLOG_LOGID_MAGIC
7453                 if [ "$rec" == "1064553b" ]; then
7454                         path=$(do_facet mgs $llog_reader $obj_file |
7455                                 grep "path=" | awk '{ print $NF }' |
7456                                 sed -e "s/^path=//g")
7457                         if [ $obj_file != $mntpt/$path ]; then
7458                                 echo "FAILED test_60a wrong obj path" \
7459                                       "$montpt/$path, should be $obj_file"
7460                                 pass=false
7461                                 break
7462                         fi
7463                 fi
7464         done
7465         rm -f $TMP/$tfile
7466         #restart mgs before "error", otherwise it will block the next test
7467         stop mgs || error "stop mgs failed"
7468         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
7469         $pass || error "test failed, see FAILED test_60a messages for specifics"
7470 }
7471 run_test 60a "llog_test run from kernel module and test llog_reader"
7472
7473 test_60b() { # bug 6411
7474         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7475
7476         dmesg > $DIR/$tfile
7477         LLOG_COUNT=$(do_facet mgs dmesg |
7478                      awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
7479                           /llog_[a-z]*.c:[0-9]/ {
7480                                 if (marker)
7481                                         from_marker++
7482                                 from_begin++
7483                           }
7484                           END {
7485                                 if (marker)
7486                                         print from_marker
7487                                 else
7488                                         print from_begin
7489                           }")
7490
7491         [[ $LLOG_COUNT -gt 120 ]] &&
7492                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
7493 }
7494 run_test 60b "limit repeated messages from CERROR/CWARN"
7495
7496 test_60c() {
7497         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7498
7499         echo "create 5000 files"
7500         createmany -o $DIR/f60c- 5000
7501 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
7502         lctl set_param fail_loc=0x80000137
7503         unlinkmany $DIR/f60c- 5000
7504         lctl set_param fail_loc=0
7505 }
7506 run_test 60c "unlink file when mds full"
7507
7508 test_60d() {
7509         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7510
7511         SAVEPRINTK=$(lctl get_param -n printk)
7512         # verify "lctl mark" is even working"
7513         MESSAGE="test message ID $RANDOM $$"
7514         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
7515         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
7516
7517         lctl set_param printk=0 || error "set lnet.printk failed"
7518         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
7519         MESSAGE="new test message ID $RANDOM $$"
7520         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
7521         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
7522         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
7523
7524         lctl set_param -n printk="$SAVEPRINTK"
7525 }
7526 run_test 60d "test printk console message masking"
7527
7528 test_60e() {
7529         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7530         remote_mds_nodsh && skip "remote MDS with nodsh"
7531
7532         touch $DIR/$tfile
7533 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
7534         do_facet mds1 lctl set_param fail_loc=0x15b
7535         rm $DIR/$tfile
7536 }
7537 run_test 60e "no space while new llog is being created"
7538
7539 test_60g() {
7540         local pid
7541         local i
7542
7543         test_mkdir -c $MDSCOUNT $DIR/$tdir
7544
7545         (
7546                 local index=0
7547                 while true; do
7548                         $LFS setdirstripe -i $(($index % $MDSCOUNT)) \
7549                                 -c $MDSCOUNT $DIR/$tdir/subdir$index \
7550                                 2>/dev/null
7551                         mkdir $DIR/$tdir/subdir$index 2>/dev/null
7552                         rmdir $DIR/$tdir/subdir$index 2>/dev/null
7553                         index=$((index + 1))
7554                 done
7555         ) &
7556
7557         pid=$!
7558
7559         for i in {0..100}; do
7560                 # define OBD_FAIL_OSD_TXN_START    0x19a
7561                 local index=$((i % MDSCOUNT + 1))
7562
7563                 do_facet mds$index $LCTL set_param fail_loc=0x8000019a \
7564                         > /dev/null
7565                 usleep 100
7566         done
7567
7568         kill -9 $pid
7569
7570         for i in $(seq $MDSCOUNT); do
7571                 do_facet mds$i $LCTL set_param fail_loc=0 > /dev/null
7572         done
7573
7574         mkdir $DIR/$tdir/new || error "mkdir failed"
7575         rmdir $DIR/$tdir/new || error "rmdir failed"
7576
7577         do_facet mds1 $LCTL lfsck_start -M $(facet_svc mds1) -A -C \
7578                 -t namespace
7579         for i in $(seq $MDSCOUNT); do
7580                 wait_update_facet mds$i "$LCTL get_param -n \
7581                         mdd.$(facet_svc mds$i).lfsck_namespace |
7582                         awk '/^status/ { print \\\$2 }'" "completed"
7583         done
7584
7585         ls -R $DIR/$tdir || error "ls failed"
7586         rm -rf $DIR/$tdir || error "rmdir failed"
7587 }
7588 run_test 60g "transaction abort won't cause MDT hung"
7589
7590 test_60h() {
7591         [ $MDS1_VERSION -le $(version_code 2.12.52) ] &&
7592                 skip "Need MDS version at least 2.12.52"
7593         [ $MDSCOUNT -lt 2 ] && skip "Need at least 2 MDTs"
7594
7595         local f
7596
7597         #define OBD_FAIL_MDS_STRIPE_CREATE       0x188
7598         #define OBD_FAIL_MDS_STRIPE_FID          0x189
7599         for fail_loc in 0x80000188 0x80000189; do
7600                 do_facet mds1 "$LCTL set_param fail_loc=$fail_loc"
7601                 $LFS mkdir -c $MDSCOUNT -i 0 $DIR/$tdir-$fail_loc ||
7602                         error "mkdir $dir-$fail_loc failed"
7603                 for i in {0..10}; do
7604                         # create may fail on missing stripe
7605                         echo $i > $DIR/$tdir-$fail_loc/$i
7606                 done
7607                 $LFS getdirstripe $DIR/$tdir-$fail_loc ||
7608                         error "getdirstripe $tdir-$fail_loc failed"
7609                 $LFS migrate -m 1 $DIR/$tdir-$fail_loc ||
7610                         error "migrate $tdir-$fail_loc failed"
7611                 $LFS getdirstripe $DIR/$tdir-$fail_loc ||
7612                         error "getdirstripe $tdir-$fail_loc failed"
7613                 pushd $DIR/$tdir-$fail_loc
7614                 for f in *; do
7615                         echo $f | cmp $f - || error "$f data mismatch"
7616                 done
7617                 popd
7618                 rm -rf $DIR/$tdir-$fail_loc
7619         done
7620 }
7621 run_test 60h "striped directory with missing stripes can be accessed"
7622
7623 test_61a() {
7624         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7625
7626         f="$DIR/f61"
7627         dd if=/dev/zero of=$f bs=$PAGE_SIZE count=1 || error "dd $f failed"
7628         cancel_lru_locks osc
7629         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
7630         sync
7631 }
7632 run_test 61a "mmap() writes don't make sync hang ================"
7633
7634 test_61b() {
7635         mmap_mknod_test $DIR/$tfile || error "mmap_mknod_test failed"
7636 }
7637 run_test 61b "mmap() of unstriped file is successful"
7638
7639 # bug 2330 - insufficient obd_match error checking causes LBUG
7640 test_62() {
7641         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7642
7643         f="$DIR/f62"
7644         echo foo > $f
7645         cancel_lru_locks osc
7646         lctl set_param fail_loc=0x405
7647         cat $f && error "cat succeeded, expect -EIO"
7648         lctl set_param fail_loc=0
7649 }
7650 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
7651 # match every page all of the time.
7652 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
7653
7654 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
7655 # Though this test is irrelevant anymore, it helped to reveal some
7656 # other grant bugs (LU-4482), let's keep it.
7657 test_63a() {   # was test_63
7658         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7659
7660         MAX_DIRTY_MB=$(lctl get_param -n osc.*.max_dirty_mb | head -n 1)
7661
7662         for i in `seq 10` ; do
7663                 dd if=/dev/zero of=$DIR/f63 bs=8k &
7664                 sleep 5
7665                 kill $!
7666                 sleep 1
7667         done
7668
7669         rm -f $DIR/f63 || true
7670 }
7671 run_test 63a "Verify oig_wait interruption does not crash ======="
7672
7673 # bug 2248 - async write errors didn't return to application on sync
7674 # bug 3677 - async write errors left page locked
7675 test_63b() {
7676         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7677
7678         debugsave
7679         lctl set_param debug=-1
7680
7681         # ensure we have a grant to do async writes
7682         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
7683         rm $DIR/$tfile
7684
7685         sync    # sync lest earlier test intercept the fail_loc
7686
7687         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7688         lctl set_param fail_loc=0x80000406
7689         $MULTIOP $DIR/$tfile Owy && \
7690                 error "sync didn't return ENOMEM"
7691         sync; sleep 2; sync     # do a real sync this time to flush page
7692         lctl get_param -n llite.*.dump_page_cache | grep locked && \
7693                 error "locked page left in cache after async error" || true
7694         debugrestore
7695 }
7696 run_test 63b "async write errors should be returned to fsync ==="
7697
7698 test_64a () {
7699         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7700
7701         lfs df $DIR
7702         lctl get_param osc.*[oO][sS][cC][_-]*.cur* | grep "=[1-9]"
7703 }
7704 run_test 64a "verify filter grant calculations (in kernel) ====="
7705
7706 test_64b () {
7707         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7708
7709         sh oos.sh $MOUNT || error "oos.sh failed: $?"
7710 }
7711 run_test 64b "check out-of-space detection on client"
7712
7713 test_64c() {
7714         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
7715 }
7716 run_test 64c "verify grant shrink"
7717
7718 # this does exactly what osc_request.c:osc_announce_cached() does in
7719 # order to calculate max amount of grants to ask from server
7720 want_grant() {
7721         local tgt=$1
7722
7723         local nrpages=$($LCTL get_param -n osc.${tgt}.max_pages_per_rpc)
7724         local rpc_in_flight=$($LCTL get_param -n osc.${tgt}.max_rpcs_in_flight)
7725
7726         ((rpc_in_flight ++));
7727         nrpages=$((nrpages * rpc_in_flight))
7728
7729         local dirty_max_pages=$($LCTL get_param -n osc.${tgt}.max_dirty_mb)
7730
7731         dirty_max_pages=$((dirty_max_pages * 1024 * 1024 / PAGE_SIZE))
7732
7733         [[ $dirty_max_pages -gt $nrpages ]] && nrpages=$dirty_max_pages
7734         local undirty=$((nrpages * PAGE_SIZE))
7735
7736         local max_extent_pages
7737         max_extent_pages=$($LCTL get_param osc.${tgt}.import |
7738             grep grant_max_extent_size | awk '{print $2}')
7739         max_extent_pages=$((max_extent_pages / PAGE_SIZE))
7740         local nrextents=$(((nrpages + max_extent_pages - 1) / max_extent_pages))
7741         local grant_extent_tax
7742         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
7743             grep grant_extent_tax | awk '{print $2}')
7744
7745         undirty=$((undirty + nrextents * grant_extent_tax))
7746
7747         echo $undirty
7748 }
7749
7750 # this is size of unit for grant allocation. It should be equal to
7751 # what tgt_grant.c:tgt_grant_chunk() calculates
7752 grant_chunk() {
7753         local tgt=$1
7754         local max_brw_size
7755         local grant_extent_tax
7756
7757         max_brw_size=$($LCTL get_param osc.${tgt}.import |
7758             grep max_brw_size | awk '{print $2}')
7759
7760         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
7761             grep grant_extent_tax | awk '{print $2}')
7762
7763         echo $(((max_brw_size + grant_extent_tax) * 2))
7764 }
7765
7766 test_64d() {
7767         [ $OST1_VERSION -lt $(version_code 2.10.56) ] &&
7768                 skip "OST < 2.10.55 doesn't limit grants enough"
7769
7770         local tgt=$($LCTL dl | grep "0000-osc-[^mM]" | awk '{print $4}')
7771         local file=$DIR/$tfile
7772
7773         [[ $($LCTL get_param osc.${tgt}.import |
7774              grep "connect_flags:.*grant_param") ]] ||
7775                 skip "no grant_param connect flag"
7776
7777         local olddebug=$($LCTL get_param -n debug 2> /dev/null)
7778
7779         $LCTL set_param debug="$OLDDEBUG" 2> /dev/null || true
7780
7781         local max_cur_granted=$(($(want_grant $tgt) + $(grant_chunk $tgt)))
7782         stack_trap "rm -f $file" EXIT
7783
7784         $LFS setstripe $file -i 0 -c 1
7785         dd if=/dev/zero of=$file bs=1M count=1000 &
7786         ddpid=$!
7787
7788         while true
7789         do
7790                 local cur_grant=$($LCTL get_param -n osc.${tgt}.cur_grant_bytes)
7791                 if [[ $cur_grant -gt $max_cur_granted ]]
7792                 then
7793                         kill $ddpid
7794                         error "cur_grant $cur_grant > $max_cur_granted"
7795                 fi
7796                 kill -0 $ddpid
7797                 [[ $? -ne 0 ]] && break;
7798                 sleep 2
7799         done
7800
7801         rm -f $DIR/$tfile
7802         wait_delete_completed
7803         $LCTL set_param debug="$olddebug" 2> /dev/null || true
7804 }
7805 run_test 64d "check grant limit exceed"
7806
7807 # bug 1414 - set/get directories' stripe info
7808 test_65a() {
7809         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7810
7811         test_mkdir $DIR/$tdir
7812         touch $DIR/$tdir/f1
7813         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
7814 }
7815 run_test 65a "directory with no stripe info"
7816
7817 test_65b() {
7818         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7819
7820         test_mkdir $DIR/$tdir
7821         local STRIPESIZE=$($LFS getstripe -S $DIR/$tdir)
7822
7823         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
7824                                                 error "setstripe"
7825         touch $DIR/$tdir/f2
7826         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
7827 }
7828 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
7829
7830 test_65c() {
7831         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7832         [ $OSTCOUNT -lt 2 ] && skip_env "need at least 2 OSTs"
7833
7834         test_mkdir $DIR/$tdir
7835         local stripesize=$($LFS getstripe -S $DIR/$tdir)
7836
7837         $LFS setstripe -S $((stripesize * 4)) -i 1 \
7838                 -c $((OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
7839         touch $DIR/$tdir/f3
7840         $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
7841 }
7842 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
7843
7844 test_65d() {
7845         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7846
7847         test_mkdir $DIR/$tdir
7848         local STRIPECOUNT=$($LFS getstripe -c $DIR/$tdir)
7849         local STRIPESIZE=$($LFS getstripe -S $DIR/$tdir)
7850
7851         if [[ $STRIPECOUNT -le 0 ]]; then
7852                 sc=1
7853         elif [[ $STRIPECOUNT -gt $LOV_MAX_STRIPE_COUNT ]]; then
7854                 [[ $OSTCOUNT -gt $LOV_MAX_STRIPE_COUNT ]] &&
7855                         sc=$LOV_MAX_STRIPE_COUNT || sc=$(($OSTCOUNT - 1))
7856         else
7857                 sc=$(($STRIPECOUNT - 1))
7858         fi
7859         $LFS setstripe -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
7860         touch $DIR/$tdir/f4 $DIR/$tdir/f5
7861         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
7862                 error "lverify failed"
7863 }
7864 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
7865
7866 test_65e() {
7867         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7868
7869         test_mkdir $DIR/$tdir
7870
7871         $LFS setstripe $DIR/$tdir || error "setstripe"
7872         $LFS getstripe -v $DIR/$tdir | grep "Default" ||
7873                                         error "no stripe info failed"
7874         touch $DIR/$tdir/f6
7875         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
7876 }
7877 run_test 65e "directory setstripe defaults"
7878
7879 test_65f() {
7880         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7881
7882         test_mkdir $DIR/${tdir}f
7883         $RUNAS $LFS setstripe $DIR/${tdir}f &&
7884                 error "setstripe succeeded" || true
7885 }
7886 run_test 65f "dir setstripe permission (should return error) ==="
7887
7888 test_65g() {
7889         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7890
7891         test_mkdir $DIR/$tdir
7892         local STRIPESIZE=$($LFS getstripe -S $DIR/$tdir)
7893
7894         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
7895                 error "setstripe -S failed"
7896         $LFS setstripe -d $DIR/$tdir || error "setstripe -d failed"
7897         $LFS getstripe -v $DIR/$tdir | grep "Default" ||
7898                 error "delete default stripe failed"
7899 }
7900 run_test 65g "directory setstripe -d"
7901
7902 test_65h() {
7903         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7904
7905         test_mkdir $DIR/$tdir
7906         local STRIPESIZE=$($LFS getstripe -S $DIR/$tdir)
7907
7908         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
7909                 error "setstripe -S failed"
7910         test_mkdir $DIR/$tdir/dd1
7911         [ $($LFS getstripe -c $DIR/$tdir) = $($LFS getstripe -c $DIR/$tdir/dd1) ] ||
7912                 error "stripe info inherit failed"
7913 }
7914 run_test 65h "directory stripe info inherit ===================="
7915
7916 test_65i() {
7917         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7918
7919         save_layout_restore_at_exit $MOUNT
7920
7921         # bug6367: set non-default striping on root directory
7922         $LFS setstripe -S 65536 -c -1 $MOUNT || error "error setting stripe"
7923
7924         # bug12836: getstripe on -1 default directory striping
7925         $LFS getstripe $MOUNT || error "getstripe $MOUNT failed"
7926
7927         # bug12836: getstripe -v on -1 default directory striping
7928         $LFS getstripe -v $MOUNT || error "getstripe -v $MOUNT failed"
7929
7930         # bug12836: new find on -1 default directory striping
7931         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
7932 }
7933 run_test 65i "various tests to set root directory striping"
7934
7935 test_65j() { # bug6367
7936         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7937
7938         sync; sleep 1
7939
7940         # if we aren't already remounting for each test, do so for this test
7941         if [ "$I_MOUNTED" = "yes" ]; then
7942                 cleanup || error "failed to unmount"
7943                 setup
7944         fi
7945
7946         save_layout_restore_at_exit $MOUNT
7947
7948         $LFS setstripe -d $MOUNT || error "setstripe failed"
7949 }
7950 run_test 65j "set default striping on root directory (bug 6367)="
7951
7952 cleanup_65k() {
7953         rm -rf $DIR/$tdir
7954         wait_delete_completed
7955         do_facet $SINGLEMDS "lctl set_param -n \
7956                 osp.$ost*MDT0000.max_create_count=$max_count"
7957         do_facet $SINGLEMDS "lctl set_param -n \
7958                 osp.$ost*MDT0000.create_count=$count"
7959         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
7960         echo $INACTIVE_OSC "is Activate"
7961
7962         wait_osc_import_state mds ost$(( ostnum + 1 )) FULL
7963 }
7964
7965 test_65k() { # bug11679
7966         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7967         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
7968         remote_mds_nodsh && skip "remote MDS with nodsh"
7969
7970         local disable_precreate=true
7971         [ $MDS1_VERSION -le $(version_code 2.8.54) ] &&
7972                 disable_precreate=false
7973
7974         echo "Check OST status: "
7975         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
7976                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
7977
7978         for OSC in $MDS_OSCS; do
7979                 echo $OSC "is active"
7980                 do_facet $SINGLEMDS lctl --device %$OSC activate
7981         done
7982
7983         for INACTIVE_OSC in $MDS_OSCS; do
7984                 local ost=$(osc_to_ost $INACTIVE_OSC)
7985                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
7986                                lov.*md*.target_obd |
7987                                awk -F: /$ost/'{ print $1 }' | head -n 1)
7988
7989                 mkdir -p $DIR/$tdir
7990                 $LFS setstripe -i $ostnum -c 1 $DIR/$tdir
7991                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
7992
7993                 echo "Deactivate: " $INACTIVE_OSC
7994                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
7995
7996                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
7997                               osp.$ost*MDT0000.create_count")
7998                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
7999                                   osp.$ost*MDT0000.max_create_count")
8000                 $disable_precreate &&
8001                         do_facet $SINGLEMDS "lctl set_param -n \
8002                                 osp.$ost*MDT0000.max_create_count=0"
8003
8004                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
8005                         [ -f $DIR/$tdir/$idx ] && continue
8006                         echo "$LFS setstripe -i $idx -c 1 $DIR/$tdir/$idx"
8007                         $LFS setstripe -i $idx -c 1 $DIR/$tdir/$idx ||
8008                                 { cleanup_65k;
8009                                   error "setstripe $idx should succeed"; }
8010                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
8011                 done
8012                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
8013                 rmdir $DIR/$tdir
8014
8015                 do_facet $SINGLEMDS "lctl set_param -n \
8016                         osp.$ost*MDT0000.max_create_count=$max_count"
8017                 do_facet $SINGLEMDS "lctl set_param -n \
8018                         osp.$ost*MDT0000.create_count=$count"
8019                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
8020                 echo $INACTIVE_OSC "is Activate"
8021
8022                 wait_osc_import_state mds ost$(( ostnum + 1 )) FULL
8023         done
8024 }
8025 run_test 65k "validate manual striping works properly with deactivated OSCs"
8026
8027 test_65l() { # bug 12836
8028         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8029
8030         test_mkdir -p $DIR/$tdir/test_dir
8031         $LFS setstripe -c -1 $DIR/$tdir/test_dir
8032         $LFS find -mtime -1 $DIR/$tdir >/dev/null
8033 }
8034 run_test 65l "lfs find on -1 stripe dir ========================"
8035
8036 test_65m() {
8037         local layout=$(save_layout $MOUNT)
8038         $RUNAS $LFS setstripe -c 2 $MOUNT && {
8039                 restore_layout $MOUNT $layout
8040                 error "setstripe should fail by non-root users"
8041         }
8042         true
8043 }
8044 run_test 65m "normal user can't set filesystem default stripe"
8045
8046 test_65n() {
8047         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
8048         [[ $MDS1_VERSION -ge $(version_code 2.12.50) ]] ||
8049                 skip "Need MDS version at least 2.12.50"
8050         [[ $PARALLEL != "yes" ]] || skip "skip parallel run"
8051
8052         [[ $OSTCOUNT -ge 2 ]] || skip_env "needs >= 2 OSTs"
8053         which getfattr > /dev/null 2>&1 || skip_env "no getfattr command"
8054         which setfattr > /dev/null 2>&1 || skip_env "no setfattr command"
8055
8056         local root_layout=$(save_layout $MOUNT)
8057         stack_trap "restore_layout $MOUNT $root_layout" EXIT
8058
8059         # new subdirectory under root directory should not inherit
8060         # the default layout from root
8061         local dir1=$MOUNT/$tdir-1
8062         mkdir $dir1 || error "mkdir $dir1 failed"
8063         ! getfattr -n trusted.lov $dir1 &> /dev/null ||
8064                 error "$dir1 shouldn't have LOV EA"
8065
8066         # delete the default layout on root directory
8067         $LFS setstripe -d $MOUNT || error "delete root default layout failed"
8068
8069         local dir2=$MOUNT/$tdir-2
8070         mkdir $dir2 || error "mkdir $dir2 failed"
8071         ! getfattr -n trusted.lov $dir2 &> /dev/null ||
8072                 error "$dir2 shouldn't have LOV EA"
8073
8074         # set a new striping pattern on root directory
8075         local def_stripe_size=$($LFS getstripe -S $MOUNT)
8076         local new_def_stripe_size=$((def_stripe_size * 2))
8077         $LFS setstripe -S $new_def_stripe_size $MOUNT ||
8078                 error "set stripe size on $MOUNT failed"
8079
8080         # new file created in $dir2 should inherit the new stripe size from
8081         # the filesystem default
8082         local file2=$dir2/$tfile-2
8083         touch $file2 || error "touch $file2 failed"
8084
8085         local file2_stripe_size=$($LFS getstripe -S $file2)
8086         [[ $file2_stripe_size -eq $new_def_stripe_size ]] ||
8087                 error "$file2 didn't inherit stripe size $new_def_stripe_size"
8088
8089         local dir3=$MOUNT/$tdir-3
8090         mkdir $dir3 || error "mkdir $dir3 failed"
8091         # $dir3 shouldn't have LOV EA, but "lfs getstripe -d $dir3" should show
8092         # the root layout, which is the actual default layout that will be used
8093         # when new files are created in $dir3.
8094         local dir3_layout=$(get_layout_param $dir3)
8095         local root_dir_layout=$(get_layout_param $MOUNT)
8096         [[ "$dir3_layout" = "$root_dir_layout" ]] ||
8097                 error "$dir3 should show the default layout from $MOUNT"
8098
8099         # set OST pool on root directory
8100         local pool=$TESTNAME
8101         pool_add $pool || error "add $pool failed"
8102         pool_add_targets $pool 0 $((OSTCOUNT - 1)) 1 ||
8103                 error "add targets to $pool failed"
8104
8105         $LFS setstripe -p $pool $MOUNT ||
8106                 error "set OST pool on $MOUNT failed"
8107
8108         # new file created in $dir3 should inherit the pool from
8109         # the filesystem default
8110         local file3=$dir3/$tfile-3
8111         touch $file3 || error "touch $file3 failed"
8112
8113         local file3_pool=$($LFS getstripe -p $file3)
8114         [[ "$file3_pool" = "$pool" ]] ||
8115                 error "$file3 didn't inherit OST pool $pool"
8116
8117         local dir4=$MOUNT/$tdir-4
8118         mkdir $dir4 || error "mkdir $dir4 failed"
8119         local dir4_layout=$(get_layout_param $dir4)
8120         root_dir_layout=$(get_layout_param $MOUNT)
8121         echo "$LFS getstripe -d $dir4"
8122         $LFS getstripe -d $dir4
8123         echo "$LFS getstripe -d $MOUNT"
8124         $LFS getstripe -d $MOUNT
8125         [[ "$dir4_layout" = "$root_dir_layout" ]] ||
8126                 error "$dir4 should show the default layout from $MOUNT"
8127
8128         # new file created in $dir4 should inherit the pool from
8129         # the filesystem default
8130         local file4=$dir4/$tfile-4
8131         touch $file4 || error "touch $file4 failed"
8132
8133         local file4_pool=$($LFS getstripe -p $file4)
8134         [[ "$file4_pool" = "$pool" ]] ||
8135                 error "$file4 didn't inherit OST pool $pool"
8136
8137         # new subdirectory under non-root directory should inherit
8138         # the default layout from its parent directory
8139         $LFS setstripe -S $new_def_stripe_size -p $pool $dir4 ||
8140                 error "set directory layout on $dir4 failed"
8141
8142         local dir5=$dir4/$tdir-5
8143         mkdir $dir5 || error "mkdir $dir5 failed"
8144
8145         dir4_layout=$(get_layout_param $dir4)
8146         local dir5_layout=$(get_layout_param $dir5)
8147         [[ "$dir4_layout" = "$dir5_layout" ]] ||
8148                 error "$dir5 should inherit the default layout from $dir4"
8149
8150         # though subdir under ROOT doesn't inherit default layout, but
8151         # its sub dir/file should be created with default layout.
8152         [[ $MDSCOUNT -ge 2 ]] || skip_env "needs >= 2 MDTs"
8153         [[ $MDS1_VERSION -ge $(version_code 2.12.59) ]] ||
8154                 skip "Need MDS version at least 2.12.59"
8155
8156         local default_lmv_count=$($LFS getdirstripe -D -c $MOUNT)
8157         local default_lmv_index=$($LFS getdirstripe -D -i $MOUNT)
8158         local default_lmv_hash=$($LFS getdirstripe -D -H $MOUNT)
8159
8160         if [ $default_lmv_hash == "none" ]; then
8161                 stack_trap "$LFS setdirstripe -D -d $MOUNT" EXIT
8162         else
8163                 stack_trap "$LFS setdirstripe -D -i $default_lmv_index \
8164                         -c $default_lmv_count -H $default_lmv_hash $MOUNT" EXIT
8165         fi
8166
8167         $LFS setdirstripe -D -c 2 $MOUNT ||
8168                 error "setdirstripe -D -c 2 failed"
8169         mkdir $MOUNT/$tdir-6 || error "mkdir $tdir-6 failed"
8170         local lmv_count=$($LFS getdirstripe -c $MOUNT/$tdir-6)
8171         [ $lmv_count -eq 2 ] || error "$tdir-6 stripe count $lmv_count"
8172 }
8173 run_test 65n "don't inherit default layout from root for new subdirectories"
8174
8175 # bug 2543 - update blocks count on client
8176 test_66() {
8177         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8178
8179         COUNT=${COUNT:-8}
8180         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
8181         sync; sync_all_data; sync; sync_all_data
8182         cancel_lru_locks osc
8183         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
8184         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
8185 }
8186 run_test 66 "update inode blocks count on client ==============="
8187
8188 meminfo() {
8189         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
8190 }
8191
8192 swap_used() {
8193         swapon -s | awk '($1 == "'$1'") { print $4 }'
8194 }
8195
8196 # bug5265, obdfilter oa2dentry return -ENOENT
8197 # #define OBD_FAIL_SRV_ENOENT 0x217
8198 test_69() {
8199         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8200         remote_ost_nodsh && skip "remote OST with nodsh"
8201
8202         f="$DIR/$tfile"
8203         $LFS setstripe -c 1 -i 0 $f
8204
8205         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
8206
8207         do_facet ost1 lctl set_param fail_loc=0x217
8208         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
8209         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
8210
8211         do_facet ost1 lctl set_param fail_loc=0
8212         $DIRECTIO write $f 0 2 || error "write error"
8213
8214         cancel_lru_locks osc
8215         $DIRECTIO read $f 0 1 || error "read error"
8216
8217         do_facet ost1 lctl set_param fail_loc=0x217
8218         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
8219
8220         do_facet ost1 lctl set_param fail_loc=0
8221         rm -f $f
8222 }
8223 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
8224
8225 test_71() {
8226         test_mkdir $DIR/$tdir
8227         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
8228         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
8229 }
8230 run_test 71 "Running dbench on lustre (don't segment fault) ===="
8231
8232 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
8233         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8234         [ "$RUNAS_ID" = "$UID" ] &&
8235                 skip_env "RUNAS_ID = UID = $UID -- skipping"
8236         # Check that testing environment is properly set up. Skip if not
8237         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS ||
8238                 skip_env "User $RUNAS_ID does not exist - skipping"
8239
8240         touch $DIR/$tfile
8241         chmod 777 $DIR/$tfile
8242         chmod ug+s $DIR/$tfile
8243         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
8244                 error "$RUNAS dd $DIR/$tfile failed"
8245         # See if we are still setuid/sgid
8246         [ -u $DIR/$tfile ] || [ -g $DIR/$tfile ] &&
8247                 error "S/gid is not dropped on write"
8248         # Now test that MDS is updated too
8249         cancel_lru_locks mdc
8250         [ -u $DIR/$tfile ] || [ -g $DIR/$tfile ] &&
8251                 error "S/gid is not dropped on MDS"
8252         rm -f $DIR/$tfile
8253 }
8254 run_test 72a "Test that remove suid works properly (bug5695) ===="
8255
8256 test_72b() { # bug 24226 -- keep mode setting when size is not changing
8257         local perm
8258
8259         [ "$RUNAS_ID" = "$UID" ] &&
8260                 skip_env "RUNAS_ID = UID = $UID -- skipping"
8261         [ "$RUNAS_ID" -eq 0 ] &&
8262                 skip_env "RUNAS_ID = 0 -- skipping"
8263         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8264         # Check that testing environment is properly set up. Skip if not
8265         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS ||
8266                 skip_env "User $RUNAS_ID does not exist - skipping"
8267
8268         touch $DIR/${tfile}-f{g,u}
8269         test_mkdir $DIR/${tfile}-dg
8270         test_mkdir $DIR/${tfile}-du
8271         chmod 770 $DIR/${tfile}-{f,d}{g,u}
8272         chmod g+s $DIR/${tfile}-{f,d}g
8273         chmod u+s $DIR/${tfile}-{f,d}u
8274         for perm in 777 2777 4777; do
8275                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
8276                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
8277                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
8278                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
8279         done
8280         true
8281 }
8282 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
8283
8284 # bug 3462 - multiple simultaneous MDC requests
8285 test_73() {
8286         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8287
8288         test_mkdir $DIR/d73-1
8289         test_mkdir $DIR/d73-2
8290         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
8291         pid1=$!
8292
8293         lctl set_param fail_loc=0x80000129
8294         $MULTIOP $DIR/d73-1/f73-2 Oc &
8295         sleep 1
8296         lctl set_param fail_loc=0
8297
8298         $MULTIOP $DIR/d73-2/f73-3 Oc &
8299         pid3=$!
8300
8301         kill -USR1 $pid1
8302         wait $pid1 || return 1
8303
8304         sleep 25
8305
8306         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
8307         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
8308         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
8309
8310         rm -rf $DIR/d73-*
8311 }
8312 run_test 73 "multiple MDC requests (should not deadlock)"
8313
8314 test_74a() { # bug 6149, 6184
8315         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8316
8317         touch $DIR/f74a
8318         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
8319         #
8320         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
8321         # will spin in a tight reconnection loop
8322         $LCTL set_param fail_loc=0x8000030e
8323         # get any lock that won't be difficult - lookup works.
8324         ls $DIR/f74a
8325         $LCTL set_param fail_loc=0
8326         rm -f $DIR/f74a
8327         true
8328 }
8329 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
8330
8331 test_74b() { # bug 13310
8332         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8333
8334         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
8335         #
8336         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
8337         # will spin in a tight reconnection loop
8338         $LCTL set_param fail_loc=0x8000030e
8339         # get a "difficult" lock
8340         touch $DIR/f74b
8341         $LCTL set_param fail_loc=0
8342         rm -f $DIR/f74b
8343         true
8344 }
8345 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
8346
8347 test_74c() {
8348         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8349
8350         #define OBD_FAIL_LDLM_NEW_LOCK
8351         $LCTL set_param fail_loc=0x319
8352         touch $DIR/$tfile && error "touch successful"
8353         $LCTL set_param fail_loc=0
8354         true
8355 }
8356 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
8357
8358 num_inodes() {
8359         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
8360 }
8361
8362 test_76() { # Now for bug 20433, added originally in bug 1443
8363         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8364
8365         cancel_lru_locks osc
8366         local cpus=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
8367         local before=$(num_inodes)
8368         local count=$((512 * cpus))
8369         [ "$SLOW" = "no" ] && count=$((64 * cpus))
8370
8371         echo "before inodes: $before"
8372         for i in $(seq $count); do
8373                 touch $DIR/$tfile
8374                 rm -f $DIR/$tfile
8375         done
8376         cancel_lru_locks osc
8377         local after=$(num_inodes)
8378         echo "after inodes: $after"
8379         while (( after > before + 8 * ${cpus:-1} )); do
8380                 sleep 1
8381                 after=$(num_inodes)
8382                 wait=$((wait + 1))
8383                 (( wait % 5 == 0 )) && echo "wait $wait seconds inodes: $after"
8384                 if (( wait > 30 )); then
8385                         error "inode slab grew from $before to $after"
8386                 fi
8387         done
8388 }
8389 run_test 76 "confirm clients recycle inodes properly ===="
8390
8391
8392 export ORIG_CSUM=""
8393 set_checksums()
8394 {
8395         # Note: in sptlrpc modes which enable its own bulk checksum, the
8396         # original crc32_le bulk checksum will be automatically disabled,
8397         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
8398         # will be checked by sptlrpc code against sptlrpc bulk checksum.
8399         # In this case set_checksums() will not be no-op, because sptlrpc
8400         # bulk checksum will be enabled all through the test.
8401
8402         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
8403         lctl set_param -n osc.*.checksums $1
8404         return 0
8405 }
8406
8407 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
8408                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
8409 CKSUM_TYPES=${CKSUM_TYPES:-$(lctl get_param -n osc.*osc-[^mM]*.checksum_type |
8410                              tr -d [] | head -n1)}
8411 set_checksum_type()
8412 {
8413         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
8414         rc=$?
8415         log "set checksum type to $1, rc = $rc"
8416         return $rc
8417 }
8418
8419 get_osc_checksum_type()
8420 {
8421         # arugment 1: OST name, like OST0000
8422         ost=$1
8423         checksum_type=$(lctl get_param -n osc.*${ost}-osc-[^mM]*.checksum_type |
8424                         sed 's/.*\[\(.*\)\].*/\1/g')
8425         rc=$?
8426         [ $rc -ne 0 ] && error "failed to get checksum type of $ost, rc = $rc, output = $checksum_type"
8427         echo $checksum_type
8428 }
8429
8430 F77_TMP=$TMP/f77-temp
8431 F77SZ=8
8432 setup_f77() {
8433         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
8434                 error "error writing to $F77_TMP"
8435 }
8436
8437 test_77a() { # bug 10889
8438         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8439         $GSS && skip_env "could not run with gss"
8440
8441         [ ! -f $F77_TMP ] && setup_f77
8442         set_checksums 1
8443         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
8444         set_checksums 0
8445         rm -f $DIR/$tfile
8446 }
8447 run_test 77a "normal checksum read/write operation"
8448
8449 test_77b() { # bug 10889
8450         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8451         $GSS && skip_env "could not run with gss"
8452
8453         [ ! -f $F77_TMP ] && setup_f77
8454         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
8455         $LCTL set_param fail_loc=0x80000409
8456         set_checksums 1
8457
8458         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
8459                 error "dd error: $?"
8460         $LCTL set_param fail_loc=0
8461
8462         for algo in $CKSUM_TYPES; do
8463                 cancel_lru_locks osc
8464                 set_checksum_type $algo
8465                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
8466                 $LCTL set_param fail_loc=0x80000408
8467                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
8468                 $LCTL set_param fail_loc=0
8469         done
8470         set_checksums 0
8471         set_checksum_type $ORIG_CSUM_TYPE
8472         rm -f $DIR/$tfile
8473 }
8474 run_test 77b "checksum error on client write, read"
8475
8476 cleanup_77c() {
8477         trap 0
8478         set_checksums 0
8479         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
8480         $check_ost &&
8481                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
8482         [ -n "$osc_file_prefix" ] && rm -f ${osc_file_prefix}*
8483         $check_ost && [ -n "$ost_file_prefix" ] &&
8484                 do_facet ost1 rm -f ${ost_file_prefix}\*
8485 }
8486
8487 test_77c() {
8488         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8489         $GSS && skip_env "could not run with gss"
8490         remote_ost_nodsh && skip "remote OST with nodsh"
8491
8492         local bad1
8493         local osc_file_prefix
8494         local osc_file
8495         local check_ost=false
8496         local ost_file_prefix
8497         local ost_file
8498         local orig_cksum
8499         local dump_cksum
8500         local fid
8501
8502         # ensure corruption will occur on first OSS/OST
8503         $LFS setstripe -i 0 $DIR/$tfile
8504
8505         [ ! -f $F77_TMP ] && setup_f77
8506         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
8507                 error "dd write error: $?"
8508         fid=$($LFS path2fid $DIR/$tfile)
8509
8510         if [ $OST1_VERSION -ge $(version_code 2.9.57) ]
8511         then
8512                 check_ost=true
8513                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
8514                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
8515         else
8516                 echo "OSS do not support bulk pages dump upon error"
8517         fi
8518
8519         osc_file_prefix=$($LCTL get_param -n debug_path)
8520         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
8521
8522         trap cleanup_77c EXIT
8523
8524         set_checksums 1
8525         # enable bulk pages dump upon error on Client
8526         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
8527         # enable bulk pages dump upon error on OSS
8528         $check_ost &&
8529                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
8530
8531         # flush Client cache to allow next read to reach OSS
8532         cancel_lru_locks osc
8533
8534         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
8535         $LCTL set_param fail_loc=0x80000408
8536         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
8537         $LCTL set_param fail_loc=0
8538
8539         rm -f $DIR/$tfile
8540
8541         # check cksum dump on Client
8542         osc_file=$(ls ${osc_file_prefix}*)
8543         [ -n "$osc_file" ] || error "no checksum dump file on Client"
8544         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
8545         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
8546         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
8547         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
8548                      cksum)
8549         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
8550         [[ "$orig_cksum" == "$dump_cksum" ]] ||
8551                 error "dump content does not match on Client"
8552
8553         $check_ost || skip "No need to check cksum dump on OSS"
8554
8555         # check cksum dump on OSS
8556         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
8557         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
8558         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
8559         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
8560         [[ "$orig_cksum" == "$dump_cksum" ]] ||
8561                 error "dump content does not match on OSS"
8562
8563         cleanup_77c
8564 }
8565 run_test 77c "checksum error on client read with debug"
8566
8567 test_77d() { # bug 10889
8568         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8569         $GSS && skip_env "could not run with gss"
8570
8571         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
8572         $LCTL set_param fail_loc=0x80000409
8573         set_checksums 1
8574         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
8575                 error "direct write: rc=$?"
8576         $LCTL set_param fail_loc=0
8577         set_checksums 0
8578
8579         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
8580         $LCTL set_param fail_loc=0x80000408
8581         set_checksums 1
8582         cancel_lru_locks osc
8583         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
8584                 error "direct read: rc=$?"
8585         $LCTL set_param fail_loc=0
8586         set_checksums 0
8587 }
8588 run_test 77d "checksum error on OST direct write, read"
8589
8590 test_77f() { # bug 10889
8591         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8592         $GSS && skip_env "could not run with gss"
8593
8594         set_checksums 1
8595         for algo in $CKSUM_TYPES; do
8596                 cancel_lru_locks osc
8597                 set_checksum_type $algo
8598                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
8599                 $LCTL set_param fail_loc=0x409
8600                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
8601                         error "direct write succeeded"
8602                 $LCTL set_param fail_loc=0
8603         done
8604         set_checksum_type $ORIG_CSUM_TYPE
8605         set_checksums 0
8606 }
8607 run_test 77f "repeat checksum error on write (expect error)"
8608
8609 test_77g() { # bug 10889
8610         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8611         $GSS && skip_env "could not run with gss"
8612         remote_ost_nodsh && skip "remote OST with nodsh"
8613
8614         [ ! -f $F77_TMP ] && setup_f77
8615
8616         local file=$DIR/$tfile
8617         stack_trap "rm -f $file" EXIT
8618
8619         $LFS setstripe -c 1 -i 0 $file
8620         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
8621         do_facet ost1 lctl set_param fail_loc=0x8000021a
8622         set_checksums 1
8623         dd if=$F77_TMP of=$file bs=1M count=$F77SZ ||
8624                 error "write error: rc=$?"
8625         do_facet ost1 lctl set_param fail_loc=0
8626         set_checksums 0
8627
8628         cancel_lru_locks osc
8629         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
8630         do_facet ost1 lctl set_param fail_loc=0x8000021b
8631         set_checksums 1
8632         cmp $F77_TMP $file || error "file compare failed"
8633         do_facet ost1 lctl set_param fail_loc=0
8634         set_checksums 0
8635 }
8636 run_test 77g "checksum error on OST write, read"
8637
8638 test_77k() { # LU-10906
8639         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8640         $GSS && skip_env "could not run with gss"
8641
8642         local cksum_param="osc.$FSNAME*.checksums"
8643         local get_checksum="$LCTL get_param -n $cksum_param | head -n1"
8644         local checksum
8645         local i
8646
8647         [ "$ORIG_CSUM" ] || ORIG_CSUM=$(eval $get_checksum)
8648         stack_trap "wait_update $HOSTNAME '$get_checksum' $ORIG_CSUM" EXIT
8649         stack_trap "do_facet mgs $LCTL set_param -P $cksum_param=$ORIG_CSUM" \
8650                 EXIT
8651
8652         for i in 0 1; do
8653                 do_facet mgs $LCTL set_param -P $cksum_param=$i ||
8654                         error "failed to set checksum=$i on MGS"
8655                 wait_update $HOSTNAME "$get_checksum" $i
8656                 #remount
8657                 echo "remount client, checksum should be $i"
8658                 remount_client $MOUNT || error "failed to remount client"
8659                 checksum=$(eval $get_checksum)
8660                 [ $checksum -eq $i ] || error "checksum($checksum) != $i"
8661         done
8662         # remove persistent param to avoid races with checksum mountopt below
8663         do_facet mgs $LCTL set_param -P -d $cksum_param ||
8664                 error "failed to delete checksum on MGS"
8665
8666         for opt in "checksum" "nochecksum"; do
8667                 #remount with mount option
8668                 echo "remount client with option $opt, checksum should be $i"
8669                 umount_client $MOUNT || error "failed to umount client"
8670                 mount_client $MOUNT "$MOUNT_OPTS,$opt" ||
8671                         error "failed to mount client with option '$opt'"
8672                 checksum=$(eval $get_checksum)
8673                 [ $checksum -eq $i ] || error "checksum($checksum) != $i"
8674                 i=$((i - 1))
8675         done
8676
8677         remount_client $MOUNT || error "failed to remount client"
8678 }
8679 run_test 77k "enable/disable checksum correctly"
8680
8681 test_77l() {
8682         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8683         $GSS && skip_env "could not run with gss"
8684
8685         set_checksums 1
8686         stack_trap "set_checksums $ORIG_CSUM" EXIT
8687         stack_trap "set_checksum_type $ORIG_CSUM_TYPE" EXIT
8688
8689         set_checksum_type invalid && error "unexpected success of invalid checksum type"
8690
8691         $LFS setstripe -c 1 -i 0 $DIR/$tfile
8692         for algo in $CKSUM_TYPES; do
8693                 set_checksum_type $algo || error "fail to set checksum type $algo"
8694                 osc_algo=$(get_osc_checksum_type OST0000)
8695                 [ "$osc_algo" != "$algo" ] && error "checksum type is $osc_algo after setting it to $algo"
8696
8697                 # no locks, no reqs to let the connection idle
8698                 cancel_lru_locks osc
8699                 lru_resize_disable osc
8700                 wait_osc_import_state client ost1 IDLE
8701
8702                 # ensure ost1 is connected
8703                 stat $DIR/$tfile >/dev/null || error "can't stat"
8704                 wait_osc_import_state client ost1 FULL
8705
8706                 osc_algo=$(get_osc_checksum_type OST0000)
8707                 [ "$osc_algo" != "$algo" ] && error "checksum type changed from $algo to $osc_algo after reconnection"
8708         done
8709         return 0
8710 }
8711 run_test 77l "preferred checksum type is remembered after reconnected"
8712
8713 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
8714 rm -f $F77_TMP
8715 unset F77_TMP
8716
8717 cleanup_test_78() {
8718         trap 0
8719         rm -f $DIR/$tfile
8720 }
8721
8722 test_78() { # bug 10901
8723         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8724         remote_ost || skip_env "local OST"
8725
8726         NSEQ=5
8727         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
8728         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
8729         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
8730         echo "MemTotal: $MEMTOTAL"
8731
8732         # reserve 256MB of memory for the kernel and other running processes,
8733         # and then take 1/2 of the remaining memory for the read/write buffers.
8734         if [ $MEMTOTAL -gt 512 ] ;then
8735                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
8736         else
8737                 # for those poor memory-starved high-end clusters...
8738                 MEMTOTAL=$((MEMTOTAL / 2))
8739         fi
8740         echo "Mem to use for directio: $MEMTOTAL"
8741
8742         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
8743         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
8744         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
8745         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
8746                 head -n1)
8747         echo "Smallest OST: $SMALLESTOST"
8748         [[ $SMALLESTOST -lt 10240 ]] &&
8749                 skip "too small OSTSIZE, useless to run large O_DIRECT test"
8750
8751         trap cleanup_test_78 EXIT
8752
8753         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
8754                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
8755
8756         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
8757         echo "File size: $F78SIZE"
8758         $LFS setstripe -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
8759         for i in $(seq 1 $NSEQ); do
8760                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
8761                 echo directIO rdwr round $i of $NSEQ
8762                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
8763         done
8764
8765         cleanup_test_78
8766 }
8767 run_test 78 "handle large O_DIRECT writes correctly ============"
8768
8769 test_79() { # bug 12743
8770         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8771
8772         wait_delete_completed
8773
8774         BKTOTAL=$(calc_osc_kbytes kbytestotal)
8775         BKFREE=$(calc_osc_kbytes kbytesfree)
8776         BKAVAIL=$(calc_osc_kbytes kbytesavail)
8777
8778         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
8779         DFTOTAL=`echo $STRING | cut -d, -f1`
8780         DFUSED=`echo $STRING  | cut -d, -f2`
8781         DFAVAIL=`echo $STRING | cut -d, -f3`
8782         DFFREE=$(($DFTOTAL - $DFUSED))
8783
8784         ALLOWANCE=$((64 * $OSTCOUNT))
8785
8786         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
8787            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
8788                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
8789         fi
8790         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
8791            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
8792                 error "df free($DFFREE) mismatch OST free($BKFREE)"
8793         fi
8794         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
8795            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
8796                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
8797         fi
8798 }
8799 run_test 79 "df report consistency check ======================="
8800
8801 test_80() { # bug 10718
8802         remote_ost_nodsh && skip "remote OST with nodsh"
8803         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8804
8805         # relax strong synchronous semantics for slow backends like ZFS
8806         if [ "$ost1_FSTYPE" != "ldiskfs" ]; then
8807                 local soc="obdfilter.*.sync_lock_cancel"
8808                 local save=$(do_facet ost1 $LCTL get_param -n $soc | head -n1)
8809
8810                 # "sync_on_lock_cancel" was broken by v2_11_55_0-26-g7059644e9a
8811                 if [ -z "$save" ]; then
8812                         soc="obdfilter.*.sync_on_lock_cancel"
8813                         save=$(do_facet ost1 $LCTL get_param -n $soc | head -n1)
8814                 fi
8815
8816                 if [ "$save" != "never" ]; then
8817                         local hosts=$(comma_list $(osts_nodes))
8818
8819                         do_nodes $hosts $LCTL set_param $soc=never
8820                         stack_trap "do_nodes $hosts $LCTL set_param $soc=$save"
8821                 fi
8822         fi
8823
8824         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
8825         sync; sleep 1; sync
8826         local before=$(date +%s)
8827         cancel_lru_locks osc
8828         local after=$(date +%s)
8829         local diff=$((after - before))
8830         [ $diff -le 1 ] || error "elapsed for 1M@1T = $diff"
8831
8832         rm -f $DIR/$tfile
8833 }
8834 run_test 80 "Page eviction is equally fast at high offsets too"
8835
8836 test_81a() { # LU-456
8837         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8838         remote_ost_nodsh && skip "remote OST with nodsh"
8839
8840         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
8841         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
8842         do_facet ost1 lctl set_param fail_loc=0x80000228
8843
8844         # write should trigger a retry and success
8845         $LFS setstripe -i 0 -c 1 $DIR/$tfile
8846         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8847         RC=$?
8848         if [ $RC -ne 0 ] ; then
8849                 error "write should success, but failed for $RC"
8850         fi
8851 }
8852 run_test 81a "OST should retry write when get -ENOSPC ==============="
8853
8854 test_81b() { # LU-456
8855         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8856         remote_ost_nodsh && skip "remote OST with nodsh"
8857
8858         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
8859         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
8860         do_facet ost1 lctl set_param fail_loc=0x228
8861
8862         # write should retry several times and return -ENOSPC finally
8863         $LFS setstripe -i 0 -c 1 $DIR/$tfile
8864         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8865         RC=$?
8866         ENOSPC=28
8867         if [ $RC -ne $ENOSPC ] ; then
8868                 error "dd should fail for -ENOSPC, but succeed."
8869         fi
8870 }
8871 run_test 81b "OST should return -ENOSPC when retry still fails ======="
8872
8873 test_82() { # LU-1031
8874         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
8875         local gid1=14091995
8876         local gid2=16022000
8877
8878         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
8879         local MULTIPID1=$!
8880         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
8881         local MULTIPID2=$!
8882         kill -USR1 $MULTIPID2
8883         sleep 2
8884         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
8885                 error "First grouplock does not block second one"
8886         else
8887                 echo "Second grouplock blocks first one"
8888         fi
8889         kill -USR1 $MULTIPID1
8890         wait $MULTIPID1
8891         wait $MULTIPID2
8892 }
8893 run_test 82 "Basic grouplock test"
8894
8895 test_99() {
8896         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs"
8897
8898         test_mkdir $DIR/$tdir.cvsroot
8899         chown $RUNAS_ID $DIR/$tdir.cvsroot
8900
8901         cd $TMP
8902         $RUNAS cvs -d $DIR/$tdir.cvsroot init || error "cvs init failed"
8903
8904         cd /etc/init.d
8905         # some versions of cvs import exit(1) when asked to import links or
8906         # files they can't read.  ignore those files.
8907         local toignore=$(find . -type l -printf '-I %f\n' -o \
8908                          ! -perm /4 -printf '-I %f\n')
8909         $RUNAS cvs -d $DIR/$tdir.cvsroot import -m "nomesg" $toignore \
8910                 $tdir.reposname vtag rtag
8911
8912         cd $DIR
8913         test_mkdir $DIR/$tdir.reposname
8914         chown $RUNAS_ID $DIR/$tdir.reposname
8915         $RUNAS cvs -d $DIR/$tdir.cvsroot co $tdir.reposname
8916
8917         cd $DIR/$tdir.reposname
8918         $RUNAS touch foo99
8919         $RUNAS cvs add -m 'addmsg' foo99
8920         $RUNAS cvs update
8921         $RUNAS cvs commit -m 'nomsg' foo99
8922         rm -fr $DIR/$tdir.cvsroot
8923 }
8924 run_test 99 "cvs strange file/directory operations"
8925
8926 test_100() {
8927         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8928         [[ "$NETTYPE" =~ tcp ]] ||
8929                 skip_env "TCP secure port test, not useful for NETTYPE=$NETTYPE"
8930         remote_ost_nodsh && skip "remote OST with nodsh"
8931         remote_mds_nodsh && skip "remote MDS with nodsh"
8932         remote_servers ||
8933                 skip "useless for local single node setup"
8934
8935         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
8936                 [ "$PROT" != "tcp" ] && continue
8937                 RPORT=$(echo $REMOTE | cut -d: -f2)
8938                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
8939
8940                 rc=0
8941                 LPORT=`echo $LOCAL | cut -d: -f2`
8942                 if [ $LPORT -ge 1024 ]; then
8943                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
8944                         netstat -tna
8945                         error_exit "local: $LPORT > 1024, remote: $RPORT"
8946                 fi
8947         done
8948         [ "$rc" = 0 ] || error_exit "privileged port not found" )
8949 }
8950 run_test 100 "check local port using privileged port ==========="
8951
8952 function get_named_value()
8953 {
8954     local tag
8955
8956     tag=$1
8957     while read ;do
8958         line=$REPLY
8959         case $line in
8960         $tag*)
8961             echo $line | sed "s/^$tag[ ]*//"
8962             break
8963             ;;
8964         esac
8965     done
8966 }
8967
8968 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
8969                    awk '/^max_cached_mb/ { print $2 }')
8970
8971 cleanup_101a() {
8972         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
8973         trap 0
8974 }
8975
8976 test_101a() {
8977         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8978
8979         local s
8980         local discard
8981         local nreads=10000
8982         local cache_limit=32
8983
8984         $LCTL set_param -n osc.*-osc*.rpc_stats 0
8985         trap cleanup_101a EXIT
8986         $LCTL set_param -n llite.*.read_ahead_stats 0
8987         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
8988
8989         #
8990         # randomly read 10000 of 64K chunks from file 3x 32MB in size
8991         #
8992         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
8993         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
8994
8995         discard=0
8996         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
8997                 get_named_value 'read but discarded' | cut -d" " -f1); do
8998                         discard=$(($discard + $s))
8999         done
9000         cleanup_101a
9001
9002         $LCTL get_param osc.*-osc*.rpc_stats
9003         $LCTL get_param llite.*.read_ahead_stats
9004
9005         # Discard is generally zero, but sometimes a few random reads line up
9006         # and trigger larger readahead, which is wasted & leads to discards.
9007         if [[ $(($discard)) -gt $nreads ]]; then
9008                 error "too many ($discard) discarded pages"
9009         fi
9010         rm -f $DIR/$tfile || true
9011 }
9012 run_test 101a "check read-ahead for random reads"
9013
9014 setup_test101bc() {
9015         test_mkdir $DIR/$tdir
9016         local ssize=$1
9017         local FILE_LENGTH=$2
9018         STRIPE_OFFSET=0
9019
9020         local FILE_SIZE_MB=$((FILE_LENGTH / ssize))
9021
9022         local list=$(comma_list $(osts_nodes))
9023         set_osd_param $list '' read_cache_enable 0
9024         set_osd_param $list '' writethrough_cache_enable 0
9025
9026         trap cleanup_test101bc EXIT
9027         # prepare the read-ahead file
9028         $LFS setstripe -S $ssize -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
9029
9030         dd if=/dev/zero of=$DIR/$tfile bs=$ssize \
9031                                 count=$FILE_SIZE_MB 2> /dev/null
9032
9033 }
9034
9035 cleanup_test101bc() {
9036         trap 0
9037         rm -rf $DIR/$tdir
9038         rm -f $DIR/$tfile
9039
9040         local list=$(comma_list $(osts_nodes))
9041         set_osd_param $list '' read_cache_enable 1
9042         set_osd_param $list '' writethrough_cache_enable 1
9043 }
9044
9045 calc_total() {
9046         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
9047 }
9048
9049 ra_check_101() {
9050         local READ_SIZE=$1
9051         local STRIPE_SIZE=$2
9052         local FILE_LENGTH=$3
9053         local RA_INC=1048576
9054         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
9055         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
9056                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
9057         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
9058                         get_named_value 'read but discarded' |
9059                         cut -d" " -f1 | calc_total)
9060         if [[ $DISCARD -gt $discard_limit ]]; then
9061                 $LCTL get_param llite.*.read_ahead_stats
9062                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
9063         else
9064                 echo "Read-ahead success for size ${READ_SIZE}"
9065         fi
9066 }
9067
9068 test_101b() {
9069         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9070         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9071
9072         local STRIPE_SIZE=1048576
9073         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
9074
9075         if [ $SLOW == "yes" ]; then
9076                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
9077         else
9078                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
9079         fi
9080
9081         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
9082
9083         # prepare the read-ahead file
9084         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
9085         cancel_lru_locks osc
9086         for BIDX in 2 4 8 16 32 64 128 256
9087         do
9088                 local BSIZE=$((BIDX*4096))
9089                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
9090                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
9091                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
9092                 $LCTL set_param -n llite.*.read_ahead_stats 0
9093                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
9094                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
9095                 cancel_lru_locks osc
9096                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
9097         done
9098         cleanup_test101bc
9099         true
9100 }
9101 run_test 101b "check stride-io mode read-ahead ================="
9102
9103 test_101c() {
9104         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9105
9106         local STRIPE_SIZE=1048576
9107         local FILE_LENGTH=$((STRIPE_SIZE*100))
9108         local nreads=10000
9109         local rsize=65536
9110         local osc_rpc_stats
9111
9112         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
9113
9114         cancel_lru_locks osc
9115         $LCTL set_param osc.*.rpc_stats 0
9116         $READS -f $DIR/$tfile -s$FILE_LENGTH -b$rsize -n$nreads -t 180
9117         $LCTL get_param osc.*.rpc_stats
9118         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
9119                 local stats=$($LCTL get_param -n $osc_rpc_stats)
9120                 local lines=$(echo "$stats" | awk 'END {print NR;}')
9121                 local size
9122
9123                 if [ $lines -le 20 ]; then
9124                         echo "continue debug"
9125                         continue
9126                 fi
9127                 for size in 1 2 4 8; do
9128                         local rpc=$(echo "$stats" |
9129                                     awk '($1 == "'$size':") {print $2; exit; }')
9130                         [ $rpc != 0 ] && ((size * PAGE_SIZE < rsize)) &&
9131                                 error "Small $((size*PAGE_SIZE)) read IO $rpc!"
9132                 done
9133                 echo "$osc_rpc_stats check passed!"
9134         done
9135         cleanup_test101bc
9136         true
9137 }
9138 run_test 101c "check stripe_size aligned read-ahead ================="
9139
9140 test_101d() {
9141         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9142
9143         local file=$DIR/$tfile
9144         local sz_MB=${FILESIZE_101d:-80}
9145         local ra_MB=${READAHEAD_MB:-40}
9146
9147         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
9148         [ $free_MB -lt $sz_MB ] &&
9149                 skip "Need free space ${sz_MB}M, have ${free_MB}M"
9150
9151         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
9152         $LFS setstripe -c -1 $file || error "setstripe failed"
9153
9154         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
9155         echo Cancel LRU locks on lustre client to flush the client cache
9156         cancel_lru_locks osc
9157
9158         echo Disable read-ahead
9159         local old_RA=$($LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1)
9160         $LCTL set_param -n llite.*.max_read_ahead_mb=0
9161         stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb $old_RA" EXIT
9162         $LCTL get_param -n llite.*.max_read_ahead_mb
9163
9164         echo "Reading the test file $file with read-ahead disabled"
9165         local sz_KB=$((sz_MB * 1024 / 4))
9166         # 10485760 bytes transferred in 0.000938 secs (11179579337 bytes/sec)
9167         # 104857600 bytes (105 MB) copied, 0.00876352 s, 12.0 GB/s
9168         local raOFF=$(LANG=C dd if=$file of=/dev/null bs=4k count=$sz_KB |&
9169                       sed -e '/records/d' -e 's/.* \([0-9]*\.[0-9]*\) *s.*/\1/')
9170
9171         echo "Cancel LRU locks on lustre client to flush the client cache"
9172         cancel_lru_locks osc
9173         echo Enable read-ahead with ${ra_MB}MB
9174         $LCTL set_param -n llite.*.max_read_ahead_mb=$ra_MB
9175
9176         echo "Reading the test file $file with read-ahead enabled"
9177         local raON=$(LANG=C dd if=$file of=/dev/null bs=4k count=$sz_KB |&
9178                      sed -e '/records/d' -e 's/.* \([0-9]*\.[0-9]*\) *s.*/\1/')
9179
9180         echo "read-ahead disabled time read $raOFF"
9181         echo "read-ahead enabled time read $raON"
9182
9183         rm -f $file
9184         wait_delete_completed
9185
9186         # use awk for this check instead of bash because it handles decimals
9187         awk "{ exit !($raOFF < 1.0 || $raOFF > $raON) }" <<<"ignore_me" ||
9188                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
9189 }
9190 run_test 101d "file read with and without read-ahead enabled"
9191
9192 test_101e() {
9193         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9194
9195         local file=$DIR/$tfile
9196         local size_KB=500  #KB
9197         local count=100
9198         local bsize=1024
9199
9200         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
9201         local need_KB=$((count * size_KB))
9202         [[ $free_KB -le $need_KB ]] &&
9203                 skip_env "Need free space $need_KB, have $free_KB"
9204
9205         echo "Creating $count ${size_KB}K test files"
9206         for ((i = 0; i < $count; i++)); do
9207                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
9208         done
9209
9210         echo "Cancel LRU locks on lustre client to flush the client cache"
9211         cancel_lru_locks $OSC
9212
9213         echo "Reset readahead stats"
9214         $LCTL set_param -n llite.*.read_ahead_stats 0
9215
9216         for ((i = 0; i < $count; i++)); do
9217                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
9218         done
9219
9220         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9221                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
9222
9223         for ((i = 0; i < $count; i++)); do
9224                 rm -rf $file.$i 2>/dev/null
9225         done
9226
9227         #10000 means 20% reads are missing in readahead
9228         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
9229 }
9230 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
9231
9232 test_101f() {
9233         which iozone || skip_env "no iozone installed"
9234
9235         local old_debug=$($LCTL get_param debug)
9236         old_debug=${old_debug#*=}
9237         $LCTL set_param debug="reada mmap"
9238
9239         # create a test file
9240         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
9241
9242         echo Cancel LRU locks on lustre client to flush the client cache
9243         cancel_lru_locks osc
9244
9245         echo Reset readahead stats
9246         $LCTL set_param -n llite.*.read_ahead_stats 0
9247
9248         echo mmap read the file with small block size
9249         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
9250                 > /dev/null 2>&1
9251
9252         echo checking missing pages
9253         $LCTL get_param llite.*.read_ahead_stats
9254         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9255                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
9256
9257         $LCTL set_param debug="$old_debug"
9258         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
9259         rm -f $DIR/$tfile
9260 }
9261 run_test 101f "check mmap read performance"
9262
9263 test_101g_brw_size_test() {
9264         local mb=$1
9265         local pages=$((mb * 1048576 / PAGE_SIZE))
9266         local file=$DIR/$tfile
9267
9268         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
9269                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
9270         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
9271                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
9272                         return 2
9273         done
9274
9275         stack_trap "rm -f $file" EXIT
9276         $LCTL set_param -n osc.*.rpc_stats=0
9277
9278         # 10 RPCs should be enough for the test
9279         local count=10
9280         dd if=/dev/zero of=$file bs=${mb}M count=$count ||
9281                 { error "dd write ${mb} MB blocks failed"; return 3; }
9282         cancel_lru_locks osc
9283         dd of=/dev/null if=$file bs=${mb}M count=$count ||
9284                 { error "dd write ${mb} MB blocks failed"; return 4; }
9285
9286         # calculate number of full-sized read and write RPCs
9287         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
9288                 sed -n '/pages per rpc/,/^$/p' |
9289                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
9290                 END { print reads,writes }'))
9291         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
9292                 return 5
9293         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
9294                 return 6
9295
9296         return 0
9297 }
9298
9299 test_101g() {
9300         remote_ost_nodsh && skip "remote OST with nodsh"
9301
9302         local rpcs
9303         local osts=$(get_facets OST)
9304         local list=$(comma_list $(osts_nodes))
9305         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
9306         local brw_size="obdfilter.*.brw_size"
9307
9308         $LFS setstripe -i 0 -c 1 $DIR/$tfile
9309
9310         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
9311
9312         if { [ $OST1_VERSION -ge $(version_code 2.8.52) ] ||
9313                 { [ $OST1_VERSION -ge $(version_code 2.7.17) ] &&
9314                   [ $OST1_VERSION -lt $(version_code 2.7.50) ]; }; } &&
9315            { [ $CLIENT_VERSION -ge $(version_code 2.8.52) ] ||
9316                 { [ $CLIENT_VERSION -ge $(version_code 2.7.17) ] &&
9317                   [ $CLIENT_VERSION -lt $(version_code 2.7.50) ]; }; }; then
9318
9319                 [ $OST1_VERSION -ge $(version_code 2.9.52) ] &&
9320                         suffix="M"
9321
9322                 if [[ $orig_mb -lt 16 ]]; then
9323                         save_lustre_params $osts "$brw_size" > $p
9324                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
9325                                 error "set 16MB RPC size failed"
9326
9327                         echo "remount client to enable new RPC size"
9328                         remount_client $MOUNT || error "remount_client failed"
9329                 fi
9330
9331                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
9332                 # should be able to set brw_size=12, but no rpc_stats for that
9333                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
9334         fi
9335
9336         test_101g_brw_size_test 4 || error "4MB RPC test failed"
9337
9338         if [[ $orig_mb -lt 16 ]]; then
9339                 restore_lustre_params < $p
9340                 remount_client $MOUNT || error "remount_client restore failed"
9341         fi
9342
9343         rm -f $p $DIR/$tfile
9344 }
9345 run_test 101g "Big bulk(4/16 MiB) readahead"
9346
9347 test_101h() {
9348         $LFS setstripe -i 0 -c 1 $DIR/$tfile
9349
9350         dd if=/dev/zero of=$DIR/$tfile bs=1M count=70 ||
9351                 error "dd 70M file failed"
9352         echo Cancel LRU locks on lustre client to flush the client cache
9353         cancel_lru_locks osc
9354
9355         echo "Reset readahead stats"
9356         $LCTL set_param -n llite.*.read_ahead_stats 0
9357
9358         echo "Read 10M of data but cross 64M bundary"
9359         dd if=$DIR/$tfile of=/dev/null bs=10M skip=6 count=1
9360         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9361                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
9362         [ $miss -eq 1 ] || error "expected miss 1 but got $miss"
9363         rm -f $p $DIR/$tfile
9364 }
9365 run_test 101h "Readahead should cover current read window"
9366
9367 test_101i() {
9368         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 ||
9369                 error "dd 10M file failed"
9370
9371         local max_per_file_mb=$($LCTL get_param -n \
9372                 llite.*.max_read_ahead_per_file_mb 2>/dev/null)
9373         cancel_lru_locks osc
9374         stack_trap "$LCTL set_param llite.*.max_read_ahead_per_file_mb=$max_per_file_mb"
9375         $LCTL set_param llite.*.max_read_ahead_per_file_mb=1 ||
9376                 error "set max_read_ahead_per_file_mb to 1 failed"
9377
9378         echo "Reset readahead stats"
9379         $LCTL set_param llite.*.read_ahead_stats=0
9380
9381         dd if=$DIR/$tfile of=/dev/null bs=2M
9382
9383         $LCTL get_param llite.*.read_ahead_stats
9384         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9385                      awk '/misses/ { print $2 }')
9386         [ $miss -eq 5 ] || error "expected misses 5 but got $miss"
9387         rm -f $DIR/$tfile
9388 }
9389 run_test 101i "allow current readahead to exceed reservation"
9390
9391 test_101j() {
9392         $LFS setstripe -i 0 -c 1 $DIR/$tfile ||
9393                 error "setstripe $DIR/$tfile failed"
9394         local file_size=$((1048576 * 16))
9395         local old_ra=$($LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1)
9396         stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb $old_ra" EXIT
9397
9398         echo Disable read-ahead
9399         $LCTL set_param -n llite.*.max_read_ahead_mb=0
9400
9401         dd if=/dev/zero of=$DIR/$tfile bs=1M count=$(($file_size / 1048576))
9402         for blk in $PAGE_SIZE 1048576 $file_size; do
9403                 cancel_lru_locks osc
9404                 echo "Reset readahead stats"
9405                 $LCTL set_param -n llite.*.read_ahead_stats=0
9406                 local count=$(($file_size / $blk))
9407                 dd if=$DIR/$tfile bs=$blk count=$count of=/dev/null
9408                 local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9409                              get_named_value 'failed to fast read' |
9410                              cut -d" " -f1 | calc_total)
9411                 $LCTL get_param -n llite.*.read_ahead_stats
9412                 [ $miss -eq $count ] || error "expected $count got $miss"
9413         done
9414
9415         rm -f $p $DIR/$tfile
9416 }
9417 run_test 101j "A complete read block should be submitted when no RA"
9418
9419 setup_test102() {
9420         test_mkdir $DIR/$tdir
9421         chown $RUNAS_ID $DIR/$tdir
9422         STRIPE_SIZE=65536
9423         STRIPE_OFFSET=1
9424         STRIPE_COUNT=$OSTCOUNT
9425         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
9426
9427         trap cleanup_test102 EXIT
9428         cd $DIR
9429         $1 $LFS setstripe -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
9430         cd $DIR/$tdir
9431         for num in 1 2 3 4; do
9432                 for count in $(seq 1 $STRIPE_COUNT); do
9433                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
9434                                 local size=`expr $STRIPE_SIZE \* $num`
9435                                 local file=file"$num-$idx-$count"
9436                                 $1 $LFS setstripe -S $size -i $idx -c $count $file
9437                         done
9438                 done
9439         done
9440
9441         cd $DIR
9442         $1 tar cf $TMP/f102.tar $tdir --xattrs
9443 }
9444
9445 cleanup_test102() {
9446         trap 0
9447         rm -f $TMP/f102.tar
9448         rm -rf $DIR/d0.sanity/d102
9449 }
9450
9451 test_102a() {
9452         [ "$UID" != 0 ] && skip "must run as root"
9453         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
9454                 skip_env "must have user_xattr"
9455
9456         [ -z "$(which setfattr 2>/dev/null)" ] &&
9457                 skip_env "could not find setfattr"
9458
9459         local testfile=$DIR/$tfile
9460
9461         touch $testfile
9462         echo "set/get xattr..."
9463         setfattr -n trusted.name1 -v value1 $testfile ||
9464                 error "setfattr -n trusted.name1=value1 $testfile failed"
9465         getfattr -n trusted.name1 $testfile 2> /dev/null |
9466           grep "trusted.name1=.value1" ||
9467                 error "$testfile missing trusted.name1=value1"
9468
9469         setfattr -n user.author1 -v author1 $testfile ||
9470                 error "setfattr -n user.author1=author1 $testfile failed"
9471         getfattr -n user.author1 $testfile 2> /dev/null |
9472           grep "user.author1=.author1" ||
9473                 error "$testfile missing trusted.author1=author1"
9474
9475         echo "listxattr..."
9476         setfattr -n trusted.name2 -v value2 $testfile ||
9477                 error "$testfile unable to set trusted.name2"
9478         setfattr -n trusted.name3 -v value3 $testfile ||
9479                 error "$testfile unable to set trusted.name3"
9480         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
9481             grep "trusted.name" | wc -l) -eq 3 ] ||
9482                 error "$testfile missing 3 trusted.name xattrs"
9483
9484         setfattr -n user.author2 -v author2 $testfile ||
9485                 error "$testfile unable to set user.author2"
9486         setfattr -n user.author3 -v author3 $testfile ||
9487                 error "$testfile unable to set user.author3"
9488         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
9489             grep "user.author" | wc -l) -eq 3 ] ||
9490                 error "$testfile missing 3 user.author xattrs"
9491
9492         echo "remove xattr..."
9493         setfattr -x trusted.name1 $testfile ||
9494                 error "$testfile error deleting trusted.name1"
9495         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
9496                 error "$testfile did not delete trusted.name1 xattr"
9497
9498         setfattr -x user.author1 $testfile ||
9499                 error "$testfile error deleting user.author1"
9500         echo "set lustre special xattr ..."
9501         $LFS setstripe -c1 $testfile
9502         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
9503                 awk -F "=" '/trusted.lov/ { print $2 }' )
9504         setfattr -n "trusted.lov" -v $lovea $testfile ||
9505                 error "$testfile doesn't ignore setting trusted.lov again"
9506         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
9507                 error "$testfile allow setting invalid trusted.lov"
9508         rm -f $testfile
9509 }
9510 run_test 102a "user xattr test =================================="
9511
9512 test_102b() {
9513         [ -z "$(which setfattr 2>/dev/null)" ] &&
9514                 skip_env "could not find setfattr"
9515         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9516
9517         # b10930: get/set/list trusted.lov xattr
9518         echo "get/set/list trusted.lov xattr ..."
9519         local testfile=$DIR/$tfile
9520         $LFS setstripe -S 65536 -i 1 -c $OSTCOUNT $testfile ||
9521                 error "setstripe failed"
9522         local STRIPECOUNT=$($LFS getstripe -c $testfile) ||
9523                 error "getstripe failed"
9524         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
9525                 error "can't get trusted.lov from $testfile"
9526
9527         local testfile2=${testfile}2
9528         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
9529                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
9530
9531         $MCREATE $testfile2
9532         setfattr -n trusted.lov -v $value $testfile2
9533         local stripe_size=$($LFS getstripe -S $testfile2)
9534         local stripe_count=$($LFS getstripe -c $testfile2)
9535         [[ $stripe_size -eq 65536 ]] ||
9536                 error "stripe size $stripe_size != 65536"
9537         [[ $stripe_count -eq $STRIPECOUNT ]] ||
9538                 error "stripe count $stripe_count != $STRIPECOUNT"
9539         rm -f $DIR/$tfile
9540 }
9541 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
9542
9543 test_102c() {
9544         [ -z "$(which setfattr 2>/dev/null)" ] &&
9545                 skip_env "could not find setfattr"
9546         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9547
9548         # b10930: get/set/list lustre.lov xattr
9549         echo "get/set/list lustre.lov xattr ..."
9550         test_mkdir $DIR/$tdir
9551         chown $RUNAS_ID $DIR/$tdir
9552         local testfile=$DIR/$tdir/$tfile
9553         $RUNAS $LFS setstripe -S 65536 -i 1 -c $OSTCOUNT $testfile ||
9554                 error "setstripe failed"
9555         local STRIPECOUNT=$($RUNAS $LFS getstripe -c $testfile) ||
9556                 error "getstripe failed"
9557         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
9558         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
9559
9560         local testfile2=${testfile}2
9561         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
9562                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
9563
9564         $RUNAS $MCREATE $testfile2
9565         $RUNAS setfattr -n lustre.lov -v $value $testfile2
9566         local stripe_size=$($RUNAS $LFS getstripe -S $testfile2)
9567         local stripe_count=$($RUNAS $LFS getstripe -c $testfile2)
9568         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
9569         [ $stripe_count -eq $STRIPECOUNT ] ||
9570                 error "stripe count $stripe_count != $STRIPECOUNT"
9571 }
9572 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
9573
9574 compare_stripe_info1() {
9575         local stripe_index_all_zero=true
9576
9577         for num in 1 2 3 4; do
9578                 for count in $(seq 1 $STRIPE_COUNT); do
9579                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
9580                                 local size=$((STRIPE_SIZE * num))
9581                                 local file=file"$num-$offset-$count"
9582                                 stripe_size=$($LFS getstripe -S $PWD/$file)
9583                                 [[ $stripe_size -ne $size ]] &&
9584                                     error "$file: size $stripe_size != $size"
9585                                 stripe_count=$($LFS getstripe -c $PWD/$file)
9586                                 # allow fewer stripes to be created, ORI-601
9587                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
9588                                     error "$file: count $stripe_count != $count"
9589                                 stripe_index=$($LFS getstripe -i $PWD/$file)
9590                                 [[ $stripe_index -ne 0 ]] &&
9591                                         stripe_index_all_zero=false
9592                         done
9593                 done
9594         done
9595         $stripe_index_all_zero &&
9596                 error "all files are being extracted starting from OST index 0"
9597         return 0
9598 }
9599
9600 have_xattrs_include() {
9601         tar --help | grep -q xattrs-include &&
9602                 echo --xattrs-include="lustre.*"
9603 }
9604
9605 test_102d() {
9606         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9607         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9608
9609         XINC=$(have_xattrs_include)
9610         setup_test102
9611         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
9612         cd $DIR/$tdir/$tdir
9613         compare_stripe_info1
9614 }
9615 run_test 102d "tar restore stripe info from tarfile,not keep osts"
9616
9617 test_102f() {
9618         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9619         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9620
9621         XINC=$(have_xattrs_include)
9622         setup_test102
9623         test_mkdir $DIR/$tdir.restore
9624         cd $DIR
9625         tar cf - --xattrs $tdir | tar xf - \
9626                 -C $DIR/$tdir.restore --xattrs $XINC
9627         cd $DIR/$tdir.restore/$tdir
9628         compare_stripe_info1
9629 }
9630 run_test 102f "tar copy files, not keep osts"
9631
9632 grow_xattr() {
9633         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
9634                 skip "must have user_xattr"
9635         [ -z "$(which setfattr 2>/dev/null)" ] &&
9636                 skip_env "could not find setfattr"
9637         [ -z "$(which getfattr 2>/dev/null)" ] &&
9638                 skip_env "could not find getfattr"
9639
9640         local xsize=${1:-1024}  # in bytes
9641         local file=$DIR/$tfile
9642         local value="$(generate_string $xsize)"
9643         local xbig=trusted.big
9644         local toobig=$2
9645
9646         touch $file
9647         log "save $xbig on $file"
9648         if [ -z "$toobig" ]
9649         then
9650                 setfattr -n $xbig -v $value $file ||
9651                         error "saving $xbig on $file failed"
9652         else
9653                 setfattr -n $xbig -v $value $file &&
9654                         error "saving $xbig on $file succeeded"
9655                 return 0
9656         fi
9657
9658         local orig=$(get_xattr_value $xbig $file)
9659         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
9660
9661         local xsml=trusted.sml
9662         log "save $xsml on $file"
9663         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
9664
9665         local new=$(get_xattr_value $xbig $file)
9666         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
9667
9668         log "grow $xsml on $file"
9669         setfattr -n $xsml -v "$value" $file ||
9670                 error "growing $xsml on $file failed"
9671
9672         new=$(get_xattr_value $xbig $file)
9673         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
9674         log "$xbig still valid after growing $xsml"
9675
9676         rm -f $file
9677 }
9678
9679 test_102h() { # bug 15777
9680         grow_xattr 1024
9681 }
9682 run_test 102h "grow xattr from inside inode to external block"
9683
9684 test_102ha() {
9685         large_xattr_enabled || skip_env "ea_inode feature disabled"
9686
9687         echo "setting xattr of max xattr size: $(max_xattr_size)"
9688         grow_xattr $(max_xattr_size)
9689
9690         echo "setting xattr of > max xattr size: $(max_xattr_size) + 10"
9691         echo "This should fail:"
9692         grow_xattr $(($(max_xattr_size) + 10)) 1
9693 }
9694 run_test 102ha "grow xattr from inside inode to external inode"
9695
9696 test_102i() { # bug 17038
9697         [ -z "$(which getfattr 2>/dev/null)" ] &&
9698                 skip "could not find getfattr"
9699
9700         touch $DIR/$tfile
9701         ln -s $DIR/$tfile $DIR/${tfile}link
9702         getfattr -n trusted.lov $DIR/$tfile ||
9703                 error "lgetxattr on $DIR/$tfile failed"
9704         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
9705                 grep -i "no such attr" ||
9706                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
9707         rm -f $DIR/$tfile $DIR/${tfile}link
9708 }
9709 run_test 102i "lgetxattr test on symbolic link ============"
9710
9711 test_102j() {
9712         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9713         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9714
9715         XINC=$(have_xattrs_include)
9716         setup_test102 "$RUNAS"
9717         chown $RUNAS_ID $DIR/$tdir
9718         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
9719         cd $DIR/$tdir/$tdir
9720         compare_stripe_info1 "$RUNAS"
9721 }
9722 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
9723
9724 test_102k() {
9725         [ -z "$(which setfattr 2>/dev/null)" ] &&
9726                 skip "could not find setfattr"
9727
9728         touch $DIR/$tfile
9729         # b22187 just check that does not crash for regular file.
9730         setfattr -n trusted.lov $DIR/$tfile
9731         # b22187 'setfattr -n trusted.lov' should remove LOV EA for directories
9732         local test_kdir=$DIR/$tdir
9733         test_mkdir $test_kdir
9734         local default_size=$($LFS getstripe -S $test_kdir)
9735         local default_count=$($LFS getstripe -c $test_kdir)
9736         local default_offset=$($LFS getstripe -i $test_kdir)
9737         $LFS setstripe -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
9738                 error 'dir setstripe failed'
9739         setfattr -n trusted.lov $test_kdir
9740         local stripe_size=$($LFS getstripe -S $test_kdir)
9741         local stripe_count=$($LFS getstripe -c $test_kdir)
9742         local stripe_offset=$($LFS getstripe -i $test_kdir)
9743         [ $stripe_size -eq $default_size ] ||
9744                 error "stripe size $stripe_size != $default_size"
9745         [ $stripe_count -eq $default_count ] ||
9746                 error "stripe count $stripe_count != $default_count"
9747         [ $stripe_offset -eq $default_offset ] ||
9748                 error "stripe offset $stripe_offset != $default_offset"
9749         rm -rf $DIR/$tfile $test_kdir
9750 }
9751 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
9752
9753 test_102l() {
9754         [ -z "$(which getfattr 2>/dev/null)" ] &&
9755                 skip "could not find getfattr"
9756
9757         # LU-532 trusted. xattr is invisible to non-root
9758         local testfile=$DIR/$tfile
9759
9760         touch $testfile
9761
9762         echo "listxattr as user..."
9763         chown $RUNAS_ID $testfile
9764         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
9765             grep -q "trusted" &&
9766                 error "$testfile trusted xattrs are user visible"
9767
9768         return 0;
9769 }
9770 run_test 102l "listxattr size test =================================="
9771
9772 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
9773         local path=$DIR/$tfile
9774         touch $path
9775
9776         listxattr_size_check $path || error "listattr_size_check $path failed"
9777 }
9778 run_test 102m "Ensure listxattr fails on small bufffer ========"
9779
9780 cleanup_test102
9781
9782 getxattr() { # getxattr path name
9783         # Return the base64 encoding of the value of xattr name on path.
9784         local path=$1
9785         local name=$2
9786
9787         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
9788         # file: $path
9789         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
9790         #
9791         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
9792
9793         getfattr --absolute-names --encoding=base64 --name=$name $path |
9794                 awk -F= -v name=$name '$1 == name {
9795                         print substr($0, index($0, "=") + 1);
9796         }'
9797 }
9798
9799 test_102n() { # LU-4101 mdt: protect internal xattrs
9800         [ -z "$(which setfattr 2>/dev/null)" ] &&
9801                 skip "could not find setfattr"
9802         if [ $MDS1_VERSION -lt $(version_code 2.5.50) ]
9803         then
9804                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
9805         fi
9806
9807         local file0=$DIR/$tfile.0
9808         local file1=$DIR/$tfile.1
9809         local xattr0=$TMP/$tfile.0
9810         local xattr1=$TMP/$tfile.1
9811         local namelist="lov lma lmv link fid version som hsm"
9812         local name
9813         local value
9814
9815         rm -rf $file0 $file1 $xattr0 $xattr1
9816         touch $file0 $file1
9817
9818         # Get 'before' xattrs of $file1.
9819         getfattr --absolute-names --dump --match=- $file1 > $xattr0
9820
9821         [ $MDS1_VERSION -lt $(version_code 2.8.53) ] &&
9822                 namelist+=" lfsck_namespace"
9823         for name in $namelist; do
9824                 # Try to copy xattr from $file0 to $file1.
9825                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
9826
9827                 setfattr --name=trusted.$name --value="$value" $file1 ||
9828                         error "setxattr 'trusted.$name' failed"
9829
9830                 # Try to set a garbage xattr.
9831                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
9832
9833                 if [[ x$name == "xlov" ]]; then
9834                         setfattr --name=trusted.lov --value="$value" $file1 &&
9835                         error "setxattr invalid 'trusted.lov' success"
9836                 else
9837                         setfattr --name=trusted.$name --value="$value" $file1 ||
9838                                 error "setxattr invalid 'trusted.$name' failed"
9839                 fi
9840
9841                 # Try to remove the xattr from $file1. We don't care if this
9842                 # appears to succeed or fail, we just don't want there to be
9843                 # any changes or crashes.
9844                 setfattr --remove=$trusted.$name $file1 2> /dev/null
9845         done
9846
9847         if [ $MDS1_VERSION -gt $(version_code 2.6.50) ]
9848         then
9849                 name="lfsck_ns"
9850                 # Try to copy xattr from $file0 to $file1.
9851                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
9852
9853                 setfattr --name=trusted.$name --value="$value" $file1 ||
9854                         error "setxattr 'trusted.$name' failed"
9855
9856                 # Try to set a garbage xattr.
9857                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
9858
9859                 setfattr --name=trusted.$name --value="$value" $file1 ||
9860                         error "setxattr 'trusted.$name' failed"
9861
9862                 # Try to remove the xattr from $file1. We don't care if this
9863                 # appears to succeed or fail, we just don't want there to be
9864                 # any changes or crashes.
9865                 setfattr --remove=$trusted.$name $file1 2> /dev/null
9866         fi
9867
9868         # Get 'after' xattrs of file1.
9869         getfattr --absolute-names --dump --match=- $file1 > $xattr1
9870
9871         if ! diff $xattr0 $xattr1; then
9872                 error "before and after xattrs of '$file1' differ"
9873         fi
9874
9875         rm -rf $file0 $file1 $xattr0 $xattr1
9876
9877         return 0
9878 }
9879 run_test 102n "silently ignore setxattr on internal trusted xattrs"
9880
9881 test_102p() { # LU-4703 setxattr did not check ownership
9882         [ $MDS1_VERSION -lt $(version_code 2.5.56) ] &&
9883                 skip "MDS needs to be at least 2.5.56"
9884
9885         local testfile=$DIR/$tfile
9886
9887         touch $testfile
9888
9889         echo "setfacl as user..."
9890         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
9891         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
9892
9893         echo "setfattr as user..."
9894         setfacl -m "u:$RUNAS_ID:---" $testfile
9895         $RUNAS setfattr -x system.posix_acl_access $testfile
9896         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
9897 }
9898 run_test 102p "check setxattr(2) correctly fails without permission"
9899
9900 test_102q() {
9901         [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
9902                 skip "MDS needs to be at least 2.6.92"
9903
9904         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
9905 }
9906 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
9907
9908 test_102r() {
9909         [ $MDS1_VERSION -lt $(version_code 2.6.93) ] &&
9910                 skip "MDS needs to be at least 2.6.93"
9911
9912         touch $DIR/$tfile || error "touch"
9913         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
9914         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
9915         rm $DIR/$tfile || error "rm"
9916
9917         #normal directory
9918         mkdir -p $DIR/$tdir || error "mkdir"
9919         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
9920         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
9921         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
9922                 error "$testfile error deleting user.author1"
9923         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
9924                 grep "user.$(basename $tdir)" &&
9925                 error "$tdir did not delete user.$(basename $tdir)"
9926         rmdir $DIR/$tdir || error "rmdir"
9927
9928         #striped directory
9929         test_mkdir $DIR/$tdir
9930         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
9931         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
9932         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
9933                 error "$testfile error deleting user.author1"
9934         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
9935                 grep "user.$(basename $tdir)" &&
9936                 error "$tdir did not delete user.$(basename $tdir)"
9937         rmdir $DIR/$tdir || error "rm striped dir"
9938 }
9939 run_test 102r "set EAs with empty values"
9940
9941 test_102s() {
9942         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
9943                 skip "MDS needs to be at least 2.11.52"
9944
9945         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
9946
9947         save_lustre_params client "llite.*.xattr_cache" > $save
9948
9949         for cache in 0 1; do
9950                 lctl set_param llite.*.xattr_cache=$cache
9951
9952                 rm -f $DIR/$tfile
9953                 touch $DIR/$tfile || error "touch"
9954                 for prefix in lustre security system trusted user; do
9955                         # Note getxattr() may fail with 'Operation not
9956                         # supported' or 'No such attribute' depending
9957                         # on prefix and cache.
9958                         getfattr -n $prefix.n102s $DIR/$tfile &&
9959                                 error "getxattr '$prefix.n102s' should fail (cache = $cache)"
9960                 done
9961         done
9962
9963         restore_lustre_params < $save
9964 }
9965 run_test 102s "getting nonexistent xattrs should fail"
9966
9967 test_102t() {
9968         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
9969                 skip "MDS needs to be at least 2.11.52"
9970
9971         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
9972
9973         save_lustre_params client "llite.*.xattr_cache" > $save
9974
9975         for cache in 0 1; do
9976                 lctl set_param llite.*.xattr_cache=$cache
9977
9978                 for buf_size in 0 256; do
9979                         rm -f $DIR/$tfile
9980                         touch $DIR/$tfile || error "touch"
9981                         setfattr -n user.multiop $DIR/$tfile
9982                         $MULTIOP $DIR/$tfile oa$buf_size ||
9983                                 error "cannot get zero length xattr value (buf_size = $buf_size)"
9984                 done
9985         done
9986
9987         restore_lustre_params < $save
9988 }
9989 run_test 102t "zero length xattr values handled correctly"
9990
9991 run_acl_subtest()
9992 {
9993     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
9994     return $?
9995 }
9996
9997 test_103a() {
9998         [ "$UID" != 0 ] && skip "must run as root"
9999         $GSS && skip_env "could not run under gss"
10000         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
10001                 skip_env "must have acl enabled"
10002         [ -z "$(which setfacl 2>/dev/null)" ] &&
10003                 skip_env "could not find setfacl"
10004         remote_mds_nodsh && skip "remote MDS with nodsh"
10005
10006         gpasswd -a daemon bin                           # LU-5641
10007         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
10008
10009         declare -a identity_old
10010
10011         for num in $(seq $MDSCOUNT); do
10012                 switch_identity $num true || identity_old[$num]=$?
10013         done
10014
10015         SAVE_UMASK=$(umask)
10016         umask 0022
10017         mkdir -p $DIR/$tdir
10018         cd $DIR/$tdir
10019
10020         echo "performing cp ..."
10021         run_acl_subtest cp || error "run_acl_subtest cp failed"
10022         echo "performing getfacl-noacl..."
10023         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
10024         echo "performing misc..."
10025         run_acl_subtest misc || error  "misc test failed"
10026         echo "performing permissions..."
10027         run_acl_subtest permissions || error "permissions failed"
10028         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
10029         if [ $MDS1_VERSION -gt $(version_code 2.8.55) ] ||
10030                 { [ $MDS1_VERSION -lt $(version_code 2.6) ] &&
10031                         [ $MDS1_VERSION -ge $(version_code 2.5.29) ]; }
10032         then
10033                 echo "performing permissions xattr..."
10034                 run_acl_subtest permissions_xattr ||
10035                         error "permissions_xattr failed"
10036         fi
10037         echo "performing setfacl..."
10038         run_acl_subtest setfacl || error  "setfacl test failed"
10039
10040         # inheritance test got from HP
10041         echo "performing inheritance..."
10042         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
10043         chmod +x make-tree || error "chmod +x failed"
10044         run_acl_subtest inheritance || error "inheritance test failed"
10045         rm -f make-tree
10046
10047         echo "LU-974 ignore umask when acl is enabled..."
10048         run_acl_subtest 974 || error "LU-974 umask test failed"
10049         if [ $MDSCOUNT -ge 2 ]; then
10050                 run_acl_subtest 974_remote ||
10051                         error "LU-974 umask test failed under remote dir"
10052         fi
10053
10054         echo "LU-2561 newly created file is same size as directory..."
10055         if [ "$mds1_FSTYPE" != "zfs" ]; then
10056                 run_acl_subtest 2561 || error "LU-2561 test failed"
10057         else
10058                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
10059         fi
10060
10061         run_acl_subtest 4924 || error "LU-4924 test failed"
10062
10063         cd $SAVE_PWD
10064         umask $SAVE_UMASK
10065
10066         for num in $(seq $MDSCOUNT); do
10067                 if [ "${identity_old[$num]}" = 1 ]; then
10068                         switch_identity $num false || identity_old[$num]=$?
10069                 fi
10070         done
10071 }
10072 run_test 103a "acl test"
10073
10074 test_103b() {
10075         declare -a pids
10076         local U
10077
10078         for U in {0..511}; do
10079                 {
10080                 local O=$(printf "%04o" $U)
10081
10082                 umask $(printf "%04o" $((511 ^ $O)))
10083                 $LFS setstripe -c 1 $DIR/$tfile.s$O
10084                 local S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.s$O))
10085
10086                 (( $S == ($O & 0666) )) ||
10087                         error "lfs setstripe $DIR/$tfile.s$O '$S' != '$O'"
10088
10089                 $LFS setstripe -E16M -c 1 -E1G -S4M $DIR/$tfile.p$O
10090                 S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.p$O))
10091                 (( $S == ($O & 0666) )) ||
10092                         error "lfs setstripe -E $DIR/$tfile.p$O '$S' != '$O'"
10093
10094                 $LFS setstripe -N2 -c 1 $DIR/$tfile.m$O
10095                 S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.m$O))
10096                 (( $S == ($O & 0666) )) ||
10097                         error "lfs setstripe -N2 $DIR/$tfile.m$O '$S' != '$O'"
10098                 rm -f $DIR/$tfile.[smp]$0
10099                 } &
10100                 local pid=$!
10101
10102                 # limit the concurrently running threads to 64. LU-11878
10103                 local idx=$((U % 64))
10104                 [ -z "${pids[idx]}" ] || wait ${pids[idx]}
10105                 pids[idx]=$pid
10106         done
10107         wait
10108 }
10109 run_test 103b "umask lfs setstripe"
10110
10111 test_103c() {
10112         mkdir -p $DIR/$tdir
10113         cp -rp $DIR/$tdir $DIR/$tdir.bak
10114
10115         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
10116                 error "$DIR/$tdir shouldn't contain default ACL"
10117         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
10118                 error "$DIR/$tdir.bak shouldn't contain default ACL"
10119         true
10120 }
10121 run_test 103c "'cp -rp' won't set empty acl"
10122
10123 test_104a() {
10124         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10125
10126         touch $DIR/$tfile
10127         lfs df || error "lfs df failed"
10128         lfs df -ih || error "lfs df -ih failed"
10129         lfs df -h $DIR || error "lfs df -h $DIR failed"
10130         lfs df -i $DIR || error "lfs df -i $DIR failed"
10131         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
10132         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
10133
10134         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
10135         lctl --device %$OSC deactivate
10136         lfs df || error "lfs df with deactivated OSC failed"
10137         lctl --device %$OSC activate
10138         # wait the osc back to normal
10139         wait_osc_import_ready client ost
10140
10141         lfs df || error "lfs df with reactivated OSC failed"
10142         rm -f $DIR/$tfile
10143 }
10144 run_test 104a "lfs df [-ih] [path] test ========================="
10145
10146 test_104b() {
10147         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10148         [ $RUNAS_ID -eq $UID ] &&
10149                 skip_env "RUNAS_ID = UID = $UID -- skipping"
10150
10151         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
10152                         grep "Permission denied" | wc -l)))
10153         if [ $denied_cnt -ne 0 ]; then
10154                 error "lfs check servers test failed"
10155         fi
10156 }
10157 run_test 104b "$RUNAS lfs check servers test ===================="
10158
10159 test_105a() {
10160         # doesn't work on 2.4 kernels
10161         touch $DIR/$tfile
10162         if $(flock_is_enabled); then
10163                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
10164         else
10165                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
10166         fi
10167         rm -f $DIR/$tfile
10168 }
10169 run_test 105a "flock when mounted without -o flock test ========"
10170
10171 test_105b() {
10172         touch $DIR/$tfile
10173         if $(flock_is_enabled); then
10174                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
10175         else
10176                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
10177         fi
10178         rm -f $DIR/$tfile
10179 }
10180 run_test 105b "fcntl when mounted without -o flock test ========"
10181
10182 test_105c() {
10183         touch $DIR/$tfile
10184         if $(flock_is_enabled); then
10185                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
10186         else
10187                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
10188         fi
10189         rm -f $DIR/$tfile
10190 }
10191 run_test 105c "lockf when mounted without -o flock test"
10192
10193 test_105d() { # bug 15924
10194         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10195
10196         test_mkdir $DIR/$tdir
10197         flock_is_enabled || skip_env "mount w/o flock enabled"
10198         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
10199         $LCTL set_param fail_loc=0x80000315
10200         flocks_test 2 $DIR/$tdir
10201 }
10202 run_test 105d "flock race (should not freeze) ========"
10203
10204 test_105e() { # bug 22660 && 22040
10205         flock_is_enabled || skip_env "mount w/o flock enabled"
10206
10207         touch $DIR/$tfile
10208         flocks_test 3 $DIR/$tfile
10209 }
10210 run_test 105e "Two conflicting flocks from same process"
10211
10212 test_106() { #bug 10921
10213         test_mkdir $DIR/$tdir
10214         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
10215         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
10216 }
10217 run_test 106 "attempt exec of dir followed by chown of that dir"
10218
10219 test_107() {
10220         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10221
10222         CDIR=`pwd`
10223         local file=core
10224
10225         cd $DIR
10226         rm -f $file
10227
10228         local save_pattern=$(sysctl -n kernel.core_pattern)
10229         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
10230         sysctl -w kernel.core_pattern=$file
10231         sysctl -w kernel.core_uses_pid=0
10232
10233         ulimit -c unlimited
10234         sleep 60 &
10235         SLEEPPID=$!
10236
10237         sleep 1
10238
10239         kill -s 11 $SLEEPPID
10240         wait $SLEEPPID
10241         if [ -e $file ]; then
10242                 size=`stat -c%s $file`
10243                 [ $size -eq 0 ] && error "Fail to create core file $file"
10244         else
10245                 error "Fail to create core file $file"
10246         fi
10247         rm -f $file
10248         sysctl -w kernel.core_pattern=$save_pattern
10249         sysctl -w kernel.core_uses_pid=$save_uses_pid
10250         cd $CDIR
10251 }
10252 run_test 107 "Coredump on SIG"
10253
10254 test_110() {
10255         test_mkdir $DIR/$tdir
10256         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255)
10257         $LFS mkdir -c $MDSCOUNT $DIR/$tdir/$(str_repeat 'b' 256) &&
10258                 error "mkdir with 256 char should fail, but did not"
10259         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
10260                 error "create with 255 char failed"
10261         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
10262                 error "create with 256 char should fail, but did not"
10263
10264         ls -l $DIR/$tdir
10265         rm -rf $DIR/$tdir
10266 }
10267 run_test 110 "filename length checking"
10268
10269 #
10270 # Purpose: To verify dynamic thread (OSS) creation.
10271 #
10272 test_115() {
10273         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10274         remote_ost_nodsh && skip "remote OST with nodsh"
10275
10276         # Lustre does not stop service threads once they are started.
10277         # Reset number of running threads to default.
10278         stopall
10279         setupall
10280
10281         local OSTIO_pre
10282         local save_params="$TMP/sanity-$TESTNAME.parameters"
10283
10284         # Get ll_ost_io count before I/O
10285         OSTIO_pre=$(do_facet ost1 \
10286                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
10287         # Exit if lustre is not running (ll_ost_io not running).
10288         [ -z "$OSTIO_pre" ] && error "no OSS threads"
10289
10290         echo "Starting with $OSTIO_pre threads"
10291         local thread_max=$((OSTIO_pre * 2))
10292         local rpc_in_flight=$((thread_max * 2))
10293         # Number of I/O Process proposed to be started.
10294         local nfiles
10295         local facets=$(get_facets OST)
10296
10297         save_lustre_params client "osc.*OST*.max_rpcs_in_flight" > $save_params
10298         save_lustre_params $facets "ost.OSS.ost_io.threads_max" >> $save_params
10299
10300         # Set in_flight to $rpc_in_flight
10301         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
10302                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
10303         nfiles=${rpc_in_flight}
10304         # Set ost thread_max to $thread_max
10305         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
10306
10307         # 5 Minutes should be sufficient for max number of OSS
10308         # threads(thread_max) to be created.
10309         local timeout=300
10310
10311         # Start I/O.
10312         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
10313         test_mkdir $DIR/$tdir
10314         for i in $(seq $nfiles); do
10315                 local file=$DIR/$tdir/${tfile}-$i
10316                 $LFS setstripe -c -1 -i 0 $file
10317                 ($WTL $file $timeout)&
10318         done
10319
10320         # I/O Started - Wait for thread_started to reach thread_max or report
10321         # error if thread_started is more than thread_max.
10322         echo "Waiting for thread_started to reach thread_max"
10323         local thread_started=0
10324         local end_time=$((SECONDS + timeout))
10325
10326         while [ $SECONDS -le $end_time ] ; do
10327                 echo -n "."
10328                 # Get ost i/o thread_started count.
10329                 thread_started=$(do_facet ost1 \
10330                         "$LCTL get_param \
10331                         ost.OSS.ost_io.threads_started | cut -d= -f2")
10332                 # Break out if thread_started is equal/greater than thread_max
10333                 if [[ $thread_started -ge $thread_max ]]; then
10334                         echo ll_ost_io thread_started $thread_started, \
10335                                 equal/greater than thread_max $thread_max
10336                         break
10337                 fi
10338                 sleep 1
10339         done
10340
10341         # Cleanup - We have the numbers, Kill i/o jobs if running.
10342         jobcount=($(jobs -p))
10343         for i in $(seq 0 $((${#jobcount[@]}-1)))
10344         do
10345                 kill -9 ${jobcount[$i]}
10346                 if [ $? -ne 0 ] ; then
10347                         echo Warning: \
10348                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
10349                 fi
10350         done
10351
10352         # Cleanup files left by WTL binary.
10353         for i in $(seq $nfiles); do
10354                 local file=$DIR/$tdir/${tfile}-$i
10355                 rm -rf $file
10356                 if [ $? -ne 0 ] ; then
10357                         echo "Warning: Failed to delete file $file"
10358                 fi
10359         done
10360
10361         restore_lustre_params <$save_params
10362         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
10363
10364         # Error out if no new thread has started or Thread started is greater
10365         # than thread max.
10366         if [[ $thread_started -le $OSTIO_pre ||
10367                         $thread_started -gt $thread_max ]]; then
10368                 error "ll_ost_io: thread_started $thread_started" \
10369                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
10370                       "No new thread started or thread started greater " \
10371                       "than thread_max."
10372         fi
10373 }
10374 run_test 115 "verify dynamic thread creation===================="
10375
10376 free_min_max () {
10377         wait_delete_completed
10378         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
10379         echo "OST kbytes available: ${AVAIL[@]}"
10380         MAXV=${AVAIL[0]}
10381         MAXI=0
10382         MINV=${AVAIL[0]}
10383         MINI=0
10384         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
10385                 #echo OST $i: ${AVAIL[i]}kb
10386                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
10387                         MAXV=${AVAIL[i]}
10388                         MAXI=$i
10389                 fi
10390                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
10391                         MINV=${AVAIL[i]}
10392                         MINI=$i
10393                 fi
10394         done
10395         echo "Min free space: OST $MINI: $MINV"
10396         echo "Max free space: OST $MAXI: $MAXV"
10397 }
10398
10399 test_116a() { # was previously test_116()
10400         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10401         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
10402         remote_mds_nodsh && skip "remote MDS with nodsh"
10403
10404         echo -n "Free space priority "
10405         do_facet $SINGLEMDS lctl get_param -n lo[vd].*-mdtlov.qos_prio_free |
10406                 head -n1
10407         declare -a AVAIL
10408         free_min_max
10409
10410         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip"
10411         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip"
10412         trap simple_cleanup_common EXIT
10413
10414         # Check if we need to generate uneven OSTs
10415         test_mkdir -p $DIR/$tdir/OST${MINI}
10416         local FILL=$((MINV / 4))
10417         local DIFF=$((MAXV - MINV))
10418         local DIFF2=$((DIFF * 100 / MINV))
10419
10420         local threshold=$(do_facet $SINGLEMDS \
10421                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
10422         threshold=${threshold%%%}
10423         echo -n "Check for uneven OSTs: "
10424         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
10425
10426         if [[ $DIFF2 -gt $threshold ]]; then
10427                 echo "ok"
10428                 echo "Don't need to fill OST$MINI"
10429         else
10430                 # generate uneven OSTs. Write 2% over the QOS threshold value
10431                 echo "no"
10432                 DIFF=$((threshold - DIFF2 + 2))
10433                 DIFF2=$((MINV * DIFF / 100))
10434                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
10435                 $LFS setstripe -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
10436                         error "setstripe failed"
10437                 DIFF=$((DIFF2 / 2048))
10438                 i=0
10439                 while [ $i -lt $DIFF ]; do
10440                         i=$((i + 1))
10441                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
10442                                 bs=2M count=1 2>/dev/null
10443                         echo -n .
10444                 done
10445                 echo .
10446                 sync
10447                 sleep_maxage
10448                 free_min_max
10449         fi
10450
10451         DIFF=$((MAXV - MINV))
10452         DIFF2=$((DIFF * 100 / MINV))
10453         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
10454         if [ $DIFF2 -gt $threshold ]; then
10455                 echo "ok"
10456         else
10457                 echo "failed - QOS mode won't be used"
10458                 simple_cleanup_common
10459                 skip "QOS imbalance criteria not met"
10460         fi
10461
10462         MINI1=$MINI
10463         MINV1=$MINV
10464         MAXI1=$MAXI
10465         MAXV1=$MAXV
10466
10467         # now fill using QOS
10468         $LFS setstripe -c 1 $DIR/$tdir
10469         FILL=$((FILL / 200))
10470         if [ $FILL -gt 600 ]; then
10471                 FILL=600
10472         fi
10473         echo "writing $FILL files to QOS-assigned OSTs"
10474         i=0
10475         while [ $i -lt $FILL ]; do
10476                 i=$((i + 1))
10477                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
10478                         count=1 2>/dev/null
10479                 echo -n .
10480         done
10481         echo "wrote $i 200k files"
10482         sync
10483         sleep_maxage
10484
10485         echo "Note: free space may not be updated, so measurements might be off"
10486         free_min_max
10487         DIFF2=$((MAXV - MINV))
10488         echo "free space delta: orig $DIFF final $DIFF2"
10489         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
10490         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
10491         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
10492         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
10493         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
10494         if [[ $DIFF -gt 0 ]]; then
10495                 FILL=$((DIFF2 * 100 / DIFF - 100))
10496                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
10497         fi
10498
10499         # Figure out which files were written where
10500         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
10501                awk '/'$MINI1': / {print $2; exit}')
10502         echo $UUID
10503         MINC=$($LFS getstripe --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
10504         echo "$MINC files created on smaller OST $MINI1"
10505         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
10506                awk '/'$MAXI1': / {print $2; exit}')
10507         echo $UUID
10508         MAXC=$($LFS getstripe --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
10509         echo "$MAXC files created on larger OST $MAXI1"
10510         if [[ $MINC -gt 0 ]]; then
10511                 FILL=$((MAXC * 100 / MINC - 100))
10512                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
10513         fi
10514         [[ $MAXC -gt $MINC ]] ||
10515                 error_ignore LU-9 "stripe QOS didn't balance free space"
10516         simple_cleanup_common
10517 }
10518 run_test 116a "stripe QOS: free space balance ==================="
10519
10520 test_116b() { # LU-2093
10521         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10522         remote_mds_nodsh && skip "remote MDS with nodsh"
10523
10524 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
10525         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
10526                        lo[vd].$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
10527         [ -z "$old_rr" ] && skip "no QOS"
10528         do_facet $SINGLEMDS lctl set_param \
10529                 lo[vd].$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
10530         mkdir -p $DIR/$tdir
10531         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
10532         createmany -o $DIR/$tdir/f- 20 || error "can't create"
10533         do_facet $SINGLEMDS lctl set_param fail_loc=0
10534         rm -rf $DIR/$tdir
10535         do_facet $SINGLEMDS lctl set_param \
10536                 lo[vd].$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
10537 }
10538 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
10539
10540 test_117() # bug 10891
10541 {
10542         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10543
10544         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
10545         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
10546         lctl set_param fail_loc=0x21e
10547         > $DIR/$tfile || error "truncate failed"
10548         lctl set_param fail_loc=0
10549         echo "Truncate succeeded."
10550         rm -f $DIR/$tfile
10551 }
10552 run_test 117 "verify osd extend =========="
10553
10554 NO_SLOW_RESENDCOUNT=4
10555 export OLD_RESENDCOUNT=""
10556 set_resend_count () {
10557         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
10558         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
10559         lctl set_param -n $PROC_RESENDCOUNT $1
10560         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
10561 }
10562
10563 # for reduce test_118* time (b=14842)
10564 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
10565
10566 # Reset async IO behavior after error case
10567 reset_async() {
10568         FILE=$DIR/reset_async
10569
10570         # Ensure all OSCs are cleared
10571         $LFS setstripe -c -1 $FILE
10572         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
10573         sync
10574         rm $FILE
10575 }
10576
10577 test_118a() #bug 11710
10578 {
10579         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10580
10581         reset_async
10582
10583         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10584         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10585         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
10586
10587         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10588                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10589                 return 1;
10590         fi
10591         rm -f $DIR/$tfile
10592 }
10593 run_test 118a "verify O_SYNC works =========="
10594
10595 test_118b()
10596 {
10597         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10598         remote_ost_nodsh && skip "remote OST with nodsh"
10599
10600         reset_async
10601
10602         #define OBD_FAIL_SRV_ENOENT 0x217
10603         set_nodes_failloc "$(osts_nodes)" 0x217
10604         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10605         RC=$?
10606         set_nodes_failloc "$(osts_nodes)" 0
10607         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10608         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10609                     grep -c writeback)
10610
10611         if [[ $RC -eq 0 ]]; then
10612                 error "Must return error due to dropped pages, rc=$RC"
10613                 return 1;
10614         fi
10615
10616         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10617                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10618                 return 1;
10619         fi
10620
10621         echo "Dirty pages not leaked on ENOENT"
10622
10623         # Due to the above error the OSC will issue all RPCs syncronously
10624         # until a subsequent RPC completes successfully without error.
10625         $MULTIOP $DIR/$tfile Ow4096yc
10626         rm -f $DIR/$tfile
10627
10628         return 0
10629 }
10630 run_test 118b "Reclaim dirty pages on fatal error =========="
10631
10632 test_118c()
10633 {
10634         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10635
10636         # for 118c, restore the original resend count, LU-1940
10637         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
10638                                 set_resend_count $OLD_RESENDCOUNT
10639         remote_ost_nodsh && skip "remote OST with nodsh"
10640
10641         reset_async
10642
10643         #define OBD_FAIL_OST_EROFS               0x216
10644         set_nodes_failloc "$(osts_nodes)" 0x216
10645
10646         # multiop should block due to fsync until pages are written
10647         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
10648         MULTIPID=$!
10649         sleep 1
10650
10651         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
10652                 error "Multiop failed to block on fsync, pid=$MULTIPID"
10653         fi
10654
10655         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10656                     grep -c writeback)
10657         if [[ $WRITEBACK -eq 0 ]]; then
10658                 error "No page in writeback, writeback=$WRITEBACK"
10659         fi
10660
10661         set_nodes_failloc "$(osts_nodes)" 0
10662         wait $MULTIPID
10663         RC=$?
10664         if [[ $RC -ne 0 ]]; then
10665                 error "Multiop fsync failed, rc=$RC"
10666         fi
10667
10668         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10669         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10670                     grep -c writeback)
10671         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10672                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10673         fi
10674
10675         rm -f $DIR/$tfile
10676         echo "Dirty pages flushed via fsync on EROFS"
10677         return 0
10678 }
10679 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
10680
10681 # continue to use small resend count to reduce test_118* time (b=14842)
10682 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
10683
10684 test_118d()
10685 {
10686         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10687         remote_ost_nodsh && skip "remote OST with nodsh"
10688
10689         reset_async
10690
10691         #define OBD_FAIL_OST_BRW_PAUSE_BULK
10692         set_nodes_failloc "$(osts_nodes)" 0x214
10693         # multiop should block due to fsync until pages are written
10694         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
10695         MULTIPID=$!
10696         sleep 1
10697
10698         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
10699                 error "Multiop failed to block on fsync, pid=$MULTIPID"
10700         fi
10701
10702         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10703                     grep -c writeback)
10704         if [[ $WRITEBACK -eq 0 ]]; then
10705                 error "No page in writeback, writeback=$WRITEBACK"
10706         fi
10707
10708         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
10709         set_nodes_failloc "$(osts_nodes)" 0
10710
10711         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10712         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10713                     grep -c writeback)
10714         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10715                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10716         fi
10717
10718         rm -f $DIR/$tfile
10719         echo "Dirty pages gaurenteed flushed via fsync"
10720         return 0
10721 }
10722 run_test 118d "Fsync validation inject a delay of the bulk =========="
10723
10724 test_118f() {
10725         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10726
10727         reset_async
10728
10729         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
10730         lctl set_param fail_loc=0x8000040a
10731
10732         # Should simulate EINVAL error which is fatal
10733         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10734         RC=$?
10735         if [[ $RC -eq 0 ]]; then
10736                 error "Must return error due to dropped pages, rc=$RC"
10737         fi
10738
10739         lctl set_param fail_loc=0x0
10740
10741         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10742         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10743         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10744                     grep -c writeback)
10745         if [[ $LOCKED -ne 0 ]]; then
10746                 error "Locked pages remain in cache, locked=$LOCKED"
10747         fi
10748
10749         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10750                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10751         fi
10752
10753         rm -f $DIR/$tfile
10754         echo "No pages locked after fsync"
10755
10756         reset_async
10757         return 0
10758 }
10759 run_test 118f "Simulate unrecoverable OSC side error =========="
10760
10761 test_118g() {
10762         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10763
10764         reset_async
10765
10766         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
10767         lctl set_param fail_loc=0x406
10768
10769         # simulate local -ENOMEM
10770         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10771         RC=$?
10772
10773         lctl set_param fail_loc=0
10774         if [[ $RC -eq 0 ]]; then
10775                 error "Must return error due to dropped pages, rc=$RC"
10776         fi
10777
10778         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10779         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10780         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10781                         grep -c writeback)
10782         if [[ $LOCKED -ne 0 ]]; then
10783                 error "Locked pages remain in cache, locked=$LOCKED"
10784         fi
10785
10786         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10787                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10788         fi
10789
10790         rm -f $DIR/$tfile
10791         echo "No pages locked after fsync"
10792
10793         reset_async
10794         return 0
10795 }
10796 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
10797
10798 test_118h() {
10799         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10800         remote_ost_nodsh && skip "remote OST with nodsh"
10801
10802         reset_async
10803
10804         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
10805         set_nodes_failloc "$(osts_nodes)" 0x20e
10806         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
10807         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10808         RC=$?
10809
10810         set_nodes_failloc "$(osts_nodes)" 0
10811         if [[ $RC -eq 0 ]]; then
10812                 error "Must return error due to dropped pages, rc=$RC"
10813         fi
10814
10815         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10816         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10817         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10818                     grep -c writeback)
10819         if [[ $LOCKED -ne 0 ]]; then
10820                 error "Locked pages remain in cache, locked=$LOCKED"
10821         fi
10822
10823         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10824                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10825         fi
10826
10827         rm -f $DIR/$tfile
10828         echo "No pages locked after fsync"
10829
10830         return 0
10831 }
10832 run_test 118h "Verify timeout in handling recoverables errors  =========="
10833
10834 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
10835
10836 test_118i() {
10837         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10838         remote_ost_nodsh && skip "remote OST with nodsh"
10839
10840         reset_async
10841
10842         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
10843         set_nodes_failloc "$(osts_nodes)" 0x20e
10844
10845         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
10846         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
10847         PID=$!
10848         sleep 5
10849         set_nodes_failloc "$(osts_nodes)" 0
10850
10851         wait $PID
10852         RC=$?
10853         if [[ $RC -ne 0 ]]; then
10854                 error "got error, but should be not, rc=$RC"
10855         fi
10856
10857         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10858         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10859         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
10860         if [[ $LOCKED -ne 0 ]]; then
10861                 error "Locked pages remain in cache, locked=$LOCKED"
10862         fi
10863
10864         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10865                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10866         fi
10867
10868         rm -f $DIR/$tfile
10869         echo "No pages locked after fsync"
10870
10871         return 0
10872 }
10873 run_test 118i "Fix error before timeout in recoverable error  =========="
10874
10875 [ "$SLOW" = "no" ] && set_resend_count 4
10876
10877 test_118j() {
10878         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10879         remote_ost_nodsh && skip "remote OST with nodsh"
10880
10881         reset_async
10882
10883         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
10884         set_nodes_failloc "$(osts_nodes)" 0x220
10885
10886         # return -EIO from OST
10887         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10888         RC=$?
10889         set_nodes_failloc "$(osts_nodes)" 0x0
10890         if [[ $RC -eq 0 ]]; then
10891                 error "Must return error due to dropped pages, rc=$RC"
10892         fi
10893
10894         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10895         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10896         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
10897         if [[ $LOCKED -ne 0 ]]; then
10898                 error "Locked pages remain in cache, locked=$LOCKED"
10899         fi
10900
10901         # in recoverable error on OST we want resend and stay until it finished
10902         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10903                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10904         fi
10905
10906         rm -f $DIR/$tfile
10907         echo "No pages locked after fsync"
10908
10909         return 0
10910 }
10911 run_test 118j "Simulate unrecoverable OST side error =========="
10912
10913 test_118k()
10914 {
10915         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10916         remote_ost_nodsh && skip "remote OSTs with nodsh"
10917
10918         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
10919         set_nodes_failloc "$(osts_nodes)" 0x20e
10920         test_mkdir $DIR/$tdir
10921
10922         for ((i=0;i<10;i++)); do
10923                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
10924                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
10925                 SLEEPPID=$!
10926                 sleep 0.500s
10927                 kill $SLEEPPID
10928                 wait $SLEEPPID
10929         done
10930
10931         set_nodes_failloc "$(osts_nodes)" 0
10932         rm -rf $DIR/$tdir
10933 }
10934 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
10935
10936 test_118l() # LU-646
10937 {
10938         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10939
10940         test_mkdir $DIR/$tdir
10941         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
10942         rm -rf $DIR/$tdir
10943 }
10944 run_test 118l "fsync dir"
10945
10946 test_118m() # LU-3066
10947 {
10948         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10949
10950         test_mkdir $DIR/$tdir
10951         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
10952         rm -rf $DIR/$tdir
10953 }
10954 run_test 118m "fdatasync dir ========="
10955
10956 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
10957
10958 test_118n()
10959 {
10960         local begin
10961         local end
10962
10963         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10964         remote_ost_nodsh && skip "remote OSTs with nodsh"
10965
10966         # Sleep to avoid a cached response.
10967         #define OBD_STATFS_CACHE_SECONDS 1
10968         sleep 2
10969
10970         # Inject a 10 second delay in the OST_STATFS handler.
10971         #define OBD_FAIL_OST_STATFS_DELAY 0x242
10972         set_nodes_failloc "$(osts_nodes)" 0x242
10973
10974         begin=$SECONDS
10975         stat --file-system $MOUNT > /dev/null
10976         end=$SECONDS
10977
10978         set_nodes_failloc "$(osts_nodes)" 0
10979
10980         if ((end - begin > 20)); then
10981             error "statfs took $((end - begin)) seconds, expected 10"
10982         fi
10983 }
10984 run_test 118n "statfs() sends OST_STATFS requests in parallel"
10985
10986 test_119a() # bug 11737
10987 {
10988         BSIZE=$((512 * 1024))
10989         directio write $DIR/$tfile 0 1 $BSIZE
10990         # We ask to read two blocks, which is more than a file size.
10991         # directio will indicate an error when requested and actual
10992         # sizes aren't equeal (a normal situation in this case) and
10993         # print actual read amount.
10994         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
10995         if [ "$NOB" != "$BSIZE" ]; then
10996                 error "read $NOB bytes instead of $BSIZE"
10997         fi
10998         rm -f $DIR/$tfile
10999 }
11000 run_test 119a "Short directIO read must return actual read amount"
11001
11002 test_119b() # bug 11737
11003 {
11004         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
11005
11006         $LFS setstripe -c 2 $DIR/$tfile || error "setstripe failed"
11007         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
11008         sync
11009         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) ||
11010                 error "direct read failed"
11011         rm -f $DIR/$tfile
11012 }
11013 run_test 119b "Sparse directIO read must return actual read amount"
11014
11015 test_119c() # bug 13099
11016 {
11017         BSIZE=1048576
11018         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
11019         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
11020         rm -f $DIR/$tfile
11021 }
11022 run_test 119c "Testing for direct read hitting hole"
11023
11024 test_119d() # bug 15950
11025 {
11026         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11027
11028         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
11029         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
11030         BSIZE=1048576
11031         $LFS setstripe $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
11032         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
11033         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
11034         lctl set_param fail_loc=0x40d
11035         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
11036         pid_dio=$!
11037         sleep 1
11038         cat $DIR/$tfile > /dev/null &
11039         lctl set_param fail_loc=0
11040         pid_reads=$!
11041         wait $pid_dio
11042         log "the DIO writes have completed, now wait for the reads (should not block very long)"
11043         sleep 2
11044         [ -n "`ps h -p $pid_reads -o comm`" ] && \
11045         error "the read rpcs have not completed in 2s"
11046         rm -f $DIR/$tfile
11047         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
11048 }
11049 run_test 119d "The DIO path should try to send a new rpc once one is completed"
11050
11051 test_120a() {
11052         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11053         remote_mds_nodsh && skip "remote MDS with nodsh"
11054         test_mkdir -i0 -c1 $DIR/$tdir
11055         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11056                 skip_env "no early lock cancel on server"
11057
11058         lru_resize_disable mdc
11059         lru_resize_disable osc
11060         cancel_lru_locks mdc
11061         # asynchronous object destroy at MDT could cause bl ast to client
11062         cancel_lru_locks osc
11063
11064         stat $DIR/$tdir > /dev/null
11065         can1=$(do_facet mds1 \
11066                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11067                awk '/ldlm_cancel/ {print $2}')
11068         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11069                awk '/ldlm_bl_callback/ {print $2}')
11070         test_mkdir -i0 -c1 $DIR/$tdir/d1
11071         can2=$(do_facet mds1 \
11072                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11073                awk '/ldlm_cancel/ {print $2}')
11074         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11075                awk '/ldlm_bl_callback/ {print $2}')
11076         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11077         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11078         lru_resize_enable mdc
11079         lru_resize_enable osc
11080 }
11081 run_test 120a "Early Lock Cancel: mkdir test"
11082
11083 test_120b() {
11084         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11085         remote_mds_nodsh && skip "remote MDS with nodsh"
11086         test_mkdir $DIR/$tdir
11087         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11088                 skip_env "no early lock cancel on server"
11089
11090         lru_resize_disable mdc
11091         lru_resize_disable osc
11092         cancel_lru_locks mdc
11093         stat $DIR/$tdir > /dev/null
11094         can1=$(do_facet $SINGLEMDS \
11095                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11096                awk '/ldlm_cancel/ {print $2}')
11097         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11098                awk '/ldlm_bl_callback/ {print $2}')
11099         touch $DIR/$tdir/f1
11100         can2=$(do_facet $SINGLEMDS \
11101                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11102                awk '/ldlm_cancel/ {print $2}')
11103         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11104                awk '/ldlm_bl_callback/ {print $2}')
11105         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11106         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11107         lru_resize_enable mdc
11108         lru_resize_enable osc
11109 }
11110 run_test 120b "Early Lock Cancel: create test"
11111
11112 test_120c() {
11113         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11114         remote_mds_nodsh && skip "remote MDS with nodsh"
11115         test_mkdir -i0 -c1 $DIR/$tdir
11116         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11117                 skip "no early lock cancel on server"
11118
11119         lru_resize_disable mdc
11120         lru_resize_disable osc
11121         test_mkdir -i0 -c1 $DIR/$tdir/d1
11122         test_mkdir -i0 -c1 $DIR/$tdir/d2
11123         touch $DIR/$tdir/d1/f1
11124         cancel_lru_locks mdc
11125         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
11126         can1=$(do_facet mds1 \
11127                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11128                awk '/ldlm_cancel/ {print $2}')
11129         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11130                awk '/ldlm_bl_callback/ {print $2}')
11131         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
11132         can2=$(do_facet mds1 \
11133                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11134                awk '/ldlm_cancel/ {print $2}')
11135         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11136                awk '/ldlm_bl_callback/ {print $2}')
11137         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11138         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11139         lru_resize_enable mdc
11140         lru_resize_enable osc
11141 }
11142 run_test 120c "Early Lock Cancel: link test"
11143
11144 test_120d() {
11145         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11146         remote_mds_nodsh && skip "remote MDS with nodsh"
11147         test_mkdir -i0 -c1 $DIR/$tdir
11148         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11149                 skip_env "no early lock cancel on server"
11150
11151         lru_resize_disable mdc
11152         lru_resize_disable osc
11153         touch $DIR/$tdir
11154         cancel_lru_locks mdc
11155         stat $DIR/$tdir > /dev/null
11156         can1=$(do_facet mds1 \
11157                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11158                awk '/ldlm_cancel/ {print $2}')
11159         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11160                awk '/ldlm_bl_callback/ {print $2}')
11161         chmod a+x $DIR/$tdir
11162         can2=$(do_facet mds1 \
11163                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11164                awk '/ldlm_cancel/ {print $2}')
11165         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11166                awk '/ldlm_bl_callback/ {print $2}')
11167         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11168         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11169         lru_resize_enable mdc
11170         lru_resize_enable osc
11171 }
11172 run_test 120d "Early Lock Cancel: setattr test"
11173
11174 test_120e() {
11175         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11176         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11177                 skip_env "no early lock cancel on server"
11178         remote_mds_nodsh && skip "remote MDS with nodsh"
11179
11180         local dlmtrace_set=false
11181
11182         test_mkdir -i0 -c1 $DIR/$tdir
11183         lru_resize_disable mdc
11184         lru_resize_disable osc
11185         ! $LCTL get_param debug | grep -q dlmtrace &&
11186                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
11187         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
11188         cancel_lru_locks mdc
11189         cancel_lru_locks osc
11190         dd if=$DIR/$tdir/f1 of=/dev/null
11191         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
11192         # XXX client can not do early lock cancel of OST lock
11193         # during unlink (LU-4206), so cancel osc lock now.
11194         sleep 2
11195         cancel_lru_locks osc
11196         can1=$(do_facet mds1 \
11197                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11198                awk '/ldlm_cancel/ {print $2}')
11199         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11200                awk '/ldlm_bl_callback/ {print $2}')
11201         unlink $DIR/$tdir/f1
11202         sleep 5
11203         can2=$(do_facet mds1 \
11204                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11205                awk '/ldlm_cancel/ {print $2}')
11206         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11207                awk '/ldlm_bl_callback/ {print $2}')
11208         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
11209                 $LCTL dk $TMP/cancel.debug.txt
11210         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
11211                 $LCTL dk $TMP/blocking.debug.txt
11212         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
11213         lru_resize_enable mdc
11214         lru_resize_enable osc
11215 }
11216 run_test 120e "Early Lock Cancel: unlink test"
11217
11218 test_120f() {
11219         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11220         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11221                 skip_env "no early lock cancel on server"
11222         remote_mds_nodsh && skip "remote MDS with nodsh"
11223
11224         test_mkdir -i0 -c1 $DIR/$tdir
11225         lru_resize_disable mdc
11226         lru_resize_disable osc
11227         test_mkdir -i0 -c1 $DIR/$tdir/d1
11228         test_mkdir -i0 -c1 $DIR/$tdir/d2
11229         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
11230         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
11231         cancel_lru_locks mdc
11232         cancel_lru_locks osc
11233         dd if=$DIR/$tdir/d1/f1 of=/dev/null
11234         dd if=$DIR/$tdir/d2/f2 of=/dev/null
11235         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
11236         # XXX client can not do early lock cancel of OST lock
11237         # during rename (LU-4206), so cancel osc lock now.
11238         sleep 2
11239         cancel_lru_locks osc
11240         can1=$(do_facet mds1 \
11241                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11242                awk '/ldlm_cancel/ {print $2}')
11243         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11244                awk '/ldlm_bl_callback/ {print $2}')
11245         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
11246         sleep 5
11247         can2=$(do_facet mds1 \
11248                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11249                awk '/ldlm_cancel/ {print $2}')
11250         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11251                awk '/ldlm_bl_callback/ {print $2}')
11252         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11253         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11254         lru_resize_enable mdc
11255         lru_resize_enable osc
11256 }
11257 run_test 120f "Early Lock Cancel: rename test"
11258
11259 test_120g() {
11260         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11261         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11262                 skip_env "no early lock cancel on server"
11263         remote_mds_nodsh && skip "remote MDS with nodsh"
11264
11265         lru_resize_disable mdc
11266         lru_resize_disable osc
11267         count=10000
11268         echo create $count files
11269         test_mkdir $DIR/$tdir
11270         cancel_lru_locks mdc
11271         cancel_lru_locks osc
11272         t0=$(date +%s)
11273
11274         can0=$(do_facet $SINGLEMDS \
11275                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11276                awk '/ldlm_cancel/ {print $2}')
11277         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11278                awk '/ldlm_bl_callback/ {print $2}')
11279         createmany -o $DIR/$tdir/f $count
11280         sync
11281         can1=$(do_facet $SINGLEMDS \
11282                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11283                awk '/ldlm_cancel/ {print $2}')
11284         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11285                awk '/ldlm_bl_callback/ {print $2}')
11286         t1=$(date +%s)
11287         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
11288         echo rm $count files
11289         rm -r $DIR/$tdir
11290         sync
11291         can2=$(do_facet $SINGLEMDS \
11292                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11293                awk '/ldlm_cancel/ {print $2}')
11294         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11295                awk '/ldlm_bl_callback/ {print $2}')
11296         t2=$(date +%s)
11297         echo total: $count removes in $((t2-t1))
11298         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
11299         sleep 2
11300         # wait for commitment of removal
11301         lru_resize_enable mdc
11302         lru_resize_enable osc
11303 }
11304 run_test 120g "Early Lock Cancel: performance test"
11305
11306 test_121() { #bug #10589
11307         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11308
11309         rm -rf $DIR/$tfile
11310         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
11311 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
11312         lctl set_param fail_loc=0x310
11313         cancel_lru_locks osc > /dev/null
11314         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
11315         lctl set_param fail_loc=0
11316         [[ $reads -eq $writes ]] ||
11317                 error "read $reads blocks, must be $writes blocks"
11318 }
11319 run_test 121 "read cancel race ========="
11320
11321 test_123a() { # was test 123, statahead(bug 11401)
11322         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11323
11324         SLOWOK=0
11325         if ! grep -q "processor.*: 1" /proc/cpuinfo; then
11326                 log "testing UP system. Performance may be lower than expected."
11327                 SLOWOK=1
11328         fi
11329
11330         rm -rf $DIR/$tdir
11331         test_mkdir $DIR/$tdir
11332         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
11333         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
11334         MULT=10
11335         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
11336                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
11337
11338                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
11339                 lctl set_param -n llite.*.statahead_max 0
11340                 lctl get_param llite.*.statahead_max
11341                 cancel_lru_locks mdc
11342                 cancel_lru_locks osc
11343                 stime=`date +%s`
11344                 time ls -l $DIR/$tdir | wc -l
11345                 etime=`date +%s`
11346                 delta=$((etime - stime))
11347                 log "ls $i files without statahead: $delta sec"
11348                 lctl set_param llite.*.statahead_max=$max
11349
11350                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
11351                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
11352                 cancel_lru_locks mdc
11353                 cancel_lru_locks osc
11354                 stime=`date +%s`
11355                 time ls -l $DIR/$tdir | wc -l
11356                 etime=`date +%s`
11357                 delta_sa=$((etime - stime))
11358                 log "ls $i files with statahead: $delta_sa sec"
11359                 lctl get_param -n llite.*.statahead_stats
11360                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
11361
11362                 [[ $swrong -lt $ewrong ]] &&
11363                         log "statahead was stopped, maybe too many locks held!"
11364                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
11365
11366                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
11367                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
11368                     lctl set_param -n llite.*.statahead_max 0
11369                     lctl get_param llite.*.statahead_max
11370                     cancel_lru_locks mdc
11371                     cancel_lru_locks osc
11372                     stime=`date +%s`
11373                     time ls -l $DIR/$tdir | wc -l
11374                     etime=`date +%s`
11375                     delta=$((etime - stime))
11376                     log "ls $i files again without statahead: $delta sec"
11377                     lctl set_param llite.*.statahead_max=$max
11378                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
11379                         if [  $SLOWOK -eq 0 ]; then
11380                                 error "ls $i files is slower with statahead!"
11381                         else
11382                                 log "ls $i files is slower with statahead!"
11383                         fi
11384                         break
11385                     fi
11386                 fi
11387
11388                 [ $delta -gt 20 ] && break
11389                 [ $delta -gt 8 ] && MULT=$((50 / delta))
11390                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
11391         done
11392         log "ls done"
11393
11394         stime=`date +%s`
11395         rm -r $DIR/$tdir
11396         sync
11397         etime=`date +%s`
11398         delta=$((etime - stime))
11399         log "rm -r $DIR/$tdir/: $delta seconds"
11400         log "rm done"
11401         lctl get_param -n llite.*.statahead_stats
11402 }
11403 run_test 123a "verify statahead work"
11404
11405 test_123b () { # statahead(bug 15027)
11406         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11407
11408         test_mkdir $DIR/$tdir
11409         createmany -o $DIR/$tdir/$tfile-%d 1000
11410
11411         cancel_lru_locks mdc
11412         cancel_lru_locks osc
11413
11414 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
11415         lctl set_param fail_loc=0x80000803
11416         ls -lR $DIR/$tdir > /dev/null
11417         log "ls done"
11418         lctl set_param fail_loc=0x0
11419         lctl get_param -n llite.*.statahead_stats
11420         rm -r $DIR/$tdir
11421         sync
11422
11423 }
11424 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
11425
11426 test_123c() {
11427         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
11428
11429         test_mkdir -i 0 -c 1 $DIR/$tdir.0
11430         test_mkdir -i 1 -c 1 $DIR/$tdir.1
11431         touch $DIR/$tdir.1/{1..3}
11432         mv $DIR/$tdir.1/{1..3} $DIR/$tdir.0
11433
11434         remount_client $MOUNT
11435
11436         $MULTIOP $DIR/$tdir.0 Q
11437
11438         # let statahead to complete
11439         ls -l $DIR/$tdir.0 > /dev/null
11440
11441         testid=$(echo $TESTNAME | tr '_' ' ')
11442         dmesg | tac | sed "/$testid/,$ d" | grep "Can not initialize inode" &&
11443                 error "statahead warning" || true
11444 }
11445 run_test 123c "Can not initialize inode warning on DNE statahead"
11446
11447 test_124a() {
11448         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11449         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
11450                 skip_env "no lru resize on server"
11451
11452         local NR=2000
11453
11454         test_mkdir $DIR/$tdir
11455
11456         log "create $NR files at $DIR/$tdir"
11457         createmany -o $DIR/$tdir/f $NR ||
11458                 error "failed to create $NR files in $DIR/$tdir"
11459
11460         cancel_lru_locks mdc
11461         ls -l $DIR/$tdir > /dev/null
11462
11463         local NSDIR=""
11464         local LRU_SIZE=0
11465         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
11466                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
11467                 LRU_SIZE=$($LCTL get_param -n $PARAM)
11468                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
11469                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
11470                         log "NSDIR=$NSDIR"
11471                         log "NS=$(basename $NSDIR)"
11472                         break
11473                 fi
11474         done
11475
11476         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
11477                 skip "Not enough cached locks created!"
11478         fi
11479         log "LRU=$LRU_SIZE"
11480
11481         local SLEEP=30
11482
11483         # We know that lru resize allows one client to hold $LIMIT locks
11484         # for 10h. After that locks begin to be killed by client.
11485         local MAX_HRS=10
11486         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
11487         log "LIMIT=$LIMIT"
11488         if [ $LIMIT -lt $LRU_SIZE ]; then
11489                 skip "Limit is too small $LIMIT"
11490         fi
11491
11492         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
11493         # killing locks. Some time was spent for creating locks. This means
11494         # that up to the moment of sleep finish we must have killed some of
11495         # them (10-100 locks). This depends on how fast ther were created.
11496         # Many of them were touched in almost the same moment and thus will
11497         # be killed in groups.
11498         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
11499
11500         # Use $LRU_SIZE_B here to take into account real number of locks
11501         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
11502         local LRU_SIZE_B=$LRU_SIZE
11503         log "LVF=$LVF"
11504         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
11505         log "OLD_LVF=$OLD_LVF"
11506         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
11507
11508         # Let's make sure that we really have some margin. Client checks
11509         # cached locks every 10 sec.
11510         SLEEP=$((SLEEP+20))
11511         log "Sleep ${SLEEP} sec"
11512         local SEC=0
11513         while ((SEC<$SLEEP)); do
11514                 echo -n "..."
11515                 sleep 5
11516                 SEC=$((SEC+5))
11517                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
11518                 echo -n "$LRU_SIZE"
11519         done
11520         echo ""
11521         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
11522         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
11523
11524         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
11525                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
11526                 unlinkmany $DIR/$tdir/f $NR
11527                 return
11528         }
11529
11530         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
11531         log "unlink $NR files at $DIR/$tdir"
11532         unlinkmany $DIR/$tdir/f $NR
11533 }
11534 run_test 124a "lru resize ======================================="
11535
11536 get_max_pool_limit()
11537 {
11538         local limit=$($LCTL get_param \
11539                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
11540         local max=0
11541         for l in $limit; do
11542                 if [[ $l -gt $max ]]; then
11543                         max=$l
11544                 fi
11545         done
11546         echo $max
11547 }
11548
11549 test_124b() {
11550         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11551         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
11552                 skip_env "no lru resize on server"
11553
11554         LIMIT=$(get_max_pool_limit)
11555
11556         NR=$(($(default_lru_size)*20))
11557         if [[ $NR -gt $LIMIT ]]; then
11558                 log "Limit lock number by $LIMIT locks"
11559                 NR=$LIMIT
11560         fi
11561
11562         IFree=$(mdsrate_inodes_available)
11563         if [ $IFree -lt $NR ]; then
11564                 log "Limit lock number by $IFree inodes"
11565                 NR=$IFree
11566         fi
11567
11568         lru_resize_disable mdc
11569         test_mkdir -p $DIR/$tdir/disable_lru_resize
11570
11571         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
11572         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
11573         cancel_lru_locks mdc
11574         stime=`date +%s`
11575         PID=""
11576         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
11577         PID="$PID $!"
11578         sleep 2
11579         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
11580         PID="$PID $!"
11581         sleep 2
11582         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
11583         PID="$PID $!"
11584         wait $PID
11585         etime=`date +%s`
11586         nolruresize_delta=$((etime-stime))
11587         log "ls -la time: $nolruresize_delta seconds"
11588         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
11589         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
11590
11591         lru_resize_enable mdc
11592         test_mkdir -p $DIR/$tdir/enable_lru_resize
11593
11594         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
11595         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
11596         cancel_lru_locks mdc
11597         stime=`date +%s`
11598         PID=""
11599         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
11600         PID="$PID $!"
11601         sleep 2
11602         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
11603         PID="$PID $!"
11604         sleep 2
11605         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
11606         PID="$PID $!"
11607         wait $PID
11608         etime=`date +%s`
11609         lruresize_delta=$((etime-stime))
11610         log "ls -la time: $lruresize_delta seconds"
11611         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
11612
11613         if [ $lruresize_delta -gt $nolruresize_delta ]; then
11614                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
11615         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
11616                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
11617         else
11618                 log "lru resize performs the same with no lru resize"
11619         fi
11620         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
11621 }
11622 run_test 124b "lru resize (performance test) ======================="
11623
11624 test_124c() {
11625         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11626         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
11627                 skip_env "no lru resize on server"
11628
11629         # cache ununsed locks on client
11630         local nr=100
11631         cancel_lru_locks mdc
11632         test_mkdir $DIR/$tdir
11633         createmany -o $DIR/$tdir/f $nr ||
11634                 error "failed to create $nr files in $DIR/$tdir"
11635         ls -l $DIR/$tdir > /dev/null
11636
11637         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
11638         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
11639         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
11640         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
11641         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
11642
11643         # set lru_max_age to 1 sec
11644         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
11645         echo "sleep $((recalc_p * 2)) seconds..."
11646         sleep $((recalc_p * 2))
11647
11648         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
11649         # restore lru_max_age
11650         $LCTL set_param -n $nsdir.lru_max_age $max_age
11651         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
11652         unlinkmany $DIR/$tdir/f $nr
11653 }
11654 run_test 124c "LRUR cancel very aged locks"
11655
11656 test_124d() {
11657         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11658         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
11659                 skip_env "no lru resize on server"
11660
11661         # cache ununsed locks on client
11662         local nr=100
11663
11664         lru_resize_disable mdc
11665         stack_trap "lru_resize_enable mdc" EXIT
11666
11667         cancel_lru_locks mdc
11668
11669         # asynchronous object destroy at MDT could cause bl ast to client
11670         test_mkdir $DIR/$tdir
11671         createmany -o $DIR/$tdir/f $nr ||
11672                 error "failed to create $nr files in $DIR/$tdir"
11673         stack_trap "unlinkmany $DIR/$tdir/f $nr" EXIT
11674
11675         ls -l $DIR/$tdir > /dev/null
11676
11677         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
11678         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
11679         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
11680         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
11681
11682         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
11683
11684         # set lru_max_age to 1 sec
11685         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
11686         stack_trap "$LCTL set_param -n $nsdir.lru_max_age $max_age" EXIT
11687
11688         echo "sleep $((recalc_p * 2)) seconds..."
11689         sleep $((recalc_p * 2))
11690
11691         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
11692
11693         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
11694 }
11695 run_test 124d "cancel very aged locks if lru-resize diasbaled"
11696
11697 test_125() { # 13358
11698         $LCTL get_param -n llite.*.client_type | grep -q local ||
11699                 skip "must run as local client"
11700         $LCTL get_param -n mdc.*-mdc-*.connect_flags | grep -q acl ||
11701                 skip_env "must have acl enabled"
11702         [ -z "$(which setfacl)" ] && skip_env "must have setfacl tool"
11703
11704         test_mkdir $DIR/$tdir
11705         $LFS setstripe -S 65536 -c -1 $DIR/$tdir || error "setstripe failed"
11706         setfacl -R -m u:bin:rwx $DIR/$tdir || error "setfacl $DIR/$tdir failed"
11707         ls -ld $DIR/$tdir || error "cannot access $DIR/$tdir"
11708 }
11709 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
11710
11711 test_126() { # bug 12829/13455
11712         $GSS && skip_env "must run as gss disabled"
11713         $LCTL get_param -n llite.*.client_type | grep -q local ||
11714                 skip "must run as local client"
11715         [ "$UID" != 0 ] && skip "must run as root, not UID $UID"
11716
11717         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
11718         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
11719         rm -f $DIR/$tfile
11720         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
11721 }
11722 run_test 126 "check that the fsgid provided by the client is taken into account"
11723
11724 test_127a() { # bug 15521
11725         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11726         local name count samp unit min max sum sumsq
11727
11728         $LFS setstripe -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
11729         echo "stats before reset"
11730         $LCTL get_param osc.*.stats
11731         $LCTL set_param osc.*.stats=0
11732         local fsize=$((2048 * 1024))
11733
11734         dd if=/dev/zero of=$DIR/$tfile bs=$fsize count=1
11735         cancel_lru_locks osc
11736         dd if=$DIR/$tfile of=/dev/null bs=$fsize
11737
11738         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/$tfile.tmp
11739         stack_trap "rm -f $TMP/$tfile.tmp"
11740         while read name count samp unit min max sum sumsq; do
11741                 echo "got name=$name count=$count unit=$unit min=$min max=$max"
11742                 [ ! $min ] && error "Missing min value for $name proc entry"
11743                 eval $name=$count || error "Wrong proc format"
11744
11745                 case $name in
11746                 read_bytes|write_bytes)
11747                         [[ "$unit" =~ "bytes" ]] ||
11748                                 error "unit is not 'bytes': $unit"
11749                         (( $min >= 4096 )) || error "min is too small: $min"
11750                         (( $min <= $fsize )) || error "min is too big: $min"
11751                         (( $max >= 4096 )) || error "max is too small: $max"
11752                         (( $max <= $fsize )) || error "max is too big: $max"
11753                         (( $sum == $fsize )) || error "sum is wrong: $sum"
11754                         (( $sumsq >= ($fsize / 4096) * (4096 * 4096) )) ||
11755                                 error "sumsquare is too small: $sumsq"
11756                         (( $sumsq <= $fsize * $fsize )) ||
11757                                 error "sumsquare is too big: $sumsq"
11758                         ;;
11759                 ost_read|ost_write)
11760                         [[ "$unit" =~ "usec" ]] ||
11761                                 error "unit is not 'usec': $unit"
11762                         ;;
11763                 *)      ;;
11764                 esac
11765         done < $DIR/$tfile.tmp
11766
11767         #check that we actually got some stats
11768         [ "$read_bytes" ] || error "Missing read_bytes stats"
11769         [ "$write_bytes" ] || error "Missing write_bytes stats"
11770         [ "$read_bytes" != 0 ] || error "no read done"
11771         [ "$write_bytes" != 0 ] || error "no write done"
11772 }
11773 run_test 127a "verify the client stats are sane"
11774
11775 test_127b() { # bug LU-333
11776         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11777         local name count samp unit min max sum sumsq
11778
11779         echo "stats before reset"
11780         $LCTL get_param llite.*.stats
11781         $LCTL set_param llite.*.stats=0
11782
11783         # perform 2 reads and writes so MAX is different from SUM.
11784         dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE count=1
11785         dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE count=1
11786         cancel_lru_locks osc
11787         dd if=$DIR/$tfile of=/dev/null bs=$PAGE_SIZE count=1
11788         dd if=$DIR/$tfile of=/dev/null bs=$PAGE_SIZE count=1
11789
11790         $LCTL get_param llite.*.stats | grep samples > $TMP/$tfile.tmp
11791         stack_trap "rm -f $TMP/$tfile.tmp"
11792         while read name count samp unit min max sum sumsq; do
11793                 echo "got name=$name count=$count unit=$unit min=$min max=$max"
11794                 eval $name=$count || error "Wrong proc format"
11795
11796                 case $name in
11797                 read_bytes|write_bytes)
11798                         [[ "$unit" =~ "bytes" ]] ||
11799                                 error "unit is not 'bytes': $unit"
11800                         (( $count == 2 )) || error "count is not 2: $count"
11801                         (( $min == $PAGE_SIZE )) ||
11802                                 error "min is not $PAGE_SIZE: $min"
11803                         (( $max == $PAGE_SIZE )) ||
11804                                 error "max is not $PAGE_SIZE: $max"
11805                         (( $sum == $PAGE_SIZE * 2 )) ||
11806                                 error "sum is not $((PAGE_SIZE * 2)): $sum"
11807                         ;;
11808                 read|write)
11809                         [[ "$unit" =~ "usec" ]] ||
11810                                 error "unit is not 'usec': $unit"
11811                         ;;
11812                 *)      ;;
11813                 esac
11814         done < $TMP/$tfile.tmp
11815
11816         #check that we actually got some stats
11817         [ "$read_bytes" ] || error "Missing read_bytes stats"
11818         [ "$write_bytes" ] || error "Missing write_bytes stats"
11819         [ "$read_bytes" != 0 ] || error "no read done"
11820         [ "$write_bytes" != 0 ] || error "no write done"
11821 }
11822 run_test 127b "verify the llite client stats are sane"
11823
11824 test_127c() { # LU-12394
11825         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
11826         local size
11827         local bsize
11828         local reads
11829         local writes
11830         local count
11831
11832         $LCTL set_param llite.*.extents_stats=1
11833         stack_trap "$LCTL set_param llite.*.extents_stats=0" EXIT
11834
11835         # Use two stripes so there is enough space in default config
11836         $LFS setstripe -c 2 $DIR/$tfile
11837
11838         # Extent stats start at 0-4K and go in power of two buckets
11839         # LL_HIST_START = 12 --> 2^12 = 4K
11840         # We do 3K*2^i, so 3K, 6K, 12K, 24K... hitting each bucket.
11841         # We do not do buckets larger than 64 MiB to avoid ENOSPC issues on
11842         # small configs
11843         for size in 3K 6K 12K 24K 48K 96K 192K 384K 768K 1536K 3M 6M 12M 24M 48M;
11844                 do
11845                 # Write and read, 2x each, second time at a non-zero offset
11846                 dd if=/dev/zero of=$DIR/$tfile bs=$size count=1
11847                 dd if=/dev/zero of=$DIR/$tfile bs=$size count=1 seek=10
11848                 dd if=$DIR/$tfile of=/dev/null bs=$size count=1
11849                 dd if=$DIR/$tfile of=/dev/null bs=$size count=1 seek=10
11850                 rm -f $DIR/$tfile
11851         done
11852
11853         $LCTL get_param llite.*.extents_stats
11854
11855         count=2
11856         for bsize in 4K 8K 16K 32K 64K 128K 256K 512K 1M 2M 4M 8M 16M 32M 64M;
11857                 do
11858                 local bucket=$($LCTL get_param -n llite.*.extents_stats |
11859                                 grep -m 1 $bsize)
11860                 reads=$(echo $bucket | awk '{print $5}')
11861                 writes=$(echo $bucket | awk '{print $9}')
11862                 [ "$reads" -eq $count ] ||
11863                         error "$reads reads in < $bsize bucket, expect $count"
11864                 [ "$writes" -eq $count ] ||
11865                         error "$writes writes in < $bsize bucket, expect $count"
11866         done
11867
11868         # Test mmap write and read
11869         $LCTL set_param llite.*.extents_stats=c
11870         size=512
11871         dd if=/dev/zero of=$DIR/$tfile bs=${size}K count=1
11872         $MULTIOP $DIR/$tfile OSMRUc || error "$MULTIOP $DIR/$tfile failed"
11873         $MULTIOP $DIR/$tfile OSMWUc || error "$MULTIOP $DIR/$tfile failed"
11874
11875         $LCTL get_param llite.*.extents_stats
11876
11877         count=$(((size*1024) / PAGE_SIZE))
11878
11879         bsize=$((2 * PAGE_SIZE / 1024))K
11880
11881         bucket=$($LCTL get_param -n llite.*.extents_stats |
11882                         grep -m 1 $bsize)
11883         reads=$(echo $bucket | awk '{print $5}')
11884         writes=$(echo $bucket | awk '{print $9}')
11885         # mmap writes fault in the page first, creating an additonal read
11886         [ "$reads" -eq $((2 * count)) ] ||
11887                 error "$reads reads in < $bsize bucket, expect $count"
11888         [ "$writes" -eq $count ] ||
11889                 error "$writes writes in < $bsize bucket, expect $count"
11890 }
11891 run_test 127c "test llite extent stats with regular & mmap i/o"
11892
11893 test_128() { # bug 15212
11894         touch $DIR/$tfile
11895         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
11896                 find $DIR/$tfile
11897                 find $DIR/$tfile
11898         EOF
11899
11900         result=$(grep error $TMP/$tfile.log)
11901         rm -f $DIR/$tfile $TMP/$tfile.log
11902         [ -z "$result" ] ||
11903                 error "consecutive find's under interactive lfs failed"
11904 }
11905 run_test 128 "interactive lfs for 2 consecutive find's"
11906
11907 set_dir_limits () {
11908         local mntdev
11909         local canondev
11910         local node
11911
11912         local ldproc=/proc/fs/ldiskfs
11913         local facets=$(get_facets MDS)
11914
11915         for facet in ${facets//,/ }; do
11916                 canondev=$(ldiskfs_canon \
11917                            *.$(convert_facet2label $facet).mntdev $facet)
11918                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
11919                         ldproc=/sys/fs/ldiskfs
11920                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
11921                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
11922         done
11923 }
11924
11925 check_mds_dmesg() {
11926         local facets=$(get_facets MDS)
11927         for facet in ${facets//,/ }; do
11928                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
11929         done
11930         return 1
11931 }
11932
11933 test_129() {
11934         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11935         [[ $MDS1_VERSION -ge $(version_code 2.5.56) ]] ||
11936                 skip "Need MDS version with at least 2.5.56"
11937         if [ "$mds1_FSTYPE" != ldiskfs ]; then
11938                 skip_env "ldiskfs only test"
11939         fi
11940         remote_mds_nodsh && skip "remote MDS with nodsh"
11941
11942         local ENOSPC=28
11943         local EFBIG=27
11944         local has_warning=false
11945
11946         rm -rf $DIR/$tdir
11947         mkdir -p $DIR/$tdir
11948
11949         # block size of mds1
11950         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
11951         set_dir_limits $maxsize $maxsize
11952         local dirsize=$(stat -c%s "$DIR/$tdir")
11953         local nfiles=0
11954         while [[ $dirsize -le $maxsize ]]; do
11955                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
11956                 rc=$?
11957                 if ! $has_warning; then
11958                         check_mds_dmesg '"is approaching"' && has_warning=true
11959                 fi
11960                 # check two errors:
11961                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
11962                 # EFBIG for previous versions included in ldiskfs series
11963                 if [ $rc -eq $EFBIG ] || [ $rc -eq $ENOSPC ]; then
11964                         set_dir_limits 0 0
11965                         echo "return code $rc received as expected"
11966
11967                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
11968                                 error_exit "create failed w/o dir size limit"
11969
11970                         check_mds_dmesg '"has reached"' ||
11971                                 error_exit "reached message should be output"
11972
11973                         [ $has_warning = "false" ] &&
11974                                 error_exit "warning message should be output"
11975
11976                         dirsize=$(stat -c%s "$DIR/$tdir")
11977
11978                         [[ $dirsize -ge $maxsize ]] && return 0
11979                         error_exit "current dir size $dirsize, " \
11980                                    "previous limit $maxsize"
11981                 elif [ $rc -ne 0 ]; then
11982                         set_dir_limits 0 0
11983                         error_exit "return $rc received instead of expected " \
11984                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
11985                 fi
11986                 nfiles=$((nfiles + 1))
11987                 dirsize=$(stat -c%s "$DIR/$tdir")
11988         done
11989
11990         set_dir_limits 0 0
11991         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
11992 }
11993 run_test 129 "test directory size limit ========================"
11994
11995 OLDIFS="$IFS"
11996 cleanup_130() {
11997         trap 0
11998         IFS="$OLDIFS"
11999 }
12000
12001 test_130a() {
12002         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12003         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
12004
12005         trap cleanup_130 EXIT RETURN
12006
12007         local fm_file=$DIR/$tfile
12008         $LFS setstripe -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
12009         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
12010                 error "dd failed for $fm_file"
12011
12012         # LU-1795: test filefrag/FIEMAP once, even if unsupported
12013         filefrag -ves $fm_file
12014         RC=$?
12015         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12016                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12017         [ $RC != 0 ] && error "filefrag $fm_file failed"
12018
12019         filefrag_op=$(filefrag -ve -k $fm_file |
12020                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12021         lun=$($LFS getstripe -i $fm_file)
12022
12023         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
12024         IFS=$'\n'
12025         tot_len=0
12026         for line in $filefrag_op
12027         do
12028                 frag_lun=`echo $line | cut -d: -f5`
12029                 ext_len=`echo $line | cut -d: -f4`
12030                 if (( $frag_lun != $lun )); then
12031                         cleanup_130
12032                         error "FIEMAP on 1-stripe file($fm_file) failed"
12033                         return
12034                 fi
12035                 (( tot_len += ext_len ))
12036         done
12037
12038         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
12039                 cleanup_130
12040                 error "FIEMAP on 1-stripe file($fm_file) failed;"
12041                 return
12042         fi
12043
12044         cleanup_130
12045
12046         echo "FIEMAP on single striped file succeeded"
12047 }
12048 run_test 130a "FIEMAP (1-stripe file)"
12049
12050 test_130b() {
12051         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
12052
12053         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12054         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
12055
12056         trap cleanup_130 EXIT RETURN
12057
12058         local fm_file=$DIR/$tfile
12059         $LFS setstripe -S 65536 -c $OSTCOUNT $fm_file ||
12060                         error "setstripe on $fm_file"
12061         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12062                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12063
12064         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
12065                 error "dd failed on $fm_file"
12066
12067         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12068         filefrag_op=$(filefrag -ve -k $fm_file |
12069                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12070
12071         last_lun=$(echo $filefrag_op | cut -d: -f5 |
12072                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12073
12074         IFS=$'\n'
12075         tot_len=0
12076         num_luns=1
12077         for line in $filefrag_op
12078         do
12079                 frag_lun=$(echo $line | cut -d: -f5 |
12080                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12081                 ext_len=$(echo $line | cut -d: -f4)
12082                 if (( $frag_lun != $last_lun )); then
12083                         if (( tot_len != 1024 )); then
12084                                 cleanup_130
12085                                 error "FIEMAP on $fm_file failed; returned " \
12086                                 "len $tot_len for OST $last_lun instead of 1024"
12087                                 return
12088                         else
12089                                 (( num_luns += 1 ))
12090                                 tot_len=0
12091                         fi
12092                 fi
12093                 (( tot_len += ext_len ))
12094                 last_lun=$frag_lun
12095         done
12096         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
12097                 cleanup_130
12098                 error "FIEMAP on $fm_file failed; returned wrong number of " \
12099                         "luns or wrong len for OST $last_lun"
12100                 return
12101         fi
12102
12103         cleanup_130
12104
12105         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
12106 }
12107 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
12108
12109 test_130c() {
12110         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
12111
12112         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12113         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
12114
12115         trap cleanup_130 EXIT RETURN
12116
12117         local fm_file=$DIR/$tfile
12118         $LFS setstripe -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
12119         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12120                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12121
12122         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
12123                         error "dd failed on $fm_file"
12124
12125         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12126         filefrag_op=$(filefrag -ve -k $fm_file |
12127                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12128
12129         last_lun=$(echo $filefrag_op | cut -d: -f5 |
12130                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12131
12132         IFS=$'\n'
12133         tot_len=0
12134         num_luns=1
12135         for line in $filefrag_op
12136         do
12137                 frag_lun=$(echo $line | cut -d: -f5 |
12138                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12139                 ext_len=$(echo $line | cut -d: -f4)
12140                 if (( $frag_lun != $last_lun )); then
12141                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
12142                         if (( logical != 512 )); then
12143                                 cleanup_130
12144                                 error "FIEMAP on $fm_file failed; returned " \
12145                                 "logical start for lun $logical instead of 512"
12146                                 return
12147                         fi
12148                         if (( tot_len != 512 )); then
12149                                 cleanup_130
12150                                 error "FIEMAP on $fm_file failed; returned " \
12151                                 "len $tot_len for OST $last_lun instead of 1024"
12152                                 return
12153                         else
12154                                 (( num_luns += 1 ))
12155                                 tot_len=0
12156                         fi
12157                 fi
12158                 (( tot_len += ext_len ))
12159                 last_lun=$frag_lun
12160         done
12161         if (( num_luns != 2 || tot_len != 512 )); then
12162                 cleanup_130
12163                 error "FIEMAP on $fm_file failed; returned wrong number of " \
12164                         "luns or wrong len for OST $last_lun"
12165                 return
12166         fi
12167
12168         cleanup_130
12169
12170         echo "FIEMAP on 2-stripe file with hole succeeded"
12171 }
12172 run_test 130c "FIEMAP (2-stripe file with hole)"
12173
12174 test_130d() {
12175         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs"
12176
12177         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12178         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
12179
12180         trap cleanup_130 EXIT RETURN
12181
12182         local fm_file=$DIR/$tfile
12183         $LFS setstripe -S 65536 -c $OSTCOUNT $fm_file ||
12184                         error "setstripe on $fm_file"
12185         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12186                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12187
12188         local actual_stripe_count=$($LFS getstripe -c $fm_file)
12189         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripe_count ||
12190                 error "dd failed on $fm_file"
12191
12192         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12193         filefrag_op=$(filefrag -ve -k $fm_file |
12194                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12195
12196         last_lun=$(echo $filefrag_op | cut -d: -f5 |
12197                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12198
12199         IFS=$'\n'
12200         tot_len=0
12201         num_luns=1
12202         for line in $filefrag_op
12203         do
12204                 frag_lun=$(echo $line | cut -d: -f5 |
12205                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12206                 ext_len=$(echo $line | cut -d: -f4)
12207                 if (( $frag_lun != $last_lun )); then
12208                         if (( tot_len != 1024 )); then
12209                                 cleanup_130
12210                                 error "FIEMAP on $fm_file failed; returned " \
12211                                 "len $tot_len for OST $last_lun instead of 1024"
12212                                 return
12213                         else
12214                                 (( num_luns += 1 ))
12215                                 tot_len=0
12216                         fi
12217                 fi
12218                 (( tot_len += ext_len ))
12219                 last_lun=$frag_lun
12220         done
12221         if (( num_luns != actual_stripe_count || tot_len != 1024 )); then
12222                 cleanup_130
12223                 error "FIEMAP on $fm_file failed; returned wrong number of " \
12224                         "luns or wrong len for OST $last_lun"
12225                 return
12226         fi
12227
12228         cleanup_130
12229
12230         echo "FIEMAP on N-stripe file succeeded"
12231 }
12232 run_test 130d "FIEMAP (N-stripe file)"
12233
12234 test_130e() {
12235         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
12236
12237         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12238         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
12239
12240         trap cleanup_130 EXIT RETURN
12241
12242         local fm_file=$DIR/$tfile
12243         $LFS setstripe -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
12244         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12245                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12246
12247         NUM_BLKS=512
12248         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
12249         for ((i = 0; i < $NUM_BLKS; i++))
12250         do
12251                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
12252         done
12253
12254         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12255         filefrag_op=$(filefrag -ve -k $fm_file |
12256                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12257
12258         last_lun=$(echo $filefrag_op | cut -d: -f5 |
12259                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12260
12261         IFS=$'\n'
12262         tot_len=0
12263         num_luns=1
12264         for line in $filefrag_op
12265         do
12266                 frag_lun=$(echo $line | cut -d: -f5 |
12267                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12268                 ext_len=$(echo $line | cut -d: -f4)
12269                 if (( $frag_lun != $last_lun )); then
12270                         if (( tot_len != $EXPECTED_LEN )); then
12271                                 cleanup_130
12272                                 error "FIEMAP on $fm_file failed; returned " \
12273                                 "len $tot_len for OST $last_lun instead " \
12274                                 "of $EXPECTED_LEN"
12275                                 return
12276                         else
12277                                 (( num_luns += 1 ))
12278                                 tot_len=0
12279                         fi
12280                 fi
12281                 (( tot_len += ext_len ))
12282                 last_lun=$frag_lun
12283         done
12284         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
12285                 cleanup_130
12286                 error "FIEMAP on $fm_file failed; returned wrong number " \
12287                         "of luns or wrong len for OST $last_lun"
12288                 return
12289         fi
12290
12291         cleanup_130
12292
12293         echo "FIEMAP with continuation calls succeeded"
12294 }
12295 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
12296
12297 test_130f() {
12298         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12299         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
12300
12301         local fm_file=$DIR/$tfile
12302         $MULTIOP $fm_file oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T33554432c ||
12303                 error "multiop create with lov_delay_create on $fm_file"
12304
12305         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12306         filefrag_extents=$(filefrag -vek $fm_file |
12307                            awk '/extents? found/ { print $2 }')
12308         if [[ "$filefrag_extents" != "0" ]]; then
12309                 error "FIEMAP on $fm_file failed; " \
12310                       "returned $filefrag_extents expected 0"
12311         fi
12312
12313         rm -f $fm_file
12314 }
12315 run_test 130f "FIEMAP (unstriped file)"
12316
12317 # Test for writev/readv
12318 test_131a() {
12319         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
12320                 error "writev test failed"
12321         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
12322                 error "readv failed"
12323         rm -f $DIR/$tfile
12324 }
12325 run_test 131a "test iov's crossing stripe boundary for writev/readv"
12326
12327 test_131b() {
12328         local fsize=$((524288 + 1048576 + 1572864))
12329         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
12330                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
12331                         error "append writev test failed"
12332
12333         ((fsize += 1572864 + 1048576))
12334         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
12335                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
12336                         error "append writev test failed"
12337         rm -f $DIR/$tfile
12338 }
12339 run_test 131b "test append writev"
12340
12341 test_131c() {
12342         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
12343         error "NOT PASS"
12344 }
12345 run_test 131c "test read/write on file w/o objects"
12346
12347 test_131d() {
12348         rwv -f $DIR/$tfile -w -n 1 1572864
12349         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
12350         if [ "$NOB" != 1572864 ]; then
12351                 error "Short read filed: read $NOB bytes instead of 1572864"
12352         fi
12353         rm -f $DIR/$tfile
12354 }
12355 run_test 131d "test short read"
12356
12357 test_131e() {
12358         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
12359         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
12360         error "read hitting hole failed"
12361         rm -f $DIR/$tfile
12362 }
12363 run_test 131e "test read hitting hole"
12364
12365 check_stats() {
12366         local facet=$1
12367         local op=$2
12368         local want=${3:-0}
12369         local res
12370
12371         case $facet in
12372         mds*) res=$(do_facet $facet \
12373                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
12374                  ;;
12375         ost*) res=$(do_facet $facet \
12376                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
12377                  ;;
12378         *) error "Wrong facet '$facet'" ;;
12379         esac
12380         [ "$res" ] || error "The counter for $op on $facet was not incremented"
12381         # if the argument $3 is zero, it means any stat increment is ok.
12382         if [[ $want -gt 0 ]]; then
12383                 local count=$(echo $res | awk '{ print $2 }')
12384                 [[ $count -ne $want ]] &&
12385                         error "The $op counter on $facet is $count, not $want"
12386         fi
12387 }
12388
12389 test_133a() {
12390         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12391         remote_ost_nodsh && skip "remote OST with nodsh"
12392         remote_mds_nodsh && skip "remote MDS with nodsh"
12393         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
12394                 skip_env "MDS doesn't support rename stats"
12395
12396         local testdir=$DIR/${tdir}/stats_testdir
12397
12398         mkdir -p $DIR/${tdir}
12399
12400         # clear stats.
12401         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12402         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
12403
12404         # verify mdt stats first.
12405         mkdir ${testdir} || error "mkdir failed"
12406         check_stats $SINGLEMDS "mkdir" 1
12407         touch ${testdir}/${tfile} || error "touch failed"
12408         check_stats $SINGLEMDS "open" 1
12409         check_stats $SINGLEMDS "close" 1
12410         [ $MDS1_VERSION -ge $(version_code 2.8.54) ] && {
12411                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
12412                 check_stats $SINGLEMDS "mknod" 2
12413         }
12414         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
12415         check_stats $SINGLEMDS "unlink" 1
12416         rm -f ${testdir}/${tfile} || error "file remove failed"
12417         check_stats $SINGLEMDS "unlink" 2
12418
12419         # remove working dir and check mdt stats again.
12420         rmdir ${testdir} || error "rmdir failed"
12421         check_stats $SINGLEMDS "rmdir" 1
12422
12423         local testdir1=$DIR/${tdir}/stats_testdir1
12424         mkdir -p ${testdir}
12425         mkdir -p ${testdir1}
12426         touch ${testdir1}/test1
12427         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
12428         check_stats $SINGLEMDS "crossdir_rename" 1
12429
12430         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
12431         check_stats $SINGLEMDS "samedir_rename" 1
12432
12433         rm -rf $DIR/${tdir}
12434 }
12435 run_test 133a "Verifying MDT stats ========================================"
12436
12437 test_133b() {
12438         local res
12439
12440         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12441         remote_ost_nodsh && skip "remote OST with nodsh"
12442         remote_mds_nodsh && skip "remote MDS with nodsh"
12443
12444         local testdir=$DIR/${tdir}/stats_testdir
12445
12446         mkdir -p ${testdir} || error "mkdir failed"
12447         touch ${testdir}/${tfile} || error "touch failed"
12448         cancel_lru_locks mdc
12449
12450         # clear stats.
12451         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12452         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
12453
12454         # extra mdt stats verification.
12455         chmod 444 ${testdir}/${tfile} || error "chmod failed"
12456         check_stats $SINGLEMDS "setattr" 1
12457         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12458         if [ $MDS1_VERSION -ne $(version_code 2.2.0) ]
12459         then            # LU-1740
12460                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
12461                 check_stats $SINGLEMDS "getattr" 1
12462         fi
12463         rm -rf $DIR/${tdir}
12464
12465         # when DNE is enabled, MDT uses STATFS RPC to ping other targets
12466         # so the check below is not reliable
12467         [ $MDSCOUNT -eq 1 ] || return 0
12468
12469         # Sleep to avoid a cached response.
12470         #define OBD_STATFS_CACHE_SECONDS 1
12471         sleep 2
12472         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12473         do_facet ost1 $LCTL set_param obdfilter.*.exports.*.stats=clear
12474         $LFS df || error "lfs failed"
12475         check_stats $SINGLEMDS "statfs" 1
12476
12477         # check aggregated statfs (LU-10018)
12478         [ $MDS1_VERSION -lt $(version_code 2.11.54) ] &&
12479                 return 0
12480         [ $CLIENT_VERSION -lt $(version_code 2.11.54) ] &&
12481                 return 0
12482         sleep 2
12483         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12484         do_facet ost1 $LCTL set_param obdfilter.*.exports.*.stats=clear
12485         df $DIR
12486         check_stats $SINGLEMDS "statfs" 1
12487
12488         # We want to check that the client didn't send OST_STATFS to
12489         # ost1 but the MDT also uses OST_STATFS for precreate. So some
12490         # extra care is needed here.
12491         if remote_mds; then
12492                 local nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
12493                 local param="obdfilter.$FSNAME-OST0000.exports.'$nid'.stats"
12494
12495                 res=$(do_facet ost1 $LCTL get_param $param | grep statfs)
12496                 [ "$res" ] && error "OST got STATFS"
12497         fi
12498
12499         return 0
12500 }
12501 run_test 133b "Verifying extra MDT stats =================================="
12502
12503 test_133c() {
12504         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12505         remote_ost_nodsh && skip "remote OST with nodsh"
12506         remote_mds_nodsh && skip "remote MDS with nodsh"
12507
12508         local testdir=$DIR/$tdir/stats_testdir
12509
12510         test_mkdir -p $testdir
12511
12512         # verify obdfilter stats.
12513         $LFS setstripe -c 1 -i 0 $testdir/$tfile
12514         sync
12515         cancel_lru_locks osc
12516         wait_delete_completed
12517
12518         # clear stats.
12519         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12520         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
12521
12522         dd if=/dev/zero of=$testdir/$tfile conv=notrunc bs=512k count=1 ||
12523                 error "dd failed"
12524         sync
12525         cancel_lru_locks osc
12526         check_stats ost1 "write" 1
12527
12528         dd if=$testdir/$tfile of=/dev/null bs=1k count=1 || error "dd failed"
12529         check_stats ost1 "read" 1
12530
12531         > $testdir/$tfile || error "truncate failed"
12532         check_stats ost1 "punch" 1
12533
12534         rm -f $testdir/$tfile || error "file remove failed"
12535         wait_delete_completed
12536         check_stats ost1 "destroy" 1
12537
12538         rm -rf $DIR/$tdir
12539 }
12540 run_test 133c "Verifying OST stats ========================================"
12541
12542 order_2() {
12543         local value=$1
12544         local orig=$value
12545         local order=1
12546
12547         while [ $value -ge 2 ]; do
12548                 order=$((order*2))
12549                 value=$((value/2))
12550         done
12551
12552         if [ $orig -gt $order ]; then
12553                 order=$((order*2))
12554         fi
12555         echo $order
12556 }
12557
12558 size_in_KMGT() {
12559     local value=$1
12560     local size=('K' 'M' 'G' 'T');
12561     local i=0
12562     local size_string=$value
12563
12564     while [ $value -ge 1024 ]; do
12565         if [ $i -gt 3 ]; then
12566             #T is the biggest unit we get here, if that is bigger,
12567             #just return XXXT
12568             size_string=${value}T
12569             break
12570         fi
12571         value=$((value >> 10))
12572         if [ $value -lt 1024 ]; then
12573             size_string=${value}${size[$i]}
12574             break
12575         fi
12576         i=$((i + 1))
12577     done
12578
12579     echo $size_string
12580 }
12581
12582 get_rename_size() {
12583         local size=$1
12584         local context=${2:-.}
12585         local sample=$(do_facet $SINGLEMDS $LCTL \
12586                 get_param mdt.$FSNAME-MDT0000.rename_stats |
12587                 grep -A1 $context |
12588                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
12589         echo $sample
12590 }
12591
12592 test_133d() {
12593         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12594         remote_ost_nodsh && skip "remote OST with nodsh"
12595         remote_mds_nodsh && skip "remote MDS with nodsh"
12596         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
12597                 skip_env "MDS doesn't support rename stats"
12598
12599         local testdir1=$DIR/${tdir}/stats_testdir1
12600         local testdir2=$DIR/${tdir}/stats_testdir2
12601         mkdir -p $DIR/${tdir}
12602
12603         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
12604
12605         lfs mkdir -i 0 -c 1 ${testdir1} || error "mkdir failed"
12606         lfs mkdir -i 0 -c 1 ${testdir2} || error "mkdir failed"
12607
12608         createmany -o $testdir1/test 512 || error "createmany failed"
12609
12610         # check samedir rename size
12611         mv ${testdir1}/test0 ${testdir1}/test_0
12612
12613         local testdir1_size=$(ls -l $DIR/${tdir} |
12614                 awk '/stats_testdir1/ {print $5}')
12615         local testdir2_size=$(ls -l $DIR/${tdir} |
12616                 awk '/stats_testdir2/ {print $5}')
12617
12618         testdir1_size=$(order_2 $testdir1_size)
12619         testdir2_size=$(order_2 $testdir2_size)
12620
12621         testdir1_size=$(size_in_KMGT $testdir1_size)
12622         testdir2_size=$(size_in_KMGT $testdir2_size)
12623
12624         echo "source rename dir size: ${testdir1_size}"
12625         echo "target rename dir size: ${testdir2_size}"
12626
12627         local cmd="do_facet $SINGLEMDS $LCTL "
12628         cmd+="get_param mdt.$FSNAME-MDT0000.rename_stats"
12629
12630         eval $cmd || error "$cmd failed"
12631         local samedir=$($cmd | grep 'same_dir')
12632         local same_sample=$(get_rename_size $testdir1_size)
12633         [ -z "$samedir" ] && error "samedir_rename_size count error"
12634         [[ $same_sample -eq 1 ]] ||
12635                 error "samedir_rename_size error $same_sample"
12636         echo "Check same dir rename stats success"
12637
12638         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
12639
12640         # check crossdir rename size
12641         mv ${testdir1}/test_0 ${testdir2}/test_0
12642
12643         testdir1_size=$(ls -l $DIR/${tdir} |
12644                 awk '/stats_testdir1/ {print $5}')
12645         testdir2_size=$(ls -l $DIR/${tdir} |
12646                 awk '/stats_testdir2/ {print $5}')
12647
12648         testdir1_size=$(order_2 $testdir1_size)
12649         testdir2_size=$(order_2 $testdir2_size)
12650
12651         testdir1_size=$(size_in_KMGT $testdir1_size)
12652         testdir2_size=$(size_in_KMGT $testdir2_size)
12653
12654         echo "source rename dir size: ${testdir1_size}"
12655         echo "target rename dir size: ${testdir2_size}"
12656
12657         eval $cmd || error "$cmd failed"
12658         local crossdir=$($cmd | grep 'crossdir')
12659         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
12660         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
12661         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
12662         [[ $src_sample -eq 1 ]] ||
12663                 error "crossdir_rename_size error $src_sample"
12664         [[ $tgt_sample -eq 1 ]] ||
12665                 error "crossdir_rename_size error $tgt_sample"
12666         echo "Check cross dir rename stats success"
12667         rm -rf $DIR/${tdir}
12668 }
12669 run_test 133d "Verifying rename_stats ========================================"
12670
12671 test_133e() {
12672         remote_mds_nodsh && skip "remote MDS with nodsh"
12673         remote_ost_nodsh && skip "remote OST with nodsh"
12674         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12675
12676         local testdir=$DIR/${tdir}/stats_testdir
12677         local ctr f0 f1 bs=32768 count=42 sum
12678
12679         mkdir -p ${testdir} || error "mkdir failed"
12680
12681         $LFS setstripe -c 1 -i 0 ${testdir}/${tfile}
12682
12683         for ctr in {write,read}_bytes; do
12684                 sync
12685                 cancel_lru_locks osc
12686
12687                 do_facet ost1 $LCTL set_param -n \
12688                         "obdfilter.*.exports.clear=clear"
12689
12690                 if [ $ctr = write_bytes ]; then
12691                         f0=/dev/zero
12692                         f1=${testdir}/${tfile}
12693                 else
12694                         f0=${testdir}/${tfile}
12695                         f1=/dev/null
12696                 fi
12697
12698                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
12699                         error "dd failed"
12700                 sync
12701                 cancel_lru_locks osc
12702
12703                 sum=$(do_facet ost1 $LCTL get_param \
12704                         "obdfilter.*.exports.*.stats" |
12705                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
12706                                 $1 == ctr { sum += $7 }
12707                                 END { printf("%0.0f", sum) }')
12708
12709                 if ((sum != bs * count)); then
12710                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
12711                 fi
12712         done
12713
12714         rm -rf $DIR/${tdir}
12715 }
12716 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
12717
12718 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
12719
12720 # Some versions of find (4.5.11, 4.5.14) included in CentOS 7.3-7.5 do
12721 # not honor the -ignore_readdir_race option correctly. So we call
12722 # error_ignore() rather than error() in these cases. See LU-11152.
12723 error_133() {
12724         if (find --version; do_facet mds1 find --version) |
12725                 grep -q '\b4\.5\.1[1-4]\b'; then
12726                 error_ignore LU-11152 "$@"
12727         else
12728                 error "$@"
12729         fi
12730 }
12731
12732 test_133f() {
12733         # First without trusting modes.
12734         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
12735         echo "proc_dirs='$proc_dirs'"
12736         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
12737         find $proc_dirs -exec cat '{}' \; &> /dev/null
12738
12739         # Second verifying readability.
12740         $LCTL get_param -R '*' &> /dev/null
12741
12742         # Verifing writability with badarea_io.
12743         find $proc_dirs \
12744                 -ignore_readdir_race \
12745                 -type f \
12746                 -not -name force_lbug \
12747                 -not -name changelog_mask \
12748                 -exec badarea_io '{}' \; ||
12749                         error_133 "find $proc_dirs failed"
12750 }
12751 run_test 133f "Check reads/writes of client lustre proc files with bad area io"
12752
12753 test_133g() {
12754         remote_mds_nodsh && skip "remote MDS with nodsh"
12755         remote_ost_nodsh && skip "remote OST with nodsh"
12756
12757         local facet
12758         for facet in mds1 ost1; do
12759                 local facet_ver=$(lustre_version_code $facet)
12760                 if [ $facet_ver -ge $(version_code 2.7.65) ]; then
12761                         do_facet $facet "$LCTL get_param -R '*'" &> /dev/null
12762                 else
12763                         log "$facet: too old lustre for get_param -R"
12764                 fi
12765                 if [ $facet_ver -ge $(version_code 2.5.54) ]; then
12766                         do_facet $facet "$LCTL list_param -R '*' | grep '=' |
12767                                 tr -d = | egrep -v 'force_lbug|changelog_mask' |
12768                                 xargs badarea_io" ||
12769                                         error_133 "$facet badarea_io failed"
12770                 else
12771                         skip_noexit "$facet: too old lustre for get_param -R"
12772                 fi
12773         done
12774
12775         # remount the FS in case writes/reads /proc break the FS
12776         cleanup || error "failed to unmount"
12777         setup || error "failed to setup"
12778         true
12779 }
12780 run_test 133g "Check reads/writes of server lustre proc files with bad area io"
12781
12782 test_133h() {
12783         remote_mds_nodsh && skip "remote MDS with nodsh"
12784         remote_ost_nodsh && skip "remote OST with nodsh"
12785         [[ $MDS1_VERSION -lt $(version_code 2.9.54) ]] &&
12786                 skip "Need MDS version at least 2.9.54"
12787
12788         local facet
12789
12790         for facet in client mds1 ost1; do
12791                 local facet_proc_dirs=$(do_facet $facet \
12792                                         \\\ls -d $proc_regexp 2> /dev/null)
12793                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
12794                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
12795                 # Get the list of files that are missing the terminating newline
12796                 local missing=($(do_facet $facet \
12797                         find ${facet_proc_dirs} -type f \|              \
12798                                 while read F\; do                       \
12799                                         awk -v FS='\v' -v RS='\v\v'     \
12800                                         "'END { if(NR>0 &&              \
12801                                         \\\$NF !~ /.*\\\n\$/)           \
12802                                                 print FILENAME}'"       \
12803                                         '\$F'\;                         \
12804                                 done 2>/dev/null))
12805                 [ ${#missing[*]} -eq 0 ] ||
12806                         error "files do not end with newline: ${missing[*]}"
12807         done
12808 }
12809 run_test 133h "Proc files should end with newlines"
12810
12811 test_134a() {
12812         remote_mds_nodsh && skip "remote MDS with nodsh"
12813         [[ $MDS1_VERSION -lt $(version_code 2.7.54) ]] &&
12814                 skip "Need MDS version at least 2.7.54"
12815
12816         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
12817         cancel_lru_locks mdc
12818
12819         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
12820         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
12821         [ $unused -eq 0 ] || error "$unused locks are not cleared"
12822
12823         local nr=1000
12824         createmany -o $DIR/$tdir/f $nr ||
12825                 error "failed to create $nr files in $DIR/$tdir"
12826         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
12827
12828         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
12829         do_facet mds1 $LCTL set_param fail_loc=0x327
12830         do_facet mds1 $LCTL set_param fail_val=500
12831         touch $DIR/$tdir/m
12832
12833         echo "sleep 10 seconds ..."
12834         sleep 10
12835         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
12836
12837         do_facet mds1 $LCTL set_param fail_loc=0
12838         do_facet mds1 $LCTL set_param fail_val=0
12839         [ $lck_cnt -lt $unused ] ||
12840                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
12841
12842         rm $DIR/$tdir/m
12843         unlinkmany $DIR/$tdir/f $nr
12844 }
12845 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
12846
12847 test_134b() {
12848         remote_mds_nodsh && skip "remote MDS with nodsh"
12849         [[ $MDS1_VERSION -lt $(version_code 2.7.54) ]] &&
12850                 skip "Need MDS version at least 2.7.54"
12851
12852         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
12853         cancel_lru_locks mdc
12854
12855         local low_wm=$(do_facet mds1 $LCTL get_param -n \
12856                         ldlm.lock_reclaim_threshold_mb)
12857         # disable reclaim temporarily
12858         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
12859
12860         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
12861         do_facet mds1 $LCTL set_param fail_loc=0x328
12862         do_facet mds1 $LCTL set_param fail_val=500
12863
12864         $LCTL set_param debug=+trace
12865
12866         local nr=600
12867         createmany -o $DIR/$tdir/f $nr &
12868         local create_pid=$!
12869
12870         echo "Sleep $TIMEOUT seconds ..."
12871         sleep $TIMEOUT
12872         if ! ps -p $create_pid  > /dev/null 2>&1; then
12873                 do_facet mds1 $LCTL set_param fail_loc=0
12874                 do_facet mds1 $LCTL set_param fail_val=0
12875                 do_facet mds1 $LCTL set_param \
12876                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
12877                 error "createmany finished incorrectly!"
12878         fi
12879         do_facet mds1 $LCTL set_param fail_loc=0
12880         do_facet mds1 $LCTL set_param fail_val=0
12881         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
12882         wait $create_pid || return 1
12883
12884         unlinkmany $DIR/$tdir/f $nr
12885 }
12886 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
12887
12888 test_135() {
12889         remote_mds_nodsh && skip "remote MDS with nodsh"
12890         [[ $MDS1_VERSION -lt $(version_code 2.13.50) ]] &&
12891                 skip "Need MDS version at least 2.13.50"
12892         local fname
12893
12894         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
12895
12896 #define OBD_FAIL_PLAIN_RECORDS 0x1319
12897         #set only one record at plain llog
12898         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1319 fail_val=1
12899
12900         #fill already existed plain llog each 64767
12901         #wrapping whole catalog
12902         createmany -o -u $DIR/$tdir/$tfile- $((64767 * 1))
12903
12904         createmany -o $DIR/$tdir/$tfile_ 64700
12905         for (( i = 0; i < 64700; i = i + 2 ))
12906         do
12907                 rm $DIR/$tdir/$tfile_$i &
12908                 rm $DIR/$tdir/$tfile_$((i + 1)) &
12909                 local pid=$!
12910                 wait $pid
12911         done
12912
12913         #waiting osp synchronization
12914         wait_delete_completed
12915 }
12916 run_test 135 "Race catalog processing"
12917
12918 test_136() {
12919         remote_mds_nodsh && skip "remote MDS with nodsh"
12920         [[ $MDS1_VERSION -lt $(version_code 2.13.50) ]] &&
12921                 skip "Need MDS version at least 2.13.50"
12922         local fname
12923
12924         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
12925         $LFS setstripe -c 1 -i 0 $DIR/$tdir || error "failed to set striping"
12926         #set only one record at plain llog
12927 #define OBD_FAIL_CATALOG_FULL_CHECK                0x131a
12928         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x131a fail_val=1
12929
12930         #fill already existed 2 plain llogs each 64767
12931         #wrapping whole catalog
12932         createmany -o -u $DIR/$tdir/$tfile- $((64767 * 1))
12933         createmany -o -u $DIR/$tdir/$tfile- $((64767 * 3 / 2))
12934         wait_delete_completed
12935
12936         createmany -o $DIR/$tdir/$tfile_ 10
12937         sleep 25
12938
12939         do_facet $SINGLEMDS $LCTL set_param fail_val=3
12940         for (( i = 0; i < 10; i = i + 3 ))
12941         do
12942                 rm $DIR/$tdir/$tfile_$i &
12943                 rm $DIR/$tdir/$tfile_$((i + 1)) &
12944                 local pid=$!
12945                 wait $pid
12946                 sleep 7
12947                 rm $DIR/$tdir/$tfile_$((i + 2)) &
12948         done
12949
12950         #waiting osp synchronization
12951         wait_delete_completed
12952 }
12953 run_test 136 "Race catalog processing 2"
12954
12955 test_140() { #bug-17379
12956         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12957
12958         test_mkdir $DIR/$tdir
12959         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
12960         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
12961
12962         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
12963         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
12964         local i=0
12965         while i=$((i + 1)); do
12966                 test_mkdir $i
12967                 cd $i || error "Changing to $i"
12968                 ln -s ../stat stat || error "Creating stat symlink"
12969                 # Read the symlink until ELOOP present,
12970                 # not LBUGing the system is considered success,
12971                 # we didn't overrun the stack.
12972                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
12973                 if [ $ret -ne 0 ]; then
12974                         if [ $ret -eq 40 ]; then
12975                                 break  # -ELOOP
12976                         else
12977                                 error "Open stat symlink"
12978                                         return
12979                         fi
12980                 fi
12981         done
12982         i=$((i - 1))
12983         echo "The symlink depth = $i"
12984         [ $i -eq 5 ] || [ $i -eq 7 ] || [ $i -eq 8 ] || [ $i -eq 40 ] ||
12985                 error "Invalid symlink depth"
12986
12987         # Test recursive symlink
12988         ln -s symlink_self symlink_self
12989         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
12990         echo "open symlink_self returns $ret"
12991         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
12992 }
12993 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
12994
12995 test_150() {
12996         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12997
12998         local TF="$TMP/$tfile"
12999
13000         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
13001         cp $TF $DIR/$tfile
13002         cancel_lru_locks $OSC
13003         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
13004         remount_client $MOUNT
13005         df -P $MOUNT
13006         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
13007
13008         $TRUNCATE $TF 6000
13009         $TRUNCATE $DIR/$tfile 6000
13010         cancel_lru_locks $OSC
13011         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
13012
13013         echo "12345" >>$TF
13014         echo "12345" >>$DIR/$tfile
13015         cancel_lru_locks $OSC
13016         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
13017
13018         echo "12345" >>$TF
13019         echo "12345" >>$DIR/$tfile
13020         cancel_lru_locks $OSC
13021         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
13022
13023         rm -f $TF
13024         true
13025 }
13026 run_test 150 "truncate/append tests"
13027
13028 #LU-2902 roc_hit was not able to read all values from lproc
13029 function roc_hit_init() {
13030         local list=$(comma_list $(osts_nodes))
13031         local dir=$DIR/$tdir-check
13032         local file=$dir/$tfile
13033         local BEFORE
13034         local AFTER
13035         local idx
13036
13037         test_mkdir $dir
13038         #use setstripe to do a write to every ost
13039         for i in $(seq 0 $((OSTCOUNT-1))); do
13040                 $LFS setstripe -c 1 -i $i $dir || error "$LFS setstripe $file failed"
13041                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
13042                 idx=$(printf %04x $i)
13043                 BEFORE=$(get_osd_param $list *OST*$idx stats |
13044                         awk '$1 == "cache_access" {sum += $7}
13045                                 END { printf("%0.0f", sum) }')
13046
13047                 cancel_lru_locks osc
13048                 cat $file >/dev/null
13049
13050                 AFTER=$(get_osd_param $list *OST*$idx stats |
13051                         awk '$1 == "cache_access" {sum += $7}
13052                                 END { printf("%0.0f", sum) }')
13053
13054                 echo BEFORE:$BEFORE AFTER:$AFTER
13055                 if ! let "AFTER - BEFORE == 4"; then
13056                         rm -rf $dir
13057                         error "roc_hit is not safe to use"
13058                 fi
13059                 rm $file
13060         done
13061
13062         rm -rf $dir
13063 }
13064
13065 function roc_hit() {
13066         local list=$(comma_list $(osts_nodes))
13067         echo $(get_osd_param $list '' stats |
13068                 awk '$1 == "cache_hit" {sum += $7}
13069                         END { printf("%0.0f", sum) }')
13070 }
13071
13072 function set_cache() {
13073         local on=1
13074
13075         if [ "$2" == "off" ]; then
13076                 on=0;
13077         fi
13078         local list=$(comma_list $(osts_nodes))
13079         set_osd_param $list '' $1_cache_enable $on
13080
13081         cancel_lru_locks osc
13082 }
13083
13084 test_151() {
13085         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13086         remote_ost_nodsh && skip "remote OST with nodsh"
13087
13088         local CPAGES=3
13089         local list=$(comma_list $(osts_nodes))
13090
13091         # check whether obdfilter is cache capable at all
13092         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
13093                 skip "not cache-capable obdfilter"
13094         fi
13095
13096         # check cache is enabled on all obdfilters
13097         if get_osd_param $list '' read_cache_enable | grep 0; then
13098                 skip "oss cache is disabled"
13099         fi
13100
13101         set_osd_param $list '' writethrough_cache_enable 1
13102
13103         # check write cache is enabled on all obdfilters
13104         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
13105                 skip "oss write cache is NOT enabled"
13106         fi
13107
13108         roc_hit_init
13109
13110         #define OBD_FAIL_OBD_NO_LRU  0x609
13111         do_nodes $list $LCTL set_param fail_loc=0x609
13112
13113         # pages should be in the case right after write
13114         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
13115                 error "dd failed"
13116
13117         local BEFORE=$(roc_hit)
13118         cancel_lru_locks osc
13119         cat $DIR/$tfile >/dev/null
13120         local AFTER=$(roc_hit)
13121
13122         do_nodes $list $LCTL set_param fail_loc=0
13123
13124         if ! let "AFTER - BEFORE == CPAGES"; then
13125                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
13126         fi
13127
13128         cancel_lru_locks osc
13129         # invalidates OST cache
13130         do_nodes $list "echo 1 > /proc/sys/vm/drop_caches"
13131         set_osd_param $list '' read_cache_enable 0
13132         cat $DIR/$tfile >/dev/null
13133
13134         # now data shouldn't be found in the cache
13135         BEFORE=$(roc_hit)
13136         cancel_lru_locks osc
13137         cat $DIR/$tfile >/dev/null
13138         AFTER=$(roc_hit)
13139         if let "AFTER - BEFORE != 0"; then
13140                 error "IN CACHE: before: $BEFORE, after: $AFTER"
13141         fi
13142
13143         set_osd_param $list '' read_cache_enable 1
13144         rm -f $DIR/$tfile
13145 }
13146 run_test 151 "test cache on oss and controls ==============================="
13147
13148 test_152() {
13149         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13150
13151         local TF="$TMP/$tfile"
13152
13153         # simulate ENOMEM during write
13154 #define OBD_FAIL_OST_NOMEM      0x226
13155         lctl set_param fail_loc=0x80000226
13156         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
13157         cp $TF $DIR/$tfile
13158         sync || error "sync failed"
13159         lctl set_param fail_loc=0
13160
13161         # discard client's cache
13162         cancel_lru_locks osc
13163
13164         # simulate ENOMEM during read
13165         lctl set_param fail_loc=0x80000226
13166         cmp $TF $DIR/$tfile || error "cmp failed"
13167         lctl set_param fail_loc=0
13168
13169         rm -f $TF
13170 }
13171 run_test 152 "test read/write with enomem ============================"
13172
13173 test_153() {
13174         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
13175 }
13176 run_test 153 "test if fdatasync does not crash ======================="
13177
13178 dot_lustre_fid_permission_check() {
13179         local fid=$1
13180         local ffid=$MOUNT/.lustre/fid/$fid
13181         local test_dir=$2
13182
13183         echo "stat fid $fid"
13184         stat $ffid > /dev/null || error "stat $ffid failed."
13185         echo "touch fid $fid"
13186         touch $ffid || error "touch $ffid failed."
13187         echo "write to fid $fid"
13188         cat /etc/hosts > $ffid || error "write $ffid failed."
13189         echo "read fid $fid"
13190         diff /etc/hosts $ffid || error "read $ffid failed."
13191         echo "append write to fid $fid"
13192         cat /etc/hosts >> $ffid || error "append write $ffid failed."
13193         echo "rename fid $fid"
13194         mv $ffid $test_dir/$tfile.1 &&
13195                 error "rename $ffid to $tfile.1 should fail."
13196         touch $test_dir/$tfile.1
13197         mv $test_dir/$tfile.1 $ffid &&
13198                 error "rename $tfile.1 to $ffid should fail."
13199         rm -f $test_dir/$tfile.1
13200         echo "truncate fid $fid"
13201         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
13202         echo "link fid $fid"
13203         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
13204         if [[ $($LCTL get_param -n mdc.*-mdc-*.connect_flags) =~ acl ]]; then
13205                 echo "setfacl fid $fid"
13206                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
13207                 echo "getfacl fid $fid"
13208                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
13209         fi
13210         echo "unlink fid $fid"
13211         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
13212         echo "mknod fid $fid"
13213         mknod $ffid c 1 3 && error "mknod $ffid should fail."
13214
13215         fid=[0xf00000400:0x1:0x0]
13216         ffid=$MOUNT/.lustre/fid/$fid
13217
13218         echo "stat non-exist fid $fid"
13219         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
13220         echo "write to non-exist fid $fid"
13221         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
13222         echo "link new fid $fid"
13223         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
13224
13225         mkdir -p $test_dir/$tdir
13226         touch $test_dir/$tdir/$tfile
13227         fid=$($LFS path2fid $test_dir/$tdir)
13228         rc=$?
13229         [ $rc -ne 0 ] &&
13230                 error "error: could not get fid for $test_dir/$dir/$tfile."
13231
13232         ffid=$MOUNT/.lustre/fid/$fid
13233
13234         echo "ls $fid"
13235         ls $ffid > /dev/null || error "ls $ffid failed."
13236         echo "touch $fid/$tfile.1"
13237         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
13238
13239         echo "touch $MOUNT/.lustre/fid/$tfile"
13240         touch $MOUNT/.lustre/fid/$tfile && \
13241                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
13242
13243         echo "setxattr to $MOUNT/.lustre/fid"
13244         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
13245
13246         echo "listxattr for $MOUNT/.lustre/fid"
13247         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
13248
13249         echo "delxattr from $MOUNT/.lustre/fid"
13250         setfattr -x trusted.name1 $MOUNT/.lustre/fid
13251
13252         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
13253         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
13254                 error "touch invalid fid should fail."
13255
13256         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
13257         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
13258                 error "touch non-normal fid should fail."
13259
13260         echo "rename $tdir to $MOUNT/.lustre/fid"
13261         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
13262                 error "rename to $MOUNT/.lustre/fid should fail."
13263
13264         if [ $MDS1_VERSION -ge $(version_code 2.3.51) ]
13265         then            # LU-3547
13266                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
13267                 local new_obf_mode=777
13268
13269                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
13270                 chmod $new_obf_mode $DIR/.lustre/fid ||
13271                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
13272
13273                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
13274                 [ $obf_mode -eq $new_obf_mode ] ||
13275                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
13276
13277                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
13278                 chmod $old_obf_mode $DIR/.lustre/fid ||
13279                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
13280         fi
13281
13282         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
13283         fid=$($LFS path2fid $test_dir/$tfile-2)
13284
13285         if [ $MDS1_VERSION -ge $(version_code 2.6.50) ]
13286         then # LU-5424
13287                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
13288                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
13289                         error "create lov data thru .lustre failed"
13290         fi
13291         echo "cp /etc/passwd $test_dir/$tfile-2"
13292         cp /etc/passwd $test_dir/$tfile-2 ||
13293                 error "copy to $test_dir/$tfile-2 failed."
13294         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
13295         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
13296                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
13297
13298         rm -rf $test_dir/tfile.lnk
13299         rm -rf $test_dir/$tfile-2
13300 }
13301
13302 test_154A() {
13303         [[ $MDS1_VERSION -lt $(version_code 2.4.1) ]] &&
13304                 skip "Need MDS version at least 2.4.1"
13305
13306         local tf=$DIR/$tfile
13307         touch $tf
13308
13309         local fid=$($LFS path2fid $tf)
13310         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
13311
13312         # check that we get the same pathname back
13313         local found=$($LFS fid2path $MOUNT "$fid")
13314         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
13315         [ "$found" == "$tf" ] ||
13316                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
13317 }
13318 run_test 154A "lfs path2fid and fid2path basic checks"
13319
13320 test_154B() {
13321         [[ $MDS1_VERSION -lt $(version_code 2.4.1) ]] &&
13322                 skip "Need MDS version at least 2.4.1"
13323
13324         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
13325         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
13326         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
13327         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
13328
13329         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
13330         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
13331
13332         # check that we get the same pathname
13333         echo "PFID: $PFID, name: $name"
13334         local FOUND=$($LFS fid2path $MOUNT "$PFID")
13335         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
13336         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
13337                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
13338
13339         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
13340 }
13341 run_test 154B "verify the ll_decode_linkea tool"
13342
13343 test_154a() {
13344         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13345         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13346         [[ $MDS1_VERSION -ge $(version_code 2.2.51) ]] ||
13347                 skip "Need MDS version at least 2.2.51"
13348         [ -z "$(which setfacl)" ] && skip_env "must have setfacl tool"
13349
13350         cp /etc/hosts $DIR/$tfile
13351
13352         fid=$($LFS path2fid $DIR/$tfile)
13353         rc=$?
13354         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
13355
13356         dot_lustre_fid_permission_check "$fid" $DIR ||
13357                 error "dot lustre permission check $fid failed"
13358
13359         ls -a $MOUNT | grep "\.lustre" && error ".lustre should not be listed"
13360
13361         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
13362
13363         touch $MOUNT/.lustre/file &&
13364                 error "creation is not allowed under .lustre"
13365
13366         mkdir $MOUNT/.lustre/dir &&
13367                 error "mkdir is not allowed under .lustre"
13368
13369         rm -rf $DIR/$tfile
13370 }
13371 run_test 154a "Open-by-FID"
13372
13373 test_154b() {
13374         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13375         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13376         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
13377         [[ $MDS1_VERSION -ge $(version_code 2.2.51) ]] ||
13378                 skip "Need MDS version at least 2.2.51"
13379
13380         local remote_dir=$DIR/$tdir/remote_dir
13381         local MDTIDX=1
13382         local rc=0
13383
13384         mkdir -p $DIR/$tdir
13385         $LFS mkdir -i $MDTIDX $remote_dir ||
13386                 error "create remote directory failed"
13387
13388         cp /etc/hosts $remote_dir/$tfile
13389
13390         fid=$($LFS path2fid $remote_dir/$tfile)
13391         rc=$?
13392         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
13393
13394         dot_lustre_fid_permission_check "$fid" $remote_dir ||
13395                 error "dot lustre permission check $fid failed"
13396         rm -rf $DIR/$tdir
13397 }
13398 run_test 154b "Open-by-FID for remote directory"
13399
13400 test_154c() {
13401         [[ $MDS1_VERSION -lt $(version_code 2.4.1) ]] &&
13402                 skip "Need MDS version at least 2.4.1"
13403
13404         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
13405         local FID1=$($LFS path2fid $DIR/$tfile.1)
13406         local FID2=$($LFS path2fid $DIR/$tfile.2)
13407         local FID3=$($LFS path2fid $DIR/$tfile.3)
13408
13409         local N=1
13410         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
13411                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
13412                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
13413                 local want=FID$N
13414                 [ "$FID" = "${!want}" ] ||
13415                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
13416                 N=$((N + 1))
13417         done
13418
13419         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
13420         do
13421                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
13422                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
13423                 N=$((N + 1))
13424         done
13425 }
13426 run_test 154c "lfs path2fid and fid2path multiple arguments"
13427
13428 test_154d() {
13429         remote_mds_nodsh && skip "remote MDS with nodsh"
13430         [[ $MDS1_VERSION -lt $(version_code 2.5.53) ]] &&
13431                 skip "Need MDS version at least 2.5.53"
13432
13433         if remote_mds; then
13434                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
13435         else
13436                 nid="0@lo"
13437         fi
13438         local proc_ofile="mdt.*.exports.'$nid'.open_files"
13439         local fd
13440         local cmd
13441
13442         rm -f $DIR/$tfile
13443         touch $DIR/$tfile
13444
13445         local fid=$($LFS path2fid $DIR/$tfile)
13446         # Open the file
13447         fd=$(free_fd)
13448         cmd="exec $fd<$DIR/$tfile"
13449         eval $cmd
13450         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
13451         echo "$fid_list" | grep "$fid"
13452         rc=$?
13453
13454         cmd="exec $fd>/dev/null"
13455         eval $cmd
13456         if [ $rc -ne 0 ]; then
13457                 error "FID $fid not found in open files list $fid_list"
13458         fi
13459 }
13460 run_test 154d "Verify open file fid"
13461
13462 test_154e()
13463 {
13464         [[ $MDS1_VERSION -lt $(version_code 2.6.50) ]] &&
13465                 skip "Need MDS version at least 2.6.50"
13466
13467         if ls -a $MOUNT | grep -q '^\.lustre$'; then
13468                 error ".lustre returned by readdir"
13469         fi
13470 }
13471 run_test 154e ".lustre is not returned by readdir"
13472
13473 test_154f() {
13474         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13475
13476         # create parent directory on a single MDT to avoid cross-MDT hardlinks
13477         test_mkdir -p -c1 $DIR/$tdir/d
13478         # test dirs inherit from its stripe
13479         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
13480         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
13481         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
13482         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
13483         touch $DIR/f
13484
13485         # get fid of parents
13486         local FID0=$($LFS path2fid $DIR/$tdir/d)
13487         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
13488         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
13489         local FID3=$($LFS path2fid $DIR)
13490
13491         # check that path2fid --parents returns expected <parent_fid>/name
13492         # 1) test for a directory (single parent)
13493         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
13494         [ "$parent" == "$FID0/foo1" ] ||
13495                 error "expected parent: $FID0/foo1, got: $parent"
13496
13497         # 2) test for a file with nlink > 1 (multiple parents)
13498         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
13499         echo "$parent" | grep -F "$FID1/$tfile" ||
13500                 error "$FID1/$tfile not returned in parent list"
13501         echo "$parent" | grep -F "$FID2/link" ||
13502                 error "$FID2/link not returned in parent list"
13503
13504         # 3) get parent by fid
13505         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
13506         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
13507         echo "$parent" | grep -F "$FID1/$tfile" ||
13508                 error "$FID1/$tfile not returned in parent list (by fid)"
13509         echo "$parent" | grep -F "$FID2/link" ||
13510                 error "$FID2/link not returned in parent list (by fid)"
13511
13512         # 4) test for entry in root directory
13513         parent=$($LFS path2fid --parents $DIR/f)
13514         echo "$parent" | grep -F "$FID3/f" ||
13515                 error "$FID3/f not returned in parent list"
13516
13517         # 5) test it on root directory
13518         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
13519                 error "$MOUNT should not have parents"
13520
13521         # enable xattr caching and check that linkea is correctly updated
13522         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
13523         save_lustre_params client "llite.*.xattr_cache" > $save
13524         lctl set_param llite.*.xattr_cache 1
13525
13526         # 6.1) linkea update on rename
13527         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
13528
13529         # get parents by fid
13530         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
13531         # foo1 should no longer be returned in parent list
13532         echo "$parent" | grep -F "$FID1" &&
13533                 error "$FID1 should no longer be in parent list"
13534         # the new path should appear
13535         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
13536                 error "$FID2/$tfile.moved is not in parent list"
13537
13538         # 6.2) linkea update on unlink
13539         rm -f $DIR/$tdir/d/foo2/link
13540         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
13541         # foo2/link should no longer be returned in parent list
13542         echo "$parent" | grep -F "$FID2/link" &&
13543                 error "$FID2/link should no longer be in parent list"
13544         true
13545
13546         rm -f $DIR/f
13547         restore_lustre_params < $save
13548         rm -f $save
13549 }
13550 run_test 154f "get parent fids by reading link ea"
13551
13552 test_154g()
13553 {
13554         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13555         [[ $MDS1_VERSION -ge $(version_code 2.6.92) &&
13556            $CLIENT_VERSION -gt $(version_code 2.6.99) ]] ||
13557                 skip "Need MDS version at least 2.6.92"
13558
13559         mkdir -p $DIR/$tdir
13560         llapi_fid_test -d $DIR/$tdir
13561 }
13562 run_test 154g "various llapi FID tests"
13563
13564 test_155_small_load() {
13565     local temp=$TMP/$tfile
13566     local file=$DIR/$tfile
13567
13568     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
13569         error "dd of=$temp bs=6096 count=1 failed"
13570     cp $temp $file
13571     cancel_lru_locks $OSC
13572     cmp $temp $file || error "$temp $file differ"
13573
13574     $TRUNCATE $temp 6000
13575     $TRUNCATE $file 6000
13576     cmp $temp $file || error "$temp $file differ (truncate1)"
13577
13578     echo "12345" >>$temp
13579     echo "12345" >>$file
13580     cmp $temp $file || error "$temp $file differ (append1)"
13581
13582     echo "12345" >>$temp
13583     echo "12345" >>$file
13584     cmp $temp $file || error "$temp $file differ (append2)"
13585
13586     rm -f $temp $file
13587     true
13588 }
13589
13590 test_155_big_load() {
13591         remote_ost_nodsh && skip "remote OST with nodsh"
13592
13593         local temp=$TMP/$tfile
13594         local file=$DIR/$tfile
13595
13596         free_min_max
13597         local cache_size=$(do_facet ost$((MAXI+1)) \
13598                 "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
13599         local large_file_size=$((cache_size * 2))
13600
13601         echo "OSS cache size: $cache_size KB"
13602         echo "Large file size: $large_file_size KB"
13603
13604         [ $MAXV -le $large_file_size ] &&
13605                 skip_env "max available OST size needs > $large_file_size KB"
13606
13607         $LFS setstripe $file -c 1 -i $MAXI || error "$LFS setstripe $file failed"
13608
13609         dd if=/dev/urandom of=$temp bs=$large_file_size count=1k ||
13610                 error "dd of=$temp bs=$large_file_size count=1k failed"
13611         cp $temp $file
13612         ls -lh $temp $file
13613         cancel_lru_locks osc
13614         cmp $temp $file || error "$temp $file differ"
13615
13616         rm -f $temp $file
13617         true
13618 }
13619
13620 save_writethrough() {
13621         local facets=$(get_facets OST)
13622
13623         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" > $1
13624 }
13625
13626 test_155a() {
13627         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13628
13629         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13630
13631         save_writethrough $p
13632
13633         set_cache read on
13634         set_cache writethrough on
13635         test_155_small_load
13636         restore_lustre_params < $p
13637         rm -f $p
13638 }
13639 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
13640
13641 test_155b() {
13642         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13643
13644         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13645
13646         save_writethrough $p
13647
13648         set_cache read on
13649         set_cache writethrough off
13650         test_155_small_load
13651         restore_lustre_params < $p
13652         rm -f $p
13653 }
13654 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
13655
13656 test_155c() {
13657         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13658
13659         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13660
13661         save_writethrough $p
13662
13663         set_cache read off
13664         set_cache writethrough on
13665         test_155_small_load
13666         restore_lustre_params < $p
13667         rm -f $p
13668 }
13669 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
13670
13671 test_155d() {
13672         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13673
13674         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13675
13676         save_writethrough $p
13677
13678         set_cache read off
13679         set_cache writethrough off
13680         test_155_small_load
13681         restore_lustre_params < $p
13682         rm -f $p
13683 }
13684 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
13685
13686 test_155e() {
13687         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13688
13689         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13690
13691         save_writethrough $p
13692
13693         set_cache read on
13694         set_cache writethrough on
13695         test_155_big_load
13696         restore_lustre_params < $p
13697         rm -f $p
13698 }
13699 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
13700
13701 test_155f() {
13702         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13703
13704         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13705
13706         save_writethrough $p
13707
13708         set_cache read on
13709         set_cache writethrough off
13710         test_155_big_load
13711         restore_lustre_params < $p
13712         rm -f $p
13713 }
13714 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
13715
13716 test_155g() {
13717         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13718
13719         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13720
13721         save_writethrough $p
13722
13723         set_cache read off
13724         set_cache writethrough on
13725         test_155_big_load
13726         restore_lustre_params < $p
13727         rm -f $p
13728 }
13729 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
13730
13731 test_155h() {
13732         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13733
13734         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13735
13736         save_writethrough $p
13737
13738         set_cache read off
13739         set_cache writethrough off
13740         test_155_big_load
13741         restore_lustre_params < $p
13742         rm -f $p
13743 }
13744 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
13745
13746 test_156() {
13747         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13748         remote_ost_nodsh && skip "remote OST with nodsh"
13749         [ $OST1_VERSION -lt $(version_code 2.6.93) ] &&
13750                 skip "stats not implemented on old servers"
13751         [ "$ost1_FSTYPE" = "zfs" ] &&
13752                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS"
13753
13754         local CPAGES=3
13755         local BEFORE
13756         local AFTER
13757         local file="$DIR/$tfile"
13758         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13759
13760         save_writethrough $p
13761         roc_hit_init
13762
13763         log "Turn on read and write cache"
13764         set_cache read on
13765         set_cache writethrough on
13766
13767         log "Write data and read it back."
13768         log "Read should be satisfied from the cache."
13769         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
13770         BEFORE=$(roc_hit)
13771         cancel_lru_locks osc
13772         cat $file >/dev/null
13773         AFTER=$(roc_hit)
13774         if ! let "AFTER - BEFORE == CPAGES"; then
13775                 error "NOT IN CACHE (2): before: $BEFORE, after: $AFTER"
13776         else
13777                 log "cache hits: before: $BEFORE, after: $AFTER"
13778         fi
13779
13780         log "Read again; it should be satisfied from the cache."
13781         BEFORE=$AFTER
13782         cancel_lru_locks osc
13783         cat $file >/dev/null
13784         AFTER=$(roc_hit)
13785         if ! let "AFTER - BEFORE == CPAGES"; then
13786                 error "NOT IN CACHE (3): before: $BEFORE, after: $AFTER"
13787         else
13788                 log "cache hits:: before: $BEFORE, after: $AFTER"
13789         fi
13790
13791         log "Turn off the read cache and turn on the write cache"
13792         set_cache read off
13793         set_cache writethrough on
13794
13795         log "Read again; it should be satisfied from the cache."
13796         BEFORE=$(roc_hit)
13797         cancel_lru_locks osc
13798         cat $file >/dev/null
13799         AFTER=$(roc_hit)
13800         if ! let "AFTER - BEFORE == CPAGES"; then
13801                 error "NOT IN CACHE (4): before: $BEFORE, after: $AFTER"
13802         else
13803                 log "cache hits:: before: $BEFORE, after: $AFTER"
13804         fi
13805
13806         if [ $OST1_VERSION -lt $(version_code 2.12.55) ]; then
13807                 # > 2.12.56 uses pagecache if cached
13808                 log "Read again; it should not be satisfied from the cache."
13809                 BEFORE=$AFTER
13810                 cancel_lru_locks osc
13811                 cat $file >/dev/null
13812                 AFTER=$(roc_hit)
13813                 if ! let "AFTER - BEFORE == 0"; then
13814                         error "IN CACHE (5): before: $BEFORE, after: $AFTER"
13815                 else
13816                         log "cache hits:: before: $BEFORE, after: $AFTER"
13817                 fi
13818         fi
13819
13820         log "Write data and read it back."
13821         log "Read should be satisfied from the cache."
13822         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
13823         BEFORE=$(roc_hit)
13824         cancel_lru_locks osc
13825         cat $file >/dev/null
13826         AFTER=$(roc_hit)
13827         if ! let "AFTER - BEFORE == CPAGES"; then
13828                 error "NOT IN CACHE (6): before: $BEFORE, after: $AFTER"
13829         else
13830                 log "cache hits:: before: $BEFORE, after: $AFTER"
13831         fi
13832
13833         if [ $OST1_VERSION -lt $(version_code 2.12.55) ]; then
13834                 # > 2.12.56 uses pagecache if cached
13835                 log "Read again; it should not be satisfied from the cache."
13836                 BEFORE=$AFTER
13837                 cancel_lru_locks osc
13838                 cat $file >/dev/null
13839                 AFTER=$(roc_hit)
13840                 if ! let "AFTER - BEFORE == 0"; then
13841                         error "IN CACHE (7): before: $BEFORE, after: $AFTER"
13842                 else
13843                         log "cache hits:: before: $BEFORE, after: $AFTER"
13844                 fi
13845         fi
13846
13847         log "Turn off read and write cache"
13848         set_cache read off
13849         set_cache writethrough off
13850
13851         log "Write data and read it back"
13852         log "It should not be satisfied from the cache."
13853         rm -f $file
13854         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
13855         cancel_lru_locks osc
13856         BEFORE=$(roc_hit)
13857         cat $file >/dev/null
13858         AFTER=$(roc_hit)
13859         if ! let "AFTER - BEFORE == 0"; then
13860                 error_ignore bz20762 "IN CACHE (8):before:$BEFORE,after:$AFTER"
13861         else
13862                 log "cache hits:: before: $BEFORE, after: $AFTER"
13863         fi
13864
13865         log "Turn on the read cache and turn off the write cache"
13866         set_cache read on
13867         set_cache writethrough off
13868
13869         log "Write data and read it back"
13870         log "It should not be satisfied from the cache."
13871         rm -f $file
13872         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
13873         BEFORE=$(roc_hit)
13874         cancel_lru_locks osc
13875         cat $file >/dev/null
13876         AFTER=$(roc_hit)
13877         if ! let "AFTER - BEFORE == 0"; then
13878                 error_ignore bz20762 "IN CACHE (9):before:$BEFORE,after:$AFTER"
13879         else
13880                 log "cache hits:: before: $BEFORE, after: $AFTER"
13881         fi
13882
13883         log "Read again; it should be satisfied from the cache."
13884         BEFORE=$(roc_hit)
13885         cancel_lru_locks osc
13886         cat $file >/dev/null
13887         AFTER=$(roc_hit)
13888         if ! let "AFTER - BEFORE == CPAGES"; then
13889                 error "NOT IN CACHE (1): before: $BEFORE, after: $AFTER"
13890         else
13891                 log "cache hits:: before: $BEFORE, after: $AFTER"
13892         fi
13893
13894         restore_lustre_params < $p
13895         rm -f $p $file
13896 }
13897 run_test 156 "Verification of tunables"
13898
13899 test_160a() {
13900         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13901         remote_mds_nodsh && skip "remote MDS with nodsh"
13902         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] ||
13903                 skip "Need MDS version at least 2.2.0"
13904
13905         changelog_register || error "changelog_register failed"
13906         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
13907         changelog_users $SINGLEMDS | grep -q $cl_user ||
13908                 error "User $cl_user not found in changelog_users"
13909
13910         # change something
13911         test_mkdir -p $DIR/$tdir/pics/2008/zachy
13912         changelog_clear 0 || error "changelog_clear failed"
13913         touch $DIR/$tdir/pics/2008/zachy/$tfile                 # open 1
13914         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg       # open 2
13915         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
13916         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
13917         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
13918         rm $DIR/$tdir/pics/desktop.jpg
13919
13920         changelog_dump | tail -10
13921
13922         echo "verifying changelog mask"
13923         changelog_chmask "-MKDIR"
13924         changelog_chmask "-CLOSE"
13925
13926         test_mkdir -p $DIR/$tdir/pics/zach/sofia                # not logged
13927         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # not logged
13928
13929         changelog_chmask "+MKDIR"
13930         changelog_chmask "+CLOSE"
13931
13932         test_mkdir -p $DIR/$tdir/pics/2008/sofia                # mkdir 1
13933         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # open 3
13934
13935         changelog_dump | tail -10
13936         MKDIRS=$(changelog_dump | grep -c "MKDIR")
13937         CLOSES=$(changelog_dump | grep -c "CLOSE")
13938         [ $MKDIRS -eq 1 ] || error "MKDIR changelog mask count $MKDIRS != 1"
13939         [ $CLOSES -eq 3 ] || error "CLOSE changelog mask count $CLOSES != 3"
13940
13941         # verify contents
13942         echo "verifying target fid"
13943         local fidc=$(changelog_extract_field "CREAT" "$tfile" "t=")
13944         local fidf=$($LFS path2fid $DIR/$tdir/pics/zach/$tfile)
13945         [ "$fidc" == "$fidf" ] ||
13946                 error "changelog '$tfile' fid $fidc != file fid $fidf"
13947         echo "verifying parent fid"
13948         # The FID returned from the Changelog may be the directory shard on
13949         # a different MDT, and not the FID returned by path2fid on the parent.
13950         # Instead of comparing FIDs, verify that fid2path(fidp) is correct,
13951         # since this is what will matter when recreating this file in the tree.
13952         local fidp=$(changelog_extract_field "CREAT" "$tfile" "p=")
13953         local pathp=$($LFS fid2path $MOUNT "$fidp")
13954         [ "${pathp%/}" == "$DIR/$tdir/pics/zach" ] ||
13955                 error "changelog fid2path($fidc) $pathp != $DIR/$tdir/pics/zach"
13956
13957         echo "getting records for $cl_user"
13958         changelog_users $SINGLEMDS
13959         local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user)
13960         local nclr=3
13961         __changelog_clear $SINGLEMDS $cl_user +$nclr ||
13962                 error "changelog_clear failed"
13963         local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user)
13964         echo "verifying user clear: $user_rec1 + $nclr == $user_rec2"
13965         [ $user_rec2 == $((user_rec1 + nclr)) ] ||
13966                 error "user index expect $user_rec1 + $nclr != $user_rec2"
13967
13968         local min0_rec=$(changelog_users $SINGLEMDS |
13969                 awk 'min == "" || $2 < min { min = $2 }; END { print min }')
13970         local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
13971                           awk '{ print $1; exit; }')
13972
13973         changelog_dump | tail -n 5
13974         echo "verifying user min purge: $min0_rec + 1 == $first_rec"
13975         [ $first_rec == $((min0_rec + 1)) ] ||
13976                 error "first index should be $min0_rec + 1 not $first_rec"
13977
13978         # LU-3446 changelog index reset on MDT restart
13979         local cur_rec1=$(changelog_users $SINGLEMDS |
13980                          awk '/^current.index:/ { print $NF }')
13981         changelog_clear 0 ||
13982                 error "clear all changelog records for $cl_user failed"
13983         stop $SINGLEMDS || error "Fail to stop $SINGLEMDS"
13984         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
13985                 error "Fail to start $SINGLEMDS"
13986         local cur_rec2=$(changelog_users $SINGLEMDS |
13987                          awk '/^current.index:/ { print $NF }')
13988         echo "verifying index survives MDT restart: $cur_rec1 == $cur_rec2"
13989         [ $cur_rec1 == $cur_rec2 ] ||
13990                 error "current index should be $cur_rec1 not $cur_rec2"
13991
13992         echo "verifying users from this test are deregistered"
13993         changelog_deregister || error "changelog_deregister failed"
13994         changelog_users $SINGLEMDS | grep -q $cl_user &&
13995                 error "User '$cl_user' still in changelog_users"
13996
13997         # lctl get_param -n mdd.*.changelog_users
13998         # current index: 144
13999         # ID    index (idle seconds)
14000         # cl3   144 (2)
14001         if ! changelog_users $SINGLEMDS | grep "^cl"; then
14002                 # this is the normal case where all users were deregistered
14003                 # make sure no new records are added when no users are present
14004                 local last_rec1=$(changelog_users $SINGLEMDS |
14005                                   awk '/^current.index:/ { print $NF }')
14006                 touch $DIR/$tdir/chloe
14007                 local last_rec2=$(changelog_users $SINGLEMDS |
14008                                   awk '/^current.index:/ { print $NF }')
14009                 echo "verify changelogs are off: $last_rec1 == $last_rec2"
14010                 [ $last_rec1 == $last_rec2 ] || error "changelogs not off"
14011         else
14012                 # any changelog users must be leftovers from a previous test
14013                 changelog_users $SINGLEMDS
14014                 echo "other changelog users; can't verify off"
14015         fi
14016 }
14017 run_test 160a "changelog sanity"
14018
14019 test_160b() { # LU-3587
14020         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14021         remote_mds_nodsh && skip "remote MDS with nodsh"
14022         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] ||
14023                 skip "Need MDS version at least 2.2.0"
14024
14025         changelog_register || error "changelog_register failed"
14026         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
14027         changelog_users $SINGLEMDS | grep -q $cl_user ||
14028                 error "User '$cl_user' not found in changelog_users"
14029
14030         local longname1=$(str_repeat a 255)
14031         local longname2=$(str_repeat b 255)
14032
14033         cd $DIR
14034         echo "creating very long named file"
14035         touch $longname1 || error "create of '$longname1' failed"
14036         echo "renaming very long named file"
14037         mv $longname1 $longname2
14038
14039         changelog_dump | grep RENME | tail -n 5
14040         rm -f $longname2
14041 }
14042 run_test 160b "Verify that very long rename doesn't crash in changelog"
14043
14044 test_160c() {
14045         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14046         remote_mds_nodsh && skip "remote MDS with nodsh"
14047
14048         [[ $MDS1_VERSION -gt $(version_code 2.5.57) ]] ||
14049                 [[ $MDS1_VERSION -gt $(version_code 2.5.1) &&
14050                    $MDS1_VERSION -lt $(version_code 2.5.50) ]] ||
14051                 skip "Need MDS version at least 2.5.58 or 2.5.2+"
14052
14053         local rc=0
14054
14055         # Registration step
14056         changelog_register || error "changelog_register failed"
14057
14058         rm -rf $DIR/$tdir
14059         mkdir -p $DIR/$tdir
14060         $MCREATE $DIR/$tdir/foo_160c
14061         changelog_chmask "-TRUNC"
14062         $TRUNCATE $DIR/$tdir/foo_160c 200
14063         changelog_chmask "+TRUNC"
14064         $TRUNCATE $DIR/$tdir/foo_160c 199
14065         changelog_dump | tail -n 5
14066         local truncs=$(changelog_dump | tail -n 5 | grep -c TRUNC)
14067         [ $truncs -eq 1 ] || error "TRUNC changelog mask count $truncs != 1"
14068 }
14069 run_test 160c "verify that changelog log catch the truncate event"
14070
14071 test_160d() {
14072         remote_mds_nodsh && skip "remote MDS with nodsh"
14073         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14074         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14075         [[ $MDS1_VERSION -ge $(version_code 2.7.60) ]] ||
14076                 skip "Need MDS version at least 2.7.60"
14077
14078         # Registration step
14079         changelog_register || error "changelog_register failed"
14080
14081         mkdir -p $DIR/$tdir/migrate_dir
14082         changelog_clear 0 || error "changelog_clear failed"
14083
14084         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
14085         changelog_dump | tail -n 5
14086         local migrates=$(changelog_dump | grep -c "MIGRT")
14087         [ $migrates -eq 1 ] || error "MIGRATE changelog count $migrates != 1"
14088 }
14089 run_test 160d "verify that changelog log catch the migrate event"
14090
14091 test_160e() {
14092         remote_mds_nodsh && skip "remote MDS with nodsh"
14093
14094         # Create a user
14095         changelog_register || error "changelog_register failed"
14096
14097         # Delete a future user (expect fail)
14098         local MDT0=$(facet_svc $SINGLEMDS)
14099         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister "cl77"
14100         local rc=$?
14101
14102         if [ $rc -eq 0 ]; then
14103                 error "Deleted non-existant user cl77"
14104         elif [ $rc -ne 2 ]; then
14105                 error "changelog_deregister failed with $rc, expect 2 (ENOENT)"
14106         fi
14107
14108         # Clear to a bad index (1 billion should be safe)
14109         $LFS changelog_clear $MDT0 "${CL_USERS[$SINGLEMDS]%% *}" 1000000000
14110         rc=$?
14111
14112         if [ $rc -eq 0 ]; then
14113                 error "Successfully cleared to invalid CL index"
14114         elif [ $rc -ne 22 ]; then
14115                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
14116         fi
14117 }
14118 run_test 160e "changelog negative testing (should return errors)"
14119
14120 test_160f() {
14121         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14122         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
14123                 skip "Need MDS version at least 2.10.56"
14124
14125         local mdts=$(comma_list $(mdts_nodes))
14126
14127         # Create a user
14128         changelog_register || error "first changelog_register failed"
14129         changelog_register || error "second changelog_register failed"
14130         local cl_users
14131         declare -A cl_user1
14132         declare -A cl_user2
14133         local user_rec1
14134         local user_rec2
14135         local i
14136
14137         # generate some changelog records to accumulate on each MDT
14138         # use fnv1a because created files should be evenly distributed
14139         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14140                 error "test_mkdir $tdir failed"
14141         log "$(date +%s): creating first files"
14142         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
14143                 error "create $DIR/$tdir/$tfile failed"
14144
14145         # check changelogs have been generated
14146         local start=$SECONDS
14147         local idle_time=$((MDSCOUNT * 5 + 5))
14148         local nbcl=$(changelog_dump | wc -l)
14149         [[ $nbcl -eq 0 ]] && error "no changelogs found"
14150
14151         for param in "changelog_max_idle_time=$idle_time" \
14152                      "changelog_gc=1" \
14153                      "changelog_min_gc_interval=2" \
14154                      "changelog_min_free_cat_entries=3"; do
14155                 local MDT0=$(facet_svc $SINGLEMDS)
14156                 local var="${param%=*}"
14157                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
14158
14159                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
14160                 do_nodes $mdts $LCTL set_param mdd.*.$param
14161         done
14162
14163         # force cl_user2 to be idle (1st part), but also cancel the
14164         # cl_user1 records so that it is not evicted later in the test.
14165         local sleep1=$((idle_time / 2))
14166         echo "$(date +%s): sleep1 $sleep1/${idle_time}s"
14167         sleep $sleep1
14168
14169         # simulate changelog catalog almost full
14170         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
14171         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
14172
14173         for i in $(seq $MDSCOUNT); do
14174                 cl_users=(${CL_USERS[mds$i]})
14175                 cl_user1[mds$i]="${cl_users[0]}"
14176                 cl_user2[mds$i]="${cl_users[1]}"
14177
14178                 [ -n "${cl_user1[mds$i]}" ] ||
14179                         error "mds$i: no user registered"
14180                 [ -n "${cl_user2[mds$i]}" ] ||
14181                         error "mds$i: only ${cl_user2[mds$i]} is registered"
14182
14183                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14184                 [ -n "$user_rec1" ] ||
14185                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14186                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
14187                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14188                 [ -n "$user_rec2" ] ||
14189                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14190                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
14191                      "$user_rec1 + 2 == $user_rec2"
14192                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
14193                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
14194                               "$user_rec1 + 2, but is $user_rec2"
14195                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
14196                 [ -n "$user_rec2" ] ||
14197                         error "mds$i: User ${cl_user2[mds$i]} not registered"
14198                 [ $user_rec1 == $user_rec2 ] ||
14199                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
14200                               "$user_rec1, but is $user_rec2"
14201         done
14202
14203         # force cl_user2 idle (2nd part) to just exceed changelog_max_idle_time
14204         local sleep2=$((idle_time - (SECONDS - start) + 1))
14205         echo "$(date +%s): sleep2 $sleep2/${idle_time}s"
14206         sleep $sleep2
14207
14208         # Generate one more changelog to trigger GC at fail_loc for cl_user2.
14209         # cl_user1 should be OK because it recently processed records.
14210         echo "$(date +%s): creating $((MDSCOUNT * 2)) files"
14211         createmany -m $DIR/$tdir/${tfile}b $((MDSCOUNT * 2)) ||
14212                 error "create $DIR/$tdir/${tfile}b failed"
14213
14214         # ensure gc thread is done
14215         for i in $(mdts_nodes); do
14216                 wait_update $i \
14217                         "ps -e -o comm= | grep chlg_gc_thread" "" 20 ||
14218                         error "$i: GC-thread not done"
14219         done
14220
14221         local first_rec
14222         for i in $(seq $MDSCOUNT); do
14223                 # check cl_user1 still registered
14224                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
14225                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14226                 # check cl_user2 unregistered
14227                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
14228                         error "mds$i: User ${cl_user2[mds$i]} still registered"
14229
14230                 # check changelogs are present and starting at $user_rec1 + 1
14231                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14232                 [ -n "$user_rec1" ] ||
14233                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14234                 first_rec=$($LFS changelog $(facet_svc mds$i) |
14235                             awk '{ print $1; exit; }')
14236
14237                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
14238                 [ $((user_rec1 + 1)) == $first_rec ] ||
14239                         error "mds$i: first index should be $user_rec1 + 1, " \
14240                               "but is $first_rec"
14241         done
14242 }
14243 run_test 160f "changelog garbage collect (timestamped users)"
14244
14245 test_160g() {
14246         remote_mds_nodsh && skip "remote MDS with nodsh"
14247         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
14248                 skip "Need MDS version at least 2.10.56"
14249
14250         local mdts=$(comma_list $(mdts_nodes))
14251
14252         #define OBD_FAIL_TIME_IN_CHLOG_USER     0x1314
14253         do_nodes $mdts $LCTL set_param fail_loc=0x1314
14254
14255         # Create a user
14256         changelog_register || error "first changelog_register failed"
14257         changelog_register || error "second changelog_register failed"
14258         local cl_users
14259         declare -A cl_user1
14260         declare -A cl_user2
14261         local user_rec1
14262         local user_rec2
14263         local i
14264
14265         # generate some changelog records to accumulate on each MDT
14266         # use fnv1a because created files should be evenly distributed
14267         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14268                 error "mkdir $tdir failed"
14269         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
14270                 error "create $DIR/$tdir/$tfile failed"
14271
14272         # check changelogs have been generated
14273         local nbcl=$(changelog_dump | wc -l)
14274         [[ $nbcl -eq 0 ]] && error "no changelogs found"
14275
14276         # reduce the max_idle_indexes value to make sure we exceed it
14277         max_ndx=$((nbcl / 2 - 1))
14278
14279         for param in "changelog_max_idle_indexes=$max_ndx" \
14280                      "changelog_gc=1" \
14281                      "changelog_min_gc_interval=2" \
14282                      "changelog_min_free_cat_entries=3"; do
14283                 local MDT0=$(facet_svc $SINGLEMDS)
14284                 local var="${param%=*}"
14285                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
14286
14287                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
14288                 do_nodes $mdts $LCTL set_param mdd.*.$param ||
14289                         error "unable to set mdd.*.$param"
14290         done
14291
14292         # simulate changelog catalog almost full
14293         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
14294         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
14295
14296         for i in $(seq $MDSCOUNT); do
14297                 cl_users=(${CL_USERS[mds$i]})
14298                 cl_user1[mds$i]="${cl_users[0]}"
14299                 cl_user2[mds$i]="${cl_users[1]}"
14300
14301                 [ -n "${cl_user1[mds$i]}" ] ||
14302                         error "mds$i: no user registered"
14303                 [ -n "${cl_user2[mds$i]}" ] ||
14304                         error "mds$i: only ${cl_user1[mds$i]} is registered"
14305
14306                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14307                 [ -n "$user_rec1" ] ||
14308                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14309                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
14310                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14311                 [ -n "$user_rec2" ] ||
14312                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14313                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
14314                      "$user_rec1 + 2 == $user_rec2"
14315                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
14316                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
14317                               "$user_rec1 + 2, but is $user_rec2"
14318                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
14319                 [ -n "$user_rec2" ] ||
14320                         error "mds$i: User ${cl_user2[mds$i]} not registered"
14321                 [ $user_rec1 == $user_rec2 ] ||
14322                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
14323                               "$user_rec1, but is $user_rec2"
14324         done
14325
14326         # ensure we are past the previous changelog_min_gc_interval set above
14327         sleep 2
14328
14329         # generate one more changelog to trigger fail_loc
14330         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
14331                 error "create $DIR/$tdir/${tfile}bis failed"
14332
14333         # ensure gc thread is done
14334         for i in $(mdts_nodes); do
14335                 wait_update $i \
14336                         "ps -e -o comm= | grep chlg_gc_thread" "" 20 ||
14337                         error "$i: GC-thread not done"
14338         done
14339
14340         local first_rec
14341         for i in $(seq $MDSCOUNT); do
14342                 # check cl_user1 still registered
14343                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
14344                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14345                 # check cl_user2 unregistered
14346                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
14347                         error "mds$i: User ${cl_user2[mds$i]} still registered"
14348
14349                 # check changelogs are present and starting at $user_rec1 + 1
14350                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14351                 [ -n "$user_rec1" ] ||
14352                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14353                 first_rec=$($LFS changelog $(facet_svc mds$i) |
14354                             awk '{ print $1; exit; }')
14355
14356                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
14357                 [ $((user_rec1 + 1)) == $first_rec ] ||
14358                         error "mds$i: first index should be $user_rec1 + 1, " \
14359                               "but is $first_rec"
14360         done
14361 }
14362 run_test 160g "changelog garbage collect (old users)"
14363
14364 test_160h() {
14365         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14366         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
14367                 skip "Need MDS version at least 2.10.56"
14368
14369         local mdts=$(comma_list $(mdts_nodes))
14370
14371         # Create a user
14372         changelog_register || error "first changelog_register failed"
14373         changelog_register || error "second changelog_register failed"
14374         local cl_users
14375         declare -A cl_user1
14376         declare -A cl_user2
14377         local user_rec1
14378         local user_rec2
14379         local i
14380
14381         # generate some changelog records to accumulate on each MDT
14382         # use fnv1a because created files should be evenly distributed
14383         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14384                 error "test_mkdir $tdir failed"
14385         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
14386                 error "create $DIR/$tdir/$tfile failed"
14387
14388         # check changelogs have been generated
14389         local nbcl=$(changelog_dump | wc -l)
14390         [[ $nbcl -eq 0 ]] && error "no changelogs found"
14391
14392         for param in "changelog_max_idle_time=10" \
14393                      "changelog_gc=1" \
14394                      "changelog_min_gc_interval=2"; do
14395                 local MDT0=$(facet_svc $SINGLEMDS)
14396                 local var="${param%=*}"
14397                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
14398
14399                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
14400                 do_nodes $mdts $LCTL set_param mdd.*.$param
14401         done
14402
14403         # force cl_user2 to be idle (1st part)
14404         sleep 9
14405
14406         for i in $(seq $MDSCOUNT); do
14407                 cl_users=(${CL_USERS[mds$i]})
14408                 cl_user1[mds$i]="${cl_users[0]}"
14409                 cl_user2[mds$i]="${cl_users[1]}"
14410
14411                 [ -n "${cl_user1[mds$i]}" ] ||
14412                         error "mds$i: no user registered"
14413                 [ -n "${cl_user2[mds$i]}" ] ||
14414                         error "mds$i: only ${cl_user2[mds$i]} is registered"
14415
14416                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14417                 [ -n "$user_rec1" ] ||
14418                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14419                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
14420                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14421                 [ -n "$user_rec2" ] ||
14422                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14423                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
14424                      "$user_rec1 + 2 == $user_rec2"
14425                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
14426                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
14427                               "$user_rec1 + 2, but is $user_rec2"
14428                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
14429                 [ -n "$user_rec2" ] ||
14430                         error "mds$i: User ${cl_user2[mds$i]} not registered"
14431                 [ $user_rec1 == $user_rec2 ] ||
14432                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
14433                               "$user_rec1, but is $user_rec2"
14434         done
14435
14436         # force cl_user2 to be idle (2nd part) and to reach
14437         # changelog_max_idle_time
14438         sleep 2
14439
14440         # force each GC-thread start and block then
14441         # one per MDT/MDD, set fail_val accordingly
14442         #define OBD_FAIL_FORCE_GC_THREAD 0x1316
14443         do_nodes $mdts $LCTL set_param fail_loc=0x1316
14444
14445         # generate more changelogs to trigger fail_loc
14446         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
14447                 error "create $DIR/$tdir/${tfile}bis failed"
14448
14449         # stop MDT to stop GC-thread, should be done in back-ground as it will
14450         # block waiting for the thread to be released and exit
14451         declare -A stop_pids
14452         for i in $(seq $MDSCOUNT); do
14453                 stop mds$i &
14454                 stop_pids[mds$i]=$!
14455         done
14456
14457         for i in $(mdts_nodes); do
14458                 local facet
14459                 local nb=0
14460                 local facets=$(facets_up_on_host $i)
14461
14462                 for facet in ${facets//,/ }; do
14463                         if [[ $facet == mds* ]]; then
14464                                 nb=$((nb + 1))
14465                         fi
14466                 done
14467                 # ensure each MDS's gc threads are still present and all in "R"
14468                 # state (OBD_FAIL_FORCE_GC_THREAD effect!)
14469                 [[ $(do_node $i pgrep chlg_gc_thread | wc -l) -eq $nb ]] ||
14470                         error "$i: expected $nb GC-thread"
14471                 wait_update $i \
14472                         "ps -C chlg_gc_thread -o state --no-headers | uniq" \
14473                         "R" 20 ||
14474                         error "$i: GC-thread not found in R-state"
14475                 # check umounts of each MDT on MDS have reached kthread_stop()
14476                 [[ $(do_node $i pgrep umount | wc -l) -eq $nb ]] ||
14477                         error "$i: expected $nb umount"
14478                 wait_update $i \
14479                         "ps -C umount -o state --no-headers | uniq" "D" 20 ||
14480                         error "$i: umount not found in D-state"
14481         done
14482
14483         # release all GC-threads
14484         do_nodes $mdts $LCTL set_param fail_loc=0
14485
14486         # wait for MDT stop to complete
14487         for i in $(seq $MDSCOUNT); do
14488                 wait ${stop_pids[mds$i]} || error "mds$i: stop failed"
14489         done
14490
14491         # XXX
14492         # may try to check if any orphan changelog records are present
14493         # via ldiskfs/zfs and llog_reader...
14494
14495         # re-start/mount MDTs
14496         for i in $(seq $MDSCOUNT); do
14497                 start mds$i $(mdsdevname $i) $MDS_MOUNT_OPTS ||
14498                         error "Fail to start mds$i"
14499         done
14500
14501         local first_rec
14502         for i in $(seq $MDSCOUNT); do
14503                 # check cl_user1 still registered
14504                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
14505                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14506                 # check cl_user2 unregistered
14507                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
14508                         error "mds$i: User ${cl_user2[mds$i]} still registered"
14509
14510                 # check changelogs are present and starting at $user_rec1 + 1
14511                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14512                 [ -n "$user_rec1" ] ||
14513                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14514                 first_rec=$($LFS changelog $(facet_svc mds$i) |
14515                             awk '{ print $1; exit; }')
14516
14517                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
14518                 [ $((user_rec1 + 1)) == $first_rec ] ||
14519                         error "mds$i: first index should be $user_rec1 + 1, " \
14520                               "but is $first_rec"
14521         done
14522 }
14523 run_test 160h "changelog gc thread stop upon umount, orphan records delete " \
14524               "during mount"
14525
14526 test_160i() {
14527
14528         local mdts=$(comma_list $(mdts_nodes))
14529
14530         changelog_register || error "first changelog_register failed"
14531
14532         # generate some changelog records to accumulate on each MDT
14533         # use fnv1a because created files should be evenly distributed
14534         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14535                 error "mkdir $tdir failed"
14536         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
14537                 error "create $DIR/$tdir/$tfile failed"
14538
14539         # check changelogs have been generated
14540         local nbcl=$(changelog_dump | wc -l)
14541         [[ $nbcl -eq 0 ]] && error "no changelogs found"
14542
14543         # simulate race between register and unregister
14544         # XXX as fail_loc is set per-MDS, with DNE configs the race
14545         # simulation will only occur for one MDT per MDS and for the
14546         # others the normal race scenario will take place
14547         #define CFS_FAIL_CHLOG_USER_REG_UNREG_RACE          0x1315
14548         do_nodes $mdts $LCTL set_param fail_loc=0x10001315
14549         do_nodes $mdts $LCTL set_param fail_val=1
14550
14551         # unregister 1st user
14552         changelog_deregister &
14553         local pid1=$!
14554         # wait some time for deregister work to reach race rdv
14555         sleep 2
14556         # register 2nd user
14557         changelog_register || error "2nd user register failed"
14558
14559         wait $pid1 || error "1st user deregister failed"
14560
14561         local i
14562         local last_rec
14563         declare -A LAST_REC
14564         for i in $(seq $MDSCOUNT); do
14565                 if changelog_users mds$i | grep "^cl"; then
14566                         # make sure new records are added with one user present
14567                         LAST_REC[mds$i]=$(changelog_users $SINGLEMDS |
14568                                           awk '/^current.index:/ { print $NF }')
14569                 else
14570                         error "mds$i has no user registered"
14571                 fi
14572         done
14573
14574         # generate more changelog records to accumulate on each MDT
14575         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
14576                 error "create $DIR/$tdir/${tfile}bis failed"
14577
14578         for i in $(seq $MDSCOUNT); do
14579                 last_rec=$(changelog_users $SINGLEMDS |
14580                            awk '/^current.index:/ { print $NF }')
14581                 echo "verify changelogs are on: $last_rec != ${LAST_REC[mds$i]}"
14582                 [ $last_rec != ${LAST_REC[mds$i]} ] ||
14583                         error "changelogs are off on mds$i"
14584         done
14585 }
14586 run_test 160i "changelog user register/unregister race"
14587
14588 test_160j() {
14589         remote_mds_nodsh && skip "remote MDS with nodsh"
14590         [[ $MDS1_VERSION -lt $(version_code 2.12.56) ]] &&
14591                 skip "Need MDS version at least 2.12.56"
14592
14593         mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
14594         stack_trap "umount $MOUNT2" EXIT
14595
14596         changelog_register || error "first changelog_register failed"
14597         stack_trap "changelog_deregister" EXIT
14598
14599         # generate some changelog
14600         # use fnv1a because created files should be evenly distributed
14601         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14602                 error "mkdir $tdir failed"
14603         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
14604                 error "create $DIR/$tdir/${tfile}bis failed"
14605
14606         # open the changelog device
14607         exec 3>/dev/changelog-$FSNAME-MDT0000
14608         stack_trap "exec 3>&-" EXIT
14609         exec 4</dev/changelog-$FSNAME-MDT0000
14610         stack_trap "exec 4<&-" EXIT
14611
14612         # umount the first lustre mount
14613         umount $MOUNT
14614         stack_trap "mount_client $MOUNT" EXIT
14615
14616         # read changelog
14617         cat <&4 >/dev/null || error "read changelog failed"
14618
14619         # clear changelog
14620         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
14621         changelog_users $SINGLEMDS | grep -q $cl_user ||
14622                 error "User $cl_user not found in changelog_users"
14623
14624         printf 'clear:'$cl_user':0' >&3
14625 }
14626 run_test 160j "client can be umounted  while its chanangelog is being used"
14627
14628 test_160k() {
14629         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14630         remote_mds_nodsh && skip "remote MDS with nodsh"
14631
14632         mkdir -p $DIR/$tdir/1/1
14633
14634         changelog_register || error "changelog_register failed"
14635         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
14636
14637         changelog_users $SINGLEMDS | grep -q $cl_user ||
14638                 error "User '$cl_user' not found in changelog_users"
14639 #define OBD_FAIL_MDS_CHANGELOG_REORDER 0x15d
14640         do_facet mds1 $LCTL set_param fail_loc=0x8000015d fail_val=3
14641         rmdir $DIR/$tdir/1/1 & sleep 1
14642         mkdir $DIR/$tdir/2
14643         touch $DIR/$tdir/2/2
14644         rm -rf $DIR/$tdir/2
14645
14646         wait
14647         sleep 4
14648
14649         changelog_dump | grep rmdir || error "rmdir not recorded"
14650
14651         rm -rf $DIR/$tdir
14652         changelog_deregister
14653 }
14654 run_test 160k "Verify that changelog records are not lost"
14655
14656 test_161a() {
14657         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14658
14659         test_mkdir -c1 $DIR/$tdir
14660         cp /etc/hosts $DIR/$tdir/$tfile
14661         test_mkdir -c1 $DIR/$tdir/foo1
14662         test_mkdir -c1 $DIR/$tdir/foo2
14663         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
14664         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
14665         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
14666         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
14667         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
14668         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
14669                 $LFS fid2path $DIR $FID
14670                 error "bad link ea"
14671         fi
14672         # middle
14673         rm $DIR/$tdir/foo2/zachary
14674         # last
14675         rm $DIR/$tdir/foo2/thor
14676         # first
14677         rm $DIR/$tdir/$tfile
14678         # rename
14679         mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
14680         [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ] &&
14681                 { $LFS fid2path $DIR $FID; error "bad link rename"; }
14682         rm $DIR/$tdir/foo2/maggie
14683
14684         # overflow the EA
14685         local longname=$tfile.avg_len_is_thirty_two_
14686         stack_trap "unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
14687                 error_noexit 'failed to unlink many hardlinks'" EXIT
14688         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
14689                 error "failed to hardlink many files"
14690         links=$($LFS fid2path $DIR $FID | wc -l)
14691         echo -n "${links}/1000 links in link EA"
14692         [[ $links -gt 60 ]] || error "expected at least 60 links in link EA"
14693 }
14694 run_test 161a "link ea sanity"
14695
14696 test_161b() {
14697         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14698         [ $MDSCOUNT -lt 2 ] && skip_env "skipping remote directory test"
14699
14700         local MDTIDX=1
14701         local remote_dir=$DIR/$tdir/remote_dir
14702
14703         mkdir -p $DIR/$tdir
14704         $LFS mkdir -i $MDTIDX $remote_dir ||
14705                 error "create remote directory failed"
14706
14707         cp /etc/hosts $remote_dir/$tfile
14708         mkdir -p $remote_dir/foo1
14709         mkdir -p $remote_dir/foo2
14710         ln $remote_dir/$tfile $remote_dir/foo1/sofia
14711         ln $remote_dir/$tfile $remote_dir/foo2/zachary
14712         ln $remote_dir/$tfile $remote_dir/foo1/luna
14713         ln $remote_dir/$tfile $remote_dir/foo2/thor
14714
14715         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
14716                      tr -d ']')
14717         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
14718                 $LFS fid2path $DIR $FID
14719                 error "bad link ea"
14720         fi
14721         # middle
14722         rm $remote_dir/foo2/zachary
14723         # last
14724         rm $remote_dir/foo2/thor
14725         # first
14726         rm $remote_dir/$tfile
14727         # rename
14728         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
14729         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
14730         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
14731                 $LFS fid2path $DIR $FID
14732                 error "bad link rename"
14733         fi
14734         rm $remote_dir/foo2/maggie
14735
14736         # overflow the EA
14737         local longname=filename_avg_len_is_thirty_two_
14738         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
14739                 error "failed to hardlink many files"
14740         links=$($LFS fid2path $DIR $FID | wc -l)
14741         echo -n "${links}/1000 links in link EA"
14742         [[ ${links} -gt 60 ]] ||
14743                 error "expected at least 60 links in link EA"
14744         unlinkmany $remote_dir/foo2/$longname 1000 ||
14745         error "failed to unlink many hardlinks"
14746 }
14747 run_test 161b "link ea sanity under remote directory"
14748
14749 test_161c() {
14750         remote_mds_nodsh && skip "remote MDS with nodsh"
14751         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14752         [[ $MDS1_VERSION -lt $(version_code 2.1.5) ]] &&
14753                 skip "Need MDS version at least 2.1.5"
14754
14755         # define CLF_RENAME_LAST 0x0001
14756         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
14757         changelog_register || error "changelog_register failed"
14758
14759         rm -rf $DIR/$tdir
14760         test_mkdir -i $((MDSCOUNT - 1)) $DIR/$tdir
14761         touch $DIR/$tdir/foo_161c
14762         touch $DIR/$tdir/bar_161c
14763         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
14764         changelog_dump | grep RENME | tail -n 5
14765         local flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
14766         changelog_clear 0 || error "changelog_clear failed"
14767         if [ x$flags != "x0x1" ]; then
14768                 error "flag $flags is not 0x1"
14769         fi
14770
14771         echo "rename overwrite target with nlink = 1, changelog flags=$flags"
14772         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
14773         touch $DIR/$tdir/foo_161c
14774         touch $DIR/$tdir/bar_161c
14775         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
14776         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
14777         changelog_dump | grep RENME | tail -n 5
14778         flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
14779         changelog_clear 0 || error "changelog_clear failed"
14780         if [ x$flags != "x0x0" ]; then
14781                 error "flag $flags is not 0x0"
14782         fi
14783         echo "rename overwrite a target having nlink > 1," \
14784                 "changelog record has flags of $flags"
14785
14786         # rename doesn't overwrite a target (changelog flag 0x0)
14787         touch $DIR/$tdir/foo_161c
14788         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
14789         changelog_dump | grep RENME | tail -n 5
14790         flags=$(changelog_dump | grep RENME | tail -1 | cut -f5 -d' ')
14791         changelog_clear 0 || error "changelog_clear failed"
14792         if [ x$flags != "x0x0" ]; then
14793                 error "flag $flags is not 0x0"
14794         fi
14795         echo "rename doesn't overwrite a target," \
14796                 "changelog record has flags of $flags"
14797
14798         # define CLF_UNLINK_LAST 0x0001
14799         # unlink a file having nlink = 1 (changelog flag 0x1)
14800         rm -f $DIR/$tdir/foo2_161c
14801         changelog_dump | grep UNLNK | tail -n 5
14802         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
14803         changelog_clear 0 || error "changelog_clear failed"
14804         if [ x$flags != "x0x1" ]; then
14805                 error "flag $flags is not 0x1"
14806         fi
14807         echo "unlink a file having nlink = 1," \
14808                 "changelog record has flags of $flags"
14809
14810         # unlink a file having nlink > 1 (changelog flag 0x0)
14811         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
14812         rm -f $DIR/$tdir/foobar_161c
14813         changelog_dump | grep UNLNK | tail -n 5
14814         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
14815         changelog_clear 0 || error "changelog_clear failed"
14816         if [ x$flags != "x0x0" ]; then
14817                 error "flag $flags is not 0x0"
14818         fi
14819         echo "unlink a file having nlink > 1, changelog record flags '$flags'"
14820 }
14821 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
14822
14823 test_161d() {
14824         remote_mds_nodsh && skip "remote MDS with nodsh"
14825         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
14826
14827         local pid
14828         local fid
14829
14830         changelog_register || error "changelog_register failed"
14831
14832         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
14833         # interfer with $MOUNT/.lustre/fid/ access
14834         mkdir $DIR/$tdir
14835         [[ $? -eq 0 ]] || error "mkdir failed"
14836
14837         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
14838         $LCTL set_param fail_loc=0x8000140c
14839         # 5s pause
14840         $LCTL set_param fail_val=5
14841
14842         # create file
14843         echo foofoo > $DIR/$tdir/$tfile &
14844         pid=$!
14845
14846         # wait for create to be delayed
14847         sleep 2
14848
14849         ps -p $pid
14850         [[ $? -eq 0 ]] || error "create should be blocked"
14851
14852         local tempfile="$(mktemp --tmpdir $tfile.XXXXXX)"
14853         stack_trap "rm -f $tempfile"
14854         fid=$(changelog_extract_field "CREAT" "$tfile" "t=")
14855         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
14856         # some delay may occur during ChangeLog publishing and file read just
14857         # above, that could allow file write to happen finally
14858         [[ -s $tempfile ]] && echo "file should be empty"
14859
14860         $LCTL set_param fail_loc=0
14861
14862         wait $pid
14863         [[ $? -eq 0 ]] || error "create failed"
14864 }
14865 run_test 161d "create with concurrent .lustre/fid access"
14866
14867 check_path() {
14868         local expected="$1"
14869         shift
14870         local fid="$2"
14871
14872         local path
14873         path=$($LFS fid2path "$@")
14874         local rc=$?
14875
14876         if [ $rc -ne 0 ]; then
14877                 error "path looked up of '$expected' failed: rc=$rc"
14878         elif [ "$path" != "$expected" ]; then
14879                 error "path looked up '$path' instead of '$expected'"
14880         else
14881                 echo "FID '$fid' resolves to path '$path' as expected"
14882         fi
14883 }
14884
14885 test_162a() { # was test_162
14886         test_mkdir -p -c1 $DIR/$tdir/d2
14887         touch $DIR/$tdir/d2/$tfile
14888         touch $DIR/$tdir/d2/x1
14889         touch $DIR/$tdir/d2/x2
14890         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
14891         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
14892         # regular file
14893         local fid=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
14894         check_path "$tdir/d2/$tfile" $FSNAME "$fid" --link 0
14895
14896         # softlink
14897         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
14898         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
14899         check_path "$tdir/d2/p/q/r/slink" $FSNAME "$fid" --link 0
14900
14901         # softlink to wrong file
14902         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
14903         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
14904         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME "$fid" --link 0
14905
14906         # hardlink
14907         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
14908         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
14909         fid=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
14910         # fid2path dir/fsname should both work
14911         check_path "$tdir/d2/a/b/c/new_file" $FSNAME "$fid" --link 1
14912         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR "$fid" --link 0
14913
14914         # hardlink count: check that there are 2 links
14915         local nlinks=$($LFS fid2path $DIR "$fid" | wc -l)
14916         [ $nlinks -eq 2 ] || error "expect 2 links, found $nlinks"
14917
14918         # hardlink indexing: remove the first link
14919         rm $DIR/$tdir/d2/p/q/r/hlink
14920         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $fid --link 0
14921 }
14922 run_test 162a "path lookup sanity"
14923
14924 test_162b() {
14925         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14926         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14927
14928         mkdir $DIR/$tdir
14929         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
14930                                 error "create striped dir failed"
14931
14932         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
14933                                         tail -n 1 | awk '{print $2}')
14934         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
14935
14936         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
14937         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
14938
14939         # regular file
14940         for ((i=0;i<5;i++)); do
14941                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
14942                         error "get fid for f$i failed"
14943                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0
14944
14945                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
14946                         error "get fid for d$i failed"
14947                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0
14948         done
14949
14950         return 0
14951 }
14952 run_test 162b "striped directory path lookup sanity"
14953
14954 # LU-4239: Verify fid2path works with paths 100 or more directories deep
14955 test_162c() {
14956         [[ $MDS1_VERSION -lt $(version_code 2.7.51) ]] &&
14957                 skip "Need MDS version at least 2.7.51"
14958
14959         local lpath=$tdir.local
14960         local rpath=$tdir.remote
14961
14962         test_mkdir $DIR/$lpath
14963         test_mkdir $DIR/$rpath
14964
14965         for ((i = 0; i <= 101; i++)); do
14966                 lpath="$lpath/$i"
14967                 mkdir $DIR/$lpath
14968                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
14969                         error "get fid for local directory $DIR/$lpath failed"
14970                 check_path "$DIR/$lpath" $MOUNT $FID --link 0
14971
14972                 rpath="$rpath/$i"
14973                 test_mkdir $DIR/$rpath
14974                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
14975                         error "get fid for remote directory $DIR/$rpath failed"
14976                 check_path "$DIR/$rpath" $MOUNT $FID --link 0
14977         done
14978
14979         return 0
14980 }
14981 run_test 162c "fid2path works with paths 100 or more directories deep"
14982
14983 oalr_event_count() {
14984         local event="${1}"
14985         local trace="${2}"
14986
14987         awk -v name="${FSNAME}-OST0000" \
14988             -v event="${event}" \
14989             '$1 == "TRACE" && $2 == event && $3 == name' \
14990             "${trace}" |
14991         wc -l
14992 }
14993
14994 oalr_expect_event_count() {
14995         local event="${1}"
14996         local trace="${2}"
14997         local expect="${3}"
14998         local count
14999
15000         count=$(oalr_event_count "${event}" "${trace}")
15001         if ((count == expect)); then
15002                 return 0
15003         fi
15004
15005         error_noexit "${event} event count was '${count}', expected ${expect}"
15006         cat "${trace}" >&2
15007         exit 1
15008 }
15009
15010 cleanup_165() {
15011         do_facet ost1 killall --quiet -KILL ofd_access_log_reader || true
15012         stop ost1
15013         start ost1 "$(ostdevname 1)" $OST_MOUNT_OPTS
15014 }
15015
15016 setup_165() {
15017         sync # Flush previous IOs so we can count log entries.
15018         do_facet ost1 $LCTL set_param "obdfilter.${FSNAME}-OST0000.access_log_size=4096"
15019         stack_trap cleanup_165 EXIT
15020 }
15021
15022 test_165a() {
15023         local trace="/tmp/${tfile}.trace"
15024         local rc
15025         local count
15026
15027         do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
15028         setup_165
15029         sleep 5
15030
15031         do_facet ost1 ofd_access_log_reader --list
15032         stop ost1
15033
15034         do_facet ost1 killall -TERM ofd_access_log_reader
15035         wait
15036         rc=$?
15037
15038         if ((rc != 0)); then
15039                 error "ofd_access_log_reader exited with rc = '${rc}'"
15040         fi
15041
15042         # Parse trace file for discovery events:
15043         oalr_expect_event_count alr_log_add "${trace}" 1
15044         oalr_expect_event_count alr_log_eof "${trace}" 1
15045         oalr_expect_event_count alr_log_free "${trace}" 1
15046 }
15047 run_test 165a "ofd access log discovery"
15048
15049 test_165b() {
15050         local trace="/tmp/${tfile}.trace"
15051         local file="${DIR}/${tfile}"
15052         local pfid1
15053         local pfid2
15054         local -a entry
15055         local rc
15056         local count
15057         local size
15058         local flags
15059
15060         setup_165
15061
15062         lfs setstripe -c 1 -i 0 "${file}"
15063         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15064         do_facet ost1 ofd_access_log_reader --list
15065
15066         do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
15067         sleep 5
15068         do_facet ost1 killall -TERM ofd_access_log_reader
15069         wait
15070         rc=$?
15071
15072         if ((rc != 0)); then
15073                 error "ofd_access_log_reader exited with rc = '${rc}'"
15074         fi
15075
15076         oalr_expect_event_count alr_log_entry "${trace}" 1
15077
15078         pfid1=$($LFS path2fid "${file}")
15079
15080         # 1     2             3   4    5     6   7    8    9     10
15081         # TRACE alr_log_entry OST PFID BEGIN END TIME SIZE COUNT FLAGS
15082         entry=( - $(awk -v pfid="${pfid}" '$1 == "TRACE" && $2 == "alr_log_entry"' "${trace}" ) )
15083
15084         echo "entry = '${entry[*]}'" >&2
15085
15086         pfid2=${entry[4]}
15087         if [[ "${pfid1}" != "${pfid2}" ]]; then
15088                 error "entry '${entry[*]}' has invalid PFID '${pfid2}', expected ${pfid1}"
15089         fi
15090
15091         size=${entry[8]}
15092         if ((size != 1048576)); then
15093                 error "entry '${entry[*]}' has invalid io size '${size}', expected 1048576"
15094         fi
15095
15096         flags=${entry[10]}
15097         if [[ "${flags}" != "w" ]]; then
15098                 error "entry '${entry[*]}' has invalid io flags '${flags}', expected 'w'"
15099         fi
15100
15101         do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
15102         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r524288c || error "cannot read '${file}'"
15103         sleep 5
15104         do_facet ost1 killall -TERM ofd_access_log_reader
15105         wait
15106         rc=$?
15107
15108         if ((rc != 0)); then
15109                 error "ofd_access_log_reader exited with rc = '${rc}'"
15110         fi
15111
15112         oalr_expect_event_count alr_log_entry "${trace}" 1
15113
15114         entry=( - $(awk -v pfid="${pfid}" '$1 == "TRACE" && $2 == "alr_log_entry"' "${trace}" ) )
15115         echo "entry = '${entry[*]}'" >&2
15116
15117         pfid2=${entry[4]}
15118         if [[ "${pfid1}" != "${pfid2}" ]]; then
15119                 error "entry '${entry[*]}' has invalid PFID '${pfid2}', expected ${pfid1}"
15120         fi
15121
15122         size=${entry[8]}
15123         if ((size != 524288)); then
15124                 error "entry '${entry[*]}' has invalid io size '${size}', 524288"
15125         fi
15126
15127         flags=${entry[10]}
15128         if [[ "${flags}" != "r" ]]; then
15129                 error "entry '${entry[*]}' has invalid io flags '${flags}', expected 'r'"
15130         fi
15131 }
15132 run_test 165b "ofd access log entries are produced and consumed"
15133
15134 test_165c() {
15135         local file="${DIR}/${tdir}/${tfile}"
15136         test_mkdir "${DIR}/${tdir}"
15137
15138         setup_165
15139
15140         lfs setstripe -c 1 -i 0 "${DIR}/${tdir}"
15141
15142         # 4096 / 64 = 64. Create twice as many entries.
15143         for ((i = 0; i < 128; i++)); do
15144                 $MULTIOP "${file}-${i}" oO_CREAT:O_WRONLY:w512c || error "cannot create file"
15145         done
15146
15147         sync
15148         do_facet ost1 ofd_access_log_reader --list
15149         unlinkmany  "${file}-%d" 128
15150 }
15151 run_test 165c "full ofd access logs do not block IOs"
15152
15153 oal_peek_entry_count() {
15154         do_facet ost1 ofd_access_log_reader --list | awk '$1 == "_entry_count:" { print $2; }'
15155 }
15156
15157 oal_expect_entry_count() {
15158         local entry_count=$(oal_peek_entry_count)
15159         local expect="$1"
15160
15161         if ((entry_count == expect)); then
15162                 return 0
15163         fi
15164
15165         error_noexit "bad entry count, got ${entry_count}, expected ${expect}"
15166         do_facet ost1 ofd_access_log_reader --list >&2
15167         exit 1
15168 }
15169
15170 test_165d() {
15171         local trace="/tmp/${tfile}.trace"
15172         local file="${DIR}/${tdir}/${tfile}"
15173         local param="obdfilter.${FSNAME}-OST0000.access_log_mask"
15174         local entry_count
15175         test_mkdir "${DIR}/${tdir}"
15176
15177         setup_165
15178         lfs setstripe -c 1 -i 0 "${file}"
15179
15180         do_facet ost1 lctl set_param "${param}=rw"
15181         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15182         oal_expect_entry_count 1
15183
15184         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
15185         oal_expect_entry_count 2
15186
15187         do_facet ost1 lctl set_param "${param}=r"
15188         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15189         oal_expect_entry_count 2
15190
15191         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
15192         oal_expect_entry_count 3
15193
15194         do_facet ost1 lctl set_param "${param}=w"
15195         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15196         oal_expect_entry_count 4
15197
15198         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
15199         oal_expect_entry_count 4
15200
15201         do_facet ost1 lctl set_param "${param}=0"
15202         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15203         oal_expect_entry_count 4
15204
15205         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
15206         oal_expect_entry_count 4
15207 }
15208 run_test 165d "ofd_access_log mask works"
15209
15210 test_169() {
15211         # do directio so as not to populate the page cache
15212         log "creating a 10 Mb file"
15213         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
15214         log "starting reads"
15215         dd if=$DIR/$tfile of=/dev/null bs=4096 &
15216         log "truncating the file"
15217         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
15218         log "killing dd"
15219         kill %+ || true # reads might have finished
15220         echo "wait until dd is finished"
15221         wait
15222         log "removing the temporary file"
15223         rm -rf $DIR/$tfile || error "tmp file removal failed"
15224 }
15225 run_test 169 "parallel read and truncate should not deadlock"
15226
15227 test_170() {
15228         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15229
15230         $LCTL clear     # bug 18514
15231         $LCTL debug_daemon start $TMP/${tfile}_log_good
15232         touch $DIR/$tfile
15233         $LCTL debug_daemon stop
15234         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
15235                 error "sed failed to read log_good"
15236
15237         $LCTL debug_daemon start $TMP/${tfile}_log_good
15238         rm -rf $DIR/$tfile
15239         $LCTL debug_daemon stop
15240
15241         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
15242                error "lctl df log_bad failed"
15243
15244         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
15245         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
15246
15247         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
15248         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
15249
15250         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
15251                 error "bad_line good_line1 good_line2 are empty"
15252
15253         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
15254         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
15255         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
15256
15257         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
15258         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
15259         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
15260
15261         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
15262                 error "bad_line_new good_line_new are empty"
15263
15264         local expected_good=$((good_line1 + good_line2*2))
15265
15266         rm -f $TMP/${tfile}*
15267         # LU-231, short malformed line may not be counted into bad lines
15268         if [ $bad_line -ne $bad_line_new ] &&
15269                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
15270                 error "expected $bad_line bad lines, but got $bad_line_new"
15271                 return 1
15272         fi
15273
15274         if [ $expected_good -ne $good_line_new ]; then
15275                 error "expected $expected_good good lines, but got $good_line_new"
15276                 return 2
15277         fi
15278         true
15279 }
15280 run_test 170 "test lctl df to handle corrupted log ====================="
15281
15282 test_171() { # bug20592
15283         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15284
15285         #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
15286         $LCTL set_param fail_loc=0x50e
15287         $LCTL set_param fail_val=3000
15288         multiop_bg_pause $DIR/$tfile O_s || true
15289         local MULTIPID=$!
15290         kill -USR1 $MULTIPID
15291         # cause log dump
15292         sleep 3
15293         wait $MULTIPID
15294         if dmesg | grep "recursive fault"; then
15295                 error "caught a recursive fault"
15296         fi
15297         $LCTL set_param fail_loc=0
15298         true
15299 }
15300 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
15301
15302 # it would be good to share it with obdfilter-survey/iokit-libecho code
15303 setup_obdecho_osc () {
15304         local rc=0
15305         local ost_nid=$1
15306         local obdfilter_name=$2
15307         echo "Creating new osc for $obdfilter_name on $ost_nid"
15308         # make sure we can find loopback nid
15309         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
15310
15311         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
15312                            ${obdfilter_name}_osc_UUID || rc=2; }
15313         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
15314                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
15315         return $rc
15316 }
15317
15318 cleanup_obdecho_osc () {
15319         local obdfilter_name=$1
15320         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
15321         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
15322         return 0
15323 }
15324
15325 obdecho_test() {
15326         local OBD=$1
15327         local node=$2
15328         local pages=${3:-64}
15329         local rc=0
15330         local id
15331
15332         local count=10
15333         local obd_size=$(get_obd_size $node $OBD)
15334         local page_size=$(get_page_size $node)
15335         if [[ -n "$obd_size" ]]; then
15336                 local new_count=$((obd_size / (pages * page_size / 1024)))
15337                 [[ $new_count -ge $count ]] || count=$new_count
15338         fi
15339
15340         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
15341         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
15342                            rc=2; }
15343         if [ $rc -eq 0 ]; then
15344             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
15345             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
15346         fi
15347         echo "New object id is $id"
15348         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
15349                            rc=4; }
15350         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
15351                            "test_brw $count w v $pages $id" || rc=4; }
15352         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
15353                            rc=4; }
15354         [ $rc -eq 0 ] || [ $rc -gt 2 ] &&
15355                 { do_facet $node "$LCTL --device ec cleanup" || rc=5; }
15356         [ $rc -eq 0 ] || [ $rc -gt 1 ] &&
15357                 { do_facet $node "$LCTL --device ec detach" || rc=6; }
15358         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
15359         return $rc
15360 }
15361
15362 test_180a() {
15363         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15364
15365         if ! module_loaded obdecho; then
15366                 load_module obdecho/obdecho &&
15367                         stack_trap "rmmod obdecho" EXIT ||
15368                         error "unable to load obdecho on client"
15369         fi
15370
15371         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
15372         local host=$($LCTL get_param -n osc.$osc.import |
15373                      awk '/current_connection:/ { print $2 }' )
15374         local target=$($LCTL get_param -n osc.$osc.import |
15375                        awk '/target:/ { print $2 }' )
15376         target=${target%_UUID}
15377
15378         if [ -n "$target" ]; then
15379                 setup_obdecho_osc $host $target &&
15380                         stack_trap "cleanup_obdecho_osc $target" EXIT ||
15381                         { error "obdecho setup failed with $?"; return; }
15382
15383                 obdecho_test ${target}_osc client ||
15384                         error "obdecho_test failed on ${target}_osc"
15385         else
15386                 $LCTL get_param osc.$osc.import
15387                 error "there is no osc.$osc.import target"
15388         fi
15389 }
15390 run_test 180a "test obdecho on osc"
15391
15392 test_180b() {
15393         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15394         remote_ost_nodsh && skip "remote OST with nodsh"
15395
15396         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
15397                 stack_trap "do_facet ost1 rmmod obdecho" EXIT ||
15398                 error "failed to load module obdecho"
15399
15400         local target=$(do_facet ost1 $LCTL dl |
15401                        awk '/obdfilter/ { print $4; exit; }')
15402
15403         if [ -n "$target" ]; then
15404                 obdecho_test $target ost1 || error "obdecho_test failed with $?"
15405         else
15406                 do_facet ost1 $LCTL dl
15407                 error "there is no obdfilter target on ost1"
15408         fi
15409 }
15410 run_test 180b "test obdecho directly on obdfilter"
15411
15412 test_180c() { # LU-2598
15413         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15414         remote_ost_nodsh && skip "remote OST with nodsh"
15415         [[ $MDS1_VERSION -lt $(version_code 2.4.0) ]] &&
15416                 skip "Need MDS version at least 2.4.0"
15417
15418         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
15419                 stack_trap "do_facet ost1 rmmod obdecho" EXIT ||
15420                 error "failed to load module obdecho"
15421
15422         local target=$(do_facet ost1 $LCTL dl |
15423                        awk '/obdfilter/ { print $4; exit; }')
15424
15425         if [ -n "$target" ]; then
15426                 local pages=16384 # 64MB bulk I/O RPC size
15427
15428                 obdecho_test "$target" ost1 "$pages" ||
15429                         error "obdecho_test with pages=$pages failed with $?"
15430         else
15431                 do_facet ost1 $LCTL dl
15432                 error "there is no obdfilter target on ost1"
15433         fi
15434 }
15435 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
15436
15437 test_181() { # bug 22177
15438         test_mkdir $DIR/$tdir
15439         # create enough files to index the directory
15440         createmany -o $DIR/$tdir/foobar 4000
15441         # print attributes for debug purpose
15442         lsattr -d .
15443         # open dir
15444         multiop_bg_pause $DIR/$tdir D_Sc || return 1
15445         MULTIPID=$!
15446         # remove the files & current working dir
15447         unlinkmany $DIR/$tdir/foobar 4000
15448         rmdir $DIR/$tdir
15449         kill -USR1 $MULTIPID
15450         wait $MULTIPID
15451         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
15452         return 0
15453 }
15454 run_test 181 "Test open-unlinked dir ========================"
15455
15456 test_182() {
15457         local fcount=1000
15458         local tcount=10
15459
15460         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
15461
15462         $LCTL set_param mdc.*.rpc_stats=clear
15463
15464         for (( i = 0; i < $tcount; i++ )) ; do
15465                 mkdir $DIR/$tdir/$i
15466         done
15467
15468         for (( i = 0; i < $tcount; i++ )) ; do
15469                 createmany -o $DIR/$tdir/$i/f- $fcount &
15470         done
15471         wait
15472
15473         for (( i = 0; i < $tcount; i++ )) ; do
15474                 unlinkmany $DIR/$tdir/$i/f- $fcount &
15475         done
15476         wait
15477
15478         $LCTL get_param mdc.*.rpc_stats
15479
15480         rm -rf $DIR/$tdir
15481 }
15482 run_test 182 "Test parallel modify metadata operations ================"
15483
15484 test_183() { # LU-2275
15485         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15486         remote_mds_nodsh && skip "remote MDS with nodsh"
15487         [[ $MDS1_VERSION -lt $(version_code 2.3.56) ]] &&
15488                 skip "Need MDS version at least 2.3.56"
15489
15490         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
15491         echo aaa > $DIR/$tdir/$tfile
15492
15493 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
15494         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
15495
15496         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
15497         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
15498
15499         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
15500
15501         # Flush negative dentry cache
15502         touch $DIR/$tdir/$tfile
15503
15504         # We are not checking for any leaked references here, they'll
15505         # become evident next time we do cleanup with module unload.
15506         rm -rf $DIR/$tdir
15507 }
15508 run_test 183 "No crash or request leak in case of strange dispositions ========"
15509
15510 # test suite 184 is for LU-2016, LU-2017
15511 test_184a() {
15512         check_swap_layouts_support
15513
15514         dir0=$DIR/$tdir/$testnum
15515         test_mkdir -p -c1 $dir0
15516         ref1=/etc/passwd
15517         ref2=/etc/group
15518         file1=$dir0/f1
15519         file2=$dir0/f2
15520         $LFS setstripe -c1 $file1
15521         cp $ref1 $file1
15522         $LFS setstripe -c2 $file2
15523         cp $ref2 $file2
15524         gen1=$($LFS getstripe -g $file1)
15525         gen2=$($LFS getstripe -g $file2)
15526
15527         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
15528         gen=$($LFS getstripe -g $file1)
15529         [[ $gen1 != $gen ]] ||
15530                 "Layout generation on $file1 does not change"
15531         gen=$($LFS getstripe -g $file2)
15532         [[ $gen2 != $gen ]] ||
15533                 "Layout generation on $file2 does not change"
15534
15535         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
15536         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
15537
15538         lfsck_verify_pfid $file1 $file2 || error "PFID are not transferred"
15539 }
15540 run_test 184a "Basic layout swap"
15541
15542 test_184b() {
15543         check_swap_layouts_support
15544
15545         dir0=$DIR/$tdir/$testnum
15546         mkdir -p $dir0 || error "creating dir $dir0"
15547         file1=$dir0/f1
15548         file2=$dir0/f2
15549         file3=$dir0/f3
15550         dir1=$dir0/d1
15551         dir2=$dir0/d2
15552         mkdir $dir1 $dir2
15553         $LFS setstripe -c1 $file1
15554         $LFS setstripe -c2 $file2
15555         $LFS setstripe -c1 $file3
15556         chown $RUNAS_ID $file3
15557         gen1=$($LFS getstripe -g $file1)
15558         gen2=$($LFS getstripe -g $file2)
15559
15560         $LFS swap_layouts $dir1 $dir2 &&
15561                 error "swap of directories layouts should fail"
15562         $LFS swap_layouts $dir1 $file1 &&
15563                 error "swap of directory and file layouts should fail"
15564         $RUNAS $LFS swap_layouts $file1 $file2 &&
15565                 error "swap of file we cannot write should fail"
15566         $LFS swap_layouts $file1 $file3 &&
15567                 error "swap of file with different owner should fail"
15568         /bin/true # to clear error code
15569 }
15570 run_test 184b "Forbidden layout swap (will generate errors)"
15571
15572 test_184c() {
15573         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
15574         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n"
15575         check_swap_layouts_support
15576
15577         local dir0=$DIR/$tdir/$testnum
15578         mkdir -p $dir0 || error "creating dir $dir0"
15579
15580         local ref1=$dir0/ref1
15581         local ref2=$dir0/ref2
15582         local file1=$dir0/file1
15583         local file2=$dir0/file2
15584         # create a file large enough for the concurrent test
15585         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
15586         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
15587         echo "ref file size: ref1($(stat -c %s $ref1))," \
15588              "ref2($(stat -c %s $ref2))"
15589
15590         cp $ref2 $file2
15591         dd if=$ref1 of=$file1 bs=16k &
15592         local DD_PID=$!
15593
15594         # Make sure dd starts to copy file
15595         while [ ! -f $file1 ]; do sleep 0.1; done
15596
15597         $LFS swap_layouts $file1 $file2
15598         local rc=$?
15599         wait $DD_PID
15600         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
15601         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
15602
15603         # how many bytes copied before swapping layout
15604         local copied=$(stat -c %s $file2)
15605         local remaining=$(stat -c %s $ref1)
15606         remaining=$((remaining - copied))
15607         echo "Copied $copied bytes before swapping layout..."
15608
15609         cmp -n $copied $file1 $ref2 | grep differ &&
15610                 error "Content mismatch [0, $copied) of ref2 and file1"
15611         cmp -n $copied $file2 $ref1 ||
15612                 error "Content mismatch [0, $copied) of ref1 and file2"
15613         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
15614                 error "Content mismatch [$copied, EOF) of ref1 and file1"
15615
15616         # clean up
15617         rm -f $ref1 $ref2 $file1 $file2
15618 }
15619 run_test 184c "Concurrent write and layout swap"
15620
15621 test_184d() {
15622         check_swap_layouts_support
15623         [ -z "$(which getfattr 2>/dev/null)" ] &&
15624                 skip_env "no getfattr command"
15625
15626         local file1=$DIR/$tdir/$tfile-1
15627         local file2=$DIR/$tdir/$tfile-2
15628         local file3=$DIR/$tdir/$tfile-3
15629         local lovea1
15630         local lovea2
15631
15632         mkdir -p $DIR/$tdir
15633         touch $file1 || error "create $file1 failed"
15634         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
15635                 error "create $file2 failed"
15636         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
15637                 error "create $file3 failed"
15638         lovea1=$(get_layout_param $file1)
15639
15640         $LFS swap_layouts $file2 $file3 ||
15641                 error "swap $file2 $file3 layouts failed"
15642         $LFS swap_layouts $file1 $file2 ||
15643                 error "swap $file1 $file2 layouts failed"
15644
15645         lovea2=$(get_layout_param $file2)
15646         echo "$lovea1"
15647         echo "$lovea2"
15648         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
15649
15650         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
15651         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
15652 }
15653 run_test 184d "allow stripeless layouts swap"
15654
15655 test_184e() {
15656         [[ $MDS1_VERSION -ge $(version_code 2.6.94) ]] ||
15657                 skip "Need MDS version at least 2.6.94"
15658         check_swap_layouts_support
15659         [ -z "$(which getfattr 2>/dev/null)" ] &&
15660                 skip_env "no getfattr command"
15661
15662         local file1=$DIR/$tdir/$tfile-1
15663         local file2=$DIR/$tdir/$tfile-2
15664         local file3=$DIR/$tdir/$tfile-3
15665         local lovea
15666
15667         mkdir -p $DIR/$tdir
15668         touch $file1 || error "create $file1 failed"
15669         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
15670                 error "create $file2 failed"
15671         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
15672                 error "create $file3 failed"
15673
15674         $LFS swap_layouts $file1 $file2 ||
15675                 error "swap $file1 $file2 layouts failed"
15676
15677         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
15678         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
15679
15680         echo 123 > $file1 || error "Should be able to write into $file1"
15681
15682         $LFS swap_layouts $file1 $file3 ||
15683                 error "swap $file1 $file3 layouts failed"
15684
15685         echo 123 > $file1 || error "Should be able to write into $file1"
15686
15687         rm -rf $file1 $file2 $file3
15688 }
15689 run_test 184e "Recreate layout after stripeless layout swaps"
15690
15691 test_184f() {
15692         # Create a file with name longer than sizeof(struct stat) ==
15693         # 144 to see if we can get chars from the file name to appear
15694         # in the returned striping. Note that 'f' == 0x66.
15695         local file=$(for ((i = 0; i < 200; i++)); do echo -n f; done)
15696
15697         mkdir -p $DIR/$tdir
15698         mcreate $DIR/$tdir/$file
15699         if lfs find --stripe-count 0x6666 $DIR/$tdir | grep $file; then
15700                 error "IOC_MDC_GETFILEINFO returned garbage striping"
15701         fi
15702 }
15703 run_test 184f "IOC_MDC_GETFILEINFO for files with long names but no striping"
15704
15705 test_185() { # LU-2441
15706         # LU-3553 - no volatile file support in old servers
15707         [[ $MDS1_VERSION -ge $(version_code 2.3.60) ]] ||
15708                 skip "Need MDS version at least 2.3.60"
15709
15710         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
15711         touch $DIR/$tdir/spoo
15712         local mtime1=$(stat -c "%Y" $DIR/$tdir)
15713         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
15714                 error "cannot create/write a volatile file"
15715         [ "$FILESET" == "" ] &&
15716         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
15717                 error "FID is still valid after close"
15718
15719         multiop_bg_pause $DIR/$tdir vVw4096_c
15720         local multi_pid=$!
15721
15722         local OLD_IFS=$IFS
15723         IFS=":"
15724         local fidv=($fid)
15725         IFS=$OLD_IFS
15726         # assume that the next FID for this client is sequential, since stdout
15727         # is unfortunately eaten by multiop_bg_pause
15728         local n=$((${fidv[1]} + 1))
15729         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
15730         if [ "$FILESET" == "" ]; then
15731                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
15732                         error "FID is missing before close"
15733         fi
15734         kill -USR1 $multi_pid
15735         # 1 second delay, so if mtime change we will see it
15736         sleep 1
15737         local mtime2=$(stat -c "%Y" $DIR/$tdir)
15738         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
15739 }
15740 run_test 185 "Volatile file support"
15741
15742 function create_check_volatile() {
15743         local idx=$1
15744         local tgt
15745
15746         $MULTIOP $MOUNT/.lustre/fid V${idx}Fw4096_c >&/tmp/${tfile}.fid &
15747         local PID=$!
15748         sleep 1
15749         local FID=$(cat /tmp/${tfile}.fid)
15750         [ "$FID" == "" ] && error "can't get FID for volatile"
15751         $CHECKSTAT -t file $MOUNT/.lustre/fid/$FID || error "can't stat $FID"
15752         tgt=$($LFS getstripe -m $MOUNT/.lustre/fid/$FID)
15753         [ "$tgt" != "$idx" ] && error "wrong MDS $tgt, expected $idx"
15754         kill -USR1 $PID
15755         wait
15756         sleep 1
15757         cancel_lru_locks mdc # flush opencache
15758         $CHECKSTAT -t file $MOUNT/.lustre/fid/$FID && error "can stat $FID"
15759         return 0
15760 }
15761
15762 test_185a(){
15763         # LU-12516 - volatile creation via .lustre
15764         [[ $MDS1_VERSION -ge $(version_code 2.12.55) ]] ||
15765                 skip "Need MDS version at least 2.3.55"
15766
15767         create_check_volatile 0
15768         [ $MDSCOUNT -lt 2 ] && return 0
15769
15770         # DNE case
15771         create_check_volatile 1
15772
15773         return 0
15774 }
15775 run_test 185a "Volatile file creation in .lustre/fid/"
15776
15777 test_187a() {
15778         remote_mds_nodsh && skip "remote MDS with nodsh"
15779         [ $MDS1_VERSION -lt $(version_code 2.3.0) ] &&
15780                 skip "Need MDS version at least 2.3.0"
15781
15782         local dir0=$DIR/$tdir/$testnum
15783         mkdir -p $dir0 || error "creating dir $dir0"
15784
15785         local file=$dir0/file1
15786         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
15787         local dv1=$($LFS data_version $file)
15788         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
15789         local dv2=$($LFS data_version $file)
15790         [[ $dv1 != $dv2 ]] ||
15791                 error "data version did not change on write $dv1 == $dv2"
15792
15793         # clean up
15794         rm -f $file1
15795 }
15796 run_test 187a "Test data version change"
15797
15798 test_187b() {
15799         remote_mds_nodsh && skip "remote MDS with nodsh"
15800         [ $MDS1_VERSION -lt $(version_code 2.3.0) ] &&
15801                 skip "Need MDS version at least 2.3.0"
15802
15803         local dir0=$DIR/$tdir/$testnum
15804         mkdir -p $dir0 || error "creating dir $dir0"
15805
15806         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
15807         [[ ${DV[0]} != ${DV[1]} ]] ||
15808                 error "data version did not change on write"\
15809                       " ${DV[0]} == ${DV[1]}"
15810
15811         # clean up
15812         rm -f $file1
15813 }
15814 run_test 187b "Test data version change on volatile file"
15815
15816 test_200() {
15817         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15818         remote_mgs_nodsh && skip "remote MGS with nodsh"
15819         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
15820
15821         local POOL=${POOL:-cea1}
15822         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
15823         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
15824         # Pool OST targets
15825         local first_ost=0
15826         local last_ost=$(($OSTCOUNT - 1))
15827         local ost_step=2
15828         local ost_list=$(seq $first_ost $ost_step $last_ost)
15829         local ost_range="$first_ost $last_ost $ost_step"
15830         local test_path=$POOL_ROOT/$POOL_DIR_NAME
15831         local file_dir=$POOL_ROOT/file_tst
15832         local subdir=$test_path/subdir
15833         local rc=0
15834
15835         while : ; do
15836                 # former test_200a test_200b
15837                 pool_add $POOL                          || { rc=$? ; break; }
15838                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
15839                 # former test_200c test_200d
15840                 mkdir -p $test_path
15841                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
15842                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
15843                 mkdir -p $subdir
15844                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
15845                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
15846                                                         || { rc=$? ; break; }
15847                 # former test_200e test_200f
15848                 local files=$((OSTCOUNT*3))
15849                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
15850                                                         || { rc=$? ; break; }
15851                 pool_create_files $POOL $file_dir $files "$ost_list" \
15852                                                         || { rc=$? ; break; }
15853                 # former test_200g test_200h
15854                 pool_lfs_df $POOL                       || { rc=$? ; break; }
15855                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
15856
15857                 # former test_201a test_201b test_201c
15858                 pool_remove_first_target $POOL          || { rc=$? ; break; }
15859
15860                 local f=$test_path/$tfile
15861                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
15862                 pool_remove $POOL $f                    || { rc=$? ; break; }
15863                 break
15864         done
15865
15866         destroy_test_pools
15867
15868         return $rc
15869 }
15870 run_test 200 "OST pools"
15871
15872 # usage: default_attr <count | size | offset>
15873 default_attr() {
15874         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
15875 }
15876
15877 # usage: check_default_stripe_attr
15878 check_default_stripe_attr() {
15879         ACTUAL=$($LFS getstripe $* $DIR/$tdir)
15880         case $1 in
15881         --stripe-count|-c)
15882                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
15883         --stripe-size|-S)
15884                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
15885         --stripe-index|-i)
15886                 EXPECTED=-1;;
15887         *)
15888                 error "unknown getstripe attr '$1'"
15889         esac
15890
15891         [ $ACTUAL == $EXPECTED ] ||
15892                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
15893 }
15894
15895 test_204a() {
15896         test_mkdir $DIR/$tdir
15897         $LFS setstripe --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
15898
15899         check_default_stripe_attr --stripe-count
15900         check_default_stripe_attr --stripe-size
15901         check_default_stripe_attr --stripe-index
15902 }
15903 run_test 204a "Print default stripe attributes"
15904
15905 test_204b() {
15906         test_mkdir $DIR/$tdir
15907         $LFS setstripe --stripe-count 1 $DIR/$tdir
15908
15909         check_default_stripe_attr --stripe-size
15910         check_default_stripe_attr --stripe-index
15911 }
15912 run_test 204b "Print default stripe size and offset"
15913
15914 test_204c() {
15915         test_mkdir $DIR/$tdir
15916         $LFS setstripe --stripe-size 65536 $DIR/$tdir
15917
15918         check_default_stripe_attr --stripe-count
15919         check_default_stripe_attr --stripe-index
15920 }
15921 run_test 204c "Print default stripe count and offset"
15922
15923 test_204d() {
15924         test_mkdir $DIR/$tdir
15925         $LFS setstripe --stripe-index 0 $DIR/$tdir
15926
15927         check_default_stripe_attr --stripe-count
15928         check_default_stripe_attr --stripe-size
15929 }
15930 run_test 204d "Print default stripe count and size"
15931
15932 test_204e() {
15933         test_mkdir $DIR/$tdir
15934         $LFS setstripe -d $DIR/$tdir
15935
15936         check_default_stripe_attr --stripe-count --raw
15937         check_default_stripe_attr --stripe-size --raw
15938         check_default_stripe_attr --stripe-index --raw
15939 }
15940 run_test 204e "Print raw stripe attributes"
15941
15942 test_204f() {
15943         test_mkdir $DIR/$tdir
15944         $LFS setstripe --stripe-count 1 $DIR/$tdir
15945
15946         check_default_stripe_attr --stripe-size --raw
15947         check_default_stripe_attr --stripe-index --raw
15948 }
15949 run_test 204f "Print raw stripe size and offset"
15950
15951 test_204g() {
15952         test_mkdir $DIR/$tdir
15953         $LFS setstripe --stripe-size 65536 $DIR/$tdir
15954
15955         check_default_stripe_attr --stripe-count --raw
15956         check_default_stripe_attr --stripe-index --raw
15957 }
15958 run_test 204g "Print raw stripe count and offset"
15959
15960 test_204h() {
15961         test_mkdir $DIR/$tdir
15962         $LFS setstripe --stripe-index 0 $DIR/$tdir
15963
15964         check_default_stripe_attr --stripe-count --raw
15965         check_default_stripe_attr --stripe-size --raw
15966 }
15967 run_test 204h "Print raw stripe count and size"
15968
15969 # Figure out which job scheduler is being used, if any,
15970 # or use a fake one
15971 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
15972         JOBENV=SLURM_JOB_ID
15973 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
15974         JOBENV=LSB_JOBID
15975 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
15976         JOBENV=PBS_JOBID
15977 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
15978         JOBENV=LOADL_STEP_ID
15979 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
15980         JOBENV=JOB_ID
15981 else
15982         $LCTL list_param jobid_name > /dev/null 2>&1
15983         if [ $? -eq 0 ]; then
15984                 JOBENV=nodelocal
15985         else
15986                 JOBENV=FAKE_JOBID
15987         fi
15988 fi
15989 LUSTRE_JOBID_SIZE=31 # plus NUL terminator
15990
15991 verify_jobstats() {
15992         local cmd=($1)
15993         shift
15994         local facets="$@"
15995
15996 # we don't really need to clear the stats for this test to work, since each
15997 # command has a unique jobid, but it makes debugging easier if needed.
15998 #       for facet in $facets; do
15999 #               local dev=$(convert_facet2label $facet)
16000 #               # clear old jobstats
16001 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
16002 #       done
16003
16004         # use a new JobID for each test, or we might see an old one
16005         [ "$JOBENV" = "FAKE_JOBID" ] &&
16006                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
16007
16008         JOBVAL=${!JOBENV:0:$LUSTRE_JOBID_SIZE}
16009
16010         [ "$JOBENV" = "nodelocal" ] && {
16011                 FAKE_JOBID=id.$testnum.%e.$RANDOM
16012                 $LCTL set_param jobid_name=$FAKE_JOBID
16013                 JOBVAL=${FAKE_JOBID/\%e/$(basename ${cmd[0]})}
16014         }
16015
16016         log "Test: ${cmd[*]}"
16017         log "Using JobID environment $($LCTL get_param -n jobid_var)=$JOBVAL"
16018
16019         if [ $JOBENV = "FAKE_JOBID" ]; then
16020                 FAKE_JOBID=$JOBVAL ${cmd[*]}
16021         else
16022                 ${cmd[*]}
16023         fi
16024
16025         # all files are created on OST0000
16026         for facet in $facets; do
16027                 local stats="*.$(convert_facet2label $facet).job_stats"
16028
16029                 # strip out libtool wrappers for in-tree executables
16030                 if [ $(do_facet $facet lctl get_param $stats |
16031                        sed -e 's/\.lt-/./' | grep -c $JOBVAL) -ne 1 ]; then
16032                         do_facet $facet lctl get_param $stats
16033                         error "No jobstats for $JOBVAL found on $facet::$stats"
16034                 fi
16035         done
16036 }
16037
16038 jobstats_set() {
16039         local new_jobenv=$1
16040
16041         set_persistent_param_and_check client "jobid_var" \
16042                 "$FSNAME.sys.jobid_var" $new_jobenv
16043 }
16044
16045 test_205a() { # Job stats
16046         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16047         [[ $MDS1_VERSION -ge $(version_code 2.7.1) ]] ||
16048                 skip "Need MDS version with at least 2.7.1"
16049         remote_mgs_nodsh && skip "remote MGS with nodsh"
16050         remote_mds_nodsh && skip "remote MDS with nodsh"
16051         remote_ost_nodsh && skip "remote OST with nodsh"
16052         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
16053                 skip "Server doesn't support jobstats"
16054         [[ $JOBID_VAR = disable ]] && skip_env "jobstats is disabled"
16055
16056         local old_jobenv=$($LCTL get_param -n jobid_var)
16057         [ $old_jobenv != $JOBENV ] && jobstats_set $JOBENV
16058
16059         if [[ $PERM_CMD == *"set_param -P"* ]]; then
16060                 stack_trap "do_facet mgs $PERM_CMD jobid_var=$old_jobenv" EXIT
16061         else
16062                 stack_trap "do_facet mgs $PERM_CMD \
16063                         $FSNAME.sys.jobid_var=$old_jobenv" EXIT
16064         fi
16065         changelog_register
16066
16067         local old_interval=$(do_facet $SINGLEMDS lctl get_param -n \
16068                                 mdt.*.job_cleanup_interval | head -n 1)
16069         local new_interval=5
16070         do_facet $SINGLEMDS \
16071                 $LCTL set_param mdt.*.job_cleanup_interval=$new_interval
16072         stack_trap "do_facet $SINGLEMDS \
16073                 $LCTL set_param mdt.*.job_cleanup_interval=$old_interval" EXIT
16074         local start=$SECONDS
16075
16076         local cmd
16077         # mkdir
16078         cmd="mkdir $DIR/$tdir"
16079         verify_jobstats "$cmd" "$SINGLEMDS"
16080         # rmdir
16081         cmd="rmdir $DIR/$tdir"
16082         verify_jobstats "$cmd" "$SINGLEMDS"
16083         # mkdir on secondary MDT
16084         if [ $MDSCOUNT -gt 1 ]; then
16085                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
16086                 verify_jobstats "$cmd" "mds2"
16087         fi
16088         # mknod
16089         cmd="mknod $DIR/$tfile c 1 3"
16090         verify_jobstats "$cmd" "$SINGLEMDS"
16091         # unlink
16092         cmd="rm -f $DIR/$tfile"
16093         verify_jobstats "$cmd" "$SINGLEMDS"
16094         # create all files on OST0000 so verify_jobstats can find OST stats
16095         # open & close
16096         cmd="$LFS setstripe -i 0 -c 1 $DIR/$tfile"
16097         verify_jobstats "$cmd" "$SINGLEMDS"
16098         # setattr
16099         cmd="touch $DIR/$tfile"
16100         verify_jobstats "$cmd" "$SINGLEMDS ost1"
16101         # write
16102         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
16103         verify_jobstats "$cmd" "ost1"
16104         # read
16105         cancel_lru_locks osc
16106         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
16107         verify_jobstats "$cmd" "ost1"
16108         # truncate
16109         cmd="$TRUNCATE $DIR/$tfile 0"
16110         verify_jobstats "$cmd" "$SINGLEMDS ost1"
16111         # rename
16112         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
16113         verify_jobstats "$cmd" "$SINGLEMDS"
16114         # jobstats expiry - sleep until old stats should be expired
16115         local left=$((new_interval + 5 - (SECONDS - start)))
16116         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
16117                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
16118                         "0" $left
16119         cmd="mkdir $DIR/$tdir.expire"
16120         verify_jobstats "$cmd" "$SINGLEMDS"
16121         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
16122             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
16123
16124         # Ensure that jobid are present in changelog (if supported by MDS)
16125         if [ $MDS1_VERSION -ge $(version_code 2.6.52) ];then
16126                 changelog_dump | tail -10
16127                 jobids=$(changelog_dump | tail -9 | grep -c "j=")
16128                 [ $jobids -eq 9 ] ||
16129                         error "Wrong changelog jobid count $jobids != 9"
16130
16131                 # LU-5862
16132                 JOBENV="disable"
16133                 jobstats_set $JOBENV
16134                 touch $DIR/$tfile
16135                 changelog_dump | grep $tfile
16136                 jobids=$(changelog_dump | grep $tfile | tail -1 | grep -c "j=")
16137                 [ $jobids -eq 0 ] ||
16138                         error "Unexpected jobids when jobid_var=$JOBENV"
16139         fi
16140
16141         lctl set_param jobid_var=USER jobid_name="S.%j.%e.%u.%h.E"
16142         JOBENV="JOBCOMPLEX"
16143         JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname).E"
16144
16145         verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
16146 }
16147 run_test 205a "Verify job stats"
16148
16149 # LU-13117
16150 test_205b() {
16151         $LCTL set_param jobid_var=USER jobid_name="%e.%u"
16152         env -i USERTESTJOBSTATS=foolish touch $DIR/$tfile.1
16153         do_facet $SINGLEMDS $LCTL get_param mdt.*.job_stats |
16154                 grep job_id: | grep foolish &&
16155                         error "Unexpected jobid found"
16156         true
16157 }
16158 run_test 205b "Verify job stats jobid parsing"
16159
16160 # LU-1480, LU-1773 and LU-1657
16161 test_206() {
16162         mkdir -p $DIR/$tdir
16163         $LFS setstripe -c -1 $DIR/$tdir
16164 #define OBD_FAIL_LOV_INIT 0x1403
16165         $LCTL set_param fail_loc=0xa0001403
16166         $LCTL set_param fail_val=1
16167         touch $DIR/$tdir/$tfile || true
16168 }
16169 run_test 206 "fail lov_init_raid0() doesn't lbug"
16170
16171 test_207a() {
16172         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
16173         local fsz=`stat -c %s $DIR/$tfile`
16174         cancel_lru_locks mdc
16175
16176         # do not return layout in getattr intent
16177 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
16178         $LCTL set_param fail_loc=0x170
16179         local sz=`stat -c %s $DIR/$tfile`
16180
16181         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
16182
16183         rm -rf $DIR/$tfile
16184 }
16185 run_test 207a "can refresh layout at glimpse"
16186
16187 test_207b() {
16188         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
16189         local cksum=`md5sum $DIR/$tfile`
16190         local fsz=`stat -c %s $DIR/$tfile`
16191         cancel_lru_locks mdc
16192         cancel_lru_locks osc
16193
16194         # do not return layout in getattr intent
16195 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
16196         $LCTL set_param fail_loc=0x171
16197
16198         # it will refresh layout after the file is opened but before read issues
16199         echo checksum is "$cksum"
16200         echo "$cksum" |md5sum -c --quiet || error "file differs"
16201
16202         rm -rf $DIR/$tfile
16203 }
16204 run_test 207b "can refresh layout at open"
16205
16206 test_208() {
16207         # FIXME: in this test suite, only RD lease is used. This is okay
16208         # for now as only exclusive open is supported. After generic lease
16209         # is done, this test suite should be revised. - Jinshan
16210
16211         remote_mds_nodsh && skip "remote MDS with nodsh"
16212         [[ $MDS1_VERSION -ge $(version_code 2.4.52) ]] ||
16213                 skip "Need MDS version at least 2.4.52"
16214
16215         echo "==== test 1: verify get lease work"
16216         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
16217
16218         echo "==== test 2: verify lease can be broken by upcoming open"
16219         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
16220         local PID=$!
16221         sleep 1
16222
16223         $MULTIOP $DIR/$tfile oO_RDONLY:c
16224         kill -USR1 $PID && wait $PID || error "break lease error"
16225
16226         echo "==== test 3: verify lease can't be granted if an open already exists"
16227         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
16228         local PID=$!
16229         sleep 1
16230
16231         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
16232         kill -USR1 $PID && wait $PID || error "open file error"
16233
16234         echo "==== test 4: lease can sustain over recovery"
16235         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
16236         PID=$!
16237         sleep 1
16238
16239         fail mds1
16240
16241         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
16242
16243         echo "==== test 5: lease broken can't be regained by replay"
16244         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
16245         PID=$!
16246         sleep 1
16247
16248         # open file to break lease and then recovery
16249         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
16250         fail mds1
16251
16252         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
16253
16254         rm -f $DIR/$tfile
16255 }
16256 run_test 208 "Exclusive open"
16257
16258 test_209() {
16259         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
16260                 skip_env "must have disp_stripe"
16261
16262         touch $DIR/$tfile
16263         sync; sleep 5; sync;
16264
16265         echo 3 > /proc/sys/vm/drop_caches
16266         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
16267
16268         # open/close 500 times
16269         for i in $(seq 500); do
16270                 cat $DIR/$tfile
16271         done
16272
16273         echo 3 > /proc/sys/vm/drop_caches
16274         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
16275
16276         echo "before: $req_before, after: $req_after"
16277         [ $((req_after - req_before)) -ge 300 ] &&
16278                 error "open/close requests are not freed"
16279         return 0
16280 }
16281 run_test 209 "read-only open/close requests should be freed promptly"
16282
16283 test_212() {
16284         size=`date +%s`
16285         size=$((size % 8192 + 1))
16286         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
16287         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
16288         rm -f $DIR/f212 $DIR/f212.xyz
16289 }
16290 run_test 212 "Sendfile test ============================================"
16291
16292 test_213() {
16293         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
16294         cancel_lru_locks osc
16295         lctl set_param fail_loc=0x8000040f
16296         # generate a read lock
16297         cat $DIR/$tfile > /dev/null
16298         # write to the file, it will try to cancel the above read lock.
16299         cat /etc/hosts >> $DIR/$tfile
16300 }
16301 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
16302
16303 test_214() { # for bug 20133
16304         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
16305         for (( i=0; i < 340; i++ )) ; do
16306                 touch $DIR/$tdir/d214c/a$i
16307         done
16308
16309         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
16310         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
16311         ls $DIR/d214c || error "ls $DIR/d214c failed"
16312         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
16313         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
16314 }
16315 run_test 214 "hash-indexed directory test - bug 20133"
16316
16317 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
16318 create_lnet_proc_files() {
16319         lctl get_param -n $1 >$TMP/lnet_$1.sys || error "cannot read lnet.$1"
16320 }
16321
16322 # counterpart of create_lnet_proc_files
16323 remove_lnet_proc_files() {
16324         rm -f $TMP/lnet_$1.sys
16325 }
16326
16327 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
16328 # 3rd arg as regexp for body
16329 check_lnet_proc_stats() {
16330         local l=$(cat "$TMP/lnet_$1" |wc -l)
16331         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
16332
16333         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
16334 }
16335
16336 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
16337 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
16338 # optional and can be regexp for 2nd line (lnet.routes case)
16339 check_lnet_proc_entry() {
16340         local blp=2          # blp stands for 'position of 1st line of body'
16341         [ -z "$5" ] || blp=3 # lnet.routes case
16342
16343         local l=$(cat "$TMP/lnet_$1" |wc -l)
16344         # subtracting one from $blp because the body can be empty
16345         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
16346
16347         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
16348                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
16349
16350         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
16351                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
16352
16353         # bail out if any unexpected line happened
16354         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
16355         [ "$?" != 0 ] || error "$2 misformatted"
16356 }
16357
16358 test_215() { # for bugs 18102, 21079, 21517
16359         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16360
16361         local N='(0|[1-9][0-9]*)'       # non-negative numeric
16362         local P='[1-9][0-9]*'           # positive numeric
16363         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
16364         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
16365         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
16366         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
16367
16368         local L1 # regexp for 1st line
16369         local L2 # regexp for 2nd line (optional)
16370         local BR # regexp for the rest (body)
16371
16372         # lnet.stats should look as 11 space-separated non-negative numerics
16373         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
16374         create_lnet_proc_files "stats"
16375         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
16376         remove_lnet_proc_files "stats"
16377
16378         # lnet.routes should look like this:
16379         # Routing disabled/enabled
16380         # net hops priority state router
16381         # where net is a string like tcp0, hops > 0, priority >= 0,
16382         # state is up/down,
16383         # router is a string like 192.168.1.1@tcp2
16384         L1="^Routing (disabled|enabled)$"
16385         L2="^net +hops +priority +state +router$"
16386         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
16387         create_lnet_proc_files "routes"
16388         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
16389         remove_lnet_proc_files "routes"
16390
16391         # lnet.routers should look like this:
16392         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
16393         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
16394         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
16395         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
16396         L1="^ref +rtr_ref +alive +router$"
16397         BR="^$P +$P +(up|down) +$NID$"
16398         create_lnet_proc_files "routers"
16399         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
16400         remove_lnet_proc_files "routers"
16401
16402         # lnet.peers should look like this:
16403         # nid refs state last max rtr min tx min queue
16404         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
16405         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
16406         # numeric (0 or >0 or <0), queue >= 0.
16407         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
16408         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
16409         create_lnet_proc_files "peers"
16410         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
16411         remove_lnet_proc_files "peers"
16412
16413         # lnet.buffers  should look like this:
16414         # pages count credits min
16415         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
16416         L1="^pages +count +credits +min$"
16417         BR="^ +$N +$N +$I +$I$"
16418         create_lnet_proc_files "buffers"
16419         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
16420         remove_lnet_proc_files "buffers"
16421
16422         # lnet.nis should look like this:
16423         # nid status alive refs peer rtr max tx min
16424         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
16425         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
16426         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
16427         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
16428         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
16429         create_lnet_proc_files "nis"
16430         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
16431         remove_lnet_proc_files "nis"
16432
16433         # can we successfully write to lnet.stats?
16434         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
16435 }
16436 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
16437
16438 test_216() { # bug 20317
16439         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16440         remote_ost_nodsh && skip "remote OST with nodsh"
16441
16442         local node
16443         local facets=$(get_facets OST)
16444         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
16445
16446         save_lustre_params client "osc.*.contention_seconds" > $p
16447         save_lustre_params $facets \
16448                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
16449         save_lustre_params $facets \
16450                 "ldlm.namespaces.filter-*.contended_locks" >> $p
16451         save_lustre_params $facets \
16452                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
16453         clear_stats osc.*.osc_stats
16454
16455         # agressive lockless i/o settings
16456         do_nodes $(comma_list $(osts_nodes)) \
16457                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
16458                         ldlm.namespaces.filter-*.contended_locks=0 \
16459                         ldlm.namespaces.filter-*.contention_seconds=60"
16460         lctl set_param -n osc.*.contention_seconds=60
16461
16462         $DIRECTIO write $DIR/$tfile 0 10 4096
16463         $CHECKSTAT -s 40960 $DIR/$tfile
16464
16465         # disable lockless i/o
16466         do_nodes $(comma_list $(osts_nodes)) \
16467                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
16468                         ldlm.namespaces.filter-*.contended_locks=32 \
16469                         ldlm.namespaces.filter-*.contention_seconds=0"
16470         lctl set_param -n osc.*.contention_seconds=0
16471         clear_stats osc.*.osc_stats
16472
16473         dd if=/dev/zero of=$DIR/$tfile count=0
16474         $CHECKSTAT -s 0 $DIR/$tfile
16475
16476         restore_lustre_params <$p
16477         rm -f $p
16478         rm $DIR/$tfile
16479 }
16480 run_test 216 "check lockless direct write updates file size and kms correctly"
16481
16482 test_217() { # bug 22430
16483         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16484
16485         local node
16486         local nid
16487
16488         for node in $(nodes_list); do
16489                 nid=$(host_nids_address $node $NETTYPE)
16490                 if [[ $nid = *-* ]] ; then
16491                         echo "lctl ping $(h2nettype $nid)"
16492                         lctl ping $(h2nettype $nid)
16493                 else
16494                         echo "skipping $node (no hyphen detected)"
16495                 fi
16496         done
16497 }
16498 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
16499
16500 test_218() {
16501        # do directio so as not to populate the page cache
16502        log "creating a 10 Mb file"
16503        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
16504        log "starting reads"
16505        dd if=$DIR/$tfile of=/dev/null bs=4096 &
16506        log "truncating the file"
16507        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
16508        log "killing dd"
16509        kill %+ || true # reads might have finished
16510        echo "wait until dd is finished"
16511        wait
16512        log "removing the temporary file"
16513        rm -rf $DIR/$tfile || error "tmp file removal failed"
16514 }
16515 run_test 218 "parallel read and truncate should not deadlock"
16516
16517 test_219() {
16518         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16519
16520         # write one partial page
16521         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
16522         # set no grant so vvp_io_commit_write will do sync write
16523         $LCTL set_param fail_loc=0x411
16524         # write a full page at the end of file
16525         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
16526
16527         $LCTL set_param fail_loc=0
16528         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
16529         $LCTL set_param fail_loc=0x411
16530         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
16531
16532         # LU-4201
16533         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
16534         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
16535 }
16536 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
16537
16538 test_220() { #LU-325
16539         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16540         remote_ost_nodsh && skip "remote OST with nodsh"
16541         remote_mds_nodsh && skip "remote MDS with nodsh"
16542         remote_mgs_nodsh && skip "remote MGS with nodsh"
16543
16544         local OSTIDX=0
16545
16546         # create on MDT0000 so the last_id and next_id are correct
16547         mkdir $DIR/$tdir
16548         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
16549         OST=${OST%_UUID}
16550
16551         # on the mdt's osc
16552         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
16553         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
16554                         osp.$mdtosc_proc1.prealloc_last_id)
16555         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
16556                         osp.$mdtosc_proc1.prealloc_next_id)
16557
16558         $LFS df -i
16559
16560         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
16561         #define OBD_FAIL_OST_ENOINO              0x229
16562         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
16563         create_pool $FSNAME.$TESTNAME || return 1
16564         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
16565
16566         $LFS setstripe $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
16567
16568         MDSOBJS=$((last_id - next_id))
16569         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
16570
16571         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
16572         echo "OST still has $count kbytes free"
16573
16574         echo "create $MDSOBJS files @next_id..."
16575         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
16576
16577         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
16578                         osp.$mdtosc_proc1.prealloc_last_id)
16579         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
16580                         osp.$mdtosc_proc1.prealloc_next_id)
16581
16582         echo "after creation, last_id=$last_id2, next_id=$next_id2"
16583         $LFS df -i
16584
16585         echo "cleanup..."
16586
16587         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
16588         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
16589
16590         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST ||
16591                 error "$LCTL pool_remove $FSNAME.$TESTNAME $OST failed"
16592         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
16593                 error "$LCTL pool_destroy $FSNAME.$TESTNAME failed"
16594         echo "unlink $MDSOBJS files @$next_id..."
16595         unlinkmany $DIR/$tdir/f $MDSOBJS || error "unlinkmany failed"
16596 }
16597 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
16598
16599 test_221() {
16600         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16601
16602         dd if=`which date` of=$MOUNT/date oflag=sync
16603         chmod +x $MOUNT/date
16604
16605         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
16606         $LCTL set_param fail_loc=0x80001401
16607
16608         $MOUNT/date > /dev/null
16609         rm -f $MOUNT/date
16610 }
16611 run_test 221 "make sure fault and truncate race to not cause OOM"
16612
16613 test_222a () {
16614         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16615
16616         rm -rf $DIR/$tdir
16617         test_mkdir $DIR/$tdir
16618         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16619         createmany -o $DIR/$tdir/$tfile 10
16620         cancel_lru_locks mdc
16621         cancel_lru_locks osc
16622         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
16623         $LCTL set_param fail_loc=0x31a
16624         ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
16625         $LCTL set_param fail_loc=0
16626         rm -r $DIR/$tdir
16627 }
16628 run_test 222a "AGL for ls should not trigger CLIO lock failure"
16629
16630 test_222b () {
16631         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16632
16633         rm -rf $DIR/$tdir
16634         test_mkdir $DIR/$tdir
16635         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16636         createmany -o $DIR/$tdir/$tfile 10
16637         cancel_lru_locks mdc
16638         cancel_lru_locks osc
16639         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
16640         $LCTL set_param fail_loc=0x31a
16641         rm -r $DIR/$tdir || error "AGL for rmdir failed"
16642         $LCTL set_param fail_loc=0
16643 }
16644 run_test 222b "AGL for rmdir should not trigger CLIO lock failure"
16645
16646 test_223 () {
16647         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16648
16649         rm -rf $DIR/$tdir
16650         test_mkdir $DIR/$tdir
16651         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16652         createmany -o $DIR/$tdir/$tfile 10
16653         cancel_lru_locks mdc
16654         cancel_lru_locks osc
16655         #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
16656         $LCTL set_param fail_loc=0x31b
16657         ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
16658         $LCTL set_param fail_loc=0
16659         rm -r $DIR/$tdir
16660 }
16661 run_test 223 "osc reenqueue if without AGL lock granted ======================="
16662
16663 test_224a() { # LU-1039, MRP-303
16664         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16665
16666         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
16667         $LCTL set_param fail_loc=0x508
16668         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
16669         $LCTL set_param fail_loc=0
16670         df $DIR
16671 }
16672 run_test 224a "Don't panic on bulk IO failure"
16673
16674 test_224b() { # LU-1039, MRP-303
16675         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16676
16677         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
16678         cancel_lru_locks osc
16679         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
16680         $LCTL set_param fail_loc=0x515
16681         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
16682         $LCTL set_param fail_loc=0
16683         df $DIR
16684 }
16685 run_test 224b "Don't panic on bulk IO failure"
16686
16687 test_224c() { # LU-6441
16688         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16689         remote_mds_nodsh && skip "remote MDS with nodsh"
16690
16691         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
16692         save_writethrough $p
16693         set_cache writethrough on
16694
16695         local pages_per_rpc=$($LCTL get_param osc.*.max_pages_per_rpc)
16696         local at_max=$($LCTL get_param -n at_max)
16697         local timeout=$($LCTL get_param -n timeout)
16698         local test_at="at_max"
16699         local param_at="$FSNAME.sys.at_max"
16700         local test_timeout="timeout"
16701         local param_timeout="$FSNAME.sys.timeout"
16702
16703         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
16704
16705         set_persistent_param_and_check client "$test_at" "$param_at" 0
16706         set_persistent_param_and_check client "$test_timeout" "$param_timeout" 5
16707
16708         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3 0x520
16709         do_facet ost1 "$LCTL set_param fail_loc=0x520"
16710         $LFS setstripe -c 1 -i 0 $DIR/$tfile
16711         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
16712         sync
16713         do_facet ost1 "$LCTL set_param fail_loc=0"
16714
16715         set_persistent_param_and_check client "$test_at" "$param_at" $at_max
16716         set_persistent_param_and_check client "$test_timeout" "$param_timeout" \
16717                 $timeout
16718
16719         $LCTL set_param -n $pages_per_rpc
16720         restore_lustre_params < $p
16721         rm -f $p
16722 }
16723 run_test 224c "Don't hang if one of md lost during large bulk RPC"
16724
16725 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
16726 test_225a () {
16727         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16728         if [ -z ${MDSSURVEY} ]; then
16729                 skip_env "mds-survey not found"
16730         fi
16731         [ $MDS1_VERSION -ge $(version_code 2.2.51) ] ||
16732                 skip "Need MDS version at least 2.2.51"
16733
16734         local mds=$(facet_host $SINGLEMDS)
16735         local target=$(do_nodes $mds 'lctl dl' |
16736                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
16737
16738         local cmd1="file_count=1000 thrhi=4"
16739         local cmd2="dir_count=2 layer=mdd stripe_count=0"
16740         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
16741         local cmd="$cmd1 $cmd2 $cmd3"
16742
16743         rm -f ${TMP}/mds_survey*
16744         echo + $cmd
16745         eval $cmd || error "mds-survey with zero-stripe failed"
16746         cat ${TMP}/mds_survey*
16747         rm -f ${TMP}/mds_survey*
16748 }
16749 run_test 225a "Metadata survey sanity with zero-stripe"
16750
16751 test_225b () {
16752         if [ -z ${MDSSURVEY} ]; then
16753                 skip_env "mds-survey not found"
16754         fi
16755         [ $MDS1_VERSION -ge $(version_code 2.2.51) ] ||
16756                 skip "Need MDS version at least 2.2.51"
16757         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16758         remote_mds_nodsh && skip "remote MDS with nodsh"
16759         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
16760                 skip_env "Need to mount OST to test"
16761         fi
16762
16763         local mds=$(facet_host $SINGLEMDS)
16764         local target=$(do_nodes $mds 'lctl dl' |
16765                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
16766
16767         local cmd1="file_count=1000 thrhi=4"
16768         local cmd2="dir_count=2 layer=mdd stripe_count=1"
16769         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
16770         local cmd="$cmd1 $cmd2 $cmd3"
16771
16772         rm -f ${TMP}/mds_survey*
16773         echo + $cmd
16774         eval $cmd || error "mds-survey with stripe_count failed"
16775         cat ${TMP}/mds_survey*
16776         rm -f ${TMP}/mds_survey*
16777 }
16778 run_test 225b "Metadata survey sanity with stripe_count = 1"
16779
16780 mcreate_path2fid () {
16781         local mode=$1
16782         local major=$2
16783         local minor=$3
16784         local name=$4
16785         local desc=$5
16786         local path=$DIR/$tdir/$name
16787         local fid
16788         local rc
16789         local fid_path
16790
16791         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
16792                 error "cannot create $desc"
16793
16794         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
16795         rc=$?
16796         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
16797
16798         fid_path=$($LFS fid2path $MOUNT $fid)
16799         rc=$?
16800         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
16801
16802         [ "$path" == "$fid_path" ] ||
16803                 error "fid2path returned $fid_path, expected $path"
16804
16805         echo "pass with $path and $fid"
16806 }
16807
16808 test_226a () {
16809         rm -rf $DIR/$tdir
16810         mkdir -p $DIR/$tdir
16811
16812         mcreate_path2fid 0010666 0 0 fifo "FIFO"
16813         mcreate_path2fid 0020666 1 3 null "character special file (null)"
16814         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
16815         mcreate_path2fid 0040666 0 0 dir "directory"
16816         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
16817         mcreate_path2fid 0100666 0 0 file "regular file"
16818         mcreate_path2fid 0120666 0 0 link "symbolic link"
16819         mcreate_path2fid 0140666 0 0 sock "socket"
16820 }
16821 run_test 226a "call path2fid and fid2path on files of all type"
16822
16823 test_226b () {
16824         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
16825
16826         local MDTIDX=1
16827
16828         rm -rf $DIR/$tdir
16829         mkdir -p $DIR/$tdir
16830         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
16831                 error "create remote directory failed"
16832         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
16833         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
16834                                 "character special file (null)"
16835         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
16836                                 "character special file (no device)"
16837         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
16838         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
16839                                 "block special file (loop)"
16840         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
16841         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
16842         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
16843 }
16844 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
16845
16846 # LU-1299 Executing or running ldd on a truncated executable does not
16847 # cause an out-of-memory condition.
16848 test_227() {
16849         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16850         [ -z "$(which ldd)" ] && skip_env "should have ldd tool"
16851
16852         dd if=$(which date) of=$MOUNT/date bs=1k count=1
16853         chmod +x $MOUNT/date
16854
16855         $MOUNT/date > /dev/null
16856         ldd $MOUNT/date > /dev/null
16857         rm -f $MOUNT/date
16858 }
16859 run_test 227 "running truncated executable does not cause OOM"
16860
16861 # LU-1512 try to reuse idle OI blocks
16862 test_228a() {
16863         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16864         remote_mds_nodsh && skip "remote MDS with nodsh"
16865         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
16866
16867         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
16868         local myDIR=$DIR/$tdir
16869
16870         mkdir -p $myDIR
16871         #define OBD_FAIL_SEQ_EXHAUST             0x1002
16872         $LCTL set_param fail_loc=0x80001002
16873         createmany -o $myDIR/t- 10000
16874         $LCTL set_param fail_loc=0
16875         # The guard is current the largest FID holder
16876         touch $myDIR/guard
16877         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
16878                     tr -d '[')
16879         local IDX=$(($SEQ % 64))
16880
16881         do_facet $SINGLEMDS sync
16882         # Make sure journal flushed.
16883         sleep 6
16884         local blk1=$(do_facet $SINGLEMDS \
16885                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16886                      grep Blockcount | awk '{print $4}')
16887
16888         # Remove old files, some OI blocks will become idle.
16889         unlinkmany $myDIR/t- 10000
16890         # Create new files, idle OI blocks should be reused.
16891         createmany -o $myDIR/t- 2000
16892         do_facet $SINGLEMDS sync
16893         # Make sure journal flushed.
16894         sleep 6
16895         local blk2=$(do_facet $SINGLEMDS \
16896                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16897                      grep Blockcount | awk '{print $4}')
16898
16899         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
16900 }
16901 run_test 228a "try to reuse idle OI blocks"
16902
16903 test_228b() {
16904         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16905         remote_mds_nodsh && skip "remote MDS with nodsh"
16906         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
16907
16908         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
16909         local myDIR=$DIR/$tdir
16910
16911         mkdir -p $myDIR
16912         #define OBD_FAIL_SEQ_EXHAUST             0x1002
16913         $LCTL set_param fail_loc=0x80001002
16914         createmany -o $myDIR/t- 10000
16915         $LCTL set_param fail_loc=0
16916         # The guard is current the largest FID holder
16917         touch $myDIR/guard
16918         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
16919                     tr -d '[')
16920         local IDX=$(($SEQ % 64))
16921
16922         do_facet $SINGLEMDS sync
16923         # Make sure journal flushed.
16924         sleep 6
16925         local blk1=$(do_facet $SINGLEMDS \
16926                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16927                      grep Blockcount | awk '{print $4}')
16928
16929         # Remove old files, some OI blocks will become idle.
16930         unlinkmany $myDIR/t- 10000
16931
16932         # stop the MDT
16933         stop $SINGLEMDS || error "Fail to stop MDT."
16934         # remount the MDT
16935         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
16936
16937         df $MOUNT || error "Fail to df."
16938         # Create new files, idle OI blocks should be reused.
16939         createmany -o $myDIR/t- 2000
16940         do_facet $SINGLEMDS sync
16941         # Make sure journal flushed.
16942         sleep 6
16943         local blk2=$(do_facet $SINGLEMDS \
16944                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16945                      grep Blockcount | awk '{print $4}')
16946
16947         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
16948 }
16949 run_test 228b "idle OI blocks can be reused after MDT restart"
16950
16951 #LU-1881
16952 test_228c() {
16953         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16954         remote_mds_nodsh && skip "remote MDS with nodsh"
16955         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
16956
16957         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
16958         local myDIR=$DIR/$tdir
16959
16960         mkdir -p $myDIR
16961         #define OBD_FAIL_SEQ_EXHAUST             0x1002
16962         $LCTL set_param fail_loc=0x80001002
16963         # 20000 files can guarantee there are index nodes in the OI file
16964         createmany -o $myDIR/t- 20000
16965         $LCTL set_param fail_loc=0
16966         # The guard is current the largest FID holder
16967         touch $myDIR/guard
16968         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
16969                     tr -d '[')
16970         local IDX=$(($SEQ % 64))
16971
16972         do_facet $SINGLEMDS sync
16973         # Make sure journal flushed.
16974         sleep 6
16975         local blk1=$(do_facet $SINGLEMDS \
16976                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16977                      grep Blockcount | awk '{print $4}')
16978
16979         # Remove old files, some OI blocks will become idle.
16980         unlinkmany $myDIR/t- 20000
16981         rm -f $myDIR/guard
16982         # The OI file should become empty now
16983
16984         # Create new files, idle OI blocks should be reused.
16985         createmany -o $myDIR/t- 2000
16986         do_facet $SINGLEMDS sync
16987         # Make sure journal flushed.
16988         sleep 6
16989         local blk2=$(do_facet $SINGLEMDS \
16990                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16991                      grep Blockcount | awk '{print $4}')
16992
16993         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
16994 }
16995 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
16996
16997 test_229() { # LU-2482, LU-3448
16998         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16999         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
17000         [ $MDS1_VERSION -lt $(version_code 2.4.53) ] &&
17001                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53"
17002
17003         rm -f $DIR/$tfile
17004
17005         # Create a file with a released layout and stripe count 2.
17006         $MULTIOP $DIR/$tfile H2c ||
17007                 error "failed to create file with released layout"
17008
17009         $LFS getstripe -v $DIR/$tfile
17010
17011         local pattern=$($LFS getstripe -L $DIR/$tfile)
17012         [ X"$pattern" = X"released" ] || error "pattern error ($pattern)"
17013
17014         local stripe_count=$($LFS getstripe -c $DIR/$tfile) ||
17015                 error "getstripe"
17016         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
17017         stat $DIR/$tfile || error "failed to stat released file"
17018
17019         chown $RUNAS_ID $DIR/$tfile ||
17020                 error "chown $RUNAS_ID $DIR/$tfile failed"
17021
17022         chgrp $RUNAS_ID $DIR/$tfile ||
17023                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
17024
17025         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
17026         rm $DIR/$tfile || error "failed to remove released file"
17027 }
17028 run_test 229 "getstripe/stat/rm/attr changes work on released files"
17029
17030 test_230a() {
17031         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17032         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17033         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17034                 skip "Need MDS version at least 2.11.52"
17035
17036         local MDTIDX=1
17037
17038         test_mkdir $DIR/$tdir
17039         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
17040         local mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230_local)
17041         [ $mdt_idx -ne 0 ] &&
17042                 error "create local directory on wrong MDT $mdt_idx"
17043
17044         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
17045                         error "create remote directory failed"
17046         local mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230)
17047         [ $mdt_idx -ne $MDTIDX ] &&
17048                 error "create remote directory on wrong MDT $mdt_idx"
17049
17050         createmany -o $DIR/$tdir/test_230/t- 10 ||
17051                 error "create files on remote directory failed"
17052         mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230/t-0)
17053         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
17054         rm -r $DIR/$tdir || error "unlink remote directory failed"
17055 }
17056 run_test 230a "Create remote directory and files under the remote directory"
17057
17058 test_230b() {
17059         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17060         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17061         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17062                 skip "Need MDS version at least 2.11.52"
17063
17064         local MDTIDX=1
17065         local mdt_index
17066         local i
17067         local file
17068         local pid
17069         local stripe_count
17070         local migrate_dir=$DIR/$tdir/migrate_dir
17071         local other_dir=$DIR/$tdir/other_dir
17072
17073         test_mkdir $DIR/$tdir
17074         test_mkdir -i0 -c1 $migrate_dir
17075         test_mkdir -i0 -c1 $other_dir
17076         for ((i=0; i<10; i++)); do
17077                 mkdir -p $migrate_dir/dir_${i}
17078                 createmany -o $migrate_dir/dir_${i}/f 10 ||
17079                         error "create files under remote dir failed $i"
17080         done
17081
17082         cp /etc/passwd $migrate_dir/$tfile
17083         cp /etc/passwd $other_dir/$tfile
17084         chattr +SAD $migrate_dir
17085         chattr +SAD $migrate_dir/$tfile
17086
17087         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
17088         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
17089         local old_dir_mode=$(stat -c%f $migrate_dir)
17090         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
17091
17092         mkdir -p $migrate_dir/dir_default_stripe2
17093         $LFS setstripe -c 2 $migrate_dir/dir_default_stripe2
17094         $LFS setstripe -c 2 $migrate_dir/${tfile}_stripe2
17095
17096         mkdir -p $other_dir
17097         ln $migrate_dir/$tfile $other_dir/luna
17098         ln $migrate_dir/$tfile $migrate_dir/sofia
17099         ln $other_dir/$tfile $migrate_dir/david
17100         ln -s $migrate_dir/$tfile $other_dir/zachary
17101         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
17102         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
17103
17104         local len
17105         local lnktgt
17106
17107         # inline symlink
17108         for len in 58 59 60; do
17109                 lnktgt=$(str_repeat 'l' $len)
17110                 touch $migrate_dir/$lnktgt
17111                 ln -s $lnktgt $migrate_dir/${len}char_ln
17112         done
17113
17114         # PATH_MAX
17115         for len in 4094 4095; do
17116                 lnktgt=$(str_repeat 'l' $len)
17117                 ln -s $lnktgt $migrate_dir/${len}char_ln
17118         done
17119
17120         # NAME_MAX
17121         for len in 254 255; do
17122                 touch $migrate_dir/$(str_repeat 'l' $len)
17123         done
17124
17125         $LFS migrate -m $MDTIDX $migrate_dir ||
17126                 error "fails on migrating remote dir to MDT1"
17127
17128         echo "migratate to MDT1, then checking.."
17129         for ((i = 0; i < 10; i++)); do
17130                 for file in $(find $migrate_dir/dir_${i}); do
17131                         mdt_index=$($LFS getstripe -m $file)
17132                         # broken symlink getstripe will fail
17133                         [ $mdt_index -ne $MDTIDX ] && stat -L $file &&
17134                                 error "$file is not on MDT${MDTIDX}"
17135                 done
17136         done
17137
17138         # the multiple link file should still in MDT0
17139         mdt_index=$($LFS getstripe -m $migrate_dir/$tfile)
17140         [ $mdt_index == 0 ] ||
17141                 error "$file is not on MDT${MDTIDX}"
17142
17143         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
17144         [ "$old_dir_flag" = "$new_dir_flag" ] ||
17145                 error " expect $old_dir_flag get $new_dir_flag"
17146
17147         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
17148         [ "$old_file_flag" = "$new_file_flag" ] ||
17149                 error " expect $old_file_flag get $new_file_flag"
17150
17151         local new_dir_mode=$(stat -c%f $migrate_dir)
17152         [ "$old_dir_mode" = "$new_dir_mode" ] ||
17153                 error "expect mode $old_dir_mode get $new_dir_mode"
17154
17155         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
17156         [ "$old_file_mode" = "$new_file_mode" ] ||
17157                 error "expect mode $old_file_mode get $new_file_mode"
17158
17159         diff /etc/passwd $migrate_dir/$tfile ||
17160                 error "$tfile different after migration"
17161
17162         diff /etc/passwd $other_dir/luna ||
17163                 error "luna different after migration"
17164
17165         diff /etc/passwd $migrate_dir/sofia ||
17166                 error "sofia different after migration"
17167
17168         diff /etc/passwd $migrate_dir/david ||
17169                 error "david different after migration"
17170
17171         diff /etc/passwd $other_dir/zachary ||
17172                 error "zachary different after migration"
17173
17174         diff /etc/passwd $migrate_dir/${tfile}_ln ||
17175                 error "${tfile}_ln different after migration"
17176
17177         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
17178                 error "${tfile}_ln_other different after migration"
17179
17180         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
17181         [ $stripe_count = 2 ] ||
17182                 error "dir strpe_count $d != 2 after migration."
17183
17184         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
17185         [ $stripe_count = 2 ] ||
17186                 error "file strpe_count $d != 2 after migration."
17187
17188         #migrate back to MDT0
17189         MDTIDX=0
17190
17191         $LFS migrate -m $MDTIDX $migrate_dir ||
17192                 error "fails on migrating remote dir to MDT0"
17193
17194         echo "migrate back to MDT0, checking.."
17195         for file in $(find $migrate_dir); do
17196                 mdt_index=$($LFS getstripe -m $file)
17197                 [ $mdt_index -ne $MDTIDX ] && stat -L $file &&
17198                         error "$file is not on MDT${MDTIDX}"
17199         done
17200
17201         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
17202         [ "$old_dir_flag" = "$new_dir_flag" ] ||
17203                 error " expect $old_dir_flag get $new_dir_flag"
17204
17205         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
17206         [ "$old_file_flag" = "$new_file_flag" ] ||
17207                 error " expect $old_file_flag get $new_file_flag"
17208
17209         local new_dir_mode=$(stat -c%f $migrate_dir)
17210         [ "$old_dir_mode" = "$new_dir_mode" ] ||
17211                 error "expect mode $old_dir_mode get $new_dir_mode"
17212
17213         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
17214         [ "$old_file_mode" = "$new_file_mode" ] ||
17215                 error "expect mode $old_file_mode get $new_file_mode"
17216
17217         diff /etc/passwd ${migrate_dir}/$tfile ||
17218                 error "$tfile different after migration"
17219
17220         diff /etc/passwd ${other_dir}/luna ||
17221                 error "luna different after migration"
17222
17223         diff /etc/passwd ${migrate_dir}/sofia ||
17224                 error "sofia different after migration"
17225
17226         diff /etc/passwd ${other_dir}/zachary ||
17227                 error "zachary different after migration"
17228
17229         diff /etc/passwd $migrate_dir/${tfile}_ln ||
17230                 error "${tfile}_ln different after migration"
17231
17232         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
17233                 error "${tfile}_ln_other different after migration"
17234
17235         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
17236         [ $stripe_count = 2 ] ||
17237                 error "dir strpe_count $d != 2 after migration."
17238
17239         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
17240         [ $stripe_count = 2 ] ||
17241                 error "file strpe_count $d != 2 after migration."
17242
17243         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17244 }
17245 run_test 230b "migrate directory"
17246
17247 test_230c() {
17248         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17249         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17250         remote_mds_nodsh && skip "remote MDS with nodsh"
17251         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17252                 skip "Need MDS version at least 2.11.52"
17253
17254         local MDTIDX=1
17255         local total=3
17256         local mdt_index
17257         local file
17258         local migrate_dir=$DIR/$tdir/migrate_dir
17259
17260         #If migrating directory fails in the middle, all entries of
17261         #the directory is still accessiable.
17262         test_mkdir $DIR/$tdir
17263         test_mkdir -i0 -c1 $migrate_dir
17264         test_mkdir -i1 -c1 $DIR/$tdir/remote_dir
17265         stat $migrate_dir
17266         createmany -o $migrate_dir/f $total ||
17267                 error "create files under ${migrate_dir} failed"
17268
17269         # fail after migrating top dir, and this will fail only once, so the
17270         # first sub file migration will fail (currently f3), others succeed.
17271         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
17272         do_facet mds1 lctl set_param fail_loc=0x1801
17273         local t=$(ls $migrate_dir | wc -l)
17274         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
17275                 error "migrate should fail"
17276         local u=$(ls $migrate_dir | wc -l)
17277         [ "$u" == "$t" ] || error "$u != $t during migration"
17278
17279         # add new dir/file should succeed
17280         mkdir $migrate_dir/dir ||
17281                 error "mkdir failed under migrating directory"
17282         touch $migrate_dir/file ||
17283                 error "create file failed under migrating directory"
17284
17285         # add file with existing name should fail
17286         for file in $migrate_dir/f*; do
17287                 stat $file > /dev/null || error "stat $file failed"
17288                 $OPENFILE -f O_CREAT:O_EXCL $file &&
17289                         error "open(O_CREAT|O_EXCL) $file should fail"
17290                 $MULTIOP $file m && error "create $file should fail"
17291                 touch $DIR/$tdir/remote_dir/$tfile ||
17292                         error "touch $tfile failed"
17293                 ln $DIR/$tdir/remote_dir/$tfile $file &&
17294                         error "link $file should fail"
17295                 mdt_index=$($LFS getstripe -m $file)
17296                 if [ $mdt_index == 0 ]; then
17297                         # file failed to migrate is not allowed to rename to
17298                         mv $DIR/$tdir/remote_dir/$tfile $file &&
17299                                 error "rename to $file should fail"
17300                 else
17301                         mv $DIR/$tdir/remote_dir/$tfile $file ||
17302                                 error "rename to $file failed"
17303                 fi
17304                 echo hello >> $file || error "write $file failed"
17305         done
17306
17307         # resume migration with different options should fail
17308         $LFS migrate -m 0 $migrate_dir &&
17309                 error "migrate -m 0 $migrate_dir should fail"
17310
17311         $LFS migrate -m $MDTIDX -c 2 $migrate_dir &&
17312                 error "migrate -c 2 $migrate_dir should fail"
17313
17314         # resume migration should succeed
17315         $LFS migrate -m $MDTIDX $migrate_dir ||
17316                 error "migrate $migrate_dir failed"
17317
17318         echo "Finish migration, then checking.."
17319         for file in $(find $migrate_dir); do
17320                 mdt_index=$($LFS getstripe -m $file)
17321                 [ $mdt_index == $MDTIDX ] ||
17322                         error "$file is not on MDT${MDTIDX}"
17323         done
17324
17325         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17326 }
17327 run_test 230c "check directory accessiblity if migration failed"
17328
17329 test_230d() {
17330         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17331         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17332         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17333                 skip "Need MDS version at least 2.11.52"
17334         # LU-11235
17335         [ "$mds1_FSTYPE" == "zfs" ] && skip "skip ZFS backend"
17336
17337         local migrate_dir=$DIR/$tdir/migrate_dir
17338         local old_index
17339         local new_index
17340         local old_count
17341         local new_count
17342         local new_hash
17343         local mdt_index
17344         local i
17345         local j
17346
17347         old_index=$((RANDOM % MDSCOUNT))
17348         old_count=$((MDSCOUNT - old_index))
17349         new_index=$((RANDOM % MDSCOUNT))
17350         new_count=$((MDSCOUNT - new_index))
17351         new_hash=1 # for all_char
17352
17353         [ $old_count -gt 1 ] && old_count=$((old_count - RANDOM % old_count))
17354         [ $new_count -gt 1 ] && new_count=$((new_count - RANDOM % new_count))
17355
17356         test_mkdir $DIR/$tdir
17357         test_mkdir -i $old_index -c $old_count $migrate_dir
17358
17359         for ((i=0; i<100; i++)); do
17360                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
17361                 createmany -o $migrate_dir/dir_${i}/f 100 ||
17362                         error "create files under remote dir failed $i"
17363         done
17364
17365         echo -n "Migrate from MDT$old_index "
17366         [ $old_count -gt 1 ] && echo -n "... MDT$((old_index + old_count - 1)) "
17367         echo -n "to MDT$new_index"
17368         [ $new_count -gt 1 ] && echo -n " ... MDT$((new_index + new_count - 1))"
17369         echo
17370
17371         echo "$LFS migrate -m$new_index -c$new_count -H $new_hash $migrate_dir"
17372         $LFS migrate -m $new_index -c $new_count -H $new_hash $migrate_dir ||
17373                 error "migrate remote dir error"
17374
17375         echo "Finish migration, then checking.."
17376         for file in $(find $migrate_dir); do
17377                 mdt_index=$($LFS getstripe -m $file)
17378                 if [ $mdt_index -lt $new_index ] ||
17379                    [ $mdt_index -gt $((new_index + new_count - 1)) ]; then
17380                         error "$file is on MDT$mdt_index"
17381                 fi
17382         done
17383
17384         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17385 }
17386 run_test 230d "check migrate big directory"
17387
17388 test_230e() {
17389         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17390         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17391         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17392                 skip "Need MDS version at least 2.11.52"
17393
17394         local i
17395         local j
17396         local a_fid
17397         local b_fid
17398
17399         mkdir -p $DIR/$tdir
17400         mkdir $DIR/$tdir/migrate_dir
17401         mkdir $DIR/$tdir/other_dir
17402         touch $DIR/$tdir/migrate_dir/a
17403         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
17404         ls $DIR/$tdir/other_dir
17405
17406         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
17407                 error "migrate dir fails"
17408
17409         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
17410         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
17411
17412         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17413         [ $mdt_index == 0 ] || error "a is not on MDT0"
17414
17415         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
17416                 error "migrate dir fails"
17417
17418         mdt_index=$($LFS getstripe -m $DIR/$tdir/other_dir)
17419         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
17420
17421         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17422         [ $mdt_index == 1 ] || error "a is not on MDT1"
17423
17424         mdt_index=$($LFS getstripe -m $DIR/$tdir/other_dir/b)
17425         [ $mdt_index == 1 ] || error "b is not on MDT1"
17426
17427         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
17428         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
17429
17430         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
17431
17432         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17433 }
17434 run_test 230e "migrate mulitple local link files"
17435
17436 test_230f() {
17437         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17438         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17439         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17440                 skip "Need MDS version at least 2.11.52"
17441
17442         local a_fid
17443         local ln_fid
17444
17445         mkdir -p $DIR/$tdir
17446         mkdir $DIR/$tdir/migrate_dir
17447         $LFS mkdir -i1 $DIR/$tdir/other_dir
17448         touch $DIR/$tdir/migrate_dir/a
17449         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
17450         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
17451         ls $DIR/$tdir/other_dir
17452
17453         # a should be migrated to MDT1, since no other links on MDT0
17454         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
17455                 error "#1 migrate dir fails"
17456         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
17457         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
17458         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17459         [ $mdt_index == 1 ] || error "a is not on MDT1"
17460
17461         # a should stay on MDT1, because it is a mulitple link file
17462         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
17463                 error "#2 migrate dir fails"
17464         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17465         [ $mdt_index == 1 ] || error "a is not on MDT1"
17466
17467         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
17468                 error "#3 migrate dir fails"
17469
17470         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
17471         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
17472         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
17473
17474         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
17475         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
17476
17477         # a should be migrated to MDT0, since no other links on MDT1
17478         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
17479                 error "#4 migrate dir fails"
17480         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17481         [ $mdt_index == 0 ] || error "a is not on MDT0"
17482
17483         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17484 }
17485 run_test 230f "migrate mulitple remote link files"
17486
17487 test_230g() {
17488         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17489         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17490         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17491                 skip "Need MDS version at least 2.11.52"
17492
17493         mkdir -p $DIR/$tdir/migrate_dir
17494
17495         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
17496                 error "migrating dir to non-exist MDT succeeds"
17497         true
17498 }
17499 run_test 230g "migrate dir to non-exist MDT"
17500
17501 test_230h() {
17502         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17503         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17504         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17505                 skip "Need MDS version at least 2.11.52"
17506
17507         local mdt_index
17508
17509         mkdir -p $DIR/$tdir/migrate_dir
17510
17511         $LFS migrate -m1 $DIR &&
17512                 error "migrating mountpoint1 should fail"
17513
17514         $LFS migrate -m1 $DIR/$tdir/.. &&
17515                 error "migrating mountpoint2 should fail"
17516
17517         # same as mv
17518         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. &&
17519                 error "migrating $tdir/migrate_dir/.. should fail"
17520
17521         true
17522 }
17523 run_test 230h "migrate .. and root"
17524
17525 test_230i() {
17526         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17527         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17528         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17529                 skip "Need MDS version at least 2.11.52"
17530
17531         mkdir -p $DIR/$tdir/migrate_dir
17532
17533         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
17534                 error "migration fails with a tailing slash"
17535
17536         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
17537                 error "migration fails with two tailing slashes"
17538 }
17539 run_test 230i "lfs migrate -m tolerates trailing slashes"
17540
17541 test_230j() {
17542         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17543         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17544                 skip "Need MDS version at least 2.11.52"
17545
17546         $LFS mkdir -m 0 -c 1 $DIR/$tdir || error "mkdir $tdir failed"
17547         $LFS setstripe -E 1M -L mdt $DIR/$tdir/$tfile ||
17548                 error "create $tfile failed"
17549         cat /etc/passwd > $DIR/$tdir/$tfile
17550
17551         $LFS migrate -m 1 $DIR/$tdir
17552
17553         cmp /etc/passwd $DIR/$tdir/$tfile ||
17554                 error "DoM file mismatch after migration"
17555 }
17556 run_test 230j "DoM file data not changed after dir migration"
17557
17558 test_230k() {
17559         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs"
17560         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
17561                 skip "Need MDS version at least 2.11.56"
17562
17563         local total=20
17564         local files_on_starting_mdt=0
17565
17566         $LFS mkdir -i -1 -c 2 $DIR/$tdir || error "mkdir failed"
17567         $LFS getdirstripe $DIR/$tdir
17568         for i in $(seq $total); do
17569                 echo $((i*i - i)) > $DIR/$tdir/$tfile.$i || error "write failed"
17570                 [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 0 ]] &&
17571                         files_on_starting_mdt=$((files_on_starting_mdt + 1))
17572         done
17573
17574         echo "$files_on_starting_mdt files on MDT0"
17575
17576         $LFS migrate -m 1,3 $DIR/$tdir || error "migrate -m 1,3 failed"
17577         $LFS getdirstripe $DIR/$tdir
17578
17579         files_on_starting_mdt=0
17580         for i in $(seq $total); do
17581                 $(echo $((i*i - i)) | cmp $DIR/$tdir/$tfile.$i -) ||
17582                         error "file $tfile.$i mismatch after migration"
17583                 [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 1 ]] &&
17584                         files_on_starting_mdt=$((files_on_starting_mdt + 1))
17585         done
17586
17587         echo "$files_on_starting_mdt files on MDT1 after migration"
17588         [[ $files_on_starting_mdt -eq $total ]] && error "all files on MDT1"
17589
17590         $LFS migrate -m 0 -c 2 $DIR/$tdir || error "migrate -m 0 -c 2 failed"
17591         $LFS getdirstripe $DIR/$tdir
17592
17593         files_on_starting_mdt=0
17594         for i in $(seq $total); do
17595                 $(echo $((i*i - i)) | cmp $DIR/$tdir/$tfile.$i -) ||
17596                         error "file $tfile.$i mismatch after 2nd migration"
17597                 [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 0 ]] &&
17598                         files_on_starting_mdt=$((files_on_starting_mdt + 1))
17599         done
17600
17601         echo "$files_on_starting_mdt files on MDT0 after 2nd migration"
17602         [[ $files_on_starting_mdt -eq $total ]] && error "all files on MDT0"
17603
17604         true
17605 }
17606 run_test 230k "file data not changed after dir migration"
17607
17608 test_230l() {
17609         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17610         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
17611                 skip "Need MDS version at least 2.11.56"
17612
17613         $LFS mkdir -i 0 -c 1 $DIR/$tdir || error "mkdir failed"
17614         createmany -o $DIR/$tdir/f___________________________________ 1000 ||
17615                 error "create files under remote dir failed $i"
17616         $LFS migrate -m 1 $DIR/$tdir || error "migrate failed"
17617 }
17618 run_test 230l "readdir between MDTs won't crash"
17619
17620 test_230m() {
17621         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17622         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
17623                 skip "Need MDS version at least 2.11.56"
17624
17625         local MDTIDX=1
17626         local mig_dir=$DIR/$tdir/migrate_dir
17627         local longstr="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
17628         local shortstr="b"
17629         local val
17630
17631         echo "Creating files and dirs with xattrs"
17632         test_mkdir $DIR/$tdir
17633         test_mkdir -i0 -c1 $mig_dir
17634         mkdir $mig_dir/dir
17635         setfattr -n user.attr1 -v $longstr $mig_dir/dir ||
17636                 error "cannot set xattr attr1 on dir"
17637         setfattr -n user.attr2 -v $shortstr $mig_dir/dir ||
17638                 error "cannot set xattr attr2 on dir"
17639         touch $mig_dir/dir/f0
17640         setfattr -n user.attr1 -v $longstr $mig_dir/dir/f0 ||
17641                 error "cannot set xattr attr1 on file"
17642         setfattr -n user.attr2 -v $shortstr $mig_dir/dir/f0 ||
17643                 error "cannot set xattr attr2 on file"
17644         sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
17645         val=$(getfattr --only-values -n user.attr1 $mig_dir/dir 2>/dev/null)
17646         [ "$val" = $longstr ] || error "xattr attr1 not set properly on dir"
17647         val=$(getfattr --only-values -n user.attr2 $mig_dir/dir 2>/dev/null)
17648         [ "$val" = $shortstr ] || error "xattr attr2 not set properly on dir"
17649         val=$(getfattr --only-values -n user.attr1 $mig_dir/dir/f0 2>/dev/null)
17650         [ "$val" = $longstr ] || error "xattr attr1 not set properly on file"
17651         val=$(getfattr --only-values -n user.attr2 $mig_dir/dir/f0 2>/dev/null)
17652         [ "$val" = $shortstr ] || error "xattr attr2 not set properly on file"
17653
17654         echo "Migrating to MDT1"
17655         $LFS migrate -m $MDTIDX $mig_dir ||
17656                 error "fails on migrating dir to MDT1"
17657
17658         sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
17659         echo "Checking xattrs"
17660         val=$(getfattr --only-values -n user.attr1 $mig_dir/dir 2>/dev/null)
17661         [ "$val" = $longstr ] ||
17662                 error "expecting xattr1 $longstr on dir, found $val"
17663         val=$(getfattr --only-values -n user.attr2 $mig_dir/dir 2>/dev/null)
17664         [ "$val" = $shortstr ] ||
17665                 error "expecting xattr2 $shortstr on dir, found $val"
17666         val=$(getfattr --only-values -n user.attr1 $mig_dir/dir/f0 2>/dev/null)
17667         [ "$val" = $longstr ] ||
17668                 error "expecting xattr1 $longstr on file, found $val"
17669         val=$(getfattr --only-values -n user.attr2 $mig_dir/dir/f0 2>/dev/null)
17670         [ "$val" = $shortstr ] ||
17671                 error "expecting xattr2 $shortstr on file, found $val"
17672 }
17673 run_test 230m "xattrs not changed after dir migration"
17674
17675 test_230n() {
17676         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17677         [[ $MDS1_VERSION -ge $(version_code 2.13.53) ]] ||
17678                 skip "Need MDS version at least 2.13.53"
17679
17680         $LFS mkdir -i 0 $DIR/$tdir || error "mkdir $tdir failed"
17681         cat /etc/hosts > $DIR/$tdir/$tfile
17682         $LFS mirror extend -N1 $DIR/$tdir/$tfile || error "Mirroring failed"
17683         $LFS migrate -m 1 $DIR/$tdir || error "Migration failed"
17684
17685         cmp /etc/hosts $DIR/$tdir/$tfile ||
17686                 error "File data mismatch after migration"
17687 }
17688 run_test 230n "Dir migration with mirrored file"
17689
17690 test_231a()
17691 {
17692         # For simplicity this test assumes that max_pages_per_rpc
17693         # is the same across all OSCs
17694         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
17695         local bulk_size=$((max_pages * PAGE_SIZE))
17696         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
17697                                        head -n 1)
17698
17699         mkdir -p $DIR/$tdir
17700         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
17701                 error "failed to set stripe with -S ${brw_size}M option"
17702
17703         # clear the OSC stats
17704         $LCTL set_param osc.*.stats=0 &>/dev/null
17705         stop_writeback
17706
17707         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
17708         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
17709                 oflag=direct &>/dev/null || error "dd failed"
17710
17711         sync; sleep 1; sync # just to be safe
17712         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
17713         if [ x$nrpcs != "x1" ]; then
17714                 $LCTL get_param osc.*.stats
17715                 error "found $nrpcs ost_write RPCs, not 1 as expected"
17716         fi
17717
17718         start_writeback
17719         # Drop the OSC cache, otherwise we will read from it
17720         cancel_lru_locks osc
17721
17722         # clear the OSC stats
17723         $LCTL set_param osc.*.stats=0 &>/dev/null
17724
17725         # Client reads $bulk_size.
17726         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
17727                 iflag=direct &>/dev/null || error "dd failed"
17728
17729         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
17730         if [ x$nrpcs != "x1" ]; then
17731                 $LCTL get_param osc.*.stats
17732                 error "found $nrpcs ost_read RPCs, not 1 as expected"
17733         fi
17734 }
17735 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
17736
17737 test_231b() {
17738         mkdir -p $DIR/$tdir
17739         local i
17740         for i in {0..1023}; do
17741                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
17742                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
17743                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
17744         done
17745         sync
17746 }
17747 run_test 231b "must not assert on fully utilized OST request buffer"
17748
17749 test_232a() {
17750         mkdir -p $DIR/$tdir
17751         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
17752
17753         #define OBD_FAIL_LDLM_OST_LVB            0x31c
17754         do_facet ost1 $LCTL set_param fail_loc=0x31c
17755
17756         # ignore dd failure
17757         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
17758
17759         do_facet ost1 $LCTL set_param fail_loc=0
17760         umount_client $MOUNT || error "umount failed"
17761         mount_client $MOUNT || error "mount failed"
17762         stop ost1 || error "cannot stop ost1"
17763         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
17764 }
17765 run_test 232a "failed lock should not block umount"
17766
17767 test_232b() {
17768         [ $MDS1_VERSION -ge $(version_code 2.10.58) ] ||
17769                 skip "Need MDS version at least 2.10.58"
17770
17771         mkdir -p $DIR/$tdir
17772         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
17773         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1
17774         sync
17775         cancel_lru_locks osc
17776
17777         #define OBD_FAIL_LDLM_OST_LVB            0x31c
17778         do_facet ost1 $LCTL set_param fail_loc=0x31c
17779
17780         # ignore failure
17781         $LFS data_version $DIR/$tdir/$tfile || true
17782
17783         do_facet ost1 $LCTL set_param fail_loc=0
17784         umount_client $MOUNT || error "umount failed"
17785         mount_client $MOUNT || error "mount failed"
17786         stop ost1 || error "cannot stop ost1"
17787         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
17788 }
17789 run_test 232b "failed data version lock should not block umount"
17790
17791 test_233a() {
17792         [ $MDS1_VERSION -ge $(version_code 2.3.64) ] ||
17793                 skip "Need MDS version at least 2.3.64"
17794         [ -n "$FILESET" ] && skip_env "SKIP due to FILESET set"
17795
17796         local fid=$($LFS path2fid $MOUNT)
17797
17798         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
17799                 error "cannot access $MOUNT using its FID '$fid'"
17800 }
17801 run_test 233a "checking that OBF of the FS root succeeds"
17802
17803 test_233b() {
17804         [ $MDS1_VERSION -ge $(version_code 2.5.90) ] ||
17805                 skip "Need MDS version at least 2.5.90"
17806         [ -n "$FILESET" ] && skip_env "SKIP due to FILESET set"
17807
17808         local fid=$($LFS path2fid $MOUNT/.lustre)
17809
17810         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
17811                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
17812
17813         fid=$($LFS path2fid $MOUNT/.lustre/fid)
17814         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
17815                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
17816 }
17817 run_test 233b "checking that OBF of the FS .lustre succeeds"
17818
17819 test_234() {
17820         local p="$TMP/sanityN-$TESTNAME.parameters"
17821         save_lustre_params client "llite.*.xattr_cache" > $p
17822         lctl set_param llite.*.xattr_cache 1 ||
17823                 skip_env "xattr cache is not supported"
17824
17825         mkdir -p $DIR/$tdir || error "mkdir failed"
17826         touch $DIR/$tdir/$tfile || error "touch failed"
17827         # OBD_FAIL_LLITE_XATTR_ENOMEM
17828         $LCTL set_param fail_loc=0x1405
17829         getfattr -n user.attr $DIR/$tdir/$tfile &&
17830                 error "getfattr should have failed with ENOMEM"
17831         $LCTL set_param fail_loc=0x0
17832         rm -rf $DIR/$tdir
17833
17834         restore_lustre_params < $p
17835         rm -f $p
17836 }
17837 run_test 234 "xattr cache should not crash on ENOMEM"
17838
17839 test_235() {
17840         [ $MDS1_VERSION -lt $(version_code 2.4.52) ] &&
17841                 skip "Need MDS version at least 2.4.52"
17842
17843         flock_deadlock $DIR/$tfile
17844         local RC=$?
17845         case $RC in
17846                 0)
17847                 ;;
17848                 124) error "process hangs on a deadlock"
17849                 ;;
17850                 *) error "error executing flock_deadlock $DIR/$tfile"
17851                 ;;
17852         esac
17853 }
17854 run_test 235 "LU-1715: flock deadlock detection does not work properly"
17855
17856 #LU-2935
17857 test_236() {
17858         check_swap_layouts_support
17859
17860         local ref1=/etc/passwd
17861         local ref2=/etc/group
17862         local file1=$DIR/$tdir/f1
17863         local file2=$DIR/$tdir/f2
17864
17865         test_mkdir -c1 $DIR/$tdir
17866         $LFS setstripe -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
17867         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
17868         $LFS setstripe -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
17869         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
17870         local fd=$(free_fd)
17871         local cmd="exec $fd<>$file2"
17872         eval $cmd
17873         rm $file2
17874         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
17875                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
17876         cmd="exec $fd>&-"
17877         eval $cmd
17878         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
17879
17880         #cleanup
17881         rm -rf $DIR/$tdir
17882 }
17883 run_test 236 "Layout swap on open unlinked file"
17884
17885 # LU-4659 linkea consistency
17886 test_238() {
17887         [[ $MDS1_VERSION -gt $(version_code 2.5.57) ]] ||
17888                 [[ $MDS1_VERSION -gt $(version_code 2.5.1) &&
17889                    $MDS1_VERSION -lt $(version_code 2.5.50) ]] ||
17890                 skip "Need MDS version at least 2.5.58 or 2.5.2+"
17891
17892         touch $DIR/$tfile
17893         ln $DIR/$tfile $DIR/$tfile.lnk
17894         touch $DIR/$tfile.new
17895         mv $DIR/$tfile.new $DIR/$tfile
17896         local fid1=$($LFS path2fid $DIR/$tfile)
17897         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
17898         local path1=$($LFS fid2path $FSNAME "$fid1")
17899         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
17900         local path2=$($LFS fid2path $FSNAME "$fid2")
17901         [ $tfile.lnk == $path2 ] ||
17902                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
17903         rm -f $DIR/$tfile*
17904 }
17905 run_test 238 "Verify linkea consistency"
17906
17907 test_239A() { # was test_239
17908         [ $MDS1_VERSION -lt $(version_code 2.5.60) ] &&
17909                 skip "Need MDS version at least 2.5.60"
17910
17911         local list=$(comma_list $(mdts_nodes))
17912
17913         mkdir -p $DIR/$tdir
17914         createmany -o $DIR/$tdir/f- 5000
17915         unlinkmany $DIR/$tdir/f- 5000
17916         [ $MDS1_VERSION -gt $(version_code 2.10.4) ] &&
17917                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
17918         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
17919                         osp.*MDT*.sync_in_flight" | calc_sum)
17920         [ "$changes" -eq 0 ] || error "$changes not synced"
17921 }
17922 run_test 239A "osp_sync test"
17923
17924 test_239a() { #LU-5297
17925         remote_mds_nodsh && skip "remote MDS with nodsh"
17926
17927         touch $DIR/$tfile
17928         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
17929         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
17930         chgrp $RUNAS_GID $DIR/$tfile
17931         wait_delete_completed
17932 }
17933 run_test 239a "process invalid osp sync record correctly"
17934
17935 test_239b() { #LU-5297
17936         remote_mds_nodsh && skip "remote MDS with nodsh"
17937
17938         touch $DIR/$tfile1
17939         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
17940         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
17941         chgrp $RUNAS_GID $DIR/$tfile1
17942         wait_delete_completed
17943         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
17944         touch $DIR/$tfile2
17945         chgrp $RUNAS_GID $DIR/$tfile2
17946         wait_delete_completed
17947 }
17948 run_test 239b "process osp sync record with ENOMEM error correctly"
17949
17950 test_240() {
17951         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17952         remote_mds_nodsh && skip "remote MDS with nodsh"
17953
17954         mkdir -p $DIR/$tdir
17955
17956         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
17957                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
17958         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
17959                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
17960
17961         umount_client $MOUNT || error "umount failed"
17962         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
17963         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
17964         mount_client $MOUNT || error "failed to mount client"
17965
17966         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
17967         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
17968 }
17969 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
17970
17971 test_241_bio() {
17972         local count=$1
17973         local bsize=$2
17974
17975         for LOOP in $(seq $count); do
17976                 dd if=$DIR/$tfile of=/dev/null bs=$bsize count=1 2>/dev/null
17977                 cancel_lru_locks $OSC || true
17978         done
17979 }
17980
17981 test_241_dio() {
17982         local count=$1
17983         local bsize=$2
17984
17985         for LOOP in $(seq $1); do
17986                 dd if=$DIR/$tfile of=/dev/null bs=$bsize count=1 iflag=direct \
17987                         2>/dev/null
17988         done
17989 }
17990
17991 test_241a() { # was test_241
17992         local bsize=$PAGE_SIZE
17993
17994         (( bsize < 40960 )) && bsize=40960
17995         dd if=/dev/zero of=$DIR/$tfile count=1 bs=$bsize
17996         ls -la $DIR/$tfile
17997         cancel_lru_locks $OSC
17998         test_241_bio 1000 $bsize &
17999         PID=$!
18000         test_241_dio 1000 $bsize
18001         wait $PID
18002 }
18003 run_test 241a "bio vs dio"
18004
18005 test_241b() {
18006         local bsize=$PAGE_SIZE
18007
18008         (( bsize < 40960 )) && bsize=40960
18009         dd if=/dev/zero of=$DIR/$tfile count=1 bs=$bsize
18010         ls -la $DIR/$tfile
18011         test_241_dio 1000 $bsize &
18012         PID=$!
18013         test_241_dio 1000 $bsize
18014         wait $PID
18015 }
18016 run_test 241b "dio vs dio"
18017
18018 test_242() {
18019         remote_mds_nodsh && skip "remote MDS with nodsh"
18020
18021         mkdir -p $DIR/$tdir
18022         touch $DIR/$tdir/$tfile
18023
18024         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
18025         do_facet mds1 lctl set_param fail_loc=0x105
18026         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
18027
18028         do_facet mds1 lctl set_param fail_loc=0
18029         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
18030 }
18031 run_test 242 "mdt_readpage failure should not cause directory unreadable"
18032
18033 test_243()
18034 {
18035         test_mkdir $DIR/$tdir
18036         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
18037 }
18038 run_test 243 "various group lock tests"
18039
18040 test_244a()
18041 {
18042         test_mkdir $DIR/$tdir
18043         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
18044         sendfile_grouplock $DIR/$tdir/$tfile || \
18045                 error "sendfile+grouplock failed"
18046         rm -rf $DIR/$tdir
18047 }
18048 run_test 244a "sendfile with group lock tests"
18049
18050 test_244b()
18051 {
18052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
18053
18054         local threads=50
18055         local size=$((1024*1024))
18056
18057         test_mkdir $DIR/$tdir
18058         for i in $(seq 1 $threads); do
18059                 local file=$DIR/$tdir/file_$((i / 10))
18060                 $MULTIOP $file OG1234w$size_$((i % 3))w$size_$((i % 4))g1234c &
18061                 local pids[$i]=$!
18062         done
18063         for i in $(seq 1 $threads); do
18064                 wait ${pids[$i]}
18065         done
18066 }
18067 run_test 244b "multi-threaded write with group lock"
18068
18069 test_245() {
18070         local flagname="multi_mod_rpcs"
18071         local connect_data_name="max_mod_rpcs"
18072         local out
18073
18074         # check if multiple modify RPCs flag is set
18075         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
18076                 grep "connect_flags:")
18077         echo "$out"
18078
18079         echo "$out" | grep -qw $flagname
18080         if [ $? -ne 0 ]; then
18081                 echo "connect flag $flagname is not set"
18082                 return
18083         fi
18084
18085         # check if multiple modify RPCs data is set
18086         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
18087         echo "$out"
18088
18089         echo "$out" | grep -qw $connect_data_name ||
18090                 error "import should have connect data $connect_data_name"
18091 }
18092 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
18093
18094 cleanup_247() {
18095         local submount=$1
18096
18097         trap 0
18098         umount_client $submount
18099         rmdir $submount
18100 }
18101
18102 test_247a() {
18103         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
18104                 grep -q subtree ||
18105                 skip_env "Fileset feature is not supported"
18106
18107         local submount=${MOUNT}_$tdir
18108
18109         mkdir $MOUNT/$tdir
18110         mkdir -p $submount || error "mkdir $submount failed"
18111         FILESET="$FILESET/$tdir" mount_client $submount ||
18112                 error "mount $submount failed"
18113         trap "cleanup_247 $submount" EXIT
18114         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
18115         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
18116                 error "read $MOUNT/$tdir/$tfile failed"
18117         cleanup_247 $submount
18118 }
18119 run_test 247a "mount subdir as fileset"
18120
18121 test_247b() {
18122         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
18123                 skip_env "Fileset feature is not supported"
18124
18125         local submount=${MOUNT}_$tdir
18126
18127         rm -rf $MOUNT/$tdir
18128         mkdir -p $submount || error "mkdir $submount failed"
18129         SKIP_FILESET=1
18130         FILESET="$FILESET/$tdir" mount_client $submount &&
18131                 error "mount $submount should fail"
18132         rmdir $submount
18133 }
18134 run_test 247b "mount subdir that dose not exist"
18135
18136 test_247c() {
18137         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
18138                 skip_env "Fileset feature is not supported"
18139
18140         local submount=${MOUNT}_$tdir
18141
18142         mkdir -p $MOUNT/$tdir/dir1
18143         mkdir -p $submount || error "mkdir $submount failed"
18144         trap "cleanup_247 $submount" EXIT
18145         FILESET="$FILESET/$tdir" mount_client $submount ||
18146                 error "mount $submount failed"
18147         local fid=$($LFS path2fid $MOUNT/)
18148         $LFS fid2path $submount $fid && error "fid2path should fail"
18149         cleanup_247 $submount
18150 }
18151 run_test 247c "running fid2path outside root"
18152
18153 test_247d() {
18154         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
18155                 skip "Fileset feature is not supported"
18156
18157         local submount=${MOUNT}_$tdir
18158
18159         mkdir -p $MOUNT/$tdir/dir1
18160         mkdir -p $submount || error "mkdir $submount failed"
18161         FILESET="$FILESET/$tdir" mount_client $submount ||
18162                 error "mount $submount failed"
18163         trap "cleanup_247 $submount" EXIT
18164         local fid=$($LFS path2fid $submount/dir1)
18165         $LFS fid2path $submount $fid || error "fid2path should succeed"
18166         cleanup_247 $submount
18167 }
18168 run_test 247d "running fid2path inside root"
18169
18170 # LU-8037
18171 test_247e() {
18172         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
18173                 grep -q subtree ||
18174                 skip "Fileset feature is not supported"
18175
18176         local submount=${MOUNT}_$tdir
18177
18178         mkdir $MOUNT/$tdir
18179         mkdir -p $submount || error "mkdir $submount failed"
18180         FILESET="$FILESET/.." mount_client $submount &&
18181                 error "mount $submount should fail"
18182         rmdir $submount
18183 }
18184 run_test 247e "mount .. as fileset"
18185
18186 test_248a() {
18187         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
18188         [ -z "$fast_read_sav" ] && skip "no fast read support"
18189
18190         # create a large file for fast read verification
18191         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
18192
18193         # make sure the file is created correctly
18194         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
18195                 { rm -f $DIR/$tfile; skip "file creation error"; }
18196
18197         echo "Test 1: verify that fast read is 4 times faster on cache read"
18198
18199         # small read with fast read enabled
18200         $LCTL set_param -n llite.*.fast_read=1
18201         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
18202                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
18203                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
18204         # small read with fast read disabled
18205         $LCTL set_param -n llite.*.fast_read=0
18206         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
18207                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
18208                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
18209
18210         # verify that fast read is 4 times faster for cache read
18211         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
18212                 error_not_in_vm "fast read was not 4 times faster: " \
18213                            "$t_fast vs $t_slow"
18214
18215         echo "Test 2: verify the performance between big and small read"
18216         $LCTL set_param -n llite.*.fast_read=1
18217
18218         # 1k non-cache read
18219         cancel_lru_locks osc
18220         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
18221                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
18222                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
18223
18224         # 1M non-cache read
18225         cancel_lru_locks osc
18226         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
18227                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
18228                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
18229
18230         # verify that big IO is not 4 times faster than small IO
18231         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
18232                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
18233
18234         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
18235         rm -f $DIR/$tfile
18236 }
18237 run_test 248a "fast read verification"
18238
18239 test_248b() {
18240         # Default short_io_bytes=16384, try both smaller and larger sizes.
18241         # Lustre O_DIRECT read and write needs to be a multiple of PAGE_SIZE.
18242         # 6017024 = 2^12*13*113 = 47008*128 = 11752*512 = 4096*1469 = 53248*113
18243         echo "bs=53248 count=113 normal buffered write"
18244         dd if=/dev/urandom of=$TMP/$tfile.0 bs=53248 count=113 ||
18245                 error "dd of initial data file failed"
18246         stack_trap "rm -f $DIR/$tfile.[0-3] $TMP/$tfile.[0-3]" EXIT
18247
18248         echo "bs=47008 count=128 oflag=dsync normal write $tfile.0"
18249         dd if=$TMP/$tfile.0 of=$DIR/$tfile.0 bs=47008 count=128 oflag=dsync ||
18250                 error "dd with sync normal writes failed"
18251         cmp $TMP/$tfile.0 $DIR/$tfile.0 || error "compare $DIR/$tfile.0 failed"
18252
18253         echo "bs=11752 count=512 oflag=dsync small write $tfile.1"
18254         dd if=$TMP/$tfile.0 of=$DIR/$tfile.1 bs=11752 count=512 oflag=dsync ||
18255                 error "dd with sync small writes failed"
18256         cmp $TMP/$tfile.0 $DIR/$tfile.1 || error "compare $DIR/$tfile.1 failed"
18257
18258         cancel_lru_locks osc
18259
18260         # calculate the small O_DIRECT size and count for the client PAGE_SIZE
18261         local num=$((13 * 113 / (PAGE_SIZE / 4096)))
18262         echo "bs=$PAGE_SIZE count=$num iflag=direct small read $tfile.1"
18263         dd if=$DIR/$tfile.1 of=$TMP/$tfile.1 bs=$PAGE_SIZE count=$num \
18264                 iflag=direct || error "dd with O_DIRECT small read failed"
18265         # adjust bytes checked to handle larger PAGE_SIZE for ARM/PPC
18266         cmp --bytes=$((PAGE_SIZE * num)) $TMP/$tfile.0 $TMP/$tfile.1 ||
18267                 error "compare $TMP/$tfile.1 failed"
18268
18269         local save=$($LCTL get_param -n osc.*OST000*.short_io_bytes | head -n 1)
18270         stack_trap "$LCTL set_param osc.$FSNAME-*.short_io_bytes=$save" EXIT
18271
18272         # just to see what the maximum tunable value is, and test parsing
18273         echo "test invalid parameter 2MB"
18274         $LCTL set_param osc.$FSNAME-OST0000*.short_io_bytes=2M &&
18275                 error "too-large short_io_bytes allowed"
18276         echo "test maximum parameter 512KB"
18277         # if we can set a larger short_io_bytes, run test regardless of version
18278         if ! $LCTL set_param osc.$FSNAME-OST0000*.short_io_bytes=512K; then
18279                 # older clients may not allow setting it this large, that's OK
18280                 [ $CLIENT_VERSION -ge $(version_code 2.13.50) ] ||
18281                         skip "Need at least client version 2.13.50"
18282                 error "medium short_io_bytes failed"
18283         fi
18284         $LCTL get_param osc.$FSNAME-OST0000*.short_io_bytes
18285         size=$($LCTL get_param -n osc.$FSNAME-OST0000*.short_io_bytes)
18286
18287         echo "test large parameter 64KB"
18288         $LCTL set_param osc.$FSNAME-*.short_io_bytes=65536
18289         $LCTL get_param osc.$FSNAME-OST0000*.short_io_bytes
18290
18291         echo "bs=47008 count=128 oflag=dsync large write $tfile.2"
18292         dd if=$TMP/$tfile.0 of=$DIR/$tfile.2 bs=47008 count=128 oflag=dsync ||
18293                 error "dd with sync large writes failed"
18294         cmp $TMP/$tfile.0 $DIR/$tfile.2 || error "compare $DIR/$tfile.2 failed"
18295
18296         # calculate the large O_DIRECT size and count for the client PAGE_SIZE
18297         local size=$(((4096 * 13 + PAGE_SIZE - 1) / PAGE_SIZE * PAGE_SIZE))
18298         num=$((113 * 4096 / PAGE_SIZE))
18299         echo "bs=$size count=$num oflag=direct large write $tfile.3"
18300         dd if=$TMP/$tfile.0 of=$DIR/$tfile.3 bs=$size count=$num oflag=direct ||
18301                 error "dd with O_DIRECT large writes failed"
18302         cmp --bytes=$((size * num)) $TMP/$tfile.0 $DIR/$tfile.3 ||
18303                 error "compare $DIR/$tfile.3 failed"
18304
18305         cancel_lru_locks osc
18306
18307         echo "bs=$size count=$num iflag=direct large read $tfile.2"
18308         dd if=$DIR/$tfile.2 of=$TMP/$tfile.2 bs=$size count=$num iflag=direct ||
18309                 error "dd with O_DIRECT large read failed"
18310         cmp --bytes=$((size * num)) $TMP/$tfile.0 $TMP/$tfile.2 ||
18311                 error "compare $TMP/$tfile.2 failed"
18312
18313         echo "bs=$size count=$num iflag=direct large read $tfile.3"
18314         dd if=$DIR/$tfile.3 of=$TMP/$tfile.3 bs=$size count=$num iflag=direct ||
18315                 error "dd with O_DIRECT large read failed"
18316         cmp --bytes=$((size * num)) $TMP/$tfile.0 $TMP/$tfile.3 ||
18317                 error "compare $TMP/$tfile.3 failed"
18318 }
18319 run_test 248b "test short_io read and write for both small and large sizes"
18320
18321 test_249() { # LU-7890
18322         [ $MDS1_VERSION -lt $(version_code 2.8.53) ] &&
18323                 skip "Need at least version 2.8.54"
18324
18325         rm -f $DIR/$tfile
18326         $LFS setstripe -c 1 $DIR/$tfile
18327         # Offset 2T == 4k * 512M
18328         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
18329                 error "dd to 2T offset failed"
18330 }
18331 run_test 249 "Write above 2T file size"
18332
18333 test_250() {
18334         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR/$tfile) + 1)))" = "zfs" ] \
18335          && skip "no 16TB file size limit on ZFS"
18336
18337         $LFS setstripe -c 1 $DIR/$tfile
18338         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
18339         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
18340         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
18341         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
18342                 conv=notrunc,fsync && error "append succeeded"
18343         return 0
18344 }
18345 run_test 250 "Write above 16T limit"
18346
18347 test_251() {
18348         $LFS setstripe -c -1 -S 1048576 $DIR/$tfile
18349
18350         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
18351         #Skip once - writing the first stripe will succeed
18352         $LCTL set_param fail_loc=0xa0001407 fail_val=1
18353         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
18354                 error "short write happened"
18355
18356         $LCTL set_param fail_loc=0xa0001407 fail_val=1
18357         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
18358                 error "short read happened"
18359
18360         rm -f $DIR/$tfile
18361 }
18362 run_test 251 "Handling short read and write correctly"
18363
18364 test_252() {
18365         remote_mds_nodsh && skip "remote MDS with nodsh"
18366         remote_ost_nodsh && skip "remote OST with nodsh"
18367         if [ "$ost1_FSTYPE" != ldiskfs ] || [ "$mds1_FSTYPE" != ldiskfs ]; then
18368                 skip_env "ldiskfs only test"
18369         fi
18370
18371         local tgt
18372         local dev
18373         local out
18374         local uuid
18375         local num
18376         local gen
18377
18378         # check lr_reader on OST0000
18379         tgt=ost1
18380         dev=$(facet_device $tgt)
18381         out=$(do_facet $tgt $LR_READER $dev)
18382         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
18383         echo "$out"
18384         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
18385         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
18386                 error "Invalid uuid returned by $LR_READER on target $tgt"
18387         echo -e "uuid returned by $LR_READER is '$uuid'\n"
18388
18389         # check lr_reader -c on MDT0000
18390         tgt=mds1
18391         dev=$(facet_device $tgt)
18392         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
18393                 skip "$LR_READER does not support additional options"
18394         fi
18395         out=$(do_facet $tgt $LR_READER -c $dev)
18396         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
18397         echo "$out"
18398         num=$(echo "$out" | grep -c "mdtlov")
18399         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
18400                 error "Invalid number of mdtlov clients returned by $LR_READER"
18401         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
18402
18403         # check lr_reader -cr on MDT0000
18404         out=$(do_facet $tgt $LR_READER -cr $dev)
18405         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
18406         echo "$out"
18407         echo "$out" | grep -q "^reply_data:$" ||
18408                 error "$LR_READER should have returned 'reply_data' section"
18409         num=$(echo "$out" | grep -c "client_generation")
18410         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
18411 }
18412 run_test 252 "check lr_reader tool"
18413
18414 test_253() {
18415         [ $PARALLEL == "yes" ] && skip "skip parallel run"
18416         remote_mds_nodsh && skip "remote MDS with nodsh"
18417         remote_mgs_nodsh && skip "remote MGS with nodsh"
18418
18419         local ostidx=0
18420         local rc=0
18421         local ost_name=$(ostname_from_index $ostidx)
18422
18423         # on the mdt's osc
18424         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
18425         do_facet $SINGLEMDS $LCTL get_param -n \
18426                 osp.$mdtosc_proc1.reserved_mb_high ||
18427                 skip  "remote MDS does not support reserved_mb_high"
18428
18429         rm -rf $DIR/$tdir
18430         wait_mds_ost_sync
18431         wait_delete_completed
18432         mkdir $DIR/$tdir
18433
18434         pool_add $TESTNAME || error "Pool creation failed"
18435         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
18436
18437         $LFS setstripe $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
18438                 error "Setstripe failed"
18439
18440         dd if=/dev/zero of=$DIR/$tdir/$tfile.0 bs=1M count=10
18441
18442         local wms=$(ost_watermarks_set_enospc $tfile $ostidx |
18443                     grep "watermarks")
18444         stack_trap "ost_watermarks_clear_enospc $tfile $ostidx $wms" EXIT
18445
18446         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
18447                         osp.$mdtosc_proc1.prealloc_status)
18448         echo "prealloc_status $oa_status"
18449
18450         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1M count=1 &&
18451                 error "File creation should fail"
18452
18453         #object allocation was stopped, but we still able to append files
18454         dd if=/dev/zero of=$DIR/$tdir/$tfile.0 bs=1M seek=6 count=5 \
18455                 oflag=append || error "Append failed"
18456
18457         rm -f $DIR/$tdir/$tfile.0
18458
18459         # For this test, we want to delete the files we created to go out of
18460         # space but leave the watermark, so we remain nearly out of space
18461         ost_watermarks_enospc_delete_files $tfile $ostidx
18462
18463         wait_delete_completed
18464
18465         sleep_maxage
18466
18467         for i in $(seq 10 12); do
18468                 dd if=/dev/zero of=$DIR/$tdir/$tfile.$i bs=1M count=1 \
18469                         2>/dev/null || error "File creation failed after rm"
18470         done
18471
18472         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
18473                         osp.$mdtosc_proc1.prealloc_status)
18474         echo "prealloc_status $oa_status"
18475
18476         if (( oa_status != 0 )); then
18477                 error "Object allocation still disable after rm"
18478         fi
18479 }
18480 run_test 253 "Check object allocation limit"
18481
18482 test_254() {
18483         [ $PARALLEL == "yes" ] && skip "skip parallel run"
18484         remote_mds_nodsh && skip "remote MDS with nodsh"
18485         do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_size ||
18486                 skip "MDS does not support changelog_size"
18487
18488         local cl_user
18489         local MDT0=$(facet_svc $SINGLEMDS)
18490
18491         changelog_register || error "changelog_register failed"
18492
18493         changelog_clear 0 || error "changelog_clear failed"
18494
18495         local size1=$(do_facet $SINGLEMDS \
18496                       $LCTL get_param -n mdd.$MDT0.changelog_size)
18497         echo "Changelog size $size1"
18498
18499         rm -rf $DIR/$tdir
18500         $LFS mkdir -i 0 $DIR/$tdir
18501         # change something
18502         mkdir -p $DIR/$tdir/pics/2008/zachy
18503         touch $DIR/$tdir/pics/2008/zachy/timestamp
18504         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
18505         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
18506         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
18507         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
18508         rm $DIR/$tdir/pics/desktop.jpg
18509
18510         local size2=$(do_facet $SINGLEMDS \
18511                       $LCTL get_param -n mdd.$MDT0.changelog_size)
18512         echo "Changelog size after work $size2"
18513
18514         (( $size2 > $size1 )) ||
18515                 error "new Changelog size=$size2 less than old size=$size1"
18516 }
18517 run_test 254 "Check changelog size"
18518
18519 ladvise_no_type()
18520 {
18521         local type=$1
18522         local file=$2
18523
18524         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
18525                 awk -F: '{print $2}' | grep $type > /dev/null
18526         if [ $? -ne 0 ]; then
18527                 return 0
18528         fi
18529         return 1
18530 }
18531
18532 ladvise_no_ioctl()
18533 {
18534         local file=$1
18535
18536         lfs ladvise -a willread $file > /dev/null 2>&1
18537         if [ $? -eq 0 ]; then
18538                 return 1
18539         fi
18540
18541         lfs ladvise -a willread $file 2>&1 |
18542                 grep "Inappropriate ioctl for device" > /dev/null
18543         if [ $? -eq 0 ]; then
18544                 return 0
18545         fi
18546         return 1
18547 }
18548
18549 percent() {
18550         bc <<<"scale=2; ($1 - $2) * 100 / $2"
18551 }
18552
18553 # run a random read IO workload
18554 # usage: random_read_iops <filename> <filesize> <iosize>
18555 random_read_iops() {
18556         local file=$1
18557         local fsize=$2
18558         local iosize=${3:-4096}
18559
18560         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
18561                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
18562 }
18563
18564 drop_file_oss_cache() {
18565         local file="$1"
18566         local nodes="$2"
18567
18568         $LFS ladvise -a dontneed $file 2>/dev/null ||
18569                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
18570 }
18571
18572 ladvise_willread_performance()
18573 {
18574         local repeat=10
18575         local average_origin=0
18576         local average_cache=0
18577         local average_ladvise=0
18578
18579         for ((i = 1; i <= $repeat; i++)); do
18580                 echo "Iter $i/$repeat: reading without willread hint"
18581                 cancel_lru_locks osc
18582                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
18583                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
18584                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
18585                 average_origin=$(bc <<<"$average_origin + $speed_origin")
18586
18587                 cancel_lru_locks osc
18588                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
18589                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
18590                 average_cache=$(bc <<<"$average_cache + $speed_cache")
18591
18592                 cancel_lru_locks osc
18593                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
18594                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
18595                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
18596                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
18597                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
18598         done
18599         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
18600         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
18601         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
18602
18603         speedup_cache=$(percent $average_cache $average_origin)
18604         speedup_ladvise=$(percent $average_ladvise $average_origin)
18605
18606         echo "Average uncached read: $average_origin"
18607         echo "Average speedup with OSS cached read: " \
18608                 "$average_cache = +$speedup_cache%"
18609         echo "Average speedup with ladvise willread: " \
18610                 "$average_ladvise = +$speedup_ladvise%"
18611
18612         local lowest_speedup=20
18613         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
18614                 echo "Speedup with OSS cached read less than $lowest_speedup%," \
18615                         "got $average_cache%. Skipping ladvise willread check."
18616                 return 0
18617         fi
18618
18619         # the test won't work on ZFS until it supports 'ladvise dontneed', but
18620         # it is still good to run until then to exercise 'ladvise willread'
18621         ! $LFS ladvise -a dontneed $DIR/$tfile &&
18622                 [ "$ost1_FSTYPE" = "zfs" ] &&
18623                 echo "osd-zfs does not support dontneed or drop_caches" &&
18624                 return 0
18625
18626         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
18627         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
18628                 error_not_in_vm "Speedup with willread is less than " \
18629                         "$lowest_speedup%, got $average_ladvise%"
18630 }
18631
18632 test_255a() {
18633         [ $OST1_VERSION -lt $(version_code 2.8.54) ] &&
18634                 skip "lustre < 2.8.54 does not support ladvise "
18635         remote_ost_nodsh && skip "remote OST with nodsh"
18636
18637         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
18638
18639         ladvise_no_type willread $DIR/$tfile &&
18640                 skip "willread ladvise is not supported"
18641
18642         ladvise_no_ioctl $DIR/$tfile &&
18643                 skip "ladvise ioctl is not supported"
18644
18645         local size_mb=100
18646         local size=$((size_mb * 1048576))
18647         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
18648                 error "dd to $DIR/$tfile failed"
18649
18650         lfs ladvise -a willread $DIR/$tfile ||
18651                 error "Ladvise failed with no range argument"
18652
18653         lfs ladvise -a willread -s 0 $DIR/$tfile ||
18654                 error "Ladvise failed with no -l or -e argument"
18655
18656         lfs ladvise -a willread -e 1 $DIR/$tfile ||
18657                 error "Ladvise failed with only -e argument"
18658
18659         lfs ladvise -a willread -l 1 $DIR/$tfile ||
18660                 error "Ladvise failed with only -l argument"
18661
18662         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
18663                 error "End offset should not be smaller than start offset"
18664
18665         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
18666                 error "End offset should not be equal to start offset"
18667
18668         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
18669                 error "Ladvise failed with overflowing -s argument"
18670
18671         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
18672                 error "Ladvise failed with overflowing -e argument"
18673
18674         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
18675                 error "Ladvise failed with overflowing -l argument"
18676
18677         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
18678                 error "Ladvise succeeded with conflicting -l and -e arguments"
18679
18680         echo "Synchronous ladvise should wait"
18681         local delay=4
18682 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
18683         do_nodes $(comma_list $(osts_nodes)) \
18684                 $LCTL set_param fail_val=$delay fail_loc=0x237
18685
18686         local start_ts=$SECONDS
18687         lfs ladvise -a willread $DIR/$tfile ||
18688                 error "Ladvise failed with no range argument"
18689         local end_ts=$SECONDS
18690         local inteval_ts=$((end_ts - start_ts))
18691
18692         if [ $inteval_ts -lt $(($delay - 1)) ]; then
18693                 error "Synchronous advice didn't wait reply"
18694         fi
18695
18696         echo "Asynchronous ladvise shouldn't wait"
18697         local start_ts=$SECONDS
18698         lfs ladvise -a willread -b $DIR/$tfile ||
18699                 error "Ladvise failed with no range argument"
18700         local end_ts=$SECONDS
18701         local inteval_ts=$((end_ts - start_ts))
18702
18703         if [ $inteval_ts -gt $(($delay / 2)) ]; then
18704                 error "Asynchronous advice blocked"
18705         fi
18706
18707         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
18708         ladvise_willread_performance
18709 }
18710 run_test 255a "check 'lfs ladvise -a willread'"
18711
18712 facet_meminfo() {
18713         local facet=$1
18714         local info=$2
18715
18716         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
18717 }
18718
18719 test_255b() {
18720         [ $OST1_VERSION -lt $(version_code 2.8.54) ] &&
18721                 skip "lustre < 2.8.54 does not support ladvise "
18722         remote_ost_nodsh && skip "remote OST with nodsh"
18723
18724         lfs setstripe -c 1 -i 0 $DIR/$tfile
18725
18726         ladvise_no_type dontneed $DIR/$tfile &&
18727                 skip "dontneed ladvise is not supported"
18728
18729         ladvise_no_ioctl $DIR/$tfile &&
18730                 skip "ladvise ioctl is not supported"
18731
18732         ! $LFS ladvise -a dontneed $DIR/$tfile &&
18733                 [ "$ost1_FSTYPE" = "zfs" ] &&
18734                 skip "zfs-osd does not support 'ladvise dontneed'"
18735
18736         local size_mb=100
18737         local size=$((size_mb * 1048576))
18738         # In order to prevent disturbance of other processes, only check 3/4
18739         # of the memory usage
18740         local kibibytes=$((size_mb * 1024 * 3 / 4))
18741
18742         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
18743                 error "dd to $DIR/$tfile failed"
18744
18745         #force write to complete before dropping OST cache & checking memory
18746         sync
18747
18748         local total=$(facet_meminfo ost1 MemTotal)
18749         echo "Total memory: $total KiB"
18750
18751         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
18752         local before_read=$(facet_meminfo ost1 Cached)
18753         echo "Cache used before read: $before_read KiB"
18754
18755         lfs ladvise -a willread $DIR/$tfile ||
18756                 error "Ladvise willread failed"
18757         local after_read=$(facet_meminfo ost1 Cached)
18758         echo "Cache used after read: $after_read KiB"
18759
18760         lfs ladvise -a dontneed $DIR/$tfile ||
18761                 error "Ladvise dontneed again failed"
18762         local no_read=$(facet_meminfo ost1 Cached)
18763         echo "Cache used after dontneed ladvise: $no_read KiB"
18764
18765         if [ $total -lt $((before_read + kibibytes)) ]; then
18766                 echo "Memory is too small, abort checking"
18767                 return 0
18768         fi
18769
18770         if [ $((before_read + kibibytes)) -gt $after_read ]; then
18771                 error "Ladvise willread should use more memory" \
18772                         "than $kibibytes KiB"
18773         fi
18774
18775         if [ $((no_read + kibibytes)) -gt $after_read ]; then
18776                 error "Ladvise dontneed should release more memory" \
18777                         "than $kibibytes KiB"
18778         fi
18779 }
18780 run_test 255b "check 'lfs ladvise -a dontneed'"
18781
18782 test_255c() {
18783         [ $OST1_VERSION -lt $(version_code 2.10.50) ] &&
18784                 skip "lustre < 2.10.50 does not support lockahead"
18785
18786         local count
18787         local new_count
18788         local difference
18789         local i
18790         local rc
18791
18792         test_mkdir -p $DIR/$tdir
18793         $LFS setstripe -i 0 -c 1 $DIR/$tdir
18794
18795         #test 10 returns only success/failure
18796         i=10
18797         lockahead_test -d $DIR/$tdir -t $i -f $tfile
18798         rc=$?
18799         if [ $rc -eq 255 ]; then
18800                 error "Ladvise test${i} failed, ${rc}"
18801         fi
18802
18803         #test 11 counts lock enqueue requests, all others count new locks
18804         i=11
18805         count=$(do_facet ost1 \
18806                 $LCTL get_param -n ost.OSS.ost.stats)
18807         count=$(echo "$count" | grep ldlm_extent_enqueue | awk '{ print $2 }')
18808
18809         lockahead_test -d $DIR/$tdir -t $i -f $tfile
18810         rc=$?
18811         if [ $rc -eq 255 ]; then
18812                 error "Ladvise test${i} failed, ${rc}"
18813         fi
18814
18815         new_count=$(do_facet ost1 \
18816                 $LCTL get_param -n ost.OSS.ost.stats)
18817         new_count=$(echo "$new_count" | grep ldlm_extent_enqueue | \
18818                    awk '{ print $2 }')
18819
18820         difference="$((new_count - count))"
18821         if [ $difference -ne $rc ]; then
18822                 error "Ladvise test${i}, bad enqueue count, returned " \
18823                       "${rc}, actual ${difference}"
18824         fi
18825
18826         for i in $(seq 12 21); do
18827                 # If we do not do this, we run the risk of having too many
18828                 # locks and starting lock cancellation while we are checking
18829                 # lock counts.
18830                 cancel_lru_locks osc
18831
18832                 count=$($LCTL get_param -n \
18833                        ldlm.namespaces.$FSNAME-OST0000*osc-[-0-9a-f]*.lock_unused_count)
18834
18835                 lockahead_test -d $DIR/$tdir -t $i -f $tfile
18836                 rc=$?
18837                 if [ $rc -eq 255 ]; then
18838                         error "Ladvise test ${i} failed, ${rc}"
18839                 fi
18840
18841                 new_count=$($LCTL get_param -n \
18842                        ldlm.namespaces.$FSNAME-OST0000*osc-[-0-9a-f]*.lock_unused_count)
18843                 difference="$((new_count - count))"
18844
18845                 # Test 15 output is divided by 100 to map down to valid return
18846                 if [ $i -eq 15 ]; then
18847                         rc="$((rc * 100))"
18848                 fi
18849
18850                 if [ $difference -ne $rc ]; then
18851                         error "Ladvise test ${i}, bad lock count, returned " \
18852                               "${rc}, actual ${difference}"
18853                 fi
18854         done
18855
18856         #test 22 returns only success/failure
18857         i=22
18858         lockahead_test -d $DIR/$tdir -t $i -f $tfile
18859         rc=$?
18860         if [ $rc -eq 255 ]; then
18861                 error "Ladvise test${i} failed, ${rc}"
18862         fi
18863 }
18864 run_test 255c "suite of ladvise lockahead tests"
18865
18866 test_256() {
18867         [ $PARALLEL == "yes" ] && skip "skip parallel run"
18868         remote_mds_nodsh && skip "remote MDS with nodsh"
18869         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip "ldiskfs only test"
18870         changelog_users $SINGLEMDS | grep "^cl" &&
18871                 skip "active changelog user"
18872
18873         local cl_user
18874         local cat_sl
18875         local mdt_dev
18876
18877         mdt_dev=$(mdsdevname 1)
18878         echo $mdt_dev
18879
18880         changelog_register || error "changelog_register failed"
18881
18882         rm -rf $DIR/$tdir
18883         mkdir -p $DIR/$tdir
18884
18885         changelog_clear 0 || error "changelog_clear failed"
18886
18887         # change something
18888         touch $DIR/$tdir/{1..10}
18889
18890         # stop the MDT
18891         stop $SINGLEMDS || error "Fail to stop MDT"
18892
18893         # remount the MDT
18894
18895         start $SINGLEMDS $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT"
18896
18897         #after mount new plainllog is used
18898         touch $DIR/$tdir/{11..19}
18899         local tmpfile="$(mktemp --tmpdir -u $tfile.XXXXXX)"
18900         stack_trap "rm -f $tmpfile"
18901         cat_sl=$(do_facet $SINGLEMDS "sync; \
18902                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
18903                  llog_reader $tmpfile | grep -c type=1064553b")
18904         do_facet $SINGLEMDS llog_reader $tmpfile
18905
18906         [ $cat_sl != 2 ] && error "Changelog catalog has $cat_sl != 2 slots"
18907
18908         changelog_clear 0 || error "changelog_clear failed"
18909
18910         cat_sl=$(do_facet $SINGLEMDS "sync; \
18911                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
18912                  llog_reader $tmpfile | grep -c type=1064553b")
18913
18914         if (( cat_sl == 2 )); then
18915                 error "Empty plain llog was not deleted from changelog catalog"
18916         elif (( cat_sl != 1 )); then
18917                 error "Active plain llog shouldn't be deleted from catalog"
18918         fi
18919 }
18920 run_test 256 "Check llog delete for empty and not full state"
18921
18922 test_257() {
18923         remote_mds_nodsh && skip "remote MDS with nodsh"
18924         [[ $MDS1_VERSION -lt $(version_code 2.8.55) ]] &&
18925                 skip "Need MDS version at least 2.8.55"
18926
18927         test_mkdir $DIR/$tdir
18928
18929         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
18930                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
18931         stat $DIR/$tdir
18932
18933 #define OBD_FAIL_MDS_XATTR_REP                  0x161
18934         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
18935         local facet=mds$((mdtidx + 1))
18936         set_nodes_failloc $(facet_active_host $facet) 0x80000161
18937         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
18938
18939         stop $facet || error "stop MDS failed"
18940         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
18941                 error "start MDS fail"
18942         wait_recovery_complete $facet
18943 }
18944 run_test 257 "xattr locks are not lost"
18945
18946 # Verify we take the i_mutex when security requires it
18947 test_258a() {
18948 #define OBD_FAIL_IMUTEX_SEC 0x141c
18949         $LCTL set_param fail_loc=0x141c
18950         touch $DIR/$tfile
18951         chmod u+s $DIR/$tfile
18952         chmod a+rwx $DIR/$tfile
18953         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
18954         RC=$?
18955         if [ $RC -ne 0 ]; then
18956                 error "error, failed to take i_mutex, rc=$?"
18957         fi
18958         rm -f $DIR/$tfile
18959 }
18960 run_test 258a "verify i_mutex security behavior when suid attributes is set"
18961
18962 # Verify we do NOT take the i_mutex in the normal case
18963 test_258b() {
18964 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
18965         $LCTL set_param fail_loc=0x141d
18966         touch $DIR/$tfile
18967         chmod a+rwx $DIR
18968         chmod a+rw $DIR/$tfile
18969         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
18970         RC=$?
18971         if [ $RC -ne 0 ]; then
18972                 error "error, took i_mutex unnecessarily, rc=$?"
18973         fi
18974         rm -f $DIR/$tfile
18975
18976 }
18977 run_test 258b "verify i_mutex security behavior"
18978
18979 test_259() {
18980         local file=$DIR/$tfile
18981         local before
18982         local after
18983
18984         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip "ldiskfs only test"
18985
18986         stack_trap "rm -f $file" EXIT
18987
18988         wait_delete_completed
18989         before=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
18990         echo "before: $before"
18991
18992         $LFS setstripe -i 0 -c 1 $file
18993         dd if=/dev/zero of=$file bs=1M count=10 || error "couldn't write"
18994         sync_all_data
18995         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
18996         echo "after write: $after"
18997
18998 #define OBD_FAIL_OSD_FAIL_AT_TRUNCATE          0x2301
18999         do_facet ost1 $LCTL set_param fail_loc=0x2301
19000         $TRUNCATE $file 0
19001         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
19002         echo "after truncate: $after"
19003
19004         stop ost1
19005         do_facet ost1 $LCTL set_param fail_loc=0
19006         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
19007         sleep 2
19008         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
19009         echo "after restart: $after"
19010         [ $((after - before)) -ge $(fs_log_size ost1) ] &&
19011                 error "missing truncate?"
19012
19013         return 0
19014 }
19015 run_test 259 "crash at delayed truncate"
19016
19017 test_260() {
19018 #define OBD_FAIL_MDC_CLOSE               0x806
19019         $LCTL set_param fail_loc=0x80000806
19020         touch $DIR/$tfile
19021
19022 }
19023 run_test 260 "Check mdc_close fail"
19024
19025 ### Data-on-MDT sanity tests ###
19026 test_270a() {
19027         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19028                 skip "Need MDS version at least 2.10.55 for DoM"
19029
19030         # create DoM file
19031         local dom=$DIR/$tdir/dom_file
19032         local tmp=$DIR/$tdir/tmp_file
19033
19034         mkdir -p $DIR/$tdir
19035
19036         # basic checks for DoM component creation
19037         $LFS setstripe -E 1024K -E 2048K -L mdt $dom 2>/dev/null &&
19038                 error "Can set MDT layout to non-first entry"
19039
19040         $LFS setstripe -E 1024K -L mdt -E 2048K -L mdt $dom 2>/dev/null &&
19041                 error "Can define multiple entries as MDT layout"
19042
19043         $LFS setstripe -E 1M -L mdt $dom || error "Can't create DoM layout"
19044
19045         [ $($LFS getstripe -L $dom) == "mdt" ] || error "bad pattern"
19046         [ $($LFS getstripe -c $dom) == 0 ] || error "bad stripe count"
19047         [ $($LFS getstripe -S $dom) == 1048576 ] || error "bad stripe size"
19048
19049         local mdtidx=$($LFS getstripe -m $dom)
19050         local mdtname=MDT$(printf %04x $mdtidx)
19051         local facet=mds$((mdtidx + 1))
19052         local space_check=1
19053
19054         # Skip free space checks with ZFS
19055         [ "$(facet_fstype $facet)" == "zfs" ] && space_check=0
19056
19057         # write
19058         sync
19059         local size_tmp=$((65536 * 3))
19060         local mdtfree1=$(do_facet $facet \
19061                          lctl get_param -n osd*.*$mdtname.kbytesfree)
19062
19063         dd if=/dev/urandom of=$tmp bs=1024 count=$((size_tmp / 1024))
19064         # check also direct IO along write
19065         # IO size must be a multiple of PAGE_SIZE on all platforms (ARM=64KB)
19066         dd if=$tmp of=$dom bs=65536 count=$((size_tmp / 65536)) oflag=direct
19067         sync
19068         cmp $tmp $dom || error "file data is different"
19069         [ $(stat -c%s $dom) == $size_tmp ] ||
19070                 error "bad size after write: $(stat -c%s $dom) != $size_tmp"
19071         if [ $space_check == 1 ]; then
19072                 local mdtfree2=$(do_facet $facet \
19073                                  lctl get_param -n osd*.*$mdtname.kbytesfree)
19074
19075                 # increase in usage from by $size_tmp
19076                 [ $(($mdtfree1 - $mdtfree2)) -ge $((size_tmp / 1024)) ] ||
19077                         error "MDT free space wrong after write: " \
19078                               "$mdtfree1 >= $mdtfree2 + $size_tmp/1024"
19079         fi
19080
19081         # truncate
19082         local size_dom=10000
19083
19084         $TRUNCATE $dom $size_dom
19085         [ $(stat -c%s $dom) == $size_dom ] ||
19086                 error "bad size after truncate: $(stat -c%s $dom) != $size_dom"
19087         if [ $space_check == 1 ]; then
19088                 mdtfree1=$(do_facet $facet \
19089                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19090                 # decrease in usage from $size_tmp to new $size_dom
19091                 [ $(($mdtfree1 - $mdtfree2)) -ge \
19092                   $(((size_tmp - size_dom) / 1024)) ] ||
19093                         error "MDT free space is wrong after truncate: " \
19094                               "$mdtfree1 >= $mdtfree2 + ($size_tmp - $size_dom) / 1024"
19095         fi
19096
19097         # append
19098         cat $tmp >> $dom
19099         sync
19100         size_dom=$((size_dom + size_tmp))
19101         [ $(stat -c%s $dom) == $size_dom ] ||
19102                 error "bad size after append: $(stat -c%s $dom) != $size_dom"
19103         if [ $space_check == 1 ]; then
19104                 mdtfree2=$(do_facet $facet \
19105                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19106                 # increase in usage by $size_tmp from previous
19107                 [ $(($mdtfree1 - $mdtfree2)) -ge $((size_tmp / 1024)) ] ||
19108                         error "MDT free space is wrong after append: " \
19109                               "$mdtfree1 >= $mdtfree2 + $size_tmp/1024"
19110         fi
19111
19112         # delete
19113         rm $dom
19114         if [ $space_check == 1 ]; then
19115                 mdtfree1=$(do_facet $facet \
19116                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19117                 # decrease in usage by $size_dom from previous
19118                 [ $(($mdtfree1 - $mdtfree2)) -ge $((size_dom / 1024)) ] ||
19119                         error "MDT free space is wrong after removal: " \
19120                               "$mdtfree1 >= $mdtfree2 + $size_dom/1024"
19121         fi
19122
19123         # combined striping
19124         $LFS setstripe -E 1024K -L mdt -E EOF $dom ||
19125                 error "Can't create DoM + OST striping"
19126
19127         size_tmp=2031616 # must be a multiple of PAGE_SIZE=65536 on ARM
19128         dd if=/dev/urandom of=$tmp bs=1024 count=$((size_tmp / 1024))
19129         # check also direct IO along write
19130         dd if=$tmp of=$dom bs=65536 count=$((size_tmp / 65536)) oflag=direct
19131         sync
19132         cmp $tmp $dom || error "file data is different"
19133         [ $(stat -c%s $dom) == $size_tmp ] ||
19134                 error "bad size after write: $(stat -c%s $dom) != $size_tmp"
19135         rm $dom $tmp
19136
19137         return 0
19138 }
19139 run_test 270a "DoM: basic functionality tests"
19140
19141 test_270b() {
19142         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19143                 skip "Need MDS version at least 2.10.55"
19144
19145         local dom=$DIR/$tdir/dom_file
19146         local max_size=1048576
19147
19148         mkdir -p $DIR/$tdir
19149         $LFS setstripe -E $max_size -L mdt $dom
19150
19151         # truncate over the limit
19152         $TRUNCATE $dom $(($max_size + 1)) &&
19153                 error "successful truncate over the maximum size"
19154         # write over the limit
19155         dd if=/dev/zero of=$dom bs=$max_size seek=1 count=1 &&
19156                 error "successful write over the maximum size"
19157         # append over the limit
19158         dd if=/dev/zero of=$dom bs=$(($max_size - 3)) count=1
19159         echo "12345" >> $dom && error "successful append over the maximum size"
19160         rm $dom
19161
19162         return 0
19163 }
19164 run_test 270b "DoM: maximum size overflow checks for DoM-only file"
19165
19166 test_270c() {
19167         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19168                 skip "Need MDS version at least 2.10.55"
19169
19170         mkdir -p $DIR/$tdir
19171         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19172
19173         # check files inherit DoM EA
19174         touch $DIR/$tdir/first
19175         [ $($LFS getstripe -L $DIR/$tdir/first) == "mdt" ] ||
19176                 error "bad pattern"
19177         [ $($LFS getstripe -c $DIR/$tdir/first) == 0 ] ||
19178                 error "bad stripe count"
19179         [ $($LFS getstripe -S $DIR/$tdir/first) == 1048576 ] ||
19180                 error "bad stripe size"
19181
19182         # check directory inherits DoM EA and uses it as default
19183         mkdir $DIR/$tdir/subdir
19184         touch $DIR/$tdir/subdir/second
19185         [ $($LFS getstripe -L $DIR/$tdir/subdir/second) == "mdt" ] ||
19186                 error "bad pattern in sub-directory"
19187         [ $($LFS getstripe -c $DIR/$tdir/subdir/second) == 0 ] ||
19188                 error "bad stripe count in sub-directory"
19189         [ $($LFS getstripe -S $DIR/$tdir/subdir/second) == 1048576 ] ||
19190                 error "bad stripe size in sub-directory"
19191         return 0
19192 }
19193 run_test 270c "DoM: DoM EA inheritance tests"
19194
19195 test_270d() {
19196         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19197                 skip "Need MDS version at least 2.10.55"
19198
19199         mkdir -p $DIR/$tdir
19200         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19201
19202         # inherit default DoM striping
19203         mkdir $DIR/$tdir/subdir
19204         touch $DIR/$tdir/subdir/f1
19205
19206         # change default directory striping
19207         $LFS setstripe -c 1 $DIR/$tdir/subdir
19208         touch $DIR/$tdir/subdir/f2
19209         [ $($LFS getstripe -c $DIR/$tdir/subdir/f2) == 1 ] ||
19210                 error "wrong default striping in file 2"
19211         [ $($LFS getstripe -L $DIR/$tdir/subdir/f2) == "raid0" ] ||
19212                 error "bad pattern in file 2"
19213         return 0
19214 }
19215 run_test 270d "DoM: change striping from DoM to RAID0"
19216
19217 test_270e() {
19218         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19219                 skip "Need MDS version at least 2.10.55"
19220
19221         mkdir -p $DIR/$tdir/dom
19222         mkdir -p $DIR/$tdir/norm
19223         DOMFILES=20
19224         NORMFILES=10
19225         $LFS setstripe -E 1M -L mdt $DIR/$tdir/dom
19226         $LFS setstripe -i 0 -S 2M $DIR/$tdir/norm
19227
19228         createmany -o $DIR/$tdir/dom/dom- $DOMFILES
19229         createmany -o $DIR/$tdir/norm/norm- $NORMFILES
19230
19231         # find DoM files by layout
19232         NUM=$($LFS find -L mdt -type f $DIR/$tdir 2>/dev/null | wc -l)
19233         [ $NUM -eq  $DOMFILES ] ||
19234                 error "lfs find -L: found $NUM, expected $DOMFILES"
19235         echo "Test 1: lfs find 20 DOM files by layout: OK"
19236
19237         # there should be 1 dir with default DOM striping
19238         NUM=$($LFS find -L mdt -type d $DIR/$tdir 2>/dev/null | wc -l)
19239         [ $NUM -eq  1 ] ||
19240                 error "lfs find -L: found $NUM, expected 1 dir"
19241         echo "Test 2: lfs find 1 DOM dir by layout: OK"
19242
19243         # find DoM files by stripe size
19244         NUM=$($LFS find -S -1200K -type f $DIR/$tdir 2>/dev/null | wc -l)
19245         [ $NUM -eq  $DOMFILES ] ||
19246                 error "lfs find -S: found $NUM, expected $DOMFILES"
19247         echo "Test 4: lfs find 20 DOM files by stripe size: OK"
19248
19249         # find files by stripe offset except DoM files
19250         NUM=$($LFS find -i 0 -type f $DIR/$tdir 2>/dev/null | wc -l)
19251         [ $NUM -eq  $NORMFILES ] ||
19252                 error "lfs find -i: found $NUM, expected $NORMFILES"
19253         echo "Test 5: lfs find no DOM files by stripe index: OK"
19254         return 0
19255 }
19256 run_test 270e "DoM: lfs find with DoM files test"
19257
19258 test_270f() {
19259         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19260                 skip "Need MDS version at least 2.10.55"
19261
19262         local mdtname=${FSNAME}-MDT0000-mdtlov
19263         local dom=$DIR/$tdir/dom_file
19264         local dom_limit_saved=$(do_facet mds1 $LCTL get_param -n \
19265                                                 lod.$mdtname.dom_stripesize)
19266         local dom_limit=131072
19267
19268         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=$dom_limit
19269         local dom_current=$(do_facet mds1 $LCTL get_param -n \
19270                                                 lod.$mdtname.dom_stripesize)
19271         [ ${dom_limit} -eq ${dom_current} ] ||
19272                 error "Cannot change per-MDT DoM stripe limit to $dom_limit"
19273
19274         $LFS mkdir -i 0 -c 1 $DIR/$tdir
19275         $LFS setstripe -d $DIR/$tdir
19276         $LFS setstripe -E $dom_limit -L mdt $DIR/$tdir ||
19277                 error "Can't set directory default striping"
19278
19279         # exceed maximum stripe size
19280         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
19281                 error "Can't create file with $((dom_limit * 2)) DoM stripe"
19282         [ $($LFS getstripe -S $dom) -eq $((dom_limit * 2)) ] &&
19283                 error "Able to create DoM component size more than LOD limit"
19284
19285         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=0
19286         dom_current=$(do_facet mds1 $LCTL get_param -n \
19287                                                 lod.$mdtname.dom_stripesize)
19288         [ 0 -eq ${dom_current} ] ||
19289                 error "Can't set zero DoM stripe limit"
19290         rm $dom
19291
19292         # attempt to create DoM file on server with disabled DoM should
19293         # remove DoM entry from layout and be succeed
19294         $LFS setstripe -E $dom_limit -L mdt -E -1 $dom ||
19295                 error "Can't create DoM file (DoM is disabled)"
19296         [ $($LFS getstripe -L $dom) == "mdt" ] &&
19297                 error "File has DoM component while DoM is disabled"
19298         rm $dom
19299
19300         # attempt to create DoM file with only DoM stripe should return error
19301         $LFS setstripe -E $dom_limit -L mdt $dom &&
19302                 error "Able to create DoM-only file while DoM is disabled"
19303
19304         # too low values to be aligned with smallest stripe size 64K
19305         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=30000
19306         dom_current=$(do_facet mds1 $LCTL get_param -n \
19307                                                 lod.$mdtname.dom_stripesize)
19308         [ 30000 -eq ${dom_current} ] &&
19309                 error "Can set too small DoM stripe limit"
19310
19311         # 64K is a minimal stripe size in Lustre, expect limit of that size
19312         [ 65536 -eq ${dom_current} ] ||
19313                 error "Limit is not set to 64K but ${dom_current}"
19314
19315         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=2147483648
19316         dom_current=$(do_facet mds1 $LCTL get_param -n \
19317                                                 lod.$mdtname.dom_stripesize)
19318         echo $dom_current
19319         [ 2147483648 -eq ${dom_current} ] &&
19320                 error "Can set too large DoM stripe limit"
19321
19322         do_facet mds1 $LCTL set_param -n \
19323                                 lod.$mdtname.dom_stripesize=$((dom_limit * 2))
19324         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
19325                 error "Can't create DoM component size after limit change"
19326         do_facet mds1 $LCTL set_param -n \
19327                                 lod.$mdtname.dom_stripesize=$((dom_limit / 2))
19328         $LFS setstripe -E $dom_limit -L mdt ${dom}_big ||
19329                 error "Can't create DoM file after limit decrease"
19330         [ $($LFS getstripe -S ${dom}_big) -eq $((dom_limit / 2)) ] ||
19331                 error "Can create big DoM component after limit decrease"
19332         touch ${dom}_def ||
19333                 error "Can't create file with old default layout"
19334
19335         do_facet mds1 $LCTL set_param -n lod.*.dom_stripesize=$dom_limit_saved
19336         return 0
19337 }
19338 run_test 270f "DoM: maximum DoM stripe size checks"
19339
19340 test_270g() {
19341         [ $MDS1_VERSION -ge $(version_code 2.13.52) ] ||
19342                 skip "Need MDS version at least 2.13.52"
19343         local dom=$DIR/$tdir/$tfile
19344
19345         $LFS mkdir -i 0 -c 1 $DIR/$tdir
19346         local lodname=${FSNAME}-MDT0000-mdtlov
19347
19348         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
19349         save_lustre_params mds1 "lod.${lodname}.dom_stripesize_max_kb" > $save
19350         save_lustre_params mds1 "lod.${lodname}.dom_threshold_free_mb" >> $save
19351         stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
19352
19353         local dom_limit=1024
19354         local dom_threshold="50%"
19355
19356         $LFS setstripe -d $DIR/$tdir
19357         $LFS setstripe -E ${dom_limit}K -L mdt $DIR/$tdir ||
19358                 error "Can't set directory default striping"
19359
19360         do_facet mds1 $LCTL set_param -n \
19361                                 lod.${lodname}.dom_stripesize_max_kb=$dom_limit
19362         # set 0 threshold and create DOM file to change tunable stripesize
19363         do_facet mds1 $LCTL set_param -n lod.${lodname}.dom_threshold_free_mb=0
19364         $LFS setstripe -E ${dom_limit}K -L mdt -E -1 $dom ||
19365                 error "Failed to create $dom file"
19366         # now tunable dom_cur_stripesize should reach maximum
19367         local dom_current=$(do_facet mds1 $LCTL get_param -n \
19368                                         lod.${lodname}.dom_stripesize_cur_kb)
19369         [[ $dom_current == $dom_limit ]] ||
19370                 error "Current DOM stripesize is not maximum"
19371         rm $dom
19372
19373         # set threshold for further tests
19374         do_facet mds1 $LCTL set_param -n \
19375                         lod.${lodname}.dom_threshold_free_mb=$dom_threshold
19376         echo "DOM threshold is $dom_threshold free space"
19377         local dom_def
19378         local dom_set
19379         # Spoof bfree to exceed threshold
19380         #define OBD_FAIL_MDS_STATFS_SPOOF   0x168
19381         do_facet mds1 $LCTL set_param -n fail_loc=0x0168
19382         for spfree in 40 20 0 15 30 55; do
19383                 do_facet mds1 $LCTL set_param -n fail_val=$spfree
19384                 $LFS setstripe -E ${dom_limit}K -L mdt -E -1 $dom ||
19385                         error "Failed to create $dom file"
19386                 dom_def=$(do_facet mds1 $LCTL get_param -n \
19387                                         lod.${lodname}.dom_stripesize_cur_kb)
19388                 echo "Free space: ${spfree}%, default DOM stripe: ${dom_def}K"
19389                 [[ $dom_def != $dom_current ]] ||
19390                         error "Default stripe size was not changed"
19391                 if [[ $spfree > 0 ]] ; then
19392                         dom_set=$($LFS getstripe -S $dom)
19393                         [[ $dom_set == $((dom_def * 1024)) ]] ||
19394                                 error "DOM component size is still old"
19395                 else
19396                         [[ $($LFS getstripe -L $dom) != "mdt" ]] ||
19397                                 error "DoM component is set with no free space"
19398                 fi
19399                 rm $dom
19400                 dom_current=$dom_def
19401         done
19402 }
19403 run_test 270g "DoM: default DoM stripe size depends on free space"
19404
19405 test_271a() {
19406         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19407                 skip "Need MDS version at least 2.10.55"
19408
19409         local dom=$DIR/$tdir/dom
19410
19411         mkdir -p $DIR/$tdir
19412
19413         $LFS setstripe -E 1024K -L mdt $dom
19414
19415         lctl set_param -n mdc.*.stats=clear
19416         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
19417         cat $dom > /dev/null
19418         local reads=$(lctl get_param -n mdc.*.stats | grep -c ost_read)
19419         [ $reads -eq 0 ] || error "Unexpected $reads READ RPCs"
19420         ls $dom
19421         rm -f $dom
19422 }
19423 run_test 271a "DoM: data is cached for read after write"
19424
19425 test_271b() {
19426         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19427                 skip "Need MDS version at least 2.10.55"
19428
19429         local dom=$DIR/$tdir/dom
19430
19431         mkdir -p $DIR/$tdir
19432
19433         $LFS setstripe -E 1024K -L mdt -E EOF $dom
19434
19435         lctl set_param -n mdc.*.stats=clear
19436         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
19437         cancel_lru_locks mdc
19438         $CHECKSTAT -t file -s 4096 $dom || error "stat #1 fails"
19439         # second stat to check size is cached on client
19440         $CHECKSTAT -t file -s 4096 $dom || error "stat #2 fails"
19441         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
19442         [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
19443         rm -f $dom
19444 }
19445 run_test 271b "DoM: no glimpse RPC for stat (DoM only file)"
19446
19447 test_271ba() {
19448         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19449                 skip "Need MDS version at least 2.10.55"
19450
19451         local dom=$DIR/$tdir/dom
19452
19453         mkdir -p $DIR/$tdir
19454
19455         $LFS setstripe -E 1024K -L mdt -E EOF $dom
19456
19457         lctl set_param -n mdc.*.stats=clear
19458         lctl set_param -n osc.*.stats=clear
19459         dd if=/dev/zero of=$dom bs=2048K count=1 || return 1
19460         cancel_lru_locks mdc
19461         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
19462         # second stat to check size is cached on client
19463         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
19464         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
19465         [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
19466         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
19467         [ $gls == 0 ] || error "Unexpected $gls OSC glimpse RPCs"
19468         rm -f $dom
19469 }
19470 run_test 271ba "DoM: no glimpse RPC for stat (combined file)"
19471
19472
19473 get_mdc_stats() {
19474         local mdtidx=$1
19475         local param=$2
19476         local mdt=MDT$(printf %04x $mdtidx)
19477
19478         if [ -z $param ]; then
19479                 lctl get_param -n mdc.*$mdt*.stats
19480         else
19481                 lctl get_param -n mdc.*$mdt*.stats | awk "/$param/"'{print $2}'
19482         fi
19483 }
19484
19485 test_271c() {
19486         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19487                 skip "Need MDS version at least 2.10.55"
19488
19489         local dom=$DIR/$tdir/dom
19490
19491         mkdir -p $DIR/$tdir
19492
19493         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19494
19495         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
19496         local facet=mds$((mdtidx + 1))
19497
19498         cancel_lru_locks mdc
19499         do_facet $facet lctl set_param -n mdt.*.dom_lock=0
19500         createmany -o $dom 1000
19501         lctl set_param -n mdc.*.stats=clear
19502         smalliomany -w $dom 1000 200
19503         get_mdc_stats $mdtidx
19504         local enq=$(get_mdc_stats $mdtidx ldlm_ibits_enqueue)
19505         # Each file has 1 open, 1 IO enqueues, total 2000
19506         # but now we have also +1 getxattr for security.capability, total 3000
19507         [ $enq -ge 2000 ] || error "Too few enqueues $enq, expected > 2000"
19508         unlinkmany $dom 1000
19509
19510         cancel_lru_locks mdc
19511         do_facet $facet lctl set_param -n mdt.*.dom_lock=1
19512         createmany -o $dom 1000
19513         lctl set_param -n mdc.*.stats=clear
19514         smalliomany -w $dom 1000 200
19515         local enq_2=$(get_mdc_stats $mdtidx ldlm_ibits_enqueue)
19516         # Expect to see reduced amount of RPCs by 1000 due to single enqueue
19517         # for OPEN and IO lock.
19518         [ $((enq - enq_2)) -ge 1000 ] ||
19519                 error "Too many enqueues $enq_2, expected about $((enq - 1000))"
19520         unlinkmany $dom 1000
19521         return 0
19522 }
19523 run_test 271c "DoM: IO lock at open saves enqueue RPCs"
19524
19525 cleanup_271def_tests() {
19526         trap 0
19527         rm -f $1
19528 }
19529
19530 test_271d() {
19531         [ $MDS1_VERSION -lt $(version_code 2.10.57) ] &&
19532                 skip "Need MDS version at least 2.10.57"
19533
19534         local dom=$DIR/$tdir/dom
19535         local tmp=$TMP/$tfile
19536         trap "cleanup_271def_tests $tmp" EXIT
19537
19538         mkdir -p $DIR/$tdir
19539
19540         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19541
19542         local mdtidx=$($LFS getstripe --mdt-index $DIR/$tdir)
19543
19544         cancel_lru_locks mdc
19545         dd if=/dev/urandom of=$tmp bs=1000 count=1
19546         dd if=$tmp of=$dom bs=1000 count=1
19547         cancel_lru_locks mdc
19548
19549         cat /etc/hosts >> $tmp
19550         lctl set_param -n mdc.*.stats=clear
19551
19552         # append data to the same file it should update local page
19553         echo "Append to the same page"
19554         cat /etc/hosts >> $dom
19555         local num=$(get_mdc_stats $mdtidx ost_read)
19556         local ra=$(get_mdc_stats $mdtidx req_active)
19557         local rw=$(get_mdc_stats $mdtidx req_waittime)
19558
19559         [ -z $num ] || error "$num READ RPC occured"
19560         [ $ra == $rw ] || error "$((ra - rw)) resend occured"
19561         echo "... DONE"
19562
19563         # compare content
19564         cmp $tmp $dom || error "file miscompare"
19565
19566         cancel_lru_locks mdc
19567         lctl set_param -n mdc.*.stats=clear
19568
19569         echo "Open and read file"
19570         cat $dom > /dev/null
19571         local num=$(get_mdc_stats $mdtidx ost_read)
19572         local ra=$(get_mdc_stats $mdtidx req_active)
19573         local rw=$(get_mdc_stats $mdtidx req_waittime)
19574
19575         [ -z $num ] || error "$num READ RPC occured"
19576         [ $ra == $rw ] || error "$((ra - rw)) resend occured"
19577         echo "... DONE"
19578
19579         # compare content
19580         cmp $tmp $dom || error "file miscompare"
19581
19582         return 0
19583 }
19584 run_test 271d "DoM: read on open (1K file in reply buffer)"
19585
19586 test_271f() {
19587         [ $MDS1_VERSION -lt $(version_code 2.10.57) ] &&
19588                 skip "Need MDS version at least 2.10.57"
19589
19590         local dom=$DIR/$tdir/dom
19591         local tmp=$TMP/$tfile
19592         trap "cleanup_271def_tests $tmp" EXIT
19593
19594         mkdir -p $DIR/$tdir
19595
19596         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19597
19598         local mdtidx=$($LFS getstripe --mdt-index $DIR/$tdir)
19599
19600         cancel_lru_locks mdc
19601         dd if=/dev/urandom of=$tmp bs=265000 count=1
19602         dd if=$tmp of=$dom bs=265000 count=1
19603         cancel_lru_locks mdc
19604         cat /etc/hosts >> $tmp
19605         lctl set_param -n mdc.*.stats=clear
19606
19607         echo "Append to the same page"
19608         cat /etc/hosts >> $dom
19609         local num=$(get_mdc_stats $mdtidx ost_read)
19610         local ra=$(get_mdc_stats $mdtidx req_active)
19611         local rw=$(get_mdc_stats $mdtidx req_waittime)
19612
19613         [ -z $num ] || error "$num READ RPC occured"
19614         [ $ra == $rw ] || error "$((ra - rw)) resend occured"
19615         echo "... DONE"
19616
19617         # compare content
19618         cmp $tmp $dom || error "file miscompare"
19619
19620         cancel_lru_locks mdc
19621         lctl set_param -n mdc.*.stats=clear
19622
19623         echo "Open and read file"
19624         cat $dom > /dev/null
19625         local num=$(get_mdc_stats $mdtidx ost_read)
19626         local ra=$(get_mdc_stats $mdtidx req_active)
19627         local rw=$(get_mdc_stats $mdtidx req_waittime)
19628
19629         [ -z $num ] && num=0
19630         [ $num -eq 1 ] || error "expect 1 READ RPC, $num occured"
19631         [ $ra == $rw ] || error "$((ra - rw)) resend occured"
19632         echo "... DONE"
19633
19634         # compare content
19635         cmp $tmp $dom || error "file miscompare"
19636
19637         return 0
19638 }
19639 run_test 271f "DoM: read on open (200K file and read tail)"
19640
19641 test_271g() {
19642         [[ $($LCTL get_param mdc.*.import) =~ async_discard ]] ||
19643                 skip "Skipping due to old client or server version"
19644
19645         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
19646         # to get layout
19647         $CHECKSTAT -t file $DIR1/$tfile
19648
19649         $MULTIOP $DIR1/$tfile Ow40960_w4096c &
19650         MULTIOP_PID=$!
19651         sleep 1
19652         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE
19653         $LCTL set_param fail_loc=0x80000314
19654         rm $DIR1/$tfile || error "Unlink fails"
19655         RC=$?
19656         kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
19657         [ $RC -eq 0 ] || error "Failed write to stale object"
19658 }
19659 run_test 271g "Discard DoM data vs client flush race"
19660
19661 test_272a() {
19662         [ $MDS1_VERSION -lt $(version_code 2.11.50) ] &&
19663                 skip "Need MDS version at least 2.11.50"
19664
19665         local dom=$DIR/$tdir/dom
19666         mkdir -p $DIR/$tdir
19667
19668         $LFS setstripe -E 256K -L mdt -E -1 -c1 $dom
19669         dd if=/dev/urandom of=$dom bs=512K count=1 ||
19670                 error "failed to write data into $dom"
19671         local old_md5=$(md5sum $dom)
19672
19673         $LFS migrate -E 256K -L mdt -E -1 -c2 $dom ||
19674                 error "failed to migrate to the same DoM component"
19675
19676         local new_md5=$(md5sum $dom)
19677
19678         [ "$old_md5" == "$new_md5" ] ||
19679                 error "md5sum differ: $old_md5, $new_md5"
19680
19681         [ $($LFS getstripe -c $dom) -eq 2 ] ||
19682                 error "bad final stripe count: $($LFS getstripe -c $dom) != 2"
19683 }
19684 run_test 272a "DoM migration: new layout with the same DOM component"
19685
19686 test_272b() {
19687         [ $MDS1_VERSION -lt $(version_code 2.11.50) ] &&
19688                 skip "Need MDS version at least 2.11.50"
19689
19690         local dom=$DIR/$tdir/dom
19691         mkdir -p $DIR/$tdir
19692         $LFS setstripe -E 1M -L mdt -E -1 -c1 $dom
19693
19694         local mdtidx=$($LFS getstripe -m $dom)
19695         local mdtname=MDT$(printf %04x $mdtidx)
19696         local facet=mds$((mdtidx + 1))
19697
19698         local mdtfree1=$(do_facet $facet \
19699                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19700         dd if=/dev/urandom of=$dom bs=2M count=1 ||
19701                 error "failed to write data into $dom"
19702         local old_md5=$(md5sum $dom)
19703         cancel_lru_locks mdc
19704         local mdtfree1=$(do_facet $facet \
19705                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19706
19707         $LFS migrate -c2 $dom ||
19708                 error "failed to migrate to the new composite layout"
19709         [ $($LFS getstripe -L $dom) != 'mdt' ] ||
19710                 error "MDT stripe was not removed"
19711
19712         cancel_lru_locks mdc
19713         local new_md5=$(md5sum $dom)
19714         [ "$old_md5" == "$new_md5" ] ||
19715                 error "$old_md5 != $new_md5"
19716
19717         # Skip free space checks with ZFS
19718         if [ "$(facet_fstype $facet)" != "zfs" ]; then
19719                 local mdtfree2=$(do_facet $facet \
19720                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19721                 [ $mdtfree2 -gt $mdtfree1 ] ||
19722                         error "MDT space is not freed after migration"
19723         fi
19724         return 0
19725 }
19726 run_test 272b "DoM migration: DOM file to the OST-striped file (plain)"
19727
19728 test_272c() {
19729         [ $MDS1_VERSION -lt $(version_code 2.11.50) ] &&
19730                 skip "Need MDS version at least 2.11.50"
19731
19732         local dom=$DIR/$tdir/$tfile
19733         mkdir -p $DIR/$tdir
19734         $LFS setstripe -E 1M -L mdt -E -1 -c1 $dom
19735
19736         local mdtidx=$($LFS getstripe -m $dom)
19737         local mdtname=MDT$(printf %04x $mdtidx)
19738         local facet=mds$((mdtidx + 1))
19739
19740         dd if=/dev/urandom of=$dom bs=2M count=1 oflag=direct ||
19741                 error "failed to write data into $dom"
19742         local old_md5=$(md5sum $dom)
19743         cancel_lru_locks mdc
19744         local mdtfree1=$(do_facet $facet \
19745                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19746
19747         $LFS migrate -E 2M -c1 -E -1 -c2 $dom ||
19748                 error "failed to migrate to the new composite layout"
19749         [ $($LFS getstripe -L $dom) == 'mdt' ] &&
19750                 error "MDT stripe was not removed"
19751
19752         cancel_lru_locks mdc
19753         local new_md5=$(md5sum $dom)
19754         [ "$old_md5" == "$new_md5" ] ||
19755                 error "$old_md5 != $new_md5"
19756
19757         # Skip free space checks with ZFS
19758         if [ "$(facet_fstype $facet)" != "zfs" ]; then
19759                 local mdtfree2=$(do_facet $facet \
19760                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19761                 [ $mdtfree2 -gt $mdtfree1 ] ||
19762                         error "MDS space is not freed after migration"
19763         fi
19764         return 0
19765 }
19766 run_test 272c "DoM migration: DOM file to the OST-striped file (composite)"
19767
19768 test_272d() {
19769         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
19770                 skip "Need MDS version at least 2.12.55"
19771
19772         local dom=$DIR/$tdir/$tfile
19773         mkdir -p $DIR/$tdir
19774         $LFS setstripe -E 1M -L mdt -E -1 -c1 $dom
19775
19776         local mdtidx=$($LFS getstripe -m $dom)
19777         local mdtname=MDT$(printf %04x $mdtidx)
19778         local facet=mds$((mdtidx + 1))
19779
19780         dd if=/dev/urandom of=$dom bs=2M count=1 oflag=direct ||
19781                 error "failed to write data into $dom"
19782         local old_md5=$(md5sum $dom)
19783         cancel_lru_locks mdc
19784         local mdtfree1=$(do_facet $facet \
19785                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19786
19787         $LFS mirror extend -N -E 2M -c1 -E -1 -c2 $dom ||
19788                 error "failed mirroring to the new composite layout"
19789         $LFS mirror resync $dom ||
19790                 error "failed mirror resync"
19791         $LFS mirror split --mirror-id 1 -d $dom ||
19792                 error "failed mirror split"
19793
19794         [ $($LFS getstripe -L $dom) != 'mdt' ] ||
19795                 error "MDT stripe was not removed"
19796
19797         cancel_lru_locks mdc
19798         local new_md5=$(md5sum $dom)
19799         [ "$old_md5" == "$new_md5" ] ||
19800                 error "$old_md5 != $new_md5"
19801
19802         # Skip free space checks with ZFS
19803         if [ "$(facet_fstype $facet)" != "zfs" ]; then
19804                 local mdtfree2=$(do_facet $facet \
19805                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19806                 [ $mdtfree2 -gt $mdtfree1 ] ||
19807                         error "MDS space is not freed after DOM mirror deletion"
19808         fi
19809         return 0
19810 }
19811 run_test 272d "DoM mirroring: OST-striped mirror to DOM file"
19812
19813 test_272e() {
19814         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
19815                 skip "Need MDS version at least 2.12.55"
19816
19817         local dom=$DIR/$tdir/$tfile
19818         mkdir -p $DIR/$tdir
19819         $LFS setstripe -c 2 $dom
19820
19821         dd if=/dev/urandom of=$dom bs=512K count=1 oflag=direct ||
19822                 error "failed to write data into $dom"
19823         local old_md5=$(md5sum $dom)
19824         cancel_lru_locks mdc
19825
19826         $LFS mirror extend -N -E 1M -L mdt -E eof -c2 $dom ||
19827                 error "failed mirroring to the DOM layout"
19828         $LFS mirror resync $dom ||
19829                 error "failed mirror resync"
19830         $LFS mirror split --mirror-id 1 -d $dom ||
19831                 error "failed mirror split"
19832
19833         [ $($LFS getstripe -L $dom) != 'mdt' ] ||
19834                 error "MDT stripe was not removed"
19835
19836         cancel_lru_locks mdc
19837         local new_md5=$(md5sum $dom)
19838         [ "$old_md5" == "$new_md5" ] ||
19839                 error "$old_md5 != $new_md5"
19840
19841         return 0
19842 }
19843 run_test 272e "DoM mirroring: DOM mirror to the OST-striped file"
19844
19845 test_272f() {
19846         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
19847                 skip "Need MDS version at least 2.12.55"
19848
19849         local dom=$DIR/$tdir/$tfile
19850         mkdir -p $DIR/$tdir
19851         $LFS setstripe -c 2 $dom
19852
19853         dd if=/dev/urandom of=$dom bs=512K count=1 oflag=direct ||
19854                 error "failed to write data into $dom"
19855         local old_md5=$(md5sum $dom)
19856         cancel_lru_locks mdc
19857
19858         $LFS migrate -E 1M -L mdt -E eof -c2 -v $dom ||
19859                 error "failed migrating to the DOM file"
19860
19861         cancel_lru_locks mdc
19862         local new_md5=$(md5sum $dom)
19863         [ "$old_md5" != "$new_md5" ] &&
19864                 error "$old_md5 != $new_md5"
19865
19866         return 0
19867 }
19868 run_test 272f "DoM migration: OST-striped file to DOM file"
19869
19870 test_273a() {
19871         [ $MDS1_VERSION -lt $(version_code 2.11.50) ] &&
19872                 skip "Need MDS version at least 2.11.50"
19873
19874         # Layout swap cannot be done if either file has DOM component,
19875         # this will never be supported, migration should be used instead
19876
19877         local dom=$DIR/$tdir/$tfile
19878         mkdir -p $DIR/$tdir
19879
19880         $LFS setstripe -c2 ${dom}_plain
19881         $LFS setstripe -E 1M -L mdt -E -1 -c2 ${dom}_dom
19882         $LFS swap_layouts ${dom}_plain ${dom}_dom &&
19883                 error "can swap layout with DoM component"
19884         $LFS swap_layouts ${dom}_dom ${dom}_plain &&
19885                 error "can swap layout with DoM component"
19886
19887         $LFS setstripe -E 1M -c1 -E -1 -c2 ${dom}_comp
19888         $LFS swap_layouts ${dom}_comp ${dom}_dom &&
19889                 error "can swap layout with DoM component"
19890         $LFS swap_layouts ${dom}_dom ${dom}_comp &&
19891                 error "can swap layout with DoM component"
19892         return 0
19893 }
19894 run_test 273a "DoM: layout swapping should fail with DOM"
19895
19896 test_275() {
19897         remote_ost_nodsh && skip "remote OST with nodsh"
19898         [ $OST1_VERSION -lt $(version_code 2.10.57) ] &&
19899                 skip "Need OST version >= 2.10.57"
19900
19901         local file=$DIR/$tfile
19902         local oss
19903
19904         oss=$(comma_list $(osts_nodes))
19905
19906         dd if=/dev/urandom of=$file bs=1M count=2 ||
19907                 error "failed to create a file"
19908         cancel_lru_locks osc
19909
19910         #lock 1
19911         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
19912                 error "failed to read a file"
19913
19914 #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
19915         $LCTL set_param fail_loc=0x8000031f
19916
19917         cancel_lru_locks osc &
19918         sleep 1
19919
19920 #define OBD_FAIL_LDLM_PROLONG_PAUSE      0x32b
19921         do_nodes $oss $LCTL set_param fail_loc=0x8000032b
19922         #IO takes another lock, but matches the PENDING one
19923         #and places it to the IO RPC
19924         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
19925                 error "failed to read a file with PENDING lock"
19926 }
19927 run_test 275 "Read on a canceled duplicate lock"
19928
19929 test_276() {
19930         remote_ost_nodsh && skip "remote OST with nodsh"
19931         local pid
19932
19933         do_facet ost1 "(while true; do \
19934                 $LCTL get_param obdfilter.*.filesfree > /dev/null 2>&1; \
19935                 done) & pid=\\\$!; echo \\\$pid > $TMP/sanity_276_pid" &
19936         pid=$!
19937
19938         for LOOP in $(seq 20); do
19939                 stop ost1
19940                 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
19941         done
19942         kill -9 $pid
19943         do_facet ost1 "pid=\\\$(cat $TMP/sanity_276_pid); kill -9 \\\$pid; \
19944                 rm $TMP/sanity_276_pid"
19945 }
19946 run_test 276 "Race between mount and obd_statfs"
19947
19948 test_277() {
19949         $LCTL set_param ldlm.namespaces.*.lru_size=0
19950         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
19951         local cached_mb=$($LCTL get_param llite.*.max_cached_mb |
19952                         grep ^used_mb | awk '{print $2}')
19953         [ $cached_mb -eq 1 ] || error "expected mb 1 got $cached_mb"
19954         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 \
19955                 oflag=direct conv=notrunc
19956         cached_mb=$($LCTL get_param llite.*.max_cached_mb |
19957                         grep ^used_mb | awk '{print $2}')
19958         [ $cached_mb -eq 0 ] || error "expected mb 0 got $cached_mb"
19959 }
19960 run_test 277 "Direct IO shall drop page cache"
19961
19962 test_278() {
19963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
19964         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
19965         [[ "$(facet_host mds1)" != "$(facet_host mds2)" ]] &&
19966                 skip "needs the same host for mdt1 mdt2" && return
19967
19968         local pid1
19969         local pid2
19970
19971 #define OBD_FAIL_OBD_STOP_MDS_RACE     0x60b
19972         do_facet mds2 $LCTL set_param fail_loc=0x8000060c
19973         stop mds2 &
19974         pid2=$!
19975
19976         stop mds1
19977
19978         echo "Starting MDTs"
19979         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
19980         wait $pid2
19981 #For the error assertion will happen. lu_env_get_key(..., &mdt_thread_key)
19982 #will return NULL
19983         do_facet mds2 $LCTL set_param fail_loc=0
19984
19985         start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS
19986         wait_recovery_complete mds2
19987 }
19988 run_test 278 "Race starting MDS between MDTs stop/start"
19989
19990 test_280() {
19991         [ $MGS_VERSION -lt $(version_code 2.13.52) ] &&
19992                 skip "Need MGS version at least 2.13.52"
19993         [ $PARALLEL == "yes" ] && skip "skip parallel run"
19994         combined_mgs_mds || skip "needs combined MGS/MDT"
19995
19996         umount_client $MOUNT
19997 #define OBD_FAIL_MDS_LLOG_UMOUNT_RACE   0x15e
19998         do_facet mgs $LCTL set_param fail_loc=0x8000015e fail_val=0
19999
20000         mount_client $MOUNT &
20001         sleep 1
20002         stop mgs || error "stop mgs failed"
20003         #for a race mgs would crash
20004         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
20005         mount_client $MOUNT || error "mount client failed"
20006 }
20007 run_test 280 "Race between MGS umount and client llog processing"
20008
20009 cleanup_test_300() {
20010         trap 0
20011         umask $SAVE_UMASK
20012 }
20013 test_striped_dir() {
20014         local mdt_index=$1
20015         local stripe_count
20016         local stripe_index
20017
20018         mkdir -p $DIR/$tdir
20019
20020         SAVE_UMASK=$(umask)
20021         trap cleanup_test_300 RETURN EXIT
20022
20023         $LFS setdirstripe -i $mdt_index -c 2 -H all_char -o 755 \
20024                                                 $DIR/$tdir/striped_dir ||
20025                 error "set striped dir error"
20026
20027         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
20028         [ "$mode" = "755" ] || error "expect 755 got $mode"
20029
20030         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
20031                 error "getdirstripe failed"
20032         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
20033         if [ "$stripe_count" != "2" ]; then
20034                 error "1:stripe_count is $stripe_count, expect 2"
20035         fi
20036         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
20037         if [ "$stripe_count" != "2" ]; then
20038                 error "2:stripe_count is $stripe_count, expect 2"
20039         fi
20040
20041         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
20042         if [ "$stripe_index" != "$mdt_index" ]; then
20043                 error "stripe_index is $stripe_index, expect $mdt_index"
20044         fi
20045
20046         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
20047                 error "nlink error after create striped dir"
20048
20049         mkdir $DIR/$tdir/striped_dir/a
20050         mkdir $DIR/$tdir/striped_dir/b
20051
20052         stat $DIR/$tdir/striped_dir/a ||
20053                 error "create dir under striped dir failed"
20054         stat $DIR/$tdir/striped_dir/b ||
20055                 error "create dir under striped dir failed"
20056
20057         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
20058                 error "nlink error after mkdir"
20059
20060         rmdir $DIR/$tdir/striped_dir/a
20061         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
20062                 error "nlink error after rmdir"
20063
20064         rmdir $DIR/$tdir/striped_dir/b
20065         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
20066                 error "nlink error after rmdir"
20067
20068         chattr +i $DIR/$tdir/striped_dir
20069         createmany -o $DIR/$tdir/striped_dir/f 10 &&
20070                 error "immutable flags not working under striped dir!"
20071         chattr -i $DIR/$tdir/striped_dir
20072
20073         rmdir $DIR/$tdir/striped_dir ||
20074                 error "rmdir striped dir error"
20075
20076         cleanup_test_300
20077
20078         true
20079 }
20080
20081 test_300a() {
20082         [ $MDS1_VERSION -lt $(version_code 2.7.0) ] &&
20083                 skip "skipped for lustre < 2.7.0"
20084         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20085         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20086
20087         test_striped_dir 0 || error "failed on striped dir on MDT0"
20088         test_striped_dir 1 || error "failed on striped dir on MDT0"
20089 }
20090 run_test 300a "basic striped dir sanity test"
20091
20092 test_300b() {
20093         [ $MDS1_VERSION -lt $(version_code 2.7.0) ] &&
20094                 skip "skipped for lustre < 2.7.0"
20095         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20096         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20097
20098         local i
20099         local mtime1
20100         local mtime2
20101         local mtime3
20102
20103         test_mkdir $DIR/$tdir || error "mkdir fail"
20104         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
20105                 error "set striped dir error"
20106         for i in {0..9}; do
20107                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
20108                 sleep 1
20109                 touch $DIR/$tdir/striped_dir/file_$i || error "touch error $i"
20110                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
20111                 [ $mtime1 -eq $mtime2 ] && error "mtime unchanged after create"
20112                 sleep 1
20113                 rm -f $DIR/$tdir/striped_dir/file_$i || error "unlink error $i"
20114                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
20115                 [ $mtime2 -eq $mtime3 ] && error "mtime unchanged after unlink"
20116         done
20117         true
20118 }
20119 run_test 300b "check ctime/mtime for striped dir"
20120
20121 test_300c() {
20122         [ $MDS1_VERSION -lt $(version_code 2.7.0) ] &&
20123                 skip "skipped for lustre < 2.7.0"
20124         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20125         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20126
20127         local file_count
20128
20129         mkdir -p $DIR/$tdir
20130         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
20131                 error "set striped dir error"
20132
20133         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
20134                 error "chown striped dir failed"
20135
20136         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
20137                 error "create 5k files failed"
20138
20139         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
20140
20141         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
20142
20143         rm -rf $DIR/$tdir
20144 }
20145 run_test 300c "chown && check ls under striped directory"
20146
20147 test_300d() {
20148         [ $MDS1_VERSION -lt $(version_code 2.7.0) ] &&
20149                 skip "skipped for lustre < 2.7.0"
20150         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20151         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20152
20153         local stripe_count
20154         local file
20155
20156         mkdir -p $DIR/$tdir
20157         $LFS setstripe -c 2 $DIR/$tdir
20158
20159         #local striped directory
20160         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
20161                 error "set striped dir error"
20162         #look at the directories for debug purposes
20163         ls -l $DIR/$tdir
20164         $LFS getdirstripe $DIR/$tdir
20165         ls -l $DIR/$tdir/striped_dir
20166         $LFS getdirstripe $DIR/$tdir/striped_dir
20167         createmany -o $DIR/$tdir/striped_dir/f 10 ||
20168                 error "create 10 files failed"
20169
20170         #remote striped directory
20171         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
20172                 error "set striped dir error"
20173         #look at the directories for debug purposes
20174         ls -l $DIR/$tdir
20175         $LFS getdirstripe $DIR/$tdir
20176         ls -l $DIR/$tdir/remote_striped_dir
20177         $LFS getdirstripe $DIR/$tdir/remote_striped_dir
20178         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
20179                 error "create 10 files failed"
20180
20181         for file in $(find $DIR/$tdir); do
20182                 stripe_count=$($LFS getstripe -c $file)
20183                 [ $stripe_count -eq 2 ] ||
20184                         error "wrong stripe $stripe_count for $file"
20185         done
20186
20187         rm -rf $DIR/$tdir
20188 }
20189 run_test 300d "check default stripe under striped directory"
20190
20191 test_300e() {
20192         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20193                 skip "Need MDS version at least 2.7.55"
20194         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20195         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20196
20197         local stripe_count
20198         local file
20199
20200         mkdir -p $DIR/$tdir
20201
20202         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
20203                 error "set striped dir error"
20204
20205         touch $DIR/$tdir/striped_dir/a
20206         touch $DIR/$tdir/striped_dir/b
20207         touch $DIR/$tdir/striped_dir/c
20208
20209         mkdir $DIR/$tdir/striped_dir/dir_a
20210         mkdir $DIR/$tdir/striped_dir/dir_b
20211         mkdir $DIR/$tdir/striped_dir/dir_c
20212
20213         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_a ||
20214                 error "set striped adir under striped dir error"
20215
20216         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
20217                 error "set striped bdir under striped dir error"
20218
20219         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_c ||
20220                 error "set striped cdir under striped dir error"
20221
20222         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
20223                 error "rename dir under striped dir fails"
20224
20225         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
20226                 error "rename dir under different stripes fails"
20227
20228         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
20229                 error "rename file under striped dir should succeed"
20230
20231         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
20232                 error "rename dir under striped dir should succeed"
20233
20234         rm -rf $DIR/$tdir
20235 }
20236 run_test 300e "check rename under striped directory"
20237
20238 test_300f() {
20239         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20240         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20241         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20242                 skip "Need MDS version at least 2.7.55"
20243
20244         local stripe_count
20245         local file
20246
20247         rm -rf $DIR/$tdir
20248         mkdir -p $DIR/$tdir
20249
20250         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
20251                 error "set striped dir error"
20252
20253         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir1 ||
20254                 error "set striped dir error"
20255
20256         touch $DIR/$tdir/striped_dir/a
20257         mkdir $DIR/$tdir/striped_dir/dir_a
20258         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
20259                 error "create striped dir under striped dir fails"
20260
20261         touch $DIR/$tdir/striped_dir1/b
20262         mkdir $DIR/$tdir/striped_dir1/dir_b
20263         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
20264                 error "create striped dir under striped dir fails"
20265
20266         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
20267                 error "rename dir under different striped dir should fail"
20268
20269         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
20270                 error "rename striped dir under diff striped dir should fail"
20271
20272         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
20273                 error "rename file under diff striped dirs fails"
20274
20275         rm -rf $DIR/$tdir
20276 }
20277 run_test 300f "check rename cross striped directory"
20278
20279 test_300_check_default_striped_dir()
20280 {
20281         local dirname=$1
20282         local default_count=$2
20283         local default_index=$3
20284         local stripe_count
20285         local stripe_index
20286         local dir_stripe_index
20287         local dir
20288
20289         echo "checking $dirname $default_count $default_index"
20290         $LFS setdirstripe -D -c $default_count -i $default_index \
20291                                 -t all_char $DIR/$tdir/$dirname ||
20292                 error "set default stripe on striped dir error"
20293         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
20294         [ $stripe_count -eq $default_count ] ||
20295                 error "expect $default_count get $stripe_count for $dirname"
20296
20297         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
20298         [ $stripe_index -eq $default_index ] ||
20299                 error "expect $default_index get $stripe_index for $dirname"
20300
20301         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
20302                                                 error "create dirs failed"
20303
20304         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
20305         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
20306         for dir in $(find $DIR/$tdir/$dirname/*); do
20307                 stripe_count=$($LFS getdirstripe -c $dir)
20308                 [ $stripe_count -eq $default_count ] ||
20309                 [ $stripe_count -eq 0 ] || [ $default_count -eq 1 ] ||
20310                 error "stripe count $default_count != $stripe_count for $dir"
20311
20312                 stripe_index=$($LFS getdirstripe -i $dir)
20313                 [ $default_index -eq -1 ] ||
20314                         [ $stripe_index -eq $default_index ] ||
20315                         error "$stripe_index != $default_index for $dir"
20316
20317                 #check default stripe
20318                 stripe_count=$($LFS getdirstripe -D -c $dir)
20319                 [ $stripe_count -eq $default_count ] ||
20320                 error "default count $default_count != $stripe_count for $dir"
20321
20322                 stripe_index=$($LFS getdirstripe -D -i $dir)
20323                 [ $stripe_index -eq $default_index ] ||
20324                 error "default index $default_index != $stripe_index for $dir"
20325         done
20326         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
20327 }
20328
20329 test_300g() {
20330         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20331         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20332                 skip "Need MDS version at least 2.7.55"
20333
20334         local dir
20335         local stripe_count
20336         local stripe_index
20337
20338         mkdir $DIR/$tdir
20339         mkdir $DIR/$tdir/normal_dir
20340
20341         #Checking when client cache stripe index
20342         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
20343         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
20344                 error "create striped_dir failed"
20345
20346         $LFS setdirstripe -i0 $DIR/$tdir/striped_dir/dir0 ||
20347                 error "create dir0 fails"
20348         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir0)
20349         [ $stripe_index -eq 0 ] ||
20350                 error "dir0 expect index 0 got $stripe_index"
20351
20352         mkdir $DIR/$tdir/striped_dir/dir1 ||
20353                 error "create dir1 fails"
20354         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
20355         [ $stripe_index -eq 1 ] ||
20356                 error "dir1 expect index 1 got $stripe_index"
20357
20358         #check default stripe count/stripe index
20359         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
20360         test_300_check_default_striped_dir normal_dir 1 0
20361         test_300_check_default_striped_dir normal_dir 2 1
20362         test_300_check_default_striped_dir normal_dir 2 -1
20363
20364         #delete default stripe information
20365         echo "delete default stripeEA"
20366         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
20367                 error "set default stripe on striped dir error"
20368
20369         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
20370         for dir in $(find $DIR/$tdir/normal_dir/*); do
20371                 stripe_count=$($LFS getdirstripe -c $dir)
20372                 [ $stripe_count -eq 0 ] ||
20373                         error "expect 1 get $stripe_count for $dir"
20374                 stripe_index=$($LFS getdirstripe -i $dir)
20375                 [ $stripe_index -eq 0 ] ||
20376                         error "expect 0 get $stripe_index for $dir"
20377         done
20378 }
20379 run_test 300g "check default striped directory for normal directory"
20380
20381 test_300h() {
20382         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20383         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20384                 skip "Need MDS version at least 2.7.55"
20385
20386         local dir
20387         local stripe_count
20388
20389         mkdir $DIR/$tdir
20390         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
20391                 error "set striped dir error"
20392
20393         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
20394         test_300_check_default_striped_dir striped_dir 1 0
20395         test_300_check_default_striped_dir striped_dir 2 1
20396         test_300_check_default_striped_dir striped_dir 2 -1
20397
20398         #delete default stripe information
20399         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
20400                 error "set default stripe on striped dir error"
20401
20402         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
20403         for dir in $(find $DIR/$tdir/striped_dir/*); do
20404                 stripe_count=$($LFS getdirstripe -c $dir)
20405                 [ $stripe_count -eq 0 ] ||
20406                         error "expect 1 get $stripe_count for $dir"
20407         done
20408 }
20409 run_test 300h "check default striped directory for striped directory"
20410
20411 test_300i() {
20412         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20413         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20414         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20415                 skip "Need MDS version at least 2.7.55"
20416
20417         local stripe_count
20418         local file
20419
20420         mkdir $DIR/$tdir
20421
20422         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
20423                 error "set striped dir error"
20424
20425         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
20426                 error "create files under striped dir failed"
20427
20428         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
20429                 error "set striped hashdir error"
20430
20431         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
20432                 error "create dir0 under hash dir failed"
20433         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
20434                 error "create dir1 under hash dir failed"
20435
20436         # unfortunately, we need to umount to clear dir layout cache for now
20437         # once we fully implement dir layout, we can drop this
20438         umount_client $MOUNT || error "umount failed"
20439         mount_client $MOUNT || error "mount failed"
20440
20441         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
20442         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
20443         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
20444
20445         #set the stripe to be unknown hash type
20446         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
20447         $LCTL set_param fail_loc=0x1901
20448         for ((i = 0; i < 10; i++)); do
20449                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
20450                         error "stat f-$i failed"
20451                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
20452         done
20453
20454         touch $DIR/$tdir/striped_dir/f0 &&
20455                 error "create under striped dir with unknown hash should fail"
20456
20457         $LCTL set_param fail_loc=0
20458
20459         umount_client $MOUNT || error "umount failed"
20460         mount_client $MOUNT || error "mount failed"
20461
20462         return 0
20463 }
20464 run_test 300i "client handle unknown hash type striped directory"
20465
20466 test_300j() {
20467         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20468         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20469         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20470                 skip "Need MDS version at least 2.7.55"
20471
20472         local stripe_count
20473         local file
20474
20475         mkdir $DIR/$tdir
20476
20477         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
20478         $LCTL set_param fail_loc=0x1702
20479         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
20480                 error "set striped dir error"
20481
20482         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
20483                 error "create files under striped dir failed"
20484
20485         $LCTL set_param fail_loc=0
20486
20487         rm -rf $DIR/$tdir || error "unlink striped dir fails"
20488
20489         return 0
20490 }
20491 run_test 300j "test large update record"
20492
20493 test_300k() {
20494         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20495         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20496         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20497                 skip "Need MDS version at least 2.7.55"
20498
20499         # this test needs a huge transaction
20500         local kb
20501         kb=$(do_facet $SINGLEMDS "$LCTL get_param -n \
20502              osd*.$FSNAME-MDT0000.kbytestotal")
20503         [ $kb -lt $((1024*1024)) ] && skip "MDT0 too small: $kb"
20504
20505         local stripe_count
20506         local file
20507
20508         mkdir $DIR/$tdir
20509
20510         #define OBD_FAIL_LARGE_STRIPE   0x1703
20511         $LCTL set_param fail_loc=0x1703
20512         $LFS setdirstripe -i 0 -c192 $DIR/$tdir/striped_dir ||
20513                 error "set striped dir error"
20514         $LCTL set_param fail_loc=0
20515
20516         $LFS getdirstripe $DIR/$tdir/striped_dir ||
20517                 error "getstripeddir fails"
20518         rm -rf $DIR/$tdir/striped_dir ||
20519                 error "unlink striped dir fails"
20520
20521         return 0
20522 }
20523 run_test 300k "test large striped directory"
20524
20525 test_300l() {
20526         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20527         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20528         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20529                 skip "Need MDS version at least 2.7.55"
20530
20531         local stripe_index
20532
20533         test_mkdir -p $DIR/$tdir/striped_dir
20534         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
20535                         error "chown $RUNAS_ID failed"
20536         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
20537                 error "set default striped dir failed"
20538
20539         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
20540         $LCTL set_param fail_loc=0x80000158
20541         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
20542
20543         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
20544         [ $stripe_index -eq 1 ] ||
20545                 error "expect 1 get $stripe_index for $dir"
20546 }
20547 run_test 300l "non-root user to create dir under striped dir with stale layout"
20548
20549 test_300m() {
20550         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20551         [ $MDSCOUNT -ge 2 ] && skip_env "Only for single MDT"
20552         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20553                 skip "Need MDS version at least 2.7.55"
20554
20555         mkdir -p $DIR/$tdir/striped_dir
20556         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
20557                 error "set default stripes dir error"
20558
20559         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
20560
20561         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
20562         [ $stripe_count -eq 0 ] ||
20563                         error "expect 0 get $stripe_count for a"
20564
20565         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
20566                 error "set default stripes dir error"
20567
20568         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
20569
20570         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
20571         [ $stripe_count -eq 0 ] ||
20572                         error "expect 0 get $stripe_count for b"
20573
20574         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
20575                 error "set default stripes dir error"
20576
20577         mkdir $DIR/$tdir/striped_dir/c &&
20578                 error "default stripe_index is invalid, mkdir c should fails"
20579
20580         rm -rf $DIR/$tdir || error "rmdir fails"
20581 }
20582 run_test 300m "setstriped directory on single MDT FS"
20583
20584 cleanup_300n() {
20585         local list=$(comma_list $(mdts_nodes))
20586
20587         trap 0
20588         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
20589 }
20590
20591 test_300n() {
20592         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20593         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20594         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20595                 skip "Need MDS version at least 2.7.55"
20596         remote_mds_nodsh && skip "remote MDS with nodsh"
20597
20598         local stripe_index
20599         local list=$(comma_list $(mdts_nodes))
20600
20601         trap cleanup_300n RETURN EXIT
20602         mkdir -p $DIR/$tdir
20603         chmod 777 $DIR/$tdir
20604         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
20605                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
20606                 error "create striped dir succeeds with gid=0"
20607
20608         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
20609         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
20610                 error "create striped dir fails with gid=-1"
20611
20612         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
20613         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
20614                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
20615                 error "set default striped dir succeeds with gid=0"
20616
20617
20618         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
20619         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
20620                 error "set default striped dir fails with gid=-1"
20621
20622
20623         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
20624         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
20625                                         error "create test_dir fails"
20626         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
20627                                         error "create test_dir1 fails"
20628         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
20629                                         error "create test_dir2 fails"
20630         cleanup_300n
20631 }
20632 run_test 300n "non-root user to create dir under striped dir with default EA"
20633
20634 test_300o() {
20635         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20636         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20637         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20638                 skip "Need MDS version at least 2.7.55"
20639
20640         local numfree1
20641         local numfree2
20642
20643         mkdir -p $DIR/$tdir
20644
20645         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
20646         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
20647         if [ $numfree1 -lt 66000 ] || [ $numfree2 -lt 66000 ]; then
20648                 skip "not enough free inodes $numfree1 $numfree2"
20649         fi
20650
20651         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
20652         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
20653         if [ $numfree1 -lt 300000 ] || [ $numfree2 -lt 300000 ]; then
20654                 skip "not enough free space $numfree1 $numfree2"
20655         fi
20656
20657         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
20658                 error "setdirstripe fails"
20659
20660         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
20661                 error "create dirs fails"
20662
20663         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
20664         ls $DIR/$tdir/striped_dir > /dev/null ||
20665                 error "ls striped dir fails"
20666         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
20667                 error "unlink big striped dir fails"
20668 }
20669 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
20670
20671 test_300p() {
20672         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20673         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20674         remote_mds_nodsh && skip "remote MDS with nodsh"
20675
20676         mkdir -p $DIR/$tdir
20677
20678         #define OBD_FAIL_OUT_ENOSPC     0x1704
20679         do_facet mds2 lctl set_param fail_loc=0x80001704
20680         $LFS setdirstripe -i 0 -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 \
20681                  && error "create striped directory should fail"
20682
20683         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
20684
20685         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
20686         true
20687 }
20688 run_test 300p "create striped directory without space"
20689
20690 test_300q() {
20691         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20692         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20693
20694         local fd=$(free_fd)
20695         local cmd="exec $fd<$tdir"
20696         cd $DIR
20697         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
20698         eval $cmd
20699         cmd="exec $fd<&-"
20700         trap "eval $cmd" EXIT
20701         cd $tdir || error "cd $tdir fails"
20702         rmdir  ../$tdir || error "rmdir $tdir fails"
20703         mkdir local_dir && error "create dir succeeds"
20704         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
20705         eval $cmd
20706         return 0
20707 }
20708 run_test 300q "create remote directory under orphan directory"
20709
20710 test_300r() {
20711         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20712                 skip "Need MDS version at least 2.7.55" && return
20713         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
20714
20715         mkdir $DIR/$tdir
20716
20717         $LFS setdirstripe -i 0 -c -1 $DIR/$tdir/striped_dir ||
20718                 error "set striped dir error"
20719
20720         $LFS getdirstripe $DIR/$tdir/striped_dir ||
20721                 error "getstripeddir fails"
20722
20723         local stripe_count
20724         stripe_count=$($LFS getdirstripe $DIR/$tdir/striped_dir |
20725                       awk '/lmv_stripe_count:/ { print $2 }')
20726
20727         [ $MDSCOUNT -ne $stripe_count ] &&
20728                 error "wrong stripe count $stripe_count expected $MDSCOUNT"
20729
20730         rm -rf $DIR/$tdir/striped_dir ||
20731                 error "unlink striped dir fails"
20732 }
20733 run_test 300r "test -1 striped directory"
20734
20735 prepare_remote_file() {
20736         mkdir $DIR/$tdir/src_dir ||
20737                 error "create remote source failed"
20738
20739         cp /etc/hosts $DIR/$tdir/src_dir/a ||
20740                  error "cp to remote source failed"
20741         touch $DIR/$tdir/src_dir/a
20742
20743         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
20744                 error "create remote target dir failed"
20745
20746         touch $DIR/$tdir/tgt_dir/b
20747
20748         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
20749                 error "rename dir cross MDT failed!"
20750
20751         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
20752                 error "src_child still exists after rename"
20753
20754         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
20755                 error "missing file(a) after rename"
20756
20757         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
20758                 error "diff after rename"
20759 }
20760
20761 test_310a() {
20762         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 4 MDTs"
20763         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20764
20765         local remote_file=$DIR/$tdir/tgt_dir/b
20766
20767         mkdir -p $DIR/$tdir
20768
20769         prepare_remote_file || error "prepare remote file failed"
20770
20771         #open-unlink file
20772         $OPENUNLINK $remote_file $remote_file ||
20773                 error "openunlink $remote_file failed"
20774         $CHECKSTAT -a $remote_file || error "$remote_file exists"
20775 }
20776 run_test 310a "open unlink remote file"
20777
20778 test_310b() {
20779         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 4 MDTs"
20780         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20781
20782         local remote_file=$DIR/$tdir/tgt_dir/b
20783
20784         mkdir -p $DIR/$tdir
20785
20786         prepare_remote_file || error "prepare remote file failed"
20787
20788         ln $remote_file $DIR/$tfile || error "link failed for remote file"
20789         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
20790         $CHECKSTAT -t file $remote_file || error "check file failed"
20791 }
20792 run_test 310b "unlink remote file with multiple links while open"
20793
20794 test_310c() {
20795         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20796         [[ $MDSCOUNT -lt 4 ]] && skip_env "needs >= 4 MDTs"
20797
20798         local remote_file=$DIR/$tdir/tgt_dir/b
20799
20800         mkdir -p $DIR/$tdir
20801
20802         prepare_remote_file || error "prepare remote file failed"
20803
20804         ln $remote_file $DIR/$tfile || error "link failed for remote file"
20805         multiop_bg_pause $remote_file O_uc ||
20806                         error "mulitop failed for remote file"
20807         MULTIPID=$!
20808         $MULTIOP $DIR/$tfile Ouc
20809         kill -USR1 $MULTIPID
20810         wait $MULTIPID
20811 }
20812 run_test 310c "open-unlink remote file with multiple links"
20813
20814 #LU-4825
20815 test_311() {
20816         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20817         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
20818         [ $MDS1_VERSION -lt $(version_code 2.8.54) ] &&
20819                 skip "lustre < 2.8.54 does not contain LU-4825 fix"
20820         remote_mds_nodsh && skip "remote MDS with nodsh"
20821
20822         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
20823         local mdts=$(comma_list $(mdts_nodes))
20824
20825         mkdir -p $DIR/$tdir
20826         $LFS setstripe -i 0 -c 1 $DIR/$tdir
20827         createmany -o $DIR/$tdir/$tfile. 1000
20828
20829         # statfs data is not real time, let's just calculate it
20830         old_iused=$((old_iused + 1000))
20831
20832         local count=$(do_facet $SINGLEMDS "$LCTL get_param -n \
20833                         osp.*OST0000*MDT0000.create_count")
20834         local max_count=$(do_facet $SINGLEMDS "$LCTL get_param -n \
20835                                 osp.*OST0000*MDT0000.max_create_count")
20836         do_nodes $mdts "$LCTL set_param -n osp.*OST0000*.max_create_count=0"
20837
20838         $LFS setstripe -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
20839         local index=$($LFS getstripe -i $DIR/$tdir/$tfile)
20840         [ $index -ne 0 ] || error "$tfile stripe index is 0"
20841
20842         unlinkmany $DIR/$tdir/$tfile. 1000
20843
20844         do_nodes $mdts "$LCTL set_param -n \
20845                         osp.*OST0000*.max_create_count=$max_count"
20846         [ $MDS1_VERSION -lt $(version_code 2.12.51) ] &&
20847                 do_nodes $mdts "$LCTL set_param -n \
20848                                 osp.*OST0000*.create_count=$count"
20849         do_nodes $mdts "$LCTL get_param osp.*OST0000*.create_count" |
20850                         grep "=0" && error "create_count is zero"
20851
20852         local new_iused
20853         for i in $(seq 120); do
20854                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
20855                 # system may be too busy to destroy all objs in time, use
20856                 # a somewhat small value to not fail autotest
20857                 [ $((old_iused - new_iused)) -gt 400 ] && break
20858                 sleep 1
20859         done
20860
20861         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
20862         [ $((old_iused - new_iused)) -gt 400 ] ||
20863                 error "objs not destroyed after unlink"
20864 }
20865 run_test 311 "disable OSP precreate, and unlink should destroy objs"
20866
20867 zfs_oid_to_objid()
20868 {
20869         local ost=$1
20870         local objid=$2
20871
20872         local vdevdir=$(dirname $(facet_vdevice $ost))
20873         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
20874         local zfs_zapid=$(do_facet $ost $cmd |
20875                           grep -w "/O/0/d$((objid%32))" -C 5 |
20876                           awk '/Object/{getline; print $1}')
20877         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
20878                           awk "/$objid = /"'{printf $3}')
20879
20880         echo $zfs_objid
20881 }
20882
20883 zfs_object_blksz() {
20884         local ost=$1
20885         local objid=$2
20886
20887         local vdevdir=$(dirname $(facet_vdevice $ost))
20888         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
20889         local blksz=$(do_facet $ost $cmd $objid |
20890                       awk '/dblk/{getline; printf $4}')
20891
20892         case "${blksz: -1}" in
20893                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
20894                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
20895                 *) ;;
20896         esac
20897
20898         echo $blksz
20899 }
20900
20901 test_312() { # LU-4856
20902         remote_ost_nodsh && skip "remote OST with nodsh"
20903         [ "$ost1_FSTYPE" = "zfs" ] ||
20904                 skip_env "the test only applies to zfs"
20905
20906         local max_blksz=$(do_facet ost1 \
20907                           $ZFS get -p recordsize $(facet_device ost1) |
20908                           awk '!/VALUE/{print $3}')
20909
20910         # to make life a little bit easier
20911         $LFS mkdir -c 1 -i 0 $DIR/$tdir
20912         $LFS setstripe -c 1 -i 0 $DIR/$tdir
20913
20914         local tf=$DIR/$tdir/$tfile
20915         touch $tf
20916         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
20917
20918         # Get ZFS object id
20919         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
20920         # block size change by sequential overwrite
20921         local bs
20922
20923         for ((bs=$PAGE_SIZE; bs <= max_blksz; bs *= 4)) ; do
20924                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
20925
20926                 local blksz=$(zfs_object_blksz ost1 $zfs_objid)
20927                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
20928         done
20929         rm -f $tf
20930
20931         # block size change by sequential append write
20932         dd if=/dev/zero of=$tf bs=$PAGE_SIZE count=1 oflag=sync conv=notrunc
20933         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
20934         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
20935         local count
20936
20937         for ((count = 1; count < $((max_blksz / PAGE_SIZE)); count *= 2)); do
20938                 dd if=/dev/zero of=$tf bs=$PAGE_SIZE count=$count seek=$count \
20939                         oflag=sync conv=notrunc
20940
20941                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
20942                 [ $blksz -eq $((2 * count * PAGE_SIZE)) ] ||
20943                         error "blksz error, actual $blksz, " \
20944                                 "expected: 2 * $count * $PAGE_SIZE"
20945         done
20946         rm -f $tf
20947
20948         # random write
20949         touch $tf
20950         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
20951         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
20952
20953         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
20954         blksz=$(zfs_object_blksz ost1 $zfs_objid)
20955         [ $blksz -eq $PAGE_SIZE ] ||
20956                 error "blksz error: $blksz, expected: $PAGE_SIZE"
20957
20958         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
20959         blksz=$(zfs_object_blksz ost1 $zfs_objid)
20960         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
20961
20962         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
20963         blksz=$(zfs_object_blksz ost1 $zfs_objid)
20964         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
20965 }
20966 run_test 312 "make sure ZFS adjusts its block size by write pattern"
20967
20968 test_313() {
20969         remote_ost_nodsh && skip "remote OST with nodsh"
20970
20971         local file=$DIR/$tfile
20972
20973         rm -f $file
20974         $LFS setstripe -c 1 -i 0 $file || error "setstripe failed"
20975
20976         # define OBD_FAIL_TGT_RCVD_EIO           0x720
20977         do_facet ost1 "$LCTL set_param fail_loc=0x720"
20978         dd if=/dev/zero of=$file bs=$PAGE_SIZE oflag=direct count=1 &&
20979                 error "write should failed"
20980         do_facet ost1 "$LCTL set_param fail_loc=0"
20981         rm -f $file
20982 }
20983 run_test 313 "io should fail after last_rcvd update fail"
20984
20985 test_314() {
20986         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
20987
20988         $LFS setstripe -c 2 -i 0 $DIR/$tfile || error "setstripe failed"
20989         do_facet ost1 "$LCTL set_param fail_loc=0x720"
20990         rm -f $DIR/$tfile
20991         wait_delete_completed
20992         do_facet ost1 "$LCTL set_param fail_loc=0"
20993 }
20994 run_test 314 "OSP shouldn't fail after last_rcvd update failure"
20995
20996 test_315() { # LU-618
20997         [ -f /proc/$$/io ] || skip_env "no IO accounting in kernel"
20998
20999         local file=$DIR/$tfile
21000         rm -f $file
21001
21002         $MULTIOP $file oO_CREAT:O_DIRECT:O_RDWR:w4063232c ||
21003                 error "multiop file write failed"
21004         $MULTIOP $file oO_RDONLY:r4063232_c &
21005         PID=$!
21006
21007         sleep 2
21008
21009         local rbytes=$(awk '/read_bytes/ { print $2 }' /proc/$PID/io)
21010         kill -USR1 $PID
21011
21012         [ $rbytes -gt 4000000 ] || error "read is not accounted ($rbytes)"
21013         rm -f $file
21014 }
21015 run_test 315 "read should be accounted"
21016
21017 test_316() {
21018         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
21019         large_xattr_enabled || skip_env "ea_inode feature disabled"
21020
21021         rm -rf $DIR/$tdir/d
21022         mkdir -p $DIR/$tdir/d
21023         chown nobody $DIR/$tdir/d
21024         touch $DIR/$tdir/d/file
21025
21026         $LFS mv -m1 $DIR/$tdir/d || error "lfs mv failed"
21027 }
21028 run_test 316 "lfs mv"
21029
21030 test_317() {
21031         [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
21032                 skip "Need MDS version at least 2.11.53"
21033         if [ "$ost1_FSTYPE" == "zfs" ]; then
21034                 skip "LU-10370: no implementation for ZFS"
21035         fi
21036
21037         local trunc_sz
21038         local grant_blk_size
21039
21040         grant_blk_size=$($LCTL get_param osc.$FSNAME*.import |
21041                         awk '/grant_block_size:/ { print $2; exit; }')
21042         #
21043         # Create File of size 5M. Truncate it to below size's and verify
21044         # blocks count.
21045         #
21046         dd if=/dev/zero of=$DIR/$tfile bs=5M count=1 conv=fsync ||
21047                 error "Create file $DIR/$tfile failed"
21048         stack_trap "rm -f $DIR/$tfile" EXIT
21049
21050         for trunc_sz in 2097152 4097 4000 509 0; do
21051                 $TRUNCATE $DIR/$tfile $trunc_sz ||
21052                         error "truncate $tfile to $trunc_sz failed"
21053                 local sz=$(stat --format=%s $DIR/$tfile)
21054                 local blk=$(stat --format=%b $DIR/$tfile)
21055                 local trunc_blk=$((((trunc_sz + (grant_blk_size - 1) ) /
21056                                      grant_blk_size) * 8))
21057
21058                 if [[ $blk -ne $trunc_blk ]]; then
21059                         $(which stat) $DIR/$tfile
21060                         error "Expected Block $trunc_blk got $blk for $tfile"
21061                 fi
21062
21063                 $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
21064                         error "Expected Size $trunc_sz got $sz for $tfile"
21065         done
21066
21067         #
21068         # sparse file test
21069         # Create file with a hole and write actual two blocks. Block count
21070         # must be 16.
21071         #
21072         dd if=/dev/zero of=$DIR/$tfile bs=$grant_blk_size count=2 seek=5 \
21073                 conv=fsync || error "Create file : $DIR/$tfile"
21074
21075         # Calculate the final truncate size.
21076         trunc_sz=$(($(stat --format=%s $DIR/$tfile) - (grant_blk_size + 1)))
21077
21078         #
21079         # truncate to size $trunc_sz bytes. Strip the last block
21080         # The block count must drop to 8
21081         #
21082         $TRUNCATE $DIR/$tfile $trunc_sz ||
21083                 error "truncate $tfile to $trunc_sz failed"
21084
21085         local trunc_bsz=$((grant_blk_size / $(stat --format=%B $DIR/$tfile)))
21086         sz=$(stat --format=%s $DIR/$tfile)
21087         blk=$(stat --format=%b $DIR/$tfile)
21088
21089         if [[ $blk -ne $trunc_bsz ]]; then
21090                 $(which stat) $DIR/$tfile
21091                 error "Expected Block $trunc_bsz got $blk for $tfile"
21092         fi
21093
21094         $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
21095                 error "Expected Size $trunc_sz got $sz for $tfile"
21096 }
21097 run_test 317 "Verify blocks get correctly update after truncate"
21098
21099 test_318() {
21100         local old_max_active=$($LCTL get_param -n \
21101                             llite.*.max_read_ahead_async_active 2>/dev/null)
21102
21103         $LCTL set_param llite.*.max_read_ahead_async_active=256
21104         local max_active=$($LCTL get_param -n \
21105                            llite.*.max_read_ahead_async_active 2>/dev/null)
21106         [ $max_active -ne 256 ] && error "expected 256 but got $max_active"
21107
21108         $LCTL set_param llite.*.max_read_ahead_async_active=0 ||
21109                 error "set max_read_ahead_async_active should succeed"
21110
21111         $LCTL set_param llite.*.max_read_ahead_async_active=512
21112         max_active=$($LCTL get_param -n \
21113                      llite.*.max_read_ahead_async_active 2>/dev/null)
21114         [ $max_active -eq 512 ] || error "expected 512 but got $max_active"
21115
21116         # restore @max_active
21117         [ $old_max_active -ne 0 ] && $LCTL set_param \
21118                 llite.*.max_read_ahead_async_active=$old_max_active
21119
21120         local old_threshold=$($LCTL get_param -n \
21121                 llite.*.read_ahead_async_file_threshold_mb 2>/dev/null)
21122         local max_per_file_mb=$($LCTL get_param -n \
21123                 llite.*.max_read_ahead_per_file_mb 2>/dev/null)
21124
21125         local invalid=$(($max_per_file_mb + 1))
21126         $LCTL set_param \
21127                 llite.*.read_ahead_async_file_threshold_mb=$invalid\
21128                         && error "set $invalid should fail"
21129
21130         local valid=$(($invalid - 1))
21131         $LCTL set_param \
21132                 llite.*.read_ahead_async_file_threshold_mb=$valid ||
21133                         error "set $valid should succeed"
21134         local threshold=$($LCTL get_param -n \
21135                 llite.*.read_ahead_async_file_threshold_mb 2>/dev/null)
21136         [ $threshold -eq $valid ] || error \
21137                 "expect threshold $valid got $threshold"
21138         $LCTL set_param \
21139                 llite.*.read_ahead_async_file_threshold_mb=$old_threshold
21140 }
21141 run_test 318 "Verify async readahead tunables"
21142
21143 test_319() {
21144         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
21145
21146         local before=$(date +%s)
21147         local evict
21148         local mdir=$DIR/$tdir
21149         local file=$mdir/xxx
21150
21151         $LFS mkdir -i0 $mdir || error "mkdir $mdir fails"
21152         touch $file
21153
21154 #define OBD_FAIL_LDLM_LOCAL_CANCEL_PAUSE 0x32c
21155         $LCTL set_param fail_val=5 fail_loc=0x8000032c
21156         $LFS mv -m1 $file &
21157
21158         sleep 1
21159         dd if=$file of=/dev/null
21160         wait
21161         evict=$($LCTL get_param mdc.$FSNAME-MDT*.state |
21162           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
21163
21164         [ -z "$evict" ] || [[ $evict -le $before ]] || error "eviction happened"
21165 }
21166 run_test 319 "lost lease lock on migrate error"
21167
21168 test_398a() { # LU-4198
21169         $LFS setstripe -c 1 -i 0 $DIR/$tfile
21170         $LCTL set_param ldlm.namespaces.*.lru_size=clear
21171
21172         # request a new lock on client
21173         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
21174
21175         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=direct conv=notrunc
21176         local lock_count=$($LCTL get_param -n \
21177                            ldlm.namespaces.*-OST0000-osc-ffff*.lru_size)
21178         [[ $lock_count -eq 0 ]] || error "lock should be cancelled by direct IO"
21179
21180         $LCTL set_param ldlm.namespaces.*-OST0000-osc-ffff*.lru_size=clear
21181
21182         # no lock cached, should use lockless IO and not enqueue new lock
21183         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=direct conv=notrunc
21184         lock_count=$($LCTL get_param -n \
21185                      ldlm.namespaces.*-OST0000-osc-ffff*.lru_size)
21186         [[ $lock_count -eq 0 ]] || error "no lock should be held by direct IO"
21187 }
21188 run_test 398a "direct IO should cancel lock otherwise lockless"
21189
21190 test_398b() { # LU-4198
21191         which fio || skip_env "no fio installed"
21192         $LFS setstripe -c -1 $DIR/$tfile
21193
21194         local size=12
21195         dd if=/dev/zero of=$DIR/$tfile bs=1M count=$size
21196
21197         local njobs=4
21198         echo "mix direct rw ${size}M to OST0 by fio with $njobs jobs..."
21199         fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE --direct=1 \
21200                 --numjobs=$njobs --fallocate=none \
21201                 --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
21202                 --filename=$DIR/$tfile &
21203         bg_pid=$!
21204
21205         echo "mix buffer rw ${size}M to OST0 by fio with $njobs jobs..."
21206         fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE \
21207                 --numjobs=$njobs --fallocate=none \
21208                 --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
21209                 --filename=$DIR/$tfile || true
21210         wait $bg_pid
21211
21212         rm -rf $DIR/$tfile
21213 }
21214 run_test 398b "DIO and buffer IO race"
21215
21216 test_398c() { # LU-4198
21217         which fio || skip_env "no fio installed"
21218
21219         saved_debug=$($LCTL get_param -n debug)
21220         $LCTL set_param debug=0
21221
21222         local size=$(lctl get_param -n osc.$FSNAME-OST0000*.kbytesavail | head -1)
21223         ((size /= 1024)) # by megabytes
21224         ((size /= 2)) # write half of the OST at most
21225         [ $size -gt 40 ] && size=40 #reduce test time anyway
21226
21227         $LFS setstripe -c 1 $DIR/$tfile
21228
21229         # it seems like ldiskfs reserves more space than necessary if the
21230         # writing blocks are not mapped, so it extends the file firstly
21231         dd if=/dev/zero of=$DIR/$tfile bs=1M count=$size && sync
21232         cancel_lru_locks osc
21233
21234         # clear and verify rpc_stats later
21235         $LCTL set_param osc.${FSNAME}-OST0000-osc-ffff*.rpc_stats=clear
21236
21237         local njobs=4
21238         echo "writing ${size}M to OST0 by fio with $njobs jobs..."
21239         fio --name=rand-write --rw=randwrite --bs=$PAGE_SIZE --direct=1 \
21240                 --numjobs=$njobs --fallocate=none --ioengine=libaio \
21241                 --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
21242                 --filename=$DIR/$tfile
21243         [ $? -eq 0 ] || error "fio write error"
21244
21245         [ $($LCTL get_param -n \
21246          ldlm.namespaces.${FSNAME}-OST0000-osc-ffff*.lock_count) -eq 0 ] ||
21247                 error "Locks were requested while doing AIO"
21248
21249         # get the percentage of 1-page I/O
21250         pct=$($LCTL get_param osc.${FSNAME}-OST0000-osc-ffff*.rpc_stats |
21251                 grep -A 1 'pages per rpc' | grep -v 'pages per rpc' |
21252                 awk '{print $7}')
21253         [ $pct -le 50 ] || error "$pct% of I/O are 1-page"
21254
21255         echo "mix rw ${size}M to OST0 by fio with $njobs jobs..."
21256         fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE --direct=1 \
21257                 --numjobs=$njobs --fallocate=none --ioengine=libaio \
21258                 --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
21259                 --filename=$DIR/$tfile
21260         [ $? -eq 0 ] || error "fio mixed read write error"
21261
21262         rm -rf $DIR/$tfile
21263         $LCTL set_param debug="$saved_debug"
21264 }
21265 run_test 398c "run fio to test AIO"
21266
21267 test_fake_rw() {
21268         local read_write=$1
21269         if [ "$read_write" = "write" ]; then
21270                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
21271         elif [ "$read_write" = "read" ]; then
21272                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
21273         else
21274                 error "argument error"
21275         fi
21276
21277         # turn off debug for performance testing
21278         local saved_debug=$($LCTL get_param -n debug)
21279         $LCTL set_param debug=0
21280
21281         $LFS setstripe -c 1 -i 0 $DIR/$tfile
21282
21283         # get ost1 size - $FSNAME-OST0000
21284         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
21285         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
21286         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
21287
21288         if [ "$read_write" = "read" ]; then
21289                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
21290         fi
21291
21292         local start_time=$(date +%s.%N)
21293         $dd_cmd bs=1M count=$blocks oflag=sync ||
21294                 error "real dd $read_write error"
21295         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
21296
21297         if [ "$read_write" = "write" ]; then
21298                 rm -f $DIR/$tfile
21299         fi
21300
21301         # define OBD_FAIL_OST_FAKE_RW           0x238
21302         do_facet ost1 $LCTL set_param fail_loc=0x238
21303
21304         local start_time=$(date +%s.%N)
21305         $dd_cmd bs=1M count=$blocks oflag=sync ||
21306                 error "fake dd $read_write error"
21307         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
21308
21309         if [ "$read_write" = "write" ]; then
21310                 # verify file size
21311                 cancel_lru_locks osc
21312                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
21313                         error "$tfile size not $blocks MB"
21314         fi
21315         do_facet ost1 $LCTL set_param fail_loc=0
21316
21317         echo "fake $read_write $duration_fake vs. normal $read_write" \
21318                 "$duration in seconds"
21319         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
21320                 error_not_in_vm "fake write is slower"
21321
21322         $LCTL set_param -n debug="$saved_debug"
21323         rm -f $DIR/$tfile
21324 }
21325 test_399a() { # LU-7655 for OST fake write
21326         remote_ost_nodsh && skip "remote OST with nodsh"
21327
21328         test_fake_rw write
21329 }
21330 run_test 399a "fake write should not be slower than normal write"
21331
21332 test_399b() { # LU-8726 for OST fake read
21333         remote_ost_nodsh && skip "remote OST with nodsh"
21334         if [ "$ost1_FSTYPE" != "ldiskfs" ]; then
21335                 skip_env "ldiskfs only test"
21336         fi
21337
21338         test_fake_rw read
21339 }
21340 run_test 399b "fake read should not be slower than normal read"
21341
21342 test_400a() { # LU-1606, was conf-sanity test_74
21343         if ! which $CC > /dev/null 2>&1; then
21344                 skip_env "$CC is not installed"
21345         fi
21346
21347         local extra_flags=''
21348         local out=$TMP/$tfile
21349         local prefix=/usr/include/lustre
21350         local prog
21351
21352         # Oleg removes c files in his test rig so test if any c files exist
21353         [ -z "$(ls -A $LUSTRE_TESTS_API_DIR)" ] && \
21354                 skip_env "Needed c test files are missing"
21355
21356         if ! [[ -d $prefix ]]; then
21357                 # Assume we're running in tree and fixup the include path.
21358                 extra_flags+=" -I$LUSTRE/../lnet/include/uapi -I$LUSTRE/include/uapi -I$LUSTRE/include"
21359                 extra_flags+=" -L$LUSTRE/utils/.lib"
21360         fi
21361
21362         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
21363                 $CC -Wall -Werror -std=c99 $extra_flags -o $out $prog -llustreapi ||
21364                         error "client api broken"
21365         done
21366         rm -f $out
21367 }
21368 run_test 400a "Lustre client api program can compile and link"
21369
21370 test_400b() { # LU-1606, LU-5011
21371         local header
21372         local out=$TMP/$tfile
21373         local prefix=/usr/include/linux/lustre
21374
21375         # We use a hard coded prefix so that this test will not fail
21376         # when run in tree. There are headers in lustre/include/lustre/
21377         # that are not packaged (like lustre_idl.h) and have more
21378         # complicated include dependencies (like config.h and lnet/types.h).
21379         # Since this test about correct packaging we just skip them when
21380         # they don't exist (see below) rather than try to fixup cppflags.
21381
21382         if ! which $CC > /dev/null 2>&1; then
21383                 skip_env "$CC is not installed"
21384         fi
21385
21386         for header in $prefix/*.h; do
21387                 if ! [[ -f "$header" ]]; then
21388                         continue
21389                 fi
21390
21391                 if [[ "$(basename $header)" == lustre_ioctl.h ]]; then
21392                         continue # lustre_ioctl.h is internal header
21393                 fi
21394
21395                 $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out ||
21396                         error "cannot compile '$header'"
21397         done
21398         rm -f $out
21399 }
21400 run_test 400b "packaged headers can be compiled"
21401
21402 test_401a() { #LU-7437
21403         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
21404         [ -n "$printf_arg" ] && skip_env "find does not support -printf"
21405
21406         #count the number of parameters by "list_param -R"
21407         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
21408         #count the number of parameters by listing proc files
21409         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
21410         echo "proc_dirs='$proc_dirs'"
21411         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
21412         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
21413                       sort -u | wc -l)
21414
21415         [ $params -eq $procs ] ||
21416                 error "found $params parameters vs. $procs proc files"
21417
21418         # test the list_param -D option only returns directories
21419         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
21420         #count the number of parameters by listing proc directories
21421         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
21422                 sort -u | wc -l)
21423
21424         [ $params -eq $procs ] ||
21425                 error "found $params parameters vs. $procs proc files"
21426 }
21427 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
21428
21429 test_401b() {
21430         local save=$($LCTL get_param -n jobid_var)
21431         local tmp=testing
21432
21433         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
21434                 error "no error returned when setting bad parameters"
21435
21436         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
21437         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
21438
21439         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
21440         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
21441         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
21442 }
21443 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
21444
21445 test_401c() {
21446         local jobid_var_old=$($LCTL get_param -n jobid_var)
21447         local jobid_var_new
21448
21449         $LCTL set_param jobid_var= &&
21450                 error "no error returned for 'set_param a='"
21451
21452         jobid_var_new=$($LCTL get_param -n jobid_var)
21453         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
21454                 error "jobid_var was changed by setting without value"
21455
21456         $LCTL set_param jobid_var &&
21457                 error "no error returned for 'set_param a'"
21458
21459         jobid_var_new=$($LCTL get_param -n jobid_var)
21460         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
21461                 error "jobid_var was changed by setting without value"
21462 }
21463 run_test 401c "Verify 'lctl set_param' without value fails in either format."
21464
21465 test_401d() {
21466         local jobid_var_old=$($LCTL get_param -n jobid_var)
21467         local jobid_var_new
21468         local new_value="foo=bar"
21469
21470         $LCTL set_param jobid_var=$new_value ||
21471                 error "'set_param a=b' did not accept a value containing '='"
21472
21473         jobid_var_new=$($LCTL get_param -n jobid_var)
21474         [[ "$jobid_var_new" == "$new_value" ]] ||
21475                 error "'set_param a=b' failed on a value containing '='"
21476
21477         # Reset the jobid_var to test the other format
21478         $LCTL set_param jobid_var=$jobid_var_old
21479         jobid_var_new=$($LCTL get_param -n jobid_var)
21480         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
21481                 error "failed to reset jobid_var"
21482
21483         $LCTL set_param jobid_var $new_value ||
21484                 error "'set_param a b' did not accept a value containing '='"
21485
21486         jobid_var_new=$($LCTL get_param -n jobid_var)
21487         [[ "$jobid_var_new" == "$new_value" ]] ||
21488                 error "'set_param a b' failed on a value containing '='"
21489
21490         $LCTL set_param jobid_var $jobid_var_old
21491         jobid_var_new=$($LCTL get_param -n jobid_var)
21492         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
21493                 error "failed to reset jobid_var"
21494 }
21495 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
21496
21497 test_402() {
21498         [[ $MDS1_VERSION -ge $(version_code 2.7.66) ]] ||
21499         [[ $MDS1_VERSION -ge $(version_code 2.7.18.4) &&
21500                 $MDS1_VERSION -lt $(version_code 2.7.50) ]] ||
21501         [[ $MDS1_VERSION -ge $(version_code 2.7.2) &&
21502                 $MDS1_VERSION -lt $(version_code 2.7.11) ]] ||
21503                 skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+"
21504         remote_mds_nodsh && skip "remote MDS with nodsh"
21505
21506         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
21507 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
21508         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
21509         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
21510                 echo "Touch failed - OK"
21511 }
21512 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
21513
21514 test_403() {
21515         local file1=$DIR/$tfile.1
21516         local file2=$DIR/$tfile.2
21517         local tfile=$TMP/$tfile
21518
21519         rm -f $file1 $file2 $tfile
21520
21521         touch $file1
21522         ln $file1 $file2
21523
21524         # 30 sec OBD_TIMEOUT in ll_getattr()
21525         # right before populating st_nlink
21526         $LCTL set_param fail_loc=0x80001409
21527         stat -c %h $file1 > $tfile &
21528
21529         # create an alias, drop all locks and reclaim the dentry
21530         < $file2
21531         cancel_lru_locks mdc
21532         cancel_lru_locks osc
21533         sysctl -w vm.drop_caches=2
21534
21535         wait
21536
21537         [ $(cat $tfile) -gt 0 ] || error "wrong nlink count: $(cat $tfile)"
21538
21539         rm -f $tfile $file1 $file2
21540 }
21541 run_test 403 "i_nlink should not drop to zero due to aliasing"
21542
21543 test_404() { # LU-6601
21544         [[ $MDS1_VERSION -ge $(version_code 2.8.53) ]] ||
21545                 skip "Need server version newer than 2.8.52"
21546         remote_mds_nodsh && skip "remote MDS with nodsh"
21547
21548         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
21549                 awk '/osp .*-osc-MDT/ { print $4}')
21550
21551         local osp
21552         for osp in $mosps; do
21553                 echo "Deactivate: " $osp
21554                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
21555                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
21556                         awk -vp=$osp '$4 == p { print $2 }')
21557                 [ $stat = IN ] || {
21558                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
21559                         error "deactivate error"
21560                 }
21561                 echo "Activate: " $osp
21562                 do_facet $SINGLEMDS $LCTL --device %$osp activate
21563                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
21564                         awk -vp=$osp '$4 == p { print $2 }')
21565                 [ $stat = UP ] || {
21566                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
21567                         error "activate error"
21568                 }
21569         done
21570 }
21571 run_test 404 "validate manual {de}activated works properly for OSPs"
21572
21573 test_405() {
21574         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
21575         [ $MDS1_VERSION -lt $(version_code 2.6.92) ] ||
21576                 [ $CLIENT_VERSION -lt $(version_code 2.6.99) ] &&
21577                         skip "Layout swap lock is not supported"
21578
21579         check_swap_layouts_support
21580
21581         test_mkdir $DIR/$tdir
21582         swap_lock_test -d $DIR/$tdir ||
21583                 error "One layout swap locked test failed"
21584 }
21585 run_test 405 "Various layout swap lock tests"
21586
21587 test_406() {
21588         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
21589         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
21590         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
21591         [ $PARALLEL == "yes" ] && skip "skip parallel run"
21592         [ $MDS1_VERSION -lt $(version_code 2.8.50) ] &&
21593                 skip "Need MDS version at least 2.8.50"
21594
21595         local def_stripe_size=$($LFS getstripe -S $MOUNT)
21596         local test_pool=$TESTNAME
21597
21598         pool_add $test_pool || error "pool_add failed"
21599         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
21600                 error "pool_add_targets failed"
21601
21602         save_layout_restore_at_exit $MOUNT
21603
21604         # parent set default stripe count only, child will stripe from both
21605         # parent and fs default
21606         $LFS setstripe -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
21607                 error "setstripe $MOUNT failed"
21608         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
21609         $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
21610         for i in $(seq 10); do
21611                 local f=$DIR/$tdir/$tfile.$i
21612                 touch $f || error "touch failed"
21613                 local count=$($LFS getstripe -c $f)
21614                 [ $count -eq $OSTCOUNT ] ||
21615                         error "$f stripe count $count != $OSTCOUNT"
21616                 local offset=$($LFS getstripe -i $f)
21617                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
21618                 local size=$($LFS getstripe -S $f)
21619                 [ $size -eq $((def_stripe_size * 2)) ] ||
21620                         error "$f stripe size $size != $((def_stripe_size * 2))"
21621                 local pool=$($LFS getstripe -p $f)
21622                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
21623         done
21624
21625         # change fs default striping, delete parent default striping, now child
21626         # will stripe from new fs default striping only
21627         $LFS setstripe -c 1 -S $def_stripe_size -i 0 $MOUNT ||
21628                 error "change $MOUNT default stripe failed"
21629         $LFS setstripe -c 0 $DIR/$tdir ||
21630                 error "delete $tdir default stripe failed"
21631         for i in $(seq 11 20); do
21632                 local f=$DIR/$tdir/$tfile.$i
21633                 touch $f || error "touch $f failed"
21634                 local count=$($LFS getstripe -c $f)
21635                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
21636                 local offset=$($LFS getstripe -i $f)
21637                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
21638                 local size=$($LFS getstripe -S $f)
21639                 [ $size -eq $def_stripe_size ] ||
21640                         error "$f stripe size $size != $def_stripe_size"
21641                 local pool=$($LFS getstripe -p $f)
21642                 [ $pool == $test_pool ] || error "$f pool $pool isn't set"
21643         done
21644
21645         unlinkmany $DIR/$tdir/$tfile. 1 20
21646
21647         local f=$DIR/$tdir/$tfile
21648         pool_remove_all_targets $test_pool $f
21649         pool_remove $test_pool $f
21650 }
21651 run_test 406 "DNE support fs default striping"
21652
21653 test_407() {
21654         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
21655         [[ $MDS1_VERSION -lt $(version_code 2.8.55) ]] &&
21656                 skip "Need MDS version at least 2.8.55"
21657         remote_mds_nodsh && skip "remote MDS with nodsh"
21658
21659         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
21660                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
21661         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
21662                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
21663         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
21664
21665         #define OBD_FAIL_DT_TXN_STOP    0x2019
21666         for idx in $(seq $MDSCOUNT); do
21667                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
21668         done
21669         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
21670         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
21671                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
21672         true
21673 }
21674 run_test 407 "transaction fail should cause operation fail"
21675
21676 test_408() {
21677         dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE count=1 oflag=direct
21678
21679         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
21680         lctl set_param fail_loc=0x8000040a
21681         # let ll_prepare_partial_page() fail
21682         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
21683
21684         rm -f $DIR/$tfile
21685
21686         # create at least 100 unused inodes so that
21687         # shrink_icache_memory(0) should not return 0
21688         touch $DIR/$tfile-{0..100}
21689         rm -f $DIR/$tfile-{0..100}
21690         sync
21691
21692         echo 2 > /proc/sys/vm/drop_caches
21693 }
21694 run_test 408 "drop_caches should not hang due to page leaks"
21695
21696 test_409()
21697 {
21698         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
21699
21700         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
21701         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
21702         touch $DIR/$tdir/guard || error "(2) Fail to create"
21703
21704         local PREFIX=$(str_repeat 'A' 128)
21705         echo "Create 1K hard links start at $(date)"
21706         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
21707                 error "(3) Fail to hard link"
21708
21709         echo "Links count should be right although linkEA overflow"
21710         stat $DIR/$tdir/guard || error "(4) Fail to stat"
21711         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
21712         [ $linkcount -eq 1001 ] ||
21713                 error "(5) Unexpected hard links count: $linkcount"
21714
21715         echo "List all links start at $(date)"
21716         ls -l $DIR/$tdir/foo > /dev/null ||
21717                 error "(6) Fail to list $DIR/$tdir/foo"
21718
21719         echo "Unlink hard links start at $(date)"
21720         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
21721                 error "(7) Fail to unlink"
21722         echo "Unlink hard links finished at $(date)"
21723 }
21724 run_test 409 "Large amount of cross-MDTs hard links on the same file"
21725
21726 test_410()
21727 {
21728         [[ $CLIENT_VERSION -lt $(version_code 2.9.59) ]] &&
21729                 skip "Need client version at least 2.9.59"
21730
21731         # Create a file, and stat it from the kernel
21732         local testfile=$DIR/$tfile
21733         touch $testfile
21734
21735         local run_id=$RANDOM
21736         local my_ino=$(stat --format "%i" $testfile)
21737
21738         # Try to insert the module. This will always fail as the
21739         # module is designed to not be inserted.
21740         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
21741             &> /dev/null
21742
21743         # Anything but success is a test failure
21744         dmesg | grep -q \
21745             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
21746             error "no inode match"
21747 }
21748 run_test 410 "Test inode number returned from kernel thread"
21749
21750 cleanup_test411_cgroup() {
21751         trap 0
21752         rmdir "$1"
21753 }
21754
21755 test_411() {
21756         local cg_basedir=/sys/fs/cgroup/memory
21757         # LU-9966
21758         test -f "$cg_basedir/memory.kmem.limit_in_bytes" ||
21759                 skip "no setup for cgroup"
21760
21761         dd if=/dev/zero of=$DIR/$tfile bs=1M count=100 conv=fsync ||
21762                 error "test file creation failed"
21763         cancel_lru_locks osc
21764
21765         # Create a very small memory cgroup to force a slab allocation error
21766         local cgdir=$cg_basedir/osc_slab_alloc
21767         mkdir $cgdir || error "cgroup mkdir '$cgdir' failed"
21768         trap "cleanup_test411_cgroup $cgdir" EXIT
21769         echo 2M > $cgdir/memory.kmem.limit_in_bytes
21770         echo 1M > $cgdir/memory.limit_in_bytes
21771
21772         # Should not LBUG, just be killed by oom-killer
21773         # dd will return 0 even allocation failure in some environment.
21774         # So don't check return value
21775         sh -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null"
21776         cleanup_test411_cgroup $cgdir
21777
21778         return 0
21779 }
21780 run_test 411 "Slab allocation error with cgroup does not LBUG"
21781
21782 test_412() {
21783         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
21784         if [ $MDS1_VERSION -lt $(version_code 2.10.55) ]; then
21785                 skip "Need server version at least 2.10.55"
21786         fi
21787
21788         $LFS mkdir -i $((MDSCOUNT - 1)),$((MDSCOUNT - 2)) $DIR/$tdir ||
21789                 error "mkdir failed"
21790         $LFS getdirstripe $DIR/$tdir
21791         local stripe_index=$($LFS getdirstripe -i $DIR/$tdir)
21792         [ $stripe_index -eq $((MDSCOUNT - 1)) ] ||
21793                 error "expect $((MDSCOUT - 1)) get $stripe_index"
21794         local stripe_count=$($LFS getdirstripe -T $DIR/$tdir)
21795         [ $stripe_count -eq 2 ] ||
21796                 error "expect 2 get $stripe_count"
21797 }
21798 run_test 412 "mkdir on specific MDTs"
21799
21800 test_qos_mkdir() {
21801         local mkdir_cmd=$1
21802         local stripe_count=$2
21803         local mdts=$(comma_list $(mdts_nodes))
21804
21805         local testdir
21806         local lmv_qos_prio_free
21807         local lmv_qos_threshold_rr
21808         local lmv_qos_maxage
21809         local lod_qos_prio_free
21810         local lod_qos_threshold_rr
21811         local lod_qos_maxage
21812         local count
21813         local i
21814
21815         lmv_qos_prio_free=$($LCTL get_param -n lmv.*.qos_prio_free | head -n1)
21816         lmv_qos_prio_free=${lmv_qos_prio_free%%%}
21817         lmv_qos_threshold_rr=$($LCTL get_param -n lmv.*.qos_threshold_rr |
21818                 head -n1)
21819         lmv_qos_threshold_rr=${lmv_qos_threshold_rr%%%}
21820         lmv_qos_maxage=$($LCTL get_param -n lmv.*.qos_maxage)
21821         stack_trap "$LCTL set_param \
21822                 lmv.*.qos_prio_free=$lmv_qos_prio_free > /dev/null" EXIT
21823         stack_trap "$LCTL set_param \
21824                 lmv.*.qos_threshold_rr=$lmv_qos_threshold_rr > /dev/null" EXIT
21825         stack_trap "$LCTL set_param \
21826                 lmv.*.qos_maxage=$lmv_qos_maxage > /dev/null" EXIT
21827
21828         lod_qos_prio_free=$(do_facet mds1 $LCTL get_param -n \
21829                 lod.$FSNAME-MDT0000-mdtlov.mdt_qos_prio_free | head -n1)
21830         lod_qos_prio_free=${lod_qos_prio_free%%%}
21831         lod_qos_threshold_rr=$(do_facet mds1 $LCTL get_param -n \
21832                 lod.$FSNAME-MDT0000-mdtlov.mdt_qos_threshold_rr | head -n1)
21833         lod_qos_threshold_rr=${lod_qos_threshold_rr%%%}
21834         lod_qos_maxage=$(do_facet mds1 $LCTL get_param -n \
21835                 lod.$FSNAME-MDT0000-mdtlov.qos_maxage | awk '{ print $1 }')
21836         stack_trap "do_nodes $mdts $LCTL set_param \
21837                 lod.*.mdt_qos_prio_free=$lod_qos_prio_free > /dev/null" EXIT
21838         stack_trap "do_nodes $mdts $LCTL set_param \
21839                 lod.*.mdt_qos_threshold_rr=$lod_qos_threshold_rr > /dev/null" \
21840                 EXIT
21841         stack_trap "do_nodes $mdts $LCTL set_param \
21842                 lod.*.mdt_qos_maxage=$lod_qos_maxage > /dev/null" EXIT
21843
21844         echo
21845         echo "Mkdir (stripe_count $stripe_count) roundrobin:"
21846
21847         $LCTL set_param lmv.*.qos_threshold_rr=100 > /dev/null
21848         do_nodes $mdts $LCTL set_param lod.*.mdt_qos_threshold_rr=100 > /dev/null
21849
21850         testdir=$DIR/$tdir-s$stripe_count/rr
21851
21852         for i in $(seq $((100 * MDSCOUNT))); do
21853                 eval $mkdir_cmd $testdir/subdir$i ||
21854                         error "$mkdir_cmd subdir$i failed"
21855         done
21856
21857         for i in $(seq $MDSCOUNT); do
21858                 count=$($LFS getdirstripe -i $testdir/* |
21859                                 grep ^$((i - 1))$ | wc -l)
21860                 echo "$count directories created on MDT$((i - 1))"
21861                 [ $count -eq 100 ] || error "subdirs are not evenly distributed"
21862
21863                 if [ $stripe_count -gt 1 ]; then
21864                         count=$($LFS getdirstripe $testdir/* |
21865                                 grep -P "^\s+$((i - 1))\t" | wc -l)
21866                         echo "$count stripes created on MDT$((i - 1))"
21867                         # deviation should < 5% of average
21868                         [ $count -lt $((95 * stripe_count)) ] ||
21869                         [ $count -gt $((105 * stripe_count)) ] &&
21870                                 error "stripes are not evenly distributed"
21871                 fi
21872         done
21873
21874         $LCTL set_param lmv.*.qos_threshold_rr=$lmv_qos_threshold_rr > /dev/null
21875         do_nodes $mdts $LCTL set_param \
21876                 lod.*.mdt_qos_threshold_rr=$lod_qos_threshold_rr > /dev/null
21877
21878         echo
21879         echo "Check for uneven MDTs: "
21880
21881         local ffree
21882         local bavail
21883         local max
21884         local min
21885         local max_index
21886         local min_index
21887         local tmp
21888
21889         ffree=($(lctl get_param -n mdc.*[mM][dD][cC]-[^M]*.filesfree))
21890         bavail=($(lctl get_param -n mdc.*[mM][dD][cC]-[^M]*.kbytesavail))
21891         bsize=$(lctl get_param -n mdc.*MDT0000*.blocksize)
21892
21893         max=$(((${ffree[0]} >> 8) * (${bavail[0]} * bsize >> 16)))
21894         min=$(((${ffree[0]} >> 8) * (${bavail[0]} * bsize >> 16)))
21895         max_index=0
21896         min_index=0
21897         for ((i = 1; i < ${#ffree[@]}; i++)); do
21898                 tmp=$(((${ffree[i]} >> 8) * (${bavail[i]} * bsize >> 16)))
21899                 if [ $tmp -gt $max ]; then
21900                         max=$tmp
21901                         max_index=$i
21902                 fi
21903                 if [ $tmp -lt $min ]; then
21904                         min=$tmp
21905                         min_index=$i
21906                 fi
21907         done
21908
21909         [ ${ffree[min_index]} -eq 0 ] &&
21910                 skip "no free files in MDT$min_index"
21911         [ ${ffree[min_index]} -gt 100000000 ] &&
21912                 skip "too much free files in MDT$min_index"
21913
21914         # Check if we need to generate uneven MDTs
21915         local threshold=50
21916         local diff=$(((max - min) * 100 / min))
21917         local value="$(generate_string 1024)"
21918
21919         while [ $diff -lt $threshold ]; do
21920                 # generate uneven MDTs, create till $threshold% diff
21921                 echo -n "weight diff=$diff% must be > $threshold% ..."
21922                 count=$((${ffree[min_index]} / 10))
21923                 # 50 sec per 10000 files in vm
21924                 [ $count -gt 40000 ] && [ "$SLOW" = "no" ] &&
21925                         skip "$count files to create"
21926                 echo "Fill MDT$min_index with $count files"
21927                 [ -d $DIR/$tdir-MDT$min_index ] ||
21928                         $LFS mkdir -i $min_index $DIR/$tdir-MDT$min_index ||
21929                         error "mkdir $tdir-MDT$min_index failed"
21930                 for i in $(seq $count); do
21931                         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE \
21932                                 $DIR/$tdir-MDT$min_index/f$j_$i > /dev/null ||
21933                                 error "create f$j_$i failed"
21934                         setfattr -n user.413b -v $value \
21935                                 $DIR/$tdir-MDT$min_index/f$j_$i ||
21936                                 error "setfattr f$j_$i failed"
21937                 done
21938
21939                 ffree=($(lctl get_param -n mdc.*[mM][dD][cC]-*.filesfree))
21940                 bavail=($(lctl get_param -n mdc.*[mM][dD][cC]-*.kbytesavail))
21941                 max=$(((${ffree[max_index]} >> 8) * \
21942                         (${bavail[max_index]} * bsize >> 16)))
21943                 min=$(((${ffree[min_index]} >> 8) * \
21944                         (${bavail[min_index]} * bsize >> 16)))
21945                 diff=$(((max - min) * 100 / min))
21946         done
21947
21948         echo "MDT filesfree available: ${ffree[@]}"
21949         echo "MDT blocks available: ${bavail[@]}"
21950         echo "weight diff=$diff%"
21951
21952         echo
21953         echo "Mkdir (stripe_count $stripe_count) with balanced space usage:"
21954
21955         $LCTL set_param lmv.*.qos_prio_free=100 > /dev/null
21956         do_nodes $mdts $LCTL set_param lod.*.mdt_qos_prio_free=100 > /dev/null
21957         # decrease statfs age, so that it can be updated in time
21958         $LCTL set_param lmv.*.qos_maxage=1 > /dev/null
21959         do_nodes $mdts $LCTL set_param lod.*.mdt_qos_maxage=1 > /dev/null
21960
21961         sleep 1
21962
21963         testdir=$DIR/$tdir-s$stripe_count/qos
21964
21965         for i in $(seq $((100 * MDSCOUNT))); do
21966                 eval $mkdir_cmd $testdir/subdir$i ||
21967                         error "$mkdir_cmd subdir$i failed"
21968         done
21969
21970         for i in $(seq $MDSCOUNT); do
21971                 count=$($LFS getdirstripe -i $testdir/* | grep ^$((i - 1))$ |
21972                         wc -l)
21973                 echo "$count directories created on MDT$((i - 1))"
21974
21975                 if [ $stripe_count -gt 1 ]; then
21976                         count=$($LFS getdirstripe $testdir/* |
21977                                 grep -P "^\s+$((i - 1))\t" | wc -l)
21978                         echo "$count stripes created on MDT$((i - 1))"
21979                 fi
21980         done
21981
21982         max=$($LFS getdirstripe -i $testdir/* | grep ^$max_index$ | wc -l)
21983         min=$($LFS getdirstripe -i $testdir/* | grep ^$min_index$ | wc -l)
21984
21985         # D-value should > 10% of averge
21986         [ $((max - min)) -lt 10 ] &&
21987                 error "subdirs shouldn't be evenly distributed"
21988
21989         # ditto
21990         if [ $stripe_count -gt 1 ]; then
21991                 max=$($LFS getdirstripe $testdir/* |
21992                         grep -P "^\s+$max_index\t" | wc -l)
21993                 min=$($LFS getdirstripe $testdir/* |
21994                         grep -P "^\s+$min_index\t" | wc -l)
21995                 [ $((max - min)) -le $((10 * stripe_count)) ] &&
21996                         error "stripes shouldn't be evenly distributed"|| true
21997         fi
21998 }
21999
22000 test_413a() {
22001         [ $MDSCOUNT -lt 2 ] &&
22002                 skip "We need at least 2 MDTs for this test"
22003
22004         [ $MDS1_VERSION -lt $(version_code 2.12.52) ] &&
22005                 skip "Need server version at least 2.12.52"
22006
22007         local stripe_count
22008
22009         for stripe_count in $(seq 1 $((MDSCOUNT - 1))); do
22010                 mkdir $DIR/$tdir-s$stripe_count || error "mkdir failed"
22011                 mkdir $DIR/$tdir-s$stripe_count/rr || error "mkdir failed"
22012                 mkdir $DIR/$tdir-s$stripe_count/qos || error "mkdir failed"
22013                 test_qos_mkdir "$LFS mkdir -c $stripe_count" $stripe_count
22014         done
22015 }
22016 run_test 413a "QoS mkdir with 'lfs mkdir -i -1'"
22017
22018 test_413b() {
22019         [ $MDSCOUNT -lt 2 ] &&
22020                 skip "We need at least 2 MDTs for this test"
22021
22022         [ $MDS1_VERSION -lt $(version_code 2.12.52) ] &&
22023                 skip "Need server version at least 2.12.52"
22024
22025         local stripe_count
22026
22027         for stripe_count in $(seq 1 $((MDSCOUNT - 1))); do
22028                 mkdir $DIR/$tdir-s$stripe_count || error "mkdir failed"
22029                 mkdir $DIR/$tdir-s$stripe_count/rr || error "mkdir failed"
22030                 mkdir $DIR/$tdir-s$stripe_count/qos || error "mkdir failed"
22031                 $LFS setdirstripe -D -c $stripe_count \
22032                         $DIR/$tdir-s$stripe_count/rr ||
22033                         error "setdirstripe failed"
22034                 $LFS setdirstripe -D -c $stripe_count \
22035                         $DIR/$tdir-s$stripe_count/qos ||
22036                         error "setdirstripe failed"
22037                 test_qos_mkdir "mkdir" $stripe_count
22038         done
22039 }
22040 run_test 413b "QoS mkdir under dir whose default LMV starting MDT offset is -1"
22041
22042 test_414() {
22043 #define OBD_FAIL_PTLRPC_BULK_ATTACH      0x521
22044         $LCTL set_param fail_loc=0x80000521
22045         dd if=/dev/zero of=$DIR/$tfile bs=2M count=1 oflag=sync
22046         rm -f $DIR/$tfile
22047 }
22048 run_test 414 "simulate ENOMEM in ptlrpc_register_bulk()"
22049
22050 test_415() {
22051         [ $PARALLEL == "yes" ] && skip "skip parallel run"
22052         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
22053                 skip "Need server version at least 2.11.52"
22054
22055         # LU-11102
22056         local total
22057         local setattr_pid
22058         local start_time
22059         local end_time
22060         local duration
22061
22062         total=500
22063         # this test may be slow on ZFS
22064         [ "$mds1_FSTYPE" == "zfs" ] && total=100
22065
22066         # though this test is designed for striped directory, let's test normal
22067         # directory too since lock is always saved as CoS lock.
22068         test_mkdir $DIR/$tdir || error "mkdir $tdir"
22069         createmany -o $DIR/$tdir/$tfile. $total || error "createmany"
22070
22071         (
22072                 while true; do
22073                         touch $DIR/$tdir
22074                 done
22075         ) &
22076         setattr_pid=$!
22077
22078         start_time=$(date +%s)
22079         for i in $(seq $total); do
22080                 mrename $DIR/$tdir/$tfile.$i $DIR/$tdir/$tfile-new.$i \
22081                         > /dev/null
22082         done
22083         end_time=$(date +%s)
22084         duration=$((end_time - start_time))
22085
22086         kill -9 $setattr_pid
22087
22088         echo "rename $total files took $duration sec"
22089         [ $duration -lt 100 ] || error "rename took $duration sec"
22090 }
22091 run_test 415 "lock revoke is not missing"
22092
22093 test_416() {
22094         [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
22095                 skip "Need server version at least 2.11.55"
22096
22097         # define OBD_FAIL_OSD_TXN_START    0x19a
22098         do_facet mds1 lctl set_param fail_loc=0x19a
22099
22100         lfs mkdir -c $MDSCOUNT $DIR/$tdir
22101
22102         true
22103 }
22104 run_test 416 "transaction start failure won't cause system hung"
22105
22106 cleanup_417() {
22107         trap 0
22108         do_nodes $(comma_list $(mdts_nodes)) \
22109                 "$LCTL set_param -n mdt.*MDT*.enable_dir_migration=1"
22110         do_nodes $(comma_list $(mdts_nodes)) \
22111                 "$LCTL set_param -n mdt.*MDT*.enable_remote_dir=1"
22112         do_nodes $(comma_list $(mdts_nodes)) \
22113                 "$LCTL set_param -n mdt.*MDT*.enable_striped_dir=1"
22114 }
22115
22116 test_417() {
22117         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
22118         [[ $MDS1_VERSION -lt $(version_code 2.11.56) ]] &&
22119                 skip "Need MDS version at least 2.11.56"
22120
22121         trap cleanup_417 RETURN EXIT
22122
22123         $LFS mkdir -i 1 $DIR/$tdir.1 || error "create remote dir $tdir.1 failed"
22124         do_nodes $(comma_list $(mdts_nodes)) \
22125                 "$LCTL set_param -n mdt.*MDT*.enable_dir_migration=0"
22126         $LFS migrate -m 0 $DIR/$tdir.1 &&
22127                 error "migrate dir $tdir.1 should fail"
22128
22129         do_nodes $(comma_list $(mdts_nodes)) \
22130                 "$LCTL set_param -n mdt.*MDT*.enable_remote_dir=0"
22131         $LFS mkdir -i 1 $DIR/$tdir.2 &&
22132                 error "create remote dir $tdir.2 should fail"
22133
22134         do_nodes $(comma_list $(mdts_nodes)) \
22135                 "$LCTL set_param -n mdt.*MDT*.enable_striped_dir=0"
22136         $LFS mkdir -c 2 $DIR/$tdir.3 &&
22137                 error "create striped dir $tdir.3 should fail"
22138         true
22139 }
22140 run_test 417 "disable remote dir, striped dir and dir migration"
22141
22142 # Checks that the outputs of df [-i] and lfs df [-i] match
22143 #
22144 # usage: check_lfs_df <blocks | inodes> <mountpoint>
22145 check_lfs_df() {
22146         local dir=$2
22147         local inodes
22148         local df_out
22149         local lfs_df_out
22150         local count
22151         local passed=false
22152
22153         # blocks or inodes
22154         [ "$1" == "blocks" ] && inodes= || inodes="-i"
22155
22156         for count in {1..100}; do
22157                 cancel_lru_locks
22158                 sync; sleep 0.2
22159
22160                 # read the lines of interest
22161                 df_out=($(df -P $inodes $dir | tail -n +2)) ||
22162                         error "df $inodes $dir | tail -n +2 failed"
22163                 lfs_df_out=($($LFS df $inodes $dir | grep summary:)) ||
22164                         error "lfs df $inodes $dir | grep summary: failed"
22165
22166                 # skip first substrings of each output as they are different
22167                 # "<NID>:/<fsname>" for df, "filesystem_summary:" for lfs df
22168                 # compare the two outputs
22169                 passed=true
22170                 for i in {1..5}; do
22171                         [ "${df_out[i]}" != "${lfs_df_out[i]}" ] && passed=false
22172                 done
22173                 $passed && break
22174         done
22175
22176         if ! $passed; then
22177                 df -P $inodes $dir
22178                 echo
22179                 lfs df $inodes $dir
22180                 error "df and lfs df $1 output mismatch: "      \
22181                       "df ${inodes}: ${df_out[*]}, "            \
22182                       "lfs df ${inodes}: ${lfs_df_out[*]}"
22183         fi
22184 }
22185
22186 test_418() {
22187         [ $PARALLEL == "yes" ] && skip "skip parallel run"
22188
22189         local dir=$DIR/$tdir
22190         local numfiles=$((RANDOM % 4096 + 2))
22191         local numblocks=$((RANDOM % 256 + 1))
22192
22193         wait_delete_completed
22194         test_mkdir $dir
22195
22196         # check block output
22197         check_lfs_df blocks $dir
22198         # check inode output
22199         check_lfs_df inodes $dir
22200
22201         # create a single file and retest
22202         echo "Creating a single file and testing"
22203         createmany -o $dir/$tfile- 1 &>/dev/null ||
22204                 error "creating 1 file in $dir failed"
22205         check_lfs_df blocks $dir
22206         check_lfs_df inodes $dir
22207
22208         # create a random number of files
22209         echo "Creating $((numfiles - 1)) files and testing"
22210         createmany -o $dir/$tfile- 1 $((numfiles - 1)) &>/dev/null ||
22211                 error "creating $((numfiles - 1)) files in $dir failed"
22212
22213         # write a random number of blocks to the first test file
22214         echo "Writing $numblocks 4K blocks and testing"
22215         dd if=/dev/urandom of=$dir/${tfile}-0 bs=4K conv=fsync \
22216                 count=$numblocks &>/dev/null ||
22217                 error "dd to $dir/${tfile}-0 failed"
22218
22219         # retest
22220         check_lfs_df blocks $dir
22221         check_lfs_df inodes $dir
22222
22223         unlinkmany $dir/$tfile- $numfiles &>/dev/null ||
22224                 error "unlinking $numfiles files in $dir failed"
22225 }
22226 run_test 418 "df and lfs df outputs match"
22227
22228 test_419()
22229 {
22230         local dir=$DIR/$tdir
22231
22232         mkdir -p $dir
22233         touch $dir/file
22234
22235         cancel_lru_locks mdc
22236
22237         #OBD_FAIL_LLITE_OPEN_BY_NAME    0x1410
22238         $LCTL set_param fail_loc=0x1410
22239         cat $dir/file
22240         $LCTL set_param fail_loc=0
22241         rm -rf $dir
22242 }
22243 run_test 419 "Verify open file by name doesn't crash kernel"
22244
22245 test_420()
22246 {
22247         [[ $MDS1_VERSION -ge $(version_code 2.12.53) ]] ||
22248                 skip "Need MDS version at least 2.12.53"
22249
22250         local SAVE_UMASK=$(umask)
22251         local dir=$DIR/$tdir
22252         local uname=$(getent passwd $RUNAS_ID | cut -d: -f1)
22253
22254         mkdir -p $dir
22255         umask 0000
22256         mkdir -m03777 $dir/testdir
22257         ls -dn $dir/testdir
22258         # Need to remove trailing '.' when SELinux is enabled
22259         local dirperms=$(ls -dn $dir/testdir |
22260                          awk '{ sub(/\.$/, "", $1); print $1}')
22261         [ $dirperms == "drwxrwsrwt" ] ||
22262                 error "incorrect perms on $dir/testdir"
22263
22264         su - $uname -c "PATH=$LUSTRE/tests:\$PATH; \
22265                 openfile -f O_RDONLY:O_CREAT -m 02755 $dir/testdir/testfile"
22266         ls -n $dir/testdir/testfile
22267         local fileperms=$(ls -n $dir/testdir/testfile |
22268                           awk '{ sub(/\.$/, "", $1); print $1}')
22269         [ $fileperms == "-rwxr-xr-x" ] ||
22270                 error "incorrect perms on $dir/testdir/testfile"
22271
22272         umask $SAVE_UMASK
22273 }
22274 run_test 420 "clear SGID bit on non-directories for non-members"
22275
22276 test_421a() {
22277         local cnt
22278         local fid1
22279         local fid2
22280
22281         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22282                 skip "Need MDS version at least 2.12.54"
22283
22284         test_mkdir $DIR/$tdir
22285         createmany -o $DIR/$tdir/f 3
22286         cnt=$(ls -1 $DIR/$tdir | wc -l)
22287         [ $cnt != 3 ] && error "unexpected #files: $cnt"
22288
22289         fid1=$(lfs path2fid $DIR/$tdir/f1)
22290         fid2=$(lfs path2fid $DIR/$tdir/f2)
22291         $LFS rmfid $DIR $fid1 $fid2 || error "rmfid failed"
22292
22293         stat $DIR/$tdir/f1 && error "f1 still visible on the client"
22294         stat $DIR/$tdir/f2 && error "f2 still visible on the client"
22295
22296         cnt=$(ls -1 $DIR/$tdir | wc -l)
22297         [ $cnt == 1 ] || error "unexpected #files after: $cnt"
22298
22299         rm -f $DIR/$tdir/f3 || error "can't remove f3"
22300         createmany -o $DIR/$tdir/f 3
22301         cnt=$(ls -1 $DIR/$tdir | wc -l)
22302         [ $cnt != 3 ] && error "unexpected #files: $cnt"
22303
22304         fid1=$(lfs path2fid $DIR/$tdir/f1)
22305         fid2=$(lfs path2fid $DIR/$tdir/f2)
22306         echo "remove using fsname $FSNAME"
22307         $LFS rmfid $FSNAME $fid1 $fid2 || error "rmfid with fsname failed"
22308
22309         cnt=$(ls -1 $DIR/$tdir | wc -l)
22310         [ $cnt == 1 ] || error "unexpected #files after: $cnt"
22311 }
22312 run_test 421a "simple rm by fid"
22313
22314 test_421b() {
22315         local cnt
22316         local FID1
22317         local FID2
22318
22319         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22320                 skip "Need MDS version at least 2.12.54"
22321
22322         test_mkdir $DIR/$tdir
22323         createmany -o $DIR/$tdir/f 3
22324         multiop_bg_pause $DIR/$tdir/f1 o_c || error "multiop failed to start"
22325         MULTIPID=$!
22326
22327         FID1=$(lfs path2fid $DIR/$tdir/f1)
22328         FID2=$(lfs path2fid $DIR/$tdir/f2)
22329         $LFS rmfid $DIR $FID1 $FID2 && error "rmfid didn't fail"
22330
22331         kill -USR1 $MULTIPID
22332         wait
22333
22334         cnt=$(ls $DIR/$tdir | wc -l)
22335         [ $cnt == 2 ] || error "unexpected #files after: $cnt"
22336 }
22337 run_test 421b "rm by fid on open file"
22338
22339 test_421c() {
22340         local cnt
22341         local FIDS
22342
22343         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22344                 skip "Need MDS version at least 2.12.54"
22345
22346         test_mkdir $DIR/$tdir
22347         createmany -o $DIR/$tdir/f 3
22348         touch $DIR/$tdir/$tfile
22349         createmany -l$DIR/$tdir/$tfile $DIR/$tdir/h 180
22350         cnt=$(ls -1 $DIR/$tdir | wc -l)
22351         [ $cnt != 184 ] && error "unexpected #files: $cnt"
22352
22353         FID1=$(lfs path2fid $DIR/$tdir/$tfile)
22354         $LFS rmfid $DIR $FID1 || error "rmfid failed"
22355
22356         cnt=$(ls $DIR/$tdir | wc -l)
22357         [ $cnt == 3 ] || error "unexpected #files after: $cnt"
22358 }
22359 run_test 421c "rm by fid against hardlinked files"
22360
22361 test_421d() {
22362         local cnt
22363         local FIDS
22364
22365         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22366                 skip "Need MDS version at least 2.12.54"
22367
22368         test_mkdir $DIR/$tdir
22369         createmany -o $DIR/$tdir/f 4097
22370         cnt=$(ls -1 $DIR/$tdir | wc -l)
22371         [ $cnt != 4097 ] && error "unexpected #files: $cnt"
22372
22373         FIDS=$(lfs path2fid $DIR/$tdir/f* | sed "s/[/][^:]*://g")
22374         $LFS rmfid $DIR $FIDS || error "rmfid failed"
22375
22376         cnt=$(ls $DIR/$tdir | wc -l)
22377         rm -rf $DIR/$tdir
22378         [ $cnt == 0 ] || error "unexpected #files after: $cnt"
22379 }
22380 run_test 421d "rmfid en masse"
22381
22382 test_421e() {
22383         local cnt
22384         local FID
22385
22386         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
22387         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22388                 skip "Need MDS version at least 2.12.54"
22389
22390         mkdir -p $DIR/$tdir
22391         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
22392         createmany -o $DIR/$tdir/striped_dir/f 512
22393         cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
22394         [ $cnt != 512 ] && error "unexpected #files: $cnt"
22395
22396         FIDS=$(lfs path2fid $DIR/$tdir/striped_dir/f* |
22397                 sed "s/[/][^:]*://g")
22398         $LFS rmfid $DIR $FIDS || error "rmfid failed"
22399
22400         cnt=$(ls $DIR/$tdir/striped_dir | wc -l)
22401         rm -rf $DIR/$tdir
22402         [ $cnt == 0 ] || error "unexpected #files after: $cnt"
22403 }
22404 run_test 421e "rmfid in DNE"
22405
22406 test_421f() {
22407         local cnt
22408         local FID
22409
22410         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22411                 skip "Need MDS version at least 2.12.54"
22412
22413         test_mkdir $DIR/$tdir
22414         touch $DIR/$tdir/f
22415         cnt=$(ls -1 $DIR/$tdir | wc -l)
22416         [ $cnt != 1 ] && error "unexpected #files: $cnt"
22417
22418         FID=$(lfs path2fid $DIR/$tdir/f)
22419         $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail (1)"
22420         # rmfid should fail
22421         cnt=$(ls -1 $DIR/$tdir | wc -l)
22422         [ $cnt != 1 ] && error "unexpected #files after (2): $cnt"
22423
22424         chmod a+rw $DIR/$tdir
22425         ls -la $DIR/$tdir
22426         $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail (2)"
22427         # rmfid should fail
22428         cnt=$(ls -1 $DIR/$tdir | wc -l)
22429         [ $cnt != 1 ] && error "unexpected #files after (3): $cnt"
22430
22431         rm -f $DIR/$tdir/f
22432         $RUNAS touch $DIR/$tdir/f
22433         FID=$(lfs path2fid $DIR/$tdir/f)
22434         echo "rmfid as root"
22435         $LFS rmfid $DIR $FID || error "rmfid as root failed"
22436         cnt=$(ls -1 $DIR/$tdir | wc -l)
22437         [ $cnt == 0 ] || error "unexpected #files after (4): $cnt"
22438
22439         rm -f $DIR/$tdir/f
22440         $RUNAS touch $DIR/$tdir/f
22441         cnt=$(ls -1 $DIR/$tdir | wc -l)
22442         [ $cnt != 1 ] && error "unexpected #files (4): $cnt"
22443         FID=$(lfs path2fid $DIR/$tdir/f)
22444         # rmfid w/o user_fid2path mount option should fail
22445         $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail(3)"
22446         cnt=$(ls -1 $DIR/$tdir | wc -l)
22447         [ $cnt == 1 ] || error "unexpected #files after (5): $cnt"
22448
22449         umount_client $MOUNT || error "failed to umount client"
22450         mount_client $MOUNT "$MOUNT_OPTS,user_fid2path" ||
22451                 error "failed to mount client'"
22452
22453         $RUNAS $LFS rmfid $DIR $FID || error "rmfid failed"
22454         # rmfid should succeed
22455         cnt=$(ls -1 $DIR/$tdir | wc -l)
22456         [ $cnt == 0 ] || error "unexpected #files after (6): $cnt"
22457
22458         # rmfid shouldn't allow to remove files due to dir's permission
22459         chmod a+rwx $DIR/$tdir
22460         touch $DIR/$tdir/f
22461         ls -la $DIR/$tdir
22462         FID=$(lfs path2fid $DIR/$tdir/f)
22463         $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail"
22464
22465         umount_client $MOUNT || error "failed to umount client"
22466         mount_client $MOUNT "$MOUNT_OPTS" ||
22467                 error "failed to mount client'"
22468
22469 }
22470 run_test 421f "rmfid checks permissions"
22471
22472 test_421g() {
22473         local cnt
22474         local FIDS
22475
22476         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
22477         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22478                 skip "Need MDS version at least 2.12.54"
22479
22480         mkdir -p $DIR/$tdir
22481         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
22482         createmany -o $DIR/$tdir/striped_dir/f 512
22483         cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
22484         [ $cnt != 512 ] && error "unexpected #files: $cnt"
22485
22486         FIDS=$(lfs path2fid $DIR/$tdir/striped_dir/f* |
22487                 sed "s/[/][^:]*://g")
22488
22489         rm -f $DIR/$tdir/striped_dir/f1*
22490         cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
22491         removed=$((512 - cnt))
22492
22493         # few files have been just removed, so we expect
22494         # rmfid to fail on their fids
22495         errors=$($LFS rmfid $DIR $FIDS 2>&1 | wc -l)
22496         [ $removed != $errors ] && error "$errors != $removed"
22497
22498         cnt=$(ls $DIR/$tdir/striped_dir | wc -l)
22499         rm -rf $DIR/$tdir
22500         [ $cnt == 0 ] || error "unexpected #files after: $cnt"
22501 }
22502 run_test 421g "rmfid to return errors properly"
22503
22504 test_422() {
22505         test_mkdir -i 0 -c 1 -p $DIR/$tdir/d1
22506         test_mkdir -i 0 -c 1 -p $DIR/$tdir/d2
22507         test_mkdir -i 0 -c 1 -p $DIR/$tdir/d3
22508         dd if=/dev/zero of=$DIR/$tdir/d1/file1 bs=1k count=1
22509         dd if=/dev/zero of=$DIR/$tdir/d2/file1 bs=1k count=1
22510
22511         local amc=$(at_max_get client)
22512         local amo=$(at_max_get mds1)
22513         local timeout=`lctl get_param -n timeout`
22514
22515         at_max_set 0 client
22516         at_max_set 0 mds1
22517
22518 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
22519         do_facet mds1 $LCTL set_param fail_loc=0x8000050a \
22520                         fail_val=$(((2*timeout + 10)*1000))
22521         touch $DIR/$tdir/d3/file &
22522         sleep 2
22523 #define OBD_FAIL_TGT_REPLY_DATA_RACE     0x722
22524         do_facet mds1 $LCTL set_param fail_loc=0x80000722 \
22525                         fail_val=$((2*timeout + 5))
22526         mv $DIR/$tdir/d1/file1 $DIR/$tdir/d1/file2 &
22527         local pid=$!
22528         sleep 1
22529         kill -9 $pid
22530         sleep $((2 * timeout))
22531         echo kill $pid
22532         kill -9 $pid
22533         lctl mark touch
22534         touch $DIR/$tdir/d2/file3
22535         touch $DIR/$tdir/d2/file4
22536         touch $DIR/$tdir/d2/file5
22537
22538         wait
22539         at_max_set $amc client
22540         at_max_set $amo mds1
22541
22542         # LU-12838 - verify the ptlrpc thread watchdog is not always throttled
22543         do_facet mds1 "dmesg | grep 'Dumping the stack trace for debugging'" ||
22544                 error "Watchdog is always throttled"
22545 }
22546 run_test 422 "kill a process with RPC in progress"
22547
22548 stat_test() {
22549     df -h $MOUNT &
22550     df -h $MOUNT &
22551     df -h $MOUNT &
22552     df -h $MOUNT &
22553     df -h $MOUNT &
22554     df -h $MOUNT &
22555 }
22556
22557 test_423() {
22558     local _stats
22559     # ensure statfs cache is expired
22560     sleep 2;
22561
22562     _stats=$(stat_test | grep $MOUNT | sort -u | wc -l)
22563     [[ ${_stats} -ne 1 ]] && error "statfs wrong"
22564
22565     return 0
22566 }
22567 run_test 423 "statfs should return a right data"
22568
22569 prep_801() {
22570         [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] ||
22571         [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&
22572                 skip "Need server version at least 2.9.55"
22573
22574         start_full_debug_logging
22575 }
22576
22577 post_801() {
22578         stop_full_debug_logging
22579 }
22580
22581 barrier_stat() {
22582         if [ $MGS_VERSION -le $(version_code 2.10.0) ]; then
22583                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
22584                            awk '/The barrier for/ { print $7 }')
22585                 echo $st
22586         else
22587                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
22588                 echo \'$st\'
22589         fi
22590 }
22591
22592 barrier_expired() {
22593         local expired
22594
22595         if [ $MGS_VERSION -le $(version_code 2.10.0) ]; then
22596                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
22597                           awk '/will be expired/ { print $7 }')
22598         else
22599                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
22600         fi
22601
22602         echo $expired
22603 }
22604
22605 test_801a() {
22606         prep_801
22607
22608         echo "Start barrier_freeze at: $(date)"
22609         #define OBD_FAIL_BARRIER_DELAY          0x2202
22610         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
22611         # Do not reduce barrier time - See LU-11873
22612         do_facet mgs $LCTL barrier_freeze $FSNAME 20 &
22613
22614         sleep 2
22615         local b_status=$(barrier_stat)
22616         echo "Got barrier status at: $(date)"
22617         [ "$b_status" = "'freezing_p1'" ] ||
22618                 error "(1) unexpected barrier status $b_status"
22619
22620         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
22621         wait
22622         b_status=$(barrier_stat)
22623         [ "$b_status" = "'frozen'" ] ||
22624                 error "(2) unexpected barrier status $b_status"
22625
22626         local expired=$(barrier_expired)
22627         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
22628         sleep $((expired + 3))
22629
22630         b_status=$(barrier_stat)
22631         [ "$b_status" = "'expired'" ] ||
22632                 error "(3) unexpected barrier status $b_status"
22633
22634         # Do not reduce barrier time - See LU-11873
22635         do_facet mgs $LCTL barrier_freeze $FSNAME 20 ||
22636                 error "(4) fail to freeze barrier"
22637
22638         b_status=$(barrier_stat)
22639         [ "$b_status" = "'frozen'" ] ||
22640                 error "(5) unexpected barrier status $b_status"
22641
22642         echo "Start barrier_thaw at: $(date)"
22643         #define OBD_FAIL_BARRIER_DELAY          0x2202
22644         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
22645         do_facet mgs $LCTL barrier_thaw $FSNAME &
22646
22647         sleep 2
22648         b_status=$(barrier_stat)
22649         echo "Got barrier status at: $(date)"
22650         [ "$b_status" = "'thawing'" ] ||
22651                 error "(6) unexpected barrier status $b_status"
22652
22653         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
22654         wait
22655         b_status=$(barrier_stat)
22656         [ "$b_status" = "'thawed'" ] ||
22657                 error "(7) unexpected barrier status $b_status"
22658
22659         #define OBD_FAIL_BARRIER_FAILURE        0x2203
22660         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
22661         do_facet mgs $LCTL barrier_freeze $FSNAME
22662
22663         b_status=$(barrier_stat)
22664         [ "$b_status" = "'failed'" ] ||
22665                 error "(8) unexpected barrier status $b_status"
22666
22667         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
22668         do_facet mgs $LCTL barrier_thaw $FSNAME
22669
22670         post_801
22671 }
22672 run_test 801a "write barrier user interfaces and stat machine"
22673
22674 test_801b() {
22675         prep_801
22676
22677         mkdir $DIR/$tdir || error "(1) fail to mkdir"
22678         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
22679         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
22680         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
22681         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
22682
22683         cancel_lru_locks mdc
22684
22685         # 180 seconds should be long enough
22686         do_facet mgs $LCTL barrier_freeze $FSNAME 180
22687
22688         local b_status=$(barrier_stat)
22689         [ "$b_status" = "'frozen'" ] ||
22690                 error "(6) unexpected barrier status $b_status"
22691
22692         mkdir $DIR/$tdir/d0/d10 &
22693         mkdir_pid=$!
22694
22695         touch $DIR/$tdir/d1/f13 &
22696         touch_pid=$!
22697
22698         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
22699         ln_pid=$!
22700
22701         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
22702         mv_pid=$!
22703
22704         rm -f $DIR/$tdir/d4/f12 &
22705         rm_pid=$!
22706
22707         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
22708
22709         # To guarantee taht the 'stat' is not blocked
22710         b_status=$(barrier_stat)
22711         [ "$b_status" = "'frozen'" ] ||
22712                 error "(8) unexpected barrier status $b_status"
22713
22714         # let above commands to run at background
22715         sleep 5
22716
22717         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
22718         ps -p $touch_pid || error "(10) touch should be blocked"
22719         ps -p $ln_pid || error "(11) link should be blocked"
22720         ps -p $mv_pid || error "(12) rename should be blocked"
22721         ps -p $rm_pid || error "(13) unlink should be blocked"
22722
22723         b_status=$(barrier_stat)
22724         [ "$b_status" = "'frozen'" ] ||
22725                 error "(14) unexpected barrier status $b_status"
22726
22727         do_facet mgs $LCTL barrier_thaw $FSNAME
22728         b_status=$(barrier_stat)
22729         [ "$b_status" = "'thawed'" ] ||
22730                 error "(15) unexpected barrier status $b_status"
22731
22732         wait $mkdir_pid || error "(16) mkdir should succeed"
22733         wait $touch_pid || error "(17) touch should succeed"
22734         wait $ln_pid || error "(18) link should succeed"
22735         wait $mv_pid || error "(19) rename should succeed"
22736         wait $rm_pid || error "(20) unlink should succeed"
22737
22738         post_801
22739 }
22740 run_test 801b "modification will be blocked by write barrier"
22741
22742 test_801c() {
22743         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
22744
22745         prep_801
22746
22747         stop mds2 || error "(1) Fail to stop mds2"
22748
22749         do_facet mgs $LCTL barrier_freeze $FSNAME 30
22750
22751         local b_status=$(barrier_stat)
22752         [ "$b_status" = "'expired'" ] || [ "$b_status" = "'failed'" ] || {
22753                 do_facet mgs $LCTL barrier_thaw $FSNAME
22754                 error "(2) unexpected barrier status $b_status"
22755         }
22756
22757         do_facet mgs $LCTL barrier_rescan $FSNAME ||
22758                 error "(3) Fail to rescan barrier bitmap"
22759
22760         # Do not reduce barrier time - See LU-11873
22761         do_facet mgs $LCTL barrier_freeze $FSNAME 20
22762
22763         b_status=$(barrier_stat)
22764         [ "$b_status" = "'frozen'" ] ||
22765                 error "(4) unexpected barrier status $b_status"
22766
22767         do_facet mgs $LCTL barrier_thaw $FSNAME
22768         b_status=$(barrier_stat)
22769         [ "$b_status" = "'thawed'" ] ||
22770                 error "(5) unexpected barrier status $b_status"
22771
22772         local devname=$(mdsdevname 2)
22773
22774         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
22775
22776         do_facet mgs $LCTL barrier_rescan $FSNAME ||
22777                 error "(7) Fail to rescan barrier bitmap"
22778
22779         post_801
22780 }
22781 run_test 801c "rescan barrier bitmap"
22782
22783 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
22784 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
22785 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
22786 saved_MOUNT_OPTS=$MOUNT_OPTS
22787
22788 cleanup_802a() {
22789         trap 0
22790
22791         stopall
22792         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
22793         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
22794         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
22795         MOUNT_OPTS=$saved_MOUNT_OPTS
22796         setupall
22797 }
22798
22799 test_802a() {
22800         [[ $mds1_FSTYPE = zfs ]] || skip "ZFS specific test"
22801         [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] ||
22802         [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&
22803                 skip "Need server version at least 2.9.55"
22804
22805         [[ $ENABLE_QUOTA ]] && skip "Quota enabled for read-only test"
22806
22807         mkdir $DIR/$tdir || error "(1) fail to mkdir"
22808
22809         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
22810                 error "(2) Fail to copy"
22811
22812         trap cleanup_802a EXIT
22813
22814         # sync by force before remount as readonly
22815         sync; sync_all_data; sleep 3; sync_all_data
22816
22817         stopall
22818
22819         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
22820         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
22821         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
22822
22823         echo "Mount the server as read only"
22824         setupall server_only || error "(3) Fail to start servers"
22825
22826         echo "Mount client without ro should fail"
22827         mount_client $MOUNT &&
22828                 error "(4) Mount client without 'ro' should fail"
22829
22830         echo "Mount client with ro should succeed"
22831         MOUNT_OPTS=$(csa_add "$MOUNT_OPTS" -o ro)
22832         mount_client $MOUNT ||
22833                 error "(5) Mount client with 'ro' should succeed"
22834
22835         echo "Modify should be refused"
22836         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
22837
22838         echo "Read should be allowed"
22839         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
22840                 error "(7) Read should succeed under ro mode"
22841
22842         cleanup_802a
22843 }
22844 run_test 802a "simulate readonly device"
22845
22846 test_802b() {
22847         [ $PARALLEL == "yes" ] && skip "skip parallel run"
22848         remote_mds_nodsh && skip "remote MDS with nodsh"
22849
22850         do_facet $SINGLEMDS $LCTL get_param mdt.*.readonly ||
22851                 skip "readonly option not available"
22852
22853         $LFS mkdir -i 0 -c 1 $DIR/$tdir || error "(1) fail to mkdir"
22854
22855         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
22856                 error "(2) Fail to copy"
22857
22858         # write back all cached data before setting MDT to readonly
22859         cancel_lru_locks
22860         sync_all_data
22861
22862         do_facet $SINGLEMDS $LCTL set_param mdt.*.readonly=1
22863         stack_trap "do_facet $SINGLEMDS $LCTL set_param mdt.*.readonly=0" EXIT
22864
22865         echo "Modify should be refused"
22866         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
22867
22868         echo "Read should be allowed"
22869         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
22870                 error "(7) Read should succeed under ro mode"
22871
22872         # disable readonly
22873         do_facet $SINGLEMDS $LCTL set_param mdt.*.readonly=0
22874 }
22875 run_test 802b "be able to set MDTs to readonly"
22876
22877 test_803() {
22878         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
22879         [ $MDS1_VERSION -lt $(version_code 2.10.54) ] &&
22880                 skip "MDS needs to be newer than 2.10.54"
22881
22882         mkdir -p $DIR/$tdir
22883         # Create some objects on all MDTs to trigger related logs objects
22884         for idx in $(seq $MDSCOUNT); do
22885                 $LFS mkdir -c $MDSCOUNT -i $((idx % $MDSCOUNT)) \
22886                         $DIR/$tdir/dir${idx} ||
22887                         error "Fail to create $DIR/$tdir/dir${idx}"
22888         done
22889
22890         sync; sleep 3
22891         wait_delete_completed # ensure old test cleanups are finished
22892         echo "before create:"
22893         $LFS df -i $MOUNT
22894         local before_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
22895
22896         for i in {1..10}; do
22897                 $LFS mkdir -c 1 -i 1 $DIR/$tdir/foo$i ||
22898                         error "Fail to create $DIR/$tdir/foo$i"
22899         done
22900
22901         sync; sleep 3
22902         echo "after create:"
22903         $LFS df -i $MOUNT
22904         local after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
22905
22906         # allow for an llog to be cleaned up during the test
22907         [ $after_used -ge $((before_used + 10 - 1)) ] ||
22908                 error "before ($before_used) + 10 > after ($after_used)"
22909
22910         for i in {1..10}; do
22911                 rm -rf $DIR/$tdir/foo$i ||
22912                         error "Fail to remove $DIR/$tdir/foo$i"
22913         done
22914
22915         sleep 3 # avoid MDT return cached statfs
22916         wait_delete_completed
22917         echo "after unlink:"
22918         $LFS df -i $MOUNT
22919         after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
22920
22921         # allow for an llog to be created during the test
22922         [ $after_used -le $((before_used + 1)) ] ||
22923                 error "after ($after_used) > before ($before_used) + 1"
22924 }
22925 run_test 803 "verify agent object for remote object"
22926
22927 test_804() {
22928         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
22929         [ $MDS1_VERSION -lt $(version_code 2.10.54) ] &&
22930                 skip "MDS needs to be newer than 2.10.54"
22931         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
22932
22933         mkdir -p $DIR/$tdir
22934         $LFS mkdir -c 1 -i 1 $DIR/$tdir/dir0 ||
22935                 error "Fail to create $DIR/$tdir/dir0"
22936
22937         local fid=$($LFS path2fid $DIR/$tdir/dir0)
22938         local dev=$(mdsdevname 2)
22939
22940         do_facet mds2 "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
22941                 grep ${fid} || error "NOT found agent entry for dir0"
22942
22943         $LFS mkdir -c $MDSCOUNT -i 0 $DIR/$tdir/dir1 ||
22944                 error "Fail to create $DIR/$tdir/dir1"
22945
22946         touch $DIR/$tdir/dir1/foo0 ||
22947                 error "Fail to create $DIR/$tdir/dir1/foo0"
22948         fid=$($LFS path2fid $DIR/$tdir/dir1/foo0)
22949         local rc=0
22950
22951         for idx in $(seq $MDSCOUNT); do
22952                 dev=$(mdsdevname $idx)
22953                 do_facet mds${idx} \
22954                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
22955                         grep ${fid} && rc=$idx
22956         done
22957
22958         mv $DIR/$tdir/dir1/foo0 $DIR/$tdir/dir1/foo1 ||
22959                 error "Fail to rename foo0 to foo1"
22960         if [ $rc -eq 0 ]; then
22961                 for idx in $(seq $MDSCOUNT); do
22962                         dev=$(mdsdevname $idx)
22963                         do_facet mds${idx} \
22964                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
22965                         grep ${fid} && rc=$idx
22966                 done
22967         fi
22968
22969         mv $DIR/$tdir/dir1/foo1 $DIR/$tdir/dir1/foo2 ||
22970                 error "Fail to rename foo1 to foo2"
22971         if [ $rc -eq 0 ]; then
22972                 for idx in $(seq $MDSCOUNT); do
22973                         dev=$(mdsdevname $idx)
22974                         do_facet mds${idx} \
22975                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
22976                         grep ${fid} && rc=$idx
22977                 done
22978         fi
22979
22980         [ $rc -ne 0 ] || error "NOT found agent entry for foo"
22981
22982         ln $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir0/guard ||
22983                 error "Fail to link to $DIR/$tdir/dir1/foo2"
22984         mv $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir1/foo0 ||
22985                 error "Fail to rename foo2 to foo0"
22986         unlink $DIR/$tdir/dir1/foo0 ||
22987                 error "Fail to unlink $DIR/$tdir/dir1/foo0"
22988         rm -rf $DIR/$tdir/dir0 ||
22989                 error "Fail to rm $DIR/$tdir/dir0"
22990
22991         for idx in $(seq $MDSCOUNT); do
22992                 dev=$(mdsdevname $idx)
22993                 rc=0
22994
22995                 stop mds${idx}
22996                 run_e2fsck $(facet_active_host mds$idx) $dev -n ||
22997                         rc=$?
22998                 start mds${idx} $dev $MDS_MOUNT_OPTS ||
22999                         error "mount mds$idx failed"
23000                 df $MOUNT > /dev/null 2>&1
23001
23002                 # e2fsck should not return error
23003                 [ $rc -eq 0 ] ||
23004                         error "e2fsck detected error on MDT${idx}: rc=$rc"
23005         done
23006 }
23007 run_test 804 "verify agent entry for remote entry"
23008
23009 cleanup_805() {
23010         do_facet $SINGLEMDS zfs set quota=$old $fsset
23011         unlinkmany $DIR/$tdir/f- 1000000
23012         trap 0
23013 }
23014
23015 test_805() {
23016         local zfs_version=$(do_facet mds1 cat /sys/module/zfs/version)
23017         [ "$mds1_FSTYPE" != "zfs" ] && skip "ZFS specific test"
23018         [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
23019                 skip "netfree not implemented before 0.7"
23020         [[ $MDS1_VERSION -ge $(version_code 2.10.57) ]] ||
23021                 skip "Need MDS version at least 2.10.57"
23022
23023         local fsset
23024         local freekb
23025         local usedkb
23026         local old
23027         local quota
23028         local pref="osd-zfs.$FSNAME-MDT0000."
23029
23030         # limit available space on MDS dataset to meet nospace issue
23031         # quickly. then ZFS 0.7.2 can use reserved space if asked
23032         # properly (using netfree flag in osd_declare_destroy()
23033         fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
23034         old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
23035                 gawk '{print $3}')
23036         freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
23037         usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
23038         let "usedkb=usedkb-freekb"
23039         let "freekb=freekb/2"
23040         if let "freekb > 5000"; then
23041                 let "freekb=5000"
23042         fi
23043         do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
23044         trap cleanup_805 EXIT
23045         mkdir $DIR/$tdir
23046         $LFS setstripe -E 1M -c2 -E 4M -c2 -E -1 -c2 $DIR/$tdir ||
23047                 error "Can't set PFL layout"
23048         createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
23049         rm -rf $DIR/$tdir || error "not able to remove"
23050         do_facet $SINGLEMDS zfs set quota=$old $fsset
23051         trap 0
23052 }
23053 run_test 805 "ZFS can remove from full fs"
23054
23055 # Size-on-MDS test
23056 check_lsom_data()
23057 {
23058         local file=$1
23059         local size=$($LFS getsom -s $file)
23060         local expect=$(stat -c %s $file)
23061
23062         [[ $size == $expect ]] ||
23063                 error "$file expected size: $expect, got: $size"
23064
23065         local blocks=$($LFS getsom -b $file)
23066         expect=$(stat -c %b $file)
23067         [[ $blocks == $expect ]] ||
23068                 error "$file expected blocks: $expect, got: $blocks"
23069 }
23070
23071 check_lsom_size()
23072 {
23073         local size=$($LFS getsom -s $1)
23074         local expect=$2
23075
23076         [[ $size == $expect ]] ||
23077                 error "$file expected size: $expect, got: $size"
23078 }
23079
23080 test_806() {
23081         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
23082                 skip "Need MDS version at least 2.11.52"
23083
23084         local bs=1048576
23085
23086         touch $DIR/$tfile || error "touch $tfile failed"
23087
23088         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
23089         save_lustre_params client "llite.*.xattr_cache" > $save
23090         lctl set_param llite.*.xattr_cache=0
23091         stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
23092
23093         # single-threaded write
23094         echo "Test SOM for single-threaded write"
23095         dd if=/dev/zero of=$DIR/$tfile bs=$bs count=1 ||
23096                 error "write $tfile failed"
23097         check_lsom_size $DIR/$tfile $bs
23098
23099         local num=32
23100         local size=$(($num * $bs))
23101         local offset=0
23102         local i
23103
23104         echo "Test SOM for single client multi-threaded($num) write"
23105         $TRUNCATE $DIR/$tfile 0
23106         for ((i = 0; i < $num; i++)); do
23107                 $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23108                 local pids[$i]=$!
23109                 offset=$((offset + $bs))
23110         done
23111         for (( i=0; i < $num; i++ )); do
23112                 wait ${pids[$i]}
23113         done
23114         check_lsom_size $DIR/$tfile $size
23115
23116         $TRUNCATE $DIR/$tfile 0
23117         for ((i = 0; i < $num; i++)); do
23118                 offset=$((offset - $bs))
23119                 $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23120                 local pids[$i]=$!
23121         done
23122         for (( i=0; i < $num; i++ )); do
23123                 wait ${pids[$i]}
23124         done
23125         check_lsom_size $DIR/$tfile $size
23126
23127         # multi-client writes
23128         num=$(get_node_count ${CLIENTS//,/ })
23129         size=$(($num * $bs))
23130         offset=0
23131         i=0
23132
23133         echo "Test SOM for multi-client ($num) writes"
23134         $TRUNCATE $DIR/$tfile 0
23135         for client in ${CLIENTS//,/ }; do
23136                 do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23137                 local pids[$i]=$!
23138                 i=$((i + 1))
23139                 offset=$((offset + $bs))
23140         done
23141         for (( i=0; i < $num; i++ )); do
23142                 wait ${pids[$i]}
23143         done
23144         check_lsom_size $DIR/$tfile $offset
23145
23146         i=0
23147         $TRUNCATE $DIR/$tfile 0
23148         for client in ${CLIENTS//,/ }; do
23149                 offset=$((offset - $bs))
23150                 do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23151                 local pids[$i]=$!
23152                 i=$((i + 1))
23153         done
23154         for (( i=0; i < $num; i++ )); do
23155                 wait ${pids[$i]}
23156         done
23157         check_lsom_size $DIR/$tfile $size
23158
23159         # verify truncate
23160         echo "Test SOM for truncate"
23161         $TRUNCATE $DIR/$tfile 1048576
23162         check_lsom_size $DIR/$tfile 1048576
23163         $TRUNCATE $DIR/$tfile 1234
23164         check_lsom_size $DIR/$tfile 1234
23165
23166         # verify SOM blocks count
23167         echo "Verify SOM block count"
23168         $TRUNCATE $DIR/$tfile 0
23169         $MULTIOP $DIR/$tfile oO_TRUNC:O_RDWR:w1048576YSc ||
23170                 error "failed to write file $tfile"
23171         check_lsom_data $DIR/$tfile
23172 }
23173 run_test 806 "Verify Lazy Size on MDS"
23174
23175 test_807() {
23176         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
23177         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
23178                 skip "Need MDS version at least 2.11.52"
23179
23180         # Registration step
23181         changelog_register || error "changelog_register failed"
23182         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
23183         changelog_users $SINGLEMDS | grep -q $cl_user ||
23184                 error "User $cl_user not found in changelog_users"
23185
23186         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
23187         save_lustre_params client "llite.*.xattr_cache" > $save
23188         lctl set_param llite.*.xattr_cache=0
23189         stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
23190
23191         rm -rf $DIR/$tdir || error "rm $tdir failed"
23192         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
23193         touch $DIR/$tdir/trunc || error "touch $tdir/trunc failed"
23194         $TRUNCATE $DIR/$tdir/trunc 1024 || error "truncate $tdir/trunc failed"
23195         $TRUNCATE $DIR/$tdir/trunc 1048576 ||
23196                 error "truncate $tdir/trunc failed"
23197
23198         local bs=1048576
23199         dd if=/dev/zero of=$DIR/$tdir/single_dd bs=$bs count=1 conv=fsync ||
23200                 error "write $tfile failed"
23201
23202         # multi-client wirtes
23203         local num=$(get_node_count ${CLIENTS//,/ })
23204         local offset=0
23205         local i=0
23206
23207         echo "Test SOM for multi-client ($num) writes"
23208         touch $DIR/$tfile || error "touch $tfile failed"
23209         $TRUNCATE $DIR/$tfile 0
23210         for client in ${CLIENTS//,/ }; do
23211                 do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23212                 local pids[$i]=$!
23213                 i=$((i + 1))
23214                 offset=$((offset + $bs))
23215         done
23216         for (( i=0; i < $num; i++ )); do
23217                 wait ${pids[$i]}
23218         done
23219
23220         do_rpc_nodes "$CLIENTS" cancel_lru_locks osc
23221         do_nodes "$CLIENTS" "sync ; sleep 5 ; sync"
23222         $LSOM_SYNC -u $cl_user -m $FSNAME-MDT0000 $MOUNT
23223         check_lsom_data $DIR/$tdir/trunc
23224         check_lsom_data $DIR/$tdir/single_dd
23225         check_lsom_data $DIR/$tfile
23226
23227         rm -rf $DIR/$tdir
23228         # Deregistration step
23229         changelog_deregister || error "changelog_deregister failed"
23230 }
23231 run_test 807 "verify LSOM syncing tool"
23232
23233 check_som_nologged()
23234 {
23235         local lines=$($LFS changelog $FSNAME-MDT0000 |
23236                 grep 'x=trusted.som' | wc -l)
23237         [ $lines -ne 0 ] && error "trusted.som xattr is logged in Changelogs"
23238 }
23239
23240 test_808() {
23241         [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
23242                 skip "Need MDS version at least 2.11.55"
23243
23244         # Registration step
23245         changelog_register || error "changelog_register failed"
23246
23247         touch $DIR/$tfile || error "touch $tfile failed"
23248         check_som_nologged
23249
23250         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=1 ||
23251                 error "write $tfile failed"
23252         check_som_nologged
23253
23254         $TRUNCATE $DIR/$tfile 1234
23255         check_som_nologged
23256
23257         $TRUNCATE $DIR/$tfile 1048576
23258         check_som_nologged
23259
23260         # Deregistration step
23261         changelog_deregister || error "changelog_deregister failed"
23262 }
23263 run_test 808 "Check trusted.som xattr not logged in Changelogs"
23264
23265 check_som_nodata()
23266 {
23267         $LFS getsom $1
23268         [[ $? -eq 61 ]] || error "DoM-only file $1 has SOM xattr"
23269 }
23270
23271 test_809() {
23272         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
23273                 skip "Need MDS version at least 2.11.56"
23274
23275         $LFS setstripe -E 1M -L mdt $DIR/$tfile ||
23276                 error "failed to create DoM-only file $DIR/$tfile"
23277         touch $DIR/$tfile || error "touch $tfile failed"
23278         check_som_nodata $DIR/$tfile
23279
23280         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 ||
23281                 error "write $tfile failed"
23282         check_som_nodata $DIR/$tfile
23283
23284         $TRUNCATE $DIR/$tfile 1234
23285         check_som_nodata $DIR/$tfile
23286
23287         $TRUNCATE $DIR/$tfile 4097
23288         check_som_nodata $DIR/$file
23289 }
23290 run_test 809 "Verify no SOM xattr store for DoM-only files"
23291
23292 test_810() {
23293         [ $PARALLEL == "yes" ] && skip "skip parallel run"
23294         $GSS && skip_env "could not run with gss"
23295         [[ $OST1_VERSION -gt $(version_code 2.12.58) ]] ||
23296                 skip "OST < 2.12.58 doesn't align checksum"
23297
23298         set_checksums 1
23299         stack_trap "set_checksums $ORIG_CSUM" EXIT
23300         stack_trap "set_checksum_type $ORIG_CSUM_TYPE" EXIT
23301
23302         local csum
23303         local before
23304         local after
23305         for csum in $CKSUM_TYPES; do
23306                 #define OBD_FAIL_OSC_NO_GRANT   0x411
23307                 $LCTL set_param osc.*.checksum_type=$csum fail_loc=0x411
23308                 for i in "10240 0" "10000 0" "4000 1" "500 1"; do
23309                         eval set -- $i
23310                         dd if=/dev/urandom of=$DIR/$tfile bs=$1 count=2 seek=$2
23311                         before=$(md5sum $DIR/$tfile)
23312                         $LCTL set_param ldlm.namespaces.*osc*.lru_size=clear
23313                         after=$(md5sum $DIR/$tfile)
23314                         [ "$before" == "$after" ] ||
23315                                 error "$csum: $before != $after bs=$1 seek=$2"
23316                 done
23317         done
23318 }
23319 run_test 810 "partial page writes on ZFS (LU-11663)"
23320
23321 test_812a() {
23322         [ $OST1_VERSION -lt $(version_code 2.12.51) ] &&
23323                 skip "OST < 2.12.51 doesn't support this fail_loc"
23324         [ "$SHARED_KEY" = true ] &&
23325                 skip "OSC connections never go IDLE with Shared-Keys enabled"
23326
23327         $LFS setstripe -c 1 -i 0 $DIR/$tfile
23328         # ensure ost1 is connected
23329         stat $DIR/$tfile >/dev/null || error "can't stat"
23330         wait_osc_import_state client ost1 FULL
23331         # no locks, no reqs to let the connection idle
23332         cancel_lru_locks osc
23333
23334         # delay OST_DISCONNECT on OST1 to put OSC into intermediate state
23335 #define OBD_FAIL_OST_DISCONNECT_DELAY    0x245
23336         do_facet ost1 "$LCTL set_param fail_loc=0x245 fail_val=8"
23337         wait_osc_import_state client ost1 CONNECTING
23338         do_facet ost1 "$LCTL set_param fail_loc=0 fail_val=0"
23339
23340         stat $DIR/$tfile >/dev/null || error "can't stat file"
23341 }
23342 run_test 812a "do not drop reqs generated when imp is going to idle (LU-11951)"
23343
23344 test_812b() { # LU-12378
23345         [ $OST1_VERSION -lt $(version_code 2.12.51) ] &&
23346                 skip "OST < 2.12.51 doesn't support this fail_loc"
23347         [ "$SHARED_KEY" = true ] &&
23348                 skip "OSC connections never go IDLE with Shared-Keys enabled"
23349
23350         $LFS setstripe -c 1 -i 0 $DIR/$tfile || error "setstripe failed"
23351         # ensure ost1 is connected
23352         stat $DIR/$tfile >/dev/null || error "can't stat"
23353         wait_osc_import_state client ost1 FULL
23354         # no locks, no reqs to let the connection idle
23355         cancel_lru_locks osc
23356
23357         # delay OST_DISCONNECT on OST1 to put OSC into intermediate state
23358 #define OBD_FAIL_OST_DISCONNECT_DELAY    0x245
23359         do_facet ost1 "$LCTL set_param fail_loc=0x245 fail_val=8"
23360         wait_osc_import_state client ost1 CONNECTING
23361         do_facet ost1 "$LCTL set_param fail_loc=0 fail_val=0"
23362
23363         $LFS quota -u 0 $DIR/ || error "lfs quota should succeed"
23364         wait_osc_import_state client ost1 IDLE
23365 }
23366 run_test 812b "do not drop no resend request for idle connect"
23367
23368 test_813() {
23369         local file_heat_sav=$($LCTL get_param -n llite.*.file_heat 2>/dev/null)
23370         [ -z "$file_heat_sav" ] && skip "no file heat support"
23371
23372         local readsample
23373         local writesample
23374         local readbyte
23375         local writebyte
23376         local readsample1
23377         local writesample1
23378         local readbyte1
23379         local writebyte1
23380
23381         local period_second=$($LCTL get_param -n llite.*.heat_period_second)
23382         local decay_pct=$($LCTL get_param -n llite.*.heat_decay_percentage)
23383
23384         $LCTL set_param -n llite.*.file_heat=1
23385         echo "Turn on file heat"
23386         echo "Period second: $period_second, Decay percentage: $decay_pct"
23387
23388         echo "QQQQ" > $DIR/$tfile
23389         echo "QQQQ" > $DIR/$tfile
23390         echo "QQQQ" > $DIR/$tfile
23391         cat $DIR/$tfile > /dev/null
23392         cat $DIR/$tfile > /dev/null
23393         cat $DIR/$tfile > /dev/null
23394         cat $DIR/$tfile > /dev/null
23395
23396         local out=$($LFS heat_get $DIR/$tfile)
23397
23398         $LFS heat_get $DIR/$tfile
23399         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23400         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23401         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23402         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23403
23404         [ $readsample -le 4 ] || error "read sample ($readsample) is wrong"
23405         [ $writesample -le 3 ] || error "write sample ($writesample) is wrong"
23406         [ $readbyte -le 20 ] || error "read bytes ($readbyte) is wrong"
23407         [ $writebyte -le 15 ] || error "write bytes ($writebyte) is wrong"
23408
23409         sleep $((period_second + 3))
23410         echo "Sleep $((period_second + 3)) seconds..."
23411         # The recursion formula to calculate the heat of the file f is as
23412         # follow:
23413         # Hi+1(f) = (1-P)*Hi(f)+ P*Ci
23414         # Where Hi is the heat value in the period between time points i*I and
23415         # (i+1)*I; Ci is the access count in the period; the symbol P refers
23416         # to the weight of Ci.
23417         out=$($LFS heat_get $DIR/$tfile)
23418         $LFS heat_get $DIR/$tfile
23419         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23420         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23421         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23422         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23423
23424         [ $(bc <<< "$readsample <= 4 * $decay_pct / 100") -eq 1 ] ||
23425                 error "read sample ($readsample) is wrong"
23426         [ $(bc <<< "$writesample <= 3 * $decay_pct / 100") -eq 1 ] ||
23427                 error "write sample ($writesample) is wrong"
23428         [ $(bc <<< "$readbyte <= 20 * $decay_pct / 100") -eq 1 ] ||
23429                 error "read bytes ($readbyte) is wrong"
23430         [ $(bc <<< "$writebyte <= 15 * $decay_pct / 100") -eq 1 ] ||
23431                 error "write bytes ($writebyte) is wrong"
23432
23433         echo "QQQQ" > $DIR/$tfile
23434         echo "QQQQ" > $DIR/$tfile
23435         echo "QQQQ" > $DIR/$tfile
23436         cat $DIR/$tfile > /dev/null
23437         cat $DIR/$tfile > /dev/null
23438         cat $DIR/$tfile > /dev/null
23439         cat $DIR/$tfile > /dev/null
23440
23441         sleep $((period_second + 3))
23442         echo "Sleep $((period_second + 3)) seconds..."
23443
23444         out=$($LFS heat_get $DIR/$tfile)
23445         $LFS heat_get $DIR/$tfile
23446         readsample1=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23447         writesample1=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23448         readbyte1=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23449         writebyte1=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23450
23451         [ $(bc <<< "$readsample1 <= ($readsample * (100 - $decay_pct) + \
23452                 4 * $decay_pct) / 100") -eq 1 ] ||
23453                 error "read sample ($readsample1) is wrong"
23454         [ $(bc <<< "$writesample1 <= ($writesample * (100 - $decay_pct) + \
23455                 3 * $decay_pct) / 100") -eq 1 ] ||
23456                 error "write sample ($writesample1) is wrong"
23457         [ $(bc <<< "$readbyte1 <= ($readbyte * (100 - $decay_pct) + \
23458                 20 * $decay_pct) / 100") -eq 1 ] ||
23459                 error "read bytes ($readbyte1) is wrong"
23460         [ $(bc <<< "$writebyte1 <= ($writebyte * (100 - $decay_pct) + \
23461                 15 * $decay_pct) / 100") -eq 1 ] ||
23462                 error "write bytes ($writebyte1) is wrong"
23463
23464         echo "Turn off file heat for the file $DIR/$tfile"
23465         $LFS heat_set -o $DIR/$tfile
23466
23467         echo "QQQQ" > $DIR/$tfile
23468         echo "QQQQ" > $DIR/$tfile
23469         echo "QQQQ" > $DIR/$tfile
23470         cat $DIR/$tfile > /dev/null
23471         cat $DIR/$tfile > /dev/null
23472         cat $DIR/$tfile > /dev/null
23473         cat $DIR/$tfile > /dev/null
23474
23475         out=$($LFS heat_get $DIR/$tfile)
23476         $LFS heat_get $DIR/$tfile
23477         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23478         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23479         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23480         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23481
23482         [ $readsample -eq 0 ] || error "read sample ($readsample) is wrong"
23483         [ $writesample -eq 0 ] || error "write sample ($writesample) is wrong"
23484         [ $readbyte -eq 0 ] || error "read bytes ($readbyte) is wrong"
23485         [ $writebyte -eq 0 ] || error "write bytes ($writebyte) is wrong"
23486
23487         echo "Trun on file heat for the file $DIR/$tfile"
23488         $LFS heat_set -O $DIR/$tfile
23489
23490         echo "QQQQ" > $DIR/$tfile
23491         echo "QQQQ" > $DIR/$tfile
23492         echo "QQQQ" > $DIR/$tfile
23493         cat $DIR/$tfile > /dev/null
23494         cat $DIR/$tfile > /dev/null
23495         cat $DIR/$tfile > /dev/null
23496         cat $DIR/$tfile > /dev/null
23497
23498         out=$($LFS heat_get $DIR/$tfile)
23499         $LFS heat_get $DIR/$tfile
23500         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23501         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23502         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23503         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23504
23505         [ $readsample -gt 0 ] || error "read sample ($readsample) is wrong"
23506         [ $writesample -gt 0 ] || error "write sample ($writesample) is wrong"
23507         [ $readbyte -gt 0 ] || error "read bytes ($readbyte) is wrong"
23508         [ $writebyte -gt 0 ] || error "write bytes ($writebyte) is wrong"
23509
23510         $LFS heat_set -c $DIR/$tfile
23511         $LCTL set_param -n llite.*.file_heat=0
23512         echo "Turn off file heat support for the Lustre filesystem"
23513
23514         echo "QQQQ" > $DIR/$tfile
23515         echo "QQQQ" > $DIR/$tfile
23516         echo "QQQQ" > $DIR/$tfile
23517         cat $DIR/$tfile > /dev/null
23518         cat $DIR/$tfile > /dev/null
23519         cat $DIR/$tfile > /dev/null
23520         cat $DIR/$tfile > /dev/null
23521
23522         out=$($LFS heat_get $DIR/$tfile)
23523         $LFS heat_get $DIR/$tfile
23524         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23525         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23526         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23527         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23528
23529         [ $readsample -eq 0 ] || error "read sample ($readsample) is wrong"
23530         [ $writesample -eq 0 ] || error "write sample ($writesample) is wrong"
23531         [ $readbyte -eq 0 ] || error "read bytes ($readbyte) is wrong"
23532         [ $writebyte -eq 0 ] || error "write bytes ($writebyte) is wrong"
23533
23534         $LCTL set_param -n llite.*.file_heat=$file_heat_sav
23535         rm -f $DIR/$tfile
23536 }
23537 run_test 813 "File heat verfication"
23538
23539 test_814()
23540 {
23541         dd of=$DIR/$tfile seek=128 bs=1k < /dev/null
23542         echo -n y >> $DIR/$tfile
23543         cp --sparse=always $DIR/$tfile $DIR/${tfile}.cp || error "copy failed"
23544         diff $DIR/$tfile $DIR/${tfile}.cp || error "files should be same"
23545 }
23546 run_test 814 "sparse cp works as expected (LU-12361)"
23547
23548 test_815()
23549 {
23550         writeme -b 100 $DIR/$tfile || error "write 100 bytes failed"
23551         writeme -b 0 $DIR/$tfile || error "write 0 byte failed"
23552 }
23553 run_test 815 "zero byte tiny write doesn't hang (LU-12382)"
23554
23555 test_816() {
23556         [ "$SHARED_KEY" = true ] &&
23557                 skip "OSC connections never go IDLE with Shared-Keys enabled"
23558
23559         $LFS setstripe -c 1 -i 0 $DIR/$tfile
23560         # ensure ost1 is connected
23561         stat $DIR/$tfile >/dev/null || error "can't stat"
23562         wait_osc_import_state client ost1 FULL
23563         # no locks, no reqs to let the connection idle
23564         cancel_lru_locks osc
23565         lru_resize_disable osc
23566         local before
23567         local now
23568         before=$($LCTL get_param -n \
23569                  ldlm.namespaces.$FSNAME-OST0000-osc-[^M]*.lru_size)
23570
23571         wait_osc_import_state client ost1 IDLE
23572         dd if=/dev/null of=$DIR/$tfile bs=1k count=1 conv=sync
23573         now=$($LCTL get_param -n \
23574               ldlm.namespaces.$FSNAME-OST0000-osc-[^M]*.lru_size)
23575         [ $before == $now ] || error "lru_size changed $before != $now"
23576 }
23577 run_test 816 "do not reset lru_resize on idle reconnect"
23578
23579 cleanup_817() {
23580         umount $tmpdir
23581         exportfs -u localhost:$DIR/nfsexp
23582         rm -rf $DIR/nfsexp
23583 }
23584
23585 test_817() {
23586         systemctl restart nfs-server.service || skip "failed to restart nfsd"
23587
23588         mkdir -p $DIR/nfsexp
23589         exportfs -orw,no_root_squash localhost:$DIR/nfsexp ||
23590                 error "failed to export nfs"
23591
23592         tmpdir=$(mktemp -d /tmp/nfs-XXXXXX)
23593         stack_trap cleanup_817 EXIT
23594
23595         mount -t nfs -orw localhost:$DIR/nfsexp $tmpdir ||
23596                 error "failed to mount nfs to $tmpdir"
23597
23598         cp /bin/true $tmpdir
23599         $DIR/nfsexp/true || error "failed to execute 'true' command"
23600 }
23601 run_test 817 "nfsd won't cache write lock for exec file"
23602
23603 test_818() {
23604         mkdir $DIR/$tdir
23605         $LFS setstripe -c1 -i0 $DIR/$tfile
23606         $LFS setstripe -c1 -i1 $DIR/$tfile
23607         stop $SINGLEMDS
23608         #define OBD_FAIL_OSP_CANT_PROCESS_LLOG          0x2105
23609         do_facet $SINGLEMDS lctl set_param fail_loc=0x80002105
23610         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
23611                 error "start $SINGLEMDS failed"
23612         rm -rf $DIR/$tdir
23613 }
23614 run_test 818 "unlink with failed llog"
23615
23616 test_819a() {
23617         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
23618         cancel_lru_locks osc
23619         #define OBD_FAIL_OST_2BIG_NIOBUF                0x248
23620         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000248
23621         dd if=$DIR/$tfile of=/dev/null bs=1M count=1
23622         rm -f $TDIR/$tfile
23623 }
23624 run_test 819a "too big niobuf in read"
23625
23626 test_819b() {
23627         #define OBD_FAIL_OST_2BIG_NIOBUF                0x248
23628         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000248
23629         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
23630         cancel_lru_locks osc
23631         sleep 1
23632         rm -f $TDIR/$tfile
23633 }
23634 run_test 819b "too big niobuf in write"
23635
23636
23637 function test_820_start_ost() {
23638         sleep 5
23639
23640         for num in $(seq $OSTCOUNT); do
23641                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS
23642         done
23643 }
23644
23645 test_820() {
23646         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
23647
23648         mkdir $DIR/$tdir
23649         umount_client $MOUNT || error "umount failed"
23650         for num in $(seq $OSTCOUNT); do
23651                 stop ost$num
23652         done
23653
23654         # mount client with no active OSTs
23655         # so that the client can't initialize max LOV EA size
23656         # from OSC notifications
23657         mount_client $MOUNT || error "mount failed"
23658         # delay OST starting to keep this 0 max EA size for a while
23659         test_820_start_ost &
23660
23661         # create a directory on MDS2
23662         test_mkdir -i 1 -c1 $DIR/$tdir/mds2 ||
23663                 error "Failed to create directory"
23664         # open intent should update default EA size
23665         # see mdc_update_max_ea_from_body()
23666         # notice this is the very first RPC to MDS2
23667         cp /etc/services $DIR/$tdir/mds2 ||
23668                 error "Failed to copy files to mds$n"
23669 }
23670 run_test 820 "update max EA from open intent"
23671
23672 #
23673 # tests that do cleanup/setup should be run at the end
23674 #
23675
23676 test_900() {
23677         [ $PARALLEL == "yes" ] && skip "skip parallel run"
23678         local ls
23679
23680         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
23681         $LCTL set_param fail_loc=0x903
23682
23683         cancel_lru_locks MGC
23684
23685         FAIL_ON_ERROR=true cleanup
23686         FAIL_ON_ERROR=true setup
23687 }
23688 run_test 900 "umount should not race with any mgc requeue thread"
23689
23690 # LUS-6253/LU-11185
23691 test_901() {
23692         local oldc
23693         local newc
23694         local olds
23695         local news
23696         [ $PARALLEL == "yes" ] && skip "skip parallel run"
23697
23698         # some get_param have a bug to handle dot in param name
23699         cancel_lru_locks MGC
23700         oldc=$($LCTL get_param -n 'ldlm.namespaces.MGC*.lock_count')
23701         olds=$(do_facet mgs $LCTL get_param -n 'ldlm.namespaces.MGS*.lock_count')
23702         umount_client $MOUNT || error "umount failed"
23703         mount_client $MOUNT || error "mount failed"
23704         cancel_lru_locks MGC
23705         newc=$($LCTL get_param -n 'ldlm.namespaces.MGC*.lock_count')
23706         news=$(do_facet mgs $LCTL get_param -n 'ldlm.namespaces.MGS*.lock_count')
23707
23708         [ $oldc -lt $newc ] && error "mgc lock leak ($oldc != $newc)"
23709         [ $olds -lt $news ] && error "mgs lock leak ($olds != $news)"
23710
23711         return 0
23712 }
23713 run_test 901 "don't leak a mgc lock on client umount"
23714
23715 # LU-13377
23716 test_902() {
23717         [ $CLIENT_VERSION -lt $(version_code 2.13.52) ] &&
23718                 skip "client does not have LU-13377 fix"
23719         #define OBD_FAIL_LLITE_SHORT_COMMIT 0x1415
23720         $LCTL set_param fail_loc=0x1415
23721         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
23722         cancel_lru_locks osc
23723         rm -f $DIR/$tfile
23724 }
23725 run_test 902 "test short write doesn't hang lustre"
23726
23727 complete $SECONDS
23728 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
23729 check_and_cleanup_lustre
23730 if [ "$I_MOUNTED" != "yes" ]; then
23731         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
23732 fi
23733 exit_status