Whamcloud - gitweb
LU-13168 tests: verify truncated xattr is handled
[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_30d() {
3088         cp $(which dd) $DIR || error "failed to copy dd to $DIR/dd"
3089
3090         for i in {1..10}; do
3091                 $DIR/dd bs=1M count=128 if=/dev/zero of=$DIR/$tfile &
3092                 local PID=$!
3093                 sleep 1
3094                 $LCTL set_param ldlm.namespaces.*MDT*.lru_size=clear
3095                 wait $PID || error "executing dd from Lustre failed"
3096                 rm -f $DIR/$tfile
3097         done
3098
3099         rm -f $DIR/dd
3100 }
3101 run_test 30d "execute binary from Lustre while clear locks"
3102
3103 test_31a() {
3104         $OPENUNLINK $DIR/f31 $DIR/f31 || error "openunlink failed"
3105         $CHECKSTAT -a $DIR/f31 || error "$DIR/f31 exists"
3106 }
3107 run_test 31a "open-unlink file =================================="
3108
3109 test_31b() {
3110         touch $DIR/f31 || error "touch $DIR/f31 failed"
3111         ln $DIR/f31 $DIR/f31b || error "ln failed"
3112         $MULTIOP $DIR/f31b Ouc || error "multiop failed"
3113         $CHECKSTAT -t file $DIR/f31 || error "$DIR/f31 not file type"
3114 }
3115 run_test 31b "unlink file with multiple links while open ======="
3116
3117 test_31c() {
3118         touch $DIR/f31 || error "touch $DIR/f31 failed"
3119         ln $DIR/f31 $DIR/f31c || error "ln failed"
3120         multiop_bg_pause $DIR/f31 O_uc ||
3121                 error "multiop_bg_pause for $DIR/f31 failed"
3122         MULTIPID=$!
3123         $MULTIOP $DIR/f31c Ouc
3124         kill -USR1 $MULTIPID
3125         wait $MULTIPID
3126 }
3127 run_test 31c "open-unlink file with multiple links ============="
3128
3129 test_31d() {
3130         opendirunlink $DIR/d31d $DIR/d31d || error "opendirunlink failed"
3131         $CHECKSTAT -a $DIR/d31d || error "$DIR/d31d exists"
3132 }
3133 run_test 31d "remove of open directory ========================="
3134
3135 test_31e() { # bug 2904
3136         openfilleddirunlink $DIR/d31e || error "openfilleddirunlink failed"
3137 }
3138 run_test 31e "remove of open non-empty directory ==============="
3139
3140 test_31f() { # bug 4554
3141         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3142
3143         set -vx
3144         test_mkdir $DIR/d31f
3145         $LFS setstripe -S 1048576 -c 1 $DIR/d31f
3146         cp /etc/hosts $DIR/d31f
3147         ls -l $DIR/d31f
3148         $LFS getstripe $DIR/d31f/hosts
3149         multiop_bg_pause $DIR/d31f D_c || return 1
3150         MULTIPID=$!
3151
3152         rm -rv $DIR/d31f || error "first of $DIR/d31f"
3153         test_mkdir $DIR/d31f
3154         $LFS setstripe -S 1048576 -c 1 $DIR/d31f
3155         cp /etc/hosts $DIR/d31f
3156         ls -l $DIR/d31f
3157         $LFS getstripe $DIR/d31f/hosts
3158         multiop_bg_pause $DIR/d31f D_c || return 1
3159         MULTIPID2=$!
3160
3161         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
3162         wait $MULTIPID || error "first opendir $MULTIPID failed"
3163
3164         sleep 6
3165
3166         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
3167         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
3168         set +vx
3169 }
3170 run_test 31f "remove of open directory with open-unlink file ==="
3171
3172 test_31g() {
3173         echo "-- cross directory link --"
3174         test_mkdir -c1 $DIR/${tdir}ga
3175         test_mkdir -c1 $DIR/${tdir}gb
3176         touch $DIR/${tdir}ga/f
3177         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
3178         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
3179         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
3180         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
3181         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
3182 }
3183 run_test 31g "cross directory link==============="
3184
3185 test_31h() {
3186         echo "-- cross directory link --"
3187         test_mkdir -c1 $DIR/${tdir}
3188         test_mkdir -c1 $DIR/${tdir}/dir
3189         touch $DIR/${tdir}/f
3190         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
3191         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
3192         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
3193         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
3194         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
3195 }
3196 run_test 31h "cross directory link under child==============="
3197
3198 test_31i() {
3199         echo "-- cross directory link --"
3200         test_mkdir -c1 $DIR/$tdir
3201         test_mkdir -c1 $DIR/$tdir/dir
3202         touch $DIR/$tdir/dir/f
3203         ln $DIR/$tdir/dir/f $DIR/$tdir/g
3204         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
3205         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
3206         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
3207         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
3208 }
3209 run_test 31i "cross directory link under parent==============="
3210
3211 test_31j() {
3212         test_mkdir -c1 -p $DIR/$tdir
3213         test_mkdir -c1 -p $DIR/$tdir/dir1
3214         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
3215         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
3216         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
3217         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
3218         return 0
3219 }
3220 run_test 31j "link for directory==============="
3221
3222 test_31k() {
3223         test_mkdir -c1 -p $DIR/$tdir
3224         touch $DIR/$tdir/s
3225         touch $DIR/$tdir/exist
3226         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
3227         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
3228         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
3229         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
3230         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
3231         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
3232         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
3233         return 0
3234 }
3235 run_test 31k "link to file: the same, non-existing, dir==============="
3236
3237 test_31m() {
3238         mkdir $DIR/d31m
3239         touch $DIR/d31m/s
3240         mkdir $DIR/d31m2
3241         touch $DIR/d31m2/exist
3242         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
3243         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
3244         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
3245         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
3246         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
3247         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
3248         return 0
3249 }
3250 run_test 31m "link to file: the same, non-existing, dir==============="
3251
3252 test_31n() {
3253         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
3254         nlink=$(stat --format=%h $DIR/$tfile)
3255         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
3256         local fd=$(free_fd)
3257         local cmd="exec $fd<$DIR/$tfile"
3258         eval $cmd
3259         cmd="exec $fd<&-"
3260         trap "eval $cmd" EXIT
3261         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
3262         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
3263         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
3264         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
3265         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
3266         eval $cmd
3267 }
3268 run_test 31n "check link count of unlinked file"
3269
3270 link_one() {
3271         local tempfile=$(mktemp $1_XXXXXX)
3272         mlink $tempfile $1 2> /dev/null &&
3273                 echo "$BASHPID: link $tempfile to $1 succeeded"
3274         munlink $tempfile
3275 }
3276
3277 test_31o() { # LU-2901
3278         test_mkdir $DIR/$tdir
3279         for LOOP in $(seq 100); do
3280                 rm -f $DIR/$tdir/$tfile*
3281                 for THREAD in $(seq 8); do
3282                         link_one $DIR/$tdir/$tfile.$LOOP &
3283                 done
3284                 wait
3285                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
3286                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
3287                         error "$LINKS duplicate links to $tfile.$LOOP" &&
3288                         break || true
3289         done
3290 }
3291 run_test 31o "duplicate hard links with same filename"
3292
3293 test_31p() {
3294         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3295
3296         test_mkdir $DIR/$tdir
3297         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3298         $LFS setdirstripe -D -c2 -H all_char $DIR/$tdir/striped_dir
3299
3300         opendirunlink $DIR/$tdir/striped_dir/test1 ||
3301                 error "open unlink test1 failed"
3302         opendirunlink $DIR/$tdir/striped_dir/test2 ||
3303                 error "open unlink test2 failed"
3304
3305         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
3306                 error "test1 still exists"
3307         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
3308                 error "test2 still exists"
3309 }
3310 run_test 31p "remove of open striped directory"
3311
3312 cleanup_test32_mount() {
3313         local rc=0
3314         trap 0
3315         local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
3316         $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
3317         losetup -d $loopdev || true
3318         rm -rf $DIR/$tdir
3319         return $rc
3320 }
3321
3322 test_32a() {
3323         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3324
3325         echo "== more mountpoints and symlinks ================="
3326         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3327         trap cleanup_test32_mount EXIT
3328         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3329         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3330                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3331         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. ||
3332                 error "$DIR/$tdir/ext2-mountpoint/.. not dir type"
3333         cleanup_test32_mount
3334 }
3335 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
3336
3337 test_32b() {
3338         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3339
3340         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3341         trap cleanup_test32_mount EXIT
3342         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3343         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3344                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3345         ls -al $DIR/$tdir/ext2-mountpoint/.. ||
3346                 error "Can't list $DIR/$tdir/ext2-mountpoint/.."
3347         cleanup_test32_mount
3348 }
3349 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
3350
3351 test_32c() {
3352         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3353
3354         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3355         trap cleanup_test32_mount EXIT
3356         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3357         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3358                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3359         test_mkdir -p $DIR/$tdir/d2/test_dir
3360         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
3361                 error "$DIR/$tdir/ext2-mountpoint/../d2/test_dir not dir type"
3362         cleanup_test32_mount
3363 }
3364 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
3365
3366 test_32d() {
3367         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3368
3369         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3370         trap cleanup_test32_mount EXIT
3371         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3372         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3373                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3374         test_mkdir -p $DIR/$tdir/d2/test_dir
3375         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
3376                 error "Can't list $DIR/$tdir/ext2-mountpoint/../d2/test_dir"
3377         cleanup_test32_mount
3378 }
3379 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir"
3380
3381 test_32e() {
3382         rm -fr $DIR/$tdir
3383         test_mkdir -p $DIR/$tdir/tmp
3384         local tmp_dir=$DIR/$tdir/tmp
3385         ln -s $DIR/$tdir $tmp_dir/symlink11
3386         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
3387         $CHECKSTAT -t link $DIR/$tdir/tmp/symlink11 || error "symlink11 bad"
3388         $CHECKSTAT -t link $DIR/$tdir/symlink01 || error "symlink01 bad"
3389 }
3390 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir"
3391
3392 test_32f() {
3393         rm -fr $DIR/$tdir
3394         test_mkdir -p $DIR/$tdir/tmp
3395         local tmp_dir=$DIR/$tdir/tmp
3396         ln -s $DIR/$tdir $tmp_dir/symlink11
3397         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
3398         ls $DIR/$tdir/tmp/symlink11  || error "symlink11 bad"
3399         ls $DIR/$tdir/symlink01 || error "symlink01 bad"
3400 }
3401 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir"
3402
3403 test_32g() {
3404         local tmp_dir=$DIR/$tdir/tmp
3405         test_mkdir -p $tmp_dir
3406         test_mkdir $DIR/${tdir}2
3407         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
3408         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
3409         $CHECKSTAT -t link $tmp_dir/symlink12 || error "symlink12 not a link"
3410         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error "symlink02 not a link"
3411         $CHECKSTAT -t dir -f $tmp_dir/symlink12 || error "symlink12 not a dir"
3412         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error "symlink12 not a dir"
3413 }
3414 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
3415
3416 test_32h() {
3417         rm -fr $DIR/$tdir $DIR/${tdir}2
3418         tmp_dir=$DIR/$tdir/tmp
3419         test_mkdir -p $tmp_dir
3420         test_mkdir $DIR/${tdir}2
3421         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
3422         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
3423         ls $tmp_dir/symlink12 || error "listing symlink12"
3424         ls $DIR/$tdir/symlink02  || error "listing symlink02"
3425 }
3426 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
3427
3428 test_32i() {
3429         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3430
3431         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3432         trap cleanup_test32_mount EXIT
3433         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3434         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3435                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3436         touch $DIR/$tdir/test_file
3437         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file ||
3438                 error "$DIR/$tdir/ext2-mountpoint/../test_file not file type"
3439         cleanup_test32_mount
3440 }
3441 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
3442
3443 test_32j() {
3444         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3445
3446         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3447         trap cleanup_test32_mount EXIT
3448         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3449         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3450                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3451         touch $DIR/$tdir/test_file
3452         cat $DIR/$tdir/ext2-mountpoint/../test_file ||
3453                 error "Can't open $DIR/$tdir/ext2-mountpoint/../test_file"
3454         cleanup_test32_mount
3455 }
3456 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
3457
3458 test_32k() {
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         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
3469                 error "$DIR/$tdir/ext2-mountpoint/../d2/test_file not file type"
3470         cleanup_test32_mount
3471 }
3472 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
3473
3474 test_32l() {
3475         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3476
3477         rm -fr $DIR/$tdir
3478         trap cleanup_test32_mount EXIT
3479         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3480         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3481                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3482         test_mkdir -p $DIR/$tdir/d2
3483         touch $DIR/$tdir/d2/test_file || error "touch failed"
3484         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
3485                 error "Can't open $DIR/$tdir/ext2-mountpoint/../d2/test_file"
3486         cleanup_test32_mount
3487 }
3488 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
3489
3490 test_32m() {
3491         rm -fr $DIR/d32m
3492         test_mkdir -p $DIR/d32m/tmp
3493         TMP_DIR=$DIR/d32m/tmp
3494         ln -s $DIR $TMP_DIR/symlink11
3495         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
3496         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 ||
3497                 error "symlink11 not a link"
3498         $CHECKSTAT -t link $DIR/d32m/symlink01 ||
3499                 error "symlink01 not a link"
3500 }
3501 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
3502
3503 test_32n() {
3504         rm -fr $DIR/d32n
3505         test_mkdir -p $DIR/d32n/tmp
3506         TMP_DIR=$DIR/d32n/tmp
3507         ln -s $DIR $TMP_DIR/symlink11
3508         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
3509         ls -l $DIR/d32n/tmp/symlink11  || error "listing symlink11"
3510         ls -l $DIR/d32n/symlink01 || error "listing symlink01"
3511 }
3512 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
3513
3514 test_32o() {
3515         touch $DIR/$tfile
3516         test_mkdir -p $DIR/d32o/tmp
3517         TMP_DIR=$DIR/d32o/tmp
3518         ln -s $DIR/$tfile $TMP_DIR/symlink12
3519         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
3520         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 ||
3521                 error "symlink12 not a link"
3522         $CHECKSTAT -t link $DIR/d32o/symlink02 || error "symlink02 not a link"
3523         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 ||
3524                 error "$DIR/d32o/tmp/symlink12 not file type"
3525         $CHECKSTAT -t file -f $DIR/d32o/symlink02 ||
3526                 error "$DIR/d32o/symlink02 not file type"
3527 }
3528 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
3529
3530 test_32p() {
3531         log 32p_1
3532         rm -fr $DIR/d32p
3533         log 32p_2
3534         rm -f $DIR/$tfile
3535         log 32p_3
3536         touch $DIR/$tfile
3537         log 32p_4
3538         test_mkdir -p $DIR/d32p/tmp
3539         log 32p_5
3540         TMP_DIR=$DIR/d32p/tmp
3541         log 32p_6
3542         ln -s $DIR/$tfile $TMP_DIR/symlink12
3543         log 32p_7
3544         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
3545         log 32p_8
3546         cat $DIR/d32p/tmp/symlink12 ||
3547                 error "Can't open $DIR/d32p/tmp/symlink12"
3548         log 32p_9
3549         cat $DIR/d32p/symlink02 || error "Can't open $DIR/d32p/symlink02"
3550         log 32p_10
3551 }
3552 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
3553
3554 test_32q() {
3555         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3556
3557         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3558         trap cleanup_test32_mount EXIT
3559         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3560         touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
3561         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3562                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3563         ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
3564         cleanup_test32_mount
3565 }
3566 run_test 32q "stat follows mountpoints in Lustre (should return error)"
3567
3568 test_32r() {
3569         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3570
3571         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
3572         trap cleanup_test32_mount EXIT
3573         test_mkdir -p $DIR/$tdir/ext2-mountpoint
3574         touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
3575         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
3576                 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
3577         ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
3578         cleanup_test32_mount
3579 }
3580 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
3581
3582 test_33aa() {
3583         rm -f $DIR/$tfile
3584         touch $DIR/$tfile
3585         chmod 444 $DIR/$tfile
3586         chown $RUNAS_ID $DIR/$tfile
3587         log 33_1
3588         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
3589         log 33_2
3590 }
3591 run_test 33aa "write file with mode 444 (should return error)"
3592
3593 test_33a() {
3594         rm -fr $DIR/$tdir
3595         test_mkdir $DIR/$tdir
3596         chown $RUNAS_ID $DIR/$tdir
3597         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile ||
3598                 error "$RUNAS create $tdir/$tfile failed"
3599         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile &&
3600                 error "open RDWR" || true
3601 }
3602 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
3603
3604 test_33b() {
3605         rm -fr $DIR/$tdir
3606         test_mkdir $DIR/$tdir
3607         chown $RUNAS_ID $DIR/$tdir
3608         $RUNAS $OPENFILE -f 1286739555 $DIR/$tdir/$tfile || true
3609 }
3610 run_test 33b "test open file with malformed flags (No panic)"
3611
3612 test_33c() {
3613         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3614         remote_ost_nodsh && skip "remote OST with nodsh"
3615
3616         local ostnum
3617         local ostname
3618         local write_bytes
3619         local all_zeros
3620
3621         all_zeros=:
3622         rm -fr $DIR/$tdir
3623         test_mkdir $DIR/$tdir
3624         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
3625
3626         sync
3627         for ostnum in $(seq $OSTCOUNT); do
3628                 # test-framework's OST numbering is one-based, while Lustre's
3629                 # is zero-based
3630                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
3631                 # Parsing llobdstat's output sucks; we could grep the /proc
3632                 # path, but that's likely to not be as portable as using the
3633                 # llobdstat utility.  So we parse lctl output instead.
3634                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
3635                         obdfilter/$ostname/stats |
3636                         awk '/^write_bytes/ {print $7}' )
3637                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
3638                 if (( ${write_bytes:-0} > 0 ))
3639                 then
3640                         all_zeros=false
3641                         break;
3642                 fi
3643         done
3644
3645         $all_zeros || return 0
3646
3647         # Write four bytes
3648         echo foo > $DIR/$tdir/bar
3649         # Really write them
3650         sync
3651
3652         # Total up write_bytes after writing.  We'd better find non-zeros.
3653         for ostnum in $(seq $OSTCOUNT); do
3654                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
3655                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
3656                         obdfilter/$ostname/stats |
3657                         awk '/^write_bytes/ {print $7}' )
3658                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
3659                 if (( ${write_bytes:-0} > 0 ))
3660                 then
3661                         all_zeros=false
3662                         break;
3663                 fi
3664         done
3665
3666         if $all_zeros
3667         then
3668                 for ostnum in $(seq $OSTCOUNT); do
3669                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
3670                         echo "Check that write_bytes is present in obdfilter/*/stats:"
3671                         do_facet ost$ostnum lctl get_param -n \
3672                                 obdfilter/$ostname/stats
3673                 done
3674                 error "OST not keeping write_bytes stats (b22312)"
3675         fi
3676 }
3677 run_test 33c "test llobdstat and write_bytes"
3678
3679 test_33d() {
3680         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
3681         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3682
3683         local MDTIDX=1
3684         local remote_dir=$DIR/$tdir/remote_dir
3685
3686         test_mkdir $DIR/$tdir
3687         $LFS mkdir -i $MDTIDX $remote_dir ||
3688                 error "create remote directory failed"
3689
3690         touch $remote_dir/$tfile
3691         chmod 444 $remote_dir/$tfile
3692         chown $RUNAS_ID $remote_dir/$tfile
3693
3694         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
3695
3696         chown $RUNAS_ID $remote_dir
3697         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
3698                                         error "create" || true
3699         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
3700                                     error "open RDWR" || true
3701         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
3702 }
3703 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
3704
3705 test_33e() {
3706         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3707
3708         mkdir $DIR/$tdir
3709
3710         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3711         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
3712         mkdir $DIR/$tdir/local_dir
3713
3714         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
3715         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
3716         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
3717
3718         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3719                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
3720
3721         rmdir $DIR/$tdir/* || error "rmdir failed"
3722
3723         umask 777
3724         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3725         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
3726         mkdir $DIR/$tdir/local_dir
3727
3728         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
3729         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
3730         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
3731
3732         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3733                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
3734
3735         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
3736
3737         umask 000
3738         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
3739         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
3740         mkdir $DIR/$tdir/local_dir
3741
3742         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
3743         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
3744         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
3745
3746         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
3747                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
3748 }
3749 run_test 33e "mkdir and striped directory should have same mode"
3750
3751 cleanup_33f() {
3752         trap 0
3753         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
3754 }
3755
3756 test_33f() {
3757         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3758         remote_mds_nodsh && skip "remote MDS with nodsh"
3759
3760         mkdir $DIR/$tdir
3761         chmod go+rwx $DIR/$tdir
3762         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
3763         trap cleanup_33f EXIT
3764
3765         $RUNAS lfs mkdir -i 0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
3766                 error "cannot create striped directory"
3767
3768         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
3769                 error "cannot create files in striped directory"
3770
3771         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
3772                 error "cannot remove files in striped directory"
3773
3774         $RUNAS rmdir $DIR/$tdir/striped_dir ||
3775                 error "cannot remove striped directory"
3776
3777         cleanup_33f
3778 }
3779 run_test 33f "nonroot user can create, access, and remove a striped directory"
3780
3781 test_33g() {
3782         mkdir -p $DIR/$tdir/dir2
3783
3784         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
3785         echo $err
3786         [[ $err =~ "exists" ]] || error "Not exists error"
3787 }
3788 run_test 33g "nonroot user create already existing root created file"
3789
3790 test_33h() {
3791         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3792         [ $MDS1_VERSION -lt $(version_code 2.13.50) ] &&
3793                 skip "Need MDS version at least 2.13.50"
3794
3795         test_mkdir -c $MDSCOUNT -H crush $DIR/$tdir ||
3796                 error "mkdir $tdir failed"
3797         touch $DIR/$tdir/$tfile || error "touch $tfile failed"
3798
3799         local index=$($LFS getstripe -m $DIR/$tdir/$tfile)
3800         local index2
3801
3802         for fname in $DIR/$tdir/$tfile.bak \
3803                      $DIR/$tdir/$tfile.SAV \
3804                      $DIR/$tdir/$tfile.orig \
3805                      $DIR/$tdir/$tfile~; do
3806                 touch $fname  || error "touch $fname failed"
3807                 index2=$($LFS getstripe -m $fname)
3808                 [ $index -eq $index2 ] ||
3809                         error "$fname MDT index mismatch $index != $index2"
3810         done
3811
3812         local failed=0
3813         for i in {1..50}; do
3814                 for fname in $(mktemp -u $DIR/$tdir/.$tfile.XXXXXX) \
3815                              $(mktemp $DIR/$tdir/$tfile.XXXXXXXX); do
3816                         touch $fname  || error "touch $fname failed"
3817                         index2=$($LFS getstripe -m $fname)
3818                         if [[ $index != $index2 ]]; then
3819                                 failed=$((failed + 1))
3820                                 echo "$fname MDT index mismatch $index != $index2"
3821                         fi
3822                 done
3823         done
3824         echo "$failed MDT index mismatches"
3825         (( failed < 4 )) || error "MDT index mismatch $failed times"
3826
3827 }
3828 run_test 33h "temp file is located on the same MDT as target"
3829
3830 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
3831 test_34a() {
3832         rm -f $DIR/f34
3833         $MCREATE $DIR/f34 || error "mcreate failed"
3834         $LFS getstripe $DIR/f34 2>&1 | grep -q "no stripe info" ||
3835                 error "getstripe failed"
3836         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error "truncate failed"
3837         $LFS getstripe $DIR/f34 2>&1 | grep -q "no stripe info" ||
3838                 error "getstripe failed"
3839         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3840                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3841 }
3842 run_test 34a "truncate file that has not been opened ==========="
3843
3844 test_34b() {
3845         [ ! -f $DIR/f34 ] && test_34a
3846         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3847                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3848         $OPENFILE -f O_RDONLY $DIR/f34
3849         $LFS getstripe $DIR/f34 2>&1 | grep -q "no stripe info" ||
3850                 error "getstripe failed"
3851         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3852                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3853 }
3854 run_test 34b "O_RDONLY opening file doesn't create objects ====="
3855
3856 test_34c() {
3857         [ ! -f $DIR/f34 ] && test_34a
3858         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3859                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3860         $OPENFILE -f O_RDWR $DIR/f34
3861         $LFS getstripe $DIR/f34 2>&1 | grep -q "no stripe info" &&
3862                 error "$LFS getstripe failed"
3863         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3864                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3865 }
3866 run_test 34c "O_RDWR opening file-with-size works =============="
3867
3868 test_34d() {
3869         [ ! -f $DIR/f34 ] && test_34a
3870         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 ||
3871                 error "dd failed"
3872         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3873                 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3874         rm $DIR/f34
3875 }
3876 run_test 34d "write to sparse file ============================="
3877
3878 test_34e() {
3879         rm -f $DIR/f34e
3880         $MCREATE $DIR/f34e || error "mcreate failed"
3881         $TRUNCATE $DIR/f34e 1000 || error "truncate failed"
3882         $CHECKSTAT -s 1000 $DIR/f34e ||
3883                 error "Size of $DIR/f34e not equal to 1000 bytes"
3884         $OPENFILE -f O_RDWR $DIR/f34e
3885         $CHECKSTAT -s 1000 $DIR/f34e ||
3886                 error "Size of $DIR/f34e not equal to 1000 bytes"
3887 }
3888 run_test 34e "create objects, some with size and some without =="
3889
3890 test_34f() { # bug 6242, 6243
3891         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3892
3893         SIZE34F=48000
3894         rm -f $DIR/f34f
3895         $MCREATE $DIR/f34f || error "mcreate failed"
3896         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
3897         dd if=$DIR/f34f of=$TMP/f34f
3898         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
3899         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
3900         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
3901         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
3902         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
3903 }
3904 run_test 34f "read from a file with no objects until EOF ======="
3905
3906 test_34g() {
3907         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3908
3909         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE ||
3910                 error "dd failed"
3911         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error "truncate failed"
3912         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3913                 error "Size of $DIR/$tfile not equal to $((TEST_34_SIZE / 2))"
3914         cancel_lru_locks osc
3915         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3916                 error "wrong size after lock cancel"
3917
3918         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error "truncate failed"
3919         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3920                 error "expanding truncate failed"
3921         cancel_lru_locks osc
3922         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3923                 error "wrong expanded size after lock cancel"
3924 }
3925 run_test 34g "truncate long file ==============================="
3926
3927 test_34h() {
3928         [ $PARALLEL == "yes" ] && skip "skip parallel run"
3929
3930         local gid=10
3931         local sz=1000
3932
3933         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error "dd failed"
3934         sync # Flush the cache so that multiop below does not block on cache
3935              # flush when getting the group lock
3936         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
3937         MULTIPID=$!
3938
3939         # Since just timed wait is not good enough, let's do a sync write
3940         # that way we are sure enough time for a roundtrip + processing
3941         # passed + 2 seconds of extra margin.
3942         dd if=/dev/zero of=$DIR/${tfile}-1 bs=$PAGE_SIZE oflag=direct count=1
3943         rm $DIR/${tfile}-1
3944         sleep 2
3945
3946         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
3947                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
3948                 kill -9 $MULTIPID
3949         fi
3950         wait $MULTIPID
3951         local nsz=`stat -c %s $DIR/$tfile`
3952         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
3953 }
3954 run_test 34h "ftruncate file under grouplock should not block"
3955
3956 test_35a() {
3957         cp /bin/sh $DIR/f35a
3958         chmod 444 $DIR/f35a
3959         chown $RUNAS_ID $DIR/f35a
3960         $RUNAS $DIR/f35a && error || true
3961         rm $DIR/f35a
3962 }
3963 run_test 35a "exec file with mode 444 (should return and not leak)"
3964
3965 test_36a() {
3966         rm -f $DIR/f36
3967         utime $DIR/f36 || error "utime failed for MDS"
3968 }
3969 run_test 36a "MDS utime check (mknod, utime)"
3970
3971 test_36b() {
3972         echo "" > $DIR/f36
3973         utime $DIR/f36 || error "utime failed for OST"
3974 }
3975 run_test 36b "OST utime check (open, utime)"
3976
3977 test_36c() {
3978         rm -f $DIR/d36/f36
3979         test_mkdir $DIR/d36
3980         chown $RUNAS_ID $DIR/d36
3981         $RUNAS utime $DIR/d36/f36 || error "utime failed for MDS as non-root"
3982 }
3983 run_test 36c "non-root MDS utime check (mknod, utime)"
3984
3985 test_36d() {
3986         [ ! -d $DIR/d36 ] && test_36c
3987         echo "" > $DIR/d36/f36
3988         $RUNAS utime $DIR/d36/f36 || error "utime failed for OST as non-root"
3989 }
3990 run_test 36d "non-root OST utime check (open, utime)"
3991
3992 test_36e() {
3993         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping"
3994
3995         test_mkdir $DIR/$tdir
3996         touch $DIR/$tdir/$tfile
3997         $RUNAS utime $DIR/$tdir/$tfile &&
3998                 error "utime worked, expected failure" || true
3999 }
4000 run_test 36e "utime on non-owned file (should return error)"
4001
4002 subr_36fh() {
4003         local fl="$1"
4004         local LANG_SAVE=$LANG
4005         local LC_LANG_SAVE=$LC_LANG
4006         export LANG=C LC_LANG=C # for date language
4007
4008         DATESTR="Dec 20  2000"
4009         test_mkdir $DIR/$tdir
4010         lctl set_param fail_loc=$fl
4011         date; date +%s
4012         cp /etc/hosts $DIR/$tdir/$tfile
4013         sync & # write RPC generated with "current" inode timestamp, but delayed
4014         sleep 1
4015         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
4016         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
4017         cancel_lru_locks $OSC
4018         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
4019         date; date +%s
4020         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
4021                 echo "BEFORE: $LS_BEFORE" && \
4022                 echo "AFTER : $LS_AFTER" && \
4023                 echo "WANT  : $DATESTR" && \
4024                 error "$DIR/$tdir/$tfile timestamps changed" || true
4025
4026         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
4027 }
4028
4029 test_36f() {
4030         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4031
4032         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4033         subr_36fh "0x80000214"
4034 }
4035 run_test 36f "utime on file racing with OST BRW write =========="
4036
4037 test_36g() {
4038         remote_ost_nodsh && skip "remote OST with nodsh"
4039         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4040         [ $MDS1_VERSION -lt $(version_code 2.12.51) ] &&
4041                 skip "Need MDS version at least 2.12.51"
4042
4043         local fmd_max_age
4044         local fmd
4045         local facet="ost1"
4046         local tgt="obdfilter"
4047
4048         [[ $OSC == "mdc" ]] && tgt="mdt" && facet="mds1"
4049
4050         test_mkdir $DIR/$tdir
4051         fmd_max_age=$(do_facet $facet \
4052                 "lctl get_param -n $tgt.*.tgt_fmd_seconds 2> /dev/null | \
4053                 head -n 1")
4054
4055         echo "FMD max age: ${fmd_max_age}s"
4056         touch $DIR/$tdir/$tfile
4057         fmd=$(do_facet $facet "lctl get_param -n $tgt.*.exports.*.fmd_count" |
4058                 gawk '{cnt=cnt+$1}  END{print cnt}')
4059         echo "FMD before: $fmd"
4060         [[ $fmd == 0 ]] &&
4061                 error "FMD wasn't create by touch"
4062         sleep $((fmd_max_age + 12))
4063         fmd=$(do_facet $facet "lctl get_param -n $tgt.*.exports.*.fmd_count" |
4064                 gawk '{cnt=cnt+$1}  END{print cnt}')
4065         echo "FMD after: $fmd"
4066         [[ $fmd == 0 ]] ||
4067                 error "FMD wasn't expired by ping"
4068 }
4069 run_test 36g "FMD cache expiry ====================="
4070
4071 test_36h() {
4072         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4073
4074         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
4075         subr_36fh "0x80000227"
4076 }
4077 run_test 36h "utime on file racing with OST BRW write =========="
4078
4079 test_36i() {
4080         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
4081
4082         test_mkdir $DIR/$tdir
4083         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
4084
4085         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
4086         local new_mtime=$((mtime + 200))
4087
4088         #change Modify time of striped dir
4089         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
4090                         error "change mtime failed"
4091
4092         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
4093
4094         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
4095 }
4096 run_test 36i "change mtime on striped directory"
4097
4098 # test_37 - duplicate with tests 32q 32r
4099
4100 test_38() {
4101         local file=$DIR/$tfile
4102         touch $file
4103         openfile -f O_DIRECTORY $file
4104         local RC=$?
4105         local ENOTDIR=20
4106         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
4107         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
4108 }
4109 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
4110
4111 test_39a() { # was test_39
4112         touch $DIR/$tfile
4113         touch $DIR/${tfile}2
4114 #       ls -l  $DIR/$tfile $DIR/${tfile}2
4115 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
4116 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
4117         sleep 2
4118         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
4119         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
4120                 echo "mtime"
4121                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
4122                 echo "atime"
4123                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
4124                 echo "ctime"
4125                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
4126                 error "O_TRUNC didn't change timestamps"
4127         fi
4128 }
4129 run_test 39a "mtime changed on create"
4130
4131 test_39b() {
4132         test_mkdir -c1 $DIR/$tdir
4133         cp -p /etc/passwd $DIR/$tdir/fopen
4134         cp -p /etc/passwd $DIR/$tdir/flink
4135         cp -p /etc/passwd $DIR/$tdir/funlink
4136         cp -p /etc/passwd $DIR/$tdir/frename
4137         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
4138
4139         sleep 1
4140         echo "aaaaaa" >> $DIR/$tdir/fopen
4141         echo "aaaaaa" >> $DIR/$tdir/flink
4142         echo "aaaaaa" >> $DIR/$tdir/funlink
4143         echo "aaaaaa" >> $DIR/$tdir/frename
4144
4145         local open_new=`stat -c %Y $DIR/$tdir/fopen`
4146         local link_new=`stat -c %Y $DIR/$tdir/flink`
4147         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
4148         local rename_new=`stat -c %Y $DIR/$tdir/frename`
4149
4150         cat $DIR/$tdir/fopen > /dev/null
4151         ln $DIR/$tdir/flink $DIR/$tdir/flink2
4152         rm -f $DIR/$tdir/funlink2
4153         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
4154
4155         for (( i=0; i < 2; i++ )) ; do
4156                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
4157                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
4158                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
4159                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
4160
4161                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
4162                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
4163                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
4164                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
4165
4166                 cancel_lru_locks $OSC
4167                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4168         done
4169 }
4170 run_test 39b "mtime change on open, link, unlink, rename  ======"
4171
4172 # this should be set to past
4173 TEST_39_MTIME=`date -d "1 year ago" +%s`
4174
4175 # bug 11063
4176 test_39c() {
4177         touch $DIR1/$tfile
4178         sleep 2
4179         local mtime0=`stat -c %Y $DIR1/$tfile`
4180
4181         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4182         local mtime1=`stat -c %Y $DIR1/$tfile`
4183         [ "$mtime1" = $TEST_39_MTIME ] || \
4184                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
4185
4186         local d1=`date +%s`
4187         echo hello >> $DIR1/$tfile
4188         local d2=`date +%s`
4189         local mtime2=`stat -c %Y $DIR1/$tfile`
4190         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
4191                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
4192
4193         mv $DIR1/$tfile $DIR1/$tfile-1
4194
4195         for (( i=0; i < 2; i++ )) ; do
4196                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
4197                 [ "$mtime2" = "$mtime3" ] || \
4198                         error "mtime ($mtime2) changed (to $mtime3) on rename"
4199
4200                 cancel_lru_locks $OSC
4201                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4202         done
4203 }
4204 run_test 39c "mtime change on rename ==========================="
4205
4206 # bug 21114
4207 test_39d() {
4208         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4209
4210         touch $DIR1/$tfile
4211         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4212
4213         for (( i=0; i < 2; i++ )) ; do
4214                 local mtime=`stat -c %Y $DIR1/$tfile`
4215                 [ $mtime = $TEST_39_MTIME ] || \
4216                         error "mtime($mtime) is not set to $TEST_39_MTIME"
4217
4218                 cancel_lru_locks $OSC
4219                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4220         done
4221 }
4222 run_test 39d "create, utime, stat =============================="
4223
4224 # bug 21114
4225 test_39e() {
4226         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4227
4228         touch $DIR1/$tfile
4229         local mtime1=`stat -c %Y $DIR1/$tfile`
4230
4231         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4232
4233         for (( i=0; i < 2; i++ )) ; do
4234                 local mtime2=`stat -c %Y $DIR1/$tfile`
4235                 [ $mtime2 = $TEST_39_MTIME ] || \
4236                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
4237
4238                 cancel_lru_locks $OSC
4239                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4240         done
4241 }
4242 run_test 39e "create, stat, utime, stat ========================"
4243
4244 # bug 21114
4245 test_39f() {
4246         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4247
4248         touch $DIR1/$tfile
4249         mtime1=`stat -c %Y $DIR1/$tfile`
4250
4251         sleep 2
4252         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4253
4254         for (( i=0; i < 2; i++ )) ; do
4255                 local mtime2=`stat -c %Y $DIR1/$tfile`
4256                 [ $mtime2 = $TEST_39_MTIME ] || \
4257                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
4258
4259                 cancel_lru_locks $OSC
4260                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4261         done
4262 }
4263 run_test 39f "create, stat, sleep, utime, stat ================="
4264
4265 # bug 11063
4266 test_39g() {
4267         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4268
4269         echo hello >> $DIR1/$tfile
4270         local mtime1=`stat -c %Y $DIR1/$tfile`
4271
4272         sleep 2
4273         chmod o+r $DIR1/$tfile
4274
4275         for (( i=0; i < 2; i++ )) ; do
4276                 local mtime2=`stat -c %Y $DIR1/$tfile`
4277                 [ "$mtime1" = "$mtime2" ] || \
4278                         error "lost mtime: $mtime2, should be $mtime1"
4279
4280                 cancel_lru_locks $OSC
4281                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4282         done
4283 }
4284 run_test 39g "write, chmod, stat ==============================="
4285
4286 # bug 11063
4287 test_39h() {
4288         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4289
4290         touch $DIR1/$tfile
4291         sleep 1
4292
4293         local d1=`date`
4294         echo hello >> $DIR1/$tfile
4295         local mtime1=`stat -c %Y $DIR1/$tfile`
4296
4297         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4298         local d2=`date`
4299         if [ "$d1" != "$d2" ]; then
4300                 echo "write and touch not within one second"
4301         else
4302                 for (( i=0; i < 2; i++ )) ; do
4303                         local mtime2=`stat -c %Y $DIR1/$tfile`
4304                         [ "$mtime2" = $TEST_39_MTIME ] || \
4305                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
4306
4307                         cancel_lru_locks $OSC
4308                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4309                 done
4310         fi
4311 }
4312 run_test 39h "write, utime within one second, stat ============="
4313
4314 test_39i() {
4315         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4316
4317         touch $DIR1/$tfile
4318         sleep 1
4319
4320         echo hello >> $DIR1/$tfile
4321         local mtime1=`stat -c %Y $DIR1/$tfile`
4322
4323         mv $DIR1/$tfile $DIR1/$tfile-1
4324
4325         for (( i=0; i < 2; i++ )) ; do
4326                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
4327
4328                 [ "$mtime1" = "$mtime2" ] || \
4329                         error "lost mtime: $mtime2, should be $mtime1"
4330
4331                 cancel_lru_locks $OSC
4332                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4333         done
4334 }
4335 run_test 39i "write, rename, stat =============================="
4336
4337 test_39j() {
4338         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4339
4340         start_full_debug_logging
4341         touch $DIR1/$tfile
4342         sleep 1
4343
4344         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
4345         lctl set_param fail_loc=0x80000412
4346         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
4347                 error "multiop failed"
4348         local multipid=$!
4349         local mtime1=`stat -c %Y $DIR1/$tfile`
4350
4351         mv $DIR1/$tfile $DIR1/$tfile-1
4352
4353         kill -USR1 $multipid
4354         wait $multipid || error "multiop close failed"
4355
4356         for (( i=0; i < 2; i++ )) ; do
4357                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
4358                 [ "$mtime1" = "$mtime2" ] ||
4359                         error "mtime is lost on close: $mtime2, " \
4360                               "should be $mtime1"
4361
4362                 cancel_lru_locks
4363                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4364         done
4365         lctl set_param fail_loc=0
4366         stop_full_debug_logging
4367 }
4368 run_test 39j "write, rename, close, stat ======================="
4369
4370 test_39k() {
4371         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4372
4373         touch $DIR1/$tfile
4374         sleep 1
4375
4376         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
4377         local multipid=$!
4378         local mtime1=`stat -c %Y $DIR1/$tfile`
4379
4380         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
4381
4382         kill -USR1 $multipid
4383         wait $multipid || error "multiop close failed"
4384
4385         for (( i=0; i < 2; i++ )) ; do
4386                 local mtime2=`stat -c %Y $DIR1/$tfile`
4387
4388                 [ "$mtime2" = $TEST_39_MTIME ] || \
4389                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
4390
4391                 cancel_lru_locks
4392                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4393         done
4394 }
4395 run_test 39k "write, utime, close, stat ========================"
4396
4397 # this should be set to future
4398 TEST_39_ATIME=`date -d "1 year" +%s`
4399
4400 test_39l() {
4401         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4402         remote_mds_nodsh && skip "remote MDS with nodsh"
4403
4404         local atime_diff=$(do_facet $SINGLEMDS \
4405                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
4406         rm -rf $DIR/$tdir
4407         mkdir -p $DIR/$tdir
4408
4409         # test setting directory atime to future
4410         touch -a -d @$TEST_39_ATIME $DIR/$tdir
4411         local atime=$(stat -c %X $DIR/$tdir)
4412         [ "$atime" = $TEST_39_ATIME ] ||
4413                 error "atime is not set to future: $atime, $TEST_39_ATIME"
4414
4415         # test setting directory atime from future to now
4416         local now=$(date +%s)
4417         touch -a -d @$now $DIR/$tdir
4418
4419         atime=$(stat -c %X $DIR/$tdir)
4420         [ "$atime" -eq "$now"  ] ||
4421                 error "atime is not updated from future: $atime, $now"
4422
4423         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
4424         sleep 3
4425
4426         # test setting directory atime when now > dir atime + atime_diff
4427         local d1=$(date +%s)
4428         ls $DIR/$tdir
4429         local d2=$(date +%s)
4430         cancel_lru_locks mdc
4431         atime=$(stat -c %X $DIR/$tdir)
4432         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
4433                 error "atime is not updated  : $atime, should be $d2"
4434
4435         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
4436         sleep 3
4437
4438         # test not setting directory atime when now < dir atime + atime_diff
4439         ls $DIR/$tdir
4440         cancel_lru_locks mdc
4441         atime=$(stat -c %X $DIR/$tdir)
4442         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
4443                 error "atime is updated to $atime, should remain $d1<atime<$d2"
4444
4445         do_facet $SINGLEMDS \
4446                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
4447 }
4448 run_test 39l "directory atime update ==========================="
4449
4450 test_39m() {
4451         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4452
4453         touch $DIR1/$tfile
4454         sleep 2
4455         local far_past_mtime=$(date -d "May 29 1953" +%s)
4456         local far_past_atime=$(date -d "Dec 17 1903" +%s)
4457
4458         touch -m -d @$far_past_mtime $DIR1/$tfile
4459         touch -a -d @$far_past_atime $DIR1/$tfile
4460
4461         for (( i=0; i < 2; i++ )) ; do
4462                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
4463                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
4464                         error "atime or mtime set incorrectly"
4465
4466                 cancel_lru_locks $OSC
4467                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
4468         done
4469 }
4470 run_test 39m "test atime and mtime before 1970"
4471
4472 test_39n() { # LU-3832
4473         remote_mds_nodsh && skip "remote MDS with nodsh"
4474
4475         local atime_diff=$(do_facet $SINGLEMDS \
4476                 lctl get_param -n mdd.*MDT0000*.atime_diff)
4477         local atime0
4478         local atime1
4479         local atime2
4480
4481         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
4482
4483         rm -rf $DIR/$tfile
4484         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
4485         atime0=$(stat -c %X $DIR/$tfile)
4486
4487         sleep 5
4488         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
4489         atime1=$(stat -c %X $DIR/$tfile)
4490
4491         sleep 5
4492         cancel_lru_locks mdc
4493         cancel_lru_locks osc
4494         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
4495         atime2=$(stat -c %X $DIR/$tfile)
4496
4497         do_facet $SINGLEMDS \
4498                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
4499
4500         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
4501         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
4502 }
4503 run_test 39n "check that O_NOATIME is honored"
4504
4505 test_39o() {
4506         TESTDIR=$DIR/$tdir/$tfile
4507         [ -e $TESTDIR ] && rm -rf $TESTDIR
4508         mkdir -p $TESTDIR
4509         cd $TESTDIR
4510         links1=2
4511         ls
4512         mkdir a b
4513         ls
4514         links2=$(stat -c %h .)
4515         [ $(($links1 + 2)) != $links2 ] &&
4516                 error "wrong links count $(($links1 + 2)) != $links2"
4517         rmdir b
4518         links3=$(stat -c %h .)
4519         [ $(($links1 + 1)) != $links3 ] &&
4520                 error "wrong links count $links1 != $links3"
4521         return 0
4522 }
4523 run_test 39o "directory cached attributes updated after create"
4524
4525 test_39p() {
4526         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
4527
4528         local MDTIDX=1
4529         TESTDIR=$DIR/$tdir/$tdir
4530         [ -e $TESTDIR ] && rm -rf $TESTDIR
4531         test_mkdir -p $TESTDIR
4532         cd $TESTDIR
4533         links1=2
4534         ls
4535         test_mkdir -i $MDTIDX $TESTDIR/remote_dir1
4536         test_mkdir -i $MDTIDX $TESTDIR/remote_dir2
4537         ls
4538         links2=$(stat -c %h .)
4539         [ $(($links1 + 2)) != $links2 ] &&
4540                 error "wrong links count $(($links1 + 2)) != $links2"
4541         rmdir remote_dir2
4542         links3=$(stat -c %h .)
4543         [ $(($links1 + 1)) != $links3 ] &&
4544                 error "wrong links count $links1 != $links3"
4545         return 0
4546 }
4547 run_test 39p "remote directory cached attributes updated after create ========"
4548
4549 test_39r() {
4550         [ $OST1_VERSION -ge $(version_code 2.13.52) ] ||
4551                 skip "no atime update on old OST"
4552         if [ "$ost1_FSTYPE" != ldiskfs ]; then
4553                 skip_env "ldiskfs only test"
4554         fi
4555
4556         local saved_adiff
4557         saved_adiff=$(do_facet ost1 \
4558                 lctl get_param -n obdfilter.*OST0000.atime_diff)
4559         stack_trap "do_facet ost1 \
4560                 lctl set_param obdfilter.*.atime_diff=$saved_adiff"
4561
4562         do_facet ost1 "lctl set_param obdfilter.*.atime_diff=5"
4563
4564         $LFS setstripe -i 0 $DIR/$tfile
4565         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 ||
4566                 error "can't write initial file"
4567         cancel_lru_locks osc
4568
4569         # exceed atime_diff and access file
4570         sleep 6
4571         dd if=$DIR/$tfile of=/dev/null || error "can't udpate atime"
4572
4573         local atime_cli=$(stat -c %X $DIR/$tfile)
4574         echo "client atime: $atime_cli"
4575         # allow atime update to be written to device
4576         do_facet ost1 "$LCTL set_param -n osd*.*OST*.force_sync 1"
4577         sleep 5
4578
4579         local ostdev=$(ostdevname 1)
4580         local fid=($(lfs getstripe -y $DIR/$tfile |
4581                         awk '/l_fid:/ { print $2 }' | tr ':' ' '))
4582         local objpath="O/0/d$((${fid[1]} % 32))/$((${fid[1]}))"
4583         local cmd="debugfs -c -R \\\"stat $objpath\\\" $ostdev"
4584
4585         echo "OST atime: $(do_facet ost1 "$cmd" |& grep atime)"
4586         local atime_ost=$(do_facet ost1 "$cmd" |&
4587                           awk -F'[: ]' '/atime:/ { print $4 }')
4588         (( atime_cli == atime_ost )) ||
4589                 error "atime on client $atime_cli != ost $atime_ost"
4590 }
4591 run_test 39r "lazy atime update on OST"
4592
4593 test_39q() { # LU-8041
4594         local testdir=$DIR/$tdir
4595         mkdir -p $testdir
4596         multiop_bg_pause $testdir D_c || error "multiop failed"
4597         local multipid=$!
4598         cancel_lru_locks mdc
4599         kill -USR1 $multipid
4600         local atime=$(stat -c %X $testdir)
4601         [ "$atime" -ne 0 ] || error "atime is zero"
4602 }
4603 run_test 39q "close won't zero out atime"
4604
4605 test_40() {
4606         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
4607         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
4608                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
4609         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
4610                 error "$tfile is not 4096 bytes in size"
4611 }
4612 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
4613
4614 test_41() {
4615         # bug 1553
4616         small_write $DIR/f41 18
4617 }
4618 run_test 41 "test small file write + fstat ====================="
4619
4620 count_ost_writes() {
4621         lctl get_param -n ${OSC}.*.stats |
4622                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
4623                         END { printf("%0.0f", writes) }'
4624 }
4625
4626 # decent default
4627 WRITEBACK_SAVE=500
4628 DIRTY_RATIO_SAVE=40
4629 MAX_DIRTY_RATIO=50
4630 BG_DIRTY_RATIO_SAVE=10
4631 MAX_BG_DIRTY_RATIO=25
4632
4633 start_writeback() {
4634         trap 0
4635         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
4636         # dirty_ratio, dirty_background_ratio
4637         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
4638                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
4639                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
4640                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
4641         else
4642                 # if file not here, we are a 2.4 kernel
4643                 kill -CONT `pidof kupdated`
4644         fi
4645 }
4646
4647 stop_writeback() {
4648         # setup the trap first, so someone cannot exit the test at the
4649         # exact wrong time and mess up a machine
4650         trap start_writeback EXIT
4651         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
4652         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
4653                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
4654                 sysctl -w vm.dirty_writeback_centisecs=0
4655                 sysctl -w vm.dirty_writeback_centisecs=0
4656                 # save and increase /proc/sys/vm/dirty_ratio
4657                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
4658                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
4659                 # save and increase /proc/sys/vm/dirty_background_ratio
4660                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
4661                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
4662         else
4663                 # if file not here, we are a 2.4 kernel
4664                 kill -STOP `pidof kupdated`
4665         fi
4666 }
4667
4668 # ensure that all stripes have some grant before we test client-side cache
4669 setup_test42() {
4670         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
4671                 dd if=/dev/zero of=$i bs=4k count=1
4672                 rm $i
4673         done
4674 }
4675
4676 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
4677 # file truncation, and file removal.
4678 test_42a() {
4679         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4680
4681         setup_test42
4682         cancel_lru_locks $OSC
4683         stop_writeback
4684         sync; sleep 1; sync # just to be safe
4685         BEFOREWRITES=`count_ost_writes`
4686         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
4687         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
4688         AFTERWRITES=`count_ost_writes`
4689         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
4690                 error "$BEFOREWRITES < $AFTERWRITES"
4691         start_writeback
4692 }
4693 run_test 42a "ensure that we don't flush on close"
4694
4695 test_42b() {
4696         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4697
4698         setup_test42
4699         cancel_lru_locks $OSC
4700         stop_writeback
4701         sync
4702         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
4703         BEFOREWRITES=$(count_ost_writes)
4704         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
4705         AFTERWRITES=$(count_ost_writes)
4706         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
4707                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
4708         fi
4709         BEFOREWRITES=$(count_ost_writes)
4710         sync || error "sync: $?"
4711         AFTERWRITES=$(count_ost_writes)
4712         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
4713                 error "$BEFOREWRITES < $AFTERWRITES on sync"
4714         fi
4715         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
4716         start_writeback
4717         return 0
4718 }
4719 run_test 42b "test destroy of file with cached dirty data ======"
4720
4721 # if these tests just want to test the effect of truncation,
4722 # they have to be very careful.  consider:
4723 # - the first open gets a {0,EOF}PR lock
4724 # - the first write conflicts and gets a {0, count-1}PW
4725 # - the rest of the writes are under {count,EOF}PW
4726 # - the open for truncate tries to match a {0,EOF}PR
4727 #   for the filesize and cancels the PWs.
4728 # any number of fixes (don't get {0,EOF} on open, match
4729 # composite locks, do smarter file size management) fix
4730 # this, but for now we want these tests to verify that
4731 # the cancellation with truncate intent works, so we
4732 # start the file with a full-file pw lock to match against
4733 # until the truncate.
4734 trunc_test() {
4735         test=$1
4736         file=$DIR/$test
4737         offset=$2
4738         cancel_lru_locks $OSC
4739         stop_writeback
4740         # prime the file with 0,EOF PW to match
4741         touch $file
4742         $TRUNCATE $file 0
4743         sync; sync
4744         # now the real test..
4745         dd if=/dev/zero of=$file bs=1024 count=100
4746         BEFOREWRITES=`count_ost_writes`
4747         $TRUNCATE $file $offset
4748         cancel_lru_locks $OSC
4749         AFTERWRITES=`count_ost_writes`
4750         start_writeback
4751 }
4752
4753 test_42c() {
4754         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4755
4756         trunc_test 42c 1024
4757         [ $BEFOREWRITES -eq $AFTERWRITES ] &&
4758                 error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
4759         rm $file
4760 }
4761 run_test 42c "test partial truncate of file with cached dirty data"
4762
4763 test_42d() {
4764         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4765
4766         trunc_test 42d 0
4767         [ $BEFOREWRITES -eq $AFTERWRITES ] ||
4768                 error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
4769         rm $file
4770 }
4771 run_test 42d "test complete truncate of file with cached dirty data"
4772
4773 test_42e() { # bug22074
4774         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4775
4776         local TDIR=$DIR/${tdir}e
4777         local pages=16 # hardcoded 16 pages, don't change it.
4778         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
4779         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
4780         local max_dirty_mb
4781         local warmup_files
4782
4783         test_mkdir $DIR/${tdir}e
4784         $LFS setstripe -c 1 $TDIR
4785         createmany -o $TDIR/f $files
4786
4787         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
4788
4789         # we assume that with $OSTCOUNT files, at least one of them will
4790         # be allocated on OST0.
4791         warmup_files=$((OSTCOUNT * max_dirty_mb))
4792         createmany -o $TDIR/w $warmup_files
4793
4794         # write a large amount of data into one file and sync, to get good
4795         # avail_grant number from OST.
4796         for ((i=0; i<$warmup_files; i++)); do
4797                 idx=$($LFS getstripe -i $TDIR/w$i)
4798                 [ $idx -ne 0 ] && continue
4799                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
4800                 break
4801         done
4802         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
4803         sync
4804         $LCTL get_param $proc_osc0/cur_dirty_bytes
4805         $LCTL get_param $proc_osc0/cur_grant_bytes
4806
4807         # create as much dirty pages as we can while not to trigger the actual
4808         # RPCs directly. but depends on the env, VFS may trigger flush during this
4809         # period, hopefully we are good.
4810         for ((i=0; i<$warmup_files; i++)); do
4811                 idx=$($LFS getstripe -i $TDIR/w$i)
4812                 [ $idx -ne 0 ] && continue
4813                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
4814         done
4815         $LCTL get_param $proc_osc0/cur_dirty_bytes
4816         $LCTL get_param $proc_osc0/cur_grant_bytes
4817
4818         # perform the real test
4819         $LCTL set_param $proc_osc0/rpc_stats 0
4820         for ((;i<$files; i++)); do
4821                 [ $($LFS getstripe -i $TDIR/f$i) -eq 0 ] || continue
4822                 dd if=/dev/zero of=$TDIR/f$i bs=$PAGE_SIZE count=$pages 2>/dev/null
4823         done
4824         sync
4825         $LCTL get_param $proc_osc0/rpc_stats
4826
4827         local percent=0
4828         local have_ppr=false
4829         $LCTL get_param $proc_osc0/rpc_stats |
4830                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
4831                         # skip lines until we are at the RPC histogram data
4832                         [ "$PPR" == "pages" ] && have_ppr=true && continue
4833                         $have_ppr || continue
4834
4835                         # we only want the percent stat for < 16 pages
4836                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
4837
4838                         percent=$((percent + WPCT))
4839                         if [[ $percent -gt 15 ]]; then
4840                                 error "less than 16-pages write RPCs" \
4841                                       "$percent% > 15%"
4842                                 break
4843                         fi
4844                 done
4845         rm -rf $TDIR
4846 }
4847 run_test 42e "verify sub-RPC writes are not done synchronously"
4848
4849 test_43A() { # was test_43
4850         test_mkdir $DIR/$tdir
4851         cp -p /bin/ls $DIR/$tdir/$tfile
4852         $MULTIOP $DIR/$tdir/$tfile Ow_c &
4853         pid=$!
4854         # give multiop a chance to open
4855         sleep 1
4856
4857         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
4858         kill -USR1 $pid
4859 }
4860 run_test 43A "execution of file opened for write should return -ETXTBSY"
4861
4862 test_43a() {
4863         test_mkdir $DIR/$tdir
4864         cp -p $(which sleep) $DIR/$tdir/sleep || error "can't copy"
4865         $DIR/$tdir/sleep 60 &
4866         SLEEP_PID=$!
4867         # Make sure exec of $tdir/sleep wins race with truncate
4868         sleep 1
4869         $MULTIOP $DIR/$tdir/sleep Oc && error "expected error, got success"
4870         kill $SLEEP_PID
4871 }
4872 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
4873
4874 test_43b() {
4875         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4876
4877         test_mkdir $DIR/$tdir
4878         cp -p $(which sleep) $DIR/$tdir/sleep || error "can't copy"
4879         $DIR/$tdir/sleep 60 &
4880         SLEEP_PID=$!
4881         # Make sure exec of $tdir/sleep wins race with truncate
4882         sleep 1
4883         $TRUNCATE $DIR/$tdir/sleep 0 && error "expected error, got success"
4884         kill $SLEEP_PID
4885 }
4886 run_test 43b "truncate of file being executed should return -ETXTBSY"
4887
4888 test_43c() {
4889         local testdir="$DIR/$tdir"
4890         test_mkdir $testdir
4891         cp $SHELL $testdir/
4892         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
4893                 ( cd $testdir && md5sum -c )
4894 }
4895 run_test 43c "md5sum of copy into lustre"
4896
4897 test_44A() { # was test_44
4898         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4899
4900         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
4901         dd if=$DIR/f1 bs=4k count=1 > /dev/null
4902 }
4903 run_test 44A "zero length read from a sparse stripe"
4904
4905 test_44a() {
4906         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
4907                 awk '{ print $2 }')
4908         [ -z "$nstripe" ] && skip "can't get stripe info"
4909         [[ $nstripe -gt $OSTCOUNT ]] &&
4910                 skip "Wrong default_stripe_count: $nstripe OSTCOUNT: $OSTCOUNT"
4911
4912         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
4913                 awk '{ print $2 }')
4914         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
4915                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
4916                         awk '{ print $2 }')
4917         fi
4918
4919         OFFSETS="0 $((stride/2)) $((stride-1))"
4920         for offset in $OFFSETS; do
4921                 for i in $(seq 0 $((nstripe-1))); do
4922                         local GLOBALOFFSETS=""
4923                         # size in Bytes
4924                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
4925                         local myfn=$DIR/d44a-$size
4926                         echo "--------writing $myfn at $size"
4927                         ll_sparseness_write $myfn $size ||
4928                                 error "ll_sparseness_write"
4929                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
4930                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
4931                                 error "ll_sparseness_verify $GLOBALOFFSETS"
4932
4933                         for j in $(seq 0 $((nstripe-1))); do
4934                                 # size in Bytes
4935                                 size=$((((j + $nstripe )*$stride + $offset)))
4936                                 ll_sparseness_write $myfn $size ||
4937                                         error "ll_sparseness_write"
4938                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
4939                         done
4940                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
4941                                 error "ll_sparseness_verify $GLOBALOFFSETS"
4942                         rm -f $myfn
4943                 done
4944         done
4945 }
4946 run_test 44a "test sparse pwrite ==============================="
4947
4948 dirty_osc_total() {
4949         tot=0
4950         for d in `lctl get_param -n ${OSC}.*.cur_dirty_bytes`; do
4951                 tot=$(($tot + $d))
4952         done
4953         echo $tot
4954 }
4955 do_dirty_record() {
4956         before=`dirty_osc_total`
4957         echo executing "\"$*\""
4958         eval $*
4959         after=`dirty_osc_total`
4960         echo before $before, after $after
4961 }
4962 test_45() {
4963         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4964
4965         f="$DIR/f45"
4966         # Obtain grants from OST if it supports it
4967         echo blah > ${f}_grant
4968         stop_writeback
4969         sync
4970         do_dirty_record "echo blah > $f"
4971         [[ $before -eq $after ]] && error "write wasn't cached"
4972         do_dirty_record "> $f"
4973         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
4974         do_dirty_record "echo blah > $f"
4975         [[ $before -eq $after ]] && error "write wasn't cached"
4976         do_dirty_record "sync"
4977         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
4978         do_dirty_record "echo blah > $f"
4979         [[ $before -eq $after ]] && error "write wasn't cached"
4980         do_dirty_record "cancel_lru_locks osc"
4981         [[ $before -gt $after ]] ||
4982                 error "lock cancellation didn't lower dirty count"
4983         start_writeback
4984 }
4985 run_test 45 "osc io page accounting ============================"
4986
4987 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
4988 # test tickles a bug where re-dirtying a page was failing to be mapped to the
4989 # objects offset and an assert hit when an rpc was built with 1023's mapped
4990 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
4991 test_46() {
4992         [ $PARALLEL == "yes" ] && skip "skip parallel run"
4993
4994         f="$DIR/f46"
4995         stop_writeback
4996         sync
4997         dd if=/dev/zero of=$f bs=$PAGE_SIZE seek=511 count=1
4998         sync
4999         dd conv=notrunc if=/dev/zero of=$f bs=$PAGE_SIZE seek=1023 count=1
5000         dd conv=notrunc if=/dev/zero of=$f bs=$PAGE_SIZE seek=511 count=1
5001         sync
5002         start_writeback
5003 }
5004 run_test 46 "dirtying a previously written page ================"
5005
5006 # test_47 is removed "Device nodes check" is moved to test_28
5007
5008 test_48a() { # bug 2399
5009         [ "$mds1_FSTYPE" = "zfs" ] &&
5010         [ $MDS1_VERSION -lt $(version_code 2.3.63) ] &&
5011                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly"
5012
5013         test_mkdir $DIR/$tdir
5014         cd $DIR/$tdir
5015         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
5016         test_mkdir $DIR/$tdir
5017         touch foo || error "'touch foo' failed after recreating cwd"
5018         test_mkdir bar
5019         touch .foo || error "'touch .foo' failed after recreating cwd"
5020         test_mkdir .bar
5021         ls . > /dev/null || error "'ls .' failed after recreating cwd"
5022         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
5023         cd . || error "'cd .' failed after recreating cwd"
5024         mkdir . && error "'mkdir .' worked after recreating cwd"
5025         rmdir . && error "'rmdir .' worked after recreating cwd"
5026         ln -s . baz || error "'ln -s .' failed after recreating cwd"
5027         cd .. || error "'cd ..' failed after recreating cwd"
5028 }
5029 run_test 48a "Access renamed working dir (should return errors)="
5030
5031 test_48b() { # bug 2399
5032         rm -rf $DIR/$tdir
5033         test_mkdir $DIR/$tdir
5034         cd $DIR/$tdir
5035         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
5036         touch foo && error "'touch foo' worked after removing cwd"
5037         mkdir foo && error "'mkdir foo' worked after removing cwd"
5038         touch .foo && error "'touch .foo' worked after removing cwd"
5039         mkdir .foo && error "'mkdir .foo' worked after removing cwd"
5040         ls . > /dev/null && error "'ls .' worked after removing cwd"
5041         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
5042         mkdir . && error "'mkdir .' worked after removing cwd"
5043         rmdir . && error "'rmdir .' worked after removing cwd"
5044         ln -s . foo && error "'ln -s .' worked after removing cwd"
5045         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
5046 }
5047 run_test 48b "Access removed working dir (should return errors)="
5048
5049 test_48c() { # bug 2350
5050         #lctl set_param debug=-1
5051         #set -vx
5052         rm -rf $DIR/$tdir
5053         test_mkdir -p $DIR/$tdir/dir
5054         cd $DIR/$tdir/dir
5055         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
5056         $TRACE touch foo && error "touch foo worked after removing cwd"
5057         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
5058         touch .foo && error "touch .foo worked after removing cwd"
5059         mkdir .foo && error "mkdir .foo worked after removing cwd"
5060         $TRACE ls . && error "'ls .' worked after removing cwd"
5061         $TRACE ls .. || error "'ls ..' failed after removing cwd"
5062         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
5063         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
5064         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
5065         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
5066 }
5067 run_test 48c "Access removed working subdir (should return errors)"
5068
5069 test_48d() { # bug 2350
5070         #lctl set_param debug=-1
5071         #set -vx
5072         rm -rf $DIR/$tdir
5073         test_mkdir -p $DIR/$tdir/dir
5074         cd $DIR/$tdir/dir
5075         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
5076         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
5077         $TRACE touch foo && error "'touch foo' worked after removing parent"
5078         $TRACE mkdir foo && error "mkdir foo worked after removing parent"
5079         touch .foo && error "'touch .foo' worked after removing parent"
5080         mkdir .foo && error "mkdir .foo worked after removing parent"
5081         $TRACE ls . && error "'ls .' worked after removing parent"
5082         $TRACE ls .. && error "'ls ..' worked after removing parent"
5083         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
5084         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
5085         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
5086         true
5087 }
5088 run_test 48d "Access removed parent subdir (should return errors)"
5089
5090 test_48e() { # bug 4134
5091         #lctl set_param debug=-1
5092         #set -vx
5093         rm -rf $DIR/$tdir
5094         test_mkdir -p $DIR/$tdir/dir
5095         cd $DIR/$tdir/dir
5096         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
5097         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
5098         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
5099         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
5100         # On a buggy kernel addition of "touch foo" after cd .. will
5101         # produce kernel oops in lookup_hash_it
5102         touch ../foo && error "'cd ..' worked after recreate parent"
5103         cd $DIR
5104         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
5105 }
5106 run_test 48e "Access to recreated parent subdir (should return errors)"
5107
5108 test_49() { # LU-1030
5109         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5110         remote_ost_nodsh && skip "remote OST with nodsh"
5111
5112         # get ost1 size - $FSNAME-OST0000
5113         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
5114                 awk '{ print $4 }')
5115         # write 800M at maximum
5116         [[ $ost1_size -lt 2 ]] && ost1_size=2
5117         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
5118
5119         $LFS setstripe -c 1 -i 0 $DIR/$tfile
5120         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
5121         local dd_pid=$!
5122
5123         # change max_pages_per_rpc while writing the file
5124         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
5125         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
5126         # loop until dd process exits
5127         while ps ax -opid | grep -wq $dd_pid; do
5128                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
5129                 sleep $((RANDOM % 5 + 1))
5130         done
5131         # restore original max_pages_per_rpc
5132         $LCTL set_param $osc1_mppc=$orig_mppc
5133         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
5134 }
5135 run_test 49 "Change max_pages_per_rpc won't break osc extent"
5136
5137 test_50() {
5138         # bug 1485
5139         test_mkdir $DIR/$tdir
5140         cd $DIR/$tdir
5141         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
5142 }
5143 run_test 50 "special situations: /proc symlinks  ==============="
5144
5145 test_51a() {    # was test_51
5146         # bug 1516 - create an empty entry right after ".." then split dir
5147         test_mkdir -c1 $DIR/$tdir
5148         touch $DIR/$tdir/foo
5149         $MCREATE $DIR/$tdir/bar
5150         rm $DIR/$tdir/foo
5151         createmany -m $DIR/$tdir/longfile 201
5152         FNUM=202
5153         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
5154                 $MCREATE $DIR/$tdir/longfile$FNUM
5155                 FNUM=$(($FNUM + 1))
5156                 echo -n "+"
5157         done
5158         echo
5159         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
5160 }
5161 run_test 51a "special situations: split htree with empty entry =="
5162
5163 cleanup_print_lfs_df () {
5164         trap 0
5165         $LFS df
5166         $LFS df -i
5167 }
5168
5169 test_51b() {
5170         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5171
5172         local dir=$DIR/$tdir
5173         local nrdirs=$((65536 + 100))
5174
5175         # cleanup the directory
5176         rm -fr $dir
5177
5178         test_mkdir -c1 $dir
5179
5180         $LFS df
5181         $LFS df -i
5182         local mdtidx=$(printf "%04x" $($LFS getstripe -m $dir))
5183         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
5184         [[ $numfree -lt $nrdirs ]] &&
5185                 skip "not enough free inodes ($numfree) on MDT$mdtidx"
5186
5187         # need to check free space for the directories as well
5188         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
5189         numfree=$(( blkfree / $(fs_inode_ksize) ))
5190         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)"
5191
5192         trap cleanup_print_lfs_df EXIT
5193
5194         # create files
5195         createmany -d $dir/d $nrdirs || {
5196                 unlinkmany $dir/d $nrdirs
5197                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
5198         }
5199
5200         # really created :
5201         nrdirs=$(ls -U $dir | wc -l)
5202
5203         # unlink all but 100 subdirectories, then check it still works
5204         local left=100
5205         local delete=$((nrdirs - left))
5206
5207         $LFS df
5208         $LFS df -i
5209
5210         # for ldiskfs the nlink count should be 1, but this is OSD specific
5211         # and so this is listed for informational purposes only
5212         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
5213         unlinkmany -d $dir/d $delete ||
5214                 error "unlink of first $delete subdirs failed"
5215
5216         echo "nlink between: $(stat -c %h $dir)"
5217         local found=$(ls -U $dir | wc -l)
5218         [ $found -ne $left ] &&
5219                 error "can't find subdirs: found only $found, expected $left"
5220
5221         unlinkmany -d $dir/d $delete $left ||
5222                 error "unlink of second $left subdirs failed"
5223         # regardless of whether the backing filesystem tracks nlink accurately
5224         # or not, the nlink count shouldn't be more than "." and ".." here
5225         local after=$(stat -c %h $dir)
5226         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
5227                 echo "nlink after: $after"
5228
5229         cleanup_print_lfs_df
5230 }
5231 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
5232
5233 test_51d() {
5234         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5235         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs"
5236
5237         test_mkdir $DIR/$tdir
5238         createmany -o $DIR/$tdir/t- 1000
5239         $LFS getstripe $DIR/$tdir > $TMP/$tfile
5240         for N in $(seq 0 $((OSTCOUNT - 1))); do
5241                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
5242                         END { printf("%0.0f", objs) }' $TMP/$tfile)
5243                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
5244                         '($1 == '$N') { objs += 1 } \
5245                         END { printf("%0.0f", objs) }')
5246                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
5247         done
5248         unlinkmany $DIR/$tdir/t- 1000
5249
5250         NLAST=0
5251         for N in $(seq 1 $((OSTCOUNT - 1))); do
5252                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
5253                         error "OST $N has less objects vs OST $NLAST" \
5254                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
5255                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
5256                         error "OST $N has less objects vs OST $NLAST" \
5257                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
5258
5259                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
5260                         error "OST $N has less #0 objects vs OST $NLAST" \
5261                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
5262                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
5263                         error "OST $N has less #0 objects vs OST $NLAST" \
5264                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
5265                 NLAST=$N
5266         done
5267         rm -f $TMP/$tfile
5268 }
5269 run_test 51d "check object distribution"
5270
5271 test_51e() {
5272         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5273                 skip_env "ldiskfs only test"
5274         fi
5275
5276         test_mkdir -c1 $DIR/$tdir
5277         test_mkdir -c1 $DIR/$tdir/d0
5278
5279         touch $DIR/$tdir/d0/foo
5280         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
5281                 error "file exceed 65000 nlink limit!"
5282         unlinkmany $DIR/$tdir/d0/f- 65001
5283         return 0
5284 }
5285 run_test 51e "check file nlink limit"
5286
5287 test_51f() {
5288         test_mkdir $DIR/$tdir
5289
5290         local max=100000
5291         local ulimit_old=$(ulimit -n)
5292         local spare=20 # number of spare fd's for scripts/libraries, etc.
5293         local mdt=$($LFS getstripe -m $DIR/$tdir)
5294         local numfree=$($LFS df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
5295
5296         echo "MDT$mdt numfree=$numfree, max=$max"
5297         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
5298         if [ $((numfree + spare)) -gt $ulimit_old ]; then
5299                 while ! ulimit -n $((numfree + spare)); do
5300                         numfree=$((numfree * 3 / 4))
5301                 done
5302                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
5303         else
5304                 echo "left ulimit at $ulimit_old"
5305         fi
5306
5307         createmany -o -k -t 120 $DIR/$tdir/f $numfree || {
5308                 unlinkmany $DIR/$tdir/f $numfree
5309                 error "create+open $numfree files in $DIR/$tdir failed"
5310         }
5311         ulimit -n $ulimit_old
5312
5313         # if createmany exits at 120s there will be fewer than $numfree files
5314         unlinkmany $DIR/$tdir/f $numfree || true
5315 }
5316 run_test 51f "check many open files limit"
5317
5318 test_52a() {
5319         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
5320         test_mkdir $DIR/$tdir
5321         touch $DIR/$tdir/foo
5322         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
5323         echo bar >> $DIR/$tdir/foo || error "append bar failed"
5324         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
5325         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
5326         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
5327                                         error "link worked"
5328         echo foo >> $DIR/$tdir/foo || error "append foo failed"
5329         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
5330         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
5331                                                      error "lsattr"
5332         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
5333         cp -r $DIR/$tdir $TMP/
5334         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
5335 }
5336 run_test 52a "append-only flag test (should return errors)"
5337
5338 test_52b() {
5339         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
5340         test_mkdir $DIR/$tdir
5341         touch $DIR/$tdir/foo
5342         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
5343         cat test > $DIR/$tdir/foo && error "cat test worked"
5344         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
5345         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
5346         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
5347                                         error "link worked"
5348         echo foo >> $DIR/$tdir/foo && error "echo worked"
5349         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
5350         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
5351         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
5352         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
5353                                                         error "lsattr"
5354         chattr -i $DIR/$tdir/foo || error "chattr failed"
5355
5356         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
5357 }
5358 run_test 52b "immutable flag test (should return errors) ======="
5359
5360 test_53() {
5361         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5362         remote_mds_nodsh && skip "remote MDS with nodsh"
5363         remote_ost_nodsh && skip "remote OST with nodsh"
5364
5365         local param
5366         local param_seq
5367         local ostname
5368         local mds_last
5369         local mds_last_seq
5370         local ost_last
5371         local ost_last_seq
5372         local ost_last_id
5373         local ostnum
5374         local node
5375         local found=false
5376         local support_last_seq=true
5377
5378         [[ $MDS1_VERSION -ge $(version_code 2.3.60) ]] ||
5379                 support_last_seq=false
5380
5381         # only test MDT0000
5382         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
5383         local value
5384         for value in $(do_facet $SINGLEMDS \
5385                        $LCTL get_param osp.$mdtosc.prealloc_last_id) ; do
5386                 param=$(echo ${value[0]} | cut -d "=" -f1)
5387                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
5388
5389                 if $support_last_seq; then
5390                         param_seq=$(echo $param |
5391                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
5392                         mds_last_seq=$(do_facet $SINGLEMDS \
5393                                        $LCTL get_param -n $param_seq)
5394                 fi
5395                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
5396
5397                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
5398                 node=$(facet_active_host ost$((ostnum+1)))
5399                 param="obdfilter.$ostname.last_id"
5400                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
5401                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
5402                         ost_last_id=$ost_last
5403
5404                         if $support_last_seq; then
5405                                 ost_last_id=$(echo $ost_last |
5406                                               awk -F':' '{print $2}' |
5407                                               sed -e "s/^0x//g")
5408                                 ost_last_seq=$(echo $ost_last |
5409                                                awk -F':' '{print $1}')
5410                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
5411                         fi
5412
5413                         if [[ $ost_last_id != $mds_last ]]; then
5414                                 error "$ost_last_id != $mds_last"
5415                         else
5416                                 found=true
5417                                 break
5418                         fi
5419                 done
5420         done
5421         $found || error "can not match last_seq/last_id for $mdtosc"
5422         return 0
5423 }
5424 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
5425
5426 test_54a() {
5427         perl -MSocket -e ';' || skip "no Socket perl module installed"
5428
5429         $SOCKETSERVER $DIR/socket ||
5430                 error "$SOCKETSERVER $DIR/socket failed: $?"
5431         $SOCKETCLIENT $DIR/socket ||
5432                 error "$SOCKETCLIENT $DIR/socket failed: $?"
5433         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
5434 }
5435 run_test 54a "unix domain socket test =========================="
5436
5437 test_54b() {
5438         f="$DIR/f54b"
5439         mknod $f c 1 3
5440         chmod 0666 $f
5441         dd if=/dev/zero of=$f bs=$PAGE_SIZE count=1
5442 }
5443 run_test 54b "char device works in lustre ======================"
5444
5445 find_loop_dev() {
5446         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
5447         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
5448         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
5449
5450         for i in $(seq 3 7); do
5451                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
5452                 LOOPDEV=$LOOPBASE$i
5453                 LOOPNUM=$i
5454                 break
5455         done
5456 }
5457
5458 cleanup_54c() {
5459         local rc=0
5460         loopdev="$DIR/loop54c"
5461
5462         trap 0
5463         $UMOUNT $DIR/$tdir || rc=$?
5464         losetup -d $loopdev || true
5465         losetup -d $LOOPDEV || true
5466         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
5467         return $rc
5468 }
5469
5470 test_54c() {
5471         [ $PARALLEL == "yes" ] && skip "skip parallel run"
5472
5473         loopdev="$DIR/loop54c"
5474
5475         find_loop_dev
5476         [ -z "$LOOPNUM" ] && skip_env "couldn't find empty loop device"
5477         trap cleanup_54c EXIT
5478         mknod $loopdev b 7 $LOOPNUM
5479         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
5480         dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE seek=1024 count=1 > /dev/null
5481         losetup $loopdev $DIR/$tfile ||
5482                 error "can't set up $loopdev for $DIR/$tfile"
5483         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
5484         test_mkdir $DIR/$tdir
5485         mount -t ext2 $loopdev $DIR/$tdir ||
5486                 error "error mounting $loopdev on $DIR/$tdir"
5487         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$PAGE_SIZE count=30 ||
5488                 error "dd write"
5489         df $DIR/$tdir
5490         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$PAGE_SIZE count=30 ||
5491                 error "dd read"
5492         cleanup_54c
5493 }
5494 run_test 54c "block device works in lustre ====================="
5495
5496 test_54d() {
5497         f="$DIR/f54d"
5498         string="aaaaaa"
5499         mknod $f p
5500         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
5501 }
5502 run_test 54d "fifo device works in lustre ======================"
5503
5504 test_54e() {
5505         f="$DIR/f54e"
5506         string="aaaaaa"
5507         cp -aL /dev/console $f
5508         echo $string > $f || error "echo $string to $f failed"
5509 }
5510 run_test 54e "console/tty device works in lustre ======================"
5511
5512 test_56a() {
5513         local numfiles=3
5514         local dir=$DIR/$tdir
5515
5516         rm -rf $dir
5517         test_mkdir -p $dir/dir
5518         for i in $(seq $numfiles); do
5519                 touch $dir/file$i
5520                 touch $dir/dir/file$i
5521         done
5522
5523         local numcomp=$($LFS getstripe --component-count $dir)
5524
5525         [[ $numcomp == 0 ]] && numcomp=1
5526
5527         # test lfs getstripe with --recursive
5528         local filenum=$($LFS getstripe -r $dir | egrep -c "obdidx|l_ost_idx")
5529
5530         [[ $filenum -eq $((numfiles * 2)) ]] ||
5531                 error "$LFS getstripe -r: found $filenum != $((numfiles * 2))"
5532         filenum=$($LFS getstripe $dir | egrep -c "obdidx|l_ost_idx")
5533         [[ $filenum -eq $numfiles ]] ||
5534                 error "$LFS getstripe $dir: found $filenum, not $numfiles"
5535         echo "$LFS getstripe showed obdidx or l_ost_idx"
5536
5537         # test lfs getstripe with file instead of dir
5538         filenum=$($LFS getstripe $dir/file1 | egrep -c "obdidx|l_ost_idx")
5539         [[ $filenum -eq 1 ]] ||
5540                 error "$LFS getstripe $dir/file1: found $filenum, not 1"
5541         echo "$LFS getstripe file1 passed"
5542
5543         #test lfs getstripe with --verbose
5544         filenum=$($LFS getstripe --verbose $dir | grep -c lmm_magic)
5545         [[ $filenum -eq $((numfiles * numcomp)) ]] ||
5546                 error "$LFS getstripe --verbose $dir: "\
5547                       "got $filenum want $((numfiles * numcomp)) lmm_magic"
5548         [[ $($LFS getstripe $dir | grep -c lmm_magic) -eq 0 ]] ||
5549                 error "$LFS getstripe $dir: showed lmm_magic"
5550
5551         #test lfs getstripe with -v prints lmm_fid
5552         filenum=$($LFS getstripe -v $dir | grep -c lmm_fid)
5553         [[ $filenum -eq $((numfiles * numcomp)) ]] ||
5554                 error "$LFS getstripe -v $dir: "\
5555                       "got $filenum want $((numfiles * numcomp)) lmm_fid"
5556         [[ $($LFS getstripe $dir | grep -c lmm_fid) -eq 0 ]] ||
5557                 error "$LFS getstripe $dir: showed lmm_fid by default"
5558         echo "$LFS getstripe --verbose passed"
5559
5560         #check for FID information
5561         local fid1=$($LFS getstripe --fid $dir/file1)
5562         local fid2=$($LFS getstripe --verbose $dir/file1 |
5563                      awk '/lmm_fid: / { print $2; exit; }')
5564         local fid3=$($LFS path2fid $dir/file1)
5565
5566         [ "$fid1" != "$fid2" ] &&
5567                 error "getstripe --fid '$fid1' != getstripe --verbose '$fid2'"
5568         [ "$fid1" != "$fid3" ] &&
5569                 error "getstripe --fid '$fid1' != lfs path2fid '$fid3'"
5570         echo "$LFS getstripe --fid passed"
5571
5572         #test lfs getstripe with --obd
5573         $LFS getstripe --obd wrong_uuid $dir 2>&1 | grep -q "unknown obduuid" ||
5574                 error "$LFS getstripe --obd wrong_uuid: should return error"
5575
5576         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
5577
5578         local ostidx=1
5579         local obduuid=$(ostuuid_from_index $ostidx)
5580         local found=$($LFS getstripe -r --obd $obduuid $dir |
5581                 grep 'lmm_stripe_offset:' | grep -c " $ostidx\$")
5582
5583         filenum=$($LFS getstripe -ir $dir | grep -c "^$ostidx\$")
5584         [[ $($LFS getstripe -id $dir) -ne $ostidx ]] ||
5585                 ((filenum--))
5586         [[ $($LFS getstripe -id $dir/dir) -ne $ostidx ]] ||
5587                 ((filenum--))
5588
5589         [[ $found -eq $filenum ]] ||
5590                 error "$LFS getstripe --obd: found $found expect $filenum"
5591         [[ $($LFS getstripe -r -v --obd $obduuid $dir |
5592                 sed '/^[         ]*'${ostidx}'[  ]/d' |
5593                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
5594                 error "$LFS getstripe --obd: should not show file on other obd"
5595         echo "$LFS getstripe --obd passed"
5596 }
5597 run_test 56a "check $LFS getstripe"
5598
5599 test_56b() {
5600         local dir=$DIR/$tdir
5601         local numdirs=3
5602
5603         test_mkdir $dir
5604         for i in $(seq $numdirs); do
5605                 test_mkdir $dir/dir$i
5606         done
5607
5608         # test lfs getdirstripe default mode is non-recursion, which is
5609         # different from lfs getstripe
5610         local dircnt=$($LFS getdirstripe $dir | grep -c lmv_stripe_count)
5611
5612         [[ $dircnt -eq 1 ]] ||
5613                 error "$LFS getdirstripe: found $dircnt, not 1"
5614         dircnt=$($LFS getdirstripe --recursive $dir |
5615                 grep -c lmv_stripe_count)
5616         [[ $dircnt -eq $((numdirs + 1)) ]] ||
5617                 error "$LFS getdirstripe -r: $dircnt, != $((numdirs + 1))"
5618 }
5619 run_test 56b "check $LFS getdirstripe"
5620
5621 test_56c() {
5622         remote_ost_nodsh && skip "remote OST with nodsh"
5623
5624         local ost_idx=0
5625         local ost_name=$(ostname_from_index $ost_idx)
5626         local old_status=$(ost_dev_status $ost_idx)
5627
5628         [[ -z "$old_status" ]] ||
5629                 skip_env "OST $ost_name is in $old_status status"
5630
5631         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
5632         [[ $OST1_VERSION -ge $(version_code 2.12.55) ]] && do_facet ost1 \
5633                 $LCTL set_param -n obdfilter.$ost_name.no_precreate=1
5634         sleep_maxage
5635
5636         local new_status=$(ost_dev_status $ost_idx)
5637
5638         [[ "$new_status" =~ "D" ]] ||
5639                 error "$ost_name status is '$new_status', missing 'D'"
5640         if [[ $OST1_VERSION -ge $(version_code 2.12.55) ]]; then
5641                 [[ "$new_status" =~ "N" ]] ||
5642                         error "$ost_name status is '$new_status', missing 'N'"
5643         fi
5644
5645         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
5646         [[ $OST1_VERSION -ge $(version_code 2.12.55) ]] && do_facet ost1 \
5647                 $LCTL set_param -n obdfilter.$ost_name.no_precreate=0
5648         sleep_maxage
5649
5650         new_status=$(ost_dev_status $ost_idx)
5651         [[ ! "$new_status" =~ "D" && ! "$new_status" =~ "N" ]] ||
5652                 error "$ost_name status is '$new_status', has 'D' and/or 'N'"
5653 }
5654 run_test 56c "check 'lfs df' showing device status"
5655
5656 NUMFILES=3
5657 NUMDIRS=3
5658 setup_56() {
5659         local local_tdir="$1"
5660         local local_numfiles="$2"
5661         local local_numdirs="$3"
5662         local dir_params="$4"
5663         local dir_stripe_params="$5"
5664
5665         if [ ! -d "$local_tdir" ] ; then
5666                 test_mkdir -p $dir_stripe_params $local_tdir
5667                 [ "$dir_params" ] && $LFS setstripe $dir_params $local_tdir
5668                 for i in $(seq $local_numfiles) ; do
5669                         touch $local_tdir/file$i
5670                 done
5671                 for i in $(seq $local_numdirs) ; do
5672                         test_mkdir $dir_stripe_params $local_tdir/dir$i
5673                         for j in $(seq $local_numfiles) ; do
5674                                 touch $local_tdir/dir$i/file$j
5675                         done
5676                 done
5677         fi
5678 }
5679
5680 setup_56_special() {
5681         local local_tdir=$1
5682         local local_numfiles=$2
5683         local local_numdirs=$3
5684
5685         setup_56 $local_tdir $local_numfiles $local_numdirs
5686
5687         if [ ! -e "$local_tdir/loop${local_numfiles}b" ] ; then
5688                 for i in $(seq $local_numfiles) ; do
5689                         mknod $local_tdir/loop${i}b b 7 $i
5690                         mknod $local_tdir/null${i}c c 1 3
5691                         ln -s $local_tdir/file1 $local_tdir/link${i}
5692                 done
5693                 for i in $(seq $local_numdirs) ; do
5694                         mknod $local_tdir/dir$i/loop${i}b b 7 $i
5695                         mknod $local_tdir/dir$i/null${i}c c 1 3
5696                         ln -s $local_tdir/dir$i/file1 $local_tdir/dir$i/link${i}
5697                 done
5698         fi
5699 }
5700
5701 test_56g() {
5702         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5703         local expected=$(($NUMDIRS + 2))
5704
5705         setup_56 $dir $NUMFILES $NUMDIRS
5706
5707         # test lfs find with -name
5708         for i in $(seq $NUMFILES) ; do
5709                 local nums=$($LFS find -name "*$i" $dir | wc -l)
5710
5711                 [ $nums -eq $expected ] ||
5712                         error "lfs find -name '*$i' $dir wrong: "\
5713                               "found $nums, expected $expected"
5714         done
5715 }
5716 run_test 56g "check lfs find -name"
5717
5718 test_56h() {
5719         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5720         local expected=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
5721
5722         setup_56 $dir $NUMFILES $NUMDIRS
5723
5724         # test lfs find with ! -name
5725         for i in $(seq $NUMFILES) ; do
5726                 local nums=$($LFS find ! -name "*$i" $dir | wc -l)
5727
5728                 [ $nums -eq $expected ] ||
5729                         error "lfs find ! -name '*$i' $dir wrong: "\
5730                               "found $nums, expected $expected"
5731         done
5732 }
5733 run_test 56h "check lfs find ! -name"
5734
5735 test_56i() {
5736         local dir=$DIR/$tdir
5737
5738         test_mkdir $dir
5739
5740         local cmd="$LFS find -ost $(ostuuid_from_index 0 $dir) $dir"
5741         local out=$($cmd)
5742
5743         [ -z "$out" ] || error "'$cmd' returned directory '$out'"
5744 }
5745 run_test 56i "check 'lfs find -ost UUID' skips directories"
5746
5747 test_56j() {
5748         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5749
5750         setup_56_special $dir $NUMFILES $NUMDIRS
5751
5752         local expected=$((NUMDIRS + 1))
5753         local cmd="$LFS find -type d $dir"
5754         local nums=$($cmd | wc -l)
5755
5756         [ $nums -eq $expected ] ||
5757                 error "'$cmd' wrong: found $nums, expected $expected"
5758 }
5759 run_test 56j "check lfs find -type d"
5760
5761 test_56k() {
5762         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5763
5764         setup_56_special $dir $NUMFILES $NUMDIRS
5765
5766         local expected=$(((NUMDIRS + 1) * NUMFILES))
5767         local cmd="$LFS find -type f $dir"
5768         local nums=$($cmd | wc -l)
5769
5770         [ $nums -eq $expected ] ||
5771                 error "'$cmd' wrong: found $nums, expected $expected"
5772 }
5773 run_test 56k "check lfs find -type f"
5774
5775 test_56l() {
5776         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5777
5778         setup_56_special $dir $NUMFILES $NUMDIRS
5779
5780         local expected=$((NUMDIRS + NUMFILES))
5781         local cmd="$LFS find -type b $dir"
5782         local nums=$($cmd | wc -l)
5783
5784         [ $nums -eq $expected ] ||
5785                 error "'$cmd' wrong: found $nums, expected $expected"
5786 }
5787 run_test 56l "check lfs find -type b"
5788
5789 test_56m() {
5790         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5791
5792         setup_56_special $dir $NUMFILES $NUMDIRS
5793
5794         local expected=$((NUMDIRS + NUMFILES))
5795         local cmd="$LFS find -type c $dir"
5796         local nums=$($cmd | wc -l)
5797         [ $nums -eq $expected ] ||
5798                 error "'$cmd' wrong: found $nums, expected $expected"
5799 }
5800 run_test 56m "check lfs find -type c"
5801
5802 test_56n() {
5803         local dir=$DIR/d$(basetest $testnum)g.$TESTSUITE
5804         setup_56_special $dir $NUMFILES $NUMDIRS
5805
5806         local expected=$((NUMDIRS + NUMFILES))
5807         local cmd="$LFS find -type l $dir"
5808         local nums=$($cmd | wc -l)
5809
5810         [ $nums -eq $expected ] ||
5811                 error "'$cmd' wrong: found $nums, expected $expected"
5812 }
5813 run_test 56n "check lfs find -type l"
5814
5815 test_56o() {
5816         local dir=$DIR/$tdir
5817
5818         setup_56 $dir $NUMFILES $NUMDIRS
5819         utime $dir/file1 > /dev/null || error "utime (1)"
5820         utime $dir/file2 > /dev/null || error "utime (2)"
5821         utime $dir/dir1 > /dev/null || error "utime (3)"
5822         utime $dir/dir2 > /dev/null || error "utime (4)"
5823         utime $dir/dir1/file1 > /dev/null || error "utime (5)"
5824         dd if=/dev/zero count=1 >> $dir/dir1/file1 && sync
5825
5826         local expected=4
5827         local nums=$($LFS find -mtime +0 $dir | wc -l)
5828
5829         [ $nums -eq $expected ] ||
5830                 error "lfs find -mtime +0 $dir: found $nums expect $expected"
5831
5832         expected=12
5833         cmd="$LFS find -mtime 0 $dir"
5834         nums=$($cmd | wc -l)
5835         [ $nums -eq $expected ] ||
5836                 error "'$cmd' wrong: found $nums, expected $expected"
5837 }
5838 run_test 56o "check lfs find -mtime for old files"
5839
5840 test_56ob() {
5841         local dir=$DIR/$tdir
5842         local expected=1
5843         local count=0
5844
5845         # just to make sure there is something that won't be found
5846         test_mkdir $dir
5847         touch $dir/$tfile.now
5848
5849         for age in year week day hour min; do
5850                 count=$((count + 1))
5851
5852                 touch $dir/$tfile-a.$age $dir/$tfile-m.$age
5853                 touch --date="$count $age ago" -a $dir/$tfile-a.$age
5854                 touch --date="$count $age ago" -m $dir/$tfile-m.$age
5855
5856                 local cmd="$LFS find $dir -mtime $count${age:0:1}"
5857                 local nums=$($cmd | wc -l)
5858                 [ $nums -eq $expected ] ||
5859                         error "'$cmd' wrong: found $nums, expected $expected"
5860
5861                 cmd="$LFS find $dir -atime $count${age:0:1}"
5862                 nums=$($cmd | wc -l)
5863                 [ $nums -eq $expected ] ||
5864                         error "'$cmd' wrong: found $nums, expected $expected"
5865         done
5866
5867         sleep 2
5868         cmd="$LFS find $dir -ctime +1s -type f"
5869         nums=$($cmd | wc -l)
5870         (( $nums == $count * 2 + 1)) ||
5871                 error "'$cmd' wrong: found $nums, expected $((expected*2+1))"
5872 }
5873 run_test 56ob "check lfs find -atime -mtime -ctime with units"
5874
5875 test_newerXY_base() {
5876         local x=$1
5877         local y=$2
5878         local dir=$DIR/$tdir
5879         local ref
5880         local negref
5881
5882         if [ $y == "t" ]; then
5883                 ref="\"$(date +"%Y-%m-%d %H:%M:%S")\""
5884         else
5885                 ref=$DIR/$tfile.newer
5886                 touch $ref || error "touch $ref failed"
5887         fi
5888         sleep 2
5889         setup_56 $dir $NUMFILES $NUMDIRS "-i0 -c1" "-i0 -c1"
5890         sleep 2
5891         if [ $y == "t" ]; then
5892                 negref="\"$(date +"%Y-%m-%d %H:%M:%S")\""
5893         else
5894                 negref=$DIR/$tfile.newerneg
5895                 touch $negref || error "touch $negref failed"
5896         fi
5897
5898         local cmd="$LFS find $dir -newer$x$y $ref"
5899         local nums=$(eval $cmd | wc -l)
5900         local expected=$(((NUMFILES + 2) * NUMDIRS + 1))
5901
5902         [ $nums -eq $expected ] ||
5903                 error "'$cmd' wrong: found $nums, expected $expected"
5904
5905         cmd="$LFS find $dir ! -newer$x$y $negref"
5906         nums=$(eval $cmd | wc -l)
5907         [ $nums -eq $expected ] ||
5908                 error "'$cmd' wrong: found $nums, expected $expected"
5909
5910         cmd="$LFS find $dir -newer$x$y $ref ! -newer$x$y $negref"
5911         nums=$(eval $cmd | wc -l)
5912         [ $nums -eq $expected ] ||
5913                 error "'$cmd' wrong: found $nums, expected $expected"
5914
5915         rm -rf $DIR/*
5916 }
5917
5918 test_56oc() {
5919         test_newerXY_base "a" "a"
5920         test_newerXY_base "a" "m"
5921         test_newerXY_base "a" "c"
5922         test_newerXY_base "m" "a"
5923         test_newerXY_base "m" "m"
5924         test_newerXY_base "m" "c"
5925         test_newerXY_base "c" "a"
5926         test_newerXY_base "c" "m"
5927         test_newerXY_base "c" "c"
5928         test_newerXY_base "a" "t"
5929         test_newerXY_base "m" "t"
5930         test_newerXY_base "c" "t"
5931 }
5932 run_test 56oc "check lfs find -newerXY work"
5933
5934 test_56p() {
5935         [ $RUNAS_ID -eq $UID ] &&
5936                 skip_env "RUNAS_ID = UID = $UID -- skipping"
5937
5938         local dir=$DIR/$tdir
5939
5940         setup_56 $dir $NUMFILES $NUMDIRS
5941         chown $RUNAS_ID $dir/file* || error "chown $DIR/${tdir}g/file$i failed"
5942
5943         local expected=$NUMFILES
5944         local cmd="$LFS find -uid $RUNAS_ID $dir"
5945         local nums=$($cmd | wc -l)
5946
5947         [ $nums -eq $expected ] ||
5948                 error "'$cmd' wrong: found $nums, expected $expected"
5949
5950         expected=$(((NUMFILES + 1) * NUMDIRS + 1))
5951         cmd="$LFS find ! -uid $RUNAS_ID $dir"
5952         nums=$($cmd | wc -l)
5953         [ $nums -eq $expected ] ||
5954                 error "'$cmd' wrong: found $nums, expected $expected"
5955 }
5956 run_test 56p "check lfs find -uid and ! -uid"
5957
5958 test_56q() {
5959         [ $RUNAS_ID -eq $UID ] &&
5960                 skip_env "RUNAS_ID = UID = $UID -- skipping"
5961
5962         local dir=$DIR/$tdir
5963
5964         setup_56 $dir $NUMFILES $NUMDIRS
5965         chgrp $RUNAS_GID $dir/file* || error "chown $dir/file$i failed"
5966
5967         local expected=$NUMFILES
5968         local cmd="$LFS find -gid $RUNAS_GID $dir"
5969         local nums=$($cmd | wc -l)
5970
5971         [ $nums -eq $expected ] ||
5972                 error "'$cmd' wrong: found $nums, expected $expected"
5973
5974         expected=$(( ($NUMFILES+1) * $NUMDIRS + 1))
5975         cmd="$LFS find ! -gid $RUNAS_GID $dir"
5976         nums=$($cmd | wc -l)
5977         [ $nums -eq $expected ] ||
5978                 error "'$cmd' wrong: found $nums, expected $expected"
5979 }
5980 run_test 56q "check lfs find -gid and ! -gid"
5981
5982 test_56r() {
5983         local dir=$DIR/$tdir
5984
5985         setup_56 $dir $NUMFILES $NUMDIRS
5986
5987         local expected=12
5988         local cmd="$LFS find -size 0 -type f -lazy $dir"
5989         local nums=$($cmd | wc -l)
5990
5991         [ $nums -eq $expected ] ||
5992                 error "'$cmd' wrong: found $nums, expected $expected"
5993         cmd="$LFS find -size 0 -type f $dir"
5994         nums=$($cmd | wc -l)
5995         [ $nums -eq $expected ] ||
5996                 error "'$cmd' wrong: found $nums, expected $expected"
5997
5998         expected=0
5999         cmd="$LFS find ! -size 0 -type f -lazy $dir"
6000         nums=$($cmd | wc -l)
6001         [ $nums -eq $expected ] ||
6002                 error "'$cmd' wrong: found $nums, expected $expected"
6003         cmd="$LFS find ! -size 0 -type f $dir"
6004         nums=$($cmd | wc -l)
6005         [ $nums -eq $expected ] ||
6006                 error "'$cmd' wrong: found $nums, expected $expected"
6007
6008         echo "test" > $dir/$tfile
6009         echo "test2" > $dir/$tfile.2 && sync
6010         expected=1
6011         cmd="$LFS find -size 5 -type f -lazy $dir"
6012         nums=$($cmd | wc -l)
6013         [ $nums -eq $expected ] ||
6014                 error "'$cmd' wrong: found $nums, expected $expected"
6015         cmd="$LFS find -size 5 -type f $dir"
6016         nums=$($cmd | wc -l)
6017         [ $nums -eq $expected ] ||
6018                 error "'$cmd' wrong: found $nums, expected $expected"
6019
6020         expected=1
6021         cmd="$LFS find -size +5 -type f -lazy $dir"
6022         nums=$($cmd | wc -l)
6023         [ $nums -eq $expected ] ||
6024                 error "'$cmd' wrong: found $nums, expected $expected"
6025         cmd="$LFS find -size +5 -type f $dir"
6026         nums=$($cmd | wc -l)
6027         [ $nums -eq $expected ] ||
6028                 error "'$cmd' wrong: found $nums, expected $expected"
6029
6030         expected=2
6031         cmd="$LFS find -size +0 -type f -lazy $dir"
6032         nums=$($cmd | wc -l)
6033         [ $nums -eq $expected ] ||
6034                 error "'$cmd' wrong: found $nums, expected $expected"
6035         cmd="$LFS find -size +0 -type f $dir"
6036         nums=$($cmd | wc -l)
6037         [ $nums -eq $expected ] ||
6038                 error "'$cmd' wrong: found $nums, expected $expected"
6039
6040         expected=2
6041         cmd="$LFS find ! -size -5 -type f -lazy $dir"
6042         nums=$($cmd | wc -l)
6043         [ $nums -eq $expected ] ||
6044                 error "'$cmd' wrong: found $nums, expected $expected"
6045         cmd="$LFS find ! -size -5 -type f $dir"
6046         nums=$($cmd | wc -l)
6047         [ $nums -eq $expected ] ||
6048                 error "'$cmd' wrong: found $nums, expected $expected"
6049
6050         expected=12
6051         cmd="$LFS find -size -5 -type f -lazy $dir"
6052         nums=$($cmd | wc -l)
6053         [ $nums -eq $expected ] ||
6054                 error "'$cmd' wrong: found $nums, expected $expected"
6055         cmd="$LFS find -size -5 -type f $dir"
6056         nums=$($cmd | wc -l)
6057         [ $nums -eq $expected ] ||
6058                 error "'$cmd' wrong: found $nums, expected $expected"
6059 }
6060 run_test 56r "check lfs find -size works"
6061
6062 test_56ra() {
6063         [[ $MDS1_VERSION -gt $(version_code 2.12.58) ]] ||
6064                 skip "MDS < 2.12.58 doesn't return LSOM data"
6065         local dir=$DIR/$tdir
6066
6067         [[ $OSC == "mdc" ]] && skip "DoM files" && return
6068
6069         setup_56 $dir $NUMFILES $NUMDIRS "-c 1"
6070
6071         cancel_lru_locks $OSC
6072
6073         local rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6074         local expected=12
6075         local cmd="$LFS find -size 0 -type f -lazy $dir"
6076         local nums=$($cmd | wc -l)
6077
6078         [ $nums -eq $expected ] ||
6079                 error "'$cmd' wrong: found $nums, expected $expected"
6080
6081         local rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6082         [ $rpcs_before -eq $rpcs_after ] ||
6083                 error "'$cmd' should not send glimpse RPCs to OST"
6084         cmd="$LFS find -size 0 -type f $dir"
6085         nums=$($cmd | wc -l)
6086         [ $nums -eq $expected ] ||
6087                 error "'$cmd' wrong: found $nums, expected $expected"
6088         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6089         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6090         $LCTL get_param osc.*.stats
6091         [ $rpcs_after -eq $((rpcs_before + 12)) ] ||
6092                 error "'$cmd' should send 12 glimpse RPCs to OST"
6093
6094         cancel_lru_locks $OSC
6095         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6096         expected=0
6097         cmd="$LFS find ! -size 0 -type f -lazy $dir"
6098         nums=$($cmd | wc -l)
6099         [ $nums -eq $expected ] ||
6100                 error "'$cmd' wrong: found $nums, expected $expected"
6101         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6102         $LCTL get_param mdc.*.stats
6103         [ $rpcs_before -eq $rpcs_after ] ||
6104                 error "'$cmd' should not send glimpse RPCs to OST"
6105         cmd="$LFS find ! -size 0 -type f $dir"
6106         nums=$($cmd | wc -l)
6107         [ $nums -eq $expected ] ||
6108                 error "'$cmd' wrong: found $nums, expected $expected"
6109         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6110         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6111         [ $rpcs_after -eq $((rpcs_before + 12)) ] ||
6112                 error "'$cmd' should send 12 glimpse RPCs to OST"
6113
6114         echo "test" > $dir/$tfile
6115         echo "test2" > $dir/$tfile.2 && sync
6116         cancel_lru_locks $OSC
6117         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6118         expected=1
6119         cmd="$LFS find -size 5 -type f -lazy $dir"
6120         nums=$($cmd | wc -l)
6121         [ $nums -eq $expected ] ||
6122                 error "'$cmd' wrong: found $nums, expected $expected"
6123         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6124         [ $rpcs_before -eq $rpcs_after ] ||
6125                 error "'$cmd' should not send glimpse RPCs to OST"
6126         cmd="$LFS find -size 5 -type f $dir"
6127         nums=$($cmd | wc -l)
6128         [ $nums -eq $expected ] ||
6129                 error "'$cmd' wrong: found $nums, expected $expected"
6130         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6131         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6132         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6133                 error "'$cmd' should send 14 glimpse RPCs to OST"
6134
6135         cancel_lru_locks $OSC
6136         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6137         expected=1
6138         cmd="$LFS find -size +5 -type f -lazy $dir"
6139         nums=$($cmd | wc -l)
6140         [ $nums -eq $expected ] ||
6141                 error "'$cmd' wrong: found $nums, expected $expected"
6142         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6143         [ $rpcs_before -eq $rpcs_after ] ||
6144                 error "'$cmd' should not send glimpse RPCs to OST"
6145         cmd="$LFS find -size +5 -type f $dir"
6146         nums=$($cmd | wc -l)
6147         [ $nums -eq $expected ] ||
6148                 error "'$cmd' wrong: found $nums, expected $expected"
6149         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6150         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6151         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6152                 error "'$cmd' should send 14 glimpse RPCs to OST"
6153
6154         cancel_lru_locks $OSC
6155         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6156         expected=2
6157         cmd="$LFS find -size +0 -type f -lazy $dir"
6158         nums=$($cmd | wc -l)
6159         [ $nums -eq $expected ] ||
6160                 error "'$cmd' wrong: found $nums, expected $expected"
6161         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6162         [ $rpcs_before -eq $rpcs_after ] ||
6163                 error "'$cmd' should not send glimpse RPCs to OST"
6164         cmd="$LFS find -size +0 -type f $dir"
6165         nums=$($cmd | wc -l)
6166         [ $nums -eq $expected ] ||
6167                 error "'$cmd' wrong: found $nums, expected $expected"
6168         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6169         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6170         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6171                 error "'$cmd' should send 14 glimpse RPCs to OST"
6172
6173         cancel_lru_locks $OSC
6174         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6175         expected=2
6176         cmd="$LFS find ! -size -5 -type f -lazy $dir"
6177         nums=$($cmd | wc -l)
6178         [ $nums -eq $expected ] ||
6179                 error "'$cmd' wrong: found $nums, expected $expected"
6180         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6181         [ $rpcs_before -eq $rpcs_after ] ||
6182                 error "'$cmd' should not send glimpse RPCs to OST"
6183         cmd="$LFS find ! -size -5 -type f $dir"
6184         nums=$($cmd | wc -l)
6185         [ $nums -eq $expected ] ||
6186                 error "'$cmd' wrong: found $nums, expected $expected"
6187         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6188         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6189         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6190                 error "'$cmd' should send 14 glimpse RPCs to OST"
6191
6192         cancel_lru_locks $OSC
6193         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6194         expected=12
6195         cmd="$LFS find -size -5 -type f -lazy $dir"
6196         nums=$($cmd | wc -l)
6197         [ $nums -eq $expected ] ||
6198                 error "'$cmd' wrong: found $nums, expected $expected"
6199         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6200         [ $rpcs_before -eq $rpcs_after ] ||
6201                 error "'$cmd' should not send glimpse RPCs to OST"
6202         cmd="$LFS find -size -5 -type f $dir"
6203         nums=$($cmd | wc -l)
6204         [ $nums -eq $expected ] ||
6205                 error "'$cmd' wrong: found $nums, expected $expected"
6206         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
6207         echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
6208         [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
6209                 error "'$cmd' should send 14 glimpse RPCs to OST"
6210 }
6211 run_test 56ra "check lfs find -size -lazy works for data on OSTs"
6212
6213 test_56rb() {
6214         local dir=$DIR/$tdir
6215         local tmp=$TMP/$tfile.log
6216         local mdt_idx;
6217
6218         test_mkdir -p $dir || error "failed to mkdir $dir"
6219         $LFS setstripe -c 1 -i 0 $dir/$tfile ||
6220                 error "failed to setstripe $dir/$tfile"
6221         dd if=/dev/zero of=$dir/$tfile bs=1M count=1
6222
6223         stack_trap "rm -f $tmp" EXIT
6224         $LFS find --size +100K --ost 0 $dir 2>&1 | tee $tmp
6225         [ -z "$(cat $tmp | grep "obd_uuid: ")" ] ||
6226                 error "failed to find --size +100K --ost 0 $dir"
6227         $LFS find --size +100K --mdt $mdt_idx $dir 2>&1 | tee $tmp
6228         [ -z "$(cat $tmp | grep "obd_uuid: ")" ] ||
6229                 error "failed to find --size +100K --mdt $mdt_idx $dir"
6230 }
6231 run_test 56rb "check lfs find --size --ost/--mdt works"
6232
6233 test_56s() { # LU-611 #LU-9369
6234         [[ $OSTCOUNT -lt 2 ]] && skip_env "need at least 2 OSTs"
6235
6236         local dir=$DIR/$tdir
6237         local onestripe=$(((NUMDIRS + 1) * NUMFILES))
6238
6239         setup_56 $dir $NUMFILES $NUMDIRS "-c 1"
6240         for i in $(seq $NUMDIRS); do
6241                 $LFS setstripe -c $((OSTCOUNT + 1)) $dir/dir$i/$tfile
6242         done
6243
6244         local expected=$NUMDIRS
6245         local cmd="$LFS find -c $OSTCOUNT $dir"
6246         local nums=$($cmd | wc -l)
6247
6248         [ $nums -eq $expected ] || {
6249                 $LFS getstripe -R $dir
6250                 error "'$cmd' wrong: found $nums, expected $expected"
6251         }
6252
6253         expected=$((NUMDIRS + onestripe))
6254         cmd="$LFS find -stripe-count +0 -type f $dir"
6255         nums=$($cmd | wc -l)
6256         [ $nums -eq $expected ] || {
6257                 $LFS getstripe -R $dir
6258                 error "'$cmd' wrong: found $nums, expected $expected"
6259         }
6260
6261         expected=$onestripe
6262         cmd="$LFS find -stripe-count 1 -type f $dir"
6263         nums=$($cmd | wc -l)
6264         [ $nums -eq $expected ] || {
6265                 $LFS getstripe -R $dir
6266                 error "'$cmd' wrong: found $nums, expected $expected"
6267         }
6268
6269         cmd="$LFS find -stripe-count -2 -type f $dir"
6270         nums=$($cmd | wc -l)
6271         [ $nums -eq $expected ] || {
6272                 $LFS getstripe -R $dir
6273                 error "'$cmd' wrong: found $nums, expected $expected"
6274         }
6275
6276         expected=0
6277         cmd="$LFS find -stripe-count $((OSTCOUNT + 1)) -type f $dir"
6278         nums=$($cmd | wc -l)
6279         [ $nums -eq $expected ] || {
6280                 $LFS getstripe -R $dir
6281                 error "'$cmd' wrong: found $nums, expected $expected"
6282         }
6283 }
6284 run_test 56s "check lfs find -stripe-count works"
6285
6286 test_56t() { # LU-611 #LU-9369
6287         local dir=$DIR/$tdir
6288
6289         setup_56 $dir 0 $NUMDIRS
6290         for i in $(seq $NUMDIRS); do
6291                 $LFS setstripe -S 8M $dir/dir$i/$tfile
6292         done
6293
6294         local expected=$NUMDIRS
6295         local cmd="$LFS find -S 8M $dir"
6296         local nums=$($cmd | wc -l)
6297
6298         [ $nums -eq $expected ] || {
6299                 $LFS getstripe -R $dir
6300                 error "'$cmd' wrong: found $nums, expected $expected"
6301         }
6302         rm -rf $dir
6303
6304         setup_56 $dir $NUMFILES $NUMDIRS "--stripe-size 512k"
6305
6306         $LFS setstripe -S 256k $dir/$tfile.{0,1,2,3}
6307
6308         expected=$(((NUMDIRS + 1) * NUMFILES))
6309         cmd="$LFS find -stripe-size 512k -type f $dir"
6310         nums=$($cmd | wc -l)
6311         [ $nums -eq $expected ] ||
6312                 error "'$cmd' wrong: found $nums, expected $expected"
6313
6314         cmd="$LFS find -stripe-size +320k -type f $dir"
6315         nums=$($cmd | wc -l)
6316         [ $nums -eq $expected ] ||
6317                 error "'$cmd' wrong: found $nums, expected $expected"
6318
6319         expected=$(((NUMDIRS + 1) * NUMFILES + 4))
6320         cmd="$LFS find -stripe-size +200k -type f $dir"
6321         nums=$($cmd | wc -l)
6322         [ $nums -eq $expected ] ||
6323                 error "'$cmd' wrong: found $nums, expected $expected"
6324
6325         cmd="$LFS find -stripe-size -640k -type f $dir"
6326         nums=$($cmd | wc -l)
6327         [ $nums -eq $expected ] ||
6328                 error "'$cmd' wrong: found $nums, expected $expected"
6329
6330         expected=4
6331         cmd="$LFS find -stripe-size 256k -type f $dir"
6332         nums=$($cmd | wc -l)
6333         [ $nums -eq $expected ] ||
6334                 error "'$cmd' wrong: found $nums, expected $expected"
6335
6336         cmd="$LFS find -stripe-size -320k -type f $dir"
6337         nums=$($cmd | wc -l)
6338         [ $nums -eq $expected ] ||
6339                 error "'$cmd' wrong: found $nums, expected $expected"
6340
6341         expected=0
6342         cmd="$LFS find -stripe-size 1024k -type f $dir"
6343         nums=$($cmd | wc -l)
6344         [ $nums -eq $expected ] ||
6345                 error "'$cmd' wrong: found $nums, expected $expected"
6346 }
6347 run_test 56t "check lfs find -stripe-size works"
6348
6349 test_56u() { # LU-611
6350         local dir=$DIR/$tdir
6351
6352         setup_56 $dir $NUMFILES $NUMDIRS "-i 0 -c 1"
6353
6354         if [[ $OSTCOUNT -gt 1 ]]; then
6355                 $LFS setstripe -i 1 -c 1 $dir/$tfile.{0,1,2,3}
6356                 onestripe=4
6357         else
6358                 onestripe=0
6359         fi
6360
6361         local expected=$(((NUMDIRS + 1) * NUMFILES))
6362         local cmd="$LFS find -stripe-index 0 -type f $dir"
6363         local nums=$($cmd | wc -l)
6364
6365         [ $nums -eq $expected ] ||
6366                 error "'$cmd' wrong: found $nums, expected $expected"
6367
6368         expected=$onestripe
6369         cmd="$LFS find -stripe-index 1 -type f $dir"
6370         nums=$($cmd | wc -l)
6371         [ $nums -eq $expected ] ||
6372                 error "'$cmd' wrong: found $nums, expected $expected"
6373
6374         cmd="$LFS find ! -stripe-index 0 -type f $dir"
6375         nums=$($cmd | wc -l)
6376         [ $nums -eq $expected ] ||
6377                 error "'$cmd' wrong: found $nums, expected $expected"
6378
6379         expected=0
6380         # This should produce an error and not return any files
6381         cmd="$LFS find -stripe-index $OSTCOUNT -type f $dir"
6382         nums=$($cmd 2>/dev/null | wc -l)
6383         [ $nums -eq $expected ] ||
6384                 error "'$cmd' wrong: found $nums, expected $expected"
6385
6386         if [[ $OSTCOUNT -gt 1 ]]; then
6387                 expected=$(((NUMDIRS + 1) * NUMFILES + onestripe))
6388                 cmd="$LFS find -stripe-index 0,1 -type f $dir"
6389                 nums=$($cmd | wc -l)
6390                 [ $nums -eq $expected ] ||
6391                         error "'$cmd' wrong: found $nums, expected $expected"
6392         fi
6393 }
6394 run_test 56u "check lfs find -stripe-index works"
6395
6396 test_56v() {
6397         local mdt_idx=0
6398         local dir=$DIR/$tdir
6399
6400         setup_56 $dir $NUMFILES $NUMDIRS
6401
6402         UUID=$(mdtuuid_from_index $mdt_idx $dir)
6403         [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT $mdt_idx"
6404
6405         for file in $($LFS find -m $UUID $dir); do
6406                 file_midx=$($LFS getstripe -m $file)
6407                 [ $file_midx -eq $mdt_idx ] ||
6408                         error "lfs find -m $UUID != getstripe -m $file_midx"
6409         done
6410 }
6411 run_test 56v "check 'lfs find -m match with lfs getstripe -m'"
6412
6413 test_56w() {
6414         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6415         [ $PARALLEL == "yes" ] && skip "skip parallel run"
6416
6417         local dir=$DIR/$tdir
6418
6419         setup_56 $dir $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
6420
6421         local stripe_size=$($LFS getstripe -S -d $dir) ||
6422                 error "$LFS getstripe -S -d $dir failed"
6423         stripe_size=${stripe_size%% *}
6424
6425         local file_size=$((stripe_size * OSTCOUNT))
6426         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
6427         local required_space=$((file_num * file_size))
6428         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
6429                            head -n1)
6430         [[ $free_space -le $((required_space / 1024)) ]] &&
6431                 skip_env "need $required_space, have $free_space kbytes"
6432
6433         local dd_bs=65536
6434         local dd_count=$((file_size / dd_bs))
6435
6436         # write data into the files
6437         local i
6438         local j
6439         local file
6440
6441         for i in $(seq $NUMFILES); do
6442                 file=$dir/file$i
6443                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
6444                         error "write data into $file failed"
6445         done
6446         for i in $(seq $NUMDIRS); do
6447                 for j in $(seq $NUMFILES); do
6448                         file=$dir/dir$i/file$j
6449                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
6450                                 error "write data into $file failed"
6451                 done
6452         done
6453
6454         # $LFS_MIGRATE will fail if hard link migration is unsupported
6455         if [[ $MDS1_VERSION -gt $(version_code 2.5.55) ]]; then
6456                 createmany -l$dir/dir1/file1 $dir/dir1/link 200 ||
6457                         error "creating links to $dir/dir1/file1 failed"
6458         fi
6459
6460         local expected=-1
6461
6462         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
6463
6464         # lfs_migrate file
6465         local cmd="$LFS_MIGRATE -y -c $expected $dir/file1"
6466
6467         echo "$cmd"
6468         eval $cmd || error "$cmd failed"
6469
6470         check_stripe_count $dir/file1 $expected
6471
6472         if [ $MDS1_VERSION -ge $(version_code 2.6.90) ];
6473         then
6474                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
6475                 # OST 1 if it is on OST 0. This file is small enough to
6476                 # be on only one stripe.
6477                 file=$dir/migr_1_ost
6478                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
6479                         error "write data into $file failed"
6480                 local obdidx=$($LFS getstripe -i $file)
6481                 local oldmd5=$(md5sum $file)
6482                 local newobdidx=0
6483
6484                 [[ $obdidx -eq 0 ]] && newobdidx=1
6485                 cmd="$LFS migrate -i $newobdidx $file"
6486                 echo $cmd
6487                 eval $cmd || error "$cmd failed"
6488
6489                 local realobdix=$($LFS getstripe -i $file)
6490                 local newmd5=$(md5sum $file)
6491
6492                 [[ $newobdidx -ne $realobdix ]] &&
6493                         error "new OST is different (was=$obdidx, "\
6494                               "wanted=$newobdidx, got=$realobdix)"
6495                 [[ "$oldmd5" != "$newmd5" ]] &&
6496                         error "md5sum differ: $oldmd5, $newmd5"
6497         fi
6498
6499         # lfs_migrate dir
6500         cmd="$LFS_MIGRATE -y -c $expected $dir/dir1"
6501         echo "$cmd"
6502         eval $cmd || error "$cmd failed"
6503
6504         for j in $(seq $NUMFILES); do
6505                 check_stripe_count $dir/dir1/file$j $expected
6506         done
6507
6508         # lfs_migrate works with lfs find
6509         cmd="$LFS find -stripe_count $OSTCOUNT -type f $dir |
6510              $LFS_MIGRATE -y -c $expected"
6511         echo "$cmd"
6512         eval $cmd || error "$cmd failed"
6513
6514         for i in $(seq 2 $NUMFILES); do
6515                 check_stripe_count $dir/file$i $expected
6516         done
6517         for i in $(seq 2 $NUMDIRS); do
6518                 for j in $(seq $NUMFILES); do
6519                 check_stripe_count $dir/dir$i/file$j $expected
6520                 done
6521         done
6522 }
6523 run_test 56w "check lfs_migrate -c stripe_count works"
6524
6525 test_56wb() {
6526         local file1=$DIR/$tdir/file1
6527         local create_pool=false
6528         local initial_pool=$($LFS getstripe -p $DIR)
6529         local pool_list=()
6530         local pool=""
6531
6532         echo -n "Creating test dir..."
6533         test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
6534         echo "done."
6535
6536         echo -n "Creating test file..."
6537         touch $file1 || error "cannot create file"
6538         echo "done."
6539
6540         echo -n "Detecting existing pools..."
6541         pool_list=($($LFS pool_list $FSNAME | grep "$FSNAME\." | cut -d. -f2))
6542
6543         if [ ${#pool_list[@]} -gt 0 ]; then
6544                 echo "${pool_list[@]}"
6545                 for thispool in "${pool_list[@]}"; do
6546                         if [[ -z "$initial_pool" ||
6547                               "$initial_pool" != "$thispool" ]]; then
6548                                 pool="$thispool"
6549                                 echo "Using existing pool '$pool'"
6550                                 break
6551                         fi
6552                 done
6553         else
6554                 echo "none detected."
6555         fi
6556         if [ -z "$pool" ]; then
6557                 pool=${POOL:-testpool}
6558                 [ "$initial_pool" = "$pool" ] && pool="testpool2"
6559                 echo -n "Creating pool '$pool'..."
6560                 create_pool=true
6561                 pool_add $pool &> /dev/null ||
6562                         error "pool_add failed"
6563                 echo "done."
6564
6565                 echo -n "Adding target to pool..."
6566                 pool_add_targets $pool 0 0 1 &> /dev/null ||
6567                         error "pool_add_targets failed"
6568                 echo "done."
6569         fi
6570
6571         echo -n "Setting pool using -p option..."
6572         $LFS_MIGRATE -y -q --no-rsync -p $pool $file1 &> /dev/null ||
6573                 error "migrate failed rc = $?"
6574         echo "done."
6575
6576         echo -n "Verifying test file is in pool after migrating..."
6577         [ "$($LFS getstripe -p $file1)" = $pool ] ||
6578                 error "file was not migrated to pool $pool"
6579         echo "done."
6580
6581         echo -n "Removing test file from pool '$pool'..."
6582         # "lfs migrate $file" won't remove the file from the pool
6583         # until some striping information is changed.
6584         $LFS migrate -c 1 $file1 &> /dev/null ||
6585                 error "cannot remove from pool"
6586         [ "$($LFS getstripe -p $file1)" ] &&
6587                 error "pool still set"
6588         echo "done."
6589
6590         echo -n "Setting pool using --pool option..."
6591         $LFS_MIGRATE -y -q --no-rsync --pool $pool $file1 &> /dev/null ||
6592                 error "migrate failed rc = $?"
6593         echo "done."
6594
6595         # Clean up
6596         rm -f $file1
6597         if $create_pool; then
6598                 destroy_test_pools 2> /dev/null ||
6599                         error "destroy test pools failed"
6600         fi
6601 }
6602 run_test 56wb "check lfs_migrate pool support"
6603
6604 test_56wc() {
6605         local file1="$DIR/$tdir/file1"
6606         local parent_ssize
6607         local parent_scount
6608         local cur_ssize
6609         local cur_scount
6610         local orig_ssize
6611
6612         echo -n "Creating test dir..."
6613         test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
6614         $LFS setstripe -S 1M -c 1 "$DIR/$tdir" &> /dev/null ||
6615                 error "cannot set stripe by '-S 1M -c 1'"
6616         echo "done"
6617
6618         echo -n "Setting initial stripe for test file..."
6619         $LFS setstripe -S 512K -c 1 "$file1" &> /dev/null ||
6620                 error "cannot set stripe"
6621         cur_ssize=$($LFS getstripe -S "$file1")
6622         [ $cur_ssize -eq 524288 ] || error "setstripe -S $cur_ssize != 524288"
6623         echo "done."
6624
6625         # File currently set to -S 512K -c 1
6626
6627         # Ensure -c and -S options are rejected when -R is set
6628         echo -n "Verifying incompatible options are detected..."
6629         $LFS_MIGRATE -y -R -c 1 "$file1" &> /dev/null &&
6630                 error "incompatible -c and -R options not detected"
6631         $LFS_MIGRATE -y -R -S 1M "$file1" &> /dev/null &&
6632                 error "incompatible -S and -R options not detected"
6633         echo "done."
6634
6635         # Ensure unrecognized options are passed through to 'lfs migrate'
6636         echo -n "Verifying -S option is passed through to lfs migrate..."
6637         $LFS_MIGRATE -y -S 1M "$file1" &> /dev/null ||
6638                 error "migration failed"
6639         cur_ssize=$($LFS getstripe -S "$file1")
6640         [ $cur_ssize -eq 1048576 ] || error "migrate -S $cur_ssize != 1048576"
6641         echo "done."
6642
6643         # File currently set to -S 1M -c 1
6644
6645         # Ensure long options are supported
6646         echo -n "Verifying long options supported..."
6647         $LFS_MIGRATE -y --non-block "$file1" &> /dev/null ||
6648                 error "long option without argument not supported"
6649         $LFS_MIGRATE -y --stripe-size 512K "$file1" &> /dev/null ||
6650                 error "long option with argument not supported"
6651         cur_ssize=$($LFS getstripe -S "$file1")
6652         [ $cur_ssize -eq 524288 ] ||
6653                 error "migrate --stripe-size $cur_ssize != 524288"
6654         echo "done."
6655
6656         # File currently set to -S 512K -c 1
6657
6658         if [ "$OSTCOUNT" -gt 1 ]; then
6659                 echo -n "Verifying explicit stripe count can be set..."
6660                 $LFS_MIGRATE -y -c 2 "$file1" &> /dev/null ||
6661                         error "migrate failed"
6662                 cur_scount=$($LFS getstripe -c "$file1")
6663                 [ $cur_scount -eq 2 ] || error "migrate -c $cur_scount != 2"
6664                 echo "done."
6665         fi
6666
6667         # File currently set to -S 512K -c 1 or -S 512K -c 2
6668
6669         # Ensure parent striping is used if -R is set, and no stripe
6670         # count or size is specified
6671         echo -n "Setting stripe for parent directory..."
6672         $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
6673                 error "cannot set stripe '-S 2M -c 1'"
6674         echo "done."
6675
6676         echo -n "Verifying restripe option uses parent stripe settings..."
6677         parent_ssize=$($LFS getstripe -S $DIR/$tdir 2>/dev/null)
6678         parent_scount=$($LFS getstripe -c $DIR/$tdir 2>/dev/null)
6679         $LFS_MIGRATE -y -R "$file1" &> /dev/null ||
6680                 error "migrate failed"
6681         cur_ssize=$($LFS getstripe -S "$file1")
6682         [ $cur_ssize -eq $parent_ssize ] ||
6683                 error "migrate -R stripe_size $cur_ssize != $parent_ssize"
6684         cur_scount=$($LFS getstripe -c "$file1")
6685         [ $cur_scount -eq $parent_scount ] ||
6686                 error "migrate -R stripe_count $cur_scount != $parent_scount"
6687         echo "done."
6688
6689         # File currently set to -S 1M -c 1
6690
6691         # Ensure striping is preserved if -R is not set, and no stripe
6692         # count or size is specified
6693         echo -n "Verifying striping size preserved when not specified..."
6694         orig_ssize=$($LFS getstripe -S "$file1" 2>/dev/null)
6695         $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
6696                 error "cannot set stripe on parent directory"
6697         $LFS_MIGRATE -y "$file1" &> /dev/null ||
6698                 error "migrate failed"
6699         cur_ssize=$($LFS getstripe -S "$file1")
6700         [ $cur_ssize -eq $orig_ssize ] ||
6701                 error "migrate by default $cur_ssize != $orig_ssize"
6702         echo "done."
6703
6704         # Ensure file name properly detected when final option has no argument
6705         echo -n "Verifying file name properly detected..."
6706         $LFS_MIGRATE -y "$file1" &> /dev/null ||
6707                 error "file name interpreted as option argument"
6708         echo "done."
6709
6710         # Clean up
6711         rm -f "$file1"
6712 }
6713 run_test 56wc "check unrecognized options for lfs_migrate are passed through"
6714
6715 test_56wd() {
6716         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6717
6718         local file1=$DIR/$tdir/file1
6719
6720         echo -n "Creating test dir..."
6721         test_mkdir $DIR/$tdir || error "cannot create dir"
6722         echo "done."
6723
6724         echo -n "Creating test file..."
6725         touch $file1
6726         echo "done."
6727
6728         # Ensure 'lfs migrate' will fail by using a non-existent option,
6729         # and make sure rsync is not called to recover
6730         echo -n "Make sure --no-rsync option works..."
6731         $LFS_MIGRATE -y --no-rsync --invalid-opt $file1 2>&1 |
6732                 grep -q 'refusing to fall back to rsync' ||
6733                 error "rsync was called with --no-rsync set"
6734         echo "done."
6735
6736         # Ensure rsync is called without trying 'lfs migrate' first
6737         echo -n "Make sure --rsync option works..."
6738         $LFS_MIGRATE -y --rsync --invalid-opt $file1 2>&1 |
6739                 grep -q 'falling back to rsync' &&
6740                 error "lfs migrate was called with --rsync set"
6741         echo "done."
6742
6743         echo -n "Make sure --rsync and --no-rsync options are exclusive..."
6744         $LFS_MIGRATE -y --rsync --no-rsync $file1 2>&1 |
6745                 grep -q 'at the same time' ||
6746                 error "--rsync and --no-rsync accepted concurrently"
6747         echo "done."
6748
6749         # Clean up
6750         rm -f $file1
6751 }
6752 run_test 56wd "check lfs_migrate --rsync and --no-rsync work"
6753
6754 test_56x() {
6755         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6756         check_swap_layouts_support
6757
6758         local dir=$DIR/$tdir
6759         local ref1=/etc/passwd
6760         local file1=$dir/file1
6761
6762         test_mkdir $dir || error "creating dir $dir"
6763         $LFS setstripe -c 2 $file1
6764         cp $ref1 $file1
6765         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
6766         stripe=$($LFS getstripe -c $file1)
6767         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
6768         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
6769
6770         # clean up
6771         rm -f $file1
6772 }
6773 run_test 56x "lfs migration support"
6774
6775 test_56xa() {
6776         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6777         check_swap_layouts_support
6778
6779         local dir=$DIR/$tdir/$testnum
6780
6781         test_mkdir -p $dir
6782
6783         local ref1=/etc/passwd
6784         local file1=$dir/file1
6785
6786         $LFS setstripe -c 2 $file1
6787         cp $ref1 $file1
6788         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
6789
6790         local stripe=$($LFS getstripe -c $file1)
6791
6792         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
6793         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
6794
6795         # clean up
6796         rm -f $file1
6797 }
6798 run_test 56xa "lfs migration --block support"
6799
6800 check_migrate_links() {
6801         local dir="$1"
6802         local file1="$dir/file1"
6803         local begin="$2"
6804         local count="$3"
6805         local runas="$4"
6806         local total_count=$(($begin + $count - 1))
6807         local symlink_count=10
6808         local uniq_count=10
6809
6810         if [ ! -f "$file1" ]; then
6811                 echo -n "creating initial file..."
6812                 $LFS setstripe -c 1 -S "512k" "$file1" ||
6813                         error "cannot setstripe initial file"
6814                 echo "done"
6815
6816                 echo -n "creating symlinks..."
6817                 for s in $(seq 1 $symlink_count); do
6818                         ln -s "$file1" "$dir/slink$s" ||
6819                                 error "cannot create symlinks"
6820                 done
6821                 echo "done"
6822
6823                 echo -n "creating nonlinked files..."
6824                 createmany -o "$dir/uniq" 1 10 &> /dev/null ||
6825                         error "cannot create nonlinked files"
6826                 echo "done"
6827         fi
6828
6829         # create hard links
6830         if [ ! -f "$dir/file$total_count" ]; then
6831                 echo -n "creating hard links $begin:$total_count..."
6832                 createmany -l"$file1" "$dir/file" "$begin" "$count" &>  \
6833                         /dev/null || error "cannot create hard links"
6834                 echo "done"
6835         fi
6836
6837         echo -n "checking number of hard links listed in xattrs..."
6838         local fid=$($LFS getstripe -F "$file1")
6839         local paths=($($LFS fid2path "$MOUNT" "$fid" 2> /dev/null))
6840
6841         echo "${#paths[*]}"
6842         if [ ${#paths[*]} -lt $total_count -a "$begin" -eq 2  ]; then
6843                         skip "hard link list has unexpected size, skipping test"
6844         fi
6845         if [ ${#paths[*]} -ge $total_count -a "$begin" -ne 2  ]; then
6846                         error "link names should exceed xattrs size"
6847         fi
6848
6849         echo -n "migrating files..."
6850         local migrate_out=$($runas $LFS_MIGRATE -y -S '1m' $dir)
6851         local rc=$?
6852         [ $rc -eq 0 ] || error "migrate failed rc = $rc"
6853         echo "done"
6854
6855         # make sure all links have been properly migrated
6856         echo -n "verifying files..."
6857         fid=$($LFS getstripe -F "$file1") ||
6858                 error "cannot get fid for file $file1"
6859         for i in $(seq 2 $total_count); do
6860                 local fid2=$($LFS getstripe -F $dir/file$i)
6861
6862                 [ "$fid2" == "$fid" ] ||
6863                         error "migrated hard link has mismatched FID"
6864         done
6865
6866         # make sure hard links were properly detected, and migration was
6867         # performed only once for the entire link set; nonlinked files should
6868         # also be migrated
6869         local actual=$(grep -c 'done' <<< "$migrate_out")
6870         local expected=$(($uniq_count + 1))
6871
6872         [ "$actual" -eq  "$expected" ] ||
6873                 error "hard links individually migrated ($actual != $expected)"
6874
6875         # make sure the correct number of hard links are present
6876         local hardlinks=$(stat -c '%h' "$file1")
6877
6878         [ $hardlinks -eq $total_count ] ||
6879                 error "num hard links $hardlinks != $total_count"
6880         echo "done"
6881
6882         return 0
6883 }
6884
6885 test_56xb() {
6886         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
6887                 skip "Need MDS version at least 2.10.55"
6888
6889         local dir="$DIR/$tdir"
6890
6891         test_mkdir "$dir" || error "cannot create dir $dir"
6892
6893         echo "testing lfs migrate mode when all links fit within xattrs"
6894         LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 2 99
6895
6896         echo "testing rsync mode when all links fit within xattrs"
6897         LFS_MIGRATE_RSYNC_MODE=true check_migrate_links "$dir" 2 99
6898
6899         echo "testing lfs migrate mode when all links do not fit within xattrs"
6900         LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 101 100
6901
6902         echo "testing rsync mode when all links do not fit within xattrs"
6903         LFS_MIGRATE_RSYNC_MODE=true check_migrate_links "$dir" 101 100
6904
6905         chown -R $RUNAS_ID $dir
6906         echo "testing non-root lfs migrate mode when not all links are in xattr"
6907         LFS_MIGRATE_RSYNC_MODE=false check_migrate_links "$dir" 101 100 "$RUNAS"
6908
6909         # clean up
6910         rm -rf $dir
6911 }
6912 run_test 56xb "lfs migration hard link support"
6913
6914 test_56xc() {
6915         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6916
6917         local dir="$DIR/$tdir"
6918
6919         test_mkdir "$dir" || error "cannot create dir $dir"
6920
6921         # Test 1: ensure file < 1 GB is always migrated with 1 stripe
6922         echo -n "Setting initial stripe for 20MB test file..."
6923         $LFS setstripe -c 2 -i 0 "$dir/20mb" ||
6924                 error "cannot setstripe 20MB file"
6925         echo "done"
6926         echo -n "Sizing 20MB test file..."
6927         truncate "$dir/20mb" 20971520 || error "cannot create 20MB test file"
6928         echo "done"
6929         echo -n "Verifying small file autostripe count is 1..."
6930         $LFS_MIGRATE -y -A -C 1 "$dir/20mb" ||
6931                 error "cannot migrate 20MB file"
6932         local stripe_count=$($LFS getstripe -c "$dir/20mb") ||
6933                 error "cannot get stripe for $dir/20mb"
6934         [ $stripe_count -eq 1 ] ||
6935                 error "unexpected stripe count $stripe_count for 20MB file"
6936         rm -f "$dir/20mb"
6937         echo "done"
6938
6939         # Test 2: File is small enough to fit within the available space on
6940         # sqrt(size_in_gb) + 1 OSTs but is larger than 1GB.  The file must
6941         # have at least an additional 1KB for each desired stripe for test 3
6942         echo -n "Setting stripe for 1GB test file..."
6943         $LFS setstripe -c 1 -i 0 "$dir/1gb" || error "cannot setstripe 1GB file"
6944         echo "done"
6945         echo -n "Sizing 1GB test file..."
6946         # File size is 1GB + 3KB
6947         truncate "$dir/1gb" 1073744896 || error "cannot create 1GB test file"
6948         echo "done"
6949
6950         # need at least 512MB per OST for 1GB file to fit in 2 stripes
6951         local avail=$($LCTL get_param -n llite.$FSNAME*.kbytesavail)
6952         if (( avail > 524288 * OSTCOUNT )); then
6953                 echo -n "Migrating 1GB file..."
6954                 $LFS_MIGRATE -y -A -C 1 "$dir/1gb" ||
6955                         error "cannot migrate 1GB file"
6956                 echo "done"
6957                 echo -n "Verifying autostripe count is sqrt(n) + 1..."
6958                 stripe_count=$($LFS getstripe -c "$dir/1gb") ||
6959                         error "cannot getstripe for 1GB file"
6960                 [ $stripe_count -eq 2 ] ||
6961                         error "unexpected stripe count $stripe_count != 2"
6962                 echo "done"
6963         fi
6964
6965         # Test 3: File is too large to fit within the available space on
6966         # sqrt(n) + 1 OSTs.  Simulate limited available space with -X
6967         if [ $OSTCOUNT -ge 3 ]; then
6968                 # The required available space is calculated as
6969                 # file size (1GB + 3KB) / OST count (3).
6970                 local kb_per_ost=349526
6971
6972                 echo -n "Migrating 1GB file with limit..."
6973                 $LFS_MIGRATE -y -A -C 1 -X $kb_per_ost "$dir/1gb" ||
6974                         error "cannot migrate 1GB file with limit"
6975                 echo "done"
6976
6977                 stripe_count=$($LFS getstripe -c "$dir/1gb")
6978                 echo -n "Verifying 1GB autostripe count with limited space..."
6979                 [ "$stripe_count" -a $stripe_count -ge 3 ] ||
6980                         error "unexpected stripe count $stripe_count (min 3)"
6981                 echo "done"
6982         fi
6983
6984         # clean up
6985         rm -rf $dir
6986 }
6987 run_test 56xc "lfs migration autostripe"
6988
6989 test_56xd() {
6990         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
6991
6992         local dir=$DIR/$tdir
6993         local f_mgrt=$dir/$tfile.mgrt
6994         local f_yaml=$dir/$tfile.yaml
6995         local f_copy=$dir/$tfile.copy
6996         local layout_yaml="-E 1M -S 512K -c 1 -E -1 -S 1M -c 2 -i 0"
6997         local layout_copy="-c 2 -S 2M -i 1"
6998         local yamlfile=$dir/yamlfile
6999         local layout_before;
7000         local layout_after;
7001
7002         test_mkdir "$dir" || error "cannot create dir $dir"
7003         $LFS setstripe $layout_yaml $f_yaml ||
7004                 error "cannot setstripe $f_yaml with layout $layout_yaml"
7005         $LFS getstripe --yaml $f_yaml > $yamlfile
7006         $LFS setstripe $layout_copy $f_copy ||
7007                 error "cannot setstripe $f_copy with layout $layout_copy"
7008         touch $f_mgrt
7009         dd if=/dev/zero of=$f_mgrt bs=1M count=4
7010
7011         # 1. test option --yaml
7012         $LFS_MIGRATE -y --yaml $yamlfile $f_mgrt ||
7013                 error "cannot migrate $f_mgrt with --yaml $yamlfile"
7014         layout_before=$(get_layout_param $f_yaml)
7015         layout_after=$(get_layout_param $f_mgrt)
7016         [ "$layout_after" == "$layout_before" ] ||
7017                 error "lfs_migrate --yaml: $layout_after != $layout_before"
7018
7019         # 2. test option --copy
7020         $LFS_MIGRATE -y --copy $f_copy $f_mgrt ||
7021                 error "cannot migrate $f_mgrt with --copy $f_copy"
7022         layout_before=$(get_layout_param $f_copy)
7023         layout_after=$(get_layout_param $f_mgrt)
7024         [ "$layout_after" == "$layout_before" ] ||
7025                 error "lfs_migrate --copy: $layout_after != $layout_before"
7026 }
7027 run_test 56xd "check lfs_migrate --yaml and --copy support"
7028
7029 test_56xe() {
7030         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
7031
7032         local dir=$DIR/$tdir
7033         local f_comp=$dir/$tfile
7034         local layout="-E 1M -S 512K -c 1 -E -1 -S 1M -c 2 -i 0"
7035         local layout_before=""
7036         local layout_after=""
7037
7038         test_mkdir "$dir" || error "cannot create dir $dir"
7039         $LFS setstripe $layout $f_comp ||
7040                 error "cannot setstripe $f_comp with layout $layout"
7041         layout_before=$(get_layout_param $f_comp)
7042         dd if=/dev/zero of=$f_comp bs=1M count=4
7043
7044         # 1. migrate a comp layout file by lfs_migrate
7045         $LFS_MIGRATE -y $f_comp || error "cannot migrate $f_comp by lfs_migrate"
7046         layout_after=$(get_layout_param $f_comp)
7047         [ "$layout_before" == "$layout_after" ] ||
7048                 error "lfs_migrate: $layout_before != $layout_after"
7049
7050         # 2. migrate a comp layout file by lfs migrate
7051         $LFS migrate $f_comp || error "cannot migrate $f_comp by lfs migrate"
7052         layout_after=$(get_layout_param $f_comp)
7053         [ "$layout_before" == "$layout_after" ] ||
7054                 error "lfs migrate: $layout_before != $layout_after"
7055 }
7056 run_test 56xe "migrate a composite layout file"
7057
7058 test_56y() {
7059         [ $MDS1_VERSION -lt $(version_code 2.4.53) ] &&
7060                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53"
7061
7062         local res=""
7063         local dir=$DIR/$tdir
7064         local f1=$dir/file1
7065         local f2=$dir/file2
7066
7067         test_mkdir -p $dir || error "creating dir $dir"
7068         touch $f1 || error "creating std file $f1"
7069         $MULTIOP $f2 H2c || error "creating released file $f2"
7070
7071         # a directory can be raid0, so ask only for files
7072         res=$($LFS find $dir -L raid0 -type f | wc -l)
7073         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
7074
7075         res=$($LFS find $dir \! -L raid0 -type f | wc -l)
7076         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
7077
7078         # only files can be released, so no need to force file search
7079         res=$($LFS find $dir -L released)
7080         [[ $res == $f2 ]] || error "search released: found $res != $f2"
7081
7082         res=$($LFS find $dir -type f \! -L released)
7083         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
7084 }
7085 run_test 56y "lfs find -L raid0|released"
7086
7087 test_56z() { # LU-4824
7088         # This checks to make sure 'lfs find' continues after errors
7089         # There are two classes of errors that should be caught:
7090         # - If multiple paths are provided, all should be searched even if one
7091         #   errors out
7092         # - If errors are encountered during the search, it should not terminate
7093         #   early
7094         local dir=$DIR/$tdir
7095         local i
7096
7097         test_mkdir $dir
7098         for i in d{0..9}; do
7099                 test_mkdir $dir/$i
7100                 touch $dir/$i/$tfile
7101         done
7102         $LFS find $DIR/non_existent_dir $dir &&
7103                 error "$LFS find did not return an error"
7104         # Make a directory unsearchable. This should NOT be the last entry in
7105         # directory order.  Arbitrarily pick the 6th entry
7106         chmod 700 $($LFS find $dir -type d | sed '6!d')
7107
7108         $RUNAS $LFS find $DIR/non_existent $dir
7109         local count=$($RUNAS $LFS find $DIR/non_existent $dir | wc -l)
7110
7111         # The user should be able to see 10 directories and 9 files
7112         (( count == 19 )) ||
7113                 error "$LFS find found $count != 19 entries after error"
7114 }
7115 run_test 56z "lfs find should continue after an error"
7116
7117 test_56aa() { # LU-5937
7118         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
7119
7120         local dir=$DIR/$tdir
7121
7122         mkdir $dir
7123         $LFS setdirstripe -c$MDSCOUNT $dir/striped_dir
7124
7125         createmany -o $dir/striped_dir/${tfile}- 1024
7126         local dirs=$($LFS find --size +8k $dir/)
7127
7128         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
7129 }
7130 run_test 56aa "lfs find --size under striped dir"
7131
7132 test_56ab() { # LU-10705
7133         test_mkdir $DIR/$tdir
7134         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=8k count=1 seek=2k
7135         dd if=/dev/zero of=$DIR/$tdir/$tfile.2 bs=4k count=1 seek=4k
7136         dd if=/dev/zero of=$DIR/$tdir/$tfile.3 bs=1M count=2 seek=16
7137         # Flush writes to ensure valid blocks.  Need to be more thorough for
7138         # ZFS, since blocks are not allocated/returned to client immediately.
7139         sync_all_data
7140         wait_zfs_commit ost1 2
7141         cancel_lru_locks osc
7142         ls -ls $DIR/$tdir
7143
7144         local files=$($LFS find --size +16M $DIR/$tdir | wc -l)
7145
7146         [[ $files == 3 ]] || error ">16M size files $files isn't 3 as expected"
7147
7148         files=$($LFS find --blocks +1M $DIR/$tdir | wc -l)
7149         [[ $files == 1 ]] || error ">1M blocks files $files isn't 1 as expected"
7150
7151         rm -f $DIR/$tdir/$tfile.[123]
7152 }
7153 run_test 56ab "lfs find --blocks"
7154
7155 test_56ba() {
7156         [ $MDS1_VERSION -lt $(version_code 2.10.50) ] &&
7157                 skip "Need MDS version at least 2.10.50"
7158
7159         # Create composite files with one component
7160         local dir=$DIR/$tdir
7161
7162         setup_56 $dir/1Mfiles 5 1 "-S 1M --component-end 1M"
7163         # Create composite files with three components
7164         setup_56 $dir/2Mfiles 5 2 "-E 2M -S 1M -E 4M -E 6M"
7165         # Create non-composite files
7166         createmany -o $dir/${tfile}- 10
7167
7168         local nfiles=$($LFS find --component-end 1M --type f $dir | wc -l)
7169
7170         [[ $nfiles == 10 ]] ||
7171                 error "lfs find -E 1M found $nfiles != 10 files"
7172
7173         nfiles=$($LFS find ! -E 1M --type f $dir | wc -l)
7174         [[ $nfiles == 25 ]] ||
7175                 error "lfs find ! -E 1M found $nfiles != 25 files"
7176
7177         # All files have a component that starts at 0
7178         nfiles=$($LFS find --component-start 0 --type f $dir | wc -l)
7179         [[ $nfiles == 35 ]] ||
7180                 error "lfs find --component-start 0 - $nfiles != 35 files"
7181
7182         nfiles=$($LFS find --component-start 2M --type f $dir | wc -l)
7183         [[ $nfiles == 15 ]] ||
7184                 error "lfs find --component-start 2M - $nfiles != 15 files"
7185
7186         # All files created here have a componenet that does not starts at 2M
7187         nfiles=$($LFS find ! --component-start 2M --type f $dir | wc -l)
7188         [[ $nfiles == 35 ]] ||
7189                 error "lfs find ! --component-start 2M - $nfiles != 35 files"
7190
7191         # Find files with a specified number of components
7192         local nfiles=$($LFS find --component-count 3 --type f $dir | wc -l)
7193         [[ $nfiles == 15 ]] ||
7194                 error "lfs find --component-count 3 - $nfiles != 15 files"
7195
7196         # Remember non-composite files have a component count of zero
7197         local nfiles=$($LFS find --component-count 0 --type f $dir | wc -l)
7198         [[ $nfiles == 10 ]] ||
7199                 error "lfs find --component-count 0 - $nfiles != 10 files"
7200
7201         nfiles=$($LFS find ! --component-count 3 --type f $dir | wc -l)
7202         [[ $nfiles == 20 ]] ||
7203                 error "lfs find ! --component-count 3 - $nfiles != 20 files"
7204
7205         # All files have a flag called "init"
7206         local nfiles=$($LFS find --component-flags init --type f $dir | wc -l)
7207         [[ $nfiles == 35 ]] ||
7208                 error "lfs find --component-flags init - $nfiles != 35 files"
7209
7210         # Multi-component files will have a component not initialized
7211         local nfiles=$($LFS find ! --component-flags init --type f $dir | wc -l)
7212         [[ $nfiles == 15 ]] ||
7213                 error "lfs find !--component-flags init - $nfiles != 15 files"
7214
7215         rm -rf $dir
7216
7217 }
7218 run_test 56ba "test lfs find --component-end, -start, -count, and -flags"
7219
7220 test_56ca() {
7221         [[ $MDS1_VERSION -ge $(version_code 2.10.57) ]] ||
7222                 skip "Need MDS version at least 2.10.57"
7223
7224         local td=$DIR/$tdir
7225         local tf=$td/$tfile
7226         local dir
7227         local nfiles
7228         local cmd
7229         local i
7230         local j
7231
7232         # create mirrored directories and mirrored files
7233         mkdir $td || error "mkdir $td failed"
7234         $LFS mirror create -N3 $td || error "create mirrored dir $td failed"
7235         createmany -o $tf- 10 || error "create $tf- failed"
7236
7237         for i in $(seq 2); do
7238                 dir=$td/dir$i
7239                 mkdir $dir || error "mkdir $dir failed"
7240                 $LFS mirror create -N$((3 + i)) $dir ||
7241                         error "create mirrored dir $dir failed"
7242                 createmany -o $dir/$tfile- 10 ||
7243                         error "create $dir/$tfile- failed"
7244         done
7245
7246         # change the states of some mirrored files
7247         echo foo > $tf-6
7248         for i in $(seq 2); do
7249                 dir=$td/dir$i
7250                 for j in $(seq 4 9); do
7251                         echo foo > $dir/$tfile-$j
7252                 done
7253         done
7254
7255         # find mirrored files with specific mirror count
7256         cmd="$LFS find --mirror-count 3 --type f $td"
7257         nfiles=$($cmd | wc -l)
7258         [[ $nfiles = 10 ]] || error "$cmd: $nfiles != 10 files"
7259
7260         cmd="$LFS find ! --mirror-count 3 --type f $td"
7261         nfiles=$($cmd | wc -l)
7262         [[ $nfiles = 20 ]] || error "$cmd: $nfiles != 20 files"
7263
7264         cmd="$LFS find --mirror-count +2 --type f $td"
7265         nfiles=$($cmd | wc -l)
7266         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
7267
7268         cmd="$LFS find --mirror-count -6 --type f $td"
7269         nfiles=$($cmd | wc -l)
7270         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
7271
7272         # find mirrored files with specific file state
7273         cmd="$LFS find --maxdepth 1 --mirror-state=^ro --type f $td"
7274         [[ $($cmd) = $tf-6 ]] || error "$cmd: didn't return $tf-6"
7275
7276         cmd="$LFS find --mirror-state=ro --type f $td"
7277         nfiles=$($cmd | wc -l)
7278         [[ $nfiles = 17 ]] || error "$cmd: $nfiles != 17 files"
7279
7280         cmd="$LFS find ! --mirror-state=ro --type f $td"
7281         nfiles=$($cmd | wc -l)
7282         [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
7283
7284         cmd="$LFS find --mirror-state=wp --type f $td"
7285         nfiles=$($cmd | wc -l)
7286         [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
7287
7288         cmd="$LFS find ! --mirror-state=sp --type f $td"
7289         nfiles=$($cmd | wc -l)
7290         [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
7291 }
7292 run_test 56ca "check lfs find --mirror-count|-N and --mirror-state"
7293
7294 test_57a() {
7295         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7296         # note test will not do anything if MDS is not local
7297         if [ "$mds1_FSTYPE" != ldiskfs ]; then
7298                 skip_env "ldiskfs only test"
7299         fi
7300         remote_mds_nodsh && skip "remote MDS with nodsh"
7301
7302         local MNTDEV="osd*.*MDT*.mntdev"
7303         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
7304         [ -z "$DEV" ] && error "can't access $MNTDEV"
7305         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
7306                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
7307                         error "can't access $DEV"
7308                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
7309                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
7310                 rm $TMP/t57a.dump
7311         done
7312 }
7313 run_test 57a "verify MDS filesystem created with large inodes =="
7314
7315 test_57b() {
7316         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7317         if [ "$mds1_FSTYPE" != ldiskfs ]; then
7318                 skip_env "ldiskfs only test"
7319         fi
7320         remote_mds_nodsh && skip "remote MDS with nodsh"
7321
7322         local dir=$DIR/$tdir
7323         local filecount=100
7324         local file1=$dir/f1
7325         local fileN=$dir/f$filecount
7326
7327         rm -rf $dir || error "removing $dir"
7328         test_mkdir -c1 $dir
7329         local mdtidx=$($LFS getstripe -m $dir)
7330         local mdtname=MDT$(printf %04x $mdtidx)
7331         local facet=mds$((mdtidx + 1))
7332
7333         echo "mcreating $filecount files"
7334         createmany -m $dir/f 1 $filecount || error "creating files in $dir"
7335
7336         # verify that files do not have EAs yet
7337         $LFS getstripe $file1 2>&1 | grep -q "no stripe" ||
7338                 error "$file1 has an EA"
7339         $LFS getstripe $fileN 2>&1 | grep -q "no stripe" ||
7340                 error "$fileN has an EA"
7341
7342         sync
7343         sleep 1
7344         df $dir  #make sure we get new statfs data
7345         local mdsfree=$(do_facet $facet \
7346                         lctl get_param -n osd*.*$mdtname.kbytesfree)
7347         local mdcfree=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
7348         local file
7349
7350         echo "opening files to create objects/EAs"
7351         for file in $(seq -f $dir/f%g 1 $filecount); do
7352                 $OPENFILE -f O_RDWR $file > /dev/null 2>&1 ||
7353                         error "opening $file"
7354         done
7355
7356         # verify that files have EAs now
7357         $LFS getstripe $file1 | grep -q "obdidx" || error "$file1 missing EA"
7358         $LFS getstripe $fileN | grep -q "obdidx" || error "$fileN missing EA"
7359
7360         sleep 1  #make sure we get new statfs data
7361         df $dir
7362         local mdsfree2=$(do_facet $facet \
7363                          lctl get_param -n osd*.*$mdtname.kbytesfree)
7364         local mdcfree2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
7365
7366         if [[ $mdcfree2 -lt $((mdcfree - 16)) ]]; then
7367                 if [ "$mdsfree" != "$mdsfree2" ]; then
7368                         error "MDC before $mdcfree != after $mdcfree2"
7369                 else
7370                         echo "MDC before $mdcfree != after $mdcfree2"
7371                         echo "unable to confirm if MDS has large inodes"
7372                 fi
7373         fi
7374         rm -rf $dir
7375 }
7376 run_test 57b "default LOV EAs are stored inside large inodes ==="
7377
7378 test_58() {
7379         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7380         [ -z "$(which wiretest 2>/dev/null)" ] &&
7381                         skip_env "could not find wiretest"
7382
7383         wiretest
7384 }
7385 run_test 58 "verify cross-platform wire constants =============="
7386
7387 test_59() {
7388         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7389
7390         echo "touch 130 files"
7391         createmany -o $DIR/f59- 130
7392         echo "rm 130 files"
7393         unlinkmany $DIR/f59- 130
7394         sync
7395         # wait for commitment of removal
7396         wait_delete_completed
7397 }
7398 run_test 59 "verify cancellation of llog records async ========="
7399
7400 TEST60_HEAD="test_60 run $RANDOM"
7401 test_60a() {
7402         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7403         remote_mgs_nodsh && skip "remote MGS with nodsh"
7404         do_facet mgs "! which run-llog.sh &> /dev/null" &&
7405                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
7406                         skip_env "missing subtest run-llog.sh"
7407
7408         log "$TEST60_HEAD - from kernel mode"
7409         do_facet mgs "$LCTL dk > /dev/null"
7410         do_facet mgs "bash run-llog.sh" || error "run-llog.sh failed"
7411         do_facet mgs $LCTL dk > $TMP/$tfile
7412
7413         # LU-6388: test llog_reader
7414         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
7415         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
7416         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
7417                         skip_env "missing llog_reader"
7418         local fstype=$(facet_fstype mgs)
7419         [ $fstype != ldiskfs -a $fstype != zfs ] &&
7420                 skip_env "Only for ldiskfs or zfs type mgs"
7421
7422         local mntpt=$(facet_mntpt mgs)
7423         local mgsdev=$(mgsdevname 1)
7424         local fid_list
7425         local fid
7426         local rec_list
7427         local rec
7428         local rec_type
7429         local obj_file
7430         local path
7431         local seq
7432         local oid
7433         local pass=true
7434
7435         #get fid and record list
7436         fid_list=($(awk '/9_sub.*record/ { print $NF }' $TMP/$tfile |
7437                 tail -n 4))
7438         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' $TMP/$tfile |
7439                 tail -n 4))
7440         #remount mgs as ldiskfs or zfs type
7441         stop mgs || error "stop mgs failed"
7442         mount_fstype mgs || error "remount mgs failed"
7443         for ((i = 0; i < ${#fid_list[@]}; i++)); do
7444                 fid=${fid_list[i]}
7445                 rec=${rec_list[i]}
7446                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
7447                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
7448                 oid=$((16#$oid))
7449
7450                 case $fstype in
7451                         ldiskfs )
7452                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
7453                         zfs )
7454                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
7455                 esac
7456                 echo "obj_file is $obj_file"
7457                 do_facet mgs $llog_reader $obj_file
7458
7459                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
7460                         awk '{ print $3 }' | sed -e "s/^type=//g")
7461                 if [ $rec_type != $rec ]; then
7462                         echo "FAILED test_60a wrong record type $rec_type," \
7463                               "should be $rec"
7464                         pass=false
7465                         break
7466                 fi
7467
7468                 #check obj path if record type is LLOG_LOGID_MAGIC
7469                 if [ "$rec" == "1064553b" ]; then
7470                         path=$(do_facet mgs $llog_reader $obj_file |
7471                                 grep "path=" | awk '{ print $NF }' |
7472                                 sed -e "s/^path=//g")
7473                         if [ $obj_file != $mntpt/$path ]; then
7474                                 echo "FAILED test_60a wrong obj path" \
7475                                       "$montpt/$path, should be $obj_file"
7476                                 pass=false
7477                                 break
7478                         fi
7479                 fi
7480         done
7481         rm -f $TMP/$tfile
7482         #restart mgs before "error", otherwise it will block the next test
7483         stop mgs || error "stop mgs failed"
7484         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
7485         $pass || error "test failed, see FAILED test_60a messages for specifics"
7486 }
7487 run_test 60a "llog_test run from kernel module and test llog_reader"
7488
7489 test_60b() { # bug 6411
7490         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7491
7492         dmesg > $DIR/$tfile
7493         LLOG_COUNT=$(do_facet mgs dmesg |
7494                      awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
7495                           /llog_[a-z]*.c:[0-9]/ {
7496                                 if (marker)
7497                                         from_marker++
7498                                 from_begin++
7499                           }
7500                           END {
7501                                 if (marker)
7502                                         print from_marker
7503                                 else
7504                                         print from_begin
7505                           }")
7506
7507         [[ $LLOG_COUNT -gt 120 ]] &&
7508                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
7509 }
7510 run_test 60b "limit repeated messages from CERROR/CWARN"
7511
7512 test_60c() {
7513         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7514
7515         echo "create 5000 files"
7516         createmany -o $DIR/f60c- 5000
7517 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
7518         lctl set_param fail_loc=0x80000137
7519         unlinkmany $DIR/f60c- 5000
7520         lctl set_param fail_loc=0
7521 }
7522 run_test 60c "unlink file when mds full"
7523
7524 test_60d() {
7525         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7526
7527         SAVEPRINTK=$(lctl get_param -n printk)
7528         # verify "lctl mark" is even working"
7529         MESSAGE="test message ID $RANDOM $$"
7530         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
7531         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
7532
7533         lctl set_param printk=0 || error "set lnet.printk failed"
7534         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
7535         MESSAGE="new test message ID $RANDOM $$"
7536         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
7537         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
7538         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
7539
7540         lctl set_param -n printk="$SAVEPRINTK"
7541 }
7542 run_test 60d "test printk console message masking"
7543
7544 test_60e() {
7545         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7546         remote_mds_nodsh && skip "remote MDS with nodsh"
7547
7548         touch $DIR/$tfile
7549 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
7550         do_facet mds1 lctl set_param fail_loc=0x15b
7551         rm $DIR/$tfile
7552 }
7553 run_test 60e "no space while new llog is being created"
7554
7555 test_60g() {
7556         local pid
7557         local i
7558
7559         test_mkdir -c $MDSCOUNT $DIR/$tdir
7560
7561         (
7562                 local index=0
7563                 while true; do
7564                         $LFS setdirstripe -i $(($index % $MDSCOUNT)) \
7565                                 -c $MDSCOUNT $DIR/$tdir/subdir$index \
7566                                 2>/dev/null
7567                         mkdir $DIR/$tdir/subdir$index 2>/dev/null
7568                         rmdir $DIR/$tdir/subdir$index 2>/dev/null
7569                         index=$((index + 1))
7570                 done
7571         ) &
7572
7573         pid=$!
7574
7575         for i in {0..100}; do
7576                 # define OBD_FAIL_OSD_TXN_START    0x19a
7577                 local index=$((i % MDSCOUNT + 1))
7578
7579                 do_facet mds$index $LCTL set_param fail_loc=0x8000019a \
7580                         > /dev/null
7581                 usleep 100
7582         done
7583
7584         kill -9 $pid
7585
7586         for i in $(seq $MDSCOUNT); do
7587                 do_facet mds$i $LCTL set_param fail_loc=0 > /dev/null
7588         done
7589
7590         mkdir $DIR/$tdir/new || error "mkdir failed"
7591         rmdir $DIR/$tdir/new || error "rmdir failed"
7592
7593         do_facet mds1 $LCTL lfsck_start -M $(facet_svc mds1) -A -C \
7594                 -t namespace
7595         for i in $(seq $MDSCOUNT); do
7596                 wait_update_facet mds$i "$LCTL get_param -n \
7597                         mdd.$(facet_svc mds$i).lfsck_namespace |
7598                         awk '/^status/ { print \\\$2 }'" "completed"
7599         done
7600
7601         ls -R $DIR/$tdir || error "ls failed"
7602         rm -rf $DIR/$tdir || error "rmdir failed"
7603 }
7604 run_test 60g "transaction abort won't cause MDT hung"
7605
7606 test_60h() {
7607         [ $MDS1_VERSION -le $(version_code 2.12.52) ] &&
7608                 skip "Need MDS version at least 2.12.52"
7609         [ $MDSCOUNT -lt 2 ] && skip "Need at least 2 MDTs"
7610
7611         local f
7612
7613         #define OBD_FAIL_MDS_STRIPE_CREATE       0x188
7614         #define OBD_FAIL_MDS_STRIPE_FID          0x189
7615         for fail_loc in 0x80000188 0x80000189; do
7616                 do_facet mds1 "$LCTL set_param fail_loc=$fail_loc"
7617                 $LFS mkdir -c $MDSCOUNT -i 0 $DIR/$tdir-$fail_loc ||
7618                         error "mkdir $dir-$fail_loc failed"
7619                 for i in {0..10}; do
7620                         # create may fail on missing stripe
7621                         echo $i > $DIR/$tdir-$fail_loc/$i
7622                 done
7623                 $LFS getdirstripe $DIR/$tdir-$fail_loc ||
7624                         error "getdirstripe $tdir-$fail_loc failed"
7625                 $LFS migrate -m 1 $DIR/$tdir-$fail_loc ||
7626                         error "migrate $tdir-$fail_loc failed"
7627                 $LFS getdirstripe $DIR/$tdir-$fail_loc ||
7628                         error "getdirstripe $tdir-$fail_loc failed"
7629                 pushd $DIR/$tdir-$fail_loc
7630                 for f in *; do
7631                         echo $f | cmp $f - || error "$f data mismatch"
7632                 done
7633                 popd
7634                 rm -rf $DIR/$tdir-$fail_loc
7635         done
7636 }
7637 run_test 60h "striped directory with missing stripes can be accessed"
7638
7639 test_61a() {
7640         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7641
7642         f="$DIR/f61"
7643         dd if=/dev/zero of=$f bs=$PAGE_SIZE count=1 || error "dd $f failed"
7644         cancel_lru_locks osc
7645         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
7646         sync
7647 }
7648 run_test 61a "mmap() writes don't make sync hang ================"
7649
7650 test_61b() {
7651         mmap_mknod_test $DIR/$tfile || error "mmap_mknod_test failed"
7652 }
7653 run_test 61b "mmap() of unstriped file is successful"
7654
7655 # bug 2330 - insufficient obd_match error checking causes LBUG
7656 test_62() {
7657         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7658
7659         f="$DIR/f62"
7660         echo foo > $f
7661         cancel_lru_locks osc
7662         lctl set_param fail_loc=0x405
7663         cat $f && error "cat succeeded, expect -EIO"
7664         lctl set_param fail_loc=0
7665 }
7666 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
7667 # match every page all of the time.
7668 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
7669
7670 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
7671 # Though this test is irrelevant anymore, it helped to reveal some
7672 # other grant bugs (LU-4482), let's keep it.
7673 test_63a() {   # was test_63
7674         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7675
7676         MAX_DIRTY_MB=$(lctl get_param -n osc.*.max_dirty_mb | head -n 1)
7677
7678         for i in `seq 10` ; do
7679                 dd if=/dev/zero of=$DIR/f63 bs=8k &
7680                 sleep 5
7681                 kill $!
7682                 sleep 1
7683         done
7684
7685         rm -f $DIR/f63 || true
7686 }
7687 run_test 63a "Verify oig_wait interruption does not crash ======="
7688
7689 # bug 2248 - async write errors didn't return to application on sync
7690 # bug 3677 - async write errors left page locked
7691 test_63b() {
7692         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7693
7694         debugsave
7695         lctl set_param debug=-1
7696
7697         # ensure we have a grant to do async writes
7698         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
7699         rm $DIR/$tfile
7700
7701         sync    # sync lest earlier test intercept the fail_loc
7702
7703         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7704         lctl set_param fail_loc=0x80000406
7705         $MULTIOP $DIR/$tfile Owy && \
7706                 error "sync didn't return ENOMEM"
7707         sync; sleep 2; sync     # do a real sync this time to flush page
7708         lctl get_param -n llite.*.dump_page_cache | grep locked && \
7709                 error "locked page left in cache after async error" || true
7710         debugrestore
7711 }
7712 run_test 63b "async write errors should be returned to fsync ==="
7713
7714 test_64a () {
7715         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7716
7717         lfs df $DIR
7718         lctl get_param osc.*[oO][sS][cC][_-]*.cur* | grep "=[1-9]"
7719 }
7720 run_test 64a "verify filter grant calculations (in kernel) ====="
7721
7722 test_64b () {
7723         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7724
7725         sh oos.sh $MOUNT || error "oos.sh failed: $?"
7726 }
7727 run_test 64b "check out-of-space detection on client"
7728
7729 test_64c() {
7730         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
7731 }
7732 run_test 64c "verify grant shrink"
7733
7734 # this does exactly what osc_request.c:osc_announce_cached() does in
7735 # order to calculate max amount of grants to ask from server
7736 want_grant() {
7737         local tgt=$1
7738
7739         local nrpages=$($LCTL get_param -n osc.${tgt}.max_pages_per_rpc)
7740         local rpc_in_flight=$($LCTL get_param -n osc.${tgt}.max_rpcs_in_flight)
7741
7742         ((rpc_in_flight ++));
7743         nrpages=$((nrpages * rpc_in_flight))
7744
7745         local dirty_max_pages=$($LCTL get_param -n osc.${tgt}.max_dirty_mb)
7746
7747         dirty_max_pages=$((dirty_max_pages * 1024 * 1024 / PAGE_SIZE))
7748
7749         [[ $dirty_max_pages -gt $nrpages ]] && nrpages=$dirty_max_pages
7750         local undirty=$((nrpages * PAGE_SIZE))
7751
7752         local max_extent_pages
7753         max_extent_pages=$($LCTL get_param osc.${tgt}.import |
7754             grep grant_max_extent_size | awk '{print $2}')
7755         max_extent_pages=$((max_extent_pages / PAGE_SIZE))
7756         local nrextents=$(((nrpages + max_extent_pages - 1) / max_extent_pages))
7757         local grant_extent_tax
7758         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
7759             grep grant_extent_tax | awk '{print $2}')
7760
7761         undirty=$((undirty + nrextents * grant_extent_tax))
7762
7763         echo $undirty
7764 }
7765
7766 # this is size of unit for grant allocation. It should be equal to
7767 # what tgt_grant.c:tgt_grant_chunk() calculates
7768 grant_chunk() {
7769         local tgt=$1
7770         local max_brw_size
7771         local grant_extent_tax
7772
7773         max_brw_size=$($LCTL get_param osc.${tgt}.import |
7774             grep max_brw_size | awk '{print $2}')
7775
7776         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
7777             grep grant_extent_tax | awk '{print $2}')
7778
7779         echo $(((max_brw_size + grant_extent_tax) * 2))
7780 }
7781
7782 test_64d() {
7783         [ $OST1_VERSION -lt $(version_code 2.10.56) ] &&
7784                 skip "OST < 2.10.55 doesn't limit grants enough"
7785
7786         local tgt=$($LCTL dl | grep "0000-osc-[^mM]" | awk '{print $4}')
7787         local file=$DIR/$tfile
7788
7789         [[ $($LCTL get_param osc.${tgt}.import |
7790              grep "connect_flags:.*grant_param") ]] ||
7791                 skip "no grant_param connect flag"
7792
7793         local olddebug=$($LCTL get_param -n debug 2> /dev/null)
7794
7795         $LCTL set_param debug="$OLDDEBUG" 2> /dev/null || true
7796
7797         local max_cur_granted=$(($(want_grant $tgt) + $(grant_chunk $tgt)))
7798         stack_trap "rm -f $file" EXIT
7799
7800         $LFS setstripe $file -i 0 -c 1
7801         dd if=/dev/zero of=$file bs=1M count=1000 &
7802         ddpid=$!
7803
7804         while true
7805         do
7806                 local cur_grant=$($LCTL get_param -n osc.${tgt}.cur_grant_bytes)
7807                 if [[ $cur_grant -gt $max_cur_granted ]]
7808                 then
7809                         kill $ddpid
7810                         error "cur_grant $cur_grant > $max_cur_granted"
7811                 fi
7812                 kill -0 $ddpid
7813                 [[ $? -ne 0 ]] && break;
7814                 sleep 2
7815         done
7816
7817         rm -f $DIR/$tfile
7818         wait_delete_completed
7819         $LCTL set_param debug="$olddebug" 2> /dev/null || true
7820 }
7821 run_test 64d "check grant limit exceed"
7822
7823 # bug 1414 - set/get directories' stripe info
7824 test_65a() {
7825         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7826
7827         test_mkdir $DIR/$tdir
7828         touch $DIR/$tdir/f1
7829         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
7830 }
7831 run_test 65a "directory with no stripe info"
7832
7833 test_65b() {
7834         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7835
7836         test_mkdir $DIR/$tdir
7837         local STRIPESIZE=$($LFS getstripe -S $DIR/$tdir)
7838
7839         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
7840                                                 error "setstripe"
7841         touch $DIR/$tdir/f2
7842         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
7843 }
7844 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
7845
7846 test_65c() {
7847         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7848         [ $OSTCOUNT -lt 2 ] && skip_env "need at least 2 OSTs"
7849
7850         test_mkdir $DIR/$tdir
7851         local stripesize=$($LFS getstripe -S $DIR/$tdir)
7852
7853         $LFS setstripe -S $((stripesize * 4)) -i 1 \
7854                 -c $((OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
7855         touch $DIR/$tdir/f3
7856         $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
7857 }
7858 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
7859
7860 test_65d() {
7861         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7862
7863         test_mkdir $DIR/$tdir
7864         local STRIPECOUNT=$($LFS getstripe -c $DIR/$tdir)
7865         local STRIPESIZE=$($LFS getstripe -S $DIR/$tdir)
7866
7867         if [[ $STRIPECOUNT -le 0 ]]; then
7868                 sc=1
7869         elif [[ $STRIPECOUNT -gt $LOV_MAX_STRIPE_COUNT ]]; then
7870                 [[ $OSTCOUNT -gt $LOV_MAX_STRIPE_COUNT ]] &&
7871                         sc=$LOV_MAX_STRIPE_COUNT || sc=$(($OSTCOUNT - 1))
7872         else
7873                 sc=$(($STRIPECOUNT - 1))
7874         fi
7875         $LFS setstripe -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
7876         touch $DIR/$tdir/f4 $DIR/$tdir/f5
7877         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
7878                 error "lverify failed"
7879 }
7880 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
7881
7882 test_65e() {
7883         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7884
7885         test_mkdir $DIR/$tdir
7886
7887         $LFS setstripe $DIR/$tdir || error "setstripe"
7888         $LFS getstripe -v $DIR/$tdir | grep "Default" ||
7889                                         error "no stripe info failed"
7890         touch $DIR/$tdir/f6
7891         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
7892 }
7893 run_test 65e "directory setstripe defaults"
7894
7895 test_65f() {
7896         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7897
7898         test_mkdir $DIR/${tdir}f
7899         $RUNAS $LFS setstripe $DIR/${tdir}f &&
7900                 error "setstripe succeeded" || true
7901 }
7902 run_test 65f "dir setstripe permission (should return error) ==="
7903
7904 test_65g() {
7905         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7906
7907         test_mkdir $DIR/$tdir
7908         local STRIPESIZE=$($LFS getstripe -S $DIR/$tdir)
7909
7910         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
7911                 error "setstripe -S failed"
7912         $LFS setstripe -d $DIR/$tdir || error "setstripe -d failed"
7913         $LFS getstripe -v $DIR/$tdir | grep "Default" ||
7914                 error "delete default stripe failed"
7915 }
7916 run_test 65g "directory setstripe -d"
7917
7918 test_65h() {
7919         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7920
7921         test_mkdir $DIR/$tdir
7922         local STRIPESIZE=$($LFS getstripe -S $DIR/$tdir)
7923
7924         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
7925                 error "setstripe -S failed"
7926         test_mkdir $DIR/$tdir/dd1
7927         [ $($LFS getstripe -c $DIR/$tdir) = $($LFS getstripe -c $DIR/$tdir/dd1) ] ||
7928                 error "stripe info inherit failed"
7929 }
7930 run_test 65h "directory stripe info inherit ===================="
7931
7932 test_65i() {
7933         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7934
7935         save_layout_restore_at_exit $MOUNT
7936
7937         # bug6367: set non-default striping on root directory
7938         $LFS setstripe -S 65536 -c -1 $MOUNT || error "error setting stripe"
7939
7940         # bug12836: getstripe on -1 default directory striping
7941         $LFS getstripe $MOUNT || error "getstripe $MOUNT failed"
7942
7943         # bug12836: getstripe -v on -1 default directory striping
7944         $LFS getstripe -v $MOUNT || error "getstripe -v $MOUNT failed"
7945
7946         # bug12836: new find on -1 default directory striping
7947         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
7948 }
7949 run_test 65i "various tests to set root directory striping"
7950
7951 test_65j() { # bug6367
7952         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7953
7954         sync; sleep 1
7955
7956         # if we aren't already remounting for each test, do so for this test
7957         if [ "$I_MOUNTED" = "yes" ]; then
7958                 cleanup || error "failed to unmount"
7959                 setup
7960         fi
7961
7962         save_layout_restore_at_exit $MOUNT
7963
7964         $LFS setstripe -d $MOUNT || error "setstripe failed"
7965 }
7966 run_test 65j "set default striping on root directory (bug 6367)="
7967
7968 cleanup_65k() {
7969         rm -rf $DIR/$tdir
7970         wait_delete_completed
7971         do_facet $SINGLEMDS "lctl set_param -n \
7972                 osp.$ost*MDT0000.max_create_count=$max_count"
7973         do_facet $SINGLEMDS "lctl set_param -n \
7974                 osp.$ost*MDT0000.create_count=$count"
7975         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
7976         echo $INACTIVE_OSC "is Activate"
7977
7978         wait_osc_import_state mds ost$(( ostnum + 1 )) FULL
7979 }
7980
7981 test_65k() { # bug11679
7982         [ $PARALLEL == "yes" ] && skip "skip parallel run"
7983         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
7984         remote_mds_nodsh && skip "remote MDS with nodsh"
7985
7986         local disable_precreate=true
7987         [ $MDS1_VERSION -le $(version_code 2.8.54) ] &&
7988                 disable_precreate=false
7989
7990         echo "Check OST status: "
7991         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
7992                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
7993
7994         for OSC in $MDS_OSCS; do
7995                 echo $OSC "is active"
7996                 do_facet $SINGLEMDS lctl --device %$OSC activate
7997         done
7998
7999         for INACTIVE_OSC in $MDS_OSCS; do
8000                 local ost=$(osc_to_ost $INACTIVE_OSC)
8001                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
8002                                lov.*md*.target_obd |
8003                                awk -F: /$ost/'{ print $1 }' | head -n 1)
8004
8005                 mkdir -p $DIR/$tdir
8006                 $LFS setstripe -i $ostnum -c 1 $DIR/$tdir
8007                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
8008
8009                 echo "Deactivate: " $INACTIVE_OSC
8010                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
8011
8012                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
8013                               osp.$ost*MDT0000.create_count")
8014                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
8015                                   osp.$ost*MDT0000.max_create_count")
8016                 $disable_precreate &&
8017                         do_facet $SINGLEMDS "lctl set_param -n \
8018                                 osp.$ost*MDT0000.max_create_count=0"
8019
8020                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
8021                         [ -f $DIR/$tdir/$idx ] && continue
8022                         echo "$LFS setstripe -i $idx -c 1 $DIR/$tdir/$idx"
8023                         $LFS setstripe -i $idx -c 1 $DIR/$tdir/$idx ||
8024                                 { cleanup_65k;
8025                                   error "setstripe $idx should succeed"; }
8026                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
8027                 done
8028                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
8029                 rmdir $DIR/$tdir
8030
8031                 do_facet $SINGLEMDS "lctl set_param -n \
8032                         osp.$ost*MDT0000.max_create_count=$max_count"
8033                 do_facet $SINGLEMDS "lctl set_param -n \
8034                         osp.$ost*MDT0000.create_count=$count"
8035                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
8036                 echo $INACTIVE_OSC "is Activate"
8037
8038                 wait_osc_import_state mds ost$(( ostnum + 1 )) FULL
8039         done
8040 }
8041 run_test 65k "validate manual striping works properly with deactivated OSCs"
8042
8043 test_65l() { # bug 12836
8044         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8045
8046         test_mkdir -p $DIR/$tdir/test_dir
8047         $LFS setstripe -c -1 $DIR/$tdir/test_dir
8048         $LFS find -mtime -1 $DIR/$tdir >/dev/null
8049 }
8050 run_test 65l "lfs find on -1 stripe dir ========================"
8051
8052 test_65m() {
8053         local layout=$(save_layout $MOUNT)
8054         $RUNAS $LFS setstripe -c 2 $MOUNT && {
8055                 restore_layout $MOUNT $layout
8056                 error "setstripe should fail by non-root users"
8057         }
8058         true
8059 }
8060 run_test 65m "normal user can't set filesystem default stripe"
8061
8062 test_65n() {
8063         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
8064         [[ $MDS1_VERSION -ge $(version_code 2.12.50) ]] ||
8065                 skip "Need MDS version at least 2.12.50"
8066         [[ $PARALLEL != "yes" ]] || skip "skip parallel run"
8067
8068         [[ $OSTCOUNT -ge 2 ]] || skip_env "needs >= 2 OSTs"
8069         which getfattr > /dev/null 2>&1 || skip_env "no getfattr command"
8070         which setfattr > /dev/null 2>&1 || skip_env "no setfattr command"
8071
8072         local root_layout=$(save_layout $MOUNT)
8073         stack_trap "restore_layout $MOUNT $root_layout" EXIT
8074
8075         # new subdirectory under root directory should not inherit
8076         # the default layout from root
8077         local dir1=$MOUNT/$tdir-1
8078         mkdir $dir1 || error "mkdir $dir1 failed"
8079         ! getfattr -n trusted.lov $dir1 &> /dev/null ||
8080                 error "$dir1 shouldn't have LOV EA"
8081
8082         # delete the default layout on root directory
8083         $LFS setstripe -d $MOUNT || error "delete root default layout failed"
8084
8085         local dir2=$MOUNT/$tdir-2
8086         mkdir $dir2 || error "mkdir $dir2 failed"
8087         ! getfattr -n trusted.lov $dir2 &> /dev/null ||
8088                 error "$dir2 shouldn't have LOV EA"
8089
8090         # set a new striping pattern on root directory
8091         local def_stripe_size=$($LFS getstripe -S $MOUNT)
8092         local new_def_stripe_size=$((def_stripe_size * 2))
8093         $LFS setstripe -S $new_def_stripe_size $MOUNT ||
8094                 error "set stripe size on $MOUNT failed"
8095
8096         # new file created in $dir2 should inherit the new stripe size from
8097         # the filesystem default
8098         local file2=$dir2/$tfile-2
8099         touch $file2 || error "touch $file2 failed"
8100
8101         local file2_stripe_size=$($LFS getstripe -S $file2)
8102         [[ $file2_stripe_size -eq $new_def_stripe_size ]] ||
8103                 error "$file2 didn't inherit stripe size $new_def_stripe_size"
8104
8105         local dir3=$MOUNT/$tdir-3
8106         mkdir $dir3 || error "mkdir $dir3 failed"
8107         # $dir3 shouldn't have LOV EA, but "lfs getstripe -d $dir3" should show
8108         # the root layout, which is the actual default layout that will be used
8109         # when new files are created in $dir3.
8110         local dir3_layout=$(get_layout_param $dir3)
8111         local root_dir_layout=$(get_layout_param $MOUNT)
8112         [[ "$dir3_layout" = "$root_dir_layout" ]] ||
8113                 error "$dir3 should show the default layout from $MOUNT"
8114
8115         # set OST pool on root directory
8116         local pool=$TESTNAME
8117         pool_add $pool || error "add $pool failed"
8118         pool_add_targets $pool 0 $((OSTCOUNT - 1)) 1 ||
8119                 error "add targets to $pool failed"
8120
8121         $LFS setstripe -p $pool $MOUNT ||
8122                 error "set OST pool on $MOUNT failed"
8123
8124         # new file created in $dir3 should inherit the pool from
8125         # the filesystem default
8126         local file3=$dir3/$tfile-3
8127         touch $file3 || error "touch $file3 failed"
8128
8129         local file3_pool=$($LFS getstripe -p $file3)
8130         [[ "$file3_pool" = "$pool" ]] ||
8131                 error "$file3 didn't inherit OST pool $pool"
8132
8133         local dir4=$MOUNT/$tdir-4
8134         mkdir $dir4 || error "mkdir $dir4 failed"
8135         local dir4_layout=$(get_layout_param $dir4)
8136         root_dir_layout=$(get_layout_param $MOUNT)
8137         echo "$LFS getstripe -d $dir4"
8138         $LFS getstripe -d $dir4
8139         echo "$LFS getstripe -d $MOUNT"
8140         $LFS getstripe -d $MOUNT
8141         [[ "$dir4_layout" = "$root_dir_layout" ]] ||
8142                 error "$dir4 should show the default layout from $MOUNT"
8143
8144         # new file created in $dir4 should inherit the pool from
8145         # the filesystem default
8146         local file4=$dir4/$tfile-4
8147         touch $file4 || error "touch $file4 failed"
8148
8149         local file4_pool=$($LFS getstripe -p $file4)
8150         [[ "$file4_pool" = "$pool" ]] ||
8151                 error "$file4 didn't inherit OST pool $pool"
8152
8153         # new subdirectory under non-root directory should inherit
8154         # the default layout from its parent directory
8155         $LFS setstripe -S $new_def_stripe_size -p $pool $dir4 ||
8156                 error "set directory layout on $dir4 failed"
8157
8158         local dir5=$dir4/$tdir-5
8159         mkdir $dir5 || error "mkdir $dir5 failed"
8160
8161         dir4_layout=$(get_layout_param $dir4)
8162         local dir5_layout=$(get_layout_param $dir5)
8163         [[ "$dir4_layout" = "$dir5_layout" ]] ||
8164                 error "$dir5 should inherit the default layout from $dir4"
8165
8166         # though subdir under ROOT doesn't inherit default layout, but
8167         # its sub dir/file should be created with default layout.
8168         [[ $MDSCOUNT -ge 2 ]] || skip_env "needs >= 2 MDTs"
8169         [[ $MDS1_VERSION -ge $(version_code 2.12.59) ]] ||
8170                 skip "Need MDS version at least 2.12.59"
8171
8172         local default_lmv_count=$($LFS getdirstripe -D -c $MOUNT)
8173         local default_lmv_index=$($LFS getdirstripe -D -i $MOUNT)
8174         local default_lmv_hash=$($LFS getdirstripe -D -H $MOUNT)
8175
8176         if [ $default_lmv_hash == "none" ]; then
8177                 stack_trap "$LFS setdirstripe -D -d $MOUNT" EXIT
8178         else
8179                 stack_trap "$LFS setdirstripe -D -i $default_lmv_index \
8180                         -c $default_lmv_count -H $default_lmv_hash $MOUNT" EXIT
8181         fi
8182
8183         $LFS setdirstripe -D -c 2 $MOUNT ||
8184                 error "setdirstripe -D -c 2 failed"
8185         mkdir $MOUNT/$tdir-6 || error "mkdir $tdir-6 failed"
8186         local lmv_count=$($LFS getdirstripe -c $MOUNT/$tdir-6)
8187         [ $lmv_count -eq 2 ] || error "$tdir-6 stripe count $lmv_count"
8188 }
8189 run_test 65n "don't inherit default layout from root for new subdirectories"
8190
8191 # bug 2543 - update blocks count on client
8192 test_66() {
8193         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8194
8195         COUNT=${COUNT:-8}
8196         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
8197         sync; sync_all_data; sync; sync_all_data
8198         cancel_lru_locks osc
8199         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
8200         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
8201 }
8202 run_test 66 "update inode blocks count on client ==============="
8203
8204 meminfo() {
8205         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
8206 }
8207
8208 swap_used() {
8209         swapon -s | awk '($1 == "'$1'") { print $4 }'
8210 }
8211
8212 # bug5265, obdfilter oa2dentry return -ENOENT
8213 # #define OBD_FAIL_SRV_ENOENT 0x217
8214 test_69() {
8215         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8216         remote_ost_nodsh && skip "remote OST with nodsh"
8217
8218         f="$DIR/$tfile"
8219         $LFS setstripe -c 1 -i 0 $f
8220
8221         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
8222
8223         do_facet ost1 lctl set_param fail_loc=0x217
8224         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
8225         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
8226
8227         do_facet ost1 lctl set_param fail_loc=0
8228         $DIRECTIO write $f 0 2 || error "write error"
8229
8230         cancel_lru_locks osc
8231         $DIRECTIO read $f 0 1 || error "read error"
8232
8233         do_facet ost1 lctl set_param fail_loc=0x217
8234         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
8235
8236         do_facet ost1 lctl set_param fail_loc=0
8237         rm -f $f
8238 }
8239 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
8240
8241 test_71() {
8242         test_mkdir $DIR/$tdir
8243         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
8244         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
8245 }
8246 run_test 71 "Running dbench on lustre (don't segment fault) ===="
8247
8248 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
8249         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8250         [ "$RUNAS_ID" = "$UID" ] &&
8251                 skip_env "RUNAS_ID = UID = $UID -- skipping"
8252         # Check that testing environment is properly set up. Skip if not
8253         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS ||
8254                 skip_env "User $RUNAS_ID does not exist - skipping"
8255
8256         touch $DIR/$tfile
8257         chmod 777 $DIR/$tfile
8258         chmod ug+s $DIR/$tfile
8259         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
8260                 error "$RUNAS dd $DIR/$tfile failed"
8261         # See if we are still setuid/sgid
8262         [ -u $DIR/$tfile ] || [ -g $DIR/$tfile ] &&
8263                 error "S/gid is not dropped on write"
8264         # Now test that MDS is updated too
8265         cancel_lru_locks mdc
8266         [ -u $DIR/$tfile ] || [ -g $DIR/$tfile ] &&
8267                 error "S/gid is not dropped on MDS"
8268         rm -f $DIR/$tfile
8269 }
8270 run_test 72a "Test that remove suid works properly (bug5695) ===="
8271
8272 test_72b() { # bug 24226 -- keep mode setting when size is not changing
8273         local perm
8274
8275         [ "$RUNAS_ID" = "$UID" ] &&
8276                 skip_env "RUNAS_ID = UID = $UID -- skipping"
8277         [ "$RUNAS_ID" -eq 0 ] &&
8278                 skip_env "RUNAS_ID = 0 -- skipping"
8279         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8280         # Check that testing environment is properly set up. Skip if not
8281         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS ||
8282                 skip_env "User $RUNAS_ID does not exist - skipping"
8283
8284         touch $DIR/${tfile}-f{g,u}
8285         test_mkdir $DIR/${tfile}-dg
8286         test_mkdir $DIR/${tfile}-du
8287         chmod 770 $DIR/${tfile}-{f,d}{g,u}
8288         chmod g+s $DIR/${tfile}-{f,d}g
8289         chmod u+s $DIR/${tfile}-{f,d}u
8290         for perm in 777 2777 4777; do
8291                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
8292                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
8293                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
8294                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
8295         done
8296         true
8297 }
8298 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
8299
8300 # bug 3462 - multiple simultaneous MDC requests
8301 test_73() {
8302         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8303
8304         test_mkdir $DIR/d73-1
8305         test_mkdir $DIR/d73-2
8306         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
8307         pid1=$!
8308
8309         lctl set_param fail_loc=0x80000129
8310         $MULTIOP $DIR/d73-1/f73-2 Oc &
8311         sleep 1
8312         lctl set_param fail_loc=0
8313
8314         $MULTIOP $DIR/d73-2/f73-3 Oc &
8315         pid3=$!
8316
8317         kill -USR1 $pid1
8318         wait $pid1 || return 1
8319
8320         sleep 25
8321
8322         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
8323         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
8324         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
8325
8326         rm -rf $DIR/d73-*
8327 }
8328 run_test 73 "multiple MDC requests (should not deadlock)"
8329
8330 test_74a() { # bug 6149, 6184
8331         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8332
8333         touch $DIR/f74a
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 any lock that won't be difficult - lookup works.
8340         ls $DIR/f74a
8341         $LCTL set_param fail_loc=0
8342         rm -f $DIR/f74a
8343         true
8344 }
8345 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
8346
8347 test_74b() { # bug 13310
8348         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8349
8350         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
8351         #
8352         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
8353         # will spin in a tight reconnection loop
8354         $LCTL set_param fail_loc=0x8000030e
8355         # get a "difficult" lock
8356         touch $DIR/f74b
8357         $LCTL set_param fail_loc=0
8358         rm -f $DIR/f74b
8359         true
8360 }
8361 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
8362
8363 test_74c() {
8364         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8365
8366         #define OBD_FAIL_LDLM_NEW_LOCK
8367         $LCTL set_param fail_loc=0x319
8368         touch $DIR/$tfile && error "touch successful"
8369         $LCTL set_param fail_loc=0
8370         true
8371 }
8372 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
8373
8374 num_inodes() {
8375         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
8376 }
8377
8378 test_76() { # Now for bug 20433, added originally in bug 1443
8379         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8380
8381         cancel_lru_locks osc
8382         local cpus=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
8383         local before=$(num_inodes)
8384         local count=$((512 * cpus))
8385         [ "$SLOW" = "no" ] && count=$((64 * cpus))
8386
8387         echo "before inodes: $before"
8388         for i in $(seq $count); do
8389                 touch $DIR/$tfile
8390                 rm -f $DIR/$tfile
8391         done
8392         cancel_lru_locks osc
8393         local after=$(num_inodes)
8394         echo "after inodes: $after"
8395         while (( after > before + 8 * ${cpus:-1} )); do
8396                 sleep 1
8397                 after=$(num_inodes)
8398                 wait=$((wait + 1))
8399                 (( wait % 5 == 0 )) && echo "wait $wait seconds inodes: $after"
8400                 if (( wait > 30 )); then
8401                         error "inode slab grew from $before to $after"
8402                 fi
8403         done
8404 }
8405 run_test 76 "confirm clients recycle inodes properly ===="
8406
8407
8408 export ORIG_CSUM=""
8409 set_checksums()
8410 {
8411         # Note: in sptlrpc modes which enable its own bulk checksum, the
8412         # original crc32_le bulk checksum will be automatically disabled,
8413         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
8414         # will be checked by sptlrpc code against sptlrpc bulk checksum.
8415         # In this case set_checksums() will not be no-op, because sptlrpc
8416         # bulk checksum will be enabled all through the test.
8417
8418         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
8419         lctl set_param -n osc.*.checksums $1
8420         return 0
8421 }
8422
8423 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
8424                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
8425 CKSUM_TYPES=${CKSUM_TYPES:-$(lctl get_param -n osc.*osc-[^mM]*.checksum_type |
8426                              tr -d [] | head -n1)}
8427 set_checksum_type()
8428 {
8429         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
8430         rc=$?
8431         log "set checksum type to $1, rc = $rc"
8432         return $rc
8433 }
8434
8435 get_osc_checksum_type()
8436 {
8437         # arugment 1: OST name, like OST0000
8438         ost=$1
8439         checksum_type=$(lctl get_param -n osc.*${ost}-osc-[^mM]*.checksum_type |
8440                         sed 's/.*\[\(.*\)\].*/\1/g')
8441         rc=$?
8442         [ $rc -ne 0 ] && error "failed to get checksum type of $ost, rc = $rc, output = $checksum_type"
8443         echo $checksum_type
8444 }
8445
8446 F77_TMP=$TMP/f77-temp
8447 F77SZ=8
8448 setup_f77() {
8449         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
8450                 error "error writing to $F77_TMP"
8451 }
8452
8453 test_77a() { # bug 10889
8454         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8455         $GSS && skip_env "could not run with gss"
8456
8457         [ ! -f $F77_TMP ] && setup_f77
8458         set_checksums 1
8459         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
8460         set_checksums 0
8461         rm -f $DIR/$tfile
8462 }
8463 run_test 77a "normal checksum read/write operation"
8464
8465 test_77b() { # bug 10889
8466         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8467         $GSS && skip_env "could not run with gss"
8468
8469         [ ! -f $F77_TMP ] && setup_f77
8470         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
8471         $LCTL set_param fail_loc=0x80000409
8472         set_checksums 1
8473
8474         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
8475                 error "dd error: $?"
8476         $LCTL set_param fail_loc=0
8477
8478         for algo in $CKSUM_TYPES; do
8479                 cancel_lru_locks osc
8480                 set_checksum_type $algo
8481                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
8482                 $LCTL set_param fail_loc=0x80000408
8483                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
8484                 $LCTL set_param fail_loc=0
8485         done
8486         set_checksums 0
8487         set_checksum_type $ORIG_CSUM_TYPE
8488         rm -f $DIR/$tfile
8489 }
8490 run_test 77b "checksum error on client write, read"
8491
8492 cleanup_77c() {
8493         trap 0
8494         set_checksums 0
8495         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
8496         $check_ost &&
8497                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
8498         [ -n "$osc_file_prefix" ] && rm -f ${osc_file_prefix}*
8499         $check_ost && [ -n "$ost_file_prefix" ] &&
8500                 do_facet ost1 rm -f ${ost_file_prefix}\*
8501 }
8502
8503 test_77c() {
8504         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8505         $GSS && skip_env "could not run with gss"
8506         remote_ost_nodsh && skip "remote OST with nodsh"
8507
8508         local bad1
8509         local osc_file_prefix
8510         local osc_file
8511         local check_ost=false
8512         local ost_file_prefix
8513         local ost_file
8514         local orig_cksum
8515         local dump_cksum
8516         local fid
8517
8518         # ensure corruption will occur on first OSS/OST
8519         $LFS setstripe -i 0 $DIR/$tfile
8520
8521         [ ! -f $F77_TMP ] && setup_f77
8522         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
8523                 error "dd write error: $?"
8524         fid=$($LFS path2fid $DIR/$tfile)
8525
8526         if [ $OST1_VERSION -ge $(version_code 2.9.57) ]
8527         then
8528                 check_ost=true
8529                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
8530                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
8531         else
8532                 echo "OSS do not support bulk pages dump upon error"
8533         fi
8534
8535         osc_file_prefix=$($LCTL get_param -n debug_path)
8536         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
8537
8538         trap cleanup_77c EXIT
8539
8540         set_checksums 1
8541         # enable bulk pages dump upon error on Client
8542         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
8543         # enable bulk pages dump upon error on OSS
8544         $check_ost &&
8545                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
8546
8547         # flush Client cache to allow next read to reach OSS
8548         cancel_lru_locks osc
8549
8550         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
8551         $LCTL set_param fail_loc=0x80000408
8552         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
8553         $LCTL set_param fail_loc=0
8554
8555         rm -f $DIR/$tfile
8556
8557         # check cksum dump on Client
8558         osc_file=$(ls ${osc_file_prefix}*)
8559         [ -n "$osc_file" ] || error "no checksum dump file on Client"
8560         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
8561         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
8562         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
8563         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
8564                      cksum)
8565         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
8566         [[ "$orig_cksum" == "$dump_cksum" ]] ||
8567                 error "dump content does not match on Client"
8568
8569         $check_ost || skip "No need to check cksum dump on OSS"
8570
8571         # check cksum dump on OSS
8572         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
8573         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
8574         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
8575         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
8576         [[ "$orig_cksum" == "$dump_cksum" ]] ||
8577                 error "dump content does not match on OSS"
8578
8579         cleanup_77c
8580 }
8581 run_test 77c "checksum error on client read with debug"
8582
8583 test_77d() { # bug 10889
8584         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8585         $GSS && skip_env "could not run with gss"
8586
8587         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
8588         $LCTL set_param fail_loc=0x80000409
8589         set_checksums 1
8590         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
8591                 error "direct write: rc=$?"
8592         $LCTL set_param fail_loc=0
8593         set_checksums 0
8594
8595         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
8596         $LCTL set_param fail_loc=0x80000408
8597         set_checksums 1
8598         cancel_lru_locks osc
8599         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
8600                 error "direct read: rc=$?"
8601         $LCTL set_param fail_loc=0
8602         set_checksums 0
8603 }
8604 run_test 77d "checksum error on OST direct write, read"
8605
8606 test_77f() { # bug 10889
8607         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8608         $GSS && skip_env "could not run with gss"
8609
8610         set_checksums 1
8611         for algo in $CKSUM_TYPES; do
8612                 cancel_lru_locks osc
8613                 set_checksum_type $algo
8614                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
8615                 $LCTL set_param fail_loc=0x409
8616                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
8617                         error "direct write succeeded"
8618                 $LCTL set_param fail_loc=0
8619         done
8620         set_checksum_type $ORIG_CSUM_TYPE
8621         set_checksums 0
8622 }
8623 run_test 77f "repeat checksum error on write (expect error)"
8624
8625 test_77g() { # bug 10889
8626         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8627         $GSS && skip_env "could not run with gss"
8628         remote_ost_nodsh && skip "remote OST with nodsh"
8629
8630         [ ! -f $F77_TMP ] && setup_f77
8631
8632         local file=$DIR/$tfile
8633         stack_trap "rm -f $file" EXIT
8634
8635         $LFS setstripe -c 1 -i 0 $file
8636         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
8637         do_facet ost1 lctl set_param fail_loc=0x8000021a
8638         set_checksums 1
8639         dd if=$F77_TMP of=$file bs=1M count=$F77SZ ||
8640                 error "write error: rc=$?"
8641         do_facet ost1 lctl set_param fail_loc=0
8642         set_checksums 0
8643
8644         cancel_lru_locks osc
8645         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
8646         do_facet ost1 lctl set_param fail_loc=0x8000021b
8647         set_checksums 1
8648         cmp $F77_TMP $file || error "file compare failed"
8649         do_facet ost1 lctl set_param fail_loc=0
8650         set_checksums 0
8651 }
8652 run_test 77g "checksum error on OST write, read"
8653
8654 test_77k() { # LU-10906
8655         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8656         $GSS && skip_env "could not run with gss"
8657
8658         local cksum_param="osc.$FSNAME*.checksums"
8659         local get_checksum="$LCTL get_param -n $cksum_param | head -n1"
8660         local checksum
8661         local i
8662
8663         [ "$ORIG_CSUM" ] || ORIG_CSUM=$(eval $get_checksum)
8664         stack_trap "wait_update $HOSTNAME '$get_checksum' $ORIG_CSUM" EXIT
8665         stack_trap "do_facet mgs $LCTL set_param -P $cksum_param=$ORIG_CSUM" \
8666                 EXIT
8667
8668         for i in 0 1; do
8669                 do_facet mgs $LCTL set_param -P $cksum_param=$i ||
8670                         error "failed to set checksum=$i on MGS"
8671                 wait_update $HOSTNAME "$get_checksum" $i
8672                 #remount
8673                 echo "remount client, checksum should be $i"
8674                 remount_client $MOUNT || error "failed to remount client"
8675                 checksum=$(eval $get_checksum)
8676                 [ $checksum -eq $i ] || error "checksum($checksum) != $i"
8677         done
8678         # remove persistent param to avoid races with checksum mountopt below
8679         do_facet mgs $LCTL set_param -P -d $cksum_param ||
8680                 error "failed to delete checksum on MGS"
8681
8682         for opt in "checksum" "nochecksum"; do
8683                 #remount with mount option
8684                 echo "remount client with option $opt, checksum should be $i"
8685                 umount_client $MOUNT || error "failed to umount client"
8686                 mount_client $MOUNT "$MOUNT_OPTS,$opt" ||
8687                         error "failed to mount client with option '$opt'"
8688                 checksum=$(eval $get_checksum)
8689                 [ $checksum -eq $i ] || error "checksum($checksum) != $i"
8690                 i=$((i - 1))
8691         done
8692
8693         remount_client $MOUNT || error "failed to remount client"
8694 }
8695 run_test 77k "enable/disable checksum correctly"
8696
8697 test_77l() {
8698         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8699         $GSS && skip_env "could not run with gss"
8700
8701         set_checksums 1
8702         stack_trap "set_checksums $ORIG_CSUM" EXIT
8703         stack_trap "set_checksum_type $ORIG_CSUM_TYPE" EXIT
8704
8705         set_checksum_type invalid && error "unexpected success of invalid checksum type"
8706
8707         $LFS setstripe -c 1 -i 0 $DIR/$tfile
8708         for algo in $CKSUM_TYPES; do
8709                 set_checksum_type $algo || error "fail to set checksum type $algo"
8710                 osc_algo=$(get_osc_checksum_type OST0000)
8711                 [ "$osc_algo" != "$algo" ] && error "checksum type is $osc_algo after setting it to $algo"
8712
8713                 # no locks, no reqs to let the connection idle
8714                 cancel_lru_locks osc
8715                 lru_resize_disable osc
8716                 wait_osc_import_state client ost1 IDLE
8717
8718                 # ensure ost1 is connected
8719                 stat $DIR/$tfile >/dev/null || error "can't stat"
8720                 wait_osc_import_state client ost1 FULL
8721
8722                 osc_algo=$(get_osc_checksum_type OST0000)
8723                 [ "$osc_algo" != "$algo" ] && error "checksum type changed from $algo to $osc_algo after reconnection"
8724         done
8725         return 0
8726 }
8727 run_test 77l "preferred checksum type is remembered after reconnected"
8728
8729 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
8730 rm -f $F77_TMP
8731 unset F77_TMP
8732
8733 cleanup_test_78() {
8734         trap 0
8735         rm -f $DIR/$tfile
8736 }
8737
8738 test_78() { # bug 10901
8739         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8740         remote_ost || skip_env "local OST"
8741
8742         NSEQ=5
8743         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
8744         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
8745         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
8746         echo "MemTotal: $MEMTOTAL"
8747
8748         # reserve 256MB of memory for the kernel and other running processes,
8749         # and then take 1/2 of the remaining memory for the read/write buffers.
8750         if [ $MEMTOTAL -gt 512 ] ;then
8751                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
8752         else
8753                 # for those poor memory-starved high-end clusters...
8754                 MEMTOTAL=$((MEMTOTAL / 2))
8755         fi
8756         echo "Mem to use for directio: $MEMTOTAL"
8757
8758         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
8759         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
8760         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
8761         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
8762                 head -n1)
8763         echo "Smallest OST: $SMALLESTOST"
8764         [[ $SMALLESTOST -lt 10240 ]] &&
8765                 skip "too small OSTSIZE, useless to run large O_DIRECT test"
8766
8767         trap cleanup_test_78 EXIT
8768
8769         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
8770                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
8771
8772         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
8773         echo "File size: $F78SIZE"
8774         $LFS setstripe -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
8775         for i in $(seq 1 $NSEQ); do
8776                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
8777                 echo directIO rdwr round $i of $NSEQ
8778                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
8779         done
8780
8781         cleanup_test_78
8782 }
8783 run_test 78 "handle large O_DIRECT writes correctly ============"
8784
8785 test_79() { # bug 12743
8786         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8787
8788         wait_delete_completed
8789
8790         BKTOTAL=$(calc_osc_kbytes kbytestotal)
8791         BKFREE=$(calc_osc_kbytes kbytesfree)
8792         BKAVAIL=$(calc_osc_kbytes kbytesavail)
8793
8794         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
8795         DFTOTAL=`echo $STRING | cut -d, -f1`
8796         DFUSED=`echo $STRING  | cut -d, -f2`
8797         DFAVAIL=`echo $STRING | cut -d, -f3`
8798         DFFREE=$(($DFTOTAL - $DFUSED))
8799
8800         ALLOWANCE=$((64 * $OSTCOUNT))
8801
8802         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
8803            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
8804                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
8805         fi
8806         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
8807            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
8808                 error "df free($DFFREE) mismatch OST free($BKFREE)"
8809         fi
8810         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
8811            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
8812                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
8813         fi
8814 }
8815 run_test 79 "df report consistency check ======================="
8816
8817 test_80() { # bug 10718
8818         remote_ost_nodsh && skip "remote OST with nodsh"
8819         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8820
8821         # relax strong synchronous semantics for slow backends like ZFS
8822         if [ "$ost1_FSTYPE" != "ldiskfs" ]; then
8823                 local soc="obdfilter.*.sync_lock_cancel"
8824                 local save=$(do_facet ost1 $LCTL get_param -n $soc | head -n1)
8825
8826                 # "sync_on_lock_cancel" was broken by v2_11_55_0-26-g7059644e9a
8827                 if [ -z "$save" ]; then
8828                         soc="obdfilter.*.sync_on_lock_cancel"
8829                         save=$(do_facet ost1 $LCTL get_param -n $soc | head -n1)
8830                 fi
8831
8832                 if [ "$save" != "never" ]; then
8833                         local hosts=$(comma_list $(osts_nodes))
8834
8835                         do_nodes $hosts $LCTL set_param $soc=never
8836                         stack_trap "do_nodes $hosts $LCTL set_param $soc=$save"
8837                 fi
8838         fi
8839
8840         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
8841         sync; sleep 1; sync
8842         local before=$(date +%s)
8843         cancel_lru_locks osc
8844         local after=$(date +%s)
8845         local diff=$((after - before))
8846         [ $diff -le 1 ] || error "elapsed for 1M@1T = $diff"
8847
8848         rm -f $DIR/$tfile
8849 }
8850 run_test 80 "Page eviction is equally fast at high offsets too"
8851
8852 test_81a() { # LU-456
8853         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8854         remote_ost_nodsh && skip "remote OST with nodsh"
8855
8856         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
8857         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
8858         do_facet ost1 lctl set_param fail_loc=0x80000228
8859
8860         # write should trigger a retry and success
8861         $LFS setstripe -i 0 -c 1 $DIR/$tfile
8862         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8863         RC=$?
8864         if [ $RC -ne 0 ] ; then
8865                 error "write should success, but failed for $RC"
8866         fi
8867 }
8868 run_test 81a "OST should retry write when get -ENOSPC ==============="
8869
8870 test_81b() { # LU-456
8871         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8872         remote_ost_nodsh && skip "remote OST with nodsh"
8873
8874         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
8875         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
8876         do_facet ost1 lctl set_param fail_loc=0x228
8877
8878         # write should retry several times and return -ENOSPC finally
8879         $LFS setstripe -i 0 -c 1 $DIR/$tfile
8880         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8881         RC=$?
8882         ENOSPC=28
8883         if [ $RC -ne $ENOSPC ] ; then
8884                 error "dd should fail for -ENOSPC, but succeed."
8885         fi
8886 }
8887 run_test 81b "OST should return -ENOSPC when retry still fails ======="
8888
8889 test_82() { # LU-1031
8890         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
8891         local gid1=14091995
8892         local gid2=16022000
8893
8894         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
8895         local MULTIPID1=$!
8896         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
8897         local MULTIPID2=$!
8898         kill -USR1 $MULTIPID2
8899         sleep 2
8900         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
8901                 error "First grouplock does not block second one"
8902         else
8903                 echo "Second grouplock blocks first one"
8904         fi
8905         kill -USR1 $MULTIPID1
8906         wait $MULTIPID1
8907         wait $MULTIPID2
8908 }
8909 run_test 82 "Basic grouplock test"
8910
8911 test_99() {
8912         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs"
8913
8914         test_mkdir $DIR/$tdir.cvsroot
8915         chown $RUNAS_ID $DIR/$tdir.cvsroot
8916
8917         cd $TMP
8918         $RUNAS cvs -d $DIR/$tdir.cvsroot init || error "cvs init failed"
8919
8920         cd /etc/init.d
8921         # some versions of cvs import exit(1) when asked to import links or
8922         # files they can't read.  ignore those files.
8923         local toignore=$(find . -type l -printf '-I %f\n' -o \
8924                          ! -perm /4 -printf '-I %f\n')
8925         $RUNAS cvs -d $DIR/$tdir.cvsroot import -m "nomesg" $toignore \
8926                 $tdir.reposname vtag rtag
8927
8928         cd $DIR
8929         test_mkdir $DIR/$tdir.reposname
8930         chown $RUNAS_ID $DIR/$tdir.reposname
8931         $RUNAS cvs -d $DIR/$tdir.cvsroot co $tdir.reposname
8932
8933         cd $DIR/$tdir.reposname
8934         $RUNAS touch foo99
8935         $RUNAS cvs add -m 'addmsg' foo99
8936         $RUNAS cvs update
8937         $RUNAS cvs commit -m 'nomsg' foo99
8938         rm -fr $DIR/$tdir.cvsroot
8939 }
8940 run_test 99 "cvs strange file/directory operations"
8941
8942 test_100() {
8943         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8944         [[ "$NETTYPE" =~ tcp ]] ||
8945                 skip_env "TCP secure port test, not useful for NETTYPE=$NETTYPE"
8946         remote_ost_nodsh && skip "remote OST with nodsh"
8947         remote_mds_nodsh && skip "remote MDS with nodsh"
8948         remote_servers ||
8949                 skip "useless for local single node setup"
8950
8951         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
8952                 [ "$PROT" != "tcp" ] && continue
8953                 RPORT=$(echo $REMOTE | cut -d: -f2)
8954                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
8955
8956                 rc=0
8957                 LPORT=`echo $LOCAL | cut -d: -f2`
8958                 if [ $LPORT -ge 1024 ]; then
8959                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
8960                         netstat -tna
8961                         error_exit "local: $LPORT > 1024, remote: $RPORT"
8962                 fi
8963         done
8964         [ "$rc" = 0 ] || error_exit "privileged port not found" )
8965 }
8966 run_test 100 "check local port using privileged port ==========="
8967
8968 function get_named_value()
8969 {
8970     local tag
8971
8972     tag=$1
8973     while read ;do
8974         line=$REPLY
8975         case $line in
8976         $tag*)
8977             echo $line | sed "s/^$tag[ ]*//"
8978             break
8979             ;;
8980         esac
8981     done
8982 }
8983
8984 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
8985                    awk '/^max_cached_mb/ { print $2 }')
8986
8987 cleanup_101a() {
8988         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
8989         trap 0
8990 }
8991
8992 test_101a() {
8993         [ $PARALLEL == "yes" ] && skip "skip parallel run"
8994
8995         local s
8996         local discard
8997         local nreads=10000
8998         local cache_limit=32
8999
9000         $LCTL set_param -n osc.*-osc*.rpc_stats 0
9001         trap cleanup_101a EXIT
9002         $LCTL set_param -n llite.*.read_ahead_stats 0
9003         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
9004
9005         #
9006         # randomly read 10000 of 64K chunks from file 3x 32MB in size
9007         #
9008         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
9009         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
9010
9011         discard=0
9012         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
9013                 get_named_value 'read but discarded' | cut -d" " -f1); do
9014                         discard=$(($discard + $s))
9015         done
9016         cleanup_101a
9017
9018         $LCTL get_param osc.*-osc*.rpc_stats
9019         $LCTL get_param llite.*.read_ahead_stats
9020
9021         # Discard is generally zero, but sometimes a few random reads line up
9022         # and trigger larger readahead, which is wasted & leads to discards.
9023         if [[ $(($discard)) -gt $nreads ]]; then
9024                 error "too many ($discard) discarded pages"
9025         fi
9026         rm -f $DIR/$tfile || true
9027 }
9028 run_test 101a "check read-ahead for random reads"
9029
9030 setup_test101bc() {
9031         test_mkdir $DIR/$tdir
9032         local ssize=$1
9033         local FILE_LENGTH=$2
9034         STRIPE_OFFSET=0
9035
9036         local FILE_SIZE_MB=$((FILE_LENGTH / ssize))
9037
9038         local list=$(comma_list $(osts_nodes))
9039         set_osd_param $list '' read_cache_enable 0
9040         set_osd_param $list '' writethrough_cache_enable 0
9041
9042         trap cleanup_test101bc EXIT
9043         # prepare the read-ahead file
9044         $LFS setstripe -S $ssize -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
9045
9046         dd if=/dev/zero of=$DIR/$tfile bs=$ssize \
9047                                 count=$FILE_SIZE_MB 2> /dev/null
9048
9049 }
9050
9051 cleanup_test101bc() {
9052         trap 0
9053         rm -rf $DIR/$tdir
9054         rm -f $DIR/$tfile
9055
9056         local list=$(comma_list $(osts_nodes))
9057         set_osd_param $list '' read_cache_enable 1
9058         set_osd_param $list '' writethrough_cache_enable 1
9059 }
9060
9061 calc_total() {
9062         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
9063 }
9064
9065 ra_check_101() {
9066         local READ_SIZE=$1
9067         local STRIPE_SIZE=$2
9068         local FILE_LENGTH=$3
9069         local RA_INC=1048576
9070         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
9071         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
9072                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
9073         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
9074                         get_named_value 'read but discarded' |
9075                         cut -d" " -f1 | calc_total)
9076         if [[ $DISCARD -gt $discard_limit ]]; then
9077                 $LCTL get_param llite.*.read_ahead_stats
9078                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
9079         else
9080                 echo "Read-ahead success for size ${READ_SIZE}"
9081         fi
9082 }
9083
9084 test_101b() {
9085         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9086         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9087
9088         local STRIPE_SIZE=1048576
9089         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
9090
9091         if [ $SLOW == "yes" ]; then
9092                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
9093         else
9094                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
9095         fi
9096
9097         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
9098
9099         # prepare the read-ahead file
9100         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
9101         cancel_lru_locks osc
9102         for BIDX in 2 4 8 16 32 64 128 256
9103         do
9104                 local BSIZE=$((BIDX*4096))
9105                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
9106                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
9107                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
9108                 $LCTL set_param -n llite.*.read_ahead_stats 0
9109                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
9110                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
9111                 cancel_lru_locks osc
9112                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
9113         done
9114         cleanup_test101bc
9115         true
9116 }
9117 run_test 101b "check stride-io mode read-ahead ================="
9118
9119 test_101c() {
9120         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9121
9122         local STRIPE_SIZE=1048576
9123         local FILE_LENGTH=$((STRIPE_SIZE*100))
9124         local nreads=10000
9125         local rsize=65536
9126         local osc_rpc_stats
9127
9128         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
9129
9130         cancel_lru_locks osc
9131         $LCTL set_param osc.*.rpc_stats 0
9132         $READS -f $DIR/$tfile -s$FILE_LENGTH -b$rsize -n$nreads -t 180
9133         $LCTL get_param osc.*.rpc_stats
9134         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
9135                 local stats=$($LCTL get_param -n $osc_rpc_stats)
9136                 local lines=$(echo "$stats" | awk 'END {print NR;}')
9137                 local size
9138
9139                 if [ $lines -le 20 ]; then
9140                         echo "continue debug"
9141                         continue
9142                 fi
9143                 for size in 1 2 4 8; do
9144                         local rpc=$(echo "$stats" |
9145                                     awk '($1 == "'$size':") {print $2; exit; }')
9146                         [ $rpc != 0 ] && ((size * PAGE_SIZE < rsize)) &&
9147                                 error "Small $((size*PAGE_SIZE)) read IO $rpc!"
9148                 done
9149                 echo "$osc_rpc_stats check passed!"
9150         done
9151         cleanup_test101bc
9152         true
9153 }
9154 run_test 101c "check stripe_size aligned read-ahead ================="
9155
9156 test_101d() {
9157         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9158
9159         local file=$DIR/$tfile
9160         local sz_MB=${FILESIZE_101d:-80}
9161         local ra_MB=${READAHEAD_MB:-40}
9162
9163         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
9164         [ $free_MB -lt $sz_MB ] &&
9165                 skip "Need free space ${sz_MB}M, have ${free_MB}M"
9166
9167         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
9168         $LFS setstripe -c -1 $file || error "setstripe failed"
9169
9170         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
9171         echo Cancel LRU locks on lustre client to flush the client cache
9172         cancel_lru_locks osc
9173
9174         echo Disable read-ahead
9175         local old_RA=$($LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1)
9176         $LCTL set_param -n llite.*.max_read_ahead_mb=0
9177         stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb $old_RA" EXIT
9178         $LCTL get_param -n llite.*.max_read_ahead_mb
9179
9180         echo "Reading the test file $file with read-ahead disabled"
9181         local sz_KB=$((sz_MB * 1024 / 4))
9182         # 10485760 bytes transferred in 0.000938 secs (11179579337 bytes/sec)
9183         # 104857600 bytes (105 MB) copied, 0.00876352 s, 12.0 GB/s
9184         local raOFF=$(LANG=C dd if=$file of=/dev/null bs=4k count=$sz_KB |&
9185                       sed -e '/records/d' -e 's/.* \([0-9]*\.[0-9]*\) *s.*/\1/')
9186
9187         echo "Cancel LRU locks on lustre client to flush the client cache"
9188         cancel_lru_locks osc
9189         echo Enable read-ahead with ${ra_MB}MB
9190         $LCTL set_param -n llite.*.max_read_ahead_mb=$ra_MB
9191
9192         echo "Reading the test file $file with read-ahead enabled"
9193         local raON=$(LANG=C dd if=$file of=/dev/null bs=4k count=$sz_KB |&
9194                      sed -e '/records/d' -e 's/.* \([0-9]*\.[0-9]*\) *s.*/\1/')
9195
9196         echo "read-ahead disabled time read $raOFF"
9197         echo "read-ahead enabled time read $raON"
9198
9199         rm -f $file
9200         wait_delete_completed
9201
9202         # use awk for this check instead of bash because it handles decimals
9203         awk "{ exit !($raOFF < 1.0 || $raOFF > $raON) }" <<<"ignore_me" ||
9204                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
9205 }
9206 run_test 101d "file read with and without read-ahead enabled"
9207
9208 test_101e() {
9209         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9210
9211         local file=$DIR/$tfile
9212         local size_KB=500  #KB
9213         local count=100
9214         local bsize=1024
9215
9216         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
9217         local need_KB=$((count * size_KB))
9218         [[ $free_KB -le $need_KB ]] &&
9219                 skip_env "Need free space $need_KB, have $free_KB"
9220
9221         echo "Creating $count ${size_KB}K test files"
9222         for ((i = 0; i < $count; i++)); do
9223                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
9224         done
9225
9226         echo "Cancel LRU locks on lustre client to flush the client cache"
9227         cancel_lru_locks $OSC
9228
9229         echo "Reset readahead stats"
9230         $LCTL set_param -n llite.*.read_ahead_stats 0
9231
9232         for ((i = 0; i < $count; i++)); do
9233                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
9234         done
9235
9236         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9237                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
9238
9239         for ((i = 0; i < $count; i++)); do
9240                 rm -rf $file.$i 2>/dev/null
9241         done
9242
9243         #10000 means 20% reads are missing in readahead
9244         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
9245 }
9246 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
9247
9248 test_101f() {
9249         which iozone || skip_env "no iozone installed"
9250
9251         local old_debug=$($LCTL get_param debug)
9252         old_debug=${old_debug#*=}
9253         $LCTL set_param debug="reada mmap"
9254
9255         # create a test file
9256         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
9257
9258         echo Cancel LRU locks on lustre client to flush the client cache
9259         cancel_lru_locks osc
9260
9261         echo Reset readahead stats
9262         $LCTL set_param -n llite.*.read_ahead_stats 0
9263
9264         echo mmap read the file with small block size
9265         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
9266                 > /dev/null 2>&1
9267
9268         echo checking missing pages
9269         $LCTL get_param llite.*.read_ahead_stats
9270         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9271                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
9272
9273         $LCTL set_param debug="$old_debug"
9274         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
9275         rm -f $DIR/$tfile
9276 }
9277 run_test 101f "check mmap read performance"
9278
9279 test_101g_brw_size_test() {
9280         local mb=$1
9281         local pages=$((mb * 1048576 / PAGE_SIZE))
9282         local file=$DIR/$tfile
9283
9284         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
9285                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
9286         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
9287                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
9288                         return 2
9289         done
9290
9291         stack_trap "rm -f $file" EXIT
9292         $LCTL set_param -n osc.*.rpc_stats=0
9293
9294         # 10 RPCs should be enough for the test
9295         local count=10
9296         dd if=/dev/zero of=$file bs=${mb}M count=$count ||
9297                 { error "dd write ${mb} MB blocks failed"; return 3; }
9298         cancel_lru_locks osc
9299         dd of=/dev/null if=$file bs=${mb}M count=$count ||
9300                 { error "dd write ${mb} MB blocks failed"; return 4; }
9301
9302         # calculate number of full-sized read and write RPCs
9303         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
9304                 sed -n '/pages per rpc/,/^$/p' |
9305                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
9306                 END { print reads,writes }'))
9307         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
9308                 return 5
9309         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
9310                 return 6
9311
9312         return 0
9313 }
9314
9315 test_101g() {
9316         remote_ost_nodsh && skip "remote OST with nodsh"
9317
9318         local rpcs
9319         local osts=$(get_facets OST)
9320         local list=$(comma_list $(osts_nodes))
9321         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
9322         local brw_size="obdfilter.*.brw_size"
9323
9324         $LFS setstripe -i 0 -c 1 $DIR/$tfile
9325
9326         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
9327
9328         if { [ $OST1_VERSION -ge $(version_code 2.8.52) ] ||
9329                 { [ $OST1_VERSION -ge $(version_code 2.7.17) ] &&
9330                   [ $OST1_VERSION -lt $(version_code 2.7.50) ]; }; } &&
9331            { [ $CLIENT_VERSION -ge $(version_code 2.8.52) ] ||
9332                 { [ $CLIENT_VERSION -ge $(version_code 2.7.17) ] &&
9333                   [ $CLIENT_VERSION -lt $(version_code 2.7.50) ]; }; }; then
9334
9335                 [ $OST1_VERSION -ge $(version_code 2.9.52) ] &&
9336                         suffix="M"
9337
9338                 if [[ $orig_mb -lt 16 ]]; then
9339                         save_lustre_params $osts "$brw_size" > $p
9340                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
9341                                 error "set 16MB RPC size failed"
9342
9343                         echo "remount client to enable new RPC size"
9344                         remount_client $MOUNT || error "remount_client failed"
9345                 fi
9346
9347                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
9348                 # should be able to set brw_size=12, but no rpc_stats for that
9349                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
9350         fi
9351
9352         test_101g_brw_size_test 4 || error "4MB RPC test failed"
9353
9354         if [[ $orig_mb -lt 16 ]]; then
9355                 restore_lustre_params < $p
9356                 remount_client $MOUNT || error "remount_client restore failed"
9357         fi
9358
9359         rm -f $p $DIR/$tfile
9360 }
9361 run_test 101g "Big bulk(4/16 MiB) readahead"
9362
9363 test_101h() {
9364         $LFS setstripe -i 0 -c 1 $DIR/$tfile
9365
9366         dd if=/dev/zero of=$DIR/$tfile bs=1M count=70 ||
9367                 error "dd 70M file failed"
9368         echo Cancel LRU locks on lustre client to flush the client cache
9369         cancel_lru_locks osc
9370
9371         echo "Reset readahead stats"
9372         $LCTL set_param -n llite.*.read_ahead_stats 0
9373
9374         echo "Read 10M of data but cross 64M bundary"
9375         dd if=$DIR/$tfile of=/dev/null bs=10M skip=6 count=1
9376         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9377                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
9378         [ $miss -eq 1 ] || error "expected miss 1 but got $miss"
9379         rm -f $p $DIR/$tfile
9380 }
9381 run_test 101h "Readahead should cover current read window"
9382
9383 test_101i() {
9384         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 ||
9385                 error "dd 10M file failed"
9386
9387         local max_per_file_mb=$($LCTL get_param -n \
9388                 llite.*.max_read_ahead_per_file_mb 2>/dev/null)
9389         cancel_lru_locks osc
9390         stack_trap "$LCTL set_param llite.*.max_read_ahead_per_file_mb=$max_per_file_mb"
9391         $LCTL set_param llite.*.max_read_ahead_per_file_mb=1 ||
9392                 error "set max_read_ahead_per_file_mb to 1 failed"
9393
9394         echo "Reset readahead stats"
9395         $LCTL set_param llite.*.read_ahead_stats=0
9396
9397         dd if=$DIR/$tfile of=/dev/null bs=2M
9398
9399         $LCTL get_param llite.*.read_ahead_stats
9400         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9401                      awk '/misses/ { print $2 }')
9402         [ $miss -eq 5 ] || error "expected misses 5 but got $miss"
9403         rm -f $DIR/$tfile
9404 }
9405 run_test 101i "allow current readahead to exceed reservation"
9406
9407 test_101j() {
9408         $LFS setstripe -i 0 -c 1 $DIR/$tfile ||
9409                 error "setstripe $DIR/$tfile failed"
9410         local file_size=$((1048576 * 16))
9411         local old_ra=$($LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1)
9412         stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb $old_ra" EXIT
9413
9414         echo Disable read-ahead
9415         $LCTL set_param -n llite.*.max_read_ahead_mb=0
9416
9417         dd if=/dev/zero of=$DIR/$tfile bs=1M count=$(($file_size / 1048576))
9418         for blk in $PAGE_SIZE 1048576 $file_size; do
9419                 cancel_lru_locks osc
9420                 echo "Reset readahead stats"
9421                 $LCTL set_param -n llite.*.read_ahead_stats=0
9422                 local count=$(($file_size / $blk))
9423                 dd if=$DIR/$tfile bs=$blk count=$count of=/dev/null
9424                 local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
9425                              get_named_value 'failed to fast read' |
9426                              cut -d" " -f1 | calc_total)
9427                 $LCTL get_param -n llite.*.read_ahead_stats
9428                 [ $miss -eq $count ] || error "expected $count got $miss"
9429         done
9430
9431         rm -f $p $DIR/$tfile
9432 }
9433 run_test 101j "A complete read block should be submitted when no RA"
9434
9435 setup_test102() {
9436         test_mkdir $DIR/$tdir
9437         chown $RUNAS_ID $DIR/$tdir
9438         STRIPE_SIZE=65536
9439         STRIPE_OFFSET=1
9440         STRIPE_COUNT=$OSTCOUNT
9441         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
9442
9443         trap cleanup_test102 EXIT
9444         cd $DIR
9445         $1 $LFS setstripe -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
9446         cd $DIR/$tdir
9447         for num in 1 2 3 4; do
9448                 for count in $(seq 1 $STRIPE_COUNT); do
9449                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
9450                                 local size=`expr $STRIPE_SIZE \* $num`
9451                                 local file=file"$num-$idx-$count"
9452                                 $1 $LFS setstripe -S $size -i $idx -c $count $file
9453                         done
9454                 done
9455         done
9456
9457         cd $DIR
9458         $1 tar cf $TMP/f102.tar $tdir --xattrs
9459 }
9460
9461 cleanup_test102() {
9462         trap 0
9463         rm -f $TMP/f102.tar
9464         rm -rf $DIR/d0.sanity/d102
9465 }
9466
9467 test_102a() {
9468         [ "$UID" != 0 ] && skip "must run as root"
9469         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
9470                 skip_env "must have user_xattr"
9471
9472         [ -z "$(which setfattr 2>/dev/null)" ] &&
9473                 skip_env "could not find setfattr"
9474
9475         local testfile=$DIR/$tfile
9476
9477         touch $testfile
9478         echo "set/get xattr..."
9479         setfattr -n trusted.name1 -v value1 $testfile ||
9480                 error "setfattr -n trusted.name1=value1 $testfile failed"
9481         getfattr -n trusted.name1 $testfile 2> /dev/null |
9482           grep "trusted.name1=.value1" ||
9483                 error "$testfile missing trusted.name1=value1"
9484
9485         setfattr -n user.author1 -v author1 $testfile ||
9486                 error "setfattr -n user.author1=author1 $testfile failed"
9487         getfattr -n user.author1 $testfile 2> /dev/null |
9488           grep "user.author1=.author1" ||
9489                 error "$testfile missing trusted.author1=author1"
9490
9491         echo "listxattr..."
9492         setfattr -n trusted.name2 -v value2 $testfile ||
9493                 error "$testfile unable to set trusted.name2"
9494         setfattr -n trusted.name3 -v value3 $testfile ||
9495                 error "$testfile unable to set trusted.name3"
9496         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
9497             grep "trusted.name" | wc -l) -eq 3 ] ||
9498                 error "$testfile missing 3 trusted.name xattrs"
9499
9500         setfattr -n user.author2 -v author2 $testfile ||
9501                 error "$testfile unable to set user.author2"
9502         setfattr -n user.author3 -v author3 $testfile ||
9503                 error "$testfile unable to set user.author3"
9504         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
9505             grep "user.author" | wc -l) -eq 3 ] ||
9506                 error "$testfile missing 3 user.author xattrs"
9507
9508         echo "remove xattr..."
9509         setfattr -x trusted.name1 $testfile ||
9510                 error "$testfile error deleting trusted.name1"
9511         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
9512                 error "$testfile did not delete trusted.name1 xattr"
9513
9514         setfattr -x user.author1 $testfile ||
9515                 error "$testfile error deleting user.author1"
9516         echo "set lustre special xattr ..."
9517         $LFS setstripe -c1 $testfile
9518         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
9519                 awk -F "=" '/trusted.lov/ { print $2 }' )
9520         setfattr -n "trusted.lov" -v $lovea $testfile ||
9521                 error "$testfile doesn't ignore setting trusted.lov again"
9522         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
9523                 error "$testfile allow setting invalid trusted.lov"
9524         rm -f $testfile
9525 }
9526 run_test 102a "user xattr test =================================="
9527
9528 check_102b_layout() {
9529         local layout="$*"
9530         local testfile=$DIR/$tfile
9531
9532         echo "test layout '$layout'"
9533         $LFS setstripe $layout $testfile || error "setstripe failed"
9534         $LFS getstripe -y $testfile
9535
9536         echo "get/set/list trusted.lov xattr ..." # b=10930
9537         local value=$(getfattr -n trusted.lov -e hex $testfile | grep trusted)
9538         [[ "$value" =~ "trusted.lov" ]] ||
9539                 error "can't get trusted.lov from $testfile"
9540         local stripe_count_orig=$($LFS getstripe -c $testfile) ||
9541                 error "getstripe failed"
9542
9543         $MCREATE $testfile.2 || error "mcreate $testfile.2 failed"
9544
9545         value=$(cut -d= -f2 <<<$value)
9546         # LU-13168: truncated xattr should fail if short lov_user_md header
9547         [ $CLIENT_VERSION -lt $(version_code 2.13.53) ] &&
9548                 lens="${#value}" || lens="$(seq 4 2 ${#value})"
9549         for len in $lens; do
9550                 echo "setfattr $len $testfile.2"
9551                 setfattr -n trusted.lov -v ${value:0:$len} $testfile.2 &&
9552                         [ $len -lt 66 ] && error "short xattr len=$len worked"
9553         done
9554         local stripe_size=$($LFS getstripe -S $testfile.2)
9555         local stripe_count=$($LFS getstripe -c $testfile.2)
9556         [[ $stripe_size -eq 65536 ]] ||
9557                 error "stripe size $stripe_size != 65536"
9558         [[ $stripe_count -eq $stripe_count_orig ]] ||
9559                 error "stripe count $stripe_count != $stripe_count_orig"
9560         rm $testfile $testfile.2
9561 }
9562
9563 test_102b() {
9564         [ -z "$(which setfattr 2>/dev/null)" ] &&
9565                 skip_env "could not find setfattr"
9566         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9567
9568         # check plain layout
9569         check_102b_layout -S 65536 -i 1 -c $OSTCOUNT
9570
9571         # and also check composite layout
9572         check_102b_layout -E 1M -S 65536 -i 1 -c $OSTCOUNT -Eeof -S4M
9573
9574 }
9575 run_test 102b "getfattr/setfattr for trusted.lov EAs"
9576
9577 test_102c() {
9578         [ -z "$(which setfattr 2>/dev/null)" ] &&
9579                 skip_env "could not find setfattr"
9580         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9581
9582         # b10930: get/set/list lustre.lov xattr
9583         echo "get/set/list lustre.lov xattr ..."
9584         test_mkdir $DIR/$tdir
9585         chown $RUNAS_ID $DIR/$tdir
9586         local testfile=$DIR/$tdir/$tfile
9587         $RUNAS $LFS setstripe -S 65536 -i 1 -c $OSTCOUNT $testfile ||
9588                 error "setstripe failed"
9589         local STRIPECOUNT=$($RUNAS $LFS getstripe -c $testfile) ||
9590                 error "getstripe failed"
9591         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
9592         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
9593
9594         local testfile2=${testfile}2
9595         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
9596                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
9597
9598         $RUNAS $MCREATE $testfile2
9599         $RUNAS setfattr -n lustre.lov -v $value $testfile2
9600         local stripe_size=$($RUNAS $LFS getstripe -S $testfile2)
9601         local stripe_count=$($RUNAS $LFS getstripe -c $testfile2)
9602         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
9603         [ $stripe_count -eq $STRIPECOUNT ] ||
9604                 error "stripe count $stripe_count != $STRIPECOUNT"
9605 }
9606 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
9607
9608 compare_stripe_info1() {
9609         local stripe_index_all_zero=true
9610
9611         for num in 1 2 3 4; do
9612                 for count in $(seq 1 $STRIPE_COUNT); do
9613                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
9614                                 local size=$((STRIPE_SIZE * num))
9615                                 local file=file"$num-$offset-$count"
9616                                 stripe_size=$($LFS getstripe -S $PWD/$file)
9617                                 [[ $stripe_size -ne $size ]] &&
9618                                     error "$file: size $stripe_size != $size"
9619                                 stripe_count=$($LFS getstripe -c $PWD/$file)
9620                                 # allow fewer stripes to be created, ORI-601
9621                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
9622                                     error "$file: count $stripe_count != $count"
9623                                 stripe_index=$($LFS getstripe -i $PWD/$file)
9624                                 [[ $stripe_index -ne 0 ]] &&
9625                                         stripe_index_all_zero=false
9626                         done
9627                 done
9628         done
9629         $stripe_index_all_zero &&
9630                 error "all files are being extracted starting from OST index 0"
9631         return 0
9632 }
9633
9634 have_xattrs_include() {
9635         tar --help | grep -q xattrs-include &&
9636                 echo --xattrs-include="lustre.*"
9637 }
9638
9639 test_102d() {
9640         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9641         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9642
9643         XINC=$(have_xattrs_include)
9644         setup_test102
9645         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
9646         cd $DIR/$tdir/$tdir
9647         compare_stripe_info1
9648 }
9649 run_test 102d "tar restore stripe info from tarfile,not keep osts"
9650
9651 test_102f() {
9652         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9653         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9654
9655         XINC=$(have_xattrs_include)
9656         setup_test102
9657         test_mkdir $DIR/$tdir.restore
9658         cd $DIR
9659         tar cf - --xattrs $tdir | tar xf - \
9660                 -C $DIR/$tdir.restore --xattrs $XINC
9661         cd $DIR/$tdir.restore/$tdir
9662         compare_stripe_info1
9663 }
9664 run_test 102f "tar copy files, not keep osts"
9665
9666 grow_xattr() {
9667         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
9668                 skip "must have user_xattr"
9669         [ -z "$(which setfattr 2>/dev/null)" ] &&
9670                 skip_env "could not find setfattr"
9671         [ -z "$(which getfattr 2>/dev/null)" ] &&
9672                 skip_env "could not find getfattr"
9673
9674         local xsize=${1:-1024}  # in bytes
9675         local file=$DIR/$tfile
9676         local value="$(generate_string $xsize)"
9677         local xbig=trusted.big
9678         local toobig=$2
9679
9680         touch $file
9681         log "save $xbig on $file"
9682         if [ -z "$toobig" ]
9683         then
9684                 setfattr -n $xbig -v $value $file ||
9685                         error "saving $xbig on $file failed"
9686         else
9687                 setfattr -n $xbig -v $value $file &&
9688                         error "saving $xbig on $file succeeded"
9689                 return 0
9690         fi
9691
9692         local orig=$(get_xattr_value $xbig $file)
9693         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
9694
9695         local xsml=trusted.sml
9696         log "save $xsml on $file"
9697         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
9698
9699         local new=$(get_xattr_value $xbig $file)
9700         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
9701
9702         log "grow $xsml on $file"
9703         setfattr -n $xsml -v "$value" $file ||
9704                 error "growing $xsml on $file failed"
9705
9706         new=$(get_xattr_value $xbig $file)
9707         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
9708         log "$xbig still valid after growing $xsml"
9709
9710         rm -f $file
9711 }
9712
9713 test_102h() { # bug 15777
9714         grow_xattr 1024
9715 }
9716 run_test 102h "grow xattr from inside inode to external block"
9717
9718 test_102ha() {
9719         large_xattr_enabled || skip_env "ea_inode feature disabled"
9720
9721         echo "setting xattr of max xattr size: $(max_xattr_size)"
9722         grow_xattr $(max_xattr_size)
9723
9724         echo "setting xattr of > max xattr size: $(max_xattr_size) + 10"
9725         echo "This should fail:"
9726         grow_xattr $(($(max_xattr_size) + 10)) 1
9727 }
9728 run_test 102ha "grow xattr from inside inode to external inode"
9729
9730 test_102i() { # bug 17038
9731         [ -z "$(which getfattr 2>/dev/null)" ] &&
9732                 skip "could not find getfattr"
9733
9734         touch $DIR/$tfile
9735         ln -s $DIR/$tfile $DIR/${tfile}link
9736         getfattr -n trusted.lov $DIR/$tfile ||
9737                 error "lgetxattr on $DIR/$tfile failed"
9738         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
9739                 grep -i "no such attr" ||
9740                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
9741         rm -f $DIR/$tfile $DIR/${tfile}link
9742 }
9743 run_test 102i "lgetxattr test on symbolic link ============"
9744
9745 test_102j() {
9746         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9747         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
9748
9749         XINC=$(have_xattrs_include)
9750         setup_test102 "$RUNAS"
9751         chown $RUNAS_ID $DIR/$tdir
9752         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
9753         cd $DIR/$tdir/$tdir
9754         compare_stripe_info1 "$RUNAS"
9755 }
9756 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
9757
9758 test_102k() {
9759         [ -z "$(which setfattr 2>/dev/null)" ] &&
9760                 skip "could not find setfattr"
9761
9762         touch $DIR/$tfile
9763         # b22187 just check that does not crash for regular file.
9764         setfattr -n trusted.lov $DIR/$tfile
9765         # b22187 'setfattr -n trusted.lov' should remove LOV EA for directories
9766         local test_kdir=$DIR/$tdir
9767         test_mkdir $test_kdir
9768         local default_size=$($LFS getstripe -S $test_kdir)
9769         local default_count=$($LFS getstripe -c $test_kdir)
9770         local default_offset=$($LFS getstripe -i $test_kdir)
9771         $LFS setstripe -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
9772                 error 'dir setstripe failed'
9773         setfattr -n trusted.lov $test_kdir
9774         local stripe_size=$($LFS getstripe -S $test_kdir)
9775         local stripe_count=$($LFS getstripe -c $test_kdir)
9776         local stripe_offset=$($LFS getstripe -i $test_kdir)
9777         [ $stripe_size -eq $default_size ] ||
9778                 error "stripe size $stripe_size != $default_size"
9779         [ $stripe_count -eq $default_count ] ||
9780                 error "stripe count $stripe_count != $default_count"
9781         [ $stripe_offset -eq $default_offset ] ||
9782                 error "stripe offset $stripe_offset != $default_offset"
9783         rm -rf $DIR/$tfile $test_kdir
9784 }
9785 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
9786
9787 test_102l() {
9788         [ -z "$(which getfattr 2>/dev/null)" ] &&
9789                 skip "could not find getfattr"
9790
9791         # LU-532 trusted. xattr is invisible to non-root
9792         local testfile=$DIR/$tfile
9793
9794         touch $testfile
9795
9796         echo "listxattr as user..."
9797         chown $RUNAS_ID $testfile
9798         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
9799             grep -q "trusted" &&
9800                 error "$testfile trusted xattrs are user visible"
9801
9802         return 0;
9803 }
9804 run_test 102l "listxattr size test =================================="
9805
9806 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
9807         local path=$DIR/$tfile
9808         touch $path
9809
9810         listxattr_size_check $path || error "listattr_size_check $path failed"
9811 }
9812 run_test 102m "Ensure listxattr fails on small bufffer ========"
9813
9814 cleanup_test102
9815
9816 getxattr() { # getxattr path name
9817         # Return the base64 encoding of the value of xattr name on path.
9818         local path=$1
9819         local name=$2
9820
9821         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
9822         # file: $path
9823         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
9824         #
9825         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
9826
9827         getfattr --absolute-names --encoding=base64 --name=$name $path |
9828                 awk -F= -v name=$name '$1 == name {
9829                         print substr($0, index($0, "=") + 1);
9830         }'
9831 }
9832
9833 test_102n() { # LU-4101 mdt: protect internal xattrs
9834         [ -z "$(which setfattr 2>/dev/null)" ] &&
9835                 skip "could not find setfattr"
9836         if [ $MDS1_VERSION -lt $(version_code 2.5.50) ]
9837         then
9838                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
9839         fi
9840
9841         local file0=$DIR/$tfile.0
9842         local file1=$DIR/$tfile.1
9843         local xattr0=$TMP/$tfile.0
9844         local xattr1=$TMP/$tfile.1
9845         local namelist="lov lma lmv link fid version som hsm"
9846         local name
9847         local value
9848
9849         rm -rf $file0 $file1 $xattr0 $xattr1
9850         touch $file0 $file1
9851
9852         # Get 'before' xattrs of $file1.
9853         getfattr --absolute-names --dump --match=- $file1 > $xattr0
9854
9855         [ $MDS1_VERSION -lt $(version_code 2.8.53) ] &&
9856                 namelist+=" lfsck_namespace"
9857         for name in $namelist; do
9858                 # Try to copy xattr from $file0 to $file1.
9859                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
9860
9861                 setfattr --name=trusted.$name --value="$value" $file1 ||
9862                         error "setxattr 'trusted.$name' failed"
9863
9864                 # Try to set a garbage xattr.
9865                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
9866
9867                 if [[ x$name == "xlov" ]]; then
9868                         setfattr --name=trusted.lov --value="$value" $file1 &&
9869                         error "setxattr invalid 'trusted.lov' success"
9870                 else
9871                         setfattr --name=trusted.$name --value="$value" $file1 ||
9872                                 error "setxattr invalid 'trusted.$name' failed"
9873                 fi
9874
9875                 # Try to remove the xattr from $file1. We don't care if this
9876                 # appears to succeed or fail, we just don't want there to be
9877                 # any changes or crashes.
9878                 setfattr --remove=$trusted.$name $file1 2> /dev/null
9879         done
9880
9881         if [ $MDS1_VERSION -gt $(version_code 2.6.50) ]
9882         then
9883                 name="lfsck_ns"
9884                 # Try to copy xattr from $file0 to $file1.
9885                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
9886
9887                 setfattr --name=trusted.$name --value="$value" $file1 ||
9888                         error "setxattr 'trusted.$name' failed"
9889
9890                 # Try to set a garbage xattr.
9891                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
9892
9893                 setfattr --name=trusted.$name --value="$value" $file1 ||
9894                         error "setxattr 'trusted.$name' failed"
9895
9896                 # Try to remove the xattr from $file1. We don't care if this
9897                 # appears to succeed or fail, we just don't want there to be
9898                 # any changes or crashes.
9899                 setfattr --remove=$trusted.$name $file1 2> /dev/null
9900         fi
9901
9902         # Get 'after' xattrs of file1.
9903         getfattr --absolute-names --dump --match=- $file1 > $xattr1
9904
9905         if ! diff $xattr0 $xattr1; then
9906                 error "before and after xattrs of '$file1' differ"
9907         fi
9908
9909         rm -rf $file0 $file1 $xattr0 $xattr1
9910
9911         return 0
9912 }
9913 run_test 102n "silently ignore setxattr on internal trusted xattrs"
9914
9915 test_102p() { # LU-4703 setxattr did not check ownership
9916         [ $MDS1_VERSION -lt $(version_code 2.5.56) ] &&
9917                 skip "MDS needs to be at least 2.5.56"
9918
9919         local testfile=$DIR/$tfile
9920
9921         touch $testfile
9922
9923         echo "setfacl as user..."
9924         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
9925         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
9926
9927         echo "setfattr as user..."
9928         setfacl -m "u:$RUNAS_ID:---" $testfile
9929         $RUNAS setfattr -x system.posix_acl_access $testfile
9930         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
9931 }
9932 run_test 102p "check setxattr(2) correctly fails without permission"
9933
9934 test_102q() {
9935         [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
9936                 skip "MDS needs to be at least 2.6.92"
9937
9938         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
9939 }
9940 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
9941
9942 test_102r() {
9943         [ $MDS1_VERSION -lt $(version_code 2.6.93) ] &&
9944                 skip "MDS needs to be at least 2.6.93"
9945
9946         touch $DIR/$tfile || error "touch"
9947         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
9948         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
9949         rm $DIR/$tfile || error "rm"
9950
9951         #normal directory
9952         mkdir -p $DIR/$tdir || error "mkdir"
9953         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
9954         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
9955         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
9956                 error "$testfile error deleting user.author1"
9957         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
9958                 grep "user.$(basename $tdir)" &&
9959                 error "$tdir did not delete user.$(basename $tdir)"
9960         rmdir $DIR/$tdir || error "rmdir"
9961
9962         #striped directory
9963         test_mkdir $DIR/$tdir
9964         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
9965         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
9966         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
9967                 error "$testfile error deleting user.author1"
9968         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
9969                 grep "user.$(basename $tdir)" &&
9970                 error "$tdir did not delete user.$(basename $tdir)"
9971         rmdir $DIR/$tdir || error "rm striped dir"
9972 }
9973 run_test 102r "set EAs with empty values"
9974
9975 test_102s() {
9976         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
9977                 skip "MDS needs to be at least 2.11.52"
9978
9979         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
9980
9981         save_lustre_params client "llite.*.xattr_cache" > $save
9982
9983         for cache in 0 1; do
9984                 lctl set_param llite.*.xattr_cache=$cache
9985
9986                 rm -f $DIR/$tfile
9987                 touch $DIR/$tfile || error "touch"
9988                 for prefix in lustre security system trusted user; do
9989                         # Note getxattr() may fail with 'Operation not
9990                         # supported' or 'No such attribute' depending
9991                         # on prefix and cache.
9992                         getfattr -n $prefix.n102s $DIR/$tfile &&
9993                                 error "getxattr '$prefix.n102s' should fail (cache = $cache)"
9994                 done
9995         done
9996
9997         restore_lustre_params < $save
9998 }
9999 run_test 102s "getting nonexistent xattrs should fail"
10000
10001 test_102t() {
10002         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
10003                 skip "MDS needs to be at least 2.11.52"
10004
10005         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10006
10007         save_lustre_params client "llite.*.xattr_cache" > $save
10008
10009         for cache in 0 1; do
10010                 lctl set_param llite.*.xattr_cache=$cache
10011
10012                 for buf_size in 0 256; do
10013                         rm -f $DIR/$tfile
10014                         touch $DIR/$tfile || error "touch"
10015                         setfattr -n user.multiop $DIR/$tfile
10016                         $MULTIOP $DIR/$tfile oa$buf_size ||
10017                                 error "cannot get zero length xattr value (buf_size = $buf_size)"
10018                 done
10019         done
10020
10021         restore_lustre_params < $save
10022 }
10023 run_test 102t "zero length xattr values handled correctly"
10024
10025 run_acl_subtest()
10026 {
10027     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
10028     return $?
10029 }
10030
10031 test_103a() {
10032         [ "$UID" != 0 ] && skip "must run as root"
10033         $GSS && skip_env "could not run under gss"
10034         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
10035                 skip_env "must have acl enabled"
10036         [ -z "$(which setfacl 2>/dev/null)" ] &&
10037                 skip_env "could not find setfacl"
10038         remote_mds_nodsh && skip "remote MDS with nodsh"
10039
10040         gpasswd -a daemon bin                           # LU-5641
10041         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
10042
10043         declare -a identity_old
10044
10045         for num in $(seq $MDSCOUNT); do
10046                 switch_identity $num true || identity_old[$num]=$?
10047         done
10048
10049         SAVE_UMASK=$(umask)
10050         umask 0022
10051         mkdir -p $DIR/$tdir
10052         cd $DIR/$tdir
10053
10054         echo "performing cp ..."
10055         run_acl_subtest cp || error "run_acl_subtest cp failed"
10056         echo "performing getfacl-noacl..."
10057         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
10058         echo "performing misc..."
10059         run_acl_subtest misc || error  "misc test failed"
10060         echo "performing permissions..."
10061         run_acl_subtest permissions || error "permissions failed"
10062         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
10063         if [ $MDS1_VERSION -gt $(version_code 2.8.55) ] ||
10064                 { [ $MDS1_VERSION -lt $(version_code 2.6) ] &&
10065                         [ $MDS1_VERSION -ge $(version_code 2.5.29) ]; }
10066         then
10067                 echo "performing permissions xattr..."
10068                 run_acl_subtest permissions_xattr ||
10069                         error "permissions_xattr failed"
10070         fi
10071         echo "performing setfacl..."
10072         run_acl_subtest setfacl || error  "setfacl test failed"
10073
10074         # inheritance test got from HP
10075         echo "performing inheritance..."
10076         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
10077         chmod +x make-tree || error "chmod +x failed"
10078         run_acl_subtest inheritance || error "inheritance test failed"
10079         rm -f make-tree
10080
10081         echo "LU-974 ignore umask when acl is enabled..."
10082         run_acl_subtest 974 || error "LU-974 umask test failed"
10083         if [ $MDSCOUNT -ge 2 ]; then
10084                 run_acl_subtest 974_remote ||
10085                         error "LU-974 umask test failed under remote dir"
10086         fi
10087
10088         echo "LU-2561 newly created file is same size as directory..."
10089         if [ "$mds1_FSTYPE" != "zfs" ]; then
10090                 run_acl_subtest 2561 || error "LU-2561 test failed"
10091         else
10092                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
10093         fi
10094
10095         run_acl_subtest 4924 || error "LU-4924 test failed"
10096
10097         cd $SAVE_PWD
10098         umask $SAVE_UMASK
10099
10100         for num in $(seq $MDSCOUNT); do
10101                 if [ "${identity_old[$num]}" = 1 ]; then
10102                         switch_identity $num false || identity_old[$num]=$?
10103                 fi
10104         done
10105 }
10106 run_test 103a "acl test"
10107
10108 test_103b() {
10109         declare -a pids
10110         local U
10111
10112         for U in {0..511}; do
10113                 {
10114                 local O=$(printf "%04o" $U)
10115
10116                 umask $(printf "%04o" $((511 ^ $O)))
10117                 $LFS setstripe -c 1 $DIR/$tfile.s$O
10118                 local S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.s$O))
10119
10120                 (( $S == ($O & 0666) )) ||
10121                         error "lfs setstripe $DIR/$tfile.s$O '$S' != '$O'"
10122
10123                 $LFS setstripe -E16M -c 1 -E1G -S4M $DIR/$tfile.p$O
10124                 S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.p$O))
10125                 (( $S == ($O & 0666) )) ||
10126                         error "lfs setstripe -E $DIR/$tfile.p$O '$S' != '$O'"
10127
10128                 $LFS setstripe -N2 -c 1 $DIR/$tfile.m$O
10129                 S=$(printf "%04o" 0$(stat -c%a $DIR/$tfile.m$O))
10130                 (( $S == ($O & 0666) )) ||
10131                         error "lfs setstripe -N2 $DIR/$tfile.m$O '$S' != '$O'"
10132                 rm -f $DIR/$tfile.[smp]$0
10133                 } &
10134                 local pid=$!
10135
10136                 # limit the concurrently running threads to 64. LU-11878
10137                 local idx=$((U % 64))
10138                 [ -z "${pids[idx]}" ] || wait ${pids[idx]}
10139                 pids[idx]=$pid
10140         done
10141         wait
10142 }
10143 run_test 103b "umask lfs setstripe"
10144
10145 test_103c() {
10146         mkdir -p $DIR/$tdir
10147         cp -rp $DIR/$tdir $DIR/$tdir.bak
10148
10149         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
10150                 error "$DIR/$tdir shouldn't contain default ACL"
10151         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
10152                 error "$DIR/$tdir.bak shouldn't contain default ACL"
10153         true
10154 }
10155 run_test 103c "'cp -rp' won't set empty acl"
10156
10157 test_104a() {
10158         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10159
10160         touch $DIR/$tfile
10161         lfs df || error "lfs df failed"
10162         lfs df -ih || error "lfs df -ih failed"
10163         lfs df -h $DIR || error "lfs df -h $DIR failed"
10164         lfs df -i $DIR || error "lfs df -i $DIR failed"
10165         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
10166         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
10167
10168         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
10169         lctl --device %$OSC deactivate
10170         lfs df || error "lfs df with deactivated OSC failed"
10171         lctl --device %$OSC activate
10172         # wait the osc back to normal
10173         wait_osc_import_ready client ost
10174
10175         lfs df || error "lfs df with reactivated OSC failed"
10176         rm -f $DIR/$tfile
10177 }
10178 run_test 104a "lfs df [-ih] [path] test ========================="
10179
10180 test_104b() {
10181         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10182         [ $RUNAS_ID -eq $UID ] &&
10183                 skip_env "RUNAS_ID = UID = $UID -- skipping"
10184
10185         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
10186                         grep "Permission denied" | wc -l)))
10187         if [ $denied_cnt -ne 0 ]; then
10188                 error "lfs check servers test failed"
10189         fi
10190 }
10191 run_test 104b "$RUNAS lfs check servers test ===================="
10192
10193 test_105a() {
10194         # doesn't work on 2.4 kernels
10195         touch $DIR/$tfile
10196         if $(flock_is_enabled); then
10197                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
10198         else
10199                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
10200         fi
10201         rm -f $DIR/$tfile
10202 }
10203 run_test 105a "flock when mounted without -o flock test ========"
10204
10205 test_105b() {
10206         touch $DIR/$tfile
10207         if $(flock_is_enabled); then
10208                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
10209         else
10210                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
10211         fi
10212         rm -f $DIR/$tfile
10213 }
10214 run_test 105b "fcntl when mounted without -o flock test ========"
10215
10216 test_105c() {
10217         touch $DIR/$tfile
10218         if $(flock_is_enabled); then
10219                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
10220         else
10221                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
10222         fi
10223         rm -f $DIR/$tfile
10224 }
10225 run_test 105c "lockf when mounted without -o flock test"
10226
10227 test_105d() { # bug 15924
10228         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10229
10230         test_mkdir $DIR/$tdir
10231         flock_is_enabled || skip_env "mount w/o flock enabled"
10232         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
10233         $LCTL set_param fail_loc=0x80000315
10234         flocks_test 2 $DIR/$tdir
10235 }
10236 run_test 105d "flock race (should not freeze) ========"
10237
10238 test_105e() { # bug 22660 && 22040
10239         flock_is_enabled || skip_env "mount w/o flock enabled"
10240
10241         touch $DIR/$tfile
10242         flocks_test 3 $DIR/$tfile
10243 }
10244 run_test 105e "Two conflicting flocks from same process"
10245
10246 test_106() { #bug 10921
10247         test_mkdir $DIR/$tdir
10248         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
10249         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
10250 }
10251 run_test 106 "attempt exec of dir followed by chown of that dir"
10252
10253 test_107() {
10254         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10255
10256         CDIR=`pwd`
10257         local file=core
10258
10259         cd $DIR
10260         rm -f $file
10261
10262         local save_pattern=$(sysctl -n kernel.core_pattern)
10263         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
10264         sysctl -w kernel.core_pattern=$file
10265         sysctl -w kernel.core_uses_pid=0
10266
10267         ulimit -c unlimited
10268         sleep 60 &
10269         SLEEPPID=$!
10270
10271         sleep 1
10272
10273         kill -s 11 $SLEEPPID
10274         wait $SLEEPPID
10275         if [ -e $file ]; then
10276                 size=`stat -c%s $file`
10277                 [ $size -eq 0 ] && error "Fail to create core file $file"
10278         else
10279                 error "Fail to create core file $file"
10280         fi
10281         rm -f $file
10282         sysctl -w kernel.core_pattern=$save_pattern
10283         sysctl -w kernel.core_uses_pid=$save_uses_pid
10284         cd $CDIR
10285 }
10286 run_test 107 "Coredump on SIG"
10287
10288 test_110() {
10289         test_mkdir $DIR/$tdir
10290         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255)
10291         $LFS mkdir -c $MDSCOUNT $DIR/$tdir/$(str_repeat 'b' 256) &&
10292                 error "mkdir with 256 char should fail, but did not"
10293         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
10294                 error "create with 255 char failed"
10295         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
10296                 error "create with 256 char should fail, but did not"
10297
10298         ls -l $DIR/$tdir
10299         rm -rf $DIR/$tdir
10300 }
10301 run_test 110 "filename length checking"
10302
10303 #
10304 # Purpose: To verify dynamic thread (OSS) creation.
10305 #
10306 test_115() {
10307         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10308         remote_ost_nodsh && skip "remote OST with nodsh"
10309
10310         # Lustre does not stop service threads once they are started.
10311         # Reset number of running threads to default.
10312         stopall
10313         setupall
10314
10315         local OSTIO_pre
10316         local save_params="$TMP/sanity-$TESTNAME.parameters"
10317
10318         # Get ll_ost_io count before I/O
10319         OSTIO_pre=$(do_facet ost1 \
10320                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
10321         # Exit if lustre is not running (ll_ost_io not running).
10322         [ -z "$OSTIO_pre" ] && error "no OSS threads"
10323
10324         echo "Starting with $OSTIO_pre threads"
10325         local thread_max=$((OSTIO_pre * 2))
10326         local rpc_in_flight=$((thread_max * 2))
10327         # Number of I/O Process proposed to be started.
10328         local nfiles
10329         local facets=$(get_facets OST)
10330
10331         save_lustre_params client "osc.*OST*.max_rpcs_in_flight" > $save_params
10332         save_lustre_params $facets "ost.OSS.ost_io.threads_max" >> $save_params
10333
10334         # Set in_flight to $rpc_in_flight
10335         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
10336                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
10337         nfiles=${rpc_in_flight}
10338         # Set ost thread_max to $thread_max
10339         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
10340
10341         # 5 Minutes should be sufficient for max number of OSS
10342         # threads(thread_max) to be created.
10343         local timeout=300
10344
10345         # Start I/O.
10346         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
10347         test_mkdir $DIR/$tdir
10348         for i in $(seq $nfiles); do
10349                 local file=$DIR/$tdir/${tfile}-$i
10350                 $LFS setstripe -c -1 -i 0 $file
10351                 ($WTL $file $timeout)&
10352         done
10353
10354         # I/O Started - Wait for thread_started to reach thread_max or report
10355         # error if thread_started is more than thread_max.
10356         echo "Waiting for thread_started to reach thread_max"
10357         local thread_started=0
10358         local end_time=$((SECONDS + timeout))
10359
10360         while [ $SECONDS -le $end_time ] ; do
10361                 echo -n "."
10362                 # Get ost i/o thread_started count.
10363                 thread_started=$(do_facet ost1 \
10364                         "$LCTL get_param \
10365                         ost.OSS.ost_io.threads_started | cut -d= -f2")
10366                 # Break out if thread_started is equal/greater than thread_max
10367                 if [[ $thread_started -ge $thread_max ]]; then
10368                         echo ll_ost_io thread_started $thread_started, \
10369                                 equal/greater than thread_max $thread_max
10370                         break
10371                 fi
10372                 sleep 1
10373         done
10374
10375         # Cleanup - We have the numbers, Kill i/o jobs if running.
10376         jobcount=($(jobs -p))
10377         for i in $(seq 0 $((${#jobcount[@]}-1)))
10378         do
10379                 kill -9 ${jobcount[$i]}
10380                 if [ $? -ne 0 ] ; then
10381                         echo Warning: \
10382                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
10383                 fi
10384         done
10385
10386         # Cleanup files left by WTL binary.
10387         for i in $(seq $nfiles); do
10388                 local file=$DIR/$tdir/${tfile}-$i
10389                 rm -rf $file
10390                 if [ $? -ne 0 ] ; then
10391                         echo "Warning: Failed to delete file $file"
10392                 fi
10393         done
10394
10395         restore_lustre_params <$save_params
10396         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
10397
10398         # Error out if no new thread has started or Thread started is greater
10399         # than thread max.
10400         if [[ $thread_started -le $OSTIO_pre ||
10401                         $thread_started -gt $thread_max ]]; then
10402                 error "ll_ost_io: thread_started $thread_started" \
10403                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
10404                       "No new thread started or thread started greater " \
10405                       "than thread_max."
10406         fi
10407 }
10408 run_test 115 "verify dynamic thread creation===================="
10409
10410 free_min_max () {
10411         wait_delete_completed
10412         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
10413         echo "OST kbytes available: ${AVAIL[@]}"
10414         MAXV=${AVAIL[0]}
10415         MAXI=0
10416         MINV=${AVAIL[0]}
10417         MINI=0
10418         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
10419                 #echo OST $i: ${AVAIL[i]}kb
10420                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
10421                         MAXV=${AVAIL[i]}
10422                         MAXI=$i
10423                 fi
10424                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
10425                         MINV=${AVAIL[i]}
10426                         MINI=$i
10427                 fi
10428         done
10429         echo "Min free space: OST $MINI: $MINV"
10430         echo "Max free space: OST $MAXI: $MAXV"
10431 }
10432
10433 test_116a() { # was previously test_116()
10434         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10435         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
10436         remote_mds_nodsh && skip "remote MDS with nodsh"
10437
10438         echo -n "Free space priority "
10439         do_facet $SINGLEMDS lctl get_param -n lo[vd].*-mdtlov.qos_prio_free |
10440                 head -n1
10441         declare -a AVAIL
10442         free_min_max
10443
10444         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip"
10445         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip"
10446         trap simple_cleanup_common EXIT
10447
10448         # Check if we need to generate uneven OSTs
10449         test_mkdir -p $DIR/$tdir/OST${MINI}
10450         local FILL=$((MINV / 4))
10451         local DIFF=$((MAXV - MINV))
10452         local DIFF2=$((DIFF * 100 / MINV))
10453
10454         local threshold=$(do_facet $SINGLEMDS \
10455                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
10456         threshold=${threshold%%%}
10457         echo -n "Check for uneven OSTs: "
10458         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
10459
10460         if [[ $DIFF2 -gt $threshold ]]; then
10461                 echo "ok"
10462                 echo "Don't need to fill OST$MINI"
10463         else
10464                 # generate uneven OSTs. Write 2% over the QOS threshold value
10465                 echo "no"
10466                 DIFF=$((threshold - DIFF2 + 2))
10467                 DIFF2=$((MINV * DIFF / 100))
10468                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
10469                 $LFS setstripe -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
10470                         error "setstripe failed"
10471                 DIFF=$((DIFF2 / 2048))
10472                 i=0
10473                 while [ $i -lt $DIFF ]; do
10474                         i=$((i + 1))
10475                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
10476                                 bs=2M count=1 2>/dev/null
10477                         echo -n .
10478                 done
10479                 echo .
10480                 sync
10481                 sleep_maxage
10482                 free_min_max
10483         fi
10484
10485         DIFF=$((MAXV - MINV))
10486         DIFF2=$((DIFF * 100 / MINV))
10487         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
10488         if [ $DIFF2 -gt $threshold ]; then
10489                 echo "ok"
10490         else
10491                 echo "failed - QOS mode won't be used"
10492                 simple_cleanup_common
10493                 skip "QOS imbalance criteria not met"
10494         fi
10495
10496         MINI1=$MINI
10497         MINV1=$MINV
10498         MAXI1=$MAXI
10499         MAXV1=$MAXV
10500
10501         # now fill using QOS
10502         $LFS setstripe -c 1 $DIR/$tdir
10503         FILL=$((FILL / 200))
10504         if [ $FILL -gt 600 ]; then
10505                 FILL=600
10506         fi
10507         echo "writing $FILL files to QOS-assigned OSTs"
10508         i=0
10509         while [ $i -lt $FILL ]; do
10510                 i=$((i + 1))
10511                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
10512                         count=1 2>/dev/null
10513                 echo -n .
10514         done
10515         echo "wrote $i 200k files"
10516         sync
10517         sleep_maxage
10518
10519         echo "Note: free space may not be updated, so measurements might be off"
10520         free_min_max
10521         DIFF2=$((MAXV - MINV))
10522         echo "free space delta: orig $DIFF final $DIFF2"
10523         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
10524         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
10525         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
10526         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
10527         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
10528         if [[ $DIFF -gt 0 ]]; then
10529                 FILL=$((DIFF2 * 100 / DIFF - 100))
10530                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
10531         fi
10532
10533         # Figure out which files were written where
10534         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
10535                awk '/'$MINI1': / {print $2; exit}')
10536         echo $UUID
10537         MINC=$($LFS getstripe --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
10538         echo "$MINC files created on smaller OST $MINI1"
10539         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
10540                awk '/'$MAXI1': / {print $2; exit}')
10541         echo $UUID
10542         MAXC=$($LFS getstripe --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
10543         echo "$MAXC files created on larger OST $MAXI1"
10544         if [[ $MINC -gt 0 ]]; then
10545                 FILL=$((MAXC * 100 / MINC - 100))
10546                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
10547         fi
10548         [[ $MAXC -gt $MINC ]] ||
10549                 error_ignore LU-9 "stripe QOS didn't balance free space"
10550         simple_cleanup_common
10551 }
10552 run_test 116a "stripe QOS: free space balance ==================="
10553
10554 test_116b() { # LU-2093
10555         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10556         remote_mds_nodsh && skip "remote MDS with nodsh"
10557
10558 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
10559         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
10560                        lo[vd].$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
10561         [ -z "$old_rr" ] && skip "no QOS"
10562         do_facet $SINGLEMDS lctl set_param \
10563                 lo[vd].$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
10564         mkdir -p $DIR/$tdir
10565         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
10566         createmany -o $DIR/$tdir/f- 20 || error "can't create"
10567         do_facet $SINGLEMDS lctl set_param fail_loc=0
10568         rm -rf $DIR/$tdir
10569         do_facet $SINGLEMDS lctl set_param \
10570                 lo[vd].$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
10571 }
10572 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
10573
10574 test_117() # bug 10891
10575 {
10576         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10577
10578         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
10579         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
10580         lctl set_param fail_loc=0x21e
10581         > $DIR/$tfile || error "truncate failed"
10582         lctl set_param fail_loc=0
10583         echo "Truncate succeeded."
10584         rm -f $DIR/$tfile
10585 }
10586 run_test 117 "verify osd extend =========="
10587
10588 NO_SLOW_RESENDCOUNT=4
10589 export OLD_RESENDCOUNT=""
10590 set_resend_count () {
10591         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
10592         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
10593         lctl set_param -n $PROC_RESENDCOUNT $1
10594         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
10595 }
10596
10597 # for reduce test_118* time (b=14842)
10598 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
10599
10600 # Reset async IO behavior after error case
10601 reset_async() {
10602         FILE=$DIR/reset_async
10603
10604         # Ensure all OSCs are cleared
10605         $LFS setstripe -c -1 $FILE
10606         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
10607         sync
10608         rm $FILE
10609 }
10610
10611 test_118a() #bug 11710
10612 {
10613         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10614
10615         reset_async
10616
10617         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10618         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10619         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
10620
10621         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10622                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10623                 return 1;
10624         fi
10625         rm -f $DIR/$tfile
10626 }
10627 run_test 118a "verify O_SYNC works =========="
10628
10629 test_118b()
10630 {
10631         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10632         remote_ost_nodsh && skip "remote OST with nodsh"
10633
10634         reset_async
10635
10636         #define OBD_FAIL_SRV_ENOENT 0x217
10637         set_nodes_failloc "$(osts_nodes)" 0x217
10638         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10639         RC=$?
10640         set_nodes_failloc "$(osts_nodes)" 0
10641         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10642         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10643                     grep -c writeback)
10644
10645         if [[ $RC -eq 0 ]]; then
10646                 error "Must return error due to dropped pages, rc=$RC"
10647                 return 1;
10648         fi
10649
10650         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10651                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10652                 return 1;
10653         fi
10654
10655         echo "Dirty pages not leaked on ENOENT"
10656
10657         # Due to the above error the OSC will issue all RPCs syncronously
10658         # until a subsequent RPC completes successfully without error.
10659         $MULTIOP $DIR/$tfile Ow4096yc
10660         rm -f $DIR/$tfile
10661
10662         return 0
10663 }
10664 run_test 118b "Reclaim dirty pages on fatal error =========="
10665
10666 test_118c()
10667 {
10668         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10669
10670         # for 118c, restore the original resend count, LU-1940
10671         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
10672                                 set_resend_count $OLD_RESENDCOUNT
10673         remote_ost_nodsh && skip "remote OST with nodsh"
10674
10675         reset_async
10676
10677         #define OBD_FAIL_OST_EROFS               0x216
10678         set_nodes_failloc "$(osts_nodes)" 0x216
10679
10680         # multiop should block due to fsync until pages are written
10681         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
10682         MULTIPID=$!
10683         sleep 1
10684
10685         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
10686                 error "Multiop failed to block on fsync, pid=$MULTIPID"
10687         fi
10688
10689         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10690                     grep -c writeback)
10691         if [[ $WRITEBACK -eq 0 ]]; then
10692                 error "No page in writeback, writeback=$WRITEBACK"
10693         fi
10694
10695         set_nodes_failloc "$(osts_nodes)" 0
10696         wait $MULTIPID
10697         RC=$?
10698         if [[ $RC -ne 0 ]]; then
10699                 error "Multiop fsync failed, rc=$RC"
10700         fi
10701
10702         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10703         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10704                     grep -c writeback)
10705         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10706                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10707         fi
10708
10709         rm -f $DIR/$tfile
10710         echo "Dirty pages flushed via fsync on EROFS"
10711         return 0
10712 }
10713 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
10714
10715 # continue to use small resend count to reduce test_118* time (b=14842)
10716 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
10717
10718 test_118d()
10719 {
10720         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10721         remote_ost_nodsh && skip "remote OST with nodsh"
10722
10723         reset_async
10724
10725         #define OBD_FAIL_OST_BRW_PAUSE_BULK
10726         set_nodes_failloc "$(osts_nodes)" 0x214
10727         # multiop should block due to fsync until pages are written
10728         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
10729         MULTIPID=$!
10730         sleep 1
10731
10732         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
10733                 error "Multiop failed to block on fsync, pid=$MULTIPID"
10734         fi
10735
10736         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10737                     grep -c writeback)
10738         if [[ $WRITEBACK -eq 0 ]]; then
10739                 error "No page in writeback, writeback=$WRITEBACK"
10740         fi
10741
10742         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
10743         set_nodes_failloc "$(osts_nodes)" 0
10744
10745         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10746         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10747                     grep -c writeback)
10748         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10749                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10750         fi
10751
10752         rm -f $DIR/$tfile
10753         echo "Dirty pages gaurenteed flushed via fsync"
10754         return 0
10755 }
10756 run_test 118d "Fsync validation inject a delay of the bulk =========="
10757
10758 test_118f() {
10759         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10760
10761         reset_async
10762
10763         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
10764         lctl set_param fail_loc=0x8000040a
10765
10766         # Should simulate EINVAL error which is fatal
10767         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10768         RC=$?
10769         if [[ $RC -eq 0 ]]; then
10770                 error "Must return error due to dropped pages, rc=$RC"
10771         fi
10772
10773         lctl set_param fail_loc=0x0
10774
10775         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10776         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10777         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10778                     grep -c writeback)
10779         if [[ $LOCKED -ne 0 ]]; then
10780                 error "Locked pages remain in cache, locked=$LOCKED"
10781         fi
10782
10783         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10784                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10785         fi
10786
10787         rm -f $DIR/$tfile
10788         echo "No pages locked after fsync"
10789
10790         reset_async
10791         return 0
10792 }
10793 run_test 118f "Simulate unrecoverable OSC side error =========="
10794
10795 test_118g() {
10796         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10797
10798         reset_async
10799
10800         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
10801         lctl set_param fail_loc=0x406
10802
10803         # simulate local -ENOMEM
10804         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10805         RC=$?
10806
10807         lctl set_param fail_loc=0
10808         if [[ $RC -eq 0 ]]; then
10809                 error "Must return error due to dropped pages, rc=$RC"
10810         fi
10811
10812         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10813         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10814         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10815                         grep -c writeback)
10816         if [[ $LOCKED -ne 0 ]]; then
10817                 error "Locked pages remain in cache, locked=$LOCKED"
10818         fi
10819
10820         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10821                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10822         fi
10823
10824         rm -f $DIR/$tfile
10825         echo "No pages locked after fsync"
10826
10827         reset_async
10828         return 0
10829 }
10830 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
10831
10832 test_118h() {
10833         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10834         remote_ost_nodsh && skip "remote OST with nodsh"
10835
10836         reset_async
10837
10838         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
10839         set_nodes_failloc "$(osts_nodes)" 0x20e
10840         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
10841         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10842         RC=$?
10843
10844         set_nodes_failloc "$(osts_nodes)" 0
10845         if [[ $RC -eq 0 ]]; then
10846                 error "Must return error due to dropped pages, rc=$RC"
10847         fi
10848
10849         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10850         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10851         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
10852                     grep -c writeback)
10853         if [[ $LOCKED -ne 0 ]]; then
10854                 error "Locked pages remain in cache, locked=$LOCKED"
10855         fi
10856
10857         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10858                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10859         fi
10860
10861         rm -f $DIR/$tfile
10862         echo "No pages locked after fsync"
10863
10864         return 0
10865 }
10866 run_test 118h "Verify timeout in handling recoverables errors  =========="
10867
10868 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
10869
10870 test_118i() {
10871         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10872         remote_ost_nodsh && skip "remote OST with nodsh"
10873
10874         reset_async
10875
10876         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
10877         set_nodes_failloc "$(osts_nodes)" 0x20e
10878
10879         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
10880         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
10881         PID=$!
10882         sleep 5
10883         set_nodes_failloc "$(osts_nodes)" 0
10884
10885         wait $PID
10886         RC=$?
10887         if [[ $RC -ne 0 ]]; then
10888                 error "got error, but should be not, rc=$RC"
10889         fi
10890
10891         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10892         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10893         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
10894         if [[ $LOCKED -ne 0 ]]; then
10895                 error "Locked pages remain in cache, locked=$LOCKED"
10896         fi
10897
10898         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10899                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10900         fi
10901
10902         rm -f $DIR/$tfile
10903         echo "No pages locked after fsync"
10904
10905         return 0
10906 }
10907 run_test 118i "Fix error before timeout in recoverable error  =========="
10908
10909 [ "$SLOW" = "no" ] && set_resend_count 4
10910
10911 test_118j() {
10912         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10913         remote_ost_nodsh && skip "remote OST with nodsh"
10914
10915         reset_async
10916
10917         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
10918         set_nodes_failloc "$(osts_nodes)" 0x220
10919
10920         # return -EIO from OST
10921         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
10922         RC=$?
10923         set_nodes_failloc "$(osts_nodes)" 0x0
10924         if [[ $RC -eq 0 ]]; then
10925                 error "Must return error due to dropped pages, rc=$RC"
10926         fi
10927
10928         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
10929         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
10930         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
10931         if [[ $LOCKED -ne 0 ]]; then
10932                 error "Locked pages remain in cache, locked=$LOCKED"
10933         fi
10934
10935         # in recoverable error on OST we want resend and stay until it finished
10936         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
10937                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
10938         fi
10939
10940         rm -f $DIR/$tfile
10941         echo "No pages locked after fsync"
10942
10943         return 0
10944 }
10945 run_test 118j "Simulate unrecoverable OST side error =========="
10946
10947 test_118k()
10948 {
10949         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10950         remote_ost_nodsh && skip "remote OSTs with nodsh"
10951
10952         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
10953         set_nodes_failloc "$(osts_nodes)" 0x20e
10954         test_mkdir $DIR/$tdir
10955
10956         for ((i=0;i<10;i++)); do
10957                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
10958                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
10959                 SLEEPPID=$!
10960                 sleep 0.500s
10961                 kill $SLEEPPID
10962                 wait $SLEEPPID
10963         done
10964
10965         set_nodes_failloc "$(osts_nodes)" 0
10966         rm -rf $DIR/$tdir
10967 }
10968 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
10969
10970 test_118l() # LU-646
10971 {
10972         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10973
10974         test_mkdir $DIR/$tdir
10975         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
10976         rm -rf $DIR/$tdir
10977 }
10978 run_test 118l "fsync dir"
10979
10980 test_118m() # LU-3066
10981 {
10982         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10983
10984         test_mkdir $DIR/$tdir
10985         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
10986         rm -rf $DIR/$tdir
10987 }
10988 run_test 118m "fdatasync dir ========="
10989
10990 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
10991
10992 test_118n()
10993 {
10994         local begin
10995         local end
10996
10997         [ $PARALLEL == "yes" ] && skip "skip parallel run"
10998         remote_ost_nodsh && skip "remote OSTs with nodsh"
10999
11000         # Sleep to avoid a cached response.
11001         #define OBD_STATFS_CACHE_SECONDS 1
11002         sleep 2
11003
11004         # Inject a 10 second delay in the OST_STATFS handler.
11005         #define OBD_FAIL_OST_STATFS_DELAY 0x242
11006         set_nodes_failloc "$(osts_nodes)" 0x242
11007
11008         begin=$SECONDS
11009         stat --file-system $MOUNT > /dev/null
11010         end=$SECONDS
11011
11012         set_nodes_failloc "$(osts_nodes)" 0
11013
11014         if ((end - begin > 20)); then
11015             error "statfs took $((end - begin)) seconds, expected 10"
11016         fi
11017 }
11018 run_test 118n "statfs() sends OST_STATFS requests in parallel"
11019
11020 test_119a() # bug 11737
11021 {
11022         BSIZE=$((512 * 1024))
11023         directio write $DIR/$tfile 0 1 $BSIZE
11024         # We ask to read two blocks, which is more than a file size.
11025         # directio will indicate an error when requested and actual
11026         # sizes aren't equeal (a normal situation in this case) and
11027         # print actual read amount.
11028         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
11029         if [ "$NOB" != "$BSIZE" ]; then
11030                 error "read $NOB bytes instead of $BSIZE"
11031         fi
11032         rm -f $DIR/$tfile
11033 }
11034 run_test 119a "Short directIO read must return actual read amount"
11035
11036 test_119b() # bug 11737
11037 {
11038         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
11039
11040         $LFS setstripe -c 2 $DIR/$tfile || error "setstripe failed"
11041         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
11042         sync
11043         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) ||
11044                 error "direct read failed"
11045         rm -f $DIR/$tfile
11046 }
11047 run_test 119b "Sparse directIO read must return actual read amount"
11048
11049 test_119c() # bug 13099
11050 {
11051         BSIZE=1048576
11052         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
11053         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
11054         rm -f $DIR/$tfile
11055 }
11056 run_test 119c "Testing for direct read hitting hole"
11057
11058 test_119d() # bug 15950
11059 {
11060         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11061
11062         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
11063         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
11064         BSIZE=1048576
11065         $LFS setstripe $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
11066         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
11067         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
11068         lctl set_param fail_loc=0x40d
11069         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
11070         pid_dio=$!
11071         sleep 1
11072         cat $DIR/$tfile > /dev/null &
11073         lctl set_param fail_loc=0
11074         pid_reads=$!
11075         wait $pid_dio
11076         log "the DIO writes have completed, now wait for the reads (should not block very long)"
11077         sleep 2
11078         [ -n "`ps h -p $pid_reads -o comm`" ] && \
11079         error "the read rpcs have not completed in 2s"
11080         rm -f $DIR/$tfile
11081         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
11082 }
11083 run_test 119d "The DIO path should try to send a new rpc once one is completed"
11084
11085 test_120a() {
11086         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11087         remote_mds_nodsh && skip "remote MDS with nodsh"
11088         test_mkdir -i0 -c1 $DIR/$tdir
11089         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11090                 skip_env "no early lock cancel on server"
11091
11092         lru_resize_disable mdc
11093         lru_resize_disable osc
11094         cancel_lru_locks mdc
11095         # asynchronous object destroy at MDT could cause bl ast to client
11096         cancel_lru_locks osc
11097
11098         stat $DIR/$tdir > /dev/null
11099         can1=$(do_facet mds1 \
11100                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11101                awk '/ldlm_cancel/ {print $2}')
11102         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11103                awk '/ldlm_bl_callback/ {print $2}')
11104         test_mkdir -i0 -c1 $DIR/$tdir/d1
11105         can2=$(do_facet mds1 \
11106                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11107                awk '/ldlm_cancel/ {print $2}')
11108         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11109                awk '/ldlm_bl_callback/ {print $2}')
11110         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11111         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11112         lru_resize_enable mdc
11113         lru_resize_enable osc
11114 }
11115 run_test 120a "Early Lock Cancel: mkdir test"
11116
11117 test_120b() {
11118         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11119         remote_mds_nodsh && skip "remote MDS with nodsh"
11120         test_mkdir $DIR/$tdir
11121         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11122                 skip_env "no early lock cancel on server"
11123
11124         lru_resize_disable mdc
11125         lru_resize_disable osc
11126         cancel_lru_locks mdc
11127         stat $DIR/$tdir > /dev/null
11128         can1=$(do_facet $SINGLEMDS \
11129                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11130                awk '/ldlm_cancel/ {print $2}')
11131         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11132                awk '/ldlm_bl_callback/ {print $2}')
11133         touch $DIR/$tdir/f1
11134         can2=$(do_facet $SINGLEMDS \
11135                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11136                awk '/ldlm_cancel/ {print $2}')
11137         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11138                awk '/ldlm_bl_callback/ {print $2}')
11139         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11140         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11141         lru_resize_enable mdc
11142         lru_resize_enable osc
11143 }
11144 run_test 120b "Early Lock Cancel: create test"
11145
11146 test_120c() {
11147         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11148         remote_mds_nodsh && skip "remote MDS with nodsh"
11149         test_mkdir -i0 -c1 $DIR/$tdir
11150         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11151                 skip "no early lock cancel on server"
11152
11153         lru_resize_disable mdc
11154         lru_resize_disable osc
11155         test_mkdir -i0 -c1 $DIR/$tdir/d1
11156         test_mkdir -i0 -c1 $DIR/$tdir/d2
11157         touch $DIR/$tdir/d1/f1
11158         cancel_lru_locks mdc
11159         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
11160         can1=$(do_facet mds1 \
11161                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11162                awk '/ldlm_cancel/ {print $2}')
11163         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11164                awk '/ldlm_bl_callback/ {print $2}')
11165         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
11166         can2=$(do_facet mds1 \
11167                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11168                awk '/ldlm_cancel/ {print $2}')
11169         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11170                awk '/ldlm_bl_callback/ {print $2}')
11171         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11172         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11173         lru_resize_enable mdc
11174         lru_resize_enable osc
11175 }
11176 run_test 120c "Early Lock Cancel: link test"
11177
11178 test_120d() {
11179         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11180         remote_mds_nodsh && skip "remote MDS with nodsh"
11181         test_mkdir -i0 -c1 $DIR/$tdir
11182         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11183                 skip_env "no early lock cancel on server"
11184
11185         lru_resize_disable mdc
11186         lru_resize_disable osc
11187         touch $DIR/$tdir
11188         cancel_lru_locks mdc
11189         stat $DIR/$tdir > /dev/null
11190         can1=$(do_facet mds1 \
11191                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11192                awk '/ldlm_cancel/ {print $2}')
11193         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11194                awk '/ldlm_bl_callback/ {print $2}')
11195         chmod a+x $DIR/$tdir
11196         can2=$(do_facet mds1 \
11197                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11198                awk '/ldlm_cancel/ {print $2}')
11199         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11200                awk '/ldlm_bl_callback/ {print $2}')
11201         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11202         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11203         lru_resize_enable mdc
11204         lru_resize_enable osc
11205 }
11206 run_test 120d "Early Lock Cancel: setattr test"
11207
11208 test_120e() {
11209         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11210         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11211                 skip_env "no early lock cancel on server"
11212         remote_mds_nodsh && skip "remote MDS with nodsh"
11213
11214         local dlmtrace_set=false
11215
11216         test_mkdir -i0 -c1 $DIR/$tdir
11217         lru_resize_disable mdc
11218         lru_resize_disable osc
11219         ! $LCTL get_param debug | grep -q dlmtrace &&
11220                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
11221         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
11222         cancel_lru_locks mdc
11223         cancel_lru_locks osc
11224         dd if=$DIR/$tdir/f1 of=/dev/null
11225         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
11226         # XXX client can not do early lock cancel of OST lock
11227         # during unlink (LU-4206), so cancel osc lock now.
11228         sleep 2
11229         cancel_lru_locks osc
11230         can1=$(do_facet mds1 \
11231                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11232                awk '/ldlm_cancel/ {print $2}')
11233         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11234                awk '/ldlm_bl_callback/ {print $2}')
11235         unlink $DIR/$tdir/f1
11236         sleep 5
11237         can2=$(do_facet mds1 \
11238                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11239                awk '/ldlm_cancel/ {print $2}')
11240         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11241                awk '/ldlm_bl_callback/ {print $2}')
11242         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
11243                 $LCTL dk $TMP/cancel.debug.txt
11244         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
11245                 $LCTL dk $TMP/blocking.debug.txt
11246         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
11247         lru_resize_enable mdc
11248         lru_resize_enable osc
11249 }
11250 run_test 120e "Early Lock Cancel: unlink test"
11251
11252 test_120f() {
11253         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11254         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11255                 skip_env "no early lock cancel on server"
11256         remote_mds_nodsh && skip "remote MDS with nodsh"
11257
11258         test_mkdir -i0 -c1 $DIR/$tdir
11259         lru_resize_disable mdc
11260         lru_resize_disable osc
11261         test_mkdir -i0 -c1 $DIR/$tdir/d1
11262         test_mkdir -i0 -c1 $DIR/$tdir/d2
11263         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
11264         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
11265         cancel_lru_locks mdc
11266         cancel_lru_locks osc
11267         dd if=$DIR/$tdir/d1/f1 of=/dev/null
11268         dd if=$DIR/$tdir/d2/f2 of=/dev/null
11269         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
11270         # XXX client can not do early lock cancel of OST lock
11271         # during rename (LU-4206), so cancel osc lock now.
11272         sleep 2
11273         cancel_lru_locks osc
11274         can1=$(do_facet mds1 \
11275                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11276                awk '/ldlm_cancel/ {print $2}')
11277         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11278                awk '/ldlm_bl_callback/ {print $2}')
11279         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
11280         sleep 5
11281         can2=$(do_facet mds1 \
11282                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11283                awk '/ldlm_cancel/ {print $2}')
11284         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11285                awk '/ldlm_bl_callback/ {print $2}')
11286         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
11287         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
11288         lru_resize_enable mdc
11289         lru_resize_enable osc
11290 }
11291 run_test 120f "Early Lock Cancel: rename test"
11292
11293 test_120g() {
11294         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11295         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
11296                 skip_env "no early lock cancel on server"
11297         remote_mds_nodsh && skip "remote MDS with nodsh"
11298
11299         lru_resize_disable mdc
11300         lru_resize_disable osc
11301         count=10000
11302         echo create $count files
11303         test_mkdir $DIR/$tdir
11304         cancel_lru_locks mdc
11305         cancel_lru_locks osc
11306         t0=$(date +%s)
11307
11308         can0=$(do_facet $SINGLEMDS \
11309                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11310                awk '/ldlm_cancel/ {print $2}')
11311         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11312                awk '/ldlm_bl_callback/ {print $2}')
11313         createmany -o $DIR/$tdir/f $count
11314         sync
11315         can1=$(do_facet $SINGLEMDS \
11316                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11317                awk '/ldlm_cancel/ {print $2}')
11318         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11319                awk '/ldlm_bl_callback/ {print $2}')
11320         t1=$(date +%s)
11321         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
11322         echo rm $count files
11323         rm -r $DIR/$tdir
11324         sync
11325         can2=$(do_facet $SINGLEMDS \
11326                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
11327                awk '/ldlm_cancel/ {print $2}')
11328         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
11329                awk '/ldlm_bl_callback/ {print $2}')
11330         t2=$(date +%s)
11331         echo total: $count removes in $((t2-t1))
11332         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
11333         sleep 2
11334         # wait for commitment of removal
11335         lru_resize_enable mdc
11336         lru_resize_enable osc
11337 }
11338 run_test 120g "Early Lock Cancel: performance test"
11339
11340 test_121() { #bug #10589
11341         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11342
11343         rm -rf $DIR/$tfile
11344         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
11345 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
11346         lctl set_param fail_loc=0x310
11347         cancel_lru_locks osc > /dev/null
11348         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
11349         lctl set_param fail_loc=0
11350         [[ $reads -eq $writes ]] ||
11351                 error "read $reads blocks, must be $writes blocks"
11352 }
11353 run_test 121 "read cancel race ========="
11354
11355 test_123a() { # was test 123, statahead(bug 11401)
11356         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11357
11358         SLOWOK=0
11359         if ! grep -q "processor.*: 1" /proc/cpuinfo; then
11360                 log "testing UP system. Performance may be lower than expected."
11361                 SLOWOK=1
11362         fi
11363
11364         rm -rf $DIR/$tdir
11365         test_mkdir $DIR/$tdir
11366         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
11367         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
11368         MULT=10
11369         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
11370                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
11371
11372                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
11373                 lctl set_param -n llite.*.statahead_max 0
11374                 lctl get_param llite.*.statahead_max
11375                 cancel_lru_locks mdc
11376                 cancel_lru_locks osc
11377                 stime=`date +%s`
11378                 time ls -l $DIR/$tdir | wc -l
11379                 etime=`date +%s`
11380                 delta=$((etime - stime))
11381                 log "ls $i files without statahead: $delta sec"
11382                 lctl set_param llite.*.statahead_max=$max
11383
11384                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
11385                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
11386                 cancel_lru_locks mdc
11387                 cancel_lru_locks osc
11388                 stime=`date +%s`
11389                 time ls -l $DIR/$tdir | wc -l
11390                 etime=`date +%s`
11391                 delta_sa=$((etime - stime))
11392                 log "ls $i files with statahead: $delta_sa sec"
11393                 lctl get_param -n llite.*.statahead_stats
11394                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
11395
11396                 [[ $swrong -lt $ewrong ]] &&
11397                         log "statahead was stopped, maybe too many locks held!"
11398                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
11399
11400                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
11401                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
11402                     lctl set_param -n llite.*.statahead_max 0
11403                     lctl get_param llite.*.statahead_max
11404                     cancel_lru_locks mdc
11405                     cancel_lru_locks osc
11406                     stime=`date +%s`
11407                     time ls -l $DIR/$tdir | wc -l
11408                     etime=`date +%s`
11409                     delta=$((etime - stime))
11410                     log "ls $i files again without statahead: $delta sec"
11411                     lctl set_param llite.*.statahead_max=$max
11412                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
11413                         if [  $SLOWOK -eq 0 ]; then
11414                                 error "ls $i files is slower with statahead!"
11415                         else
11416                                 log "ls $i files is slower with statahead!"
11417                         fi
11418                         break
11419                     fi
11420                 fi
11421
11422                 [ $delta -gt 20 ] && break
11423                 [ $delta -gt 8 ] && MULT=$((50 / delta))
11424                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
11425         done
11426         log "ls done"
11427
11428         stime=`date +%s`
11429         rm -r $DIR/$tdir
11430         sync
11431         etime=`date +%s`
11432         delta=$((etime - stime))
11433         log "rm -r $DIR/$tdir/: $delta seconds"
11434         log "rm done"
11435         lctl get_param -n llite.*.statahead_stats
11436 }
11437 run_test 123a "verify statahead work"
11438
11439 test_123b () { # statahead(bug 15027)
11440         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11441
11442         test_mkdir $DIR/$tdir
11443         createmany -o $DIR/$tdir/$tfile-%d 1000
11444
11445         cancel_lru_locks mdc
11446         cancel_lru_locks osc
11447
11448 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
11449         lctl set_param fail_loc=0x80000803
11450         ls -lR $DIR/$tdir > /dev/null
11451         log "ls done"
11452         lctl set_param fail_loc=0x0
11453         lctl get_param -n llite.*.statahead_stats
11454         rm -r $DIR/$tdir
11455         sync
11456
11457 }
11458 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
11459
11460 test_123c() {
11461         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
11462
11463         test_mkdir -i 0 -c 1 $DIR/$tdir.0
11464         test_mkdir -i 1 -c 1 $DIR/$tdir.1
11465         touch $DIR/$tdir.1/{1..3}
11466         mv $DIR/$tdir.1/{1..3} $DIR/$tdir.0
11467
11468         remount_client $MOUNT
11469
11470         $MULTIOP $DIR/$tdir.0 Q
11471
11472         # let statahead to complete
11473         ls -l $DIR/$tdir.0 > /dev/null
11474
11475         testid=$(echo $TESTNAME | tr '_' ' ')
11476         dmesg | tac | sed "/$testid/,$ d" | grep "Can not initialize inode" &&
11477                 error "statahead warning" || true
11478 }
11479 run_test 123c "Can not initialize inode warning on DNE statahead"
11480
11481 test_124a() {
11482         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11483         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
11484                 skip_env "no lru resize on server"
11485
11486         local NR=2000
11487
11488         test_mkdir $DIR/$tdir
11489
11490         log "create $NR files at $DIR/$tdir"
11491         createmany -o $DIR/$tdir/f $NR ||
11492                 error "failed to create $NR files in $DIR/$tdir"
11493
11494         cancel_lru_locks mdc
11495         ls -l $DIR/$tdir > /dev/null
11496
11497         local NSDIR=""
11498         local LRU_SIZE=0
11499         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
11500                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
11501                 LRU_SIZE=$($LCTL get_param -n $PARAM)
11502                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
11503                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
11504                         log "NSDIR=$NSDIR"
11505                         log "NS=$(basename $NSDIR)"
11506                         break
11507                 fi
11508         done
11509
11510         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
11511                 skip "Not enough cached locks created!"
11512         fi
11513         log "LRU=$LRU_SIZE"
11514
11515         local SLEEP=30
11516
11517         # We know that lru resize allows one client to hold $LIMIT locks
11518         # for 10h. After that locks begin to be killed by client.
11519         local MAX_HRS=10
11520         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
11521         log "LIMIT=$LIMIT"
11522         if [ $LIMIT -lt $LRU_SIZE ]; then
11523                 skip "Limit is too small $LIMIT"
11524         fi
11525
11526         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
11527         # killing locks. Some time was spent for creating locks. This means
11528         # that up to the moment of sleep finish we must have killed some of
11529         # them (10-100 locks). This depends on how fast ther were created.
11530         # Many of them were touched in almost the same moment and thus will
11531         # be killed in groups.
11532         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
11533
11534         # Use $LRU_SIZE_B here to take into account real number of locks
11535         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
11536         local LRU_SIZE_B=$LRU_SIZE
11537         log "LVF=$LVF"
11538         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
11539         log "OLD_LVF=$OLD_LVF"
11540         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
11541
11542         # Let's make sure that we really have some margin. Client checks
11543         # cached locks every 10 sec.
11544         SLEEP=$((SLEEP+20))
11545         log "Sleep ${SLEEP} sec"
11546         local SEC=0
11547         while ((SEC<$SLEEP)); do
11548                 echo -n "..."
11549                 sleep 5
11550                 SEC=$((SEC+5))
11551                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
11552                 echo -n "$LRU_SIZE"
11553         done
11554         echo ""
11555         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
11556         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
11557
11558         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
11559                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
11560                 unlinkmany $DIR/$tdir/f $NR
11561                 return
11562         }
11563
11564         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
11565         log "unlink $NR files at $DIR/$tdir"
11566         unlinkmany $DIR/$tdir/f $NR
11567 }
11568 run_test 124a "lru resize ======================================="
11569
11570 get_max_pool_limit()
11571 {
11572         local limit=$($LCTL get_param \
11573                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
11574         local max=0
11575         for l in $limit; do
11576                 if [[ $l -gt $max ]]; then
11577                         max=$l
11578                 fi
11579         done
11580         echo $max
11581 }
11582
11583 test_124b() {
11584         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11585         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
11586                 skip_env "no lru resize on server"
11587
11588         LIMIT=$(get_max_pool_limit)
11589
11590         NR=$(($(default_lru_size)*20))
11591         if [[ $NR -gt $LIMIT ]]; then
11592                 log "Limit lock number by $LIMIT locks"
11593                 NR=$LIMIT
11594         fi
11595
11596         IFree=$(mdsrate_inodes_available)
11597         if [ $IFree -lt $NR ]; then
11598                 log "Limit lock number by $IFree inodes"
11599                 NR=$IFree
11600         fi
11601
11602         lru_resize_disable mdc
11603         test_mkdir -p $DIR/$tdir/disable_lru_resize
11604
11605         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
11606         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
11607         cancel_lru_locks mdc
11608         stime=`date +%s`
11609         PID=""
11610         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
11611         PID="$PID $!"
11612         sleep 2
11613         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
11614         PID="$PID $!"
11615         sleep 2
11616         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
11617         PID="$PID $!"
11618         wait $PID
11619         etime=`date +%s`
11620         nolruresize_delta=$((etime-stime))
11621         log "ls -la time: $nolruresize_delta seconds"
11622         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
11623         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
11624
11625         lru_resize_enable mdc
11626         test_mkdir -p $DIR/$tdir/enable_lru_resize
11627
11628         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
11629         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
11630         cancel_lru_locks mdc
11631         stime=`date +%s`
11632         PID=""
11633         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
11634         PID="$PID $!"
11635         sleep 2
11636         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
11637         PID="$PID $!"
11638         sleep 2
11639         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
11640         PID="$PID $!"
11641         wait $PID
11642         etime=`date +%s`
11643         lruresize_delta=$((etime-stime))
11644         log "ls -la time: $lruresize_delta seconds"
11645         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
11646
11647         if [ $lruresize_delta -gt $nolruresize_delta ]; then
11648                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
11649         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
11650                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
11651         else
11652                 log "lru resize performs the same with no lru resize"
11653         fi
11654         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
11655 }
11656 run_test 124b "lru resize (performance test) ======================="
11657
11658 test_124c() {
11659         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11660         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
11661                 skip_env "no lru resize on server"
11662
11663         # cache ununsed locks on client
11664         local nr=100
11665         cancel_lru_locks mdc
11666         test_mkdir $DIR/$tdir
11667         createmany -o $DIR/$tdir/f $nr ||
11668                 error "failed to create $nr files in $DIR/$tdir"
11669         ls -l $DIR/$tdir > /dev/null
11670
11671         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
11672         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
11673         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
11674         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
11675         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
11676
11677         # set lru_max_age to 1 sec
11678         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
11679         echo "sleep $((recalc_p * 2)) seconds..."
11680         sleep $((recalc_p * 2))
11681
11682         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
11683         # restore lru_max_age
11684         $LCTL set_param -n $nsdir.lru_max_age $max_age
11685         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
11686         unlinkmany $DIR/$tdir/f $nr
11687 }
11688 run_test 124c "LRUR cancel very aged locks"
11689
11690 test_124d() {
11691         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11692         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
11693                 skip_env "no lru resize on server"
11694
11695         # cache ununsed locks on client
11696         local nr=100
11697
11698         lru_resize_disable mdc
11699         stack_trap "lru_resize_enable mdc" EXIT
11700
11701         cancel_lru_locks mdc
11702
11703         # asynchronous object destroy at MDT could cause bl ast to client
11704         test_mkdir $DIR/$tdir
11705         createmany -o $DIR/$tdir/f $nr ||
11706                 error "failed to create $nr files in $DIR/$tdir"
11707         stack_trap "unlinkmany $DIR/$tdir/f $nr" EXIT
11708
11709         ls -l $DIR/$tdir > /dev/null
11710
11711         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
11712         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
11713         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
11714         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
11715
11716         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
11717
11718         # set lru_max_age to 1 sec
11719         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
11720         stack_trap "$LCTL set_param -n $nsdir.lru_max_age $max_age" EXIT
11721
11722         echo "sleep $((recalc_p * 2)) seconds..."
11723         sleep $((recalc_p * 2))
11724
11725         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
11726
11727         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
11728 }
11729 run_test 124d "cancel very aged locks if lru-resize diasbaled"
11730
11731 test_125() { # 13358
11732         $LCTL get_param -n llite.*.client_type | grep -q local ||
11733                 skip "must run as local client"
11734         $LCTL get_param -n mdc.*-mdc-*.connect_flags | grep -q acl ||
11735                 skip_env "must have acl enabled"
11736         [ -z "$(which setfacl)" ] && skip_env "must have setfacl tool"
11737
11738         test_mkdir $DIR/$tdir
11739         $LFS setstripe -S 65536 -c -1 $DIR/$tdir || error "setstripe failed"
11740         setfacl -R -m u:bin:rwx $DIR/$tdir || error "setfacl $DIR/$tdir failed"
11741         ls -ld $DIR/$tdir || error "cannot access $DIR/$tdir"
11742 }
11743 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
11744
11745 test_126() { # bug 12829/13455
11746         $GSS && skip_env "must run as gss disabled"
11747         $LCTL get_param -n llite.*.client_type | grep -q local ||
11748                 skip "must run as local client"
11749         [ "$UID" != 0 ] && skip "must run as root, not UID $UID"
11750
11751         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
11752         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
11753         rm -f $DIR/$tfile
11754         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
11755 }
11756 run_test 126 "check that the fsgid provided by the client is taken into account"
11757
11758 test_127a() { # bug 15521
11759         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11760         local name count samp unit min max sum sumsq
11761
11762         $LFS setstripe -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
11763         echo "stats before reset"
11764         $LCTL get_param osc.*.stats
11765         $LCTL set_param osc.*.stats=0
11766         local fsize=$((2048 * 1024))
11767
11768         dd if=/dev/zero of=$DIR/$tfile bs=$fsize count=1
11769         cancel_lru_locks osc
11770         dd if=$DIR/$tfile of=/dev/null bs=$fsize
11771
11772         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/$tfile.tmp
11773         stack_trap "rm -f $TMP/$tfile.tmp"
11774         while read name count samp unit min max sum sumsq; do
11775                 echo "got name=$name count=$count unit=$unit min=$min max=$max"
11776                 [ ! $min ] && error "Missing min value for $name proc entry"
11777                 eval $name=$count || error "Wrong proc format"
11778
11779                 case $name in
11780                 read_bytes|write_bytes)
11781                         [[ "$unit" =~ "bytes" ]] ||
11782                                 error "unit is not 'bytes': $unit"
11783                         (( $min >= 4096 )) || error "min is too small: $min"
11784                         (( $min <= $fsize )) || error "min is too big: $min"
11785                         (( $max >= 4096 )) || error "max is too small: $max"
11786                         (( $max <= $fsize )) || error "max is too big: $max"
11787                         (( $sum == $fsize )) || error "sum is wrong: $sum"
11788                         (( $sumsq >= ($fsize / 4096) * (4096 * 4096) )) ||
11789                                 error "sumsquare is too small: $sumsq"
11790                         (( $sumsq <= $fsize * $fsize )) ||
11791                                 error "sumsquare is too big: $sumsq"
11792                         ;;
11793                 ost_read|ost_write)
11794                         [[ "$unit" =~ "usec" ]] ||
11795                                 error "unit is not 'usec': $unit"
11796                         ;;
11797                 *)      ;;
11798                 esac
11799         done < $DIR/$tfile.tmp
11800
11801         #check that we actually got some stats
11802         [ "$read_bytes" ] || error "Missing read_bytes stats"
11803         [ "$write_bytes" ] || error "Missing write_bytes stats"
11804         [ "$read_bytes" != 0 ] || error "no read done"
11805         [ "$write_bytes" != 0 ] || error "no write done"
11806 }
11807 run_test 127a "verify the client stats are sane"
11808
11809 test_127b() { # bug LU-333
11810         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11811         local name count samp unit min max sum sumsq
11812
11813         echo "stats before reset"
11814         $LCTL get_param llite.*.stats
11815         $LCTL set_param llite.*.stats=0
11816
11817         # perform 2 reads and writes so MAX is different from SUM.
11818         dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE count=1
11819         dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE count=1
11820         cancel_lru_locks osc
11821         dd if=$DIR/$tfile of=/dev/null bs=$PAGE_SIZE count=1
11822         dd if=$DIR/$tfile of=/dev/null bs=$PAGE_SIZE count=1
11823
11824         $LCTL get_param llite.*.stats | grep samples > $TMP/$tfile.tmp
11825         stack_trap "rm -f $TMP/$tfile.tmp"
11826         while read name count samp unit min max sum sumsq; do
11827                 echo "got name=$name count=$count unit=$unit min=$min max=$max"
11828                 eval $name=$count || error "Wrong proc format"
11829
11830                 case $name in
11831                 read_bytes|write_bytes)
11832                         [[ "$unit" =~ "bytes" ]] ||
11833                                 error "unit is not 'bytes': $unit"
11834                         (( $count == 2 )) || error "count is not 2: $count"
11835                         (( $min == $PAGE_SIZE )) ||
11836                                 error "min is not $PAGE_SIZE: $min"
11837                         (( $max == $PAGE_SIZE )) ||
11838                                 error "max is not $PAGE_SIZE: $max"
11839                         (( $sum == $PAGE_SIZE * 2 )) ||
11840                                 error "sum is not $((PAGE_SIZE * 2)): $sum"
11841                         ;;
11842                 read|write)
11843                         [[ "$unit" =~ "usec" ]] ||
11844                                 error "unit is not 'usec': $unit"
11845                         ;;
11846                 *)      ;;
11847                 esac
11848         done < $TMP/$tfile.tmp
11849
11850         #check that we actually got some stats
11851         [ "$read_bytes" ] || error "Missing read_bytes stats"
11852         [ "$write_bytes" ] || error "Missing write_bytes stats"
11853         [ "$read_bytes" != 0 ] || error "no read done"
11854         [ "$write_bytes" != 0 ] || error "no write done"
11855 }
11856 run_test 127b "verify the llite client stats are sane"
11857
11858 test_127c() { # LU-12394
11859         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
11860         local size
11861         local bsize
11862         local reads
11863         local writes
11864         local count
11865
11866         $LCTL set_param llite.*.extents_stats=1
11867         stack_trap "$LCTL set_param llite.*.extents_stats=0" EXIT
11868
11869         # Use two stripes so there is enough space in default config
11870         $LFS setstripe -c 2 $DIR/$tfile
11871
11872         # Extent stats start at 0-4K and go in power of two buckets
11873         # LL_HIST_START = 12 --> 2^12 = 4K
11874         # We do 3K*2^i, so 3K, 6K, 12K, 24K... hitting each bucket.
11875         # We do not do buckets larger than 64 MiB to avoid ENOSPC issues on
11876         # small configs
11877         for size in 3K 6K 12K 24K 48K 96K 192K 384K 768K 1536K 3M 6M 12M 24M 48M;
11878                 do
11879                 # Write and read, 2x each, second time at a non-zero offset
11880                 dd if=/dev/zero of=$DIR/$tfile bs=$size count=1
11881                 dd if=/dev/zero of=$DIR/$tfile bs=$size count=1 seek=10
11882                 dd if=$DIR/$tfile of=/dev/null bs=$size count=1
11883                 dd if=$DIR/$tfile of=/dev/null bs=$size count=1 seek=10
11884                 rm -f $DIR/$tfile
11885         done
11886
11887         $LCTL get_param llite.*.extents_stats
11888
11889         count=2
11890         for bsize in 4K 8K 16K 32K 64K 128K 256K 512K 1M 2M 4M 8M 16M 32M 64M;
11891                 do
11892                 local bucket=$($LCTL get_param -n llite.*.extents_stats |
11893                                 grep -m 1 $bsize)
11894                 reads=$(echo $bucket | awk '{print $5}')
11895                 writes=$(echo $bucket | awk '{print $9}')
11896                 [ "$reads" -eq $count ] ||
11897                         error "$reads reads in < $bsize bucket, expect $count"
11898                 [ "$writes" -eq $count ] ||
11899                         error "$writes writes in < $bsize bucket, expect $count"
11900         done
11901
11902         # Test mmap write and read
11903         $LCTL set_param llite.*.extents_stats=c
11904         size=512
11905         dd if=/dev/zero of=$DIR/$tfile bs=${size}K count=1
11906         $MULTIOP $DIR/$tfile OSMRUc || error "$MULTIOP $DIR/$tfile failed"
11907         $MULTIOP $DIR/$tfile OSMWUc || error "$MULTIOP $DIR/$tfile failed"
11908
11909         $LCTL get_param llite.*.extents_stats
11910
11911         count=$(((size*1024) / PAGE_SIZE))
11912
11913         bsize=$((2 * PAGE_SIZE / 1024))K
11914
11915         bucket=$($LCTL get_param -n llite.*.extents_stats |
11916                         grep -m 1 $bsize)
11917         reads=$(echo $bucket | awk '{print $5}')
11918         writes=$(echo $bucket | awk '{print $9}')
11919         # mmap writes fault in the page first, creating an additonal read
11920         [ "$reads" -eq $((2 * count)) ] ||
11921                 error "$reads reads in < $bsize bucket, expect $count"
11922         [ "$writes" -eq $count ] ||
11923                 error "$writes writes in < $bsize bucket, expect $count"
11924 }
11925 run_test 127c "test llite extent stats with regular & mmap i/o"
11926
11927 test_128() { # bug 15212
11928         touch $DIR/$tfile
11929         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
11930                 find $DIR/$tfile
11931                 find $DIR/$tfile
11932         EOF
11933
11934         result=$(grep error $TMP/$tfile.log)
11935         rm -f $DIR/$tfile $TMP/$tfile.log
11936         [ -z "$result" ] ||
11937                 error "consecutive find's under interactive lfs failed"
11938 }
11939 run_test 128 "interactive lfs for 2 consecutive find's"
11940
11941 set_dir_limits () {
11942         local mntdev
11943         local canondev
11944         local node
11945
11946         local ldproc=/proc/fs/ldiskfs
11947         local facets=$(get_facets MDS)
11948
11949         for facet in ${facets//,/ }; do
11950                 canondev=$(ldiskfs_canon \
11951                            *.$(convert_facet2label $facet).mntdev $facet)
11952                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
11953                         ldproc=/sys/fs/ldiskfs
11954                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
11955                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
11956         done
11957 }
11958
11959 check_mds_dmesg() {
11960         local facets=$(get_facets MDS)
11961         for facet in ${facets//,/ }; do
11962                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
11963         done
11964         return 1
11965 }
11966
11967 test_129() {
11968         [ $PARALLEL == "yes" ] && skip "skip parallel run"
11969         [[ $MDS1_VERSION -ge $(version_code 2.5.56) ]] ||
11970                 skip "Need MDS version with at least 2.5.56"
11971         if [ "$mds1_FSTYPE" != ldiskfs ]; then
11972                 skip_env "ldiskfs only test"
11973         fi
11974         remote_mds_nodsh && skip "remote MDS with nodsh"
11975
11976         local ENOSPC=28
11977         local EFBIG=27
11978         local has_warning=false
11979
11980         rm -rf $DIR/$tdir
11981         mkdir -p $DIR/$tdir
11982
11983         # block size of mds1
11984         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
11985         set_dir_limits $maxsize $maxsize
11986         local dirsize=$(stat -c%s "$DIR/$tdir")
11987         local nfiles=0
11988         while [[ $dirsize -le $maxsize ]]; do
11989                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
11990                 rc=$?
11991                 if ! $has_warning; then
11992                         check_mds_dmesg '"is approaching"' && has_warning=true
11993                 fi
11994                 # check two errors:
11995                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
11996                 # EFBIG for previous versions included in ldiskfs series
11997                 if [ $rc -eq $EFBIG ] || [ $rc -eq $ENOSPC ]; then
11998                         set_dir_limits 0 0
11999                         echo "return code $rc received as expected"
12000
12001                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
12002                                 error_exit "create failed w/o dir size limit"
12003
12004                         check_mds_dmesg '"has reached"' ||
12005                                 error_exit "reached message should be output"
12006
12007                         [ $has_warning = "false" ] &&
12008                                 error_exit "warning message should be output"
12009
12010                         dirsize=$(stat -c%s "$DIR/$tdir")
12011
12012                         [[ $dirsize -ge $maxsize ]] && return 0
12013                         error_exit "current dir size $dirsize, " \
12014                                    "previous limit $maxsize"
12015                 elif [ $rc -ne 0 ]; then
12016                         set_dir_limits 0 0
12017                         error_exit "return $rc received instead of expected " \
12018                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
12019                 fi
12020                 nfiles=$((nfiles + 1))
12021                 dirsize=$(stat -c%s "$DIR/$tdir")
12022         done
12023
12024         set_dir_limits 0 0
12025         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
12026 }
12027 run_test 129 "test directory size limit ========================"
12028
12029 OLDIFS="$IFS"
12030 cleanup_130() {
12031         trap 0
12032         IFS="$OLDIFS"
12033 }
12034
12035 test_130a() {
12036         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12037         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
12038
12039         trap cleanup_130 EXIT RETURN
12040
12041         local fm_file=$DIR/$tfile
12042         $LFS setstripe -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
12043         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
12044                 error "dd failed for $fm_file"
12045
12046         # LU-1795: test filefrag/FIEMAP once, even if unsupported
12047         filefrag -ves $fm_file
12048         RC=$?
12049         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12050                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12051         [ $RC != 0 ] && error "filefrag $fm_file failed"
12052
12053         filefrag_op=$(filefrag -ve -k $fm_file |
12054                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12055         lun=$($LFS getstripe -i $fm_file)
12056
12057         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
12058         IFS=$'\n'
12059         tot_len=0
12060         for line in $filefrag_op
12061         do
12062                 frag_lun=`echo $line | cut -d: -f5`
12063                 ext_len=`echo $line | cut -d: -f4`
12064                 if (( $frag_lun != $lun )); then
12065                         cleanup_130
12066                         error "FIEMAP on 1-stripe file($fm_file) failed"
12067                         return
12068                 fi
12069                 (( tot_len += ext_len ))
12070         done
12071
12072         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
12073                 cleanup_130
12074                 error "FIEMAP on 1-stripe file($fm_file) failed;"
12075                 return
12076         fi
12077
12078         cleanup_130
12079
12080         echo "FIEMAP on single striped file succeeded"
12081 }
12082 run_test 130a "FIEMAP (1-stripe file)"
12083
12084 test_130b() {
12085         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
12086
12087         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12088         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
12089
12090         trap cleanup_130 EXIT RETURN
12091
12092         local fm_file=$DIR/$tfile
12093         $LFS setstripe -S 65536 -c $OSTCOUNT $fm_file ||
12094                         error "setstripe on $fm_file"
12095         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12096                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12097
12098         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
12099                 error "dd failed on $fm_file"
12100
12101         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12102         filefrag_op=$(filefrag -ve -k $fm_file |
12103                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12104
12105         last_lun=$(echo $filefrag_op | cut -d: -f5 |
12106                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12107
12108         IFS=$'\n'
12109         tot_len=0
12110         num_luns=1
12111         for line in $filefrag_op
12112         do
12113                 frag_lun=$(echo $line | cut -d: -f5 |
12114                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12115                 ext_len=$(echo $line | cut -d: -f4)
12116                 if (( $frag_lun != $last_lun )); then
12117                         if (( tot_len != 1024 )); then
12118                                 cleanup_130
12119                                 error "FIEMAP on $fm_file failed; returned " \
12120                                 "len $tot_len for OST $last_lun instead of 1024"
12121                                 return
12122                         else
12123                                 (( num_luns += 1 ))
12124                                 tot_len=0
12125                         fi
12126                 fi
12127                 (( tot_len += ext_len ))
12128                 last_lun=$frag_lun
12129         done
12130         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
12131                 cleanup_130
12132                 error "FIEMAP on $fm_file failed; returned wrong number of " \
12133                         "luns or wrong len for OST $last_lun"
12134                 return
12135         fi
12136
12137         cleanup_130
12138
12139         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
12140 }
12141 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
12142
12143 test_130c() {
12144         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
12145
12146         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12147         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
12148
12149         trap cleanup_130 EXIT RETURN
12150
12151         local fm_file=$DIR/$tfile
12152         $LFS setstripe -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
12153         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12154                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12155
12156         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
12157                         error "dd failed on $fm_file"
12158
12159         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12160         filefrag_op=$(filefrag -ve -k $fm_file |
12161                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12162
12163         last_lun=$(echo $filefrag_op | cut -d: -f5 |
12164                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12165
12166         IFS=$'\n'
12167         tot_len=0
12168         num_luns=1
12169         for line in $filefrag_op
12170         do
12171                 frag_lun=$(echo $line | cut -d: -f5 |
12172                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12173                 ext_len=$(echo $line | cut -d: -f4)
12174                 if (( $frag_lun != $last_lun )); then
12175                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
12176                         if (( logical != 512 )); then
12177                                 cleanup_130
12178                                 error "FIEMAP on $fm_file failed; returned " \
12179                                 "logical start for lun $logical instead of 512"
12180                                 return
12181                         fi
12182                         if (( tot_len != 512 )); then
12183                                 cleanup_130
12184                                 error "FIEMAP on $fm_file failed; returned " \
12185                                 "len $tot_len for OST $last_lun instead of 1024"
12186                                 return
12187                         else
12188                                 (( num_luns += 1 ))
12189                                 tot_len=0
12190                         fi
12191                 fi
12192                 (( tot_len += ext_len ))
12193                 last_lun=$frag_lun
12194         done
12195         if (( num_luns != 2 || tot_len != 512 )); then
12196                 cleanup_130
12197                 error "FIEMAP on $fm_file failed; returned wrong number of " \
12198                         "luns or wrong len for OST $last_lun"
12199                 return
12200         fi
12201
12202         cleanup_130
12203
12204         echo "FIEMAP on 2-stripe file with hole succeeded"
12205 }
12206 run_test 130c "FIEMAP (2-stripe file with hole)"
12207
12208 test_130d() {
12209         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs"
12210
12211         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12212         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
12213
12214         trap cleanup_130 EXIT RETURN
12215
12216         local fm_file=$DIR/$tfile
12217         $LFS setstripe -S 65536 -c $OSTCOUNT $fm_file ||
12218                         error "setstripe on $fm_file"
12219         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12220                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12221
12222         local actual_stripe_count=$($LFS getstripe -c $fm_file)
12223         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripe_count ||
12224                 error "dd failed on $fm_file"
12225
12226         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12227         filefrag_op=$(filefrag -ve -k $fm_file |
12228                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12229
12230         last_lun=$(echo $filefrag_op | cut -d: -f5 |
12231                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12232
12233         IFS=$'\n'
12234         tot_len=0
12235         num_luns=1
12236         for line in $filefrag_op
12237         do
12238                 frag_lun=$(echo $line | cut -d: -f5 |
12239                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12240                 ext_len=$(echo $line | cut -d: -f4)
12241                 if (( $frag_lun != $last_lun )); then
12242                         if (( tot_len != 1024 )); then
12243                                 cleanup_130
12244                                 error "FIEMAP on $fm_file failed; returned " \
12245                                 "len $tot_len for OST $last_lun instead of 1024"
12246                                 return
12247                         else
12248                                 (( num_luns += 1 ))
12249                                 tot_len=0
12250                         fi
12251                 fi
12252                 (( tot_len += ext_len ))
12253                 last_lun=$frag_lun
12254         done
12255         if (( num_luns != actual_stripe_count || tot_len != 1024 )); then
12256                 cleanup_130
12257                 error "FIEMAP on $fm_file failed; returned wrong number of " \
12258                         "luns or wrong len for OST $last_lun"
12259                 return
12260         fi
12261
12262         cleanup_130
12263
12264         echo "FIEMAP on N-stripe file succeeded"
12265 }
12266 run_test 130d "FIEMAP (N-stripe file)"
12267
12268 test_130e() {
12269         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
12270
12271         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12272         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP"
12273
12274         trap cleanup_130 EXIT RETURN
12275
12276         local fm_file=$DIR/$tfile
12277         $LFS setstripe -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
12278         [ "$(facet_fstype ost$(($($LFS getstripe -i $fm_file) + 1)))" = "zfs" ] &&
12279                 skip_env "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
12280
12281         NUM_BLKS=512
12282         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
12283         for ((i = 0; i < $NUM_BLKS; i++))
12284         do
12285                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
12286         done
12287
12288         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12289         filefrag_op=$(filefrag -ve -k $fm_file |
12290                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
12291
12292         last_lun=$(echo $filefrag_op | cut -d: -f5 |
12293                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12294
12295         IFS=$'\n'
12296         tot_len=0
12297         num_luns=1
12298         for line in $filefrag_op
12299         do
12300                 frag_lun=$(echo $line | cut -d: -f5 |
12301                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
12302                 ext_len=$(echo $line | cut -d: -f4)
12303                 if (( $frag_lun != $last_lun )); then
12304                         if (( tot_len != $EXPECTED_LEN )); then
12305                                 cleanup_130
12306                                 error "FIEMAP on $fm_file failed; returned " \
12307                                 "len $tot_len for OST $last_lun instead " \
12308                                 "of $EXPECTED_LEN"
12309                                 return
12310                         else
12311                                 (( num_luns += 1 ))
12312                                 tot_len=0
12313                         fi
12314                 fi
12315                 (( tot_len += ext_len ))
12316                 last_lun=$frag_lun
12317         done
12318         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
12319                 cleanup_130
12320                 error "FIEMAP on $fm_file failed; returned wrong number " \
12321                         "of luns or wrong len for OST $last_lun"
12322                 return
12323         fi
12324
12325         cleanup_130
12326
12327         echo "FIEMAP with continuation calls succeeded"
12328 }
12329 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
12330
12331 test_130f() {
12332         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
12333         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP"
12334
12335         local fm_file=$DIR/$tfile
12336         $MULTIOP $fm_file oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T33554432c ||
12337                 error "multiop create with lov_delay_create on $fm_file"
12338
12339         filefrag -ves $fm_file || error "filefrag $fm_file failed"
12340         filefrag_extents=$(filefrag -vek $fm_file |
12341                            awk '/extents? found/ { print $2 }')
12342         if [[ "$filefrag_extents" != "0" ]]; then
12343                 error "FIEMAP on $fm_file failed; " \
12344                       "returned $filefrag_extents expected 0"
12345         fi
12346
12347         rm -f $fm_file
12348 }
12349 run_test 130f "FIEMAP (unstriped file)"
12350
12351 # Test for writev/readv
12352 test_131a() {
12353         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
12354                 error "writev test failed"
12355         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
12356                 error "readv failed"
12357         rm -f $DIR/$tfile
12358 }
12359 run_test 131a "test iov's crossing stripe boundary for writev/readv"
12360
12361 test_131b() {
12362         local fsize=$((524288 + 1048576 + 1572864))
12363         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
12364                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
12365                         error "append writev test failed"
12366
12367         ((fsize += 1572864 + 1048576))
12368         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
12369                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
12370                         error "append writev test failed"
12371         rm -f $DIR/$tfile
12372 }
12373 run_test 131b "test append writev"
12374
12375 test_131c() {
12376         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
12377         error "NOT PASS"
12378 }
12379 run_test 131c "test read/write on file w/o objects"
12380
12381 test_131d() {
12382         rwv -f $DIR/$tfile -w -n 1 1572864
12383         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
12384         if [ "$NOB" != 1572864 ]; then
12385                 error "Short read filed: read $NOB bytes instead of 1572864"
12386         fi
12387         rm -f $DIR/$tfile
12388 }
12389 run_test 131d "test short read"
12390
12391 test_131e() {
12392         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
12393         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
12394         error "read hitting hole failed"
12395         rm -f $DIR/$tfile
12396 }
12397 run_test 131e "test read hitting hole"
12398
12399 check_stats() {
12400         local facet=$1
12401         local op=$2
12402         local want=${3:-0}
12403         local res
12404
12405         case $facet in
12406         mds*) res=$(do_facet $facet \
12407                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
12408                  ;;
12409         ost*) res=$(do_facet $facet \
12410                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
12411                  ;;
12412         *) error "Wrong facet '$facet'" ;;
12413         esac
12414         [ "$res" ] || error "The counter for $op on $facet was not incremented"
12415         # if the argument $3 is zero, it means any stat increment is ok.
12416         if [[ $want -gt 0 ]]; then
12417                 local count=$(echo $res | awk '{ print $2 }')
12418                 [[ $count -ne $want ]] &&
12419                         error "The $op counter on $facet is $count, not $want"
12420         fi
12421 }
12422
12423 test_133a() {
12424         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12425         remote_ost_nodsh && skip "remote OST with nodsh"
12426         remote_mds_nodsh && skip "remote MDS with nodsh"
12427         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
12428                 skip_env "MDS doesn't support rename stats"
12429
12430         local testdir=$DIR/${tdir}/stats_testdir
12431
12432         mkdir -p $DIR/${tdir}
12433
12434         # clear stats.
12435         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12436         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
12437
12438         # verify mdt stats first.
12439         mkdir ${testdir} || error "mkdir failed"
12440         check_stats $SINGLEMDS "mkdir" 1
12441         touch ${testdir}/${tfile} || error "touch failed"
12442         check_stats $SINGLEMDS "open" 1
12443         check_stats $SINGLEMDS "close" 1
12444         [ $MDS1_VERSION -ge $(version_code 2.8.54) ] && {
12445                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
12446                 check_stats $SINGLEMDS "mknod" 2
12447         }
12448         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
12449         check_stats $SINGLEMDS "unlink" 1
12450         rm -f ${testdir}/${tfile} || error "file remove failed"
12451         check_stats $SINGLEMDS "unlink" 2
12452
12453         # remove working dir and check mdt stats again.
12454         rmdir ${testdir} || error "rmdir failed"
12455         check_stats $SINGLEMDS "rmdir" 1
12456
12457         local testdir1=$DIR/${tdir}/stats_testdir1
12458         mkdir -p ${testdir}
12459         mkdir -p ${testdir1}
12460         touch ${testdir1}/test1
12461         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
12462         check_stats $SINGLEMDS "crossdir_rename" 1
12463
12464         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
12465         check_stats $SINGLEMDS "samedir_rename" 1
12466
12467         rm -rf $DIR/${tdir}
12468 }
12469 run_test 133a "Verifying MDT stats ========================================"
12470
12471 test_133b() {
12472         local res
12473
12474         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12475         remote_ost_nodsh && skip "remote OST with nodsh"
12476         remote_mds_nodsh && skip "remote MDS with nodsh"
12477
12478         local testdir=$DIR/${tdir}/stats_testdir
12479
12480         mkdir -p ${testdir} || error "mkdir failed"
12481         touch ${testdir}/${tfile} || error "touch failed"
12482         cancel_lru_locks mdc
12483
12484         # clear stats.
12485         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12486         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
12487
12488         # extra mdt stats verification.
12489         chmod 444 ${testdir}/${tfile} || error "chmod failed"
12490         check_stats $SINGLEMDS "setattr" 1
12491         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12492         if [ $MDS1_VERSION -ne $(version_code 2.2.0) ]
12493         then            # LU-1740
12494                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
12495                 check_stats $SINGLEMDS "getattr" 1
12496         fi
12497         rm -rf $DIR/${tdir}
12498
12499         # when DNE is enabled, MDT uses STATFS RPC to ping other targets
12500         # so the check below is not reliable
12501         [ $MDSCOUNT -eq 1 ] || return 0
12502
12503         # Sleep to avoid a cached response.
12504         #define OBD_STATFS_CACHE_SECONDS 1
12505         sleep 2
12506         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12507         do_facet ost1 $LCTL set_param obdfilter.*.exports.*.stats=clear
12508         $LFS df || error "lfs failed"
12509         check_stats $SINGLEMDS "statfs" 1
12510
12511         # check aggregated statfs (LU-10018)
12512         [ $MDS1_VERSION -lt $(version_code 2.11.54) ] &&
12513                 return 0
12514         [ $CLIENT_VERSION -lt $(version_code 2.11.54) ] &&
12515                 return 0
12516         sleep 2
12517         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12518         do_facet ost1 $LCTL set_param obdfilter.*.exports.*.stats=clear
12519         df $DIR
12520         check_stats $SINGLEMDS "statfs" 1
12521
12522         # We want to check that the client didn't send OST_STATFS to
12523         # ost1 but the MDT also uses OST_STATFS for precreate. So some
12524         # extra care is needed here.
12525         if remote_mds; then
12526                 local nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
12527                 local param="obdfilter.$FSNAME-OST0000.exports.'$nid'.stats"
12528
12529                 res=$(do_facet ost1 $LCTL get_param $param | grep statfs)
12530                 [ "$res" ] && error "OST got STATFS"
12531         fi
12532
12533         return 0
12534 }
12535 run_test 133b "Verifying extra MDT stats =================================="
12536
12537 test_133c() {
12538         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12539         remote_ost_nodsh && skip "remote OST with nodsh"
12540         remote_mds_nodsh && skip "remote MDS with nodsh"
12541
12542         local testdir=$DIR/$tdir/stats_testdir
12543
12544         test_mkdir -p $testdir
12545
12546         # verify obdfilter stats.
12547         $LFS setstripe -c 1 -i 0 $testdir/$tfile
12548         sync
12549         cancel_lru_locks osc
12550         wait_delete_completed
12551
12552         # clear stats.
12553         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
12554         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
12555
12556         dd if=/dev/zero of=$testdir/$tfile conv=notrunc bs=512k count=1 ||
12557                 error "dd failed"
12558         sync
12559         cancel_lru_locks osc
12560         check_stats ost1 "write" 1
12561
12562         dd if=$testdir/$tfile of=/dev/null bs=1k count=1 || error "dd failed"
12563         check_stats ost1 "read" 1
12564
12565         > $testdir/$tfile || error "truncate failed"
12566         check_stats ost1 "punch" 1
12567
12568         rm -f $testdir/$tfile || error "file remove failed"
12569         wait_delete_completed
12570         check_stats ost1 "destroy" 1
12571
12572         rm -rf $DIR/$tdir
12573 }
12574 run_test 133c "Verifying OST stats ========================================"
12575
12576 order_2() {
12577         local value=$1
12578         local orig=$value
12579         local order=1
12580
12581         while [ $value -ge 2 ]; do
12582                 order=$((order*2))
12583                 value=$((value/2))
12584         done
12585
12586         if [ $orig -gt $order ]; then
12587                 order=$((order*2))
12588         fi
12589         echo $order
12590 }
12591
12592 size_in_KMGT() {
12593     local value=$1
12594     local size=('K' 'M' 'G' 'T');
12595     local i=0
12596     local size_string=$value
12597
12598     while [ $value -ge 1024 ]; do
12599         if [ $i -gt 3 ]; then
12600             #T is the biggest unit we get here, if that is bigger,
12601             #just return XXXT
12602             size_string=${value}T
12603             break
12604         fi
12605         value=$((value >> 10))
12606         if [ $value -lt 1024 ]; then
12607             size_string=${value}${size[$i]}
12608             break
12609         fi
12610         i=$((i + 1))
12611     done
12612
12613     echo $size_string
12614 }
12615
12616 get_rename_size() {
12617         local size=$1
12618         local context=${2:-.}
12619         local sample=$(do_facet $SINGLEMDS $LCTL \
12620                 get_param mdt.$FSNAME-MDT0000.rename_stats |
12621                 grep -A1 $context |
12622                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
12623         echo $sample
12624 }
12625
12626 test_133d() {
12627         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12628         remote_ost_nodsh && skip "remote OST with nodsh"
12629         remote_mds_nodsh && skip "remote MDS with nodsh"
12630         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
12631                 skip_env "MDS doesn't support rename stats"
12632
12633         local testdir1=$DIR/${tdir}/stats_testdir1
12634         local testdir2=$DIR/${tdir}/stats_testdir2
12635         mkdir -p $DIR/${tdir}
12636
12637         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
12638
12639         lfs mkdir -i 0 -c 1 ${testdir1} || error "mkdir failed"
12640         lfs mkdir -i 0 -c 1 ${testdir2} || error "mkdir failed"
12641
12642         createmany -o $testdir1/test 512 || error "createmany failed"
12643
12644         # check samedir rename size
12645         mv ${testdir1}/test0 ${testdir1}/test_0
12646
12647         local testdir1_size=$(ls -l $DIR/${tdir} |
12648                 awk '/stats_testdir1/ {print $5}')
12649         local testdir2_size=$(ls -l $DIR/${tdir} |
12650                 awk '/stats_testdir2/ {print $5}')
12651
12652         testdir1_size=$(order_2 $testdir1_size)
12653         testdir2_size=$(order_2 $testdir2_size)
12654
12655         testdir1_size=$(size_in_KMGT $testdir1_size)
12656         testdir2_size=$(size_in_KMGT $testdir2_size)
12657
12658         echo "source rename dir size: ${testdir1_size}"
12659         echo "target rename dir size: ${testdir2_size}"
12660
12661         local cmd="do_facet $SINGLEMDS $LCTL "
12662         cmd+="get_param mdt.$FSNAME-MDT0000.rename_stats"
12663
12664         eval $cmd || error "$cmd failed"
12665         local samedir=$($cmd | grep 'same_dir')
12666         local same_sample=$(get_rename_size $testdir1_size)
12667         [ -z "$samedir" ] && error "samedir_rename_size count error"
12668         [[ $same_sample -eq 1 ]] ||
12669                 error "samedir_rename_size error $same_sample"
12670         echo "Check same dir rename stats success"
12671
12672         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
12673
12674         # check crossdir rename size
12675         mv ${testdir1}/test_0 ${testdir2}/test_0
12676
12677         testdir1_size=$(ls -l $DIR/${tdir} |
12678                 awk '/stats_testdir1/ {print $5}')
12679         testdir2_size=$(ls -l $DIR/${tdir} |
12680                 awk '/stats_testdir2/ {print $5}')
12681
12682         testdir1_size=$(order_2 $testdir1_size)
12683         testdir2_size=$(order_2 $testdir2_size)
12684
12685         testdir1_size=$(size_in_KMGT $testdir1_size)
12686         testdir2_size=$(size_in_KMGT $testdir2_size)
12687
12688         echo "source rename dir size: ${testdir1_size}"
12689         echo "target rename dir size: ${testdir2_size}"
12690
12691         eval $cmd || error "$cmd failed"
12692         local crossdir=$($cmd | grep 'crossdir')
12693         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
12694         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
12695         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
12696         [[ $src_sample -eq 1 ]] ||
12697                 error "crossdir_rename_size error $src_sample"
12698         [[ $tgt_sample -eq 1 ]] ||
12699                 error "crossdir_rename_size error $tgt_sample"
12700         echo "Check cross dir rename stats success"
12701         rm -rf $DIR/${tdir}
12702 }
12703 run_test 133d "Verifying rename_stats ========================================"
12704
12705 test_133e() {
12706         remote_mds_nodsh && skip "remote MDS with nodsh"
12707         remote_ost_nodsh && skip "remote OST with nodsh"
12708         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12709
12710         local testdir=$DIR/${tdir}/stats_testdir
12711         local ctr f0 f1 bs=32768 count=42 sum
12712
12713         mkdir -p ${testdir} || error "mkdir failed"
12714
12715         $LFS setstripe -c 1 -i 0 ${testdir}/${tfile}
12716
12717         for ctr in {write,read}_bytes; do
12718                 sync
12719                 cancel_lru_locks osc
12720
12721                 do_facet ost1 $LCTL set_param -n \
12722                         "obdfilter.*.exports.clear=clear"
12723
12724                 if [ $ctr = write_bytes ]; then
12725                         f0=/dev/zero
12726                         f1=${testdir}/${tfile}
12727                 else
12728                         f0=${testdir}/${tfile}
12729                         f1=/dev/null
12730                 fi
12731
12732                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
12733                         error "dd failed"
12734                 sync
12735                 cancel_lru_locks osc
12736
12737                 sum=$(do_facet ost1 $LCTL get_param \
12738                         "obdfilter.*.exports.*.stats" |
12739                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
12740                                 $1 == ctr { sum += $7 }
12741                                 END { printf("%0.0f", sum) }')
12742
12743                 if ((sum != bs * count)); then
12744                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
12745                 fi
12746         done
12747
12748         rm -rf $DIR/${tdir}
12749 }
12750 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
12751
12752 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
12753
12754 # Some versions of find (4.5.11, 4.5.14) included in CentOS 7.3-7.5 do
12755 # not honor the -ignore_readdir_race option correctly. So we call
12756 # error_ignore() rather than error() in these cases. See LU-11152.
12757 error_133() {
12758         if (find --version; do_facet mds1 find --version) |
12759                 grep -q '\b4\.5\.1[1-4]\b'; then
12760                 error_ignore LU-11152 "$@"
12761         else
12762                 error "$@"
12763         fi
12764 }
12765
12766 test_133f() {
12767         # First without trusting modes.
12768         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
12769         echo "proc_dirs='$proc_dirs'"
12770         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
12771         find $proc_dirs -exec cat '{}' \; &> /dev/null
12772
12773         # Second verifying readability.
12774         $LCTL get_param -R '*' &> /dev/null
12775
12776         # Verifing writability with badarea_io.
12777         find $proc_dirs \
12778                 -ignore_readdir_race \
12779                 -type f \
12780                 -not -name force_lbug \
12781                 -not -name changelog_mask \
12782                 -exec badarea_io '{}' \; ||
12783                         error_133 "find $proc_dirs failed"
12784 }
12785 run_test 133f "Check reads/writes of client lustre proc files with bad area io"
12786
12787 test_133g() {
12788         remote_mds_nodsh && skip "remote MDS with nodsh"
12789         remote_ost_nodsh && skip "remote OST with nodsh"
12790
12791         local facet
12792         for facet in mds1 ost1; do
12793                 local facet_ver=$(lustre_version_code $facet)
12794                 if [ $facet_ver -ge $(version_code 2.7.65) ]; then
12795                         do_facet $facet "$LCTL get_param -R '*'" &> /dev/null
12796                 else
12797                         log "$facet: too old lustre for get_param -R"
12798                 fi
12799                 if [ $facet_ver -ge $(version_code 2.5.54) ]; then
12800                         do_facet $facet "$LCTL list_param -R '*' | grep '=' |
12801                                 tr -d = | egrep -v 'force_lbug|changelog_mask' |
12802                                 xargs badarea_io" ||
12803                                         error_133 "$facet badarea_io failed"
12804                 else
12805                         skip_noexit "$facet: too old lustre for get_param -R"
12806                 fi
12807         done
12808
12809         # remount the FS in case writes/reads /proc break the FS
12810         cleanup || error "failed to unmount"
12811         setup || error "failed to setup"
12812         true
12813 }
12814 run_test 133g "Check reads/writes of server lustre proc files with bad area io"
12815
12816 test_133h() {
12817         remote_mds_nodsh && skip "remote MDS with nodsh"
12818         remote_ost_nodsh && skip "remote OST with nodsh"
12819         [[ $MDS1_VERSION -lt $(version_code 2.9.54) ]] &&
12820                 skip "Need MDS version at least 2.9.54"
12821
12822         local facet
12823
12824         for facet in client mds1 ost1; do
12825                 local facet_proc_dirs=$(do_facet $facet \
12826                                         \\\ls -d $proc_regexp 2> /dev/null)
12827                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
12828                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
12829                 # Get the list of files that are missing the terminating newline
12830                 local missing=($(do_facet $facet \
12831                         find ${facet_proc_dirs} -type f \|              \
12832                                 while read F\; do                       \
12833                                         awk -v FS='\v' -v RS='\v\v'     \
12834                                         "'END { if(NR>0 &&              \
12835                                         \\\$NF !~ /.*\\\n\$/)           \
12836                                                 print FILENAME}'"       \
12837                                         '\$F'\;                         \
12838                                 done 2>/dev/null))
12839                 [ ${#missing[*]} -eq 0 ] ||
12840                         error "files do not end with newline: ${missing[*]}"
12841         done
12842 }
12843 run_test 133h "Proc files should end with newlines"
12844
12845 test_134a() {
12846         remote_mds_nodsh && skip "remote MDS with nodsh"
12847         [[ $MDS1_VERSION -lt $(version_code 2.7.54) ]] &&
12848                 skip "Need MDS version at least 2.7.54"
12849
12850         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
12851         cancel_lru_locks mdc
12852
12853         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
12854         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
12855         [ $unused -eq 0 ] || error "$unused locks are not cleared"
12856
12857         local nr=1000
12858         createmany -o $DIR/$tdir/f $nr ||
12859                 error "failed to create $nr files in $DIR/$tdir"
12860         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
12861
12862         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
12863         do_facet mds1 $LCTL set_param fail_loc=0x327
12864         do_facet mds1 $LCTL set_param fail_val=500
12865         touch $DIR/$tdir/m
12866
12867         echo "sleep 10 seconds ..."
12868         sleep 10
12869         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
12870
12871         do_facet mds1 $LCTL set_param fail_loc=0
12872         do_facet mds1 $LCTL set_param fail_val=0
12873         [ $lck_cnt -lt $unused ] ||
12874                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
12875
12876         rm $DIR/$tdir/m
12877         unlinkmany $DIR/$tdir/f $nr
12878 }
12879 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
12880
12881 test_134b() {
12882         remote_mds_nodsh && skip "remote MDS with nodsh"
12883         [[ $MDS1_VERSION -lt $(version_code 2.7.54) ]] &&
12884                 skip "Need MDS version at least 2.7.54"
12885
12886         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
12887         cancel_lru_locks mdc
12888
12889         local low_wm=$(do_facet mds1 $LCTL get_param -n \
12890                         ldlm.lock_reclaim_threshold_mb)
12891         # disable reclaim temporarily
12892         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
12893
12894         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
12895         do_facet mds1 $LCTL set_param fail_loc=0x328
12896         do_facet mds1 $LCTL set_param fail_val=500
12897
12898         $LCTL set_param debug=+trace
12899
12900         local nr=600
12901         createmany -o $DIR/$tdir/f $nr &
12902         local create_pid=$!
12903
12904         echo "Sleep $TIMEOUT seconds ..."
12905         sleep $TIMEOUT
12906         if ! ps -p $create_pid  > /dev/null 2>&1; then
12907                 do_facet mds1 $LCTL set_param fail_loc=0
12908                 do_facet mds1 $LCTL set_param fail_val=0
12909                 do_facet mds1 $LCTL set_param \
12910                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
12911                 error "createmany finished incorrectly!"
12912         fi
12913         do_facet mds1 $LCTL set_param fail_loc=0
12914         do_facet mds1 $LCTL set_param fail_val=0
12915         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
12916         wait $create_pid || return 1
12917
12918         unlinkmany $DIR/$tdir/f $nr
12919 }
12920 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
12921
12922 test_135() {
12923         remote_mds_nodsh && skip "remote MDS with nodsh"
12924         [[ $MDS1_VERSION -lt $(version_code 2.13.50) ]] &&
12925                 skip "Need MDS version at least 2.13.50"
12926         local fname
12927
12928         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
12929
12930 #define OBD_FAIL_PLAIN_RECORDS 0x1319
12931         #set only one record at plain llog
12932         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1319 fail_val=1
12933
12934         #fill already existed plain llog each 64767
12935         #wrapping whole catalog
12936         createmany -o -u $DIR/$tdir/$tfile- $((64767 * 1))
12937
12938         createmany -o $DIR/$tdir/$tfile_ 64700
12939         for (( i = 0; i < 64700; i = i + 2 ))
12940         do
12941                 rm $DIR/$tdir/$tfile_$i &
12942                 rm $DIR/$tdir/$tfile_$((i + 1)) &
12943                 local pid=$!
12944                 wait $pid
12945         done
12946
12947         #waiting osp synchronization
12948         wait_delete_completed
12949 }
12950 run_test 135 "Race catalog processing"
12951
12952 test_136() {
12953         remote_mds_nodsh && skip "remote MDS with nodsh"
12954         [[ $MDS1_VERSION -lt $(version_code 2.13.50) ]] &&
12955                 skip "Need MDS version at least 2.13.50"
12956         local fname
12957
12958         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
12959         $LFS setstripe -c 1 -i 0 $DIR/$tdir || error "failed to set striping"
12960         #set only one record at plain llog
12961 #define OBD_FAIL_CATALOG_FULL_CHECK                0x131a
12962         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x131a fail_val=1
12963
12964         #fill already existed 2 plain llogs each 64767
12965         #wrapping whole catalog
12966         createmany -o -u $DIR/$tdir/$tfile- $((64767 * 1))
12967         createmany -o -u $DIR/$tdir/$tfile- $((64767 * 3 / 2))
12968         wait_delete_completed
12969
12970         createmany -o $DIR/$tdir/$tfile_ 10
12971         sleep 25
12972
12973         do_facet $SINGLEMDS $LCTL set_param fail_val=3
12974         for (( i = 0; i < 10; i = i + 3 ))
12975         do
12976                 rm $DIR/$tdir/$tfile_$i &
12977                 rm $DIR/$tdir/$tfile_$((i + 1)) &
12978                 local pid=$!
12979                 wait $pid
12980                 sleep 7
12981                 rm $DIR/$tdir/$tfile_$((i + 2)) &
12982         done
12983
12984         #waiting osp synchronization
12985         wait_delete_completed
12986 }
12987 run_test 136 "Race catalog processing 2"
12988
12989 test_140() { #bug-17379
12990         [ $PARALLEL == "yes" ] && skip "skip parallel run"
12991
12992         test_mkdir $DIR/$tdir
12993         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
12994         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
12995
12996         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
12997         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
12998         local i=0
12999         while i=$((i + 1)); do
13000                 test_mkdir $i
13001                 cd $i || error "Changing to $i"
13002                 ln -s ../stat stat || error "Creating stat symlink"
13003                 # Read the symlink until ELOOP present,
13004                 # not LBUGing the system is considered success,
13005                 # we didn't overrun the stack.
13006                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
13007                 if [ $ret -ne 0 ]; then
13008                         if [ $ret -eq 40 ]; then
13009                                 break  # -ELOOP
13010                         else
13011                                 error "Open stat symlink"
13012                                         return
13013                         fi
13014                 fi
13015         done
13016         i=$((i - 1))
13017         echo "The symlink depth = $i"
13018         [ $i -eq 5 ] || [ $i -eq 7 ] || [ $i -eq 8 ] || [ $i -eq 40 ] ||
13019                 error "Invalid symlink depth"
13020
13021         # Test recursive symlink
13022         ln -s symlink_self symlink_self
13023         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
13024         echo "open symlink_self returns $ret"
13025         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
13026 }
13027 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
13028
13029 test_150() {
13030         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13031
13032         local TF="$TMP/$tfile"
13033
13034         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
13035         cp $TF $DIR/$tfile
13036         cancel_lru_locks $OSC
13037         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
13038         remount_client $MOUNT
13039         df -P $MOUNT
13040         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
13041
13042         $TRUNCATE $TF 6000
13043         $TRUNCATE $DIR/$tfile 6000
13044         cancel_lru_locks $OSC
13045         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
13046
13047         echo "12345" >>$TF
13048         echo "12345" >>$DIR/$tfile
13049         cancel_lru_locks $OSC
13050         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
13051
13052         echo "12345" >>$TF
13053         echo "12345" >>$DIR/$tfile
13054         cancel_lru_locks $OSC
13055         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
13056
13057         rm -f $TF
13058         true
13059 }
13060 run_test 150 "truncate/append tests"
13061
13062 #LU-2902 roc_hit was not able to read all values from lproc
13063 function roc_hit_init() {
13064         local list=$(comma_list $(osts_nodes))
13065         local dir=$DIR/$tdir-check
13066         local file=$dir/$tfile
13067         local BEFORE
13068         local AFTER
13069         local idx
13070
13071         test_mkdir $dir
13072         #use setstripe to do a write to every ost
13073         for i in $(seq 0 $((OSTCOUNT-1))); do
13074                 $LFS setstripe -c 1 -i $i $dir || error "$LFS setstripe $file failed"
13075                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
13076                 idx=$(printf %04x $i)
13077                 BEFORE=$(get_osd_param $list *OST*$idx stats |
13078                         awk '$1 == "cache_access" {sum += $7}
13079                                 END { printf("%0.0f", sum) }')
13080
13081                 cancel_lru_locks osc
13082                 cat $file >/dev/null
13083
13084                 AFTER=$(get_osd_param $list *OST*$idx stats |
13085                         awk '$1 == "cache_access" {sum += $7}
13086                                 END { printf("%0.0f", sum) }')
13087
13088                 echo BEFORE:$BEFORE AFTER:$AFTER
13089                 if ! let "AFTER - BEFORE == 4"; then
13090                         rm -rf $dir
13091                         error "roc_hit is not safe to use"
13092                 fi
13093                 rm $file
13094         done
13095
13096         rm -rf $dir
13097 }
13098
13099 function roc_hit() {
13100         local list=$(comma_list $(osts_nodes))
13101         echo $(get_osd_param $list '' stats |
13102                 awk '$1 == "cache_hit" {sum += $7}
13103                         END { printf("%0.0f", sum) }')
13104 }
13105
13106 function set_cache() {
13107         local on=1
13108
13109         if [ "$2" == "off" ]; then
13110                 on=0;
13111         fi
13112         local list=$(comma_list $(osts_nodes))
13113         set_osd_param $list '' $1_cache_enable $on
13114
13115         cancel_lru_locks osc
13116 }
13117
13118 test_151() {
13119         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13120         remote_ost_nodsh && skip "remote OST with nodsh"
13121
13122         local CPAGES=3
13123         local list=$(comma_list $(osts_nodes))
13124
13125         # check whether obdfilter is cache capable at all
13126         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
13127                 skip "not cache-capable obdfilter"
13128         fi
13129
13130         # check cache is enabled on all obdfilters
13131         if get_osd_param $list '' read_cache_enable | grep 0; then
13132                 skip "oss cache is disabled"
13133         fi
13134
13135         set_osd_param $list '' writethrough_cache_enable 1
13136
13137         # check write cache is enabled on all obdfilters
13138         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
13139                 skip "oss write cache is NOT enabled"
13140         fi
13141
13142         roc_hit_init
13143
13144         #define OBD_FAIL_OBD_NO_LRU  0x609
13145         do_nodes $list $LCTL set_param fail_loc=0x609
13146
13147         # pages should be in the case right after write
13148         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
13149                 error "dd failed"
13150
13151         local BEFORE=$(roc_hit)
13152         cancel_lru_locks osc
13153         cat $DIR/$tfile >/dev/null
13154         local AFTER=$(roc_hit)
13155
13156         do_nodes $list $LCTL set_param fail_loc=0
13157
13158         if ! let "AFTER - BEFORE == CPAGES"; then
13159                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
13160         fi
13161
13162         cancel_lru_locks osc
13163         # invalidates OST cache
13164         do_nodes $list "echo 1 > /proc/sys/vm/drop_caches"
13165         set_osd_param $list '' read_cache_enable 0
13166         cat $DIR/$tfile >/dev/null
13167
13168         # now data shouldn't be found in the cache
13169         BEFORE=$(roc_hit)
13170         cancel_lru_locks osc
13171         cat $DIR/$tfile >/dev/null
13172         AFTER=$(roc_hit)
13173         if let "AFTER - BEFORE != 0"; then
13174                 error "IN CACHE: before: $BEFORE, after: $AFTER"
13175         fi
13176
13177         set_osd_param $list '' read_cache_enable 1
13178         rm -f $DIR/$tfile
13179 }
13180 run_test 151 "test cache on oss and controls ==============================="
13181
13182 test_152() {
13183         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13184
13185         local TF="$TMP/$tfile"
13186
13187         # simulate ENOMEM during write
13188 #define OBD_FAIL_OST_NOMEM      0x226
13189         lctl set_param fail_loc=0x80000226
13190         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
13191         cp $TF $DIR/$tfile
13192         sync || error "sync failed"
13193         lctl set_param fail_loc=0
13194
13195         # discard client's cache
13196         cancel_lru_locks osc
13197
13198         # simulate ENOMEM during read
13199         lctl set_param fail_loc=0x80000226
13200         cmp $TF $DIR/$tfile || error "cmp failed"
13201         lctl set_param fail_loc=0
13202
13203         rm -f $TF
13204 }
13205 run_test 152 "test read/write with enomem ============================"
13206
13207 test_153() {
13208         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
13209 }
13210 run_test 153 "test if fdatasync does not crash ======================="
13211
13212 dot_lustre_fid_permission_check() {
13213         local fid=$1
13214         local ffid=$MOUNT/.lustre/fid/$fid
13215         local test_dir=$2
13216
13217         echo "stat fid $fid"
13218         stat $ffid > /dev/null || error "stat $ffid failed."
13219         echo "touch fid $fid"
13220         touch $ffid || error "touch $ffid failed."
13221         echo "write to fid $fid"
13222         cat /etc/hosts > $ffid || error "write $ffid failed."
13223         echo "read fid $fid"
13224         diff /etc/hosts $ffid || error "read $ffid failed."
13225         echo "append write to fid $fid"
13226         cat /etc/hosts >> $ffid || error "append write $ffid failed."
13227         echo "rename fid $fid"
13228         mv $ffid $test_dir/$tfile.1 &&
13229                 error "rename $ffid to $tfile.1 should fail."
13230         touch $test_dir/$tfile.1
13231         mv $test_dir/$tfile.1 $ffid &&
13232                 error "rename $tfile.1 to $ffid should fail."
13233         rm -f $test_dir/$tfile.1
13234         echo "truncate fid $fid"
13235         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
13236         echo "link fid $fid"
13237         ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
13238         if [[ $($LCTL get_param -n mdc.*-mdc-*.connect_flags) =~ acl ]]; then
13239                 echo "setfacl fid $fid"
13240                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
13241                 echo "getfacl fid $fid"
13242                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
13243         fi
13244         echo "unlink fid $fid"
13245         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
13246         echo "mknod fid $fid"
13247         mknod $ffid c 1 3 && error "mknod $ffid should fail."
13248
13249         fid=[0xf00000400:0x1:0x0]
13250         ffid=$MOUNT/.lustre/fid/$fid
13251
13252         echo "stat non-exist fid $fid"
13253         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
13254         echo "write to non-exist fid $fid"
13255         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
13256         echo "link new fid $fid"
13257         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
13258
13259         mkdir -p $test_dir/$tdir
13260         touch $test_dir/$tdir/$tfile
13261         fid=$($LFS path2fid $test_dir/$tdir)
13262         rc=$?
13263         [ $rc -ne 0 ] &&
13264                 error "error: could not get fid for $test_dir/$dir/$tfile."
13265
13266         ffid=$MOUNT/.lustre/fid/$fid
13267
13268         echo "ls $fid"
13269         ls $ffid > /dev/null || error "ls $ffid failed."
13270         echo "touch $fid/$tfile.1"
13271         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
13272
13273         echo "touch $MOUNT/.lustre/fid/$tfile"
13274         touch $MOUNT/.lustre/fid/$tfile && \
13275                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
13276
13277         echo "setxattr to $MOUNT/.lustre/fid"
13278         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
13279
13280         echo "listxattr for $MOUNT/.lustre/fid"
13281         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
13282
13283         echo "delxattr from $MOUNT/.lustre/fid"
13284         setfattr -x trusted.name1 $MOUNT/.lustre/fid
13285
13286         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
13287         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
13288                 error "touch invalid fid should fail."
13289
13290         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
13291         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
13292                 error "touch non-normal fid should fail."
13293
13294         echo "rename $tdir to $MOUNT/.lustre/fid"
13295         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
13296                 error "rename to $MOUNT/.lustre/fid should fail."
13297
13298         if [ $MDS1_VERSION -ge $(version_code 2.3.51) ]
13299         then            # LU-3547
13300                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
13301                 local new_obf_mode=777
13302
13303                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
13304                 chmod $new_obf_mode $DIR/.lustre/fid ||
13305                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
13306
13307                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
13308                 [ $obf_mode -eq $new_obf_mode ] ||
13309                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
13310
13311                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
13312                 chmod $old_obf_mode $DIR/.lustre/fid ||
13313                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
13314         fi
13315
13316         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
13317         fid=$($LFS path2fid $test_dir/$tfile-2)
13318
13319         if [ $MDS1_VERSION -ge $(version_code 2.6.50) ]
13320         then # LU-5424
13321                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
13322                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
13323                         error "create lov data thru .lustre failed"
13324         fi
13325         echo "cp /etc/passwd $test_dir/$tfile-2"
13326         cp /etc/passwd $test_dir/$tfile-2 ||
13327                 error "copy to $test_dir/$tfile-2 failed."
13328         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
13329         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
13330                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
13331
13332         rm -rf $test_dir/tfile.lnk
13333         rm -rf $test_dir/$tfile-2
13334 }
13335
13336 test_154A() {
13337         [[ $MDS1_VERSION -lt $(version_code 2.4.1) ]] &&
13338                 skip "Need MDS version at least 2.4.1"
13339
13340         local tf=$DIR/$tfile
13341         touch $tf
13342
13343         local fid=$($LFS path2fid $tf)
13344         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
13345
13346         # check that we get the same pathname back
13347         local found=$($LFS fid2path $MOUNT "$fid")
13348         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
13349         [ "$found" == "$tf" ] ||
13350                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
13351 }
13352 run_test 154A "lfs path2fid and fid2path basic checks"
13353
13354 test_154B() {
13355         [[ $MDS1_VERSION -lt $(version_code 2.4.1) ]] &&
13356                 skip "Need MDS version at least 2.4.1"
13357
13358         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
13359         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
13360         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
13361         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
13362
13363         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
13364         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
13365
13366         # check that we get the same pathname
13367         echo "PFID: $PFID, name: $name"
13368         local FOUND=$($LFS fid2path $MOUNT "$PFID")
13369         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
13370         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
13371                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
13372
13373         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
13374 }
13375 run_test 154B "verify the ll_decode_linkea tool"
13376
13377 test_154a() {
13378         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13379         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13380         [[ $MDS1_VERSION -ge $(version_code 2.2.51) ]] ||
13381                 skip "Need MDS version at least 2.2.51"
13382         [ -z "$(which setfacl)" ] && skip_env "must have setfacl tool"
13383
13384         cp /etc/hosts $DIR/$tfile
13385
13386         fid=$($LFS path2fid $DIR/$tfile)
13387         rc=$?
13388         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
13389
13390         dot_lustre_fid_permission_check "$fid" $DIR ||
13391                 error "dot lustre permission check $fid failed"
13392
13393         ls -a $MOUNT | grep "\.lustre" && error ".lustre should not be listed"
13394
13395         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
13396
13397         touch $MOUNT/.lustre/file &&
13398                 error "creation is not allowed under .lustre"
13399
13400         mkdir $MOUNT/.lustre/dir &&
13401                 error "mkdir is not allowed under .lustre"
13402
13403         rm -rf $DIR/$tfile
13404 }
13405 run_test 154a "Open-by-FID"
13406
13407 test_154b() {
13408         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13409         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13410         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
13411         [[ $MDS1_VERSION -ge $(version_code 2.2.51) ]] ||
13412                 skip "Need MDS version at least 2.2.51"
13413
13414         local remote_dir=$DIR/$tdir/remote_dir
13415         local MDTIDX=1
13416         local rc=0
13417
13418         mkdir -p $DIR/$tdir
13419         $LFS mkdir -i $MDTIDX $remote_dir ||
13420                 error "create remote directory failed"
13421
13422         cp /etc/hosts $remote_dir/$tfile
13423
13424         fid=$($LFS path2fid $remote_dir/$tfile)
13425         rc=$?
13426         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
13427
13428         dot_lustre_fid_permission_check "$fid" $remote_dir ||
13429                 error "dot lustre permission check $fid failed"
13430         rm -rf $DIR/$tdir
13431 }
13432 run_test 154b "Open-by-FID for remote directory"
13433
13434 test_154c() {
13435         [[ $MDS1_VERSION -lt $(version_code 2.4.1) ]] &&
13436                 skip "Need MDS version at least 2.4.1"
13437
13438         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
13439         local FID1=$($LFS path2fid $DIR/$tfile.1)
13440         local FID2=$($LFS path2fid $DIR/$tfile.2)
13441         local FID3=$($LFS path2fid $DIR/$tfile.3)
13442
13443         local N=1
13444         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
13445                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
13446                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
13447                 local want=FID$N
13448                 [ "$FID" = "${!want}" ] ||
13449                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
13450                 N=$((N + 1))
13451         done
13452
13453         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
13454         do
13455                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
13456                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
13457                 N=$((N + 1))
13458         done
13459 }
13460 run_test 154c "lfs path2fid and fid2path multiple arguments"
13461
13462 test_154d() {
13463         remote_mds_nodsh && skip "remote MDS with nodsh"
13464         [[ $MDS1_VERSION -lt $(version_code 2.5.53) ]] &&
13465                 skip "Need MDS version at least 2.5.53"
13466
13467         if remote_mds; then
13468                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
13469         else
13470                 nid="0@lo"
13471         fi
13472         local proc_ofile="mdt.*.exports.'$nid'.open_files"
13473         local fd
13474         local cmd
13475
13476         rm -f $DIR/$tfile
13477         touch $DIR/$tfile
13478
13479         local fid=$($LFS path2fid $DIR/$tfile)
13480         # Open the file
13481         fd=$(free_fd)
13482         cmd="exec $fd<$DIR/$tfile"
13483         eval $cmd
13484         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
13485         echo "$fid_list" | grep "$fid"
13486         rc=$?
13487
13488         cmd="exec $fd>/dev/null"
13489         eval $cmd
13490         if [ $rc -ne 0 ]; then
13491                 error "FID $fid not found in open files list $fid_list"
13492         fi
13493 }
13494 run_test 154d "Verify open file fid"
13495
13496 test_154e()
13497 {
13498         [[ $MDS1_VERSION -lt $(version_code 2.6.50) ]] &&
13499                 skip "Need MDS version at least 2.6.50"
13500
13501         if ls -a $MOUNT | grep -q '^\.lustre$'; then
13502                 error ".lustre returned by readdir"
13503         fi
13504 }
13505 run_test 154e ".lustre is not returned by readdir"
13506
13507 test_154f() {
13508         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13509
13510         # create parent directory on a single MDT to avoid cross-MDT hardlinks
13511         test_mkdir -p -c1 $DIR/$tdir/d
13512         # test dirs inherit from its stripe
13513         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
13514         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
13515         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
13516         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
13517         touch $DIR/f
13518
13519         # get fid of parents
13520         local FID0=$($LFS path2fid $DIR/$tdir/d)
13521         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
13522         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
13523         local FID3=$($LFS path2fid $DIR)
13524
13525         # check that path2fid --parents returns expected <parent_fid>/name
13526         # 1) test for a directory (single parent)
13527         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
13528         [ "$parent" == "$FID0/foo1" ] ||
13529                 error "expected parent: $FID0/foo1, got: $parent"
13530
13531         # 2) test for a file with nlink > 1 (multiple parents)
13532         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
13533         echo "$parent" | grep -F "$FID1/$tfile" ||
13534                 error "$FID1/$tfile not returned in parent list"
13535         echo "$parent" | grep -F "$FID2/link" ||
13536                 error "$FID2/link not returned in parent list"
13537
13538         # 3) get parent by fid
13539         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
13540         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
13541         echo "$parent" | grep -F "$FID1/$tfile" ||
13542                 error "$FID1/$tfile not returned in parent list (by fid)"
13543         echo "$parent" | grep -F "$FID2/link" ||
13544                 error "$FID2/link not returned in parent list (by fid)"
13545
13546         # 4) test for entry in root directory
13547         parent=$($LFS path2fid --parents $DIR/f)
13548         echo "$parent" | grep -F "$FID3/f" ||
13549                 error "$FID3/f not returned in parent list"
13550
13551         # 5) test it on root directory
13552         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
13553                 error "$MOUNT should not have parents"
13554
13555         # enable xattr caching and check that linkea is correctly updated
13556         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
13557         save_lustre_params client "llite.*.xattr_cache" > $save
13558         lctl set_param llite.*.xattr_cache 1
13559
13560         # 6.1) linkea update on rename
13561         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
13562
13563         # get parents by fid
13564         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
13565         # foo1 should no longer be returned in parent list
13566         echo "$parent" | grep -F "$FID1" &&
13567                 error "$FID1 should no longer be in parent list"
13568         # the new path should appear
13569         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
13570                 error "$FID2/$tfile.moved is not in parent list"
13571
13572         # 6.2) linkea update on unlink
13573         rm -f $DIR/$tdir/d/foo2/link
13574         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
13575         # foo2/link should no longer be returned in parent list
13576         echo "$parent" | grep -F "$FID2/link" &&
13577                 error "$FID2/link should no longer be in parent list"
13578         true
13579
13580         rm -f $DIR/f
13581         restore_lustre_params < $save
13582         rm -f $save
13583 }
13584 run_test 154f "get parent fids by reading link ea"
13585
13586 test_154g()
13587 {
13588         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
13589         [[ $MDS1_VERSION -ge $(version_code 2.6.92) &&
13590            $CLIENT_VERSION -gt $(version_code 2.6.99) ]] ||
13591                 skip "Need MDS version at least 2.6.92"
13592
13593         mkdir -p $DIR/$tdir
13594         llapi_fid_test -d $DIR/$tdir
13595 }
13596 run_test 154g "various llapi FID tests"
13597
13598 test_155_small_load() {
13599     local temp=$TMP/$tfile
13600     local file=$DIR/$tfile
13601
13602     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
13603         error "dd of=$temp bs=6096 count=1 failed"
13604     cp $temp $file
13605     cancel_lru_locks $OSC
13606     cmp $temp $file || error "$temp $file differ"
13607
13608     $TRUNCATE $temp 6000
13609     $TRUNCATE $file 6000
13610     cmp $temp $file || error "$temp $file differ (truncate1)"
13611
13612     echo "12345" >>$temp
13613     echo "12345" >>$file
13614     cmp $temp $file || error "$temp $file differ (append1)"
13615
13616     echo "12345" >>$temp
13617     echo "12345" >>$file
13618     cmp $temp $file || error "$temp $file differ (append2)"
13619
13620     rm -f $temp $file
13621     true
13622 }
13623
13624 test_155_big_load() {
13625         remote_ost_nodsh && skip "remote OST with nodsh"
13626
13627         local temp=$TMP/$tfile
13628         local file=$DIR/$tfile
13629
13630         free_min_max
13631         local cache_size=$(do_facet ost$((MAXI+1)) \
13632                 "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
13633         local large_file_size=$((cache_size * 2))
13634
13635         echo "OSS cache size: $cache_size KB"
13636         echo "Large file size: $large_file_size KB"
13637
13638         [ $MAXV -le $large_file_size ] &&
13639                 skip_env "max available OST size needs > $large_file_size KB"
13640
13641         $LFS setstripe $file -c 1 -i $MAXI || error "$LFS setstripe $file failed"
13642
13643         dd if=/dev/urandom of=$temp bs=$large_file_size count=1k ||
13644                 error "dd of=$temp bs=$large_file_size count=1k failed"
13645         cp $temp $file
13646         ls -lh $temp $file
13647         cancel_lru_locks osc
13648         cmp $temp $file || error "$temp $file differ"
13649
13650         rm -f $temp $file
13651         true
13652 }
13653
13654 save_writethrough() {
13655         local facets=$(get_facets OST)
13656
13657         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" > $1
13658 }
13659
13660 test_155a() {
13661         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13662
13663         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13664
13665         save_writethrough $p
13666
13667         set_cache read on
13668         set_cache writethrough on
13669         test_155_small_load
13670         restore_lustre_params < $p
13671         rm -f $p
13672 }
13673 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
13674
13675 test_155b() {
13676         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13677
13678         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13679
13680         save_writethrough $p
13681
13682         set_cache read on
13683         set_cache writethrough off
13684         test_155_small_load
13685         restore_lustre_params < $p
13686         rm -f $p
13687 }
13688 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
13689
13690 test_155c() {
13691         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13692
13693         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13694
13695         save_writethrough $p
13696
13697         set_cache read off
13698         set_cache writethrough on
13699         test_155_small_load
13700         restore_lustre_params < $p
13701         rm -f $p
13702 }
13703 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
13704
13705 test_155d() {
13706         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13707
13708         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13709
13710         save_writethrough $p
13711
13712         set_cache read off
13713         set_cache writethrough off
13714         test_155_small_load
13715         restore_lustre_params < $p
13716         rm -f $p
13717 }
13718 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
13719
13720 test_155e() {
13721         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13722
13723         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13724
13725         save_writethrough $p
13726
13727         set_cache read on
13728         set_cache writethrough on
13729         test_155_big_load
13730         restore_lustre_params < $p
13731         rm -f $p
13732 }
13733 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
13734
13735 test_155f() {
13736         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13737
13738         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13739
13740         save_writethrough $p
13741
13742         set_cache read on
13743         set_cache writethrough off
13744         test_155_big_load
13745         restore_lustre_params < $p
13746         rm -f $p
13747 }
13748 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
13749
13750 test_155g() {
13751         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13752
13753         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13754
13755         save_writethrough $p
13756
13757         set_cache read off
13758         set_cache writethrough on
13759         test_155_big_load
13760         restore_lustre_params < $p
13761         rm -f $p
13762 }
13763 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
13764
13765 test_155h() {
13766         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13767
13768         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13769
13770         save_writethrough $p
13771
13772         set_cache read off
13773         set_cache writethrough off
13774         test_155_big_load
13775         restore_lustre_params < $p
13776         rm -f $p
13777 }
13778 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
13779
13780 test_156() {
13781         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13782         remote_ost_nodsh && skip "remote OST with nodsh"
13783         [ $OST1_VERSION -lt $(version_code 2.6.93) ] &&
13784                 skip "stats not implemented on old servers"
13785         [ "$ost1_FSTYPE" = "zfs" ] &&
13786                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS"
13787
13788         local CPAGES=3
13789         local BEFORE
13790         local AFTER
13791         local file="$DIR/$tfile"
13792         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13793
13794         save_writethrough $p
13795         roc_hit_init
13796
13797         log "Turn on read and write cache"
13798         set_cache read on
13799         set_cache writethrough on
13800
13801         log "Write data and read it back."
13802         log "Read should be satisfied from the cache."
13803         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
13804         BEFORE=$(roc_hit)
13805         cancel_lru_locks osc
13806         cat $file >/dev/null
13807         AFTER=$(roc_hit)
13808         if ! let "AFTER - BEFORE == CPAGES"; then
13809                 error "NOT IN CACHE (2): before: $BEFORE, after: $AFTER"
13810         else
13811                 log "cache hits: before: $BEFORE, after: $AFTER"
13812         fi
13813
13814         log "Read again; it should be satisfied from the cache."
13815         BEFORE=$AFTER
13816         cancel_lru_locks osc
13817         cat $file >/dev/null
13818         AFTER=$(roc_hit)
13819         if ! let "AFTER - BEFORE == CPAGES"; then
13820                 error "NOT IN CACHE (3): before: $BEFORE, after: $AFTER"
13821         else
13822                 log "cache hits:: before: $BEFORE, after: $AFTER"
13823         fi
13824
13825         log "Turn off the read cache and turn on the write cache"
13826         set_cache read off
13827         set_cache writethrough on
13828
13829         log "Read again; it should be satisfied from the cache."
13830         BEFORE=$(roc_hit)
13831         cancel_lru_locks osc
13832         cat $file >/dev/null
13833         AFTER=$(roc_hit)
13834         if ! let "AFTER - BEFORE == CPAGES"; then
13835                 error "NOT IN CACHE (4): before: $BEFORE, after: $AFTER"
13836         else
13837                 log "cache hits:: before: $BEFORE, after: $AFTER"
13838         fi
13839
13840         if [ $OST1_VERSION -lt $(version_code 2.12.55) ]; then
13841                 # > 2.12.56 uses pagecache if cached
13842                 log "Read again; it should not be satisfied from the cache."
13843                 BEFORE=$AFTER
13844                 cancel_lru_locks osc
13845                 cat $file >/dev/null
13846                 AFTER=$(roc_hit)
13847                 if ! let "AFTER - BEFORE == 0"; then
13848                         error "IN CACHE (5): before: $BEFORE, after: $AFTER"
13849                 else
13850                         log "cache hits:: before: $BEFORE, after: $AFTER"
13851                 fi
13852         fi
13853
13854         log "Write data and read it back."
13855         log "Read should be satisfied from the cache."
13856         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
13857         BEFORE=$(roc_hit)
13858         cancel_lru_locks osc
13859         cat $file >/dev/null
13860         AFTER=$(roc_hit)
13861         if ! let "AFTER - BEFORE == CPAGES"; then
13862                 error "NOT IN CACHE (6): before: $BEFORE, after: $AFTER"
13863         else
13864                 log "cache hits:: before: $BEFORE, after: $AFTER"
13865         fi
13866
13867         if [ $OST1_VERSION -lt $(version_code 2.12.55) ]; then
13868                 # > 2.12.56 uses pagecache if cached
13869                 log "Read again; it should not be satisfied from the cache."
13870                 BEFORE=$AFTER
13871                 cancel_lru_locks osc
13872                 cat $file >/dev/null
13873                 AFTER=$(roc_hit)
13874                 if ! let "AFTER - BEFORE == 0"; then
13875                         error "IN CACHE (7): before: $BEFORE, after: $AFTER"
13876                 else
13877                         log "cache hits:: before: $BEFORE, after: $AFTER"
13878                 fi
13879         fi
13880
13881         log "Turn off read and write cache"
13882         set_cache read off
13883         set_cache writethrough off
13884
13885         log "Write data and read it back"
13886         log "It should not be satisfied from the cache."
13887         rm -f $file
13888         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
13889         cancel_lru_locks osc
13890         BEFORE=$(roc_hit)
13891         cat $file >/dev/null
13892         AFTER=$(roc_hit)
13893         if ! let "AFTER - BEFORE == 0"; then
13894                 error_ignore bz20762 "IN CACHE (8):before:$BEFORE,after:$AFTER"
13895         else
13896                 log "cache hits:: before: $BEFORE, after: $AFTER"
13897         fi
13898
13899         log "Turn on the read cache and turn off the write cache"
13900         set_cache read on
13901         set_cache writethrough off
13902
13903         log "Write data and read it back"
13904         log "It should not be satisfied from the cache."
13905         rm -f $file
13906         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
13907         BEFORE=$(roc_hit)
13908         cancel_lru_locks osc
13909         cat $file >/dev/null
13910         AFTER=$(roc_hit)
13911         if ! let "AFTER - BEFORE == 0"; then
13912                 error_ignore bz20762 "IN CACHE (9):before:$BEFORE,after:$AFTER"
13913         else
13914                 log "cache hits:: before: $BEFORE, after: $AFTER"
13915         fi
13916
13917         log "Read again; it should be satisfied from the cache."
13918         BEFORE=$(roc_hit)
13919         cancel_lru_locks osc
13920         cat $file >/dev/null
13921         AFTER=$(roc_hit)
13922         if ! let "AFTER - BEFORE == CPAGES"; then
13923                 error "NOT IN CACHE (1): before: $BEFORE, after: $AFTER"
13924         else
13925                 log "cache hits:: before: $BEFORE, after: $AFTER"
13926         fi
13927
13928         restore_lustre_params < $p
13929         rm -f $p $file
13930 }
13931 run_test 156 "Verification of tunables"
13932
13933 test_160a() {
13934         [ $PARALLEL == "yes" ] && skip "skip parallel run"
13935         remote_mds_nodsh && skip "remote MDS with nodsh"
13936         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] ||
13937                 skip "Need MDS version at least 2.2.0"
13938
13939         changelog_register || error "changelog_register failed"
13940         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
13941         changelog_users $SINGLEMDS | grep -q $cl_user ||
13942                 error "User $cl_user not found in changelog_users"
13943
13944         # change something
13945         test_mkdir -p $DIR/$tdir/pics/2008/zachy
13946         changelog_clear 0 || error "changelog_clear failed"
13947         touch $DIR/$tdir/pics/2008/zachy/$tfile                 # open 1
13948         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg       # open 2
13949         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
13950         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
13951         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
13952         rm $DIR/$tdir/pics/desktop.jpg
13953
13954         changelog_dump | tail -10
13955
13956         echo "verifying changelog mask"
13957         changelog_chmask "-MKDIR"
13958         changelog_chmask "-CLOSE"
13959
13960         test_mkdir -p $DIR/$tdir/pics/zach/sofia                # not logged
13961         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # not logged
13962
13963         changelog_chmask "+MKDIR"
13964         changelog_chmask "+CLOSE"
13965
13966         test_mkdir -p $DIR/$tdir/pics/2008/sofia                # mkdir 1
13967         echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # open 3
13968
13969         changelog_dump | tail -10
13970         MKDIRS=$(changelog_dump | grep -c "MKDIR")
13971         CLOSES=$(changelog_dump | grep -c "CLOSE")
13972         [ $MKDIRS -eq 1 ] || error "MKDIR changelog mask count $MKDIRS != 1"
13973         [ $CLOSES -eq 3 ] || error "CLOSE changelog mask count $CLOSES != 3"
13974
13975         # verify contents
13976         echo "verifying target fid"
13977         local fidc=$(changelog_extract_field "CREAT" "$tfile" "t=")
13978         local fidf=$($LFS path2fid $DIR/$tdir/pics/zach/$tfile)
13979         [ "$fidc" == "$fidf" ] ||
13980                 error "changelog '$tfile' fid $fidc != file fid $fidf"
13981         echo "verifying parent fid"
13982         # The FID returned from the Changelog may be the directory shard on
13983         # a different MDT, and not the FID returned by path2fid on the parent.
13984         # Instead of comparing FIDs, verify that fid2path(fidp) is correct,
13985         # since this is what will matter when recreating this file in the tree.
13986         local fidp=$(changelog_extract_field "CREAT" "$tfile" "p=")
13987         local pathp=$($LFS fid2path $MOUNT "$fidp")
13988         [ "${pathp%/}" == "$DIR/$tdir/pics/zach" ] ||
13989                 error "changelog fid2path($fidc) $pathp != $DIR/$tdir/pics/zach"
13990
13991         echo "getting records for $cl_user"
13992         changelog_users $SINGLEMDS
13993         local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user)
13994         local nclr=3
13995         __changelog_clear $SINGLEMDS $cl_user +$nclr ||
13996                 error "changelog_clear failed"
13997         local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user)
13998         echo "verifying user clear: $user_rec1 + $nclr == $user_rec2"
13999         [ $user_rec2 == $((user_rec1 + nclr)) ] ||
14000                 error "user index expect $user_rec1 + $nclr != $user_rec2"
14001
14002         local min0_rec=$(changelog_users $SINGLEMDS |
14003                 awk 'min == "" || $2 < min { min = $2 }; END { print min }')
14004         local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
14005                           awk '{ print $1; exit; }')
14006
14007         changelog_dump | tail -n 5
14008         echo "verifying user min purge: $min0_rec + 1 == $first_rec"
14009         [ $first_rec == $((min0_rec + 1)) ] ||
14010                 error "first index should be $min0_rec + 1 not $first_rec"
14011
14012         # LU-3446 changelog index reset on MDT restart
14013         local cur_rec1=$(changelog_users $SINGLEMDS |
14014                          awk '/^current.index:/ { print $NF }')
14015         changelog_clear 0 ||
14016                 error "clear all changelog records for $cl_user failed"
14017         stop $SINGLEMDS || error "Fail to stop $SINGLEMDS"
14018         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
14019                 error "Fail to start $SINGLEMDS"
14020         local cur_rec2=$(changelog_users $SINGLEMDS |
14021                          awk '/^current.index:/ { print $NF }')
14022         echo "verifying index survives MDT restart: $cur_rec1 == $cur_rec2"
14023         [ $cur_rec1 == $cur_rec2 ] ||
14024                 error "current index should be $cur_rec1 not $cur_rec2"
14025
14026         echo "verifying users from this test are deregistered"
14027         changelog_deregister || error "changelog_deregister failed"
14028         changelog_users $SINGLEMDS | grep -q $cl_user &&
14029                 error "User '$cl_user' still in changelog_users"
14030
14031         # lctl get_param -n mdd.*.changelog_users
14032         # current index: 144
14033         # ID    index (idle seconds)
14034         # cl3   144 (2)
14035         if ! changelog_users $SINGLEMDS | grep "^cl"; then
14036                 # this is the normal case where all users were deregistered
14037                 # make sure no new records are added when no users are present
14038                 local last_rec1=$(changelog_users $SINGLEMDS |
14039                                   awk '/^current.index:/ { print $NF }')
14040                 touch $DIR/$tdir/chloe
14041                 local last_rec2=$(changelog_users $SINGLEMDS |
14042                                   awk '/^current.index:/ { print $NF }')
14043                 echo "verify changelogs are off: $last_rec1 == $last_rec2"
14044                 [ $last_rec1 == $last_rec2 ] || error "changelogs not off"
14045         else
14046                 # any changelog users must be leftovers from a previous test
14047                 changelog_users $SINGLEMDS
14048                 echo "other changelog users; can't verify off"
14049         fi
14050 }
14051 run_test 160a "changelog sanity"
14052
14053 test_160b() { # LU-3587
14054         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14055         remote_mds_nodsh && skip "remote MDS with nodsh"
14056         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] ||
14057                 skip "Need MDS version at least 2.2.0"
14058
14059         changelog_register || error "changelog_register failed"
14060         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
14061         changelog_users $SINGLEMDS | grep -q $cl_user ||
14062                 error "User '$cl_user' not found in changelog_users"
14063
14064         local longname1=$(str_repeat a 255)
14065         local longname2=$(str_repeat b 255)
14066
14067         cd $DIR
14068         echo "creating very long named file"
14069         touch $longname1 || error "create of '$longname1' failed"
14070         echo "renaming very long named file"
14071         mv $longname1 $longname2
14072
14073         changelog_dump | grep RENME | tail -n 5
14074         rm -f $longname2
14075 }
14076 run_test 160b "Verify that very long rename doesn't crash in changelog"
14077
14078 test_160c() {
14079         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14080         remote_mds_nodsh && skip "remote MDS with nodsh"
14081
14082         [[ $MDS1_VERSION -gt $(version_code 2.5.57) ]] ||
14083                 [[ $MDS1_VERSION -gt $(version_code 2.5.1) &&
14084                    $MDS1_VERSION -lt $(version_code 2.5.50) ]] ||
14085                 skip "Need MDS version at least 2.5.58 or 2.5.2+"
14086
14087         local rc=0
14088
14089         # Registration step
14090         changelog_register || error "changelog_register failed"
14091
14092         rm -rf $DIR/$tdir
14093         mkdir -p $DIR/$tdir
14094         $MCREATE $DIR/$tdir/foo_160c
14095         changelog_chmask "-TRUNC"
14096         $TRUNCATE $DIR/$tdir/foo_160c 200
14097         changelog_chmask "+TRUNC"
14098         $TRUNCATE $DIR/$tdir/foo_160c 199
14099         changelog_dump | tail -n 5
14100         local truncs=$(changelog_dump | tail -n 5 | grep -c TRUNC)
14101         [ $truncs -eq 1 ] || error "TRUNC changelog mask count $truncs != 1"
14102 }
14103 run_test 160c "verify that changelog log catch the truncate event"
14104
14105 test_160d() {
14106         remote_mds_nodsh && skip "remote MDS with nodsh"
14107         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14108         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14109         [[ $MDS1_VERSION -ge $(version_code 2.7.60) ]] ||
14110                 skip "Need MDS version at least 2.7.60"
14111
14112         # Registration step
14113         changelog_register || error "changelog_register failed"
14114
14115         mkdir -p $DIR/$tdir/migrate_dir
14116         changelog_clear 0 || error "changelog_clear failed"
14117
14118         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
14119         changelog_dump | tail -n 5
14120         local migrates=$(changelog_dump | grep -c "MIGRT")
14121         [ $migrates -eq 1 ] || error "MIGRATE changelog count $migrates != 1"
14122 }
14123 run_test 160d "verify that changelog log catch the migrate event"
14124
14125 test_160e() {
14126         remote_mds_nodsh && skip "remote MDS with nodsh"
14127
14128         # Create a user
14129         changelog_register || error "changelog_register failed"
14130
14131         # Delete a future user (expect fail)
14132         local MDT0=$(facet_svc $SINGLEMDS)
14133         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister "cl77"
14134         local rc=$?
14135
14136         if [ $rc -eq 0 ]; then
14137                 error "Deleted non-existant user cl77"
14138         elif [ $rc -ne 2 ]; then
14139                 error "changelog_deregister failed with $rc, expect 2 (ENOENT)"
14140         fi
14141
14142         # Clear to a bad index (1 billion should be safe)
14143         $LFS changelog_clear $MDT0 "${CL_USERS[$SINGLEMDS]%% *}" 1000000000
14144         rc=$?
14145
14146         if [ $rc -eq 0 ]; then
14147                 error "Successfully cleared to invalid CL index"
14148         elif [ $rc -ne 22 ]; then
14149                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
14150         fi
14151 }
14152 run_test 160e "changelog negative testing (should return errors)"
14153
14154 test_160f() {
14155         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14156         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
14157                 skip "Need MDS version at least 2.10.56"
14158
14159         local mdts=$(comma_list $(mdts_nodes))
14160
14161         # Create a user
14162         changelog_register || error "first changelog_register failed"
14163         changelog_register || error "second changelog_register failed"
14164         local cl_users
14165         declare -A cl_user1
14166         declare -A cl_user2
14167         local user_rec1
14168         local user_rec2
14169         local i
14170
14171         # generate some changelog records to accumulate on each MDT
14172         # use fnv1a because created files should be evenly distributed
14173         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14174                 error "test_mkdir $tdir failed"
14175         log "$(date +%s): creating first files"
14176         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
14177                 error "create $DIR/$tdir/$tfile failed"
14178
14179         # check changelogs have been generated
14180         local start=$SECONDS
14181         local idle_time=$((MDSCOUNT * 5 + 5))
14182         local nbcl=$(changelog_dump | wc -l)
14183         [[ $nbcl -eq 0 ]] && error "no changelogs found"
14184
14185         for param in "changelog_max_idle_time=$idle_time" \
14186                      "changelog_gc=1" \
14187                      "changelog_min_gc_interval=2" \
14188                      "changelog_min_free_cat_entries=3"; do
14189                 local MDT0=$(facet_svc $SINGLEMDS)
14190                 local var="${param%=*}"
14191                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
14192
14193                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
14194                 do_nodes $mdts $LCTL set_param mdd.*.$param
14195         done
14196
14197         # force cl_user2 to be idle (1st part), but also cancel the
14198         # cl_user1 records so that it is not evicted later in the test.
14199         local sleep1=$((idle_time / 2))
14200         echo "$(date +%s): sleep1 $sleep1/${idle_time}s"
14201         sleep $sleep1
14202
14203         # simulate changelog catalog almost full
14204         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
14205         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
14206
14207         for i in $(seq $MDSCOUNT); do
14208                 cl_users=(${CL_USERS[mds$i]})
14209                 cl_user1[mds$i]="${cl_users[0]}"
14210                 cl_user2[mds$i]="${cl_users[1]}"
14211
14212                 [ -n "${cl_user1[mds$i]}" ] ||
14213                         error "mds$i: no user registered"
14214                 [ -n "${cl_user2[mds$i]}" ] ||
14215                         error "mds$i: only ${cl_user2[mds$i]} is registered"
14216
14217                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14218                 [ -n "$user_rec1" ] ||
14219                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14220                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
14221                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14222                 [ -n "$user_rec2" ] ||
14223                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14224                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
14225                      "$user_rec1 + 2 == $user_rec2"
14226                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
14227                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
14228                               "$user_rec1 + 2, but is $user_rec2"
14229                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
14230                 [ -n "$user_rec2" ] ||
14231                         error "mds$i: User ${cl_user2[mds$i]} not registered"
14232                 [ $user_rec1 == $user_rec2 ] ||
14233                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
14234                               "$user_rec1, but is $user_rec2"
14235         done
14236
14237         # force cl_user2 idle (2nd part) to just exceed changelog_max_idle_time
14238         local sleep2=$((idle_time - (SECONDS - start) + 1))
14239         echo "$(date +%s): sleep2 $sleep2/${idle_time}s"
14240         sleep $sleep2
14241
14242         # Generate one more changelog to trigger GC at fail_loc for cl_user2.
14243         # cl_user1 should be OK because it recently processed records.
14244         echo "$(date +%s): creating $((MDSCOUNT * 2)) files"
14245         createmany -m $DIR/$tdir/${tfile}b $((MDSCOUNT * 2)) ||
14246                 error "create $DIR/$tdir/${tfile}b failed"
14247
14248         # ensure gc thread is done
14249         for i in $(mdts_nodes); do
14250                 wait_update $i \
14251                         "ps -e -o comm= | grep chlg_gc_thread" "" 20 ||
14252                         error "$i: GC-thread not done"
14253         done
14254
14255         local first_rec
14256         for i in $(seq $MDSCOUNT); do
14257                 # check cl_user1 still registered
14258                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
14259                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14260                 # check cl_user2 unregistered
14261                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
14262                         error "mds$i: User ${cl_user2[mds$i]} still registered"
14263
14264                 # check changelogs are present and starting at $user_rec1 + 1
14265                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14266                 [ -n "$user_rec1" ] ||
14267                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14268                 first_rec=$($LFS changelog $(facet_svc mds$i) |
14269                             awk '{ print $1; exit; }')
14270
14271                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
14272                 [ $((user_rec1 + 1)) == $first_rec ] ||
14273                         error "mds$i: first index should be $user_rec1 + 1, " \
14274                               "but is $first_rec"
14275         done
14276 }
14277 run_test 160f "changelog garbage collect (timestamped users)"
14278
14279 test_160g() {
14280         remote_mds_nodsh && skip "remote MDS with nodsh"
14281         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
14282                 skip "Need MDS version at least 2.10.56"
14283
14284         local mdts=$(comma_list $(mdts_nodes))
14285
14286         #define OBD_FAIL_TIME_IN_CHLOG_USER     0x1314
14287         do_nodes $mdts $LCTL set_param fail_loc=0x1314
14288
14289         # Create a user
14290         changelog_register || error "first changelog_register failed"
14291         changelog_register || error "second changelog_register failed"
14292         local cl_users
14293         declare -A cl_user1
14294         declare -A cl_user2
14295         local user_rec1
14296         local user_rec2
14297         local i
14298
14299         # generate some changelog records to accumulate on each MDT
14300         # use fnv1a because created files should be evenly distributed
14301         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14302                 error "mkdir $tdir failed"
14303         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
14304                 error "create $DIR/$tdir/$tfile failed"
14305
14306         # check changelogs have been generated
14307         local nbcl=$(changelog_dump | wc -l)
14308         [[ $nbcl -eq 0 ]] && error "no changelogs found"
14309
14310         # reduce the max_idle_indexes value to make sure we exceed it
14311         max_ndx=$((nbcl / 2 - 1))
14312
14313         for param in "changelog_max_idle_indexes=$max_ndx" \
14314                      "changelog_gc=1" \
14315                      "changelog_min_gc_interval=2" \
14316                      "changelog_min_free_cat_entries=3"; do
14317                 local MDT0=$(facet_svc $SINGLEMDS)
14318                 local var="${param%=*}"
14319                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
14320
14321                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
14322                 do_nodes $mdts $LCTL set_param mdd.*.$param ||
14323                         error "unable to set mdd.*.$param"
14324         done
14325
14326         # simulate changelog catalog almost full
14327         #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
14328         do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
14329
14330         for i in $(seq $MDSCOUNT); do
14331                 cl_users=(${CL_USERS[mds$i]})
14332                 cl_user1[mds$i]="${cl_users[0]}"
14333                 cl_user2[mds$i]="${cl_users[1]}"
14334
14335                 [ -n "${cl_user1[mds$i]}" ] ||
14336                         error "mds$i: no user registered"
14337                 [ -n "${cl_user2[mds$i]}" ] ||
14338                         error "mds$i: only ${cl_user1[mds$i]} is registered"
14339
14340                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14341                 [ -n "$user_rec1" ] ||
14342                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14343                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
14344                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14345                 [ -n "$user_rec2" ] ||
14346                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14347                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
14348                      "$user_rec1 + 2 == $user_rec2"
14349                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
14350                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
14351                               "$user_rec1 + 2, but is $user_rec2"
14352                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
14353                 [ -n "$user_rec2" ] ||
14354                         error "mds$i: User ${cl_user2[mds$i]} not registered"
14355                 [ $user_rec1 == $user_rec2 ] ||
14356                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
14357                               "$user_rec1, but is $user_rec2"
14358         done
14359
14360         # ensure we are past the previous changelog_min_gc_interval set above
14361         sleep 2
14362
14363         # generate one more changelog to trigger fail_loc
14364         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
14365                 error "create $DIR/$tdir/${tfile}bis failed"
14366
14367         # ensure gc thread is done
14368         for i in $(mdts_nodes); do
14369                 wait_update $i \
14370                         "ps -e -o comm= | grep chlg_gc_thread" "" 20 ||
14371                         error "$i: GC-thread not done"
14372         done
14373
14374         local first_rec
14375         for i in $(seq $MDSCOUNT); do
14376                 # check cl_user1 still registered
14377                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
14378                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14379                 # check cl_user2 unregistered
14380                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
14381                         error "mds$i: User ${cl_user2[mds$i]} still registered"
14382
14383                 # check changelogs are present and starting at $user_rec1 + 1
14384                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14385                 [ -n "$user_rec1" ] ||
14386                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14387                 first_rec=$($LFS changelog $(facet_svc mds$i) |
14388                             awk '{ print $1; exit; }')
14389
14390                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
14391                 [ $((user_rec1 + 1)) == $first_rec ] ||
14392                         error "mds$i: first index should be $user_rec1 + 1, " \
14393                               "but is $first_rec"
14394         done
14395 }
14396 run_test 160g "changelog garbage collect (old users)"
14397
14398 test_160h() {
14399         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14400         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
14401                 skip "Need MDS version at least 2.10.56"
14402
14403         local mdts=$(comma_list $(mdts_nodes))
14404
14405         # Create a user
14406         changelog_register || error "first changelog_register failed"
14407         changelog_register || error "second changelog_register failed"
14408         local cl_users
14409         declare -A cl_user1
14410         declare -A cl_user2
14411         local user_rec1
14412         local user_rec2
14413         local i
14414
14415         # generate some changelog records to accumulate on each MDT
14416         # use fnv1a because created files should be evenly distributed
14417         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14418                 error "test_mkdir $tdir failed"
14419         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
14420                 error "create $DIR/$tdir/$tfile failed"
14421
14422         # check changelogs have been generated
14423         local nbcl=$(changelog_dump | wc -l)
14424         [[ $nbcl -eq 0 ]] && error "no changelogs found"
14425
14426         for param in "changelog_max_idle_time=10" \
14427                      "changelog_gc=1" \
14428                      "changelog_min_gc_interval=2"; do
14429                 local MDT0=$(facet_svc $SINGLEMDS)
14430                 local var="${param%=*}"
14431                 local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
14432
14433                 stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
14434                 do_nodes $mdts $LCTL set_param mdd.*.$param
14435         done
14436
14437         # force cl_user2 to be idle (1st part)
14438         sleep 9
14439
14440         for i in $(seq $MDSCOUNT); do
14441                 cl_users=(${CL_USERS[mds$i]})
14442                 cl_user1[mds$i]="${cl_users[0]}"
14443                 cl_user2[mds$i]="${cl_users[1]}"
14444
14445                 [ -n "${cl_user1[mds$i]}" ] ||
14446                         error "mds$i: no user registered"
14447                 [ -n "${cl_user2[mds$i]}" ] ||
14448                         error "mds$i: only ${cl_user2[mds$i]} is registered"
14449
14450                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14451                 [ -n "$user_rec1" ] ||
14452                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14453                 __changelog_clear mds$i ${cl_user1[mds$i]} +2
14454                 user_rec2=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14455                 [ -n "$user_rec2" ] ||
14456                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14457                 echo "mds$i: verifying user ${cl_user1[mds$i]} clear: " \
14458                      "$user_rec1 + 2 == $user_rec2"
14459                 [ $((user_rec1 + 2)) == $user_rec2 ] ||
14460                         error "mds$i: user ${cl_user1[mds$i]} index expected " \
14461                               "$user_rec1 + 2, but is $user_rec2"
14462                 user_rec2=$(changelog_user_rec mds$i ${cl_user2[mds$i]})
14463                 [ -n "$user_rec2" ] ||
14464                         error "mds$i: User ${cl_user2[mds$i]} not registered"
14465                 [ $user_rec1 == $user_rec2 ] ||
14466                         error "mds$i: user ${cl_user2[mds$i]} index expected " \
14467                               "$user_rec1, but is $user_rec2"
14468         done
14469
14470         # force cl_user2 to be idle (2nd part) and to reach
14471         # changelog_max_idle_time
14472         sleep 2
14473
14474         # force each GC-thread start and block then
14475         # one per MDT/MDD, set fail_val accordingly
14476         #define OBD_FAIL_FORCE_GC_THREAD 0x1316
14477         do_nodes $mdts $LCTL set_param fail_loc=0x1316
14478
14479         # generate more changelogs to trigger fail_loc
14480         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
14481                 error "create $DIR/$tdir/${tfile}bis failed"
14482
14483         # stop MDT to stop GC-thread, should be done in back-ground as it will
14484         # block waiting for the thread to be released and exit
14485         declare -A stop_pids
14486         for i in $(seq $MDSCOUNT); do
14487                 stop mds$i &
14488                 stop_pids[mds$i]=$!
14489         done
14490
14491         for i in $(mdts_nodes); do
14492                 local facet
14493                 local nb=0
14494                 local facets=$(facets_up_on_host $i)
14495
14496                 for facet in ${facets//,/ }; do
14497                         if [[ $facet == mds* ]]; then
14498                                 nb=$((nb + 1))
14499                         fi
14500                 done
14501                 # ensure each MDS's gc threads are still present and all in "R"
14502                 # state (OBD_FAIL_FORCE_GC_THREAD effect!)
14503                 [[ $(do_node $i pgrep chlg_gc_thread | wc -l) -eq $nb ]] ||
14504                         error "$i: expected $nb GC-thread"
14505                 wait_update $i \
14506                         "ps -C chlg_gc_thread -o state --no-headers | uniq" \
14507                         "R" 20 ||
14508                         error "$i: GC-thread not found in R-state"
14509                 # check umounts of each MDT on MDS have reached kthread_stop()
14510                 [[ $(do_node $i pgrep umount | wc -l) -eq $nb ]] ||
14511                         error "$i: expected $nb umount"
14512                 wait_update $i \
14513                         "ps -C umount -o state --no-headers | uniq" "D" 20 ||
14514                         error "$i: umount not found in D-state"
14515         done
14516
14517         # release all GC-threads
14518         do_nodes $mdts $LCTL set_param fail_loc=0
14519
14520         # wait for MDT stop to complete
14521         for i in $(seq $MDSCOUNT); do
14522                 wait ${stop_pids[mds$i]} || error "mds$i: stop failed"
14523         done
14524
14525         # XXX
14526         # may try to check if any orphan changelog records are present
14527         # via ldiskfs/zfs and llog_reader...
14528
14529         # re-start/mount MDTs
14530         for i in $(seq $MDSCOUNT); do
14531                 start mds$i $(mdsdevname $i) $MDS_MOUNT_OPTS ||
14532                         error "Fail to start mds$i"
14533         done
14534
14535         local first_rec
14536         for i in $(seq $MDSCOUNT); do
14537                 # check cl_user1 still registered
14538                 changelog_users mds$i | grep -q "${cl_user1[mds$i]}" ||
14539                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14540                 # check cl_user2 unregistered
14541                 changelog_users mds$i | grep -q "${cl_user2[mds$i]}" &&
14542                         error "mds$i: User ${cl_user2[mds$i]} still registered"
14543
14544                 # check changelogs are present and starting at $user_rec1 + 1
14545                 user_rec1=$(changelog_user_rec mds$i ${cl_user1[mds$i]})
14546                 [ -n "$user_rec1" ] ||
14547                         error "mds$i: User ${cl_user1[mds$i]} not registered"
14548                 first_rec=$($LFS changelog $(facet_svc mds$i) |
14549                             awk '{ print $1; exit; }')
14550
14551                 echo "mds$i: verifying first index $user_rec1 + 1 == $first_rec"
14552                 [ $((user_rec1 + 1)) == $first_rec ] ||
14553                         error "mds$i: first index should be $user_rec1 + 1, " \
14554                               "but is $first_rec"
14555         done
14556 }
14557 run_test 160h "changelog gc thread stop upon umount, orphan records delete " \
14558               "during mount"
14559
14560 test_160i() {
14561
14562         local mdts=$(comma_list $(mdts_nodes))
14563
14564         changelog_register || error "first changelog_register failed"
14565
14566         # generate some changelog records to accumulate on each MDT
14567         # use fnv1a because created files should be evenly distributed
14568         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14569                 error "mkdir $tdir failed"
14570         createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
14571                 error "create $DIR/$tdir/$tfile failed"
14572
14573         # check changelogs have been generated
14574         local nbcl=$(changelog_dump | wc -l)
14575         [[ $nbcl -eq 0 ]] && error "no changelogs found"
14576
14577         # simulate race between register and unregister
14578         # XXX as fail_loc is set per-MDS, with DNE configs the race
14579         # simulation will only occur for one MDT per MDS and for the
14580         # others the normal race scenario will take place
14581         #define CFS_FAIL_CHLOG_USER_REG_UNREG_RACE          0x1315
14582         do_nodes $mdts $LCTL set_param fail_loc=0x10001315
14583         do_nodes $mdts $LCTL set_param fail_val=1
14584
14585         # unregister 1st user
14586         changelog_deregister &
14587         local pid1=$!
14588         # wait some time for deregister work to reach race rdv
14589         sleep 2
14590         # register 2nd user
14591         changelog_register || error "2nd user register failed"
14592
14593         wait $pid1 || error "1st user deregister failed"
14594
14595         local i
14596         local last_rec
14597         declare -A LAST_REC
14598         for i in $(seq $MDSCOUNT); do
14599                 if changelog_users mds$i | grep "^cl"; then
14600                         # make sure new records are added with one user present
14601                         LAST_REC[mds$i]=$(changelog_users $SINGLEMDS |
14602                                           awk '/^current.index:/ { print $NF }')
14603                 else
14604                         error "mds$i has no user registered"
14605                 fi
14606         done
14607
14608         # generate more changelog records to accumulate on each MDT
14609         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
14610                 error "create $DIR/$tdir/${tfile}bis failed"
14611
14612         for i in $(seq $MDSCOUNT); do
14613                 last_rec=$(changelog_users $SINGLEMDS |
14614                            awk '/^current.index:/ { print $NF }')
14615                 echo "verify changelogs are on: $last_rec != ${LAST_REC[mds$i]}"
14616                 [ $last_rec != ${LAST_REC[mds$i]} ] ||
14617                         error "changelogs are off on mds$i"
14618         done
14619 }
14620 run_test 160i "changelog user register/unregister race"
14621
14622 test_160j() {
14623         remote_mds_nodsh && skip "remote MDS with nodsh"
14624         [[ $MDS1_VERSION -lt $(version_code 2.12.56) ]] &&
14625                 skip "Need MDS version at least 2.12.56"
14626
14627         mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
14628         stack_trap "umount $MOUNT2" EXIT
14629
14630         changelog_register || error "first changelog_register failed"
14631         stack_trap "changelog_deregister" EXIT
14632
14633         # generate some changelog
14634         # use fnv1a because created files should be evenly distributed
14635         test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
14636                 error "mkdir $tdir failed"
14637         createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
14638                 error "create $DIR/$tdir/${tfile}bis failed"
14639
14640         # open the changelog device
14641         exec 3>/dev/changelog-$FSNAME-MDT0000
14642         stack_trap "exec 3>&-" EXIT
14643         exec 4</dev/changelog-$FSNAME-MDT0000
14644         stack_trap "exec 4<&-" EXIT
14645
14646         # umount the first lustre mount
14647         umount $MOUNT
14648         stack_trap "mount_client $MOUNT" EXIT
14649
14650         # read changelog
14651         cat <&4 >/dev/null || error "read changelog failed"
14652
14653         # clear changelog
14654         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
14655         changelog_users $SINGLEMDS | grep -q $cl_user ||
14656                 error "User $cl_user not found in changelog_users"
14657
14658         printf 'clear:'$cl_user':0' >&3
14659 }
14660 run_test 160j "client can be umounted  while its chanangelog is being used"
14661
14662 test_160k() {
14663         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14664         remote_mds_nodsh && skip "remote MDS with nodsh"
14665
14666         mkdir -p $DIR/$tdir/1/1
14667
14668         changelog_register || error "changelog_register failed"
14669         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
14670
14671         changelog_users $SINGLEMDS | grep -q $cl_user ||
14672                 error "User '$cl_user' not found in changelog_users"
14673 #define OBD_FAIL_MDS_CHANGELOG_REORDER 0x15d
14674         do_facet mds1 $LCTL set_param fail_loc=0x8000015d fail_val=3
14675         rmdir $DIR/$tdir/1/1 & sleep 1
14676         mkdir $DIR/$tdir/2
14677         touch $DIR/$tdir/2/2
14678         rm -rf $DIR/$tdir/2
14679
14680         wait
14681         sleep 4
14682
14683         changelog_dump | grep rmdir || error "rmdir not recorded"
14684
14685         rm -rf $DIR/$tdir
14686         changelog_deregister
14687 }
14688 run_test 160k "Verify that changelog records are not lost"
14689
14690 test_161a() {
14691         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14692
14693         test_mkdir -c1 $DIR/$tdir
14694         cp /etc/hosts $DIR/$tdir/$tfile
14695         test_mkdir -c1 $DIR/$tdir/foo1
14696         test_mkdir -c1 $DIR/$tdir/foo2
14697         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
14698         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
14699         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
14700         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
14701         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
14702         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
14703                 $LFS fid2path $DIR $FID
14704                 error "bad link ea"
14705         fi
14706         # middle
14707         rm $DIR/$tdir/foo2/zachary
14708         # last
14709         rm $DIR/$tdir/foo2/thor
14710         # first
14711         rm $DIR/$tdir/$tfile
14712         # rename
14713         mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
14714         [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ] &&
14715                 { $LFS fid2path $DIR $FID; error "bad link rename"; }
14716         rm $DIR/$tdir/foo2/maggie
14717
14718         # overflow the EA
14719         local longname=$tfile.avg_len_is_thirty_two_
14720         stack_trap "unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
14721                 error_noexit 'failed to unlink many hardlinks'" EXIT
14722         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
14723                 error "failed to hardlink many files"
14724         links=$($LFS fid2path $DIR $FID | wc -l)
14725         echo -n "${links}/1000 links in link EA"
14726         [[ $links -gt 60 ]] || error "expected at least 60 links in link EA"
14727 }
14728 run_test 161a "link ea sanity"
14729
14730 test_161b() {
14731         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14732         [ $MDSCOUNT -lt 2 ] && skip_env "skipping remote directory test"
14733
14734         local MDTIDX=1
14735         local remote_dir=$DIR/$tdir/remote_dir
14736
14737         mkdir -p $DIR/$tdir
14738         $LFS mkdir -i $MDTIDX $remote_dir ||
14739                 error "create remote directory failed"
14740
14741         cp /etc/hosts $remote_dir/$tfile
14742         mkdir -p $remote_dir/foo1
14743         mkdir -p $remote_dir/foo2
14744         ln $remote_dir/$tfile $remote_dir/foo1/sofia
14745         ln $remote_dir/$tfile $remote_dir/foo2/zachary
14746         ln $remote_dir/$tfile $remote_dir/foo1/luna
14747         ln $remote_dir/$tfile $remote_dir/foo2/thor
14748
14749         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
14750                      tr -d ']')
14751         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
14752                 $LFS fid2path $DIR $FID
14753                 error "bad link ea"
14754         fi
14755         # middle
14756         rm $remote_dir/foo2/zachary
14757         # last
14758         rm $remote_dir/foo2/thor
14759         # first
14760         rm $remote_dir/$tfile
14761         # rename
14762         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
14763         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
14764         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
14765                 $LFS fid2path $DIR $FID
14766                 error "bad link rename"
14767         fi
14768         rm $remote_dir/foo2/maggie
14769
14770         # overflow the EA
14771         local longname=filename_avg_len_is_thirty_two_
14772         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
14773                 error "failed to hardlink many files"
14774         links=$($LFS fid2path $DIR $FID | wc -l)
14775         echo -n "${links}/1000 links in link EA"
14776         [[ ${links} -gt 60 ]] ||
14777                 error "expected at least 60 links in link EA"
14778         unlinkmany $remote_dir/foo2/$longname 1000 ||
14779         error "failed to unlink many hardlinks"
14780 }
14781 run_test 161b "link ea sanity under remote directory"
14782
14783 test_161c() {
14784         remote_mds_nodsh && skip "remote MDS with nodsh"
14785         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14786         [[ $MDS1_VERSION -lt $(version_code 2.1.5) ]] &&
14787                 skip "Need MDS version at least 2.1.5"
14788
14789         # define CLF_RENAME_LAST 0x0001
14790         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
14791         changelog_register || error "changelog_register failed"
14792
14793         rm -rf $DIR/$tdir
14794         test_mkdir -i $((MDSCOUNT - 1)) $DIR/$tdir
14795         touch $DIR/$tdir/foo_161c
14796         touch $DIR/$tdir/bar_161c
14797         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
14798         changelog_dump | grep RENME | tail -n 5
14799         local flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
14800         changelog_clear 0 || error "changelog_clear failed"
14801         if [ x$flags != "x0x1" ]; then
14802                 error "flag $flags is not 0x1"
14803         fi
14804
14805         echo "rename overwrite target with nlink = 1, changelog flags=$flags"
14806         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
14807         touch $DIR/$tdir/foo_161c
14808         touch $DIR/$tdir/bar_161c
14809         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
14810         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
14811         changelog_dump | grep RENME | tail -n 5
14812         flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
14813         changelog_clear 0 || error "changelog_clear failed"
14814         if [ x$flags != "x0x0" ]; then
14815                 error "flag $flags is not 0x0"
14816         fi
14817         echo "rename overwrite a target having nlink > 1," \
14818                 "changelog record has flags of $flags"
14819
14820         # rename doesn't overwrite a target (changelog flag 0x0)
14821         touch $DIR/$tdir/foo_161c
14822         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
14823         changelog_dump | grep RENME | tail -n 5
14824         flags=$(changelog_dump | grep RENME | tail -1 | cut -f5 -d' ')
14825         changelog_clear 0 || error "changelog_clear failed"
14826         if [ x$flags != "x0x0" ]; then
14827                 error "flag $flags is not 0x0"
14828         fi
14829         echo "rename doesn't overwrite a target," \
14830                 "changelog record has flags of $flags"
14831
14832         # define CLF_UNLINK_LAST 0x0001
14833         # unlink a file having nlink = 1 (changelog flag 0x1)
14834         rm -f $DIR/$tdir/foo2_161c
14835         changelog_dump | grep UNLNK | tail -n 5
14836         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
14837         changelog_clear 0 || error "changelog_clear failed"
14838         if [ x$flags != "x0x1" ]; then
14839                 error "flag $flags is not 0x1"
14840         fi
14841         echo "unlink a file having nlink = 1," \
14842                 "changelog record has flags of $flags"
14843
14844         # unlink a file having nlink > 1 (changelog flag 0x0)
14845         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
14846         rm -f $DIR/$tdir/foobar_161c
14847         changelog_dump | grep UNLNK | tail -n 5
14848         flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
14849         changelog_clear 0 || error "changelog_clear failed"
14850         if [ x$flags != "x0x0" ]; then
14851                 error "flag $flags is not 0x0"
14852         fi
14853         echo "unlink a file having nlink > 1, changelog record flags '$flags'"
14854 }
14855 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
14856
14857 test_161d() {
14858         remote_mds_nodsh && skip "remote MDS with nodsh"
14859         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
14860
14861         local pid
14862         local fid
14863
14864         changelog_register || error "changelog_register failed"
14865
14866         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
14867         # interfer with $MOUNT/.lustre/fid/ access
14868         mkdir $DIR/$tdir
14869         [[ $? -eq 0 ]] || error "mkdir failed"
14870
14871         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
14872         $LCTL set_param fail_loc=0x8000140c
14873         # 5s pause
14874         $LCTL set_param fail_val=5
14875
14876         # create file
14877         echo foofoo > $DIR/$tdir/$tfile &
14878         pid=$!
14879
14880         # wait for create to be delayed
14881         sleep 2
14882
14883         ps -p $pid
14884         [[ $? -eq 0 ]] || error "create should be blocked"
14885
14886         local tempfile="$(mktemp --tmpdir $tfile.XXXXXX)"
14887         stack_trap "rm -f $tempfile"
14888         fid=$(changelog_extract_field "CREAT" "$tfile" "t=")
14889         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
14890         # some delay may occur during ChangeLog publishing and file read just
14891         # above, that could allow file write to happen finally
14892         [[ -s $tempfile ]] && echo "file should be empty"
14893
14894         $LCTL set_param fail_loc=0
14895
14896         wait $pid
14897         [[ $? -eq 0 ]] || error "create failed"
14898 }
14899 run_test 161d "create with concurrent .lustre/fid access"
14900
14901 check_path() {
14902         local expected="$1"
14903         shift
14904         local fid="$2"
14905
14906         local path
14907         path=$($LFS fid2path "$@")
14908         local rc=$?
14909
14910         if [ $rc -ne 0 ]; then
14911                 error "path looked up of '$expected' failed: rc=$rc"
14912         elif [ "$path" != "$expected" ]; then
14913                 error "path looked up '$path' instead of '$expected'"
14914         else
14915                 echo "FID '$fid' resolves to path '$path' as expected"
14916         fi
14917 }
14918
14919 test_162a() { # was test_162
14920         test_mkdir -p -c1 $DIR/$tdir/d2
14921         touch $DIR/$tdir/d2/$tfile
14922         touch $DIR/$tdir/d2/x1
14923         touch $DIR/$tdir/d2/x2
14924         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
14925         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
14926         # regular file
14927         local fid=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
14928         check_path "$tdir/d2/$tfile" $FSNAME "$fid" --link 0
14929
14930         # softlink
14931         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
14932         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
14933         check_path "$tdir/d2/p/q/r/slink" $FSNAME "$fid" --link 0
14934
14935         # softlink to wrong file
14936         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
14937         fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
14938         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME "$fid" --link 0
14939
14940         # hardlink
14941         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
14942         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
14943         fid=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
14944         # fid2path dir/fsname should both work
14945         check_path "$tdir/d2/a/b/c/new_file" $FSNAME "$fid" --link 1
14946         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR "$fid" --link 0
14947
14948         # hardlink count: check that there are 2 links
14949         local nlinks=$($LFS fid2path $DIR "$fid" | wc -l)
14950         [ $nlinks -eq 2 ] || error "expect 2 links, found $nlinks"
14951
14952         # hardlink indexing: remove the first link
14953         rm $DIR/$tdir/d2/p/q/r/hlink
14954         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $fid --link 0
14955 }
14956 run_test 162a "path lookup sanity"
14957
14958 test_162b() {
14959         [ $PARALLEL == "yes" ] && skip "skip parallel run"
14960         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
14961
14962         mkdir $DIR/$tdir
14963         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
14964                                 error "create striped dir failed"
14965
14966         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
14967                                         tail -n 1 | awk '{print $2}')
14968         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
14969
14970         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
14971         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
14972
14973         # regular file
14974         for ((i=0;i<5;i++)); do
14975                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
14976                         error "get fid for f$i failed"
14977                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0
14978
14979                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
14980                         error "get fid for d$i failed"
14981                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0
14982         done
14983
14984         return 0
14985 }
14986 run_test 162b "striped directory path lookup sanity"
14987
14988 # LU-4239: Verify fid2path works with paths 100 or more directories deep
14989 test_162c() {
14990         [[ $MDS1_VERSION -lt $(version_code 2.7.51) ]] &&
14991                 skip "Need MDS version at least 2.7.51"
14992
14993         local lpath=$tdir.local
14994         local rpath=$tdir.remote
14995
14996         test_mkdir $DIR/$lpath
14997         test_mkdir $DIR/$rpath
14998
14999         for ((i = 0; i <= 101; i++)); do
15000                 lpath="$lpath/$i"
15001                 mkdir $DIR/$lpath
15002                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
15003                         error "get fid for local directory $DIR/$lpath failed"
15004                 check_path "$DIR/$lpath" $MOUNT $FID --link 0
15005
15006                 rpath="$rpath/$i"
15007                 test_mkdir $DIR/$rpath
15008                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
15009                         error "get fid for remote directory $DIR/$rpath failed"
15010                 check_path "$DIR/$rpath" $MOUNT $FID --link 0
15011         done
15012
15013         return 0
15014 }
15015 run_test 162c "fid2path works with paths 100 or more directories deep"
15016
15017 oalr_event_count() {
15018         local event="${1}"
15019         local trace="${2}"
15020
15021         awk -v name="${FSNAME}-OST0000" \
15022             -v event="${event}" \
15023             '$1 == "TRACE" && $2 == event && $3 == name' \
15024             "${trace}" |
15025         wc -l
15026 }
15027
15028 oalr_expect_event_count() {
15029         local event="${1}"
15030         local trace="${2}"
15031         local expect="${3}"
15032         local count
15033
15034         count=$(oalr_event_count "${event}" "${trace}")
15035         if ((count == expect)); then
15036                 return 0
15037         fi
15038
15039         error_noexit "${event} event count was '${count}', expected ${expect}"
15040         cat "${trace}" >&2
15041         exit 1
15042 }
15043
15044 cleanup_165() {
15045         do_facet ost1 killall --quiet -KILL ofd_access_log_reader || true
15046         stop ost1
15047         start ost1 "$(ostdevname 1)" $OST_MOUNT_OPTS
15048 }
15049
15050 setup_165() {
15051         sync # Flush previous IOs so we can count log entries.
15052         do_facet ost1 $LCTL set_param "obdfilter.${FSNAME}-OST0000.access_log_size=4096"
15053         stack_trap cleanup_165 EXIT
15054 }
15055
15056 test_165a() {
15057         local trace="/tmp/${tfile}.trace"
15058         local rc
15059         local count
15060
15061         do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
15062         setup_165
15063         sleep 5
15064
15065         do_facet ost1 ofd_access_log_reader --list
15066         stop ost1
15067
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         # Parse trace file for discovery events:
15077         oalr_expect_event_count alr_log_add "${trace}" 1
15078         oalr_expect_event_count alr_log_eof "${trace}" 1
15079         oalr_expect_event_count alr_log_free "${trace}" 1
15080 }
15081 run_test 165a "ofd access log discovery"
15082
15083 test_165b() {
15084         local trace="/tmp/${tfile}.trace"
15085         local file="${DIR}/${tfile}"
15086         local pfid1
15087         local pfid2
15088         local -a entry
15089         local rc
15090         local count
15091         local size
15092         local flags
15093
15094         setup_165
15095
15096         lfs setstripe -c 1 -i 0 "${file}"
15097         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15098         do_facet ost1 ofd_access_log_reader --list
15099
15100         do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
15101         sleep 5
15102         do_facet ost1 killall -TERM ofd_access_log_reader
15103         wait
15104         rc=$?
15105
15106         if ((rc != 0)); then
15107                 error "ofd_access_log_reader exited with rc = '${rc}'"
15108         fi
15109
15110         oalr_expect_event_count alr_log_entry "${trace}" 1
15111
15112         pfid1=$($LFS path2fid "${file}")
15113
15114         # 1     2             3   4    5     6   7    8    9     10
15115         # TRACE alr_log_entry OST PFID BEGIN END TIME SIZE COUNT FLAGS
15116         entry=( - $(awk -v pfid="${pfid}" '$1 == "TRACE" && $2 == "alr_log_entry"' "${trace}" ) )
15117
15118         echo "entry = '${entry[*]}'" >&2
15119
15120         pfid2=${entry[4]}
15121         if [[ "${pfid1}" != "${pfid2}" ]]; then
15122                 error "entry '${entry[*]}' has invalid PFID '${pfid2}', expected ${pfid1}"
15123         fi
15124
15125         size=${entry[8]}
15126         if ((size != 1048576)); then
15127                 error "entry '${entry[*]}' has invalid io size '${size}', expected 1048576"
15128         fi
15129
15130         flags=${entry[10]}
15131         if [[ "${flags}" != "w" ]]; then
15132                 error "entry '${entry[*]}' has invalid io flags '${flags}', expected 'w'"
15133         fi
15134
15135         do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
15136         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r524288c || error "cannot read '${file}'"
15137         sleep 5
15138         do_facet ost1 killall -TERM ofd_access_log_reader
15139         wait
15140         rc=$?
15141
15142         if ((rc != 0)); then
15143                 error "ofd_access_log_reader exited with rc = '${rc}'"
15144         fi
15145
15146         oalr_expect_event_count alr_log_entry "${trace}" 1
15147
15148         entry=( - $(awk -v pfid="${pfid}" '$1 == "TRACE" && $2 == "alr_log_entry"' "${trace}" ) )
15149         echo "entry = '${entry[*]}'" >&2
15150
15151         pfid2=${entry[4]}
15152         if [[ "${pfid1}" != "${pfid2}" ]]; then
15153                 error "entry '${entry[*]}' has invalid PFID '${pfid2}', expected ${pfid1}"
15154         fi
15155
15156         size=${entry[8]}
15157         if ((size != 524288)); then
15158                 error "entry '${entry[*]}' has invalid io size '${size}', 524288"
15159         fi
15160
15161         flags=${entry[10]}
15162         if [[ "${flags}" != "r" ]]; then
15163                 error "entry '${entry[*]}' has invalid io flags '${flags}', expected 'r'"
15164         fi
15165 }
15166 run_test 165b "ofd access log entries are produced and consumed"
15167
15168 test_165c() {
15169         local file="${DIR}/${tdir}/${tfile}"
15170         test_mkdir "${DIR}/${tdir}"
15171
15172         setup_165
15173
15174         lfs setstripe -c 1 -i 0 "${DIR}/${tdir}"
15175
15176         # 4096 / 64 = 64. Create twice as many entries.
15177         for ((i = 0; i < 128; i++)); do
15178                 $MULTIOP "${file}-${i}" oO_CREAT:O_WRONLY:w512c || error "cannot create file"
15179         done
15180
15181         sync
15182         do_facet ost1 ofd_access_log_reader --list
15183         unlinkmany  "${file}-%d" 128
15184 }
15185 run_test 165c "full ofd access logs do not block IOs"
15186
15187 oal_peek_entry_count() {
15188         do_facet ost1 ofd_access_log_reader --list | awk '$1 == "_entry_count:" { print $2; }'
15189 }
15190
15191 oal_expect_entry_count() {
15192         local entry_count=$(oal_peek_entry_count)
15193         local expect="$1"
15194
15195         if ((entry_count == expect)); then
15196                 return 0
15197         fi
15198
15199         error_noexit "bad entry count, got ${entry_count}, expected ${expect}"
15200         do_facet ost1 ofd_access_log_reader --list >&2
15201         exit 1
15202 }
15203
15204 test_165d() {
15205         local trace="/tmp/${tfile}.trace"
15206         local file="${DIR}/${tdir}/${tfile}"
15207         local param="obdfilter.${FSNAME}-OST0000.access_log_mask"
15208         local entry_count
15209         test_mkdir "${DIR}/${tdir}"
15210
15211         setup_165
15212         lfs setstripe -c 1 -i 0 "${file}"
15213
15214         do_facet ost1 lctl set_param "${param}=rw"
15215         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15216         oal_expect_entry_count 1
15217
15218         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
15219         oal_expect_entry_count 2
15220
15221         do_facet ost1 lctl set_param "${param}=r"
15222         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15223         oal_expect_entry_count 2
15224
15225         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
15226         oal_expect_entry_count 3
15227
15228         do_facet ost1 lctl set_param "${param}=w"
15229         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15230         oal_expect_entry_count 4
15231
15232         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
15233         oal_expect_entry_count 4
15234
15235         do_facet ost1 lctl set_param "${param}=0"
15236         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
15237         oal_expect_entry_count 4
15238
15239         $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
15240         oal_expect_entry_count 4
15241 }
15242 run_test 165d "ofd_access_log mask works"
15243
15244 test_169() {
15245         # do directio so as not to populate the page cache
15246         log "creating a 10 Mb file"
15247         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
15248         log "starting reads"
15249         dd if=$DIR/$tfile of=/dev/null bs=4096 &
15250         log "truncating the file"
15251         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
15252         log "killing dd"
15253         kill %+ || true # reads might have finished
15254         echo "wait until dd is finished"
15255         wait
15256         log "removing the temporary file"
15257         rm -rf $DIR/$tfile || error "tmp file removal failed"
15258 }
15259 run_test 169 "parallel read and truncate should not deadlock"
15260
15261 test_170() {
15262         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15263
15264         $LCTL clear     # bug 18514
15265         $LCTL debug_daemon start $TMP/${tfile}_log_good
15266         touch $DIR/$tfile
15267         $LCTL debug_daemon stop
15268         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
15269                 error "sed failed to read log_good"
15270
15271         $LCTL debug_daemon start $TMP/${tfile}_log_good
15272         rm -rf $DIR/$tfile
15273         $LCTL debug_daemon stop
15274
15275         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
15276                error "lctl df log_bad failed"
15277
15278         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
15279         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
15280
15281         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
15282         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
15283
15284         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
15285                 error "bad_line good_line1 good_line2 are empty"
15286
15287         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
15288         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
15289         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
15290
15291         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
15292         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
15293         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
15294
15295         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
15296                 error "bad_line_new good_line_new are empty"
15297
15298         local expected_good=$((good_line1 + good_line2*2))
15299
15300         rm -f $TMP/${tfile}*
15301         # LU-231, short malformed line may not be counted into bad lines
15302         if [ $bad_line -ne $bad_line_new ] &&
15303                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
15304                 error "expected $bad_line bad lines, but got $bad_line_new"
15305                 return 1
15306         fi
15307
15308         if [ $expected_good -ne $good_line_new ]; then
15309                 error "expected $expected_good good lines, but got $good_line_new"
15310                 return 2
15311         fi
15312         true
15313 }
15314 run_test 170 "test lctl df to handle corrupted log ====================="
15315
15316 test_171() { # bug20592
15317         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15318
15319         #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
15320         $LCTL set_param fail_loc=0x50e
15321         $LCTL set_param fail_val=3000
15322         multiop_bg_pause $DIR/$tfile O_s || true
15323         local MULTIPID=$!
15324         kill -USR1 $MULTIPID
15325         # cause log dump
15326         sleep 3
15327         wait $MULTIPID
15328         if dmesg | grep "recursive fault"; then
15329                 error "caught a recursive fault"
15330         fi
15331         $LCTL set_param fail_loc=0
15332         true
15333 }
15334 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
15335
15336 # it would be good to share it with obdfilter-survey/iokit-libecho code
15337 setup_obdecho_osc () {
15338         local rc=0
15339         local ost_nid=$1
15340         local obdfilter_name=$2
15341         echo "Creating new osc for $obdfilter_name on $ost_nid"
15342         # make sure we can find loopback nid
15343         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
15344
15345         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
15346                            ${obdfilter_name}_osc_UUID || rc=2; }
15347         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
15348                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
15349         return $rc
15350 }
15351
15352 cleanup_obdecho_osc () {
15353         local obdfilter_name=$1
15354         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
15355         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
15356         return 0
15357 }
15358
15359 obdecho_test() {
15360         local OBD=$1
15361         local node=$2
15362         local pages=${3:-64}
15363         local rc=0
15364         local id
15365
15366         local count=10
15367         local obd_size=$(get_obd_size $node $OBD)
15368         local page_size=$(get_page_size $node)
15369         if [[ -n "$obd_size" ]]; then
15370                 local new_count=$((obd_size / (pages * page_size / 1024)))
15371                 [[ $new_count -ge $count ]] || count=$new_count
15372         fi
15373
15374         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
15375         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
15376                            rc=2; }
15377         if [ $rc -eq 0 ]; then
15378             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
15379             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
15380         fi
15381         echo "New object id is $id"
15382         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
15383                            rc=4; }
15384         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
15385                            "test_brw $count w v $pages $id" || rc=4; }
15386         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
15387                            rc=4; }
15388         [ $rc -eq 0 ] || [ $rc -gt 2 ] &&
15389                 { do_facet $node "$LCTL --device ec cleanup" || rc=5; }
15390         [ $rc -eq 0 ] || [ $rc -gt 1 ] &&
15391                 { do_facet $node "$LCTL --device ec detach" || rc=6; }
15392         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
15393         return $rc
15394 }
15395
15396 test_180a() {
15397         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15398
15399         if ! module_loaded obdecho; then
15400                 load_module obdecho/obdecho &&
15401                         stack_trap "rmmod obdecho" EXIT ||
15402                         error "unable to load obdecho on client"
15403         fi
15404
15405         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
15406         local host=$($LCTL get_param -n osc.$osc.import |
15407                      awk '/current_connection:/ { print $2 }' )
15408         local target=$($LCTL get_param -n osc.$osc.import |
15409                        awk '/target:/ { print $2 }' )
15410         target=${target%_UUID}
15411
15412         if [ -n "$target" ]; then
15413                 setup_obdecho_osc $host $target &&
15414                         stack_trap "cleanup_obdecho_osc $target" EXIT ||
15415                         { error "obdecho setup failed with $?"; return; }
15416
15417                 obdecho_test ${target}_osc client ||
15418                         error "obdecho_test failed on ${target}_osc"
15419         else
15420                 $LCTL get_param osc.$osc.import
15421                 error "there is no osc.$osc.import target"
15422         fi
15423 }
15424 run_test 180a "test obdecho on osc"
15425
15426 test_180b() {
15427         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15428         remote_ost_nodsh && skip "remote OST with nodsh"
15429
15430         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
15431                 stack_trap "do_facet ost1 rmmod obdecho" EXIT ||
15432                 error "failed to load module obdecho"
15433
15434         local target=$(do_facet ost1 $LCTL dl |
15435                        awk '/obdfilter/ { print $4; exit; }')
15436
15437         if [ -n "$target" ]; then
15438                 obdecho_test $target ost1 || error "obdecho_test failed with $?"
15439         else
15440                 do_facet ost1 $LCTL dl
15441                 error "there is no obdfilter target on ost1"
15442         fi
15443 }
15444 run_test 180b "test obdecho directly on obdfilter"
15445
15446 test_180c() { # LU-2598
15447         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15448         remote_ost_nodsh && skip "remote OST with nodsh"
15449         [[ $MDS1_VERSION -lt $(version_code 2.4.0) ]] &&
15450                 skip "Need MDS version at least 2.4.0"
15451
15452         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
15453                 stack_trap "do_facet ost1 rmmod obdecho" EXIT ||
15454                 error "failed to load module obdecho"
15455
15456         local target=$(do_facet ost1 $LCTL dl |
15457                        awk '/obdfilter/ { print $4; exit; }')
15458
15459         if [ -n "$target" ]; then
15460                 local pages=16384 # 64MB bulk I/O RPC size
15461
15462                 obdecho_test "$target" ost1 "$pages" ||
15463                         error "obdecho_test with pages=$pages failed with $?"
15464         else
15465                 do_facet ost1 $LCTL dl
15466                 error "there is no obdfilter target on ost1"
15467         fi
15468 }
15469 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
15470
15471 test_181() { # bug 22177
15472         test_mkdir $DIR/$tdir
15473         # create enough files to index the directory
15474         createmany -o $DIR/$tdir/foobar 4000
15475         # print attributes for debug purpose
15476         lsattr -d .
15477         # open dir
15478         multiop_bg_pause $DIR/$tdir D_Sc || return 1
15479         MULTIPID=$!
15480         # remove the files & current working dir
15481         unlinkmany $DIR/$tdir/foobar 4000
15482         rmdir $DIR/$tdir
15483         kill -USR1 $MULTIPID
15484         wait $MULTIPID
15485         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
15486         return 0
15487 }
15488 run_test 181 "Test open-unlinked dir ========================"
15489
15490 test_182() {
15491         local fcount=1000
15492         local tcount=10
15493
15494         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
15495
15496         $LCTL set_param mdc.*.rpc_stats=clear
15497
15498         for (( i = 0; i < $tcount; i++ )) ; do
15499                 mkdir $DIR/$tdir/$i
15500         done
15501
15502         for (( i = 0; i < $tcount; i++ )) ; do
15503                 createmany -o $DIR/$tdir/$i/f- $fcount &
15504         done
15505         wait
15506
15507         for (( i = 0; i < $tcount; i++ )) ; do
15508                 unlinkmany $DIR/$tdir/$i/f- $fcount &
15509         done
15510         wait
15511
15512         $LCTL get_param mdc.*.rpc_stats
15513
15514         rm -rf $DIR/$tdir
15515 }
15516 run_test 182 "Test parallel modify metadata operations ================"
15517
15518 test_183() { # LU-2275
15519         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15520         remote_mds_nodsh && skip "remote MDS with nodsh"
15521         [[ $MDS1_VERSION -lt $(version_code 2.3.56) ]] &&
15522                 skip "Need MDS version at least 2.3.56"
15523
15524         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
15525         echo aaa > $DIR/$tdir/$tfile
15526
15527 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
15528         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
15529
15530         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
15531         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
15532
15533         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
15534
15535         # Flush negative dentry cache
15536         touch $DIR/$tdir/$tfile
15537
15538         # We are not checking for any leaked references here, they'll
15539         # become evident next time we do cleanup with module unload.
15540         rm -rf $DIR/$tdir
15541 }
15542 run_test 183 "No crash or request leak in case of strange dispositions ========"
15543
15544 # test suite 184 is for LU-2016, LU-2017
15545 test_184a() {
15546         check_swap_layouts_support
15547
15548         dir0=$DIR/$tdir/$testnum
15549         test_mkdir -p -c1 $dir0
15550         ref1=/etc/passwd
15551         ref2=/etc/group
15552         file1=$dir0/f1
15553         file2=$dir0/f2
15554         $LFS setstripe -c1 $file1
15555         cp $ref1 $file1
15556         $LFS setstripe -c2 $file2
15557         cp $ref2 $file2
15558         gen1=$($LFS getstripe -g $file1)
15559         gen2=$($LFS getstripe -g $file2)
15560
15561         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
15562         gen=$($LFS getstripe -g $file1)
15563         [[ $gen1 != $gen ]] ||
15564                 "Layout generation on $file1 does not change"
15565         gen=$($LFS getstripe -g $file2)
15566         [[ $gen2 != $gen ]] ||
15567                 "Layout generation on $file2 does not change"
15568
15569         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
15570         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
15571
15572         lfsck_verify_pfid $file1 $file2 || error "PFID are not transferred"
15573 }
15574 run_test 184a "Basic layout swap"
15575
15576 test_184b() {
15577         check_swap_layouts_support
15578
15579         dir0=$DIR/$tdir/$testnum
15580         mkdir -p $dir0 || error "creating dir $dir0"
15581         file1=$dir0/f1
15582         file2=$dir0/f2
15583         file3=$dir0/f3
15584         dir1=$dir0/d1
15585         dir2=$dir0/d2
15586         mkdir $dir1 $dir2
15587         $LFS setstripe -c1 $file1
15588         $LFS setstripe -c2 $file2
15589         $LFS setstripe -c1 $file3
15590         chown $RUNAS_ID $file3
15591         gen1=$($LFS getstripe -g $file1)
15592         gen2=$($LFS getstripe -g $file2)
15593
15594         $LFS swap_layouts $dir1 $dir2 &&
15595                 error "swap of directories layouts should fail"
15596         $LFS swap_layouts $dir1 $file1 &&
15597                 error "swap of directory and file layouts should fail"
15598         $RUNAS $LFS swap_layouts $file1 $file2 &&
15599                 error "swap of file we cannot write should fail"
15600         $LFS swap_layouts $file1 $file3 &&
15601                 error "swap of file with different owner should fail"
15602         /bin/true # to clear error code
15603 }
15604 run_test 184b "Forbidden layout swap (will generate errors)"
15605
15606 test_184c() {
15607         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
15608         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n"
15609         check_swap_layouts_support
15610
15611         local dir0=$DIR/$tdir/$testnum
15612         mkdir -p $dir0 || error "creating dir $dir0"
15613
15614         local ref1=$dir0/ref1
15615         local ref2=$dir0/ref2
15616         local file1=$dir0/file1
15617         local file2=$dir0/file2
15618         # create a file large enough for the concurrent test
15619         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
15620         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
15621         echo "ref file size: ref1($(stat -c %s $ref1))," \
15622              "ref2($(stat -c %s $ref2))"
15623
15624         cp $ref2 $file2
15625         dd if=$ref1 of=$file1 bs=16k &
15626         local DD_PID=$!
15627
15628         # Make sure dd starts to copy file
15629         while [ ! -f $file1 ]; do sleep 0.1; done
15630
15631         $LFS swap_layouts $file1 $file2
15632         local rc=$?
15633         wait $DD_PID
15634         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
15635         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
15636
15637         # how many bytes copied before swapping layout
15638         local copied=$(stat -c %s $file2)
15639         local remaining=$(stat -c %s $ref1)
15640         remaining=$((remaining - copied))
15641         echo "Copied $copied bytes before swapping layout..."
15642
15643         cmp -n $copied $file1 $ref2 | grep differ &&
15644                 error "Content mismatch [0, $copied) of ref2 and file1"
15645         cmp -n $copied $file2 $ref1 ||
15646                 error "Content mismatch [0, $copied) of ref1 and file2"
15647         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
15648                 error "Content mismatch [$copied, EOF) of ref1 and file1"
15649
15650         # clean up
15651         rm -f $ref1 $ref2 $file1 $file2
15652 }
15653 run_test 184c "Concurrent write and layout swap"
15654
15655 test_184d() {
15656         check_swap_layouts_support
15657         [ -z "$(which getfattr 2>/dev/null)" ] &&
15658                 skip_env "no getfattr command"
15659
15660         local file1=$DIR/$tdir/$tfile-1
15661         local file2=$DIR/$tdir/$tfile-2
15662         local file3=$DIR/$tdir/$tfile-3
15663         local lovea1
15664         local lovea2
15665
15666         mkdir -p $DIR/$tdir
15667         touch $file1 || error "create $file1 failed"
15668         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
15669                 error "create $file2 failed"
15670         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
15671                 error "create $file3 failed"
15672         lovea1=$(get_layout_param $file1)
15673
15674         $LFS swap_layouts $file2 $file3 ||
15675                 error "swap $file2 $file3 layouts failed"
15676         $LFS swap_layouts $file1 $file2 ||
15677                 error "swap $file1 $file2 layouts failed"
15678
15679         lovea2=$(get_layout_param $file2)
15680         echo "$lovea1"
15681         echo "$lovea2"
15682         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
15683
15684         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
15685         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
15686 }
15687 run_test 184d "allow stripeless layouts swap"
15688
15689 test_184e() {
15690         [[ $MDS1_VERSION -ge $(version_code 2.6.94) ]] ||
15691                 skip "Need MDS version at least 2.6.94"
15692         check_swap_layouts_support
15693         [ -z "$(which getfattr 2>/dev/null)" ] &&
15694                 skip_env "no getfattr command"
15695
15696         local file1=$DIR/$tdir/$tfile-1
15697         local file2=$DIR/$tdir/$tfile-2
15698         local file3=$DIR/$tdir/$tfile-3
15699         local lovea
15700
15701         mkdir -p $DIR/$tdir
15702         touch $file1 || error "create $file1 failed"
15703         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
15704                 error "create $file2 failed"
15705         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
15706                 error "create $file3 failed"
15707
15708         $LFS swap_layouts $file1 $file2 ||
15709                 error "swap $file1 $file2 layouts failed"
15710
15711         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
15712         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
15713
15714         echo 123 > $file1 || error "Should be able to write into $file1"
15715
15716         $LFS swap_layouts $file1 $file3 ||
15717                 error "swap $file1 $file3 layouts failed"
15718
15719         echo 123 > $file1 || error "Should be able to write into $file1"
15720
15721         rm -rf $file1 $file2 $file3
15722 }
15723 run_test 184e "Recreate layout after stripeless layout swaps"
15724
15725 test_184f() {
15726         # Create a file with name longer than sizeof(struct stat) ==
15727         # 144 to see if we can get chars from the file name to appear
15728         # in the returned striping. Note that 'f' == 0x66.
15729         local file=$(for ((i = 0; i < 200; i++)); do echo -n f; done)
15730
15731         mkdir -p $DIR/$tdir
15732         mcreate $DIR/$tdir/$file
15733         if lfs find --stripe-count 0x6666 $DIR/$tdir | grep $file; then
15734                 error "IOC_MDC_GETFILEINFO returned garbage striping"
15735         fi
15736 }
15737 run_test 184f "IOC_MDC_GETFILEINFO for files with long names but no striping"
15738
15739 test_185() { # LU-2441
15740         # LU-3553 - no volatile file support in old servers
15741         [[ $MDS1_VERSION -ge $(version_code 2.3.60) ]] ||
15742                 skip "Need MDS version at least 2.3.60"
15743
15744         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
15745         touch $DIR/$tdir/spoo
15746         local mtime1=$(stat -c "%Y" $DIR/$tdir)
15747         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
15748                 error "cannot create/write a volatile file"
15749         [ "$FILESET" == "" ] &&
15750         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
15751                 error "FID is still valid after close"
15752
15753         multiop_bg_pause $DIR/$tdir vVw4096_c
15754         local multi_pid=$!
15755
15756         local OLD_IFS=$IFS
15757         IFS=":"
15758         local fidv=($fid)
15759         IFS=$OLD_IFS
15760         # assume that the next FID for this client is sequential, since stdout
15761         # is unfortunately eaten by multiop_bg_pause
15762         local n=$((${fidv[1]} + 1))
15763         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
15764         if [ "$FILESET" == "" ]; then
15765                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
15766                         error "FID is missing before close"
15767         fi
15768         kill -USR1 $multi_pid
15769         # 1 second delay, so if mtime change we will see it
15770         sleep 1
15771         local mtime2=$(stat -c "%Y" $DIR/$tdir)
15772         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
15773 }
15774 run_test 185 "Volatile file support"
15775
15776 function create_check_volatile() {
15777         local idx=$1
15778         local tgt
15779
15780         $MULTIOP $MOUNT/.lustre/fid V${idx}Fw4096_c >&/tmp/${tfile}.fid &
15781         local PID=$!
15782         sleep 1
15783         local FID=$(cat /tmp/${tfile}.fid)
15784         [ "$FID" == "" ] && error "can't get FID for volatile"
15785         $CHECKSTAT -t file $MOUNT/.lustre/fid/$FID || error "can't stat $FID"
15786         tgt=$($LFS getstripe -m $MOUNT/.lustre/fid/$FID)
15787         [ "$tgt" != "$idx" ] && error "wrong MDS $tgt, expected $idx"
15788         kill -USR1 $PID
15789         wait
15790         sleep 1
15791         cancel_lru_locks mdc # flush opencache
15792         $CHECKSTAT -t file $MOUNT/.lustre/fid/$FID && error "can stat $FID"
15793         return 0
15794 }
15795
15796 test_185a(){
15797         # LU-12516 - volatile creation via .lustre
15798         [[ $MDS1_VERSION -ge $(version_code 2.12.55) ]] ||
15799                 skip "Need MDS version at least 2.3.55"
15800
15801         create_check_volatile 0
15802         [ $MDSCOUNT -lt 2 ] && return 0
15803
15804         # DNE case
15805         create_check_volatile 1
15806
15807         return 0
15808 }
15809 run_test 185a "Volatile file creation in .lustre/fid/"
15810
15811 test_187a() {
15812         remote_mds_nodsh && skip "remote MDS with nodsh"
15813         [ $MDS1_VERSION -lt $(version_code 2.3.0) ] &&
15814                 skip "Need MDS version at least 2.3.0"
15815
15816         local dir0=$DIR/$tdir/$testnum
15817         mkdir -p $dir0 || error "creating dir $dir0"
15818
15819         local file=$dir0/file1
15820         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
15821         local dv1=$($LFS data_version $file)
15822         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
15823         local dv2=$($LFS data_version $file)
15824         [[ $dv1 != $dv2 ]] ||
15825                 error "data version did not change on write $dv1 == $dv2"
15826
15827         # clean up
15828         rm -f $file1
15829 }
15830 run_test 187a "Test data version change"
15831
15832 test_187b() {
15833         remote_mds_nodsh && skip "remote MDS with nodsh"
15834         [ $MDS1_VERSION -lt $(version_code 2.3.0) ] &&
15835                 skip "Need MDS version at least 2.3.0"
15836
15837         local dir0=$DIR/$tdir/$testnum
15838         mkdir -p $dir0 || error "creating dir $dir0"
15839
15840         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
15841         [[ ${DV[0]} != ${DV[1]} ]] ||
15842                 error "data version did not change on write"\
15843                       " ${DV[0]} == ${DV[1]}"
15844
15845         # clean up
15846         rm -f $file1
15847 }
15848 run_test 187b "Test data version change on volatile file"
15849
15850 test_200() {
15851         [ $PARALLEL == "yes" ] && skip "skip parallel run"
15852         remote_mgs_nodsh && skip "remote MGS with nodsh"
15853         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
15854
15855         local POOL=${POOL:-cea1}
15856         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
15857         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
15858         # Pool OST targets
15859         local first_ost=0
15860         local last_ost=$(($OSTCOUNT - 1))
15861         local ost_step=2
15862         local ost_list=$(seq $first_ost $ost_step $last_ost)
15863         local ost_range="$first_ost $last_ost $ost_step"
15864         local test_path=$POOL_ROOT/$POOL_DIR_NAME
15865         local file_dir=$POOL_ROOT/file_tst
15866         local subdir=$test_path/subdir
15867         local rc=0
15868
15869         while : ; do
15870                 # former test_200a test_200b
15871                 pool_add $POOL                          || { rc=$? ; break; }
15872                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
15873                 # former test_200c test_200d
15874                 mkdir -p $test_path
15875                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
15876                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
15877                 mkdir -p $subdir
15878                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
15879                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
15880                                                         || { rc=$? ; break; }
15881                 # former test_200e test_200f
15882                 local files=$((OSTCOUNT*3))
15883                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
15884                                                         || { rc=$? ; break; }
15885                 pool_create_files $POOL $file_dir $files "$ost_list" \
15886                                                         || { rc=$? ; break; }
15887                 # former test_200g test_200h
15888                 pool_lfs_df $POOL                       || { rc=$? ; break; }
15889                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
15890
15891                 # former test_201a test_201b test_201c
15892                 pool_remove_first_target $POOL          || { rc=$? ; break; }
15893
15894                 local f=$test_path/$tfile
15895                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
15896                 pool_remove $POOL $f                    || { rc=$? ; break; }
15897                 break
15898         done
15899
15900         destroy_test_pools
15901
15902         return $rc
15903 }
15904 run_test 200 "OST pools"
15905
15906 # usage: default_attr <count | size | offset>
15907 default_attr() {
15908         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
15909 }
15910
15911 # usage: check_default_stripe_attr
15912 check_default_stripe_attr() {
15913         ACTUAL=$($LFS getstripe $* $DIR/$tdir)
15914         case $1 in
15915         --stripe-count|-c)
15916                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
15917         --stripe-size|-S)
15918                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
15919         --stripe-index|-i)
15920                 EXPECTED=-1;;
15921         *)
15922                 error "unknown getstripe attr '$1'"
15923         esac
15924
15925         [ $ACTUAL == $EXPECTED ] ||
15926                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
15927 }
15928
15929 test_204a() {
15930         test_mkdir $DIR/$tdir
15931         $LFS setstripe --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
15932
15933         check_default_stripe_attr --stripe-count
15934         check_default_stripe_attr --stripe-size
15935         check_default_stripe_attr --stripe-index
15936 }
15937 run_test 204a "Print default stripe attributes"
15938
15939 test_204b() {
15940         test_mkdir $DIR/$tdir
15941         $LFS setstripe --stripe-count 1 $DIR/$tdir
15942
15943         check_default_stripe_attr --stripe-size
15944         check_default_stripe_attr --stripe-index
15945 }
15946 run_test 204b "Print default stripe size and offset"
15947
15948 test_204c() {
15949         test_mkdir $DIR/$tdir
15950         $LFS setstripe --stripe-size 65536 $DIR/$tdir
15951
15952         check_default_stripe_attr --stripe-count
15953         check_default_stripe_attr --stripe-index
15954 }
15955 run_test 204c "Print default stripe count and offset"
15956
15957 test_204d() {
15958         test_mkdir $DIR/$tdir
15959         $LFS setstripe --stripe-index 0 $DIR/$tdir
15960
15961         check_default_stripe_attr --stripe-count
15962         check_default_stripe_attr --stripe-size
15963 }
15964 run_test 204d "Print default stripe count and size"
15965
15966 test_204e() {
15967         test_mkdir $DIR/$tdir
15968         $LFS setstripe -d $DIR/$tdir
15969
15970         check_default_stripe_attr --stripe-count --raw
15971         check_default_stripe_attr --stripe-size --raw
15972         check_default_stripe_attr --stripe-index --raw
15973 }
15974 run_test 204e "Print raw stripe attributes"
15975
15976 test_204f() {
15977         test_mkdir $DIR/$tdir
15978         $LFS setstripe --stripe-count 1 $DIR/$tdir
15979
15980         check_default_stripe_attr --stripe-size --raw
15981         check_default_stripe_attr --stripe-index --raw
15982 }
15983 run_test 204f "Print raw stripe size and offset"
15984
15985 test_204g() {
15986         test_mkdir $DIR/$tdir
15987         $LFS setstripe --stripe-size 65536 $DIR/$tdir
15988
15989         check_default_stripe_attr --stripe-count --raw
15990         check_default_stripe_attr --stripe-index --raw
15991 }
15992 run_test 204g "Print raw stripe count and offset"
15993
15994 test_204h() {
15995         test_mkdir $DIR/$tdir
15996         $LFS setstripe --stripe-index 0 $DIR/$tdir
15997
15998         check_default_stripe_attr --stripe-count --raw
15999         check_default_stripe_attr --stripe-size --raw
16000 }
16001 run_test 204h "Print raw stripe count and size"
16002
16003 # Figure out which job scheduler is being used, if any,
16004 # or use a fake one
16005 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
16006         JOBENV=SLURM_JOB_ID
16007 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
16008         JOBENV=LSB_JOBID
16009 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
16010         JOBENV=PBS_JOBID
16011 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
16012         JOBENV=LOADL_STEP_ID
16013 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
16014         JOBENV=JOB_ID
16015 else
16016         $LCTL list_param jobid_name > /dev/null 2>&1
16017         if [ $? -eq 0 ]; then
16018                 JOBENV=nodelocal
16019         else
16020                 JOBENV=FAKE_JOBID
16021         fi
16022 fi
16023 LUSTRE_JOBID_SIZE=31 # plus NUL terminator
16024
16025 verify_jobstats() {
16026         local cmd=($1)
16027         shift
16028         local facets="$@"
16029
16030 # we don't really need to clear the stats for this test to work, since each
16031 # command has a unique jobid, but it makes debugging easier if needed.
16032 #       for facet in $facets; do
16033 #               local dev=$(convert_facet2label $facet)
16034 #               # clear old jobstats
16035 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
16036 #       done
16037
16038         # use a new JobID for each test, or we might see an old one
16039         [ "$JOBENV" = "FAKE_JOBID" ] &&
16040                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
16041
16042         JOBVAL=${!JOBENV:0:$LUSTRE_JOBID_SIZE}
16043
16044         [ "$JOBENV" = "nodelocal" ] && {
16045                 FAKE_JOBID=id.$testnum.%e.$RANDOM
16046                 $LCTL set_param jobid_name=$FAKE_JOBID
16047                 JOBVAL=${FAKE_JOBID/\%e/$(basename ${cmd[0]})}
16048         }
16049
16050         log "Test: ${cmd[*]}"
16051         log "Using JobID environment $($LCTL get_param -n jobid_var)=$JOBVAL"
16052
16053         if [ $JOBENV = "FAKE_JOBID" ]; then
16054                 FAKE_JOBID=$JOBVAL ${cmd[*]}
16055         else
16056                 ${cmd[*]}
16057         fi
16058
16059         # all files are created on OST0000
16060         for facet in $facets; do
16061                 local stats="*.$(convert_facet2label $facet).job_stats"
16062
16063                 # strip out libtool wrappers for in-tree executables
16064                 if [ $(do_facet $facet lctl get_param $stats |
16065                        sed -e 's/\.lt-/./' | grep -c $JOBVAL) -ne 1 ]; then
16066                         do_facet $facet lctl get_param $stats
16067                         error "No jobstats for $JOBVAL found on $facet::$stats"
16068                 fi
16069         done
16070 }
16071
16072 jobstats_set() {
16073         local new_jobenv=$1
16074
16075         set_persistent_param_and_check client "jobid_var" \
16076                 "$FSNAME.sys.jobid_var" $new_jobenv
16077 }
16078
16079 test_205a() { # Job stats
16080         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16081         [[ $MDS1_VERSION -ge $(version_code 2.7.1) ]] ||
16082                 skip "Need MDS version with at least 2.7.1"
16083         remote_mgs_nodsh && skip "remote MGS with nodsh"
16084         remote_mds_nodsh && skip "remote MDS with nodsh"
16085         remote_ost_nodsh && skip "remote OST with nodsh"
16086         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
16087                 skip "Server doesn't support jobstats"
16088         [[ $JOBID_VAR = disable ]] && skip_env "jobstats is disabled"
16089
16090         local old_jobenv=$($LCTL get_param -n jobid_var)
16091         [ $old_jobenv != $JOBENV ] && jobstats_set $JOBENV
16092
16093         if [[ $PERM_CMD == *"set_param -P"* ]]; then
16094                 stack_trap "do_facet mgs $PERM_CMD jobid_var=$old_jobenv" EXIT
16095         else
16096                 stack_trap "do_facet mgs $PERM_CMD \
16097                         $FSNAME.sys.jobid_var=$old_jobenv" EXIT
16098         fi
16099         changelog_register
16100
16101         local old_interval=$(do_facet $SINGLEMDS lctl get_param -n \
16102                                 mdt.*.job_cleanup_interval | head -n 1)
16103         local new_interval=5
16104         do_facet $SINGLEMDS \
16105                 $LCTL set_param mdt.*.job_cleanup_interval=$new_interval
16106         stack_trap "do_facet $SINGLEMDS \
16107                 $LCTL set_param mdt.*.job_cleanup_interval=$old_interval" EXIT
16108         local start=$SECONDS
16109
16110         local cmd
16111         # mkdir
16112         cmd="mkdir $DIR/$tdir"
16113         verify_jobstats "$cmd" "$SINGLEMDS"
16114         # rmdir
16115         cmd="rmdir $DIR/$tdir"
16116         verify_jobstats "$cmd" "$SINGLEMDS"
16117         # mkdir on secondary MDT
16118         if [ $MDSCOUNT -gt 1 ]; then
16119                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
16120                 verify_jobstats "$cmd" "mds2"
16121         fi
16122         # mknod
16123         cmd="mknod $DIR/$tfile c 1 3"
16124         verify_jobstats "$cmd" "$SINGLEMDS"
16125         # unlink
16126         cmd="rm -f $DIR/$tfile"
16127         verify_jobstats "$cmd" "$SINGLEMDS"
16128         # create all files on OST0000 so verify_jobstats can find OST stats
16129         # open & close
16130         cmd="$LFS setstripe -i 0 -c 1 $DIR/$tfile"
16131         verify_jobstats "$cmd" "$SINGLEMDS"
16132         # setattr
16133         cmd="touch $DIR/$tfile"
16134         verify_jobstats "$cmd" "$SINGLEMDS ost1"
16135         # write
16136         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
16137         verify_jobstats "$cmd" "ost1"
16138         # read
16139         cancel_lru_locks osc
16140         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
16141         verify_jobstats "$cmd" "ost1"
16142         # truncate
16143         cmd="$TRUNCATE $DIR/$tfile 0"
16144         verify_jobstats "$cmd" "$SINGLEMDS ost1"
16145         # rename
16146         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
16147         verify_jobstats "$cmd" "$SINGLEMDS"
16148         # jobstats expiry - sleep until old stats should be expired
16149         local left=$((new_interval + 5 - (SECONDS - start)))
16150         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
16151                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
16152                         "0" $left
16153         cmd="mkdir $DIR/$tdir.expire"
16154         verify_jobstats "$cmd" "$SINGLEMDS"
16155         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
16156             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
16157
16158         # Ensure that jobid are present in changelog (if supported by MDS)
16159         if [ $MDS1_VERSION -ge $(version_code 2.6.52) ];then
16160                 changelog_dump | tail -10
16161                 jobids=$(changelog_dump | tail -9 | grep -c "j=")
16162                 [ $jobids -eq 9 ] ||
16163                         error "Wrong changelog jobid count $jobids != 9"
16164
16165                 # LU-5862
16166                 JOBENV="disable"
16167                 jobstats_set $JOBENV
16168                 touch $DIR/$tfile
16169                 changelog_dump | grep $tfile
16170                 jobids=$(changelog_dump | grep $tfile | tail -1 | grep -c "j=")
16171                 [ $jobids -eq 0 ] ||
16172                         error "Unexpected jobids when jobid_var=$JOBENV"
16173         fi
16174
16175         lctl set_param jobid_var=USER jobid_name="S.%j.%e.%u.%h.E"
16176         JOBENV="JOBCOMPLEX"
16177         JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname).E"
16178
16179         verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
16180 }
16181 run_test 205a "Verify job stats"
16182
16183 # LU-13117
16184 test_205b() {
16185         $LCTL set_param jobid_var=USER jobid_name="%e.%u"
16186         env -i USERTESTJOBSTATS=foolish touch $DIR/$tfile.1
16187         do_facet $SINGLEMDS $LCTL get_param mdt.*.job_stats |
16188                 grep job_id: | grep foolish &&
16189                         error "Unexpected jobid found"
16190         true
16191 }
16192 run_test 205b "Verify job stats jobid parsing"
16193
16194 # LU-1480, LU-1773 and LU-1657
16195 test_206() {
16196         mkdir -p $DIR/$tdir
16197         $LFS setstripe -c -1 $DIR/$tdir
16198 #define OBD_FAIL_LOV_INIT 0x1403
16199         $LCTL set_param fail_loc=0xa0001403
16200         $LCTL set_param fail_val=1
16201         touch $DIR/$tdir/$tfile || true
16202 }
16203 run_test 206 "fail lov_init_raid0() doesn't lbug"
16204
16205 test_207a() {
16206         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
16207         local fsz=`stat -c %s $DIR/$tfile`
16208         cancel_lru_locks mdc
16209
16210         # do not return layout in getattr intent
16211 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
16212         $LCTL set_param fail_loc=0x170
16213         local sz=`stat -c %s $DIR/$tfile`
16214
16215         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
16216
16217         rm -rf $DIR/$tfile
16218 }
16219 run_test 207a "can refresh layout at glimpse"
16220
16221 test_207b() {
16222         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
16223         local cksum=`md5sum $DIR/$tfile`
16224         local fsz=`stat -c %s $DIR/$tfile`
16225         cancel_lru_locks mdc
16226         cancel_lru_locks osc
16227
16228         # do not return layout in getattr intent
16229 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
16230         $LCTL set_param fail_loc=0x171
16231
16232         # it will refresh layout after the file is opened but before read issues
16233         echo checksum is "$cksum"
16234         echo "$cksum" |md5sum -c --quiet || error "file differs"
16235
16236         rm -rf $DIR/$tfile
16237 }
16238 run_test 207b "can refresh layout at open"
16239
16240 test_208() {
16241         # FIXME: in this test suite, only RD lease is used. This is okay
16242         # for now as only exclusive open is supported. After generic lease
16243         # is done, this test suite should be revised. - Jinshan
16244
16245         remote_mds_nodsh && skip "remote MDS with nodsh"
16246         [[ $MDS1_VERSION -ge $(version_code 2.4.52) ]] ||
16247                 skip "Need MDS version at least 2.4.52"
16248
16249         echo "==== test 1: verify get lease work"
16250         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
16251
16252         echo "==== test 2: verify lease can be broken by upcoming open"
16253         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
16254         local PID=$!
16255         sleep 1
16256
16257         $MULTIOP $DIR/$tfile oO_RDONLY:c
16258         kill -USR1 $PID && wait $PID || error "break lease error"
16259
16260         echo "==== test 3: verify lease can't be granted if an open already exists"
16261         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
16262         local PID=$!
16263         sleep 1
16264
16265         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
16266         kill -USR1 $PID && wait $PID || error "open file error"
16267
16268         echo "==== test 4: lease can sustain over recovery"
16269         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
16270         PID=$!
16271         sleep 1
16272
16273         fail mds1
16274
16275         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
16276
16277         echo "==== test 5: lease broken can't be regained by replay"
16278         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
16279         PID=$!
16280         sleep 1
16281
16282         # open file to break lease and then recovery
16283         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
16284         fail mds1
16285
16286         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
16287
16288         rm -f $DIR/$tfile
16289 }
16290 run_test 208 "Exclusive open"
16291
16292 test_209() {
16293         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
16294                 skip_env "must have disp_stripe"
16295
16296         touch $DIR/$tfile
16297         sync; sleep 5; sync;
16298
16299         echo 3 > /proc/sys/vm/drop_caches
16300         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
16301
16302         # open/close 500 times
16303         for i in $(seq 500); do
16304                 cat $DIR/$tfile
16305         done
16306
16307         echo 3 > /proc/sys/vm/drop_caches
16308         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
16309
16310         echo "before: $req_before, after: $req_after"
16311         [ $((req_after - req_before)) -ge 300 ] &&
16312                 error "open/close requests are not freed"
16313         return 0
16314 }
16315 run_test 209 "read-only open/close requests should be freed promptly"
16316
16317 test_212() {
16318         size=`date +%s`
16319         size=$((size % 8192 + 1))
16320         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
16321         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
16322         rm -f $DIR/f212 $DIR/f212.xyz
16323 }
16324 run_test 212 "Sendfile test ============================================"
16325
16326 test_213() {
16327         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
16328         cancel_lru_locks osc
16329         lctl set_param fail_loc=0x8000040f
16330         # generate a read lock
16331         cat $DIR/$tfile > /dev/null
16332         # write to the file, it will try to cancel the above read lock.
16333         cat /etc/hosts >> $DIR/$tfile
16334 }
16335 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
16336
16337 test_214() { # for bug 20133
16338         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
16339         for (( i=0; i < 340; i++ )) ; do
16340                 touch $DIR/$tdir/d214c/a$i
16341         done
16342
16343         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
16344         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
16345         ls $DIR/d214c || error "ls $DIR/d214c failed"
16346         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
16347         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
16348 }
16349 run_test 214 "hash-indexed directory test - bug 20133"
16350
16351 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
16352 create_lnet_proc_files() {
16353         lctl get_param -n $1 >$TMP/lnet_$1.sys || error "cannot read lnet.$1"
16354 }
16355
16356 # counterpart of create_lnet_proc_files
16357 remove_lnet_proc_files() {
16358         rm -f $TMP/lnet_$1.sys
16359 }
16360
16361 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
16362 # 3rd arg as regexp for body
16363 check_lnet_proc_stats() {
16364         local l=$(cat "$TMP/lnet_$1" |wc -l)
16365         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
16366
16367         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
16368 }
16369
16370 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
16371 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
16372 # optional and can be regexp for 2nd line (lnet.routes case)
16373 check_lnet_proc_entry() {
16374         local blp=2          # blp stands for 'position of 1st line of body'
16375         [ -z "$5" ] || blp=3 # lnet.routes case
16376
16377         local l=$(cat "$TMP/lnet_$1" |wc -l)
16378         # subtracting one from $blp because the body can be empty
16379         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
16380
16381         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
16382                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
16383
16384         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
16385                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
16386
16387         # bail out if any unexpected line happened
16388         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
16389         [ "$?" != 0 ] || error "$2 misformatted"
16390 }
16391
16392 test_215() { # for bugs 18102, 21079, 21517
16393         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16394
16395         local N='(0|[1-9][0-9]*)'       # non-negative numeric
16396         local P='[1-9][0-9]*'           # positive numeric
16397         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
16398         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
16399         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
16400         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
16401
16402         local L1 # regexp for 1st line
16403         local L2 # regexp for 2nd line (optional)
16404         local BR # regexp for the rest (body)
16405
16406         # lnet.stats should look as 11 space-separated non-negative numerics
16407         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
16408         create_lnet_proc_files "stats"
16409         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
16410         remove_lnet_proc_files "stats"
16411
16412         # lnet.routes should look like this:
16413         # Routing disabled/enabled
16414         # net hops priority state router
16415         # where net is a string like tcp0, hops > 0, priority >= 0,
16416         # state is up/down,
16417         # router is a string like 192.168.1.1@tcp2
16418         L1="^Routing (disabled|enabled)$"
16419         L2="^net +hops +priority +state +router$"
16420         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
16421         create_lnet_proc_files "routes"
16422         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
16423         remove_lnet_proc_files "routes"
16424
16425         # lnet.routers should look like this:
16426         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
16427         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
16428         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
16429         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
16430         L1="^ref +rtr_ref +alive +router$"
16431         BR="^$P +$P +(up|down) +$NID$"
16432         create_lnet_proc_files "routers"
16433         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
16434         remove_lnet_proc_files "routers"
16435
16436         # lnet.peers should look like this:
16437         # nid refs state last max rtr min tx min queue
16438         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
16439         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
16440         # numeric (0 or >0 or <0), queue >= 0.
16441         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
16442         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
16443         create_lnet_proc_files "peers"
16444         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
16445         remove_lnet_proc_files "peers"
16446
16447         # lnet.buffers  should look like this:
16448         # pages count credits min
16449         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
16450         L1="^pages +count +credits +min$"
16451         BR="^ +$N +$N +$I +$I$"
16452         create_lnet_proc_files "buffers"
16453         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
16454         remove_lnet_proc_files "buffers"
16455
16456         # lnet.nis should look like this:
16457         # nid status alive refs peer rtr max tx min
16458         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
16459         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
16460         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
16461         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
16462         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
16463         create_lnet_proc_files "nis"
16464         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
16465         remove_lnet_proc_files "nis"
16466
16467         # can we successfully write to lnet.stats?
16468         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
16469 }
16470 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
16471
16472 test_216() { # bug 20317
16473         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16474         remote_ost_nodsh && skip "remote OST with nodsh"
16475
16476         local node
16477         local facets=$(get_facets OST)
16478         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
16479
16480         save_lustre_params client "osc.*.contention_seconds" > $p
16481         save_lustre_params $facets \
16482                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
16483         save_lustre_params $facets \
16484                 "ldlm.namespaces.filter-*.contended_locks" >> $p
16485         save_lustre_params $facets \
16486                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
16487         clear_stats osc.*.osc_stats
16488
16489         # agressive lockless i/o settings
16490         do_nodes $(comma_list $(osts_nodes)) \
16491                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
16492                         ldlm.namespaces.filter-*.contended_locks=0 \
16493                         ldlm.namespaces.filter-*.contention_seconds=60"
16494         lctl set_param -n osc.*.contention_seconds=60
16495
16496         $DIRECTIO write $DIR/$tfile 0 10 4096
16497         $CHECKSTAT -s 40960 $DIR/$tfile
16498
16499         # disable lockless i/o
16500         do_nodes $(comma_list $(osts_nodes)) \
16501                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
16502                         ldlm.namespaces.filter-*.contended_locks=32 \
16503                         ldlm.namespaces.filter-*.contention_seconds=0"
16504         lctl set_param -n osc.*.contention_seconds=0
16505         clear_stats osc.*.osc_stats
16506
16507         dd if=/dev/zero of=$DIR/$tfile count=0
16508         $CHECKSTAT -s 0 $DIR/$tfile
16509
16510         restore_lustre_params <$p
16511         rm -f $p
16512         rm $DIR/$tfile
16513 }
16514 run_test 216 "check lockless direct write updates file size and kms correctly"
16515
16516 test_217() { # bug 22430
16517         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16518
16519         local node
16520         local nid
16521
16522         for node in $(nodes_list); do
16523                 nid=$(host_nids_address $node $NETTYPE)
16524                 if [[ $nid = *-* ]] ; then
16525                         echo "lctl ping $(h2nettype $nid)"
16526                         lctl ping $(h2nettype $nid)
16527                 else
16528                         echo "skipping $node (no hyphen detected)"
16529                 fi
16530         done
16531 }
16532 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
16533
16534 test_218() {
16535        # do directio so as not to populate the page cache
16536        log "creating a 10 Mb file"
16537        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
16538        log "starting reads"
16539        dd if=$DIR/$tfile of=/dev/null bs=4096 &
16540        log "truncating the file"
16541        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
16542        log "killing dd"
16543        kill %+ || true # reads might have finished
16544        echo "wait until dd is finished"
16545        wait
16546        log "removing the temporary file"
16547        rm -rf $DIR/$tfile || error "tmp file removal failed"
16548 }
16549 run_test 218 "parallel read and truncate should not deadlock"
16550
16551 test_219() {
16552         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16553
16554         # write one partial page
16555         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
16556         # set no grant so vvp_io_commit_write will do sync write
16557         $LCTL set_param fail_loc=0x411
16558         # write a full page at the end of file
16559         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
16560
16561         $LCTL set_param fail_loc=0
16562         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
16563         $LCTL set_param fail_loc=0x411
16564         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
16565
16566         # LU-4201
16567         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
16568         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
16569 }
16570 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
16571
16572 test_220() { #LU-325
16573         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16574         remote_ost_nodsh && skip "remote OST with nodsh"
16575         remote_mds_nodsh && skip "remote MDS with nodsh"
16576         remote_mgs_nodsh && skip "remote MGS with nodsh"
16577
16578         local OSTIDX=0
16579
16580         # create on MDT0000 so the last_id and next_id are correct
16581         mkdir $DIR/$tdir
16582         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
16583         OST=${OST%_UUID}
16584
16585         # on the mdt's osc
16586         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
16587         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
16588                         osp.$mdtosc_proc1.prealloc_last_id)
16589         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
16590                         osp.$mdtosc_proc1.prealloc_next_id)
16591
16592         $LFS df -i
16593
16594         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
16595         #define OBD_FAIL_OST_ENOINO              0x229
16596         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
16597         create_pool $FSNAME.$TESTNAME || return 1
16598         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
16599
16600         $LFS setstripe $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
16601
16602         MDSOBJS=$((last_id - next_id))
16603         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
16604
16605         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
16606         echo "OST still has $count kbytes free"
16607
16608         echo "create $MDSOBJS files @next_id..."
16609         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
16610
16611         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
16612                         osp.$mdtosc_proc1.prealloc_last_id)
16613         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
16614                         osp.$mdtosc_proc1.prealloc_next_id)
16615
16616         echo "after creation, last_id=$last_id2, next_id=$next_id2"
16617         $LFS df -i
16618
16619         echo "cleanup..."
16620
16621         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
16622         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
16623
16624         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST ||
16625                 error "$LCTL pool_remove $FSNAME.$TESTNAME $OST failed"
16626         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
16627                 error "$LCTL pool_destroy $FSNAME.$TESTNAME failed"
16628         echo "unlink $MDSOBJS files @$next_id..."
16629         unlinkmany $DIR/$tdir/f $MDSOBJS || error "unlinkmany failed"
16630 }
16631 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
16632
16633 test_221() {
16634         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16635
16636         dd if=`which date` of=$MOUNT/date oflag=sync
16637         chmod +x $MOUNT/date
16638
16639         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
16640         $LCTL set_param fail_loc=0x80001401
16641
16642         $MOUNT/date > /dev/null
16643         rm -f $MOUNT/date
16644 }
16645 run_test 221 "make sure fault and truncate race to not cause OOM"
16646
16647 test_222a () {
16648         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16649
16650         rm -rf $DIR/$tdir
16651         test_mkdir $DIR/$tdir
16652         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16653         createmany -o $DIR/$tdir/$tfile 10
16654         cancel_lru_locks mdc
16655         cancel_lru_locks osc
16656         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
16657         $LCTL set_param fail_loc=0x31a
16658         ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
16659         $LCTL set_param fail_loc=0
16660         rm -r $DIR/$tdir
16661 }
16662 run_test 222a "AGL for ls should not trigger CLIO lock failure"
16663
16664 test_222b () {
16665         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16666
16667         rm -rf $DIR/$tdir
16668         test_mkdir $DIR/$tdir
16669         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16670         createmany -o $DIR/$tdir/$tfile 10
16671         cancel_lru_locks mdc
16672         cancel_lru_locks osc
16673         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
16674         $LCTL set_param fail_loc=0x31a
16675         rm -r $DIR/$tdir || error "AGL for rmdir failed"
16676         $LCTL set_param fail_loc=0
16677 }
16678 run_test 222b "AGL for rmdir should not trigger CLIO lock failure"
16679
16680 test_223 () {
16681         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16682
16683         rm -rf $DIR/$tdir
16684         test_mkdir $DIR/$tdir
16685         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16686         createmany -o $DIR/$tdir/$tfile 10
16687         cancel_lru_locks mdc
16688         cancel_lru_locks osc
16689         #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
16690         $LCTL set_param fail_loc=0x31b
16691         ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
16692         $LCTL set_param fail_loc=0
16693         rm -r $DIR/$tdir
16694 }
16695 run_test 223 "osc reenqueue if without AGL lock granted ======================="
16696
16697 test_224a() { # LU-1039, MRP-303
16698         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16699
16700         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
16701         $LCTL set_param fail_loc=0x508
16702         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
16703         $LCTL set_param fail_loc=0
16704         df $DIR
16705 }
16706 run_test 224a "Don't panic on bulk IO failure"
16707
16708 test_224b() { # LU-1039, MRP-303
16709         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16710
16711         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
16712         cancel_lru_locks osc
16713         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
16714         $LCTL set_param fail_loc=0x515
16715         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
16716         $LCTL set_param fail_loc=0
16717         df $DIR
16718 }
16719 run_test 224b "Don't panic on bulk IO failure"
16720
16721 test_224c() { # LU-6441
16722         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16723         remote_mds_nodsh && skip "remote MDS with nodsh"
16724
16725         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
16726         save_writethrough $p
16727         set_cache writethrough on
16728
16729         local pages_per_rpc=$($LCTL get_param osc.*.max_pages_per_rpc)
16730         local at_max=$($LCTL get_param -n at_max)
16731         local timeout=$($LCTL get_param -n timeout)
16732         local test_at="at_max"
16733         local param_at="$FSNAME.sys.at_max"
16734         local test_timeout="timeout"
16735         local param_timeout="$FSNAME.sys.timeout"
16736
16737         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
16738
16739         set_persistent_param_and_check client "$test_at" "$param_at" 0
16740         set_persistent_param_and_check client "$test_timeout" "$param_timeout" 5
16741
16742         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3 0x520
16743         do_facet ost1 "$LCTL set_param fail_loc=0x520"
16744         $LFS setstripe -c 1 -i 0 $DIR/$tfile
16745         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
16746         sync
16747         do_facet ost1 "$LCTL set_param fail_loc=0"
16748
16749         set_persistent_param_and_check client "$test_at" "$param_at" $at_max
16750         set_persistent_param_and_check client "$test_timeout" "$param_timeout" \
16751                 $timeout
16752
16753         $LCTL set_param -n $pages_per_rpc
16754         restore_lustre_params < $p
16755         rm -f $p
16756 }
16757 run_test 224c "Don't hang if one of md lost during large bulk RPC"
16758
16759 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
16760 test_225a () {
16761         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16762         if [ -z ${MDSSURVEY} ]; then
16763                 skip_env "mds-survey not found"
16764         fi
16765         [ $MDS1_VERSION -ge $(version_code 2.2.51) ] ||
16766                 skip "Need MDS version at least 2.2.51"
16767
16768         local mds=$(facet_host $SINGLEMDS)
16769         local target=$(do_nodes $mds 'lctl dl' |
16770                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
16771
16772         local cmd1="file_count=1000 thrhi=4"
16773         local cmd2="dir_count=2 layer=mdd stripe_count=0"
16774         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
16775         local cmd="$cmd1 $cmd2 $cmd3"
16776
16777         rm -f ${TMP}/mds_survey*
16778         echo + $cmd
16779         eval $cmd || error "mds-survey with zero-stripe failed"
16780         cat ${TMP}/mds_survey*
16781         rm -f ${TMP}/mds_survey*
16782 }
16783 run_test 225a "Metadata survey sanity with zero-stripe"
16784
16785 test_225b () {
16786         if [ -z ${MDSSURVEY} ]; then
16787                 skip_env "mds-survey not found"
16788         fi
16789         [ $MDS1_VERSION -ge $(version_code 2.2.51) ] ||
16790                 skip "Need MDS version at least 2.2.51"
16791         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16792         remote_mds_nodsh && skip "remote MDS with nodsh"
16793         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
16794                 skip_env "Need to mount OST to test"
16795         fi
16796
16797         local mds=$(facet_host $SINGLEMDS)
16798         local target=$(do_nodes $mds 'lctl dl' |
16799                        awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
16800
16801         local cmd1="file_count=1000 thrhi=4"
16802         local cmd2="dir_count=2 layer=mdd stripe_count=1"
16803         local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
16804         local cmd="$cmd1 $cmd2 $cmd3"
16805
16806         rm -f ${TMP}/mds_survey*
16807         echo + $cmd
16808         eval $cmd || error "mds-survey with stripe_count failed"
16809         cat ${TMP}/mds_survey*
16810         rm -f ${TMP}/mds_survey*
16811 }
16812 run_test 225b "Metadata survey sanity with stripe_count = 1"
16813
16814 mcreate_path2fid () {
16815         local mode=$1
16816         local major=$2
16817         local minor=$3
16818         local name=$4
16819         local desc=$5
16820         local path=$DIR/$tdir/$name
16821         local fid
16822         local rc
16823         local fid_path
16824
16825         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
16826                 error "cannot create $desc"
16827
16828         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
16829         rc=$?
16830         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
16831
16832         fid_path=$($LFS fid2path $MOUNT $fid)
16833         rc=$?
16834         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
16835
16836         [ "$path" == "$fid_path" ] ||
16837                 error "fid2path returned $fid_path, expected $path"
16838
16839         echo "pass with $path and $fid"
16840 }
16841
16842 test_226a () {
16843         rm -rf $DIR/$tdir
16844         mkdir -p $DIR/$tdir
16845
16846         mcreate_path2fid 0010666 0 0 fifo "FIFO"
16847         mcreate_path2fid 0020666 1 3 null "character special file (null)"
16848         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
16849         mcreate_path2fid 0040666 0 0 dir "directory"
16850         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
16851         mcreate_path2fid 0100666 0 0 file "regular file"
16852         mcreate_path2fid 0120666 0 0 link "symbolic link"
16853         mcreate_path2fid 0140666 0 0 sock "socket"
16854 }
16855 run_test 226a "call path2fid and fid2path on files of all type"
16856
16857 test_226b () {
16858         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
16859
16860         local MDTIDX=1
16861
16862         rm -rf $DIR/$tdir
16863         mkdir -p $DIR/$tdir
16864         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
16865                 error "create remote directory failed"
16866         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
16867         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
16868                                 "character special file (null)"
16869         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
16870                                 "character special file (no device)"
16871         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
16872         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
16873                                 "block special file (loop)"
16874         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
16875         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
16876         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
16877 }
16878 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
16879
16880 # LU-1299 Executing or running ldd on a truncated executable does not
16881 # cause an out-of-memory condition.
16882 test_227() {
16883         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16884         [ -z "$(which ldd)" ] && skip_env "should have ldd tool"
16885
16886         dd if=$(which date) of=$MOUNT/date bs=1k count=1
16887         chmod +x $MOUNT/date
16888
16889         $MOUNT/date > /dev/null
16890         ldd $MOUNT/date > /dev/null
16891         rm -f $MOUNT/date
16892 }
16893 run_test 227 "running truncated executable does not cause OOM"
16894
16895 # LU-1512 try to reuse idle OI blocks
16896 test_228a() {
16897         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16898         remote_mds_nodsh && skip "remote MDS with nodsh"
16899         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
16900
16901         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
16902         local myDIR=$DIR/$tdir
16903
16904         mkdir -p $myDIR
16905         #define OBD_FAIL_SEQ_EXHAUST             0x1002
16906         $LCTL set_param fail_loc=0x80001002
16907         createmany -o $myDIR/t- 10000
16908         $LCTL set_param fail_loc=0
16909         # The guard is current the largest FID holder
16910         touch $myDIR/guard
16911         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
16912                     tr -d '[')
16913         local IDX=$(($SEQ % 64))
16914
16915         do_facet $SINGLEMDS sync
16916         # Make sure journal flushed.
16917         sleep 6
16918         local blk1=$(do_facet $SINGLEMDS \
16919                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16920                      grep Blockcount | awk '{print $4}')
16921
16922         # Remove old files, some OI blocks will become idle.
16923         unlinkmany $myDIR/t- 10000
16924         # Create new files, idle OI blocks should be reused.
16925         createmany -o $myDIR/t- 2000
16926         do_facet $SINGLEMDS sync
16927         # Make sure journal flushed.
16928         sleep 6
16929         local blk2=$(do_facet $SINGLEMDS \
16930                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16931                      grep Blockcount | awk '{print $4}')
16932
16933         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
16934 }
16935 run_test 228a "try to reuse idle OI blocks"
16936
16937 test_228b() {
16938         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16939         remote_mds_nodsh && skip "remote MDS with nodsh"
16940         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
16941
16942         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
16943         local myDIR=$DIR/$tdir
16944
16945         mkdir -p $myDIR
16946         #define OBD_FAIL_SEQ_EXHAUST             0x1002
16947         $LCTL set_param fail_loc=0x80001002
16948         createmany -o $myDIR/t- 10000
16949         $LCTL set_param fail_loc=0
16950         # The guard is current the largest FID holder
16951         touch $myDIR/guard
16952         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
16953                     tr -d '[')
16954         local IDX=$(($SEQ % 64))
16955
16956         do_facet $SINGLEMDS sync
16957         # Make sure journal flushed.
16958         sleep 6
16959         local blk1=$(do_facet $SINGLEMDS \
16960                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16961                      grep Blockcount | awk '{print $4}')
16962
16963         # Remove old files, some OI blocks will become idle.
16964         unlinkmany $myDIR/t- 10000
16965
16966         # stop the MDT
16967         stop $SINGLEMDS || error "Fail to stop MDT."
16968         # remount the MDT
16969         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
16970
16971         df $MOUNT || error "Fail to df."
16972         # Create new files, idle OI blocks should be reused.
16973         createmany -o $myDIR/t- 2000
16974         do_facet $SINGLEMDS sync
16975         # Make sure journal flushed.
16976         sleep 6
16977         local blk2=$(do_facet $SINGLEMDS \
16978                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
16979                      grep Blockcount | awk '{print $4}')
16980
16981         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
16982 }
16983 run_test 228b "idle OI blocks can be reused after MDT restart"
16984
16985 #LU-1881
16986 test_228c() {
16987         [ $PARALLEL == "yes" ] && skip "skip parallel run"
16988         remote_mds_nodsh && skip "remote MDS with nodsh"
16989         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
16990
16991         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
16992         local myDIR=$DIR/$tdir
16993
16994         mkdir -p $myDIR
16995         #define OBD_FAIL_SEQ_EXHAUST             0x1002
16996         $LCTL set_param fail_loc=0x80001002
16997         # 20000 files can guarantee there are index nodes in the OI file
16998         createmany -o $myDIR/t- 20000
16999         $LCTL set_param fail_loc=0
17000         # The guard is current the largest FID holder
17001         touch $myDIR/guard
17002         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
17003                     tr -d '[')
17004         local IDX=$(($SEQ % 64))
17005
17006         do_facet $SINGLEMDS sync
17007         # Make sure journal flushed.
17008         sleep 6
17009         local blk1=$(do_facet $SINGLEMDS \
17010                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
17011                      grep Blockcount | awk '{print $4}')
17012
17013         # Remove old files, some OI blocks will become idle.
17014         unlinkmany $myDIR/t- 20000
17015         rm -f $myDIR/guard
17016         # The OI file should become empty now
17017
17018         # Create new files, idle OI blocks should be reused.
17019         createmany -o $myDIR/t- 2000
17020         do_facet $SINGLEMDS sync
17021         # Make sure journal flushed.
17022         sleep 6
17023         local blk2=$(do_facet $SINGLEMDS \
17024                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
17025                      grep Blockcount | awk '{print $4}')
17026
17027         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
17028 }
17029 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
17030
17031 test_229() { # LU-2482, LU-3448
17032         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17033         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
17034         [ $MDS1_VERSION -lt $(version_code 2.4.53) ] &&
17035                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53"
17036
17037         rm -f $DIR/$tfile
17038
17039         # Create a file with a released layout and stripe count 2.
17040         $MULTIOP $DIR/$tfile H2c ||
17041                 error "failed to create file with released layout"
17042
17043         $LFS getstripe -v $DIR/$tfile
17044
17045         local pattern=$($LFS getstripe -L $DIR/$tfile)
17046         [ X"$pattern" = X"released" ] || error "pattern error ($pattern)"
17047
17048         local stripe_count=$($LFS getstripe -c $DIR/$tfile) ||
17049                 error "getstripe"
17050         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
17051         stat $DIR/$tfile || error "failed to stat released file"
17052
17053         chown $RUNAS_ID $DIR/$tfile ||
17054                 error "chown $RUNAS_ID $DIR/$tfile failed"
17055
17056         chgrp $RUNAS_ID $DIR/$tfile ||
17057                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
17058
17059         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
17060         rm $DIR/$tfile || error "failed to remove released file"
17061 }
17062 run_test 229 "getstripe/stat/rm/attr changes work on released files"
17063
17064 test_230a() {
17065         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17066         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17067         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17068                 skip "Need MDS version at least 2.11.52"
17069
17070         local MDTIDX=1
17071
17072         test_mkdir $DIR/$tdir
17073         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
17074         local mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230_local)
17075         [ $mdt_idx -ne 0 ] &&
17076                 error "create local directory on wrong MDT $mdt_idx"
17077
17078         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
17079                         error "create remote directory failed"
17080         local mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230)
17081         [ $mdt_idx -ne $MDTIDX ] &&
17082                 error "create remote directory on wrong MDT $mdt_idx"
17083
17084         createmany -o $DIR/$tdir/test_230/t- 10 ||
17085                 error "create files on remote directory failed"
17086         mdt_idx=$($LFS getstripe -m $DIR/$tdir/test_230/t-0)
17087         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
17088         rm -r $DIR/$tdir || error "unlink remote directory failed"
17089 }
17090 run_test 230a "Create remote directory and files under the remote directory"
17091
17092 test_230b() {
17093         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17094         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17095         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17096                 skip "Need MDS version at least 2.11.52"
17097
17098         local MDTIDX=1
17099         local mdt_index
17100         local i
17101         local file
17102         local pid
17103         local stripe_count
17104         local migrate_dir=$DIR/$tdir/migrate_dir
17105         local other_dir=$DIR/$tdir/other_dir
17106
17107         test_mkdir $DIR/$tdir
17108         test_mkdir -i0 -c1 $migrate_dir
17109         test_mkdir -i0 -c1 $other_dir
17110         for ((i=0; i<10; i++)); do
17111                 mkdir -p $migrate_dir/dir_${i}
17112                 createmany -o $migrate_dir/dir_${i}/f 10 ||
17113                         error "create files under remote dir failed $i"
17114         done
17115
17116         cp /etc/passwd $migrate_dir/$tfile
17117         cp /etc/passwd $other_dir/$tfile
17118         chattr +SAD $migrate_dir
17119         chattr +SAD $migrate_dir/$tfile
17120
17121         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
17122         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
17123         local old_dir_mode=$(stat -c%f $migrate_dir)
17124         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
17125
17126         mkdir -p $migrate_dir/dir_default_stripe2
17127         $LFS setstripe -c 2 $migrate_dir/dir_default_stripe2
17128         $LFS setstripe -c 2 $migrate_dir/${tfile}_stripe2
17129
17130         mkdir -p $other_dir
17131         ln $migrate_dir/$tfile $other_dir/luna
17132         ln $migrate_dir/$tfile $migrate_dir/sofia
17133         ln $other_dir/$tfile $migrate_dir/david
17134         ln -s $migrate_dir/$tfile $other_dir/zachary
17135         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
17136         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
17137
17138         local len
17139         local lnktgt
17140
17141         # inline symlink
17142         for len in 58 59 60; do
17143                 lnktgt=$(str_repeat 'l' $len)
17144                 touch $migrate_dir/$lnktgt
17145                 ln -s $lnktgt $migrate_dir/${len}char_ln
17146         done
17147
17148         # PATH_MAX
17149         for len in 4094 4095; do
17150                 lnktgt=$(str_repeat 'l' $len)
17151                 ln -s $lnktgt $migrate_dir/${len}char_ln
17152         done
17153
17154         # NAME_MAX
17155         for len in 254 255; do
17156                 touch $migrate_dir/$(str_repeat 'l' $len)
17157         done
17158
17159         $LFS migrate -m $MDTIDX $migrate_dir ||
17160                 error "fails on migrating remote dir to MDT1"
17161
17162         echo "migratate to MDT1, then checking.."
17163         for ((i = 0; i < 10; i++)); do
17164                 for file in $(find $migrate_dir/dir_${i}); do
17165                         mdt_index=$($LFS getstripe -m $file)
17166                         # broken symlink getstripe will fail
17167                         [ $mdt_index -ne $MDTIDX ] && stat -L $file &&
17168                                 error "$file is not on MDT${MDTIDX}"
17169                 done
17170         done
17171
17172         # the multiple link file should still in MDT0
17173         mdt_index=$($LFS getstripe -m $migrate_dir/$tfile)
17174         [ $mdt_index == 0 ] ||
17175                 error "$file is not on MDT${MDTIDX}"
17176
17177         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
17178         [ "$old_dir_flag" = "$new_dir_flag" ] ||
17179                 error " expect $old_dir_flag get $new_dir_flag"
17180
17181         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
17182         [ "$old_file_flag" = "$new_file_flag" ] ||
17183                 error " expect $old_file_flag get $new_file_flag"
17184
17185         local new_dir_mode=$(stat -c%f $migrate_dir)
17186         [ "$old_dir_mode" = "$new_dir_mode" ] ||
17187                 error "expect mode $old_dir_mode get $new_dir_mode"
17188
17189         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
17190         [ "$old_file_mode" = "$new_file_mode" ] ||
17191                 error "expect mode $old_file_mode get $new_file_mode"
17192
17193         diff /etc/passwd $migrate_dir/$tfile ||
17194                 error "$tfile different after migration"
17195
17196         diff /etc/passwd $other_dir/luna ||
17197                 error "luna different after migration"
17198
17199         diff /etc/passwd $migrate_dir/sofia ||
17200                 error "sofia different after migration"
17201
17202         diff /etc/passwd $migrate_dir/david ||
17203                 error "david different after migration"
17204
17205         diff /etc/passwd $other_dir/zachary ||
17206                 error "zachary different after migration"
17207
17208         diff /etc/passwd $migrate_dir/${tfile}_ln ||
17209                 error "${tfile}_ln different after migration"
17210
17211         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
17212                 error "${tfile}_ln_other different after migration"
17213
17214         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
17215         [ $stripe_count = 2 ] ||
17216                 error "dir strpe_count $d != 2 after migration."
17217
17218         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
17219         [ $stripe_count = 2 ] ||
17220                 error "file strpe_count $d != 2 after migration."
17221
17222         #migrate back to MDT0
17223         MDTIDX=0
17224
17225         $LFS migrate -m $MDTIDX $migrate_dir ||
17226                 error "fails on migrating remote dir to MDT0"
17227
17228         echo "migrate back to MDT0, checking.."
17229         for file in $(find $migrate_dir); do
17230                 mdt_index=$($LFS getstripe -m $file)
17231                 [ $mdt_index -ne $MDTIDX ] && stat -L $file &&
17232                         error "$file is not on MDT${MDTIDX}"
17233         done
17234
17235         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
17236         [ "$old_dir_flag" = "$new_dir_flag" ] ||
17237                 error " expect $old_dir_flag get $new_dir_flag"
17238
17239         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
17240         [ "$old_file_flag" = "$new_file_flag" ] ||
17241                 error " expect $old_file_flag get $new_file_flag"
17242
17243         local new_dir_mode=$(stat -c%f $migrate_dir)
17244         [ "$old_dir_mode" = "$new_dir_mode" ] ||
17245                 error "expect mode $old_dir_mode get $new_dir_mode"
17246
17247         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
17248         [ "$old_file_mode" = "$new_file_mode" ] ||
17249                 error "expect mode $old_file_mode get $new_file_mode"
17250
17251         diff /etc/passwd ${migrate_dir}/$tfile ||
17252                 error "$tfile different after migration"
17253
17254         diff /etc/passwd ${other_dir}/luna ||
17255                 error "luna different after migration"
17256
17257         diff /etc/passwd ${migrate_dir}/sofia ||
17258                 error "sofia different after migration"
17259
17260         diff /etc/passwd ${other_dir}/zachary ||
17261                 error "zachary different after migration"
17262
17263         diff /etc/passwd $migrate_dir/${tfile}_ln ||
17264                 error "${tfile}_ln different after migration"
17265
17266         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
17267                 error "${tfile}_ln_other different after migration"
17268
17269         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
17270         [ $stripe_count = 2 ] ||
17271                 error "dir strpe_count $d != 2 after migration."
17272
17273         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
17274         [ $stripe_count = 2 ] ||
17275                 error "file strpe_count $d != 2 after migration."
17276
17277         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17278 }
17279 run_test 230b "migrate directory"
17280
17281 test_230c() {
17282         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17283         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17284         remote_mds_nodsh && skip "remote MDS with nodsh"
17285         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17286                 skip "Need MDS version at least 2.11.52"
17287
17288         local MDTIDX=1
17289         local total=3
17290         local mdt_index
17291         local file
17292         local migrate_dir=$DIR/$tdir/migrate_dir
17293
17294         #If migrating directory fails in the middle, all entries of
17295         #the directory is still accessiable.
17296         test_mkdir $DIR/$tdir
17297         test_mkdir -i0 -c1 $migrate_dir
17298         test_mkdir -i1 -c1 $DIR/$tdir/remote_dir
17299         stat $migrate_dir
17300         createmany -o $migrate_dir/f $total ||
17301                 error "create files under ${migrate_dir} failed"
17302
17303         # fail after migrating top dir, and this will fail only once, so the
17304         # first sub file migration will fail (currently f3), others succeed.
17305         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
17306         do_facet mds1 lctl set_param fail_loc=0x1801
17307         local t=$(ls $migrate_dir | wc -l)
17308         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
17309                 error "migrate should fail"
17310         local u=$(ls $migrate_dir | wc -l)
17311         [ "$u" == "$t" ] || error "$u != $t during migration"
17312
17313         # add new dir/file should succeed
17314         mkdir $migrate_dir/dir ||
17315                 error "mkdir failed under migrating directory"
17316         touch $migrate_dir/file ||
17317                 error "create file failed under migrating directory"
17318
17319         # add file with existing name should fail
17320         for file in $migrate_dir/f*; do
17321                 stat $file > /dev/null || error "stat $file failed"
17322                 $OPENFILE -f O_CREAT:O_EXCL $file &&
17323                         error "open(O_CREAT|O_EXCL) $file should fail"
17324                 $MULTIOP $file m && error "create $file should fail"
17325                 touch $DIR/$tdir/remote_dir/$tfile ||
17326                         error "touch $tfile failed"
17327                 ln $DIR/$tdir/remote_dir/$tfile $file &&
17328                         error "link $file should fail"
17329                 mdt_index=$($LFS getstripe -m $file)
17330                 if [ $mdt_index == 0 ]; then
17331                         # file failed to migrate is not allowed to rename to
17332                         mv $DIR/$tdir/remote_dir/$tfile $file &&
17333                                 error "rename to $file should fail"
17334                 else
17335                         mv $DIR/$tdir/remote_dir/$tfile $file ||
17336                                 error "rename to $file failed"
17337                 fi
17338                 echo hello >> $file || error "write $file failed"
17339         done
17340
17341         # resume migration with different options should fail
17342         $LFS migrate -m 0 $migrate_dir &&
17343                 error "migrate -m 0 $migrate_dir should fail"
17344
17345         $LFS migrate -m $MDTIDX -c 2 $migrate_dir &&
17346                 error "migrate -c 2 $migrate_dir should fail"
17347
17348         # resume migration should succeed
17349         $LFS migrate -m $MDTIDX $migrate_dir ||
17350                 error "migrate $migrate_dir failed"
17351
17352         echo "Finish migration, then checking.."
17353         for file in $(find $migrate_dir); do
17354                 mdt_index=$($LFS getstripe -m $file)
17355                 [ $mdt_index == $MDTIDX ] ||
17356                         error "$file is not on MDT${MDTIDX}"
17357         done
17358
17359         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17360 }
17361 run_test 230c "check directory accessiblity if migration failed"
17362
17363 test_230d() {
17364         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17365         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17366         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17367                 skip "Need MDS version at least 2.11.52"
17368         # LU-11235
17369         [ "$mds1_FSTYPE" == "zfs" ] && skip "skip ZFS backend"
17370
17371         local migrate_dir=$DIR/$tdir/migrate_dir
17372         local old_index
17373         local new_index
17374         local old_count
17375         local new_count
17376         local new_hash
17377         local mdt_index
17378         local i
17379         local j
17380
17381         old_index=$((RANDOM % MDSCOUNT))
17382         old_count=$((MDSCOUNT - old_index))
17383         new_index=$((RANDOM % MDSCOUNT))
17384         new_count=$((MDSCOUNT - new_index))
17385         new_hash=1 # for all_char
17386
17387         [ $old_count -gt 1 ] && old_count=$((old_count - RANDOM % old_count))
17388         [ $new_count -gt 1 ] && new_count=$((new_count - RANDOM % new_count))
17389
17390         test_mkdir $DIR/$tdir
17391         test_mkdir -i $old_index -c $old_count $migrate_dir
17392
17393         for ((i=0; i<100; i++)); do
17394                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
17395                 createmany -o $migrate_dir/dir_${i}/f 100 ||
17396                         error "create files under remote dir failed $i"
17397         done
17398
17399         echo -n "Migrate from MDT$old_index "
17400         [ $old_count -gt 1 ] && echo -n "... MDT$((old_index + old_count - 1)) "
17401         echo -n "to MDT$new_index"
17402         [ $new_count -gt 1 ] && echo -n " ... MDT$((new_index + new_count - 1))"
17403         echo
17404
17405         echo "$LFS migrate -m$new_index -c$new_count -H $new_hash $migrate_dir"
17406         $LFS migrate -m $new_index -c $new_count -H $new_hash $migrate_dir ||
17407                 error "migrate remote dir error"
17408
17409         echo "Finish migration, then checking.."
17410         for file in $(find $migrate_dir); do
17411                 mdt_index=$($LFS getstripe -m $file)
17412                 if [ $mdt_index -lt $new_index ] ||
17413                    [ $mdt_index -gt $((new_index + new_count - 1)) ]; then
17414                         error "$file is on MDT$mdt_index"
17415                 fi
17416         done
17417
17418         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17419 }
17420 run_test 230d "check migrate big directory"
17421
17422 test_230e() {
17423         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17424         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17425         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17426                 skip "Need MDS version at least 2.11.52"
17427
17428         local i
17429         local j
17430         local a_fid
17431         local b_fid
17432
17433         mkdir -p $DIR/$tdir
17434         mkdir $DIR/$tdir/migrate_dir
17435         mkdir $DIR/$tdir/other_dir
17436         touch $DIR/$tdir/migrate_dir/a
17437         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
17438         ls $DIR/$tdir/other_dir
17439
17440         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
17441                 error "migrate dir fails"
17442
17443         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
17444         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
17445
17446         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17447         [ $mdt_index == 0 ] || error "a is not on MDT0"
17448
17449         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
17450                 error "migrate dir fails"
17451
17452         mdt_index=$($LFS getstripe -m $DIR/$tdir/other_dir)
17453         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
17454
17455         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17456         [ $mdt_index == 1 ] || error "a is not on MDT1"
17457
17458         mdt_index=$($LFS getstripe -m $DIR/$tdir/other_dir/b)
17459         [ $mdt_index == 1 ] || error "b is not on MDT1"
17460
17461         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
17462         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
17463
17464         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
17465
17466         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17467 }
17468 run_test 230e "migrate mulitple local link files"
17469
17470 test_230f() {
17471         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17472         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17473         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17474                 skip "Need MDS version at least 2.11.52"
17475
17476         local a_fid
17477         local ln_fid
17478
17479         mkdir -p $DIR/$tdir
17480         mkdir $DIR/$tdir/migrate_dir
17481         $LFS mkdir -i1 $DIR/$tdir/other_dir
17482         touch $DIR/$tdir/migrate_dir/a
17483         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
17484         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
17485         ls $DIR/$tdir/other_dir
17486
17487         # a should be migrated to MDT1, since no other links on MDT0
17488         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
17489                 error "#1 migrate dir fails"
17490         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir)
17491         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
17492         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17493         [ $mdt_index == 1 ] || error "a is not on MDT1"
17494
17495         # a should stay on MDT1, because it is a mulitple link file
17496         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
17497                 error "#2 migrate dir fails"
17498         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17499         [ $mdt_index == 1 ] || error "a is not on MDT1"
17500
17501         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
17502                 error "#3 migrate dir fails"
17503
17504         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
17505         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
17506         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
17507
17508         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
17509         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
17510
17511         # a should be migrated to MDT0, since no other links on MDT1
17512         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
17513                 error "#4 migrate dir fails"
17514         mdt_index=$($LFS getstripe -m $DIR/$tdir/migrate_dir/a)
17515         [ $mdt_index == 0 ] || error "a is not on MDT0"
17516
17517         rm -rf $DIR/$tdir || error "rm dir failed after migration"
17518 }
17519 run_test 230f "migrate mulitple remote link files"
17520
17521 test_230g() {
17522         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17523         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17524         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17525                 skip "Need MDS version at least 2.11.52"
17526
17527         mkdir -p $DIR/$tdir/migrate_dir
17528
17529         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
17530                 error "migrating dir to non-exist MDT succeeds"
17531         true
17532 }
17533 run_test 230g "migrate dir to non-exist MDT"
17534
17535 test_230h() {
17536         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17537         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17538         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17539                 skip "Need MDS version at least 2.11.52"
17540
17541         local mdt_index
17542
17543         mkdir -p $DIR/$tdir/migrate_dir
17544
17545         $LFS migrate -m1 $DIR &&
17546                 error "migrating mountpoint1 should fail"
17547
17548         $LFS migrate -m1 $DIR/$tdir/.. &&
17549                 error "migrating mountpoint2 should fail"
17550
17551         # same as mv
17552         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. &&
17553                 error "migrating $tdir/migrate_dir/.. should fail"
17554
17555         true
17556 }
17557 run_test 230h "migrate .. and root"
17558
17559 test_230i() {
17560         [ $PARALLEL == "yes" ] && skip "skip parallel run"
17561         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17562         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17563                 skip "Need MDS version at least 2.11.52"
17564
17565         mkdir -p $DIR/$tdir/migrate_dir
17566
17567         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
17568                 error "migration fails with a tailing slash"
17569
17570         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
17571                 error "migration fails with two tailing slashes"
17572 }
17573 run_test 230i "lfs migrate -m tolerates trailing slashes"
17574
17575 test_230j() {
17576         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17577         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
17578                 skip "Need MDS version at least 2.11.52"
17579
17580         $LFS mkdir -m 0 -c 1 $DIR/$tdir || error "mkdir $tdir failed"
17581         $LFS setstripe -E 1M -L mdt $DIR/$tdir/$tfile ||
17582                 error "create $tfile failed"
17583         cat /etc/passwd > $DIR/$tdir/$tfile
17584
17585         $LFS migrate -m 1 $DIR/$tdir
17586
17587         cmp /etc/passwd $DIR/$tdir/$tfile ||
17588                 error "DoM file mismatch after migration"
17589 }
17590 run_test 230j "DoM file data not changed after dir migration"
17591
17592 test_230k() {
17593         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs"
17594         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
17595                 skip "Need MDS version at least 2.11.56"
17596
17597         local total=20
17598         local files_on_starting_mdt=0
17599
17600         $LFS mkdir -i -1 -c 2 $DIR/$tdir || error "mkdir failed"
17601         $LFS getdirstripe $DIR/$tdir
17602         for i in $(seq $total); do
17603                 echo $((i*i - i)) > $DIR/$tdir/$tfile.$i || error "write failed"
17604                 [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 0 ]] &&
17605                         files_on_starting_mdt=$((files_on_starting_mdt + 1))
17606         done
17607
17608         echo "$files_on_starting_mdt files on MDT0"
17609
17610         $LFS migrate -m 1,3 $DIR/$tdir || error "migrate -m 1,3 failed"
17611         $LFS getdirstripe $DIR/$tdir
17612
17613         files_on_starting_mdt=0
17614         for i in $(seq $total); do
17615                 $(echo $((i*i - i)) | cmp $DIR/$tdir/$tfile.$i -) ||
17616                         error "file $tfile.$i mismatch after migration"
17617                 [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 1 ]] &&
17618                         files_on_starting_mdt=$((files_on_starting_mdt + 1))
17619         done
17620
17621         echo "$files_on_starting_mdt files on MDT1 after migration"
17622         [[ $files_on_starting_mdt -eq $total ]] && error "all files on MDT1"
17623
17624         $LFS migrate -m 0 -c 2 $DIR/$tdir || error "migrate -m 0 -c 2 failed"
17625         $LFS getdirstripe $DIR/$tdir
17626
17627         files_on_starting_mdt=0
17628         for i in $(seq $total); do
17629                 $(echo $((i*i - i)) | cmp $DIR/$tdir/$tfile.$i -) ||
17630                         error "file $tfile.$i mismatch after 2nd migration"
17631                 [[ $($LFS getstripe -m $DIR/$tdir/$tfile.$i) -eq 0 ]] &&
17632                         files_on_starting_mdt=$((files_on_starting_mdt + 1))
17633         done
17634
17635         echo "$files_on_starting_mdt files on MDT0 after 2nd migration"
17636         [[ $files_on_starting_mdt -eq $total ]] && error "all files on MDT0"
17637
17638         true
17639 }
17640 run_test 230k "file data not changed after dir migration"
17641
17642 test_230l() {
17643         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17644         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
17645                 skip "Need MDS version at least 2.11.56"
17646
17647         $LFS mkdir -i 0 -c 1 $DIR/$tdir || error "mkdir failed"
17648         createmany -o $DIR/$tdir/f___________________________________ 1000 ||
17649                 error "create files under remote dir failed $i"
17650         $LFS migrate -m 1 $DIR/$tdir || error "migrate failed"
17651 }
17652 run_test 230l "readdir between MDTs won't crash"
17653
17654 test_230m() {
17655         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17656         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
17657                 skip "Need MDS version at least 2.11.56"
17658
17659         local MDTIDX=1
17660         local mig_dir=$DIR/$tdir/migrate_dir
17661         local longstr="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
17662         local shortstr="b"
17663         local val
17664
17665         echo "Creating files and dirs with xattrs"
17666         test_mkdir $DIR/$tdir
17667         test_mkdir -i0 -c1 $mig_dir
17668         mkdir $mig_dir/dir
17669         setfattr -n user.attr1 -v $longstr $mig_dir/dir ||
17670                 error "cannot set xattr attr1 on dir"
17671         setfattr -n user.attr2 -v $shortstr $mig_dir/dir ||
17672                 error "cannot set xattr attr2 on dir"
17673         touch $mig_dir/dir/f0
17674         setfattr -n user.attr1 -v $longstr $mig_dir/dir/f0 ||
17675                 error "cannot set xattr attr1 on file"
17676         setfattr -n user.attr2 -v $shortstr $mig_dir/dir/f0 ||
17677                 error "cannot set xattr attr2 on file"
17678         sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
17679         val=$(getfattr --only-values -n user.attr1 $mig_dir/dir 2>/dev/null)
17680         [ "$val" = $longstr ] || error "xattr attr1 not set properly on dir"
17681         val=$(getfattr --only-values -n user.attr2 $mig_dir/dir 2>/dev/null)
17682         [ "$val" = $shortstr ] || error "xattr attr2 not set properly on dir"
17683         val=$(getfattr --only-values -n user.attr1 $mig_dir/dir/f0 2>/dev/null)
17684         [ "$val" = $longstr ] || error "xattr attr1 not set properly on file"
17685         val=$(getfattr --only-values -n user.attr2 $mig_dir/dir/f0 2>/dev/null)
17686         [ "$val" = $shortstr ] || error "xattr attr2 not set properly on file"
17687
17688         echo "Migrating to MDT1"
17689         $LFS migrate -m $MDTIDX $mig_dir ||
17690                 error "fails on migrating dir to MDT1"
17691
17692         sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
17693         echo "Checking xattrs"
17694         val=$(getfattr --only-values -n user.attr1 $mig_dir/dir 2>/dev/null)
17695         [ "$val" = $longstr ] ||
17696                 error "expecting xattr1 $longstr on dir, found $val"
17697         val=$(getfattr --only-values -n user.attr2 $mig_dir/dir 2>/dev/null)
17698         [ "$val" = $shortstr ] ||
17699                 error "expecting xattr2 $shortstr on dir, found $val"
17700         val=$(getfattr --only-values -n user.attr1 $mig_dir/dir/f0 2>/dev/null)
17701         [ "$val" = $longstr ] ||
17702                 error "expecting xattr1 $longstr on file, found $val"
17703         val=$(getfattr --only-values -n user.attr2 $mig_dir/dir/f0 2>/dev/null)
17704         [ "$val" = $shortstr ] ||
17705                 error "expecting xattr2 $shortstr on file, found $val"
17706 }
17707 run_test 230m "xattrs not changed after dir migration"
17708
17709 test_230n() {
17710         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
17711         [[ $MDS1_VERSION -ge $(version_code 2.13.53) ]] ||
17712                 skip "Need MDS version at least 2.13.53"
17713
17714         $LFS mkdir -i 0 $DIR/$tdir || error "mkdir $tdir failed"
17715         cat /etc/hosts > $DIR/$tdir/$tfile
17716         $LFS mirror extend -N1 $DIR/$tdir/$tfile || error "Mirroring failed"
17717         $LFS migrate -m 1 $DIR/$tdir || error "Migration failed"
17718
17719         cmp /etc/hosts $DIR/$tdir/$tfile ||
17720                 error "File data mismatch after migration"
17721 }
17722 run_test 230n "Dir migration with mirrored file"
17723
17724 test_231a()
17725 {
17726         # For simplicity this test assumes that max_pages_per_rpc
17727         # is the same across all OSCs
17728         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
17729         local bulk_size=$((max_pages * PAGE_SIZE))
17730         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
17731                                        head -n 1)
17732
17733         mkdir -p $DIR/$tdir
17734         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
17735                 error "failed to set stripe with -S ${brw_size}M option"
17736
17737         # clear the OSC stats
17738         $LCTL set_param osc.*.stats=0 &>/dev/null
17739         stop_writeback
17740
17741         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
17742         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
17743                 oflag=direct &>/dev/null || error "dd failed"
17744
17745         sync; sleep 1; sync # just to be safe
17746         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
17747         if [ x$nrpcs != "x1" ]; then
17748                 $LCTL get_param osc.*.stats
17749                 error "found $nrpcs ost_write RPCs, not 1 as expected"
17750         fi
17751
17752         start_writeback
17753         # Drop the OSC cache, otherwise we will read from it
17754         cancel_lru_locks osc
17755
17756         # clear the OSC stats
17757         $LCTL set_param osc.*.stats=0 &>/dev/null
17758
17759         # Client reads $bulk_size.
17760         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
17761                 iflag=direct &>/dev/null || error "dd failed"
17762
17763         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
17764         if [ x$nrpcs != "x1" ]; then
17765                 $LCTL get_param osc.*.stats
17766                 error "found $nrpcs ost_read RPCs, not 1 as expected"
17767         fi
17768 }
17769 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
17770
17771 test_231b() {
17772         mkdir -p $DIR/$tdir
17773         local i
17774         for i in {0..1023}; do
17775                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
17776                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
17777                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
17778         done
17779         sync
17780 }
17781 run_test 231b "must not assert on fully utilized OST request buffer"
17782
17783 test_232a() {
17784         mkdir -p $DIR/$tdir
17785         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
17786
17787         #define OBD_FAIL_LDLM_OST_LVB            0x31c
17788         do_facet ost1 $LCTL set_param fail_loc=0x31c
17789
17790         # ignore dd failure
17791         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
17792
17793         do_facet ost1 $LCTL set_param fail_loc=0
17794         umount_client $MOUNT || error "umount failed"
17795         mount_client $MOUNT || error "mount failed"
17796         stop ost1 || error "cannot stop ost1"
17797         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
17798 }
17799 run_test 232a "failed lock should not block umount"
17800
17801 test_232b() {
17802         [ $MDS1_VERSION -ge $(version_code 2.10.58) ] ||
17803                 skip "Need MDS version at least 2.10.58"
17804
17805         mkdir -p $DIR/$tdir
17806         $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
17807         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1
17808         sync
17809         cancel_lru_locks osc
17810
17811         #define OBD_FAIL_LDLM_OST_LVB            0x31c
17812         do_facet ost1 $LCTL set_param fail_loc=0x31c
17813
17814         # ignore failure
17815         $LFS data_version $DIR/$tdir/$tfile || true
17816
17817         do_facet ost1 $LCTL set_param fail_loc=0
17818         umount_client $MOUNT || error "umount failed"
17819         mount_client $MOUNT || error "mount failed"
17820         stop ost1 || error "cannot stop ost1"
17821         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
17822 }
17823 run_test 232b "failed data version lock should not block umount"
17824
17825 test_233a() {
17826         [ $MDS1_VERSION -ge $(version_code 2.3.64) ] ||
17827                 skip "Need MDS version at least 2.3.64"
17828         [ -n "$FILESET" ] && skip_env "SKIP due to FILESET set"
17829
17830         local fid=$($LFS path2fid $MOUNT)
17831
17832         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
17833                 error "cannot access $MOUNT using its FID '$fid'"
17834 }
17835 run_test 233a "checking that OBF of the FS root succeeds"
17836
17837 test_233b() {
17838         [ $MDS1_VERSION -ge $(version_code 2.5.90) ] ||
17839                 skip "Need MDS version at least 2.5.90"
17840         [ -n "$FILESET" ] && skip_env "SKIP due to FILESET set"
17841
17842         local fid=$($LFS path2fid $MOUNT/.lustre)
17843
17844         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
17845                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
17846
17847         fid=$($LFS path2fid $MOUNT/.lustre/fid)
17848         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
17849                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
17850 }
17851 run_test 233b "checking that OBF of the FS .lustre succeeds"
17852
17853 test_234() {
17854         local p="$TMP/sanityN-$TESTNAME.parameters"
17855         save_lustre_params client "llite.*.xattr_cache" > $p
17856         lctl set_param llite.*.xattr_cache 1 ||
17857                 skip_env "xattr cache is not supported"
17858
17859         mkdir -p $DIR/$tdir || error "mkdir failed"
17860         touch $DIR/$tdir/$tfile || error "touch failed"
17861         # OBD_FAIL_LLITE_XATTR_ENOMEM
17862         $LCTL set_param fail_loc=0x1405
17863         getfattr -n user.attr $DIR/$tdir/$tfile &&
17864                 error "getfattr should have failed with ENOMEM"
17865         $LCTL set_param fail_loc=0x0
17866         rm -rf $DIR/$tdir
17867
17868         restore_lustre_params < $p
17869         rm -f $p
17870 }
17871 run_test 234 "xattr cache should not crash on ENOMEM"
17872
17873 test_235() {
17874         [ $MDS1_VERSION -lt $(version_code 2.4.52) ] &&
17875                 skip "Need MDS version at least 2.4.52"
17876
17877         flock_deadlock $DIR/$tfile
17878         local RC=$?
17879         case $RC in
17880                 0)
17881                 ;;
17882                 124) error "process hangs on a deadlock"
17883                 ;;
17884                 *) error "error executing flock_deadlock $DIR/$tfile"
17885                 ;;
17886         esac
17887 }
17888 run_test 235 "LU-1715: flock deadlock detection does not work properly"
17889
17890 #LU-2935
17891 test_236() {
17892         check_swap_layouts_support
17893
17894         local ref1=/etc/passwd
17895         local ref2=/etc/group
17896         local file1=$DIR/$tdir/f1
17897         local file2=$DIR/$tdir/f2
17898
17899         test_mkdir -c1 $DIR/$tdir
17900         $LFS setstripe -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
17901         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
17902         $LFS setstripe -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
17903         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
17904         local fd=$(free_fd)
17905         local cmd="exec $fd<>$file2"
17906         eval $cmd
17907         rm $file2
17908         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
17909                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
17910         cmd="exec $fd>&-"
17911         eval $cmd
17912         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
17913
17914         #cleanup
17915         rm -rf $DIR/$tdir
17916 }
17917 run_test 236 "Layout swap on open unlinked file"
17918
17919 # LU-4659 linkea consistency
17920 test_238() {
17921         [[ $MDS1_VERSION -gt $(version_code 2.5.57) ]] ||
17922                 [[ $MDS1_VERSION -gt $(version_code 2.5.1) &&
17923                    $MDS1_VERSION -lt $(version_code 2.5.50) ]] ||
17924                 skip "Need MDS version at least 2.5.58 or 2.5.2+"
17925
17926         touch $DIR/$tfile
17927         ln $DIR/$tfile $DIR/$tfile.lnk
17928         touch $DIR/$tfile.new
17929         mv $DIR/$tfile.new $DIR/$tfile
17930         local fid1=$($LFS path2fid $DIR/$tfile)
17931         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
17932         local path1=$($LFS fid2path $FSNAME "$fid1")
17933         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
17934         local path2=$($LFS fid2path $FSNAME "$fid2")
17935         [ $tfile.lnk == $path2 ] ||
17936                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
17937         rm -f $DIR/$tfile*
17938 }
17939 run_test 238 "Verify linkea consistency"
17940
17941 test_239A() { # was test_239
17942         [ $MDS1_VERSION -lt $(version_code 2.5.60) ] &&
17943                 skip "Need MDS version at least 2.5.60"
17944
17945         local list=$(comma_list $(mdts_nodes))
17946
17947         mkdir -p $DIR/$tdir
17948         createmany -o $DIR/$tdir/f- 5000
17949         unlinkmany $DIR/$tdir/f- 5000
17950         [ $MDS1_VERSION -gt $(version_code 2.10.4) ] &&
17951                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
17952         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
17953                         osp.*MDT*.sync_in_flight" | calc_sum)
17954         [ "$changes" -eq 0 ] || error "$changes not synced"
17955 }
17956 run_test 239A "osp_sync test"
17957
17958 test_239a() { #LU-5297
17959         remote_mds_nodsh && skip "remote MDS with nodsh"
17960
17961         touch $DIR/$tfile
17962         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
17963         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
17964         chgrp $RUNAS_GID $DIR/$tfile
17965         wait_delete_completed
17966 }
17967 run_test 239a "process invalid osp sync record correctly"
17968
17969 test_239b() { #LU-5297
17970         remote_mds_nodsh && skip "remote MDS with nodsh"
17971
17972         touch $DIR/$tfile1
17973         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
17974         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
17975         chgrp $RUNAS_GID $DIR/$tfile1
17976         wait_delete_completed
17977         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
17978         touch $DIR/$tfile2
17979         chgrp $RUNAS_GID $DIR/$tfile2
17980         wait_delete_completed
17981 }
17982 run_test 239b "process osp sync record with ENOMEM error correctly"
17983
17984 test_240() {
17985         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
17986         remote_mds_nodsh && skip "remote MDS with nodsh"
17987
17988         mkdir -p $DIR/$tdir
17989
17990         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
17991                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
17992         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
17993                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
17994
17995         umount_client $MOUNT || error "umount failed"
17996         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
17997         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
17998         mount_client $MOUNT || error "failed to mount client"
17999
18000         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
18001         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
18002 }
18003 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
18004
18005 test_241_bio() {
18006         local count=$1
18007         local bsize=$2
18008
18009         for LOOP in $(seq $count); do
18010                 dd if=$DIR/$tfile of=/dev/null bs=$bsize count=1 2>/dev/null
18011                 cancel_lru_locks $OSC || true
18012         done
18013 }
18014
18015 test_241_dio() {
18016         local count=$1
18017         local bsize=$2
18018
18019         for LOOP in $(seq $1); do
18020                 dd if=$DIR/$tfile of=/dev/null bs=$bsize count=1 iflag=direct \
18021                         2>/dev/null
18022         done
18023 }
18024
18025 test_241a() { # was test_241
18026         local bsize=$PAGE_SIZE
18027
18028         (( bsize < 40960 )) && bsize=40960
18029         dd if=/dev/zero of=$DIR/$tfile count=1 bs=$bsize
18030         ls -la $DIR/$tfile
18031         cancel_lru_locks $OSC
18032         test_241_bio 1000 $bsize &
18033         PID=$!
18034         test_241_dio 1000 $bsize
18035         wait $PID
18036 }
18037 run_test 241a "bio vs dio"
18038
18039 test_241b() {
18040         local bsize=$PAGE_SIZE
18041
18042         (( bsize < 40960 )) && bsize=40960
18043         dd if=/dev/zero of=$DIR/$tfile count=1 bs=$bsize
18044         ls -la $DIR/$tfile
18045         test_241_dio 1000 $bsize &
18046         PID=$!
18047         test_241_dio 1000 $bsize
18048         wait $PID
18049 }
18050 run_test 241b "dio vs dio"
18051
18052 test_242() {
18053         remote_mds_nodsh && skip "remote MDS with nodsh"
18054
18055         mkdir -p $DIR/$tdir
18056         touch $DIR/$tdir/$tfile
18057
18058         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
18059         do_facet mds1 lctl set_param fail_loc=0x105
18060         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
18061
18062         do_facet mds1 lctl set_param fail_loc=0
18063         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
18064 }
18065 run_test 242 "mdt_readpage failure should not cause directory unreadable"
18066
18067 test_243()
18068 {
18069         test_mkdir $DIR/$tdir
18070         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
18071 }
18072 run_test 243 "various group lock tests"
18073
18074 test_244a()
18075 {
18076         test_mkdir $DIR/$tdir
18077         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
18078         sendfile_grouplock $DIR/$tdir/$tfile || \
18079                 error "sendfile+grouplock failed"
18080         rm -rf $DIR/$tdir
18081 }
18082 run_test 244a "sendfile with group lock tests"
18083
18084 test_244b()
18085 {
18086         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
18087
18088         local threads=50
18089         local size=$((1024*1024))
18090
18091         test_mkdir $DIR/$tdir
18092         for i in $(seq 1 $threads); do
18093                 local file=$DIR/$tdir/file_$((i / 10))
18094                 $MULTIOP $file OG1234w$size_$((i % 3))w$size_$((i % 4))g1234c &
18095                 local pids[$i]=$!
18096         done
18097         for i in $(seq 1 $threads); do
18098                 wait ${pids[$i]}
18099         done
18100 }
18101 run_test 244b "multi-threaded write with group lock"
18102
18103 test_245() {
18104         local flagname="multi_mod_rpcs"
18105         local connect_data_name="max_mod_rpcs"
18106         local out
18107
18108         # check if multiple modify RPCs flag is set
18109         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
18110                 grep "connect_flags:")
18111         echo "$out"
18112
18113         echo "$out" | grep -qw $flagname
18114         if [ $? -ne 0 ]; then
18115                 echo "connect flag $flagname is not set"
18116                 return
18117         fi
18118
18119         # check if multiple modify RPCs data is set
18120         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
18121         echo "$out"
18122
18123         echo "$out" | grep -qw $connect_data_name ||
18124                 error "import should have connect data $connect_data_name"
18125 }
18126 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
18127
18128 cleanup_247() {
18129         local submount=$1
18130
18131         trap 0
18132         umount_client $submount
18133         rmdir $submount
18134 }
18135
18136 test_247a() {
18137         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
18138                 grep -q subtree ||
18139                 skip_env "Fileset feature is not supported"
18140
18141         local submount=${MOUNT}_$tdir
18142
18143         mkdir $MOUNT/$tdir
18144         mkdir -p $submount || error "mkdir $submount failed"
18145         FILESET="$FILESET/$tdir" mount_client $submount ||
18146                 error "mount $submount failed"
18147         trap "cleanup_247 $submount" EXIT
18148         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
18149         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
18150                 error "read $MOUNT/$tdir/$tfile failed"
18151         cleanup_247 $submount
18152 }
18153 run_test 247a "mount subdir as fileset"
18154
18155 test_247b() {
18156         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
18157                 skip_env "Fileset feature is not supported"
18158
18159         local submount=${MOUNT}_$tdir
18160
18161         rm -rf $MOUNT/$tdir
18162         mkdir -p $submount || error "mkdir $submount failed"
18163         SKIP_FILESET=1
18164         FILESET="$FILESET/$tdir" mount_client $submount &&
18165                 error "mount $submount should fail"
18166         rmdir $submount
18167 }
18168 run_test 247b "mount subdir that dose not exist"
18169
18170 test_247c() {
18171         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
18172                 skip_env "Fileset feature is not supported"
18173
18174         local submount=${MOUNT}_$tdir
18175
18176         mkdir -p $MOUNT/$tdir/dir1
18177         mkdir -p $submount || error "mkdir $submount failed"
18178         trap "cleanup_247 $submount" EXIT
18179         FILESET="$FILESET/$tdir" mount_client $submount ||
18180                 error "mount $submount failed"
18181         local fid=$($LFS path2fid $MOUNT/)
18182         $LFS fid2path $submount $fid && error "fid2path should fail"
18183         cleanup_247 $submount
18184 }
18185 run_test 247c "running fid2path outside root"
18186
18187 test_247d() {
18188         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
18189                 skip "Fileset feature is not supported"
18190
18191         local submount=${MOUNT}_$tdir
18192
18193         mkdir -p $MOUNT/$tdir/dir1
18194         mkdir -p $submount || error "mkdir $submount failed"
18195         FILESET="$FILESET/$tdir" mount_client $submount ||
18196                 error "mount $submount failed"
18197         trap "cleanup_247 $submount" EXIT
18198         local fid=$($LFS path2fid $submount/dir1)
18199         $LFS fid2path $submount $fid || error "fid2path should succeed"
18200         cleanup_247 $submount
18201 }
18202 run_test 247d "running fid2path inside root"
18203
18204 # LU-8037
18205 test_247e() {
18206         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
18207                 grep -q subtree ||
18208                 skip "Fileset feature is not supported"
18209
18210         local submount=${MOUNT}_$tdir
18211
18212         mkdir $MOUNT/$tdir
18213         mkdir -p $submount || error "mkdir $submount failed"
18214         FILESET="$FILESET/.." mount_client $submount &&
18215                 error "mount $submount should fail"
18216         rmdir $submount
18217 }
18218 run_test 247e "mount .. as fileset"
18219
18220 test_248a() {
18221         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
18222         [ -z "$fast_read_sav" ] && skip "no fast read support"
18223
18224         # create a large file for fast read verification
18225         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
18226
18227         # make sure the file is created correctly
18228         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
18229                 { rm -f $DIR/$tfile; skip "file creation error"; }
18230
18231         echo "Test 1: verify that fast read is 4 times faster on cache read"
18232
18233         # small read with fast read enabled
18234         $LCTL set_param -n llite.*.fast_read=1
18235         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
18236                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
18237                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
18238         # small read with fast read disabled
18239         $LCTL set_param -n llite.*.fast_read=0
18240         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
18241                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
18242                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
18243
18244         # verify that fast read is 4 times faster for cache read
18245         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
18246                 error_not_in_vm "fast read was not 4 times faster: " \
18247                            "$t_fast vs $t_slow"
18248
18249         echo "Test 2: verify the performance between big and small read"
18250         $LCTL set_param -n llite.*.fast_read=1
18251
18252         # 1k non-cache read
18253         cancel_lru_locks osc
18254         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
18255                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
18256                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
18257
18258         # 1M non-cache read
18259         cancel_lru_locks osc
18260         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
18261                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
18262                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
18263
18264         # verify that big IO is not 4 times faster than small IO
18265         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
18266                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
18267
18268         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
18269         rm -f $DIR/$tfile
18270 }
18271 run_test 248a "fast read verification"
18272
18273 test_248b() {
18274         # Default short_io_bytes=16384, try both smaller and larger sizes.
18275         # Lustre O_DIRECT read and write needs to be a multiple of PAGE_SIZE.
18276         # 6017024 = 2^12*13*113 = 47008*128 = 11752*512 = 4096*1469 = 53248*113
18277         echo "bs=53248 count=113 normal buffered write"
18278         dd if=/dev/urandom of=$TMP/$tfile.0 bs=53248 count=113 ||
18279                 error "dd of initial data file failed"
18280         stack_trap "rm -f $DIR/$tfile.[0-3] $TMP/$tfile.[0-3]" EXIT
18281
18282         echo "bs=47008 count=128 oflag=dsync normal write $tfile.0"
18283         dd if=$TMP/$tfile.0 of=$DIR/$tfile.0 bs=47008 count=128 oflag=dsync ||
18284                 error "dd with sync normal writes failed"
18285         cmp $TMP/$tfile.0 $DIR/$tfile.0 || error "compare $DIR/$tfile.0 failed"
18286
18287         echo "bs=11752 count=512 oflag=dsync small write $tfile.1"
18288         dd if=$TMP/$tfile.0 of=$DIR/$tfile.1 bs=11752 count=512 oflag=dsync ||
18289                 error "dd with sync small writes failed"
18290         cmp $TMP/$tfile.0 $DIR/$tfile.1 || error "compare $DIR/$tfile.1 failed"
18291
18292         cancel_lru_locks osc
18293
18294         # calculate the small O_DIRECT size and count for the client PAGE_SIZE
18295         local num=$((13 * 113 / (PAGE_SIZE / 4096)))
18296         echo "bs=$PAGE_SIZE count=$num iflag=direct small read $tfile.1"
18297         dd if=$DIR/$tfile.1 of=$TMP/$tfile.1 bs=$PAGE_SIZE count=$num \
18298                 iflag=direct || error "dd with O_DIRECT small read failed"
18299         # adjust bytes checked to handle larger PAGE_SIZE for ARM/PPC
18300         cmp --bytes=$((PAGE_SIZE * num)) $TMP/$tfile.0 $TMP/$tfile.1 ||
18301                 error "compare $TMP/$tfile.1 failed"
18302
18303         local save=$($LCTL get_param -n osc.*OST000*.short_io_bytes | head -n 1)
18304         stack_trap "$LCTL set_param osc.$FSNAME-*.short_io_bytes=$save" EXIT
18305
18306         # just to see what the maximum tunable value is, and test parsing
18307         echo "test invalid parameter 2MB"
18308         $LCTL set_param osc.$FSNAME-OST0000*.short_io_bytes=2M &&
18309                 error "too-large short_io_bytes allowed"
18310         echo "test maximum parameter 512KB"
18311         # if we can set a larger short_io_bytes, run test regardless of version
18312         if ! $LCTL set_param osc.$FSNAME-OST0000*.short_io_bytes=512K; then
18313                 # older clients may not allow setting it this large, that's OK
18314                 [ $CLIENT_VERSION -ge $(version_code 2.13.50) ] ||
18315                         skip "Need at least client version 2.13.50"
18316                 error "medium short_io_bytes failed"
18317         fi
18318         $LCTL get_param osc.$FSNAME-OST0000*.short_io_bytes
18319         size=$($LCTL get_param -n osc.$FSNAME-OST0000*.short_io_bytes)
18320
18321         echo "test large parameter 64KB"
18322         $LCTL set_param osc.$FSNAME-*.short_io_bytes=65536
18323         $LCTL get_param osc.$FSNAME-OST0000*.short_io_bytes
18324
18325         echo "bs=47008 count=128 oflag=dsync large write $tfile.2"
18326         dd if=$TMP/$tfile.0 of=$DIR/$tfile.2 bs=47008 count=128 oflag=dsync ||
18327                 error "dd with sync large writes failed"
18328         cmp $TMP/$tfile.0 $DIR/$tfile.2 || error "compare $DIR/$tfile.2 failed"
18329
18330         # calculate the large O_DIRECT size and count for the client PAGE_SIZE
18331         local size=$(((4096 * 13 + PAGE_SIZE - 1) / PAGE_SIZE * PAGE_SIZE))
18332         num=$((113 * 4096 / PAGE_SIZE))
18333         echo "bs=$size count=$num oflag=direct large write $tfile.3"
18334         dd if=$TMP/$tfile.0 of=$DIR/$tfile.3 bs=$size count=$num oflag=direct ||
18335                 error "dd with O_DIRECT large writes failed"
18336         cmp --bytes=$((size * num)) $TMP/$tfile.0 $DIR/$tfile.3 ||
18337                 error "compare $DIR/$tfile.3 failed"
18338
18339         cancel_lru_locks osc
18340
18341         echo "bs=$size count=$num iflag=direct large read $tfile.2"
18342         dd if=$DIR/$tfile.2 of=$TMP/$tfile.2 bs=$size count=$num iflag=direct ||
18343                 error "dd with O_DIRECT large read failed"
18344         cmp --bytes=$((size * num)) $TMP/$tfile.0 $TMP/$tfile.2 ||
18345                 error "compare $TMP/$tfile.2 failed"
18346
18347         echo "bs=$size count=$num iflag=direct large read $tfile.3"
18348         dd if=$DIR/$tfile.3 of=$TMP/$tfile.3 bs=$size count=$num iflag=direct ||
18349                 error "dd with O_DIRECT large read failed"
18350         cmp --bytes=$((size * num)) $TMP/$tfile.0 $TMP/$tfile.3 ||
18351                 error "compare $TMP/$tfile.3 failed"
18352 }
18353 run_test 248b "test short_io read and write for both small and large sizes"
18354
18355 test_249() { # LU-7890
18356         [ $MDS1_VERSION -lt $(version_code 2.8.53) ] &&
18357                 skip "Need at least version 2.8.54"
18358
18359         rm -f $DIR/$tfile
18360         $LFS setstripe -c 1 $DIR/$tfile
18361         # Offset 2T == 4k * 512M
18362         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
18363                 error "dd to 2T offset failed"
18364 }
18365 run_test 249 "Write above 2T file size"
18366
18367 test_250() {
18368         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR/$tfile) + 1)))" = "zfs" ] \
18369          && skip "no 16TB file size limit on ZFS"
18370
18371         $LFS setstripe -c 1 $DIR/$tfile
18372         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
18373         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
18374         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
18375         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
18376                 conv=notrunc,fsync && error "append succeeded"
18377         return 0
18378 }
18379 run_test 250 "Write above 16T limit"
18380
18381 test_251() {
18382         $LFS setstripe -c -1 -S 1048576 $DIR/$tfile
18383
18384         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
18385         #Skip once - writing the first stripe will succeed
18386         $LCTL set_param fail_loc=0xa0001407 fail_val=1
18387         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
18388                 error "short write happened"
18389
18390         $LCTL set_param fail_loc=0xa0001407 fail_val=1
18391         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
18392                 error "short read happened"
18393
18394         rm -f $DIR/$tfile
18395 }
18396 run_test 251 "Handling short read and write correctly"
18397
18398 test_252() {
18399         remote_mds_nodsh && skip "remote MDS with nodsh"
18400         remote_ost_nodsh && skip "remote OST with nodsh"
18401         if [ "$ost1_FSTYPE" != ldiskfs ] || [ "$mds1_FSTYPE" != ldiskfs ]; then
18402                 skip_env "ldiskfs only test"
18403         fi
18404
18405         local tgt
18406         local dev
18407         local out
18408         local uuid
18409         local num
18410         local gen
18411
18412         # check lr_reader on OST0000
18413         tgt=ost1
18414         dev=$(facet_device $tgt)
18415         out=$(do_facet $tgt $LR_READER $dev)
18416         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
18417         echo "$out"
18418         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
18419         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
18420                 error "Invalid uuid returned by $LR_READER on target $tgt"
18421         echo -e "uuid returned by $LR_READER is '$uuid'\n"
18422
18423         # check lr_reader -c on MDT0000
18424         tgt=mds1
18425         dev=$(facet_device $tgt)
18426         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
18427                 skip "$LR_READER does not support additional options"
18428         fi
18429         out=$(do_facet $tgt $LR_READER -c $dev)
18430         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
18431         echo "$out"
18432         num=$(echo "$out" | grep -c "mdtlov")
18433         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
18434                 error "Invalid number of mdtlov clients returned by $LR_READER"
18435         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
18436
18437         # check lr_reader -cr on MDT0000
18438         out=$(do_facet $tgt $LR_READER -cr $dev)
18439         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
18440         echo "$out"
18441         echo "$out" | grep -q "^reply_data:$" ||
18442                 error "$LR_READER should have returned 'reply_data' section"
18443         num=$(echo "$out" | grep -c "client_generation")
18444         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
18445 }
18446 run_test 252 "check lr_reader tool"
18447
18448 test_253() {
18449         [ $PARALLEL == "yes" ] && skip "skip parallel run"
18450         remote_mds_nodsh && skip "remote MDS with nodsh"
18451         remote_mgs_nodsh && skip "remote MGS with nodsh"
18452
18453         local ostidx=0
18454         local rc=0
18455         local ost_name=$(ostname_from_index $ostidx)
18456
18457         # on the mdt's osc
18458         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
18459         do_facet $SINGLEMDS $LCTL get_param -n \
18460                 osp.$mdtosc_proc1.reserved_mb_high ||
18461                 skip  "remote MDS does not support reserved_mb_high"
18462
18463         rm -rf $DIR/$tdir
18464         wait_mds_ost_sync
18465         wait_delete_completed
18466         mkdir $DIR/$tdir
18467
18468         pool_add $TESTNAME || error "Pool creation failed"
18469         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
18470
18471         $LFS setstripe $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
18472                 error "Setstripe failed"
18473
18474         dd if=/dev/zero of=$DIR/$tdir/$tfile.0 bs=1M count=10
18475
18476         local wms=$(ost_watermarks_set_enospc $tfile $ostidx |
18477                     grep "watermarks")
18478         stack_trap "ost_watermarks_clear_enospc $tfile $ostidx $wms" EXIT
18479
18480         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
18481                         osp.$mdtosc_proc1.prealloc_status)
18482         echo "prealloc_status $oa_status"
18483
18484         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1M count=1 &&
18485                 error "File creation should fail"
18486
18487         #object allocation was stopped, but we still able to append files
18488         dd if=/dev/zero of=$DIR/$tdir/$tfile.0 bs=1M seek=6 count=5 \
18489                 oflag=append || error "Append failed"
18490
18491         rm -f $DIR/$tdir/$tfile.0
18492
18493         # For this test, we want to delete the files we created to go out of
18494         # space but leave the watermark, so we remain nearly out of space
18495         ost_watermarks_enospc_delete_files $tfile $ostidx
18496
18497         wait_delete_completed
18498
18499         sleep_maxage
18500
18501         for i in $(seq 10 12); do
18502                 dd if=/dev/zero of=$DIR/$tdir/$tfile.$i bs=1M count=1 \
18503                         2>/dev/null || error "File creation failed after rm"
18504         done
18505
18506         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
18507                         osp.$mdtosc_proc1.prealloc_status)
18508         echo "prealloc_status $oa_status"
18509
18510         if (( oa_status != 0 )); then
18511                 error "Object allocation still disable after rm"
18512         fi
18513 }
18514 run_test 253 "Check object allocation limit"
18515
18516 test_254() {
18517         [ $PARALLEL == "yes" ] && skip "skip parallel run"
18518         remote_mds_nodsh && skip "remote MDS with nodsh"
18519         do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_size ||
18520                 skip "MDS does not support changelog_size"
18521
18522         local cl_user
18523         local MDT0=$(facet_svc $SINGLEMDS)
18524
18525         changelog_register || error "changelog_register failed"
18526
18527         changelog_clear 0 || error "changelog_clear failed"
18528
18529         local size1=$(do_facet $SINGLEMDS \
18530                       $LCTL get_param -n mdd.$MDT0.changelog_size)
18531         echo "Changelog size $size1"
18532
18533         rm -rf $DIR/$tdir
18534         $LFS mkdir -i 0 $DIR/$tdir
18535         # change something
18536         mkdir -p $DIR/$tdir/pics/2008/zachy
18537         touch $DIR/$tdir/pics/2008/zachy/timestamp
18538         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
18539         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
18540         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
18541         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
18542         rm $DIR/$tdir/pics/desktop.jpg
18543
18544         local size2=$(do_facet $SINGLEMDS \
18545                       $LCTL get_param -n mdd.$MDT0.changelog_size)
18546         echo "Changelog size after work $size2"
18547
18548         (( $size2 > $size1 )) ||
18549                 error "new Changelog size=$size2 less than old size=$size1"
18550 }
18551 run_test 254 "Check changelog size"
18552
18553 ladvise_no_type()
18554 {
18555         local type=$1
18556         local file=$2
18557
18558         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
18559                 awk -F: '{print $2}' | grep $type > /dev/null
18560         if [ $? -ne 0 ]; then
18561                 return 0
18562         fi
18563         return 1
18564 }
18565
18566 ladvise_no_ioctl()
18567 {
18568         local file=$1
18569
18570         lfs ladvise -a willread $file > /dev/null 2>&1
18571         if [ $? -eq 0 ]; then
18572                 return 1
18573         fi
18574
18575         lfs ladvise -a willread $file 2>&1 |
18576                 grep "Inappropriate ioctl for device" > /dev/null
18577         if [ $? -eq 0 ]; then
18578                 return 0
18579         fi
18580         return 1
18581 }
18582
18583 percent() {
18584         bc <<<"scale=2; ($1 - $2) * 100 / $2"
18585 }
18586
18587 # run a random read IO workload
18588 # usage: random_read_iops <filename> <filesize> <iosize>
18589 random_read_iops() {
18590         local file=$1
18591         local fsize=$2
18592         local iosize=${3:-4096}
18593
18594         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
18595                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
18596 }
18597
18598 drop_file_oss_cache() {
18599         local file="$1"
18600         local nodes="$2"
18601
18602         $LFS ladvise -a dontneed $file 2>/dev/null ||
18603                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
18604 }
18605
18606 ladvise_willread_performance()
18607 {
18608         local repeat=10
18609         local average_origin=0
18610         local average_cache=0
18611         local average_ladvise=0
18612
18613         for ((i = 1; i <= $repeat; i++)); do
18614                 echo "Iter $i/$repeat: reading without willread hint"
18615                 cancel_lru_locks osc
18616                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
18617                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
18618                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
18619                 average_origin=$(bc <<<"$average_origin + $speed_origin")
18620
18621                 cancel_lru_locks osc
18622                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
18623                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
18624                 average_cache=$(bc <<<"$average_cache + $speed_cache")
18625
18626                 cancel_lru_locks osc
18627                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
18628                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
18629                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
18630                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
18631                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
18632         done
18633         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
18634         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
18635         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
18636
18637         speedup_cache=$(percent $average_cache $average_origin)
18638         speedup_ladvise=$(percent $average_ladvise $average_origin)
18639
18640         echo "Average uncached read: $average_origin"
18641         echo "Average speedup with OSS cached read: " \
18642                 "$average_cache = +$speedup_cache%"
18643         echo "Average speedup with ladvise willread: " \
18644                 "$average_ladvise = +$speedup_ladvise%"
18645
18646         local lowest_speedup=20
18647         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
18648                 echo "Speedup with OSS cached read less than $lowest_speedup%," \
18649                         "got $average_cache%. Skipping ladvise willread check."
18650                 return 0
18651         fi
18652
18653         # the test won't work on ZFS until it supports 'ladvise dontneed', but
18654         # it is still good to run until then to exercise 'ladvise willread'
18655         ! $LFS ladvise -a dontneed $DIR/$tfile &&
18656                 [ "$ost1_FSTYPE" = "zfs" ] &&
18657                 echo "osd-zfs does not support dontneed or drop_caches" &&
18658                 return 0
18659
18660         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
18661         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
18662                 error_not_in_vm "Speedup with willread is less than " \
18663                         "$lowest_speedup%, got $average_ladvise%"
18664 }
18665
18666 test_255a() {
18667         [ $OST1_VERSION -lt $(version_code 2.8.54) ] &&
18668                 skip "lustre < 2.8.54 does not support ladvise "
18669         remote_ost_nodsh && skip "remote OST with nodsh"
18670
18671         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
18672
18673         ladvise_no_type willread $DIR/$tfile &&
18674                 skip "willread ladvise is not supported"
18675
18676         ladvise_no_ioctl $DIR/$tfile &&
18677                 skip "ladvise ioctl is not supported"
18678
18679         local size_mb=100
18680         local size=$((size_mb * 1048576))
18681         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
18682                 error "dd to $DIR/$tfile failed"
18683
18684         lfs ladvise -a willread $DIR/$tfile ||
18685                 error "Ladvise failed with no range argument"
18686
18687         lfs ladvise -a willread -s 0 $DIR/$tfile ||
18688                 error "Ladvise failed with no -l or -e argument"
18689
18690         lfs ladvise -a willread -e 1 $DIR/$tfile ||
18691                 error "Ladvise failed with only -e argument"
18692
18693         lfs ladvise -a willread -l 1 $DIR/$tfile ||
18694                 error "Ladvise failed with only -l argument"
18695
18696         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
18697                 error "End offset should not be smaller than start offset"
18698
18699         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
18700                 error "End offset should not be equal to start offset"
18701
18702         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
18703                 error "Ladvise failed with overflowing -s argument"
18704
18705         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
18706                 error "Ladvise failed with overflowing -e argument"
18707
18708         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
18709                 error "Ladvise failed with overflowing -l argument"
18710
18711         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
18712                 error "Ladvise succeeded with conflicting -l and -e arguments"
18713
18714         echo "Synchronous ladvise should wait"
18715         local delay=4
18716 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
18717         do_nodes $(comma_list $(osts_nodes)) \
18718                 $LCTL set_param fail_val=$delay fail_loc=0x237
18719
18720         local start_ts=$SECONDS
18721         lfs ladvise -a willread $DIR/$tfile ||
18722                 error "Ladvise failed with no range argument"
18723         local end_ts=$SECONDS
18724         local inteval_ts=$((end_ts - start_ts))
18725
18726         if [ $inteval_ts -lt $(($delay - 1)) ]; then
18727                 error "Synchronous advice didn't wait reply"
18728         fi
18729
18730         echo "Asynchronous ladvise shouldn't wait"
18731         local start_ts=$SECONDS
18732         lfs ladvise -a willread -b $DIR/$tfile ||
18733                 error "Ladvise failed with no range argument"
18734         local end_ts=$SECONDS
18735         local inteval_ts=$((end_ts - start_ts))
18736
18737         if [ $inteval_ts -gt $(($delay / 2)) ]; then
18738                 error "Asynchronous advice blocked"
18739         fi
18740
18741         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
18742         ladvise_willread_performance
18743 }
18744 run_test 255a "check 'lfs ladvise -a willread'"
18745
18746 facet_meminfo() {
18747         local facet=$1
18748         local info=$2
18749
18750         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
18751 }
18752
18753 test_255b() {
18754         [ $OST1_VERSION -lt $(version_code 2.8.54) ] &&
18755                 skip "lustre < 2.8.54 does not support ladvise "
18756         remote_ost_nodsh && skip "remote OST with nodsh"
18757
18758         lfs setstripe -c 1 -i 0 $DIR/$tfile
18759
18760         ladvise_no_type dontneed $DIR/$tfile &&
18761                 skip "dontneed ladvise is not supported"
18762
18763         ladvise_no_ioctl $DIR/$tfile &&
18764                 skip "ladvise ioctl is not supported"
18765
18766         ! $LFS ladvise -a dontneed $DIR/$tfile &&
18767                 [ "$ost1_FSTYPE" = "zfs" ] &&
18768                 skip "zfs-osd does not support 'ladvise dontneed'"
18769
18770         local size_mb=100
18771         local size=$((size_mb * 1048576))
18772         # In order to prevent disturbance of other processes, only check 3/4
18773         # of the memory usage
18774         local kibibytes=$((size_mb * 1024 * 3 / 4))
18775
18776         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
18777                 error "dd to $DIR/$tfile failed"
18778
18779         #force write to complete before dropping OST cache & checking memory
18780         sync
18781
18782         local total=$(facet_meminfo ost1 MemTotal)
18783         echo "Total memory: $total KiB"
18784
18785         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
18786         local before_read=$(facet_meminfo ost1 Cached)
18787         echo "Cache used before read: $before_read KiB"
18788
18789         lfs ladvise -a willread $DIR/$tfile ||
18790                 error "Ladvise willread failed"
18791         local after_read=$(facet_meminfo ost1 Cached)
18792         echo "Cache used after read: $after_read KiB"
18793
18794         lfs ladvise -a dontneed $DIR/$tfile ||
18795                 error "Ladvise dontneed again failed"
18796         local no_read=$(facet_meminfo ost1 Cached)
18797         echo "Cache used after dontneed ladvise: $no_read KiB"
18798
18799         if [ $total -lt $((before_read + kibibytes)) ]; then
18800                 echo "Memory is too small, abort checking"
18801                 return 0
18802         fi
18803
18804         if [ $((before_read + kibibytes)) -gt $after_read ]; then
18805                 error "Ladvise willread should use more memory" \
18806                         "than $kibibytes KiB"
18807         fi
18808
18809         if [ $((no_read + kibibytes)) -gt $after_read ]; then
18810                 error "Ladvise dontneed should release more memory" \
18811                         "than $kibibytes KiB"
18812         fi
18813 }
18814 run_test 255b "check 'lfs ladvise -a dontneed'"
18815
18816 test_255c() {
18817         [ $OST1_VERSION -lt $(version_code 2.10.50) ] &&
18818                 skip "lustre < 2.10.50 does not support lockahead"
18819
18820         local count
18821         local new_count
18822         local difference
18823         local i
18824         local rc
18825
18826         test_mkdir -p $DIR/$tdir
18827         $LFS setstripe -i 0 -c 1 $DIR/$tdir
18828
18829         #test 10 returns only success/failure
18830         i=10
18831         lockahead_test -d $DIR/$tdir -t $i -f $tfile
18832         rc=$?
18833         if [ $rc -eq 255 ]; then
18834                 error "Ladvise test${i} failed, ${rc}"
18835         fi
18836
18837         #test 11 counts lock enqueue requests, all others count new locks
18838         i=11
18839         count=$(do_facet ost1 \
18840                 $LCTL get_param -n ost.OSS.ost.stats)
18841         count=$(echo "$count" | grep ldlm_extent_enqueue | awk '{ print $2 }')
18842
18843         lockahead_test -d $DIR/$tdir -t $i -f $tfile
18844         rc=$?
18845         if [ $rc -eq 255 ]; then
18846                 error "Ladvise test${i} failed, ${rc}"
18847         fi
18848
18849         new_count=$(do_facet ost1 \
18850                 $LCTL get_param -n ost.OSS.ost.stats)
18851         new_count=$(echo "$new_count" | grep ldlm_extent_enqueue | \
18852                    awk '{ print $2 }')
18853
18854         difference="$((new_count - count))"
18855         if [ $difference -ne $rc ]; then
18856                 error "Ladvise test${i}, bad enqueue count, returned " \
18857                       "${rc}, actual ${difference}"
18858         fi
18859
18860         for i in $(seq 12 21); do
18861                 # If we do not do this, we run the risk of having too many
18862                 # locks and starting lock cancellation while we are checking
18863                 # lock counts.
18864                 cancel_lru_locks osc
18865
18866                 count=$($LCTL get_param -n \
18867                        ldlm.namespaces.$FSNAME-OST0000*osc-[-0-9a-f]*.lock_unused_count)
18868
18869                 lockahead_test -d $DIR/$tdir -t $i -f $tfile
18870                 rc=$?
18871                 if [ $rc -eq 255 ]; then
18872                         error "Ladvise test ${i} failed, ${rc}"
18873                 fi
18874
18875                 new_count=$($LCTL get_param -n \
18876                        ldlm.namespaces.$FSNAME-OST0000*osc-[-0-9a-f]*.lock_unused_count)
18877                 difference="$((new_count - count))"
18878
18879                 # Test 15 output is divided by 100 to map down to valid return
18880                 if [ $i -eq 15 ]; then
18881                         rc="$((rc * 100))"
18882                 fi
18883
18884                 if [ $difference -ne $rc ]; then
18885                         error "Ladvise test ${i}, bad lock count, returned " \
18886                               "${rc}, actual ${difference}"
18887                 fi
18888         done
18889
18890         #test 22 returns only success/failure
18891         i=22
18892         lockahead_test -d $DIR/$tdir -t $i -f $tfile
18893         rc=$?
18894         if [ $rc -eq 255 ]; then
18895                 error "Ladvise test${i} failed, ${rc}"
18896         fi
18897 }
18898 run_test 255c "suite of ladvise lockahead tests"
18899
18900 test_256() {
18901         [ $PARALLEL == "yes" ] && skip "skip parallel run"
18902         remote_mds_nodsh && skip "remote MDS with nodsh"
18903         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip "ldiskfs only test"
18904         changelog_users $SINGLEMDS | grep "^cl" &&
18905                 skip "active changelog user"
18906
18907         local cl_user
18908         local cat_sl
18909         local mdt_dev
18910
18911         mdt_dev=$(mdsdevname 1)
18912         echo $mdt_dev
18913
18914         changelog_register || error "changelog_register failed"
18915
18916         rm -rf $DIR/$tdir
18917         mkdir -p $DIR/$tdir
18918
18919         changelog_clear 0 || error "changelog_clear failed"
18920
18921         # change something
18922         touch $DIR/$tdir/{1..10}
18923
18924         # stop the MDT
18925         stop $SINGLEMDS || error "Fail to stop MDT"
18926
18927         # remount the MDT
18928
18929         start $SINGLEMDS $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT"
18930
18931         #after mount new plainllog is used
18932         touch $DIR/$tdir/{11..19}
18933         local tmpfile="$(mktemp --tmpdir -u $tfile.XXXXXX)"
18934         stack_trap "rm -f $tmpfile"
18935         cat_sl=$(do_facet $SINGLEMDS "sync; \
18936                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
18937                  llog_reader $tmpfile | grep -c type=1064553b")
18938         do_facet $SINGLEMDS llog_reader $tmpfile
18939
18940         [ $cat_sl != 2 ] && error "Changelog catalog has $cat_sl != 2 slots"
18941
18942         changelog_clear 0 || error "changelog_clear failed"
18943
18944         cat_sl=$(do_facet $SINGLEMDS "sync; \
18945                  $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
18946                  llog_reader $tmpfile | grep -c type=1064553b")
18947
18948         if (( cat_sl == 2 )); then
18949                 error "Empty plain llog was not deleted from changelog catalog"
18950         elif (( cat_sl != 1 )); then
18951                 error "Active plain llog shouldn't be deleted from catalog"
18952         fi
18953 }
18954 run_test 256 "Check llog delete for empty and not full state"
18955
18956 test_257() {
18957         remote_mds_nodsh && skip "remote MDS with nodsh"
18958         [[ $MDS1_VERSION -lt $(version_code 2.8.55) ]] &&
18959                 skip "Need MDS version at least 2.8.55"
18960
18961         test_mkdir $DIR/$tdir
18962
18963         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
18964                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
18965         stat $DIR/$tdir
18966
18967 #define OBD_FAIL_MDS_XATTR_REP                  0x161
18968         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
18969         local facet=mds$((mdtidx + 1))
18970         set_nodes_failloc $(facet_active_host $facet) 0x80000161
18971         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
18972
18973         stop $facet || error "stop MDS failed"
18974         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
18975                 error "start MDS fail"
18976         wait_recovery_complete $facet
18977 }
18978 run_test 257 "xattr locks are not lost"
18979
18980 # Verify we take the i_mutex when security requires it
18981 test_258a() {
18982 #define OBD_FAIL_IMUTEX_SEC 0x141c
18983         $LCTL set_param fail_loc=0x141c
18984         touch $DIR/$tfile
18985         chmod u+s $DIR/$tfile
18986         chmod a+rwx $DIR/$tfile
18987         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
18988         RC=$?
18989         if [ $RC -ne 0 ]; then
18990                 error "error, failed to take i_mutex, rc=$?"
18991         fi
18992         rm -f $DIR/$tfile
18993 }
18994 run_test 258a "verify i_mutex security behavior when suid attributes is set"
18995
18996 # Verify we do NOT take the i_mutex in the normal case
18997 test_258b() {
18998 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
18999         $LCTL set_param fail_loc=0x141d
19000         touch $DIR/$tfile
19001         chmod a+rwx $DIR
19002         chmod a+rw $DIR/$tfile
19003         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
19004         RC=$?
19005         if [ $RC -ne 0 ]; then
19006                 error "error, took i_mutex unnecessarily, rc=$?"
19007         fi
19008         rm -f $DIR/$tfile
19009
19010 }
19011 run_test 258b "verify i_mutex security behavior"
19012
19013 test_259() {
19014         local file=$DIR/$tfile
19015         local before
19016         local after
19017
19018         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip "ldiskfs only test"
19019
19020         stack_trap "rm -f $file" EXIT
19021
19022         wait_delete_completed
19023         before=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
19024         echo "before: $before"
19025
19026         $LFS setstripe -i 0 -c 1 $file
19027         dd if=/dev/zero of=$file bs=1M count=10 || error "couldn't write"
19028         sync_all_data
19029         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
19030         echo "after write: $after"
19031
19032 #define OBD_FAIL_OSD_FAIL_AT_TRUNCATE          0x2301
19033         do_facet ost1 $LCTL set_param fail_loc=0x2301
19034         $TRUNCATE $file 0
19035         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
19036         echo "after truncate: $after"
19037
19038         stop ost1
19039         do_facet ost1 $LCTL set_param fail_loc=0
19040         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
19041         sleep 2
19042         after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
19043         echo "after restart: $after"
19044         [ $((after - before)) -ge $(fs_log_size ost1) ] &&
19045                 error "missing truncate?"
19046
19047         return 0
19048 }
19049 run_test 259 "crash at delayed truncate"
19050
19051 test_260() {
19052 #define OBD_FAIL_MDC_CLOSE               0x806
19053         $LCTL set_param fail_loc=0x80000806
19054         touch $DIR/$tfile
19055
19056 }
19057 run_test 260 "Check mdc_close fail"
19058
19059 ### Data-on-MDT sanity tests ###
19060 test_270a() {
19061         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19062                 skip "Need MDS version at least 2.10.55 for DoM"
19063
19064         # create DoM file
19065         local dom=$DIR/$tdir/dom_file
19066         local tmp=$DIR/$tdir/tmp_file
19067
19068         mkdir -p $DIR/$tdir
19069
19070         # basic checks for DoM component creation
19071         $LFS setstripe -E 1024K -E 2048K -L mdt $dom 2>/dev/null &&
19072                 error "Can set MDT layout to non-first entry"
19073
19074         $LFS setstripe -E 1024K -L mdt -E 2048K -L mdt $dom 2>/dev/null &&
19075                 error "Can define multiple entries as MDT layout"
19076
19077         $LFS setstripe -E 1M -L mdt $dom || error "Can't create DoM layout"
19078
19079         [ $($LFS getstripe -L $dom) == "mdt" ] || error "bad pattern"
19080         [ $($LFS getstripe -c $dom) == 0 ] || error "bad stripe count"
19081         [ $($LFS getstripe -S $dom) == 1048576 ] || error "bad stripe size"
19082
19083         local mdtidx=$($LFS getstripe -m $dom)
19084         local mdtname=MDT$(printf %04x $mdtidx)
19085         local facet=mds$((mdtidx + 1))
19086         local space_check=1
19087
19088         # Skip free space checks with ZFS
19089         [ "$(facet_fstype $facet)" == "zfs" ] && space_check=0
19090
19091         # write
19092         sync
19093         local size_tmp=$((65536 * 3))
19094         local mdtfree1=$(do_facet $facet \
19095                          lctl get_param -n osd*.*$mdtname.kbytesfree)
19096
19097         dd if=/dev/urandom of=$tmp bs=1024 count=$((size_tmp / 1024))
19098         # check also direct IO along write
19099         # IO size must be a multiple of PAGE_SIZE on all platforms (ARM=64KB)
19100         dd if=$tmp of=$dom bs=65536 count=$((size_tmp / 65536)) oflag=direct
19101         sync
19102         cmp $tmp $dom || error "file data is different"
19103         [ $(stat -c%s $dom) == $size_tmp ] ||
19104                 error "bad size after write: $(stat -c%s $dom) != $size_tmp"
19105         if [ $space_check == 1 ]; then
19106                 local mdtfree2=$(do_facet $facet \
19107                                  lctl get_param -n osd*.*$mdtname.kbytesfree)
19108
19109                 # increase in usage from by $size_tmp
19110                 [ $(($mdtfree1 - $mdtfree2)) -ge $((size_tmp / 1024)) ] ||
19111                         error "MDT free space wrong after write: " \
19112                               "$mdtfree1 >= $mdtfree2 + $size_tmp/1024"
19113         fi
19114
19115         # truncate
19116         local size_dom=10000
19117
19118         $TRUNCATE $dom $size_dom
19119         [ $(stat -c%s $dom) == $size_dom ] ||
19120                 error "bad size after truncate: $(stat -c%s $dom) != $size_dom"
19121         if [ $space_check == 1 ]; then
19122                 mdtfree1=$(do_facet $facet \
19123                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19124                 # decrease in usage from $size_tmp to new $size_dom
19125                 [ $(($mdtfree1 - $mdtfree2)) -ge \
19126                   $(((size_tmp - size_dom) / 1024)) ] ||
19127                         error "MDT free space is wrong after truncate: " \
19128                               "$mdtfree1 >= $mdtfree2 + ($size_tmp - $size_dom) / 1024"
19129         fi
19130
19131         # append
19132         cat $tmp >> $dom
19133         sync
19134         size_dom=$((size_dom + size_tmp))
19135         [ $(stat -c%s $dom) == $size_dom ] ||
19136                 error "bad size after append: $(stat -c%s $dom) != $size_dom"
19137         if [ $space_check == 1 ]; then
19138                 mdtfree2=$(do_facet $facet \
19139                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19140                 # increase in usage by $size_tmp from previous
19141                 [ $(($mdtfree1 - $mdtfree2)) -ge $((size_tmp / 1024)) ] ||
19142                         error "MDT free space is wrong after append: " \
19143                               "$mdtfree1 >= $mdtfree2 + $size_tmp/1024"
19144         fi
19145
19146         # delete
19147         rm $dom
19148         if [ $space_check == 1 ]; then
19149                 mdtfree1=$(do_facet $facet \
19150                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19151                 # decrease in usage by $size_dom from previous
19152                 [ $(($mdtfree1 - $mdtfree2)) -ge $((size_dom / 1024)) ] ||
19153                         error "MDT free space is wrong after removal: " \
19154                               "$mdtfree1 >= $mdtfree2 + $size_dom/1024"
19155         fi
19156
19157         # combined striping
19158         $LFS setstripe -E 1024K -L mdt -E EOF $dom ||
19159                 error "Can't create DoM + OST striping"
19160
19161         size_tmp=2031616 # must be a multiple of PAGE_SIZE=65536 on ARM
19162         dd if=/dev/urandom of=$tmp bs=1024 count=$((size_tmp / 1024))
19163         # check also direct IO along write
19164         dd if=$tmp of=$dom bs=65536 count=$((size_tmp / 65536)) oflag=direct
19165         sync
19166         cmp $tmp $dom || error "file data is different"
19167         [ $(stat -c%s $dom) == $size_tmp ] ||
19168                 error "bad size after write: $(stat -c%s $dom) != $size_tmp"
19169         rm $dom $tmp
19170
19171         return 0
19172 }
19173 run_test 270a "DoM: basic functionality tests"
19174
19175 test_270b() {
19176         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19177                 skip "Need MDS version at least 2.10.55"
19178
19179         local dom=$DIR/$tdir/dom_file
19180         local max_size=1048576
19181
19182         mkdir -p $DIR/$tdir
19183         $LFS setstripe -E $max_size -L mdt $dom
19184
19185         # truncate over the limit
19186         $TRUNCATE $dom $(($max_size + 1)) &&
19187                 error "successful truncate over the maximum size"
19188         # write over the limit
19189         dd if=/dev/zero of=$dom bs=$max_size seek=1 count=1 &&
19190                 error "successful write over the maximum size"
19191         # append over the limit
19192         dd if=/dev/zero of=$dom bs=$(($max_size - 3)) count=1
19193         echo "12345" >> $dom && error "successful append over the maximum size"
19194         rm $dom
19195
19196         return 0
19197 }
19198 run_test 270b "DoM: maximum size overflow checks for DoM-only file"
19199
19200 test_270c() {
19201         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19202                 skip "Need MDS version at least 2.10.55"
19203
19204         mkdir -p $DIR/$tdir
19205         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19206
19207         # check files inherit DoM EA
19208         touch $DIR/$tdir/first
19209         [ $($LFS getstripe -L $DIR/$tdir/first) == "mdt" ] ||
19210                 error "bad pattern"
19211         [ $($LFS getstripe -c $DIR/$tdir/first) == 0 ] ||
19212                 error "bad stripe count"
19213         [ $($LFS getstripe -S $DIR/$tdir/first) == 1048576 ] ||
19214                 error "bad stripe size"
19215
19216         # check directory inherits DoM EA and uses it as default
19217         mkdir $DIR/$tdir/subdir
19218         touch $DIR/$tdir/subdir/second
19219         [ $($LFS getstripe -L $DIR/$tdir/subdir/second) == "mdt" ] ||
19220                 error "bad pattern in sub-directory"
19221         [ $($LFS getstripe -c $DIR/$tdir/subdir/second) == 0 ] ||
19222                 error "bad stripe count in sub-directory"
19223         [ $($LFS getstripe -S $DIR/$tdir/subdir/second) == 1048576 ] ||
19224                 error "bad stripe size in sub-directory"
19225         return 0
19226 }
19227 run_test 270c "DoM: DoM EA inheritance tests"
19228
19229 test_270d() {
19230         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19231                 skip "Need MDS version at least 2.10.55"
19232
19233         mkdir -p $DIR/$tdir
19234         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19235
19236         # inherit default DoM striping
19237         mkdir $DIR/$tdir/subdir
19238         touch $DIR/$tdir/subdir/f1
19239
19240         # change default directory striping
19241         $LFS setstripe -c 1 $DIR/$tdir/subdir
19242         touch $DIR/$tdir/subdir/f2
19243         [ $($LFS getstripe -c $DIR/$tdir/subdir/f2) == 1 ] ||
19244                 error "wrong default striping in file 2"
19245         [ $($LFS getstripe -L $DIR/$tdir/subdir/f2) == "raid0" ] ||
19246                 error "bad pattern in file 2"
19247         return 0
19248 }
19249 run_test 270d "DoM: change striping from DoM to RAID0"
19250
19251 test_270e() {
19252         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19253                 skip "Need MDS version at least 2.10.55"
19254
19255         mkdir -p $DIR/$tdir/dom
19256         mkdir -p $DIR/$tdir/norm
19257         DOMFILES=20
19258         NORMFILES=10
19259         $LFS setstripe -E 1M -L mdt $DIR/$tdir/dom
19260         $LFS setstripe -i 0 -S 2M $DIR/$tdir/norm
19261
19262         createmany -o $DIR/$tdir/dom/dom- $DOMFILES
19263         createmany -o $DIR/$tdir/norm/norm- $NORMFILES
19264
19265         # find DoM files by layout
19266         NUM=$($LFS find -L mdt -type f $DIR/$tdir 2>/dev/null | wc -l)
19267         [ $NUM -eq  $DOMFILES ] ||
19268                 error "lfs find -L: found $NUM, expected $DOMFILES"
19269         echo "Test 1: lfs find 20 DOM files by layout: OK"
19270
19271         # there should be 1 dir with default DOM striping
19272         NUM=$($LFS find -L mdt -type d $DIR/$tdir 2>/dev/null | wc -l)
19273         [ $NUM -eq  1 ] ||
19274                 error "lfs find -L: found $NUM, expected 1 dir"
19275         echo "Test 2: lfs find 1 DOM dir by layout: OK"
19276
19277         # find DoM files by stripe size
19278         NUM=$($LFS find -S -1200K -type f $DIR/$tdir 2>/dev/null | wc -l)
19279         [ $NUM -eq  $DOMFILES ] ||
19280                 error "lfs find -S: found $NUM, expected $DOMFILES"
19281         echo "Test 4: lfs find 20 DOM files by stripe size: OK"
19282
19283         # find files by stripe offset except DoM files
19284         NUM=$($LFS find -i 0 -type f $DIR/$tdir 2>/dev/null | wc -l)
19285         [ $NUM -eq  $NORMFILES ] ||
19286                 error "lfs find -i: found $NUM, expected $NORMFILES"
19287         echo "Test 5: lfs find no DOM files by stripe index: OK"
19288         return 0
19289 }
19290 run_test 270e "DoM: lfs find with DoM files test"
19291
19292 test_270f() {
19293         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19294                 skip "Need MDS version at least 2.10.55"
19295
19296         local mdtname=${FSNAME}-MDT0000-mdtlov
19297         local dom=$DIR/$tdir/dom_file
19298         local dom_limit_saved=$(do_facet mds1 $LCTL get_param -n \
19299                                                 lod.$mdtname.dom_stripesize)
19300         local dom_limit=131072
19301
19302         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=$dom_limit
19303         local dom_current=$(do_facet mds1 $LCTL get_param -n \
19304                                                 lod.$mdtname.dom_stripesize)
19305         [ ${dom_limit} -eq ${dom_current} ] ||
19306                 error "Cannot change per-MDT DoM stripe limit to $dom_limit"
19307
19308         $LFS mkdir -i 0 -c 1 $DIR/$tdir
19309         $LFS setstripe -d $DIR/$tdir
19310         $LFS setstripe -E $dom_limit -L mdt $DIR/$tdir ||
19311                 error "Can't set directory default striping"
19312
19313         # exceed maximum stripe size
19314         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
19315                 error "Can't create file with $((dom_limit * 2)) DoM stripe"
19316         [ $($LFS getstripe -S $dom) -eq $((dom_limit * 2)) ] &&
19317                 error "Able to create DoM component size more than LOD limit"
19318
19319         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=0
19320         dom_current=$(do_facet mds1 $LCTL get_param -n \
19321                                                 lod.$mdtname.dom_stripesize)
19322         [ 0 -eq ${dom_current} ] ||
19323                 error "Can't set zero DoM stripe limit"
19324         rm $dom
19325
19326         # attempt to create DoM file on server with disabled DoM should
19327         # remove DoM entry from layout and be succeed
19328         $LFS setstripe -E $dom_limit -L mdt -E -1 $dom ||
19329                 error "Can't create DoM file (DoM is disabled)"
19330         [ $($LFS getstripe -L $dom) == "mdt" ] &&
19331                 error "File has DoM component while DoM is disabled"
19332         rm $dom
19333
19334         # attempt to create DoM file with only DoM stripe should return error
19335         $LFS setstripe -E $dom_limit -L mdt $dom &&
19336                 error "Able to create DoM-only file while DoM is disabled"
19337
19338         # too low values to be aligned with smallest stripe size 64K
19339         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=30000
19340         dom_current=$(do_facet mds1 $LCTL get_param -n \
19341                                                 lod.$mdtname.dom_stripesize)
19342         [ 30000 -eq ${dom_current} ] &&
19343                 error "Can set too small DoM stripe limit"
19344
19345         # 64K is a minimal stripe size in Lustre, expect limit of that size
19346         [ 65536 -eq ${dom_current} ] ||
19347                 error "Limit is not set to 64K but ${dom_current}"
19348
19349         do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=2147483648
19350         dom_current=$(do_facet mds1 $LCTL get_param -n \
19351                                                 lod.$mdtname.dom_stripesize)
19352         echo $dom_current
19353         [ 2147483648 -eq ${dom_current} ] &&
19354                 error "Can set too large DoM stripe limit"
19355
19356         do_facet mds1 $LCTL set_param -n \
19357                                 lod.$mdtname.dom_stripesize=$((dom_limit * 2))
19358         $LFS setstripe -E $((dom_limit * 2)) -L mdt $dom ||
19359                 error "Can't create DoM component size after limit change"
19360         do_facet mds1 $LCTL set_param -n \
19361                                 lod.$mdtname.dom_stripesize=$((dom_limit / 2))
19362         $LFS setstripe -E $dom_limit -L mdt ${dom}_big ||
19363                 error "Can't create DoM file after limit decrease"
19364         [ $($LFS getstripe -S ${dom}_big) -eq $((dom_limit / 2)) ] ||
19365                 error "Can create big DoM component after limit decrease"
19366         touch ${dom}_def ||
19367                 error "Can't create file with old default layout"
19368
19369         do_facet mds1 $LCTL set_param -n lod.*.dom_stripesize=$dom_limit_saved
19370         return 0
19371 }
19372 run_test 270f "DoM: maximum DoM stripe size checks"
19373
19374 test_270g() {
19375         [ $MDS1_VERSION -ge $(version_code 2.13.52) ] ||
19376                 skip "Need MDS version at least 2.13.52"
19377         local dom=$DIR/$tdir/$tfile
19378
19379         $LFS mkdir -i 0 -c 1 $DIR/$tdir
19380         local lodname=${FSNAME}-MDT0000-mdtlov
19381
19382         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
19383         save_lustre_params mds1 "lod.${lodname}.dom_stripesize_max_kb" > $save
19384         save_lustre_params mds1 "lod.${lodname}.dom_threshold_free_mb" >> $save
19385         stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
19386
19387         local dom_limit=1024
19388         local dom_threshold="50%"
19389
19390         $LFS setstripe -d $DIR/$tdir
19391         $LFS setstripe -E ${dom_limit}K -L mdt $DIR/$tdir ||
19392                 error "Can't set directory default striping"
19393
19394         do_facet mds1 $LCTL set_param -n \
19395                                 lod.${lodname}.dom_stripesize_max_kb=$dom_limit
19396         # set 0 threshold and create DOM file to change tunable stripesize
19397         do_facet mds1 $LCTL set_param -n lod.${lodname}.dom_threshold_free_mb=0
19398         $LFS setstripe -E ${dom_limit}K -L mdt -E -1 $dom ||
19399                 error "Failed to create $dom file"
19400         # now tunable dom_cur_stripesize should reach maximum
19401         local dom_current=$(do_facet mds1 $LCTL get_param -n \
19402                                         lod.${lodname}.dom_stripesize_cur_kb)
19403         [[ $dom_current == $dom_limit ]] ||
19404                 error "Current DOM stripesize is not maximum"
19405         rm $dom
19406
19407         # set threshold for further tests
19408         do_facet mds1 $LCTL set_param -n \
19409                         lod.${lodname}.dom_threshold_free_mb=$dom_threshold
19410         echo "DOM threshold is $dom_threshold free space"
19411         local dom_def
19412         local dom_set
19413         # Spoof bfree to exceed threshold
19414         #define OBD_FAIL_MDS_STATFS_SPOOF   0x168
19415         do_facet mds1 $LCTL set_param -n fail_loc=0x0168
19416         for spfree in 40 20 0 15 30 55; do
19417                 do_facet mds1 $LCTL set_param -n fail_val=$spfree
19418                 $LFS setstripe -E ${dom_limit}K -L mdt -E -1 $dom ||
19419                         error "Failed to create $dom file"
19420                 dom_def=$(do_facet mds1 $LCTL get_param -n \
19421                                         lod.${lodname}.dom_stripesize_cur_kb)
19422                 echo "Free space: ${spfree}%, default DOM stripe: ${dom_def}K"
19423                 [[ $dom_def != $dom_current ]] ||
19424                         error "Default stripe size was not changed"
19425                 if [[ $spfree > 0 ]] ; then
19426                         dom_set=$($LFS getstripe -S $dom)
19427                         [[ $dom_set == $((dom_def * 1024)) ]] ||
19428                                 error "DOM component size is still old"
19429                 else
19430                         [[ $($LFS getstripe -L $dom) != "mdt" ]] ||
19431                                 error "DoM component is set with no free space"
19432                 fi
19433                 rm $dom
19434                 dom_current=$dom_def
19435         done
19436 }
19437 run_test 270g "DoM: default DoM stripe size depends on free space"
19438
19439 test_271a() {
19440         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19441                 skip "Need MDS version at least 2.10.55"
19442
19443         local dom=$DIR/$tdir/dom
19444
19445         mkdir -p $DIR/$tdir
19446
19447         $LFS setstripe -E 1024K -L mdt $dom
19448
19449         lctl set_param -n mdc.*.stats=clear
19450         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
19451         cat $dom > /dev/null
19452         local reads=$(lctl get_param -n mdc.*.stats | grep -c ost_read)
19453         [ $reads -eq 0 ] || error "Unexpected $reads READ RPCs"
19454         ls $dom
19455         rm -f $dom
19456 }
19457 run_test 271a "DoM: data is cached for read after write"
19458
19459 test_271b() {
19460         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19461                 skip "Need MDS version at least 2.10.55"
19462
19463         local dom=$DIR/$tdir/dom
19464
19465         mkdir -p $DIR/$tdir
19466
19467         $LFS setstripe -E 1024K -L mdt -E EOF $dom
19468
19469         lctl set_param -n mdc.*.stats=clear
19470         dd if=/dev/zero of=$dom bs=4096 count=1 || return 1
19471         cancel_lru_locks mdc
19472         $CHECKSTAT -t file -s 4096 $dom || error "stat #1 fails"
19473         # second stat to check size is cached on client
19474         $CHECKSTAT -t file -s 4096 $dom || error "stat #2 fails"
19475         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
19476         [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
19477         rm -f $dom
19478 }
19479 run_test 271b "DoM: no glimpse RPC for stat (DoM only file)"
19480
19481 test_271ba() {
19482         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19483                 skip "Need MDS version at least 2.10.55"
19484
19485         local dom=$DIR/$tdir/dom
19486
19487         mkdir -p $DIR/$tdir
19488
19489         $LFS setstripe -E 1024K -L mdt -E EOF $dom
19490
19491         lctl set_param -n mdc.*.stats=clear
19492         lctl set_param -n osc.*.stats=clear
19493         dd if=/dev/zero of=$dom bs=2048K count=1 || return 1
19494         cancel_lru_locks mdc
19495         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
19496         # second stat to check size is cached on client
19497         $CHECKSTAT -t file -s 2097152 $dom || error "stat"
19498         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
19499         [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
19500         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
19501         [ $gls == 0 ] || error "Unexpected $gls OSC glimpse RPCs"
19502         rm -f $dom
19503 }
19504 run_test 271ba "DoM: no glimpse RPC for stat (combined file)"
19505
19506
19507 get_mdc_stats() {
19508         local mdtidx=$1
19509         local param=$2
19510         local mdt=MDT$(printf %04x $mdtidx)
19511
19512         if [ -z $param ]; then
19513                 lctl get_param -n mdc.*$mdt*.stats
19514         else
19515                 lctl get_param -n mdc.*$mdt*.stats | awk "/$param/"'{print $2}'
19516         fi
19517 }
19518
19519 test_271c() {
19520         [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
19521                 skip "Need MDS version at least 2.10.55"
19522
19523         local dom=$DIR/$tdir/dom
19524
19525         mkdir -p $DIR/$tdir
19526
19527         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19528
19529         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
19530         local facet=mds$((mdtidx + 1))
19531
19532         cancel_lru_locks mdc
19533         do_facet $facet lctl set_param -n mdt.*.dom_lock=0
19534         createmany -o $dom 1000
19535         lctl set_param -n mdc.*.stats=clear
19536         smalliomany -w $dom 1000 200
19537         get_mdc_stats $mdtidx
19538         local enq=$(get_mdc_stats $mdtidx ldlm_ibits_enqueue)
19539         # Each file has 1 open, 1 IO enqueues, total 2000
19540         # but now we have also +1 getxattr for security.capability, total 3000
19541         [ $enq -ge 2000 ] || error "Too few enqueues $enq, expected > 2000"
19542         unlinkmany $dom 1000
19543
19544         cancel_lru_locks mdc
19545         do_facet $facet lctl set_param -n mdt.*.dom_lock=1
19546         createmany -o $dom 1000
19547         lctl set_param -n mdc.*.stats=clear
19548         smalliomany -w $dom 1000 200
19549         local enq_2=$(get_mdc_stats $mdtidx ldlm_ibits_enqueue)
19550         # Expect to see reduced amount of RPCs by 1000 due to single enqueue
19551         # for OPEN and IO lock.
19552         [ $((enq - enq_2)) -ge 1000 ] ||
19553                 error "Too many enqueues $enq_2, expected about $((enq - 1000))"
19554         unlinkmany $dom 1000
19555         return 0
19556 }
19557 run_test 271c "DoM: IO lock at open saves enqueue RPCs"
19558
19559 cleanup_271def_tests() {
19560         trap 0
19561         rm -f $1
19562 }
19563
19564 test_271d() {
19565         [ $MDS1_VERSION -lt $(version_code 2.10.57) ] &&
19566                 skip "Need MDS version at least 2.10.57"
19567
19568         local dom=$DIR/$tdir/dom
19569         local tmp=$TMP/$tfile
19570         trap "cleanup_271def_tests $tmp" EXIT
19571
19572         mkdir -p $DIR/$tdir
19573
19574         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19575
19576         local mdtidx=$($LFS getstripe --mdt-index $DIR/$tdir)
19577
19578         cancel_lru_locks mdc
19579         dd if=/dev/urandom of=$tmp bs=1000 count=1
19580         dd if=$tmp of=$dom bs=1000 count=1
19581         cancel_lru_locks mdc
19582
19583         cat /etc/hosts >> $tmp
19584         lctl set_param -n mdc.*.stats=clear
19585
19586         # append data to the same file it should update local page
19587         echo "Append to the same page"
19588         cat /etc/hosts >> $dom
19589         local num=$(get_mdc_stats $mdtidx ost_read)
19590         local ra=$(get_mdc_stats $mdtidx req_active)
19591         local rw=$(get_mdc_stats $mdtidx req_waittime)
19592
19593         [ -z $num ] || error "$num READ RPC occured"
19594         [ $ra == $rw ] || error "$((ra - rw)) resend occured"
19595         echo "... DONE"
19596
19597         # compare content
19598         cmp $tmp $dom || error "file miscompare"
19599
19600         cancel_lru_locks mdc
19601         lctl set_param -n mdc.*.stats=clear
19602
19603         echo "Open and read file"
19604         cat $dom > /dev/null
19605         local num=$(get_mdc_stats $mdtidx ost_read)
19606         local ra=$(get_mdc_stats $mdtidx req_active)
19607         local rw=$(get_mdc_stats $mdtidx req_waittime)
19608
19609         [ -z $num ] || error "$num READ RPC occured"
19610         [ $ra == $rw ] || error "$((ra - rw)) resend occured"
19611         echo "... DONE"
19612
19613         # compare content
19614         cmp $tmp $dom || error "file miscompare"
19615
19616         return 0
19617 }
19618 run_test 271d "DoM: read on open (1K file in reply buffer)"
19619
19620 test_271f() {
19621         [ $MDS1_VERSION -lt $(version_code 2.10.57) ] &&
19622                 skip "Need MDS version at least 2.10.57"
19623
19624         local dom=$DIR/$tdir/dom
19625         local tmp=$TMP/$tfile
19626         trap "cleanup_271def_tests $tmp" EXIT
19627
19628         mkdir -p $DIR/$tdir
19629
19630         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
19631
19632         local mdtidx=$($LFS getstripe --mdt-index $DIR/$tdir)
19633
19634         cancel_lru_locks mdc
19635         dd if=/dev/urandom of=$tmp bs=265000 count=1
19636         dd if=$tmp of=$dom bs=265000 count=1
19637         cancel_lru_locks mdc
19638         cat /etc/hosts >> $tmp
19639         lctl set_param -n mdc.*.stats=clear
19640
19641         echo "Append to the same page"
19642         cat /etc/hosts >> $dom
19643         local num=$(get_mdc_stats $mdtidx ost_read)
19644         local ra=$(get_mdc_stats $mdtidx req_active)
19645         local rw=$(get_mdc_stats $mdtidx req_waittime)
19646
19647         [ -z $num ] || error "$num READ RPC occured"
19648         [ $ra == $rw ] || error "$((ra - rw)) resend occured"
19649         echo "... DONE"
19650
19651         # compare content
19652         cmp $tmp $dom || error "file miscompare"
19653
19654         cancel_lru_locks mdc
19655         lctl set_param -n mdc.*.stats=clear
19656
19657         echo "Open and read file"
19658         cat $dom > /dev/null
19659         local num=$(get_mdc_stats $mdtidx ost_read)
19660         local ra=$(get_mdc_stats $mdtidx req_active)
19661         local rw=$(get_mdc_stats $mdtidx req_waittime)
19662
19663         [ -z $num ] && num=0
19664         [ $num -eq 1 ] || error "expect 1 READ RPC, $num occured"
19665         [ $ra == $rw ] || error "$((ra - rw)) resend occured"
19666         echo "... DONE"
19667
19668         # compare content
19669         cmp $tmp $dom || error "file miscompare"
19670
19671         return 0
19672 }
19673 run_test 271f "DoM: read on open (200K file and read tail)"
19674
19675 test_271g() {
19676         [[ $($LCTL get_param mdc.*.import) =~ async_discard ]] ||
19677                 skip "Skipping due to old client or server version"
19678
19679         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
19680         # to get layout
19681         $CHECKSTAT -t file $DIR1/$tfile
19682
19683         $MULTIOP $DIR1/$tfile Ow40960_w4096c &
19684         MULTIOP_PID=$!
19685         sleep 1
19686         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE
19687         $LCTL set_param fail_loc=0x80000314
19688         rm $DIR1/$tfile || error "Unlink fails"
19689         RC=$?
19690         kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
19691         [ $RC -eq 0 ] || error "Failed write to stale object"
19692 }
19693 run_test 271g "Discard DoM data vs client flush race"
19694
19695 test_272a() {
19696         [ $MDS1_VERSION -lt $(version_code 2.11.50) ] &&
19697                 skip "Need MDS version at least 2.11.50"
19698
19699         local dom=$DIR/$tdir/dom
19700         mkdir -p $DIR/$tdir
19701
19702         $LFS setstripe -E 256K -L mdt -E -1 -c1 $dom
19703         dd if=/dev/urandom of=$dom bs=512K count=1 ||
19704                 error "failed to write data into $dom"
19705         local old_md5=$(md5sum $dom)
19706
19707         $LFS migrate -E 256K -L mdt -E -1 -c2 $dom ||
19708                 error "failed to migrate to the same DoM component"
19709
19710         local new_md5=$(md5sum $dom)
19711
19712         [ "$old_md5" == "$new_md5" ] ||
19713                 error "md5sum differ: $old_md5, $new_md5"
19714
19715         [ $($LFS getstripe -c $dom) -eq 2 ] ||
19716                 error "bad final stripe count: $($LFS getstripe -c $dom) != 2"
19717 }
19718 run_test 272a "DoM migration: new layout with the same DOM component"
19719
19720 test_272b() {
19721         [ $MDS1_VERSION -lt $(version_code 2.11.50) ] &&
19722                 skip "Need MDS version at least 2.11.50"
19723
19724         local dom=$DIR/$tdir/dom
19725         mkdir -p $DIR/$tdir
19726         $LFS setstripe -E 1M -L mdt -E -1 -c1 $dom
19727
19728         local mdtidx=$($LFS getstripe -m $dom)
19729         local mdtname=MDT$(printf %04x $mdtidx)
19730         local facet=mds$((mdtidx + 1))
19731
19732         local mdtfree1=$(do_facet $facet \
19733                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19734         dd if=/dev/urandom of=$dom bs=2M count=1 ||
19735                 error "failed to write data into $dom"
19736         local old_md5=$(md5sum $dom)
19737         cancel_lru_locks mdc
19738         local mdtfree1=$(do_facet $facet \
19739                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19740
19741         $LFS migrate -c2 $dom ||
19742                 error "failed to migrate to the new composite layout"
19743         [ $($LFS getstripe -L $dom) != 'mdt' ] ||
19744                 error "MDT stripe was not removed"
19745
19746         cancel_lru_locks mdc
19747         local new_md5=$(md5sum $dom)
19748         [ "$old_md5" == "$new_md5" ] ||
19749                 error "$old_md5 != $new_md5"
19750
19751         # Skip free space checks with ZFS
19752         if [ "$(facet_fstype $facet)" != "zfs" ]; then
19753                 local mdtfree2=$(do_facet $facet \
19754                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19755                 [ $mdtfree2 -gt $mdtfree1 ] ||
19756                         error "MDT space is not freed after migration"
19757         fi
19758         return 0
19759 }
19760 run_test 272b "DoM migration: DOM file to the OST-striped file (plain)"
19761
19762 test_272c() {
19763         [ $MDS1_VERSION -lt $(version_code 2.11.50) ] &&
19764                 skip "Need MDS version at least 2.11.50"
19765
19766         local dom=$DIR/$tdir/$tfile
19767         mkdir -p $DIR/$tdir
19768         $LFS setstripe -E 1M -L mdt -E -1 -c1 $dom
19769
19770         local mdtidx=$($LFS getstripe -m $dom)
19771         local mdtname=MDT$(printf %04x $mdtidx)
19772         local facet=mds$((mdtidx + 1))
19773
19774         dd if=/dev/urandom of=$dom bs=2M count=1 oflag=direct ||
19775                 error "failed to write data into $dom"
19776         local old_md5=$(md5sum $dom)
19777         cancel_lru_locks mdc
19778         local mdtfree1=$(do_facet $facet \
19779                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19780
19781         $LFS migrate -E 2M -c1 -E -1 -c2 $dom ||
19782                 error "failed to migrate to the new composite layout"
19783         [ $($LFS getstripe -L $dom) == 'mdt' ] &&
19784                 error "MDT stripe was not removed"
19785
19786         cancel_lru_locks mdc
19787         local new_md5=$(md5sum $dom)
19788         [ "$old_md5" == "$new_md5" ] ||
19789                 error "$old_md5 != $new_md5"
19790
19791         # Skip free space checks with ZFS
19792         if [ "$(facet_fstype $facet)" != "zfs" ]; then
19793                 local mdtfree2=$(do_facet $facet \
19794                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19795                 [ $mdtfree2 -gt $mdtfree1 ] ||
19796                         error "MDS space is not freed after migration"
19797         fi
19798         return 0
19799 }
19800 run_test 272c "DoM migration: DOM file to the OST-striped file (composite)"
19801
19802 test_272d() {
19803         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
19804                 skip "Need MDS version at least 2.12.55"
19805
19806         local dom=$DIR/$tdir/$tfile
19807         mkdir -p $DIR/$tdir
19808         $LFS setstripe -E 1M -L mdt -E -1 -c1 $dom
19809
19810         local mdtidx=$($LFS getstripe -m $dom)
19811         local mdtname=MDT$(printf %04x $mdtidx)
19812         local facet=mds$((mdtidx + 1))
19813
19814         dd if=/dev/urandom of=$dom bs=2M count=1 oflag=direct ||
19815                 error "failed to write data into $dom"
19816         local old_md5=$(md5sum $dom)
19817         cancel_lru_locks mdc
19818         local mdtfree1=$(do_facet $facet \
19819                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19820
19821         $LFS mirror extend -N -E 2M -c1 -E -1 -c2 $dom ||
19822                 error "failed mirroring to the new composite layout"
19823         $LFS mirror resync $dom ||
19824                 error "failed mirror resync"
19825         $LFS mirror split --mirror-id 1 -d $dom ||
19826                 error "failed mirror split"
19827
19828         [ $($LFS getstripe -L $dom) != 'mdt' ] ||
19829                 error "MDT stripe was not removed"
19830
19831         cancel_lru_locks mdc
19832         local new_md5=$(md5sum $dom)
19833         [ "$old_md5" == "$new_md5" ] ||
19834                 error "$old_md5 != $new_md5"
19835
19836         # Skip free space checks with ZFS
19837         if [ "$(facet_fstype $facet)" != "zfs" ]; then
19838                 local mdtfree2=$(do_facet $facet \
19839                                 lctl get_param -n osd*.*$mdtname.kbytesfree)
19840                 [ $mdtfree2 -gt $mdtfree1 ] ||
19841                         error "MDS space is not freed after DOM mirror deletion"
19842         fi
19843         return 0
19844 }
19845 run_test 272d "DoM mirroring: OST-striped mirror to DOM file"
19846
19847 test_272e() {
19848         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
19849                 skip "Need MDS version at least 2.12.55"
19850
19851         local dom=$DIR/$tdir/$tfile
19852         mkdir -p $DIR/$tdir
19853         $LFS setstripe -c 2 $dom
19854
19855         dd if=/dev/urandom of=$dom bs=512K count=1 oflag=direct ||
19856                 error "failed to write data into $dom"
19857         local old_md5=$(md5sum $dom)
19858         cancel_lru_locks mdc
19859
19860         $LFS mirror extend -N -E 1M -L mdt -E eof -c2 $dom ||
19861                 error "failed mirroring to the DOM layout"
19862         $LFS mirror resync $dom ||
19863                 error "failed mirror resync"
19864         $LFS mirror split --mirror-id 1 -d $dom ||
19865                 error "failed mirror split"
19866
19867         [ $($LFS getstripe -L $dom) != 'mdt' ] ||
19868                 error "MDT stripe was not removed"
19869
19870         cancel_lru_locks mdc
19871         local new_md5=$(md5sum $dom)
19872         [ "$old_md5" == "$new_md5" ] ||
19873                 error "$old_md5 != $new_md5"
19874
19875         return 0
19876 }
19877 run_test 272e "DoM mirroring: DOM mirror to the OST-striped file"
19878
19879 test_272f() {
19880         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
19881                 skip "Need MDS version at least 2.12.55"
19882
19883         local dom=$DIR/$tdir/$tfile
19884         mkdir -p $DIR/$tdir
19885         $LFS setstripe -c 2 $dom
19886
19887         dd if=/dev/urandom of=$dom bs=512K count=1 oflag=direct ||
19888                 error "failed to write data into $dom"
19889         local old_md5=$(md5sum $dom)
19890         cancel_lru_locks mdc
19891
19892         $LFS migrate -E 1M -L mdt -E eof -c2 -v $dom ||
19893                 error "failed migrating to the DOM file"
19894
19895         cancel_lru_locks mdc
19896         local new_md5=$(md5sum $dom)
19897         [ "$old_md5" != "$new_md5" ] &&
19898                 error "$old_md5 != $new_md5"
19899
19900         return 0
19901 }
19902 run_test 272f "DoM migration: OST-striped file to DOM file"
19903
19904 test_273a() {
19905         [ $MDS1_VERSION -lt $(version_code 2.11.50) ] &&
19906                 skip "Need MDS version at least 2.11.50"
19907
19908         # Layout swap cannot be done if either file has DOM component,
19909         # this will never be supported, migration should be used instead
19910
19911         local dom=$DIR/$tdir/$tfile
19912         mkdir -p $DIR/$tdir
19913
19914         $LFS setstripe -c2 ${dom}_plain
19915         $LFS setstripe -E 1M -L mdt -E -1 -c2 ${dom}_dom
19916         $LFS swap_layouts ${dom}_plain ${dom}_dom &&
19917                 error "can swap layout with DoM component"
19918         $LFS swap_layouts ${dom}_dom ${dom}_plain &&
19919                 error "can swap layout with DoM component"
19920
19921         $LFS setstripe -E 1M -c1 -E -1 -c2 ${dom}_comp
19922         $LFS swap_layouts ${dom}_comp ${dom}_dom &&
19923                 error "can swap layout with DoM component"
19924         $LFS swap_layouts ${dom}_dom ${dom}_comp &&
19925                 error "can swap layout with DoM component"
19926         return 0
19927 }
19928 run_test 273a "DoM: layout swapping should fail with DOM"
19929
19930 test_275() {
19931         remote_ost_nodsh && skip "remote OST with nodsh"
19932         [ $OST1_VERSION -lt $(version_code 2.10.57) ] &&
19933                 skip "Need OST version >= 2.10.57"
19934
19935         local file=$DIR/$tfile
19936         local oss
19937
19938         oss=$(comma_list $(osts_nodes))
19939
19940         dd if=/dev/urandom of=$file bs=1M count=2 ||
19941                 error "failed to create a file"
19942         cancel_lru_locks osc
19943
19944         #lock 1
19945         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
19946                 error "failed to read a file"
19947
19948 #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
19949         $LCTL set_param fail_loc=0x8000031f
19950
19951         cancel_lru_locks osc &
19952         sleep 1
19953
19954 #define OBD_FAIL_LDLM_PROLONG_PAUSE      0x32b
19955         do_nodes $oss $LCTL set_param fail_loc=0x8000032b
19956         #IO takes another lock, but matches the PENDING one
19957         #and places it to the IO RPC
19958         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
19959                 error "failed to read a file with PENDING lock"
19960 }
19961 run_test 275 "Read on a canceled duplicate lock"
19962
19963 test_276() {
19964         remote_ost_nodsh && skip "remote OST with nodsh"
19965         local pid
19966
19967         do_facet ost1 "(while true; do \
19968                 $LCTL get_param obdfilter.*.filesfree > /dev/null 2>&1; \
19969                 done) & pid=\\\$!; echo \\\$pid > $TMP/sanity_276_pid" &
19970         pid=$!
19971
19972         for LOOP in $(seq 20); do
19973                 stop ost1
19974                 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
19975         done
19976         kill -9 $pid
19977         do_facet ost1 "pid=\\\$(cat $TMP/sanity_276_pid); kill -9 \\\$pid; \
19978                 rm $TMP/sanity_276_pid"
19979 }
19980 run_test 276 "Race between mount and obd_statfs"
19981
19982 test_277() {
19983         $LCTL set_param ldlm.namespaces.*.lru_size=0
19984         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
19985         local cached_mb=$($LCTL get_param llite.*.max_cached_mb |
19986                         grep ^used_mb | awk '{print $2}')
19987         [ $cached_mb -eq 1 ] || error "expected mb 1 got $cached_mb"
19988         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 \
19989                 oflag=direct conv=notrunc
19990         cached_mb=$($LCTL get_param llite.*.max_cached_mb |
19991                         grep ^used_mb | awk '{print $2}')
19992         [ $cached_mb -eq 0 ] || error "expected mb 0 got $cached_mb"
19993 }
19994 run_test 277 "Direct IO shall drop page cache"
19995
19996 test_278() {
19997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
19998         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
19999         [[ "$(facet_host mds1)" != "$(facet_host mds2)" ]] &&
20000                 skip "needs the same host for mdt1 mdt2" && return
20001
20002         local pid1
20003         local pid2
20004
20005 #define OBD_FAIL_OBD_STOP_MDS_RACE     0x60b
20006         do_facet mds2 $LCTL set_param fail_loc=0x8000060c
20007         stop mds2 &
20008         pid2=$!
20009
20010         stop mds1
20011
20012         echo "Starting MDTs"
20013         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
20014         wait $pid2
20015 #For the error assertion will happen. lu_env_get_key(..., &mdt_thread_key)
20016 #will return NULL
20017         do_facet mds2 $LCTL set_param fail_loc=0
20018
20019         start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS
20020         wait_recovery_complete mds2
20021 }
20022 run_test 278 "Race starting MDS between MDTs stop/start"
20023
20024 test_280() {
20025         [ $MGS_VERSION -lt $(version_code 2.13.52) ] &&
20026                 skip "Need MGS version at least 2.13.52"
20027         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20028         combined_mgs_mds || skip "needs combined MGS/MDT"
20029
20030         umount_client $MOUNT
20031 #define OBD_FAIL_MDS_LLOG_UMOUNT_RACE   0x15e
20032         do_facet mgs $LCTL set_param fail_loc=0x8000015e fail_val=0
20033
20034         mount_client $MOUNT &
20035         sleep 1
20036         stop mgs || error "stop mgs failed"
20037         #for a race mgs would crash
20038         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
20039         mount_client $MOUNT || error "mount client failed"
20040 }
20041 run_test 280 "Race between MGS umount and client llog processing"
20042
20043 cleanup_test_300() {
20044         trap 0
20045         umask $SAVE_UMASK
20046 }
20047 test_striped_dir() {
20048         local mdt_index=$1
20049         local stripe_count
20050         local stripe_index
20051
20052         mkdir -p $DIR/$tdir
20053
20054         SAVE_UMASK=$(umask)
20055         trap cleanup_test_300 RETURN EXIT
20056
20057         $LFS setdirstripe -i $mdt_index -c 2 -H all_char -o 755 \
20058                                                 $DIR/$tdir/striped_dir ||
20059                 error "set striped dir error"
20060
20061         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
20062         [ "$mode" = "755" ] || error "expect 755 got $mode"
20063
20064         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
20065                 error "getdirstripe failed"
20066         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
20067         if [ "$stripe_count" != "2" ]; then
20068                 error "1:stripe_count is $stripe_count, expect 2"
20069         fi
20070         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
20071         if [ "$stripe_count" != "2" ]; then
20072                 error "2:stripe_count is $stripe_count, expect 2"
20073         fi
20074
20075         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
20076         if [ "$stripe_index" != "$mdt_index" ]; then
20077                 error "stripe_index is $stripe_index, expect $mdt_index"
20078         fi
20079
20080         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
20081                 error "nlink error after create striped dir"
20082
20083         mkdir $DIR/$tdir/striped_dir/a
20084         mkdir $DIR/$tdir/striped_dir/b
20085
20086         stat $DIR/$tdir/striped_dir/a ||
20087                 error "create dir under striped dir failed"
20088         stat $DIR/$tdir/striped_dir/b ||
20089                 error "create dir under striped dir failed"
20090
20091         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
20092                 error "nlink error after mkdir"
20093
20094         rmdir $DIR/$tdir/striped_dir/a
20095         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
20096                 error "nlink error after rmdir"
20097
20098         rmdir $DIR/$tdir/striped_dir/b
20099         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
20100                 error "nlink error after rmdir"
20101
20102         chattr +i $DIR/$tdir/striped_dir
20103         createmany -o $DIR/$tdir/striped_dir/f 10 &&
20104                 error "immutable flags not working under striped dir!"
20105         chattr -i $DIR/$tdir/striped_dir
20106
20107         rmdir $DIR/$tdir/striped_dir ||
20108                 error "rmdir striped dir error"
20109
20110         cleanup_test_300
20111
20112         true
20113 }
20114
20115 test_300a() {
20116         [ $MDS1_VERSION -lt $(version_code 2.7.0) ] &&
20117                 skip "skipped for lustre < 2.7.0"
20118         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20119         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20120
20121         test_striped_dir 0 || error "failed on striped dir on MDT0"
20122         test_striped_dir 1 || error "failed on striped dir on MDT0"
20123 }
20124 run_test 300a "basic striped dir sanity test"
20125
20126 test_300b() {
20127         [ $MDS1_VERSION -lt $(version_code 2.7.0) ] &&
20128                 skip "skipped for lustre < 2.7.0"
20129         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20130         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20131
20132         local i
20133         local mtime1
20134         local mtime2
20135         local mtime3
20136
20137         test_mkdir $DIR/$tdir || error "mkdir fail"
20138         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
20139                 error "set striped dir error"
20140         for i in {0..9}; do
20141                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
20142                 sleep 1
20143                 touch $DIR/$tdir/striped_dir/file_$i || error "touch error $i"
20144                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
20145                 [ $mtime1 -eq $mtime2 ] && error "mtime unchanged after create"
20146                 sleep 1
20147                 rm -f $DIR/$tdir/striped_dir/file_$i || error "unlink error $i"
20148                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
20149                 [ $mtime2 -eq $mtime3 ] && error "mtime unchanged after unlink"
20150         done
20151         true
20152 }
20153 run_test 300b "check ctime/mtime for striped dir"
20154
20155 test_300c() {
20156         [ $MDS1_VERSION -lt $(version_code 2.7.0) ] &&
20157                 skip "skipped for lustre < 2.7.0"
20158         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20159         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20160
20161         local file_count
20162
20163         mkdir -p $DIR/$tdir
20164         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
20165                 error "set striped dir error"
20166
20167         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
20168                 error "chown striped dir failed"
20169
20170         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
20171                 error "create 5k files failed"
20172
20173         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
20174
20175         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
20176
20177         rm -rf $DIR/$tdir
20178 }
20179 run_test 300c "chown && check ls under striped directory"
20180
20181 test_300d() {
20182         [ $MDS1_VERSION -lt $(version_code 2.7.0) ] &&
20183                 skip "skipped for lustre < 2.7.0"
20184         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20185         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20186
20187         local stripe_count
20188         local file
20189
20190         mkdir -p $DIR/$tdir
20191         $LFS setstripe -c 2 $DIR/$tdir
20192
20193         #local striped directory
20194         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
20195                 error "set striped dir error"
20196         #look at the directories for debug purposes
20197         ls -l $DIR/$tdir
20198         $LFS getdirstripe $DIR/$tdir
20199         ls -l $DIR/$tdir/striped_dir
20200         $LFS getdirstripe $DIR/$tdir/striped_dir
20201         createmany -o $DIR/$tdir/striped_dir/f 10 ||
20202                 error "create 10 files failed"
20203
20204         #remote striped directory
20205         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
20206                 error "set striped dir error"
20207         #look at the directories for debug purposes
20208         ls -l $DIR/$tdir
20209         $LFS getdirstripe $DIR/$tdir
20210         ls -l $DIR/$tdir/remote_striped_dir
20211         $LFS getdirstripe $DIR/$tdir/remote_striped_dir
20212         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
20213                 error "create 10 files failed"
20214
20215         for file in $(find $DIR/$tdir); do
20216                 stripe_count=$($LFS getstripe -c $file)
20217                 [ $stripe_count -eq 2 ] ||
20218                         error "wrong stripe $stripe_count for $file"
20219         done
20220
20221         rm -rf $DIR/$tdir
20222 }
20223 run_test 300d "check default stripe under striped directory"
20224
20225 test_300e() {
20226         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20227                 skip "Need MDS version at least 2.7.55"
20228         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20229         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20230
20231         local stripe_count
20232         local file
20233
20234         mkdir -p $DIR/$tdir
20235
20236         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
20237                 error "set striped dir error"
20238
20239         touch $DIR/$tdir/striped_dir/a
20240         touch $DIR/$tdir/striped_dir/b
20241         touch $DIR/$tdir/striped_dir/c
20242
20243         mkdir $DIR/$tdir/striped_dir/dir_a
20244         mkdir $DIR/$tdir/striped_dir/dir_b
20245         mkdir $DIR/$tdir/striped_dir/dir_c
20246
20247         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_a ||
20248                 error "set striped adir under striped dir error"
20249
20250         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
20251                 error "set striped bdir under striped dir error"
20252
20253         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_c ||
20254                 error "set striped cdir under striped dir error"
20255
20256         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
20257                 error "rename dir under striped dir fails"
20258
20259         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
20260                 error "rename dir under different stripes fails"
20261
20262         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
20263                 error "rename file under striped dir should succeed"
20264
20265         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
20266                 error "rename dir under striped dir should succeed"
20267
20268         rm -rf $DIR/$tdir
20269 }
20270 run_test 300e "check rename under striped directory"
20271
20272 test_300f() {
20273         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20274         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20275         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20276                 skip "Need MDS version at least 2.7.55"
20277
20278         local stripe_count
20279         local file
20280
20281         rm -rf $DIR/$tdir
20282         mkdir -p $DIR/$tdir
20283
20284         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
20285                 error "set striped dir error"
20286
20287         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir1 ||
20288                 error "set striped dir error"
20289
20290         touch $DIR/$tdir/striped_dir/a
20291         mkdir $DIR/$tdir/striped_dir/dir_a
20292         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
20293                 error "create striped dir under striped dir fails"
20294
20295         touch $DIR/$tdir/striped_dir1/b
20296         mkdir $DIR/$tdir/striped_dir1/dir_b
20297         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
20298                 error "create striped dir under striped dir fails"
20299
20300         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
20301                 error "rename dir under different striped dir should fail"
20302
20303         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
20304                 error "rename striped dir under diff striped dir should fail"
20305
20306         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
20307                 error "rename file under diff striped dirs fails"
20308
20309         rm -rf $DIR/$tdir
20310 }
20311 run_test 300f "check rename cross striped directory"
20312
20313 test_300_check_default_striped_dir()
20314 {
20315         local dirname=$1
20316         local default_count=$2
20317         local default_index=$3
20318         local stripe_count
20319         local stripe_index
20320         local dir_stripe_index
20321         local dir
20322
20323         echo "checking $dirname $default_count $default_index"
20324         $LFS setdirstripe -D -c $default_count -i $default_index \
20325                                 -t all_char $DIR/$tdir/$dirname ||
20326                 error "set default stripe on striped dir error"
20327         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
20328         [ $stripe_count -eq $default_count ] ||
20329                 error "expect $default_count get $stripe_count for $dirname"
20330
20331         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
20332         [ $stripe_index -eq $default_index ] ||
20333                 error "expect $default_index get $stripe_index for $dirname"
20334
20335         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
20336                                                 error "create dirs failed"
20337
20338         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
20339         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
20340         for dir in $(find $DIR/$tdir/$dirname/*); do
20341                 stripe_count=$($LFS getdirstripe -c $dir)
20342                 [ $stripe_count -eq $default_count ] ||
20343                 [ $stripe_count -eq 0 ] || [ $default_count -eq 1 ] ||
20344                 error "stripe count $default_count != $stripe_count for $dir"
20345
20346                 stripe_index=$($LFS getdirstripe -i $dir)
20347                 [ $default_index -eq -1 ] ||
20348                         [ $stripe_index -eq $default_index ] ||
20349                         error "$stripe_index != $default_index for $dir"
20350
20351                 #check default stripe
20352                 stripe_count=$($LFS getdirstripe -D -c $dir)
20353                 [ $stripe_count -eq $default_count ] ||
20354                 error "default count $default_count != $stripe_count for $dir"
20355
20356                 stripe_index=$($LFS getdirstripe -D -i $dir)
20357                 [ $stripe_index -eq $default_index ] ||
20358                 error "default index $default_index != $stripe_index for $dir"
20359         done
20360         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
20361 }
20362
20363 test_300g() {
20364         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20365         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20366                 skip "Need MDS version at least 2.7.55"
20367
20368         local dir
20369         local stripe_count
20370         local stripe_index
20371
20372         mkdir $DIR/$tdir
20373         mkdir $DIR/$tdir/normal_dir
20374
20375         #Checking when client cache stripe index
20376         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
20377         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
20378                 error "create striped_dir failed"
20379
20380         $LFS setdirstripe -i0 $DIR/$tdir/striped_dir/dir0 ||
20381                 error "create dir0 fails"
20382         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir0)
20383         [ $stripe_index -eq 0 ] ||
20384                 error "dir0 expect index 0 got $stripe_index"
20385
20386         mkdir $DIR/$tdir/striped_dir/dir1 ||
20387                 error "create dir1 fails"
20388         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
20389         [ $stripe_index -eq 1 ] ||
20390                 error "dir1 expect index 1 got $stripe_index"
20391
20392         #check default stripe count/stripe index
20393         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
20394         test_300_check_default_striped_dir normal_dir 1 0
20395         test_300_check_default_striped_dir normal_dir 2 1
20396         test_300_check_default_striped_dir normal_dir 2 -1
20397
20398         #delete default stripe information
20399         echo "delete default stripeEA"
20400         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
20401                 error "set default stripe on striped dir error"
20402
20403         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
20404         for dir in $(find $DIR/$tdir/normal_dir/*); do
20405                 stripe_count=$($LFS getdirstripe -c $dir)
20406                 [ $stripe_count -eq 0 ] ||
20407                         error "expect 1 get $stripe_count for $dir"
20408                 stripe_index=$($LFS getdirstripe -i $dir)
20409                 [ $stripe_index -eq 0 ] ||
20410                         error "expect 0 get $stripe_index for $dir"
20411         done
20412 }
20413 run_test 300g "check default striped directory for normal directory"
20414
20415 test_300h() {
20416         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20417         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20418                 skip "Need MDS version at least 2.7.55"
20419
20420         local dir
20421         local stripe_count
20422
20423         mkdir $DIR/$tdir
20424         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
20425                 error "set striped dir error"
20426
20427         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
20428         test_300_check_default_striped_dir striped_dir 1 0
20429         test_300_check_default_striped_dir striped_dir 2 1
20430         test_300_check_default_striped_dir striped_dir 2 -1
20431
20432         #delete default stripe information
20433         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
20434                 error "set default stripe on striped dir error"
20435
20436         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
20437         for dir in $(find $DIR/$tdir/striped_dir/*); do
20438                 stripe_count=$($LFS getdirstripe -c $dir)
20439                 [ $stripe_count -eq 0 ] ||
20440                         error "expect 1 get $stripe_count for $dir"
20441         done
20442 }
20443 run_test 300h "check default striped directory for striped directory"
20444
20445 test_300i() {
20446         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20447         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20448         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20449                 skip "Need MDS version at least 2.7.55"
20450
20451         local stripe_count
20452         local file
20453
20454         mkdir $DIR/$tdir
20455
20456         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
20457                 error "set striped dir error"
20458
20459         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
20460                 error "create files under striped dir failed"
20461
20462         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
20463                 error "set striped hashdir error"
20464
20465         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
20466                 error "create dir0 under hash dir failed"
20467         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
20468                 error "create dir1 under hash dir failed"
20469
20470         # unfortunately, we need to umount to clear dir layout cache for now
20471         # once we fully implement dir layout, we can drop this
20472         umount_client $MOUNT || error "umount failed"
20473         mount_client $MOUNT || error "mount failed"
20474
20475         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
20476         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
20477         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
20478
20479         #set the stripe to be unknown hash type
20480         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
20481         $LCTL set_param fail_loc=0x1901
20482         for ((i = 0; i < 10; i++)); do
20483                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
20484                         error "stat f-$i failed"
20485                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
20486         done
20487
20488         touch $DIR/$tdir/striped_dir/f0 &&
20489                 error "create under striped dir with unknown hash should fail"
20490
20491         $LCTL set_param fail_loc=0
20492
20493         umount_client $MOUNT || error "umount failed"
20494         mount_client $MOUNT || error "mount failed"
20495
20496         return 0
20497 }
20498 run_test 300i "client handle unknown hash type striped directory"
20499
20500 test_300j() {
20501         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20502         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20503         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20504                 skip "Need MDS version at least 2.7.55"
20505
20506         local stripe_count
20507         local file
20508
20509         mkdir $DIR/$tdir
20510
20511         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
20512         $LCTL set_param fail_loc=0x1702
20513         $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
20514                 error "set striped dir error"
20515
20516         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
20517                 error "create files under striped dir failed"
20518
20519         $LCTL set_param fail_loc=0
20520
20521         rm -rf $DIR/$tdir || error "unlink striped dir fails"
20522
20523         return 0
20524 }
20525 run_test 300j "test large update record"
20526
20527 test_300k() {
20528         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20529         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20530         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20531                 skip "Need MDS version at least 2.7.55"
20532
20533         # this test needs a huge transaction
20534         local kb
20535         kb=$(do_facet $SINGLEMDS "$LCTL get_param -n \
20536              osd*.$FSNAME-MDT0000.kbytestotal")
20537         [ $kb -lt $((1024*1024)) ] && skip "MDT0 too small: $kb"
20538
20539         local stripe_count
20540         local file
20541
20542         mkdir $DIR/$tdir
20543
20544         #define OBD_FAIL_LARGE_STRIPE   0x1703
20545         $LCTL set_param fail_loc=0x1703
20546         $LFS setdirstripe -i 0 -c192 $DIR/$tdir/striped_dir ||
20547                 error "set striped dir error"
20548         $LCTL set_param fail_loc=0
20549
20550         $LFS getdirstripe $DIR/$tdir/striped_dir ||
20551                 error "getstripeddir fails"
20552         rm -rf $DIR/$tdir/striped_dir ||
20553                 error "unlink striped dir fails"
20554
20555         return 0
20556 }
20557 run_test 300k "test large striped directory"
20558
20559 test_300l() {
20560         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20561         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20562         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20563                 skip "Need MDS version at least 2.7.55"
20564
20565         local stripe_index
20566
20567         test_mkdir -p $DIR/$tdir/striped_dir
20568         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
20569                         error "chown $RUNAS_ID failed"
20570         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
20571                 error "set default striped dir failed"
20572
20573         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
20574         $LCTL set_param fail_loc=0x80000158
20575         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
20576
20577         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
20578         [ $stripe_index -eq 1 ] ||
20579                 error "expect 1 get $stripe_index for $dir"
20580 }
20581 run_test 300l "non-root user to create dir under striped dir with stale layout"
20582
20583 test_300m() {
20584         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20585         [ $MDSCOUNT -ge 2 ] && skip_env "Only for single MDT"
20586         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20587                 skip "Need MDS version at least 2.7.55"
20588
20589         mkdir -p $DIR/$tdir/striped_dir
20590         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
20591                 error "set default stripes dir error"
20592
20593         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
20594
20595         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
20596         [ $stripe_count -eq 0 ] ||
20597                         error "expect 0 get $stripe_count for a"
20598
20599         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
20600                 error "set default stripes dir error"
20601
20602         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
20603
20604         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
20605         [ $stripe_count -eq 0 ] ||
20606                         error "expect 0 get $stripe_count for b"
20607
20608         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
20609                 error "set default stripes dir error"
20610
20611         mkdir $DIR/$tdir/striped_dir/c &&
20612                 error "default stripe_index is invalid, mkdir c should fails"
20613
20614         rm -rf $DIR/$tdir || error "rmdir fails"
20615 }
20616 run_test 300m "setstriped directory on single MDT FS"
20617
20618 cleanup_300n() {
20619         local list=$(comma_list $(mdts_nodes))
20620
20621         trap 0
20622         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
20623 }
20624
20625 test_300n() {
20626         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20627         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20628         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20629                 skip "Need MDS version at least 2.7.55"
20630         remote_mds_nodsh && skip "remote MDS with nodsh"
20631
20632         local stripe_index
20633         local list=$(comma_list $(mdts_nodes))
20634
20635         trap cleanup_300n RETURN EXIT
20636         mkdir -p $DIR/$tdir
20637         chmod 777 $DIR/$tdir
20638         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
20639                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
20640                 error "create striped dir succeeds with gid=0"
20641
20642         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
20643         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
20644                 error "create striped dir fails with gid=-1"
20645
20646         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
20647         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
20648                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
20649                 error "set default striped dir succeeds with gid=0"
20650
20651
20652         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
20653         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
20654                 error "set default striped dir fails with gid=-1"
20655
20656
20657         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
20658         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
20659                                         error "create test_dir fails"
20660         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
20661                                         error "create test_dir1 fails"
20662         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
20663                                         error "create test_dir2 fails"
20664         cleanup_300n
20665 }
20666 run_test 300n "non-root user to create dir under striped dir with default EA"
20667
20668 test_300o() {
20669         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20670         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20671         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20672                 skip "Need MDS version at least 2.7.55"
20673
20674         local numfree1
20675         local numfree2
20676
20677         mkdir -p $DIR/$tdir
20678
20679         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
20680         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
20681         if [ $numfree1 -lt 66000 ] || [ $numfree2 -lt 66000 ]; then
20682                 skip "not enough free inodes $numfree1 $numfree2"
20683         fi
20684
20685         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
20686         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
20687         if [ $numfree1 -lt 300000 ] || [ $numfree2 -lt 300000 ]; then
20688                 skip "not enough free space $numfree1 $numfree2"
20689         fi
20690
20691         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
20692                 error "setdirstripe fails"
20693
20694         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
20695                 error "create dirs fails"
20696
20697         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
20698         ls $DIR/$tdir/striped_dir > /dev/null ||
20699                 error "ls striped dir fails"
20700         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
20701                 error "unlink big striped dir fails"
20702 }
20703 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
20704
20705 test_300p() {
20706         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20707         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20708         remote_mds_nodsh && skip "remote MDS with nodsh"
20709
20710         mkdir -p $DIR/$tdir
20711
20712         #define OBD_FAIL_OUT_ENOSPC     0x1704
20713         do_facet mds2 lctl set_param fail_loc=0x80001704
20714         $LFS setdirstripe -i 0 -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 \
20715                  && error "create striped directory should fail"
20716
20717         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
20718
20719         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
20720         true
20721 }
20722 run_test 300p "create striped directory without space"
20723
20724 test_300q() {
20725         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20726         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
20727
20728         local fd=$(free_fd)
20729         local cmd="exec $fd<$tdir"
20730         cd $DIR
20731         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
20732         eval $cmd
20733         cmd="exec $fd<&-"
20734         trap "eval $cmd" EXIT
20735         cd $tdir || error "cd $tdir fails"
20736         rmdir  ../$tdir || error "rmdir $tdir fails"
20737         mkdir local_dir && error "create dir succeeds"
20738         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
20739         eval $cmd
20740         return 0
20741 }
20742 run_test 300q "create remote directory under orphan directory"
20743
20744 test_300r() {
20745         [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
20746                 skip "Need MDS version at least 2.7.55" && return
20747         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
20748
20749         mkdir $DIR/$tdir
20750
20751         $LFS setdirstripe -i 0 -c -1 $DIR/$tdir/striped_dir ||
20752                 error "set striped dir error"
20753
20754         $LFS getdirstripe $DIR/$tdir/striped_dir ||
20755                 error "getstripeddir fails"
20756
20757         local stripe_count
20758         stripe_count=$($LFS getdirstripe $DIR/$tdir/striped_dir |
20759                       awk '/lmv_stripe_count:/ { print $2 }')
20760
20761         [ $MDSCOUNT -ne $stripe_count ] &&
20762                 error "wrong stripe count $stripe_count expected $MDSCOUNT"
20763
20764         rm -rf $DIR/$tdir/striped_dir ||
20765                 error "unlink striped dir fails"
20766 }
20767 run_test 300r "test -1 striped directory"
20768
20769 prepare_remote_file() {
20770         mkdir $DIR/$tdir/src_dir ||
20771                 error "create remote source failed"
20772
20773         cp /etc/hosts $DIR/$tdir/src_dir/a ||
20774                  error "cp to remote source failed"
20775         touch $DIR/$tdir/src_dir/a
20776
20777         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
20778                 error "create remote target dir failed"
20779
20780         touch $DIR/$tdir/tgt_dir/b
20781
20782         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
20783                 error "rename dir cross MDT failed!"
20784
20785         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
20786                 error "src_child still exists after rename"
20787
20788         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
20789                 error "missing file(a) after rename"
20790
20791         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
20792                 error "diff after rename"
20793 }
20794
20795 test_310a() {
20796         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 4 MDTs"
20797         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20798
20799         local remote_file=$DIR/$tdir/tgt_dir/b
20800
20801         mkdir -p $DIR/$tdir
20802
20803         prepare_remote_file || error "prepare remote file failed"
20804
20805         #open-unlink file
20806         $OPENUNLINK $remote_file $remote_file ||
20807                 error "openunlink $remote_file failed"
20808         $CHECKSTAT -a $remote_file || error "$remote_file exists"
20809 }
20810 run_test 310a "open unlink remote file"
20811
20812 test_310b() {
20813         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 4 MDTs"
20814         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20815
20816         local remote_file=$DIR/$tdir/tgt_dir/b
20817
20818         mkdir -p $DIR/$tdir
20819
20820         prepare_remote_file || error "prepare remote file failed"
20821
20822         ln $remote_file $DIR/$tfile || error "link failed for remote file"
20823         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
20824         $CHECKSTAT -t file $remote_file || error "check file failed"
20825 }
20826 run_test 310b "unlink remote file with multiple links while open"
20827
20828 test_310c() {
20829         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20830         [[ $MDSCOUNT -lt 4 ]] && skip_env "needs >= 4 MDTs"
20831
20832         local remote_file=$DIR/$tdir/tgt_dir/b
20833
20834         mkdir -p $DIR/$tdir
20835
20836         prepare_remote_file || error "prepare remote file failed"
20837
20838         ln $remote_file $DIR/$tfile || error "link failed for remote file"
20839         multiop_bg_pause $remote_file O_uc ||
20840                         error "mulitop failed for remote file"
20841         MULTIPID=$!
20842         $MULTIOP $DIR/$tfile Ouc
20843         kill -USR1 $MULTIPID
20844         wait $MULTIPID
20845 }
20846 run_test 310c "open-unlink remote file with multiple links"
20847
20848 #LU-4825
20849 test_311() {
20850         [ $PARALLEL == "yes" ] && skip "skip parallel run"
20851         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
20852         [ $MDS1_VERSION -lt $(version_code 2.8.54) ] &&
20853                 skip "lustre < 2.8.54 does not contain LU-4825 fix"
20854         remote_mds_nodsh && skip "remote MDS with nodsh"
20855
20856         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
20857         local mdts=$(comma_list $(mdts_nodes))
20858
20859         mkdir -p $DIR/$tdir
20860         $LFS setstripe -i 0 -c 1 $DIR/$tdir
20861         createmany -o $DIR/$tdir/$tfile. 1000
20862
20863         # statfs data is not real time, let's just calculate it
20864         old_iused=$((old_iused + 1000))
20865
20866         local count=$(do_facet $SINGLEMDS "$LCTL get_param -n \
20867                         osp.*OST0000*MDT0000.create_count")
20868         local max_count=$(do_facet $SINGLEMDS "$LCTL get_param -n \
20869                                 osp.*OST0000*MDT0000.max_create_count")
20870         do_nodes $mdts "$LCTL set_param -n osp.*OST0000*.max_create_count=0"
20871
20872         $LFS setstripe -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
20873         local index=$($LFS getstripe -i $DIR/$tdir/$tfile)
20874         [ $index -ne 0 ] || error "$tfile stripe index is 0"
20875
20876         unlinkmany $DIR/$tdir/$tfile. 1000
20877
20878         do_nodes $mdts "$LCTL set_param -n \
20879                         osp.*OST0000*.max_create_count=$max_count"
20880         [ $MDS1_VERSION -lt $(version_code 2.12.51) ] &&
20881                 do_nodes $mdts "$LCTL set_param -n \
20882                                 osp.*OST0000*.create_count=$count"
20883         do_nodes $mdts "$LCTL get_param osp.*OST0000*.create_count" |
20884                         grep "=0" && error "create_count is zero"
20885
20886         local new_iused
20887         for i in $(seq 120); do
20888                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
20889                 # system may be too busy to destroy all objs in time, use
20890                 # a somewhat small value to not fail autotest
20891                 [ $((old_iused - new_iused)) -gt 400 ] && break
20892                 sleep 1
20893         done
20894
20895         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
20896         [ $((old_iused - new_iused)) -gt 400 ] ||
20897                 error "objs not destroyed after unlink"
20898 }
20899 run_test 311 "disable OSP precreate, and unlink should destroy objs"
20900
20901 zfs_oid_to_objid()
20902 {
20903         local ost=$1
20904         local objid=$2
20905
20906         local vdevdir=$(dirname $(facet_vdevice $ost))
20907         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
20908         local zfs_zapid=$(do_facet $ost $cmd |
20909                           grep -w "/O/0/d$((objid%32))" -C 5 |
20910                           awk '/Object/{getline; print $1}')
20911         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
20912                           awk "/$objid = /"'{printf $3}')
20913
20914         echo $zfs_objid
20915 }
20916
20917 zfs_object_blksz() {
20918         local ost=$1
20919         local objid=$2
20920
20921         local vdevdir=$(dirname $(facet_vdevice $ost))
20922         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
20923         local blksz=$(do_facet $ost $cmd $objid |
20924                       awk '/dblk/{getline; printf $4}')
20925
20926         case "${blksz: -1}" in
20927                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
20928                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
20929                 *) ;;
20930         esac
20931
20932         echo $blksz
20933 }
20934
20935 test_312() { # LU-4856
20936         remote_ost_nodsh && skip "remote OST with nodsh"
20937         [ "$ost1_FSTYPE" = "zfs" ] ||
20938                 skip_env "the test only applies to zfs"
20939
20940         local max_blksz=$(do_facet ost1 \
20941                           $ZFS get -p recordsize $(facet_device ost1) |
20942                           awk '!/VALUE/{print $3}')
20943
20944         # to make life a little bit easier
20945         $LFS mkdir -c 1 -i 0 $DIR/$tdir
20946         $LFS setstripe -c 1 -i 0 $DIR/$tdir
20947
20948         local tf=$DIR/$tdir/$tfile
20949         touch $tf
20950         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
20951
20952         # Get ZFS object id
20953         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
20954         # block size change by sequential overwrite
20955         local bs
20956
20957         for ((bs=$PAGE_SIZE; bs <= max_blksz; bs *= 4)) ; do
20958                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
20959
20960                 local blksz=$(zfs_object_blksz ost1 $zfs_objid)
20961                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
20962         done
20963         rm -f $tf
20964
20965         # block size change by sequential append write
20966         dd if=/dev/zero of=$tf bs=$PAGE_SIZE count=1 oflag=sync conv=notrunc
20967         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
20968         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
20969         local count
20970
20971         for ((count = 1; count < $((max_blksz / PAGE_SIZE)); count *= 2)); do
20972                 dd if=/dev/zero of=$tf bs=$PAGE_SIZE count=$count seek=$count \
20973                         oflag=sync conv=notrunc
20974
20975                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
20976                 [ $blksz -eq $((2 * count * PAGE_SIZE)) ] ||
20977                         error "blksz error, actual $blksz, " \
20978                                 "expected: 2 * $count * $PAGE_SIZE"
20979         done
20980         rm -f $tf
20981
20982         # random write
20983         touch $tf
20984         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
20985         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
20986
20987         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
20988         blksz=$(zfs_object_blksz ost1 $zfs_objid)
20989         [ $blksz -eq $PAGE_SIZE ] ||
20990                 error "blksz error: $blksz, expected: $PAGE_SIZE"
20991
20992         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
20993         blksz=$(zfs_object_blksz ost1 $zfs_objid)
20994         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
20995
20996         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
20997         blksz=$(zfs_object_blksz ost1 $zfs_objid)
20998         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
20999 }
21000 run_test 312 "make sure ZFS adjusts its block size by write pattern"
21001
21002 test_313() {
21003         remote_ost_nodsh && skip "remote OST with nodsh"
21004
21005         local file=$DIR/$tfile
21006
21007         rm -f $file
21008         $LFS setstripe -c 1 -i 0 $file || error "setstripe failed"
21009
21010         # define OBD_FAIL_TGT_RCVD_EIO           0x720
21011         do_facet ost1 "$LCTL set_param fail_loc=0x720"
21012         dd if=/dev/zero of=$file bs=$PAGE_SIZE oflag=direct count=1 &&
21013                 error "write should failed"
21014         do_facet ost1 "$LCTL set_param fail_loc=0"
21015         rm -f $file
21016 }
21017 run_test 313 "io should fail after last_rcvd update fail"
21018
21019 test_314() {
21020         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
21021
21022         $LFS setstripe -c 2 -i 0 $DIR/$tfile || error "setstripe failed"
21023         do_facet ost1 "$LCTL set_param fail_loc=0x720"
21024         rm -f $DIR/$tfile
21025         wait_delete_completed
21026         do_facet ost1 "$LCTL set_param fail_loc=0"
21027 }
21028 run_test 314 "OSP shouldn't fail after last_rcvd update failure"
21029
21030 test_315() { # LU-618
21031         [ -f /proc/$$/io ] || skip_env "no IO accounting in kernel"
21032
21033         local file=$DIR/$tfile
21034         rm -f $file
21035
21036         $MULTIOP $file oO_CREAT:O_DIRECT:O_RDWR:w4063232c ||
21037                 error "multiop file write failed"
21038         $MULTIOP $file oO_RDONLY:r4063232_c &
21039         PID=$!
21040
21041         sleep 2
21042
21043         local rbytes=$(awk '/read_bytes/ { print $2 }' /proc/$PID/io)
21044         kill -USR1 $PID
21045
21046         [ $rbytes -gt 4000000 ] || error "read is not accounted ($rbytes)"
21047         rm -f $file
21048 }
21049 run_test 315 "read should be accounted"
21050
21051 test_316() {
21052         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
21053         large_xattr_enabled || skip_env "ea_inode feature disabled"
21054
21055         rm -rf $DIR/$tdir/d
21056         mkdir -p $DIR/$tdir/d
21057         chown nobody $DIR/$tdir/d
21058         touch $DIR/$tdir/d/file
21059
21060         $LFS mv -m1 $DIR/$tdir/d || error "lfs mv failed"
21061 }
21062 run_test 316 "lfs mv"
21063
21064 test_317() {
21065         [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
21066                 skip "Need MDS version at least 2.11.53"
21067         if [ "$ost1_FSTYPE" == "zfs" ]; then
21068                 skip "LU-10370: no implementation for ZFS"
21069         fi
21070
21071         local trunc_sz
21072         local grant_blk_size
21073
21074         grant_blk_size=$($LCTL get_param osc.$FSNAME*.import |
21075                         awk '/grant_block_size:/ { print $2; exit; }')
21076         #
21077         # Create File of size 5M. Truncate it to below size's and verify
21078         # blocks count.
21079         #
21080         dd if=/dev/zero of=$DIR/$tfile bs=5M count=1 conv=fsync ||
21081                 error "Create file $DIR/$tfile failed"
21082         stack_trap "rm -f $DIR/$tfile" EXIT
21083
21084         for trunc_sz in 2097152 4097 4000 509 0; do
21085                 $TRUNCATE $DIR/$tfile $trunc_sz ||
21086                         error "truncate $tfile to $trunc_sz failed"
21087                 local sz=$(stat --format=%s $DIR/$tfile)
21088                 local blk=$(stat --format=%b $DIR/$tfile)
21089                 local trunc_blk=$((((trunc_sz + (grant_blk_size - 1) ) /
21090                                      grant_blk_size) * 8))
21091
21092                 if [[ $blk -ne $trunc_blk ]]; then
21093                         $(which stat) $DIR/$tfile
21094                         error "Expected Block $trunc_blk got $blk for $tfile"
21095                 fi
21096
21097                 $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
21098                         error "Expected Size $trunc_sz got $sz for $tfile"
21099         done
21100
21101         #
21102         # sparse file test
21103         # Create file with a hole and write actual two blocks. Block count
21104         # must be 16.
21105         #
21106         dd if=/dev/zero of=$DIR/$tfile bs=$grant_blk_size count=2 seek=5 \
21107                 conv=fsync || error "Create file : $DIR/$tfile"
21108
21109         # Calculate the final truncate size.
21110         trunc_sz=$(($(stat --format=%s $DIR/$tfile) - (grant_blk_size + 1)))
21111
21112         #
21113         # truncate to size $trunc_sz bytes. Strip the last block
21114         # The block count must drop to 8
21115         #
21116         $TRUNCATE $DIR/$tfile $trunc_sz ||
21117                 error "truncate $tfile to $trunc_sz failed"
21118
21119         local trunc_bsz=$((grant_blk_size / $(stat --format=%B $DIR/$tfile)))
21120         sz=$(stat --format=%s $DIR/$tfile)
21121         blk=$(stat --format=%b $DIR/$tfile)
21122
21123         if [[ $blk -ne $trunc_bsz ]]; then
21124                 $(which stat) $DIR/$tfile
21125                 error "Expected Block $trunc_bsz got $blk for $tfile"
21126         fi
21127
21128         $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
21129                 error "Expected Size $trunc_sz got $sz for $tfile"
21130 }
21131 run_test 317 "Verify blocks get correctly update after truncate"
21132
21133 test_318() {
21134         local old_max_active=$($LCTL get_param -n \
21135                             llite.*.max_read_ahead_async_active 2>/dev/null)
21136
21137         $LCTL set_param llite.*.max_read_ahead_async_active=256
21138         local max_active=$($LCTL get_param -n \
21139                            llite.*.max_read_ahead_async_active 2>/dev/null)
21140         [ $max_active -ne 256 ] && error "expected 256 but got $max_active"
21141
21142         $LCTL set_param llite.*.max_read_ahead_async_active=0 ||
21143                 error "set max_read_ahead_async_active should succeed"
21144
21145         $LCTL set_param llite.*.max_read_ahead_async_active=512
21146         max_active=$($LCTL get_param -n \
21147                      llite.*.max_read_ahead_async_active 2>/dev/null)
21148         [ $max_active -eq 512 ] || error "expected 512 but got $max_active"
21149
21150         # restore @max_active
21151         [ $old_max_active -ne 0 ] && $LCTL set_param \
21152                 llite.*.max_read_ahead_async_active=$old_max_active
21153
21154         local old_threshold=$($LCTL get_param -n \
21155                 llite.*.read_ahead_async_file_threshold_mb 2>/dev/null)
21156         local max_per_file_mb=$($LCTL get_param -n \
21157                 llite.*.max_read_ahead_per_file_mb 2>/dev/null)
21158
21159         local invalid=$(($max_per_file_mb + 1))
21160         $LCTL set_param \
21161                 llite.*.read_ahead_async_file_threshold_mb=$invalid\
21162                         && error "set $invalid should fail"
21163
21164         local valid=$(($invalid - 1))
21165         $LCTL set_param \
21166                 llite.*.read_ahead_async_file_threshold_mb=$valid ||
21167                         error "set $valid should succeed"
21168         local threshold=$($LCTL get_param -n \
21169                 llite.*.read_ahead_async_file_threshold_mb 2>/dev/null)
21170         [ $threshold -eq $valid ] || error \
21171                 "expect threshold $valid got $threshold"
21172         $LCTL set_param \
21173                 llite.*.read_ahead_async_file_threshold_mb=$old_threshold
21174 }
21175 run_test 318 "Verify async readahead tunables"
21176
21177 test_319() {
21178         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
21179
21180         local before=$(date +%s)
21181         local evict
21182         local mdir=$DIR/$tdir
21183         local file=$mdir/xxx
21184
21185         $LFS mkdir -i0 $mdir || error "mkdir $mdir fails"
21186         touch $file
21187
21188 #define OBD_FAIL_LDLM_LOCAL_CANCEL_PAUSE 0x32c
21189         $LCTL set_param fail_val=5 fail_loc=0x8000032c
21190         $LFS mv -m1 $file &
21191
21192         sleep 1
21193         dd if=$file of=/dev/null
21194         wait
21195         evict=$($LCTL get_param mdc.$FSNAME-MDT*.state |
21196           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
21197
21198         [ -z "$evict" ] || [[ $evict -le $before ]] || error "eviction happened"
21199 }
21200 run_test 319 "lost lease lock on migrate error"
21201
21202 test_398a() { # LU-4198
21203         $LFS setstripe -c 1 -i 0 $DIR/$tfile
21204         $LCTL set_param ldlm.namespaces.*.lru_size=clear
21205
21206         # request a new lock on client
21207         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
21208
21209         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=direct conv=notrunc
21210         local lock_count=$($LCTL get_param -n \
21211                            ldlm.namespaces.*-OST0000-osc-ffff*.lru_size)
21212         [[ $lock_count -eq 0 ]] || error "lock should be cancelled by direct IO"
21213
21214         $LCTL set_param ldlm.namespaces.*-OST0000-osc-ffff*.lru_size=clear
21215
21216         # no lock cached, should use lockless IO and not enqueue new lock
21217         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=direct conv=notrunc
21218         lock_count=$($LCTL get_param -n \
21219                      ldlm.namespaces.*-OST0000-osc-ffff*.lru_size)
21220         [[ $lock_count -eq 0 ]] || error "no lock should be held by direct IO"
21221 }
21222 run_test 398a "direct IO should cancel lock otherwise lockless"
21223
21224 test_398b() { # LU-4198
21225         which fio || skip_env "no fio installed"
21226         $LFS setstripe -c -1 $DIR/$tfile
21227
21228         local size=12
21229         dd if=/dev/zero of=$DIR/$tfile bs=1M count=$size
21230
21231         local njobs=4
21232         echo "mix direct rw ${size}M to OST0 by fio with $njobs jobs..."
21233         fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE --direct=1 \
21234                 --numjobs=$njobs --fallocate=none \
21235                 --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
21236                 --filename=$DIR/$tfile &
21237         bg_pid=$!
21238
21239         echo "mix buffer rw ${size}M to OST0 by fio with $njobs jobs..."
21240         fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE \
21241                 --numjobs=$njobs --fallocate=none \
21242                 --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
21243                 --filename=$DIR/$tfile || true
21244         wait $bg_pid
21245
21246         rm -rf $DIR/$tfile
21247 }
21248 run_test 398b "DIO and buffer IO race"
21249
21250 test_398c() { # LU-4198
21251         which fio || skip_env "no fio installed"
21252
21253         saved_debug=$($LCTL get_param -n debug)
21254         $LCTL set_param debug=0
21255
21256         local size=$(lctl get_param -n osc.$FSNAME-OST0000*.kbytesavail | head -1)
21257         ((size /= 1024)) # by megabytes
21258         ((size /= 2)) # write half of the OST at most
21259         [ $size -gt 40 ] && size=40 #reduce test time anyway
21260
21261         $LFS setstripe -c 1 $DIR/$tfile
21262
21263         # it seems like ldiskfs reserves more space than necessary if the
21264         # writing blocks are not mapped, so it extends the file firstly
21265         dd if=/dev/zero of=$DIR/$tfile bs=1M count=$size && sync
21266         cancel_lru_locks osc
21267
21268         # clear and verify rpc_stats later
21269         $LCTL set_param osc.${FSNAME}-OST0000-osc-ffff*.rpc_stats=clear
21270
21271         local njobs=4
21272         echo "writing ${size}M to OST0 by fio with $njobs jobs..."
21273         fio --name=rand-write --rw=randwrite --bs=$PAGE_SIZE --direct=1 \
21274                 --numjobs=$njobs --fallocate=none --ioengine=libaio \
21275                 --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
21276                 --filename=$DIR/$tfile
21277         [ $? -eq 0 ] || error "fio write error"
21278
21279         [ $($LCTL get_param -n \
21280          ldlm.namespaces.${FSNAME}-OST0000-osc-ffff*.lock_count) -eq 0 ] ||
21281                 error "Locks were requested while doing AIO"
21282
21283         # get the percentage of 1-page I/O
21284         pct=$($LCTL get_param osc.${FSNAME}-OST0000-osc-ffff*.rpc_stats |
21285                 grep -A 1 'pages per rpc' | grep -v 'pages per rpc' |
21286                 awk '{print $7}')
21287         [ $pct -le 50 ] || error "$pct% of I/O are 1-page"
21288
21289         echo "mix rw ${size}M to OST0 by fio with $njobs jobs..."
21290         fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE --direct=1 \
21291                 --numjobs=$njobs --fallocate=none --ioengine=libaio \
21292                 --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
21293                 --filename=$DIR/$tfile
21294         [ $? -eq 0 ] || error "fio mixed read write error"
21295
21296         rm -rf $DIR/$tfile
21297         $LCTL set_param debug="$saved_debug"
21298 }
21299 run_test 398c "run fio to test AIO"
21300
21301 test_fake_rw() {
21302         local read_write=$1
21303         if [ "$read_write" = "write" ]; then
21304                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
21305         elif [ "$read_write" = "read" ]; then
21306                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
21307         else
21308                 error "argument error"
21309         fi
21310
21311         # turn off debug for performance testing
21312         local saved_debug=$($LCTL get_param -n debug)
21313         $LCTL set_param debug=0
21314
21315         $LFS setstripe -c 1 -i 0 $DIR/$tfile
21316
21317         # get ost1 size - $FSNAME-OST0000
21318         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
21319         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
21320         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
21321
21322         if [ "$read_write" = "read" ]; then
21323                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
21324         fi
21325
21326         local start_time=$(date +%s.%N)
21327         $dd_cmd bs=1M count=$blocks oflag=sync ||
21328                 error "real dd $read_write error"
21329         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
21330
21331         if [ "$read_write" = "write" ]; then
21332                 rm -f $DIR/$tfile
21333         fi
21334
21335         # define OBD_FAIL_OST_FAKE_RW           0x238
21336         do_facet ost1 $LCTL set_param fail_loc=0x238
21337
21338         local start_time=$(date +%s.%N)
21339         $dd_cmd bs=1M count=$blocks oflag=sync ||
21340                 error "fake dd $read_write error"
21341         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
21342
21343         if [ "$read_write" = "write" ]; then
21344                 # verify file size
21345                 cancel_lru_locks osc
21346                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
21347                         error "$tfile size not $blocks MB"
21348         fi
21349         do_facet ost1 $LCTL set_param fail_loc=0
21350
21351         echo "fake $read_write $duration_fake vs. normal $read_write" \
21352                 "$duration in seconds"
21353         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
21354                 error_not_in_vm "fake write is slower"
21355
21356         $LCTL set_param -n debug="$saved_debug"
21357         rm -f $DIR/$tfile
21358 }
21359 test_399a() { # LU-7655 for OST fake write
21360         remote_ost_nodsh && skip "remote OST with nodsh"
21361
21362         test_fake_rw write
21363 }
21364 run_test 399a "fake write should not be slower than normal write"
21365
21366 test_399b() { # LU-8726 for OST fake read
21367         remote_ost_nodsh && skip "remote OST with nodsh"
21368         if [ "$ost1_FSTYPE" != "ldiskfs" ]; then
21369                 skip_env "ldiskfs only test"
21370         fi
21371
21372         test_fake_rw read
21373 }
21374 run_test 399b "fake read should not be slower than normal read"
21375
21376 test_400a() { # LU-1606, was conf-sanity test_74
21377         if ! which $CC > /dev/null 2>&1; then
21378                 skip_env "$CC is not installed"
21379         fi
21380
21381         local extra_flags=''
21382         local out=$TMP/$tfile
21383         local prefix=/usr/include/lustre
21384         local prog
21385
21386         # Oleg removes c files in his test rig so test if any c files exist
21387         [ -z "$(ls -A $LUSTRE_TESTS_API_DIR)" ] && \
21388                 skip_env "Needed c test files are missing"
21389
21390         if ! [[ -d $prefix ]]; then
21391                 # Assume we're running in tree and fixup the include path.
21392                 extra_flags+=" -I$LUSTRE/../lnet/include/uapi -I$LUSTRE/include/uapi -I$LUSTRE/include"
21393                 extra_flags+=" -L$LUSTRE/utils/.lib"
21394         fi
21395
21396         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
21397                 $CC -Wall -Werror -std=c99 $extra_flags -o $out $prog -llustreapi ||
21398                         error "client api broken"
21399         done
21400         rm -f $out
21401 }
21402 run_test 400a "Lustre client api program can compile and link"
21403
21404 test_400b() { # LU-1606, LU-5011
21405         local header
21406         local out=$TMP/$tfile
21407         local prefix=/usr/include/linux/lustre
21408
21409         # We use a hard coded prefix so that this test will not fail
21410         # when run in tree. There are headers in lustre/include/lustre/
21411         # that are not packaged (like lustre_idl.h) and have more
21412         # complicated include dependencies (like config.h and lnet/types.h).
21413         # Since this test about correct packaging we just skip them when
21414         # they don't exist (see below) rather than try to fixup cppflags.
21415
21416         if ! which $CC > /dev/null 2>&1; then
21417                 skip_env "$CC is not installed"
21418         fi
21419
21420         for header in $prefix/*.h; do
21421                 if ! [[ -f "$header" ]]; then
21422                         continue
21423                 fi
21424
21425                 if [[ "$(basename $header)" == lustre_ioctl.h ]]; then
21426                         continue # lustre_ioctl.h is internal header
21427                 fi
21428
21429                 $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out ||
21430                         error "cannot compile '$header'"
21431         done
21432         rm -f $out
21433 }
21434 run_test 400b "packaged headers can be compiled"
21435
21436 test_401a() { #LU-7437
21437         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
21438         [ -n "$printf_arg" ] && skip_env "find does not support -printf"
21439
21440         #count the number of parameters by "list_param -R"
21441         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
21442         #count the number of parameters by listing proc files
21443         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
21444         echo "proc_dirs='$proc_dirs'"
21445         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
21446         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
21447                       sort -u | wc -l)
21448
21449         [ $params -eq $procs ] ||
21450                 error "found $params parameters vs. $procs proc files"
21451
21452         # test the list_param -D option only returns directories
21453         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
21454         #count the number of parameters by listing proc directories
21455         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
21456                 sort -u | wc -l)
21457
21458         [ $params -eq $procs ] ||
21459                 error "found $params parameters vs. $procs proc files"
21460 }
21461 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
21462
21463 test_401b() {
21464         local save=$($LCTL get_param -n jobid_var)
21465         local tmp=testing
21466
21467         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
21468                 error "no error returned when setting bad parameters"
21469
21470         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
21471         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
21472
21473         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
21474         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
21475         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
21476 }
21477 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
21478
21479 test_401c() {
21480         local jobid_var_old=$($LCTL get_param -n jobid_var)
21481         local jobid_var_new
21482
21483         $LCTL set_param jobid_var= &&
21484                 error "no error returned for 'set_param a='"
21485
21486         jobid_var_new=$($LCTL get_param -n jobid_var)
21487         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
21488                 error "jobid_var was changed by setting without value"
21489
21490         $LCTL set_param jobid_var &&
21491                 error "no error returned for 'set_param a'"
21492
21493         jobid_var_new=$($LCTL get_param -n jobid_var)
21494         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
21495                 error "jobid_var was changed by setting without value"
21496 }
21497 run_test 401c "Verify 'lctl set_param' without value fails in either format."
21498
21499 test_401d() {
21500         local jobid_var_old=$($LCTL get_param -n jobid_var)
21501         local jobid_var_new
21502         local new_value="foo=bar"
21503
21504         $LCTL set_param jobid_var=$new_value ||
21505                 error "'set_param a=b' did not accept a value containing '='"
21506
21507         jobid_var_new=$($LCTL get_param -n jobid_var)
21508         [[ "$jobid_var_new" == "$new_value" ]] ||
21509                 error "'set_param a=b' failed on a value containing '='"
21510
21511         # Reset the jobid_var to test the other format
21512         $LCTL set_param jobid_var=$jobid_var_old
21513         jobid_var_new=$($LCTL get_param -n jobid_var)
21514         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
21515                 error "failed to reset jobid_var"
21516
21517         $LCTL set_param jobid_var $new_value ||
21518                 error "'set_param a b' did not accept a value containing '='"
21519
21520         jobid_var_new=$($LCTL get_param -n jobid_var)
21521         [[ "$jobid_var_new" == "$new_value" ]] ||
21522                 error "'set_param a b' failed on a value containing '='"
21523
21524         $LCTL set_param jobid_var $jobid_var_old
21525         jobid_var_new=$($LCTL get_param -n jobid_var)
21526         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
21527                 error "failed to reset jobid_var"
21528 }
21529 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
21530
21531 test_402() {
21532         [[ $MDS1_VERSION -ge $(version_code 2.7.66) ]] ||
21533         [[ $MDS1_VERSION -ge $(version_code 2.7.18.4) &&
21534                 $MDS1_VERSION -lt $(version_code 2.7.50) ]] ||
21535         [[ $MDS1_VERSION -ge $(version_code 2.7.2) &&
21536                 $MDS1_VERSION -lt $(version_code 2.7.11) ]] ||
21537                 skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+"
21538         remote_mds_nodsh && skip "remote MDS with nodsh"
21539
21540         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
21541 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
21542         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
21543         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
21544                 echo "Touch failed - OK"
21545 }
21546 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
21547
21548 test_403() {
21549         local file1=$DIR/$tfile.1
21550         local file2=$DIR/$tfile.2
21551         local tfile=$TMP/$tfile
21552
21553         rm -f $file1 $file2 $tfile
21554
21555         touch $file1
21556         ln $file1 $file2
21557
21558         # 30 sec OBD_TIMEOUT in ll_getattr()
21559         # right before populating st_nlink
21560         $LCTL set_param fail_loc=0x80001409
21561         stat -c %h $file1 > $tfile &
21562
21563         # create an alias, drop all locks and reclaim the dentry
21564         < $file2
21565         cancel_lru_locks mdc
21566         cancel_lru_locks osc
21567         sysctl -w vm.drop_caches=2
21568
21569         wait
21570
21571         [ $(cat $tfile) -gt 0 ] || error "wrong nlink count: $(cat $tfile)"
21572
21573         rm -f $tfile $file1 $file2
21574 }
21575 run_test 403 "i_nlink should not drop to zero due to aliasing"
21576
21577 test_404() { # LU-6601
21578         [[ $MDS1_VERSION -ge $(version_code 2.8.53) ]] ||
21579                 skip "Need server version newer than 2.8.52"
21580         remote_mds_nodsh && skip "remote MDS with nodsh"
21581
21582         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
21583                 awk '/osp .*-osc-MDT/ { print $4}')
21584
21585         local osp
21586         for osp in $mosps; do
21587                 echo "Deactivate: " $osp
21588                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
21589                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
21590                         awk -vp=$osp '$4 == p { print $2 }')
21591                 [ $stat = IN ] || {
21592                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
21593                         error "deactivate error"
21594                 }
21595                 echo "Activate: " $osp
21596                 do_facet $SINGLEMDS $LCTL --device %$osp activate
21597                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
21598                         awk -vp=$osp '$4 == p { print $2 }')
21599                 [ $stat = UP ] || {
21600                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
21601                         error "activate error"
21602                 }
21603         done
21604 }
21605 run_test 404 "validate manual {de}activated works properly for OSPs"
21606
21607 test_405() {
21608         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
21609         [ $MDS1_VERSION -lt $(version_code 2.6.92) ] ||
21610                 [ $CLIENT_VERSION -lt $(version_code 2.6.99) ] &&
21611                         skip "Layout swap lock is not supported"
21612
21613         check_swap_layouts_support
21614
21615         test_mkdir $DIR/$tdir
21616         swap_lock_test -d $DIR/$tdir ||
21617                 error "One layout swap locked test failed"
21618 }
21619 run_test 405 "Various layout swap lock tests"
21620
21621 test_406() {
21622         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
21623         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
21624         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
21625         [ $PARALLEL == "yes" ] && skip "skip parallel run"
21626         [ $MDS1_VERSION -lt $(version_code 2.8.50) ] &&
21627                 skip "Need MDS version at least 2.8.50"
21628
21629         local def_stripe_size=$($LFS getstripe -S $MOUNT)
21630         local test_pool=$TESTNAME
21631
21632         pool_add $test_pool || error "pool_add failed"
21633         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
21634                 error "pool_add_targets failed"
21635
21636         save_layout_restore_at_exit $MOUNT
21637
21638         # parent set default stripe count only, child will stripe from both
21639         # parent and fs default
21640         $LFS setstripe -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
21641                 error "setstripe $MOUNT failed"
21642         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
21643         $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
21644         for i in $(seq 10); do
21645                 local f=$DIR/$tdir/$tfile.$i
21646                 touch $f || error "touch failed"
21647                 local count=$($LFS getstripe -c $f)
21648                 [ $count -eq $OSTCOUNT ] ||
21649                         error "$f stripe count $count != $OSTCOUNT"
21650                 local offset=$($LFS getstripe -i $f)
21651                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
21652                 local size=$($LFS getstripe -S $f)
21653                 [ $size -eq $((def_stripe_size * 2)) ] ||
21654                         error "$f stripe size $size != $((def_stripe_size * 2))"
21655                 local pool=$($LFS getstripe -p $f)
21656                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
21657         done
21658
21659         # change fs default striping, delete parent default striping, now child
21660         # will stripe from new fs default striping only
21661         $LFS setstripe -c 1 -S $def_stripe_size -i 0 $MOUNT ||
21662                 error "change $MOUNT default stripe failed"
21663         $LFS setstripe -c 0 $DIR/$tdir ||
21664                 error "delete $tdir default stripe failed"
21665         for i in $(seq 11 20); do
21666                 local f=$DIR/$tdir/$tfile.$i
21667                 touch $f || error "touch $f failed"
21668                 local count=$($LFS getstripe -c $f)
21669                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
21670                 local offset=$($LFS getstripe -i $f)
21671                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
21672                 local size=$($LFS getstripe -S $f)
21673                 [ $size -eq $def_stripe_size ] ||
21674                         error "$f stripe size $size != $def_stripe_size"
21675                 local pool=$($LFS getstripe -p $f)
21676                 [ $pool == $test_pool ] || error "$f pool $pool isn't set"
21677         done
21678
21679         unlinkmany $DIR/$tdir/$tfile. 1 20
21680
21681         local f=$DIR/$tdir/$tfile
21682         pool_remove_all_targets $test_pool $f
21683         pool_remove $test_pool $f
21684 }
21685 run_test 406 "DNE support fs default striping"
21686
21687 test_407() {
21688         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
21689         [[ $MDS1_VERSION -lt $(version_code 2.8.55) ]] &&
21690                 skip "Need MDS version at least 2.8.55"
21691         remote_mds_nodsh && skip "remote MDS with nodsh"
21692
21693         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
21694                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
21695         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
21696                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
21697         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
21698
21699         #define OBD_FAIL_DT_TXN_STOP    0x2019
21700         for idx in $(seq $MDSCOUNT); do
21701                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
21702         done
21703         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
21704         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
21705                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
21706         true
21707 }
21708 run_test 407 "transaction fail should cause operation fail"
21709
21710 test_408() {
21711         dd if=/dev/zero of=$DIR/$tfile bs=$PAGE_SIZE count=1 oflag=direct
21712
21713         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
21714         lctl set_param fail_loc=0x8000040a
21715         # let ll_prepare_partial_page() fail
21716         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
21717
21718         rm -f $DIR/$tfile
21719
21720         # create at least 100 unused inodes so that
21721         # shrink_icache_memory(0) should not return 0
21722         touch $DIR/$tfile-{0..100}
21723         rm -f $DIR/$tfile-{0..100}
21724         sync
21725
21726         echo 2 > /proc/sys/vm/drop_caches
21727 }
21728 run_test 408 "drop_caches should not hang due to page leaks"
21729
21730 test_409()
21731 {
21732         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
21733
21734         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
21735         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
21736         touch $DIR/$tdir/guard || error "(2) Fail to create"
21737
21738         local PREFIX=$(str_repeat 'A' 128)
21739         echo "Create 1K hard links start at $(date)"
21740         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
21741                 error "(3) Fail to hard link"
21742
21743         echo "Links count should be right although linkEA overflow"
21744         stat $DIR/$tdir/guard || error "(4) Fail to stat"
21745         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
21746         [ $linkcount -eq 1001 ] ||
21747                 error "(5) Unexpected hard links count: $linkcount"
21748
21749         echo "List all links start at $(date)"
21750         ls -l $DIR/$tdir/foo > /dev/null ||
21751                 error "(6) Fail to list $DIR/$tdir/foo"
21752
21753         echo "Unlink hard links start at $(date)"
21754         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
21755                 error "(7) Fail to unlink"
21756         echo "Unlink hard links finished at $(date)"
21757 }
21758 run_test 409 "Large amount of cross-MDTs hard links on the same file"
21759
21760 test_410()
21761 {
21762         [[ $CLIENT_VERSION -lt $(version_code 2.9.59) ]] &&
21763                 skip "Need client version at least 2.9.59"
21764
21765         # Create a file, and stat it from the kernel
21766         local testfile=$DIR/$tfile
21767         touch $testfile
21768
21769         local run_id=$RANDOM
21770         local my_ino=$(stat --format "%i" $testfile)
21771
21772         # Try to insert the module. This will always fail as the
21773         # module is designed to not be inserted.
21774         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
21775             &> /dev/null
21776
21777         # Anything but success is a test failure
21778         dmesg | grep -q \
21779             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
21780             error "no inode match"
21781 }
21782 run_test 410 "Test inode number returned from kernel thread"
21783
21784 cleanup_test411_cgroup() {
21785         trap 0
21786         rmdir "$1"
21787 }
21788
21789 test_411() {
21790         local cg_basedir=/sys/fs/cgroup/memory
21791         # LU-9966
21792         test -f "$cg_basedir/memory.kmem.limit_in_bytes" ||
21793                 skip "no setup for cgroup"
21794
21795         dd if=/dev/zero of=$DIR/$tfile bs=1M count=100 conv=fsync ||
21796                 error "test file creation failed"
21797         cancel_lru_locks osc
21798
21799         # Create a very small memory cgroup to force a slab allocation error
21800         local cgdir=$cg_basedir/osc_slab_alloc
21801         mkdir $cgdir || error "cgroup mkdir '$cgdir' failed"
21802         trap "cleanup_test411_cgroup $cgdir" EXIT
21803         echo 2M > $cgdir/memory.kmem.limit_in_bytes
21804         echo 1M > $cgdir/memory.limit_in_bytes
21805
21806         # Should not LBUG, just be killed by oom-killer
21807         # dd will return 0 even allocation failure in some environment.
21808         # So don't check return value
21809         sh -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null"
21810         cleanup_test411_cgroup $cgdir
21811
21812         return 0
21813 }
21814 run_test 411 "Slab allocation error with cgroup does not LBUG"
21815
21816 test_412() {
21817         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
21818         if [ $MDS1_VERSION -lt $(version_code 2.10.55) ]; then
21819                 skip "Need server version at least 2.10.55"
21820         fi
21821
21822         $LFS mkdir -i $((MDSCOUNT - 1)),$((MDSCOUNT - 2)) $DIR/$tdir ||
21823                 error "mkdir failed"
21824         $LFS getdirstripe $DIR/$tdir
21825         local stripe_index=$($LFS getdirstripe -i $DIR/$tdir)
21826         [ $stripe_index -eq $((MDSCOUNT - 1)) ] ||
21827                 error "expect $((MDSCOUT - 1)) get $stripe_index"
21828         local stripe_count=$($LFS getdirstripe -T $DIR/$tdir)
21829         [ $stripe_count -eq 2 ] ||
21830                 error "expect 2 get $stripe_count"
21831 }
21832 run_test 412 "mkdir on specific MDTs"
21833
21834 test_qos_mkdir() {
21835         local mkdir_cmd=$1
21836         local stripe_count=$2
21837         local mdts=$(comma_list $(mdts_nodes))
21838
21839         local testdir
21840         local lmv_qos_prio_free
21841         local lmv_qos_threshold_rr
21842         local lmv_qos_maxage
21843         local lod_qos_prio_free
21844         local lod_qos_threshold_rr
21845         local lod_qos_maxage
21846         local count
21847         local i
21848
21849         lmv_qos_prio_free=$($LCTL get_param -n lmv.*.qos_prio_free | head -n1)
21850         lmv_qos_prio_free=${lmv_qos_prio_free%%%}
21851         lmv_qos_threshold_rr=$($LCTL get_param -n lmv.*.qos_threshold_rr |
21852                 head -n1)
21853         lmv_qos_threshold_rr=${lmv_qos_threshold_rr%%%}
21854         lmv_qos_maxage=$($LCTL get_param -n lmv.*.qos_maxage)
21855         stack_trap "$LCTL set_param \
21856                 lmv.*.qos_prio_free=$lmv_qos_prio_free > /dev/null" EXIT
21857         stack_trap "$LCTL set_param \
21858                 lmv.*.qos_threshold_rr=$lmv_qos_threshold_rr > /dev/null" EXIT
21859         stack_trap "$LCTL set_param \
21860                 lmv.*.qos_maxage=$lmv_qos_maxage > /dev/null" EXIT
21861
21862         lod_qos_prio_free=$(do_facet mds1 $LCTL get_param -n \
21863                 lod.$FSNAME-MDT0000-mdtlov.mdt_qos_prio_free | head -n1)
21864         lod_qos_prio_free=${lod_qos_prio_free%%%}
21865         lod_qos_threshold_rr=$(do_facet mds1 $LCTL get_param -n \
21866                 lod.$FSNAME-MDT0000-mdtlov.mdt_qos_threshold_rr | head -n1)
21867         lod_qos_threshold_rr=${lod_qos_threshold_rr%%%}
21868         lod_qos_maxage=$(do_facet mds1 $LCTL get_param -n \
21869                 lod.$FSNAME-MDT0000-mdtlov.qos_maxage | awk '{ print $1 }')
21870         stack_trap "do_nodes $mdts $LCTL set_param \
21871                 lod.*.mdt_qos_prio_free=$lod_qos_prio_free > /dev/null" EXIT
21872         stack_trap "do_nodes $mdts $LCTL set_param \
21873                 lod.*.mdt_qos_threshold_rr=$lod_qos_threshold_rr > /dev/null" \
21874                 EXIT
21875         stack_trap "do_nodes $mdts $LCTL set_param \
21876                 lod.*.mdt_qos_maxage=$lod_qos_maxage > /dev/null" EXIT
21877
21878         echo
21879         echo "Mkdir (stripe_count $stripe_count) roundrobin:"
21880
21881         $LCTL set_param lmv.*.qos_threshold_rr=100 > /dev/null
21882         do_nodes $mdts $LCTL set_param lod.*.mdt_qos_threshold_rr=100 > /dev/null
21883
21884         testdir=$DIR/$tdir-s$stripe_count/rr
21885
21886         for i in $(seq $((100 * MDSCOUNT))); do
21887                 eval $mkdir_cmd $testdir/subdir$i ||
21888                         error "$mkdir_cmd subdir$i failed"
21889         done
21890
21891         for i in $(seq $MDSCOUNT); do
21892                 count=$($LFS getdirstripe -i $testdir/* |
21893                                 grep ^$((i - 1))$ | wc -l)
21894                 echo "$count directories created on MDT$((i - 1))"
21895                 [ $count -eq 100 ] || error "subdirs are not evenly distributed"
21896
21897                 if [ $stripe_count -gt 1 ]; then
21898                         count=$($LFS getdirstripe $testdir/* |
21899                                 grep -P "^\s+$((i - 1))\t" | wc -l)
21900                         echo "$count stripes created on MDT$((i - 1))"
21901                         # deviation should < 5% of average
21902                         [ $count -lt $((95 * stripe_count)) ] ||
21903                         [ $count -gt $((105 * stripe_count)) ] &&
21904                                 error "stripes are not evenly distributed"
21905                 fi
21906         done
21907
21908         $LCTL set_param lmv.*.qos_threshold_rr=$lmv_qos_threshold_rr > /dev/null
21909         do_nodes $mdts $LCTL set_param \
21910                 lod.*.mdt_qos_threshold_rr=$lod_qos_threshold_rr > /dev/null
21911
21912         echo
21913         echo "Check for uneven MDTs: "
21914
21915         local ffree
21916         local bavail
21917         local max
21918         local min
21919         local max_index
21920         local min_index
21921         local tmp
21922
21923         ffree=($(lctl get_param -n mdc.*[mM][dD][cC]-[^M]*.filesfree))
21924         bavail=($(lctl get_param -n mdc.*[mM][dD][cC]-[^M]*.kbytesavail))
21925         bsize=$(lctl get_param -n mdc.*MDT0000*.blocksize)
21926
21927         max=$(((${ffree[0]} >> 8) * (${bavail[0]} * bsize >> 16)))
21928         min=$(((${ffree[0]} >> 8) * (${bavail[0]} * bsize >> 16)))
21929         max_index=0
21930         min_index=0
21931         for ((i = 1; i < ${#ffree[@]}; i++)); do
21932                 tmp=$(((${ffree[i]} >> 8) * (${bavail[i]} * bsize >> 16)))
21933                 if [ $tmp -gt $max ]; then
21934                         max=$tmp
21935                         max_index=$i
21936                 fi
21937                 if [ $tmp -lt $min ]; then
21938                         min=$tmp
21939                         min_index=$i
21940                 fi
21941         done
21942
21943         [ ${ffree[min_index]} -eq 0 ] &&
21944                 skip "no free files in MDT$min_index"
21945         [ ${ffree[min_index]} -gt 100000000 ] &&
21946                 skip "too much free files in MDT$min_index"
21947
21948         # Check if we need to generate uneven MDTs
21949         local threshold=50
21950         local diff=$(((max - min) * 100 / min))
21951         local value="$(generate_string 1024)"
21952
21953         while [ $diff -lt $threshold ]; do
21954                 # generate uneven MDTs, create till $threshold% diff
21955                 echo -n "weight diff=$diff% must be > $threshold% ..."
21956                 count=$((${ffree[min_index]} / 10))
21957                 # 50 sec per 10000 files in vm
21958                 [ $count -gt 40000 ] && [ "$SLOW" = "no" ] &&
21959                         skip "$count files to create"
21960                 echo "Fill MDT$min_index with $count files"
21961                 [ -d $DIR/$tdir-MDT$min_index ] ||
21962                         $LFS mkdir -i $min_index $DIR/$tdir-MDT$min_index ||
21963                         error "mkdir $tdir-MDT$min_index failed"
21964                 for i in $(seq $count); do
21965                         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE \
21966                                 $DIR/$tdir-MDT$min_index/f$j_$i > /dev/null ||
21967                                 error "create f$j_$i failed"
21968                         setfattr -n user.413b -v $value \
21969                                 $DIR/$tdir-MDT$min_index/f$j_$i ||
21970                                 error "setfattr f$j_$i failed"
21971                 done
21972
21973                 ffree=($(lctl get_param -n mdc.*[mM][dD][cC]-*.filesfree))
21974                 bavail=($(lctl get_param -n mdc.*[mM][dD][cC]-*.kbytesavail))
21975                 max=$(((${ffree[max_index]} >> 8) * \
21976                         (${bavail[max_index]} * bsize >> 16)))
21977                 min=$(((${ffree[min_index]} >> 8) * \
21978                         (${bavail[min_index]} * bsize >> 16)))
21979                 diff=$(((max - min) * 100 / min))
21980         done
21981
21982         echo "MDT filesfree available: ${ffree[@]}"
21983         echo "MDT blocks available: ${bavail[@]}"
21984         echo "weight diff=$diff%"
21985
21986         echo
21987         echo "Mkdir (stripe_count $stripe_count) with balanced space usage:"
21988
21989         $LCTL set_param lmv.*.qos_prio_free=100 > /dev/null
21990         do_nodes $mdts $LCTL set_param lod.*.mdt_qos_prio_free=100 > /dev/null
21991         # decrease statfs age, so that it can be updated in time
21992         $LCTL set_param lmv.*.qos_maxage=1 > /dev/null
21993         do_nodes $mdts $LCTL set_param lod.*.mdt_qos_maxage=1 > /dev/null
21994
21995         sleep 1
21996
21997         testdir=$DIR/$tdir-s$stripe_count/qos
21998
21999         for i in $(seq $((100 * MDSCOUNT))); do
22000                 eval $mkdir_cmd $testdir/subdir$i ||
22001                         error "$mkdir_cmd subdir$i failed"
22002         done
22003
22004         for i in $(seq $MDSCOUNT); do
22005                 count=$($LFS getdirstripe -i $testdir/* | grep ^$((i - 1))$ |
22006                         wc -l)
22007                 echo "$count directories created on MDT$((i - 1))"
22008
22009                 if [ $stripe_count -gt 1 ]; then
22010                         count=$($LFS getdirstripe $testdir/* |
22011                                 grep -P "^\s+$((i - 1))\t" | wc -l)
22012                         echo "$count stripes created on MDT$((i - 1))"
22013                 fi
22014         done
22015
22016         max=$($LFS getdirstripe -i $testdir/* | grep ^$max_index$ | wc -l)
22017         min=$($LFS getdirstripe -i $testdir/* | grep ^$min_index$ | wc -l)
22018
22019         # D-value should > 10% of averge
22020         [ $((max - min)) -lt 10 ] &&
22021                 error "subdirs shouldn't be evenly distributed"
22022
22023         # ditto
22024         if [ $stripe_count -gt 1 ]; then
22025                 max=$($LFS getdirstripe $testdir/* |
22026                         grep -P "^\s+$max_index\t" | wc -l)
22027                 min=$($LFS getdirstripe $testdir/* |
22028                         grep -P "^\s+$min_index\t" | wc -l)
22029                 [ $((max - min)) -le $((10 * stripe_count)) ] &&
22030                         error "stripes shouldn't be evenly distributed"|| true
22031         fi
22032 }
22033
22034 test_413a() {
22035         [ $MDSCOUNT -lt 2 ] &&
22036                 skip "We need at least 2 MDTs for this test"
22037
22038         [ $MDS1_VERSION -lt $(version_code 2.12.52) ] &&
22039                 skip "Need server version at least 2.12.52"
22040
22041         local stripe_count
22042
22043         for stripe_count in $(seq 1 $((MDSCOUNT - 1))); do
22044                 mkdir $DIR/$tdir-s$stripe_count || error "mkdir failed"
22045                 mkdir $DIR/$tdir-s$stripe_count/rr || error "mkdir failed"
22046                 mkdir $DIR/$tdir-s$stripe_count/qos || error "mkdir failed"
22047                 test_qos_mkdir "$LFS mkdir -c $stripe_count" $stripe_count
22048         done
22049 }
22050 run_test 413a "QoS mkdir with 'lfs mkdir -i -1'"
22051
22052 test_413b() {
22053         [ $MDSCOUNT -lt 2 ] &&
22054                 skip "We need at least 2 MDTs for this test"
22055
22056         [ $MDS1_VERSION -lt $(version_code 2.12.52) ] &&
22057                 skip "Need server version at least 2.12.52"
22058
22059         local stripe_count
22060
22061         for stripe_count in $(seq 1 $((MDSCOUNT - 1))); do
22062                 mkdir $DIR/$tdir-s$stripe_count || error "mkdir failed"
22063                 mkdir $DIR/$tdir-s$stripe_count/rr || error "mkdir failed"
22064                 mkdir $DIR/$tdir-s$stripe_count/qos || error "mkdir failed"
22065                 $LFS setdirstripe -D -c $stripe_count \
22066                         $DIR/$tdir-s$stripe_count/rr ||
22067                         error "setdirstripe failed"
22068                 $LFS setdirstripe -D -c $stripe_count \
22069                         $DIR/$tdir-s$stripe_count/qos ||
22070                         error "setdirstripe failed"
22071                 test_qos_mkdir "mkdir" $stripe_count
22072         done
22073 }
22074 run_test 413b "QoS mkdir under dir whose default LMV starting MDT offset is -1"
22075
22076 test_414() {
22077 #define OBD_FAIL_PTLRPC_BULK_ATTACH      0x521
22078         $LCTL set_param fail_loc=0x80000521
22079         dd if=/dev/zero of=$DIR/$tfile bs=2M count=1 oflag=sync
22080         rm -f $DIR/$tfile
22081 }
22082 run_test 414 "simulate ENOMEM in ptlrpc_register_bulk()"
22083
22084 test_415() {
22085         [ $PARALLEL == "yes" ] && skip "skip parallel run"
22086         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
22087                 skip "Need server version at least 2.11.52"
22088
22089         # LU-11102
22090         local total
22091         local setattr_pid
22092         local start_time
22093         local end_time
22094         local duration
22095
22096         total=500
22097         # this test may be slow on ZFS
22098         [ "$mds1_FSTYPE" == "zfs" ] && total=100
22099
22100         # though this test is designed for striped directory, let's test normal
22101         # directory too since lock is always saved as CoS lock.
22102         test_mkdir $DIR/$tdir || error "mkdir $tdir"
22103         createmany -o $DIR/$tdir/$tfile. $total || error "createmany"
22104
22105         (
22106                 while true; do
22107                         touch $DIR/$tdir
22108                 done
22109         ) &
22110         setattr_pid=$!
22111
22112         start_time=$(date +%s)
22113         for i in $(seq $total); do
22114                 mrename $DIR/$tdir/$tfile.$i $DIR/$tdir/$tfile-new.$i \
22115                         > /dev/null
22116         done
22117         end_time=$(date +%s)
22118         duration=$((end_time - start_time))
22119
22120         kill -9 $setattr_pid
22121
22122         echo "rename $total files took $duration sec"
22123         [ $duration -lt 100 ] || error "rename took $duration sec"
22124 }
22125 run_test 415 "lock revoke is not missing"
22126
22127 test_416() {
22128         [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
22129                 skip "Need server version at least 2.11.55"
22130
22131         # define OBD_FAIL_OSD_TXN_START    0x19a
22132         do_facet mds1 lctl set_param fail_loc=0x19a
22133
22134         lfs mkdir -c $MDSCOUNT $DIR/$tdir
22135
22136         true
22137 }
22138 run_test 416 "transaction start failure won't cause system hung"
22139
22140 cleanup_417() {
22141         trap 0
22142         do_nodes $(comma_list $(mdts_nodes)) \
22143                 "$LCTL set_param -n mdt.*MDT*.enable_dir_migration=1"
22144         do_nodes $(comma_list $(mdts_nodes)) \
22145                 "$LCTL set_param -n mdt.*MDT*.enable_remote_dir=1"
22146         do_nodes $(comma_list $(mdts_nodes)) \
22147                 "$LCTL set_param -n mdt.*MDT*.enable_striped_dir=1"
22148 }
22149
22150 test_417() {
22151         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
22152         [[ $MDS1_VERSION -lt $(version_code 2.11.56) ]] &&
22153                 skip "Need MDS version at least 2.11.56"
22154
22155         trap cleanup_417 RETURN EXIT
22156
22157         $LFS mkdir -i 1 $DIR/$tdir.1 || error "create remote dir $tdir.1 failed"
22158         do_nodes $(comma_list $(mdts_nodes)) \
22159                 "$LCTL set_param -n mdt.*MDT*.enable_dir_migration=0"
22160         $LFS migrate -m 0 $DIR/$tdir.1 &&
22161                 error "migrate dir $tdir.1 should fail"
22162
22163         do_nodes $(comma_list $(mdts_nodes)) \
22164                 "$LCTL set_param -n mdt.*MDT*.enable_remote_dir=0"
22165         $LFS mkdir -i 1 $DIR/$tdir.2 &&
22166                 error "create remote dir $tdir.2 should fail"
22167
22168         do_nodes $(comma_list $(mdts_nodes)) \
22169                 "$LCTL set_param -n mdt.*MDT*.enable_striped_dir=0"
22170         $LFS mkdir -c 2 $DIR/$tdir.3 &&
22171                 error "create striped dir $tdir.3 should fail"
22172         true
22173 }
22174 run_test 417 "disable remote dir, striped dir and dir migration"
22175
22176 # Checks that the outputs of df [-i] and lfs df [-i] match
22177 #
22178 # usage: check_lfs_df <blocks | inodes> <mountpoint>
22179 check_lfs_df() {
22180         local dir=$2
22181         local inodes
22182         local df_out
22183         local lfs_df_out
22184         local count
22185         local passed=false
22186
22187         # blocks or inodes
22188         [ "$1" == "blocks" ] && inodes= || inodes="-i"
22189
22190         for count in {1..100}; do
22191                 cancel_lru_locks
22192                 sync; sleep 0.2
22193
22194                 # read the lines of interest
22195                 df_out=($(df -P $inodes $dir | tail -n +2)) ||
22196                         error "df $inodes $dir | tail -n +2 failed"
22197                 lfs_df_out=($($LFS df $inodes $dir | grep summary:)) ||
22198                         error "lfs df $inodes $dir | grep summary: failed"
22199
22200                 # skip first substrings of each output as they are different
22201                 # "<NID>:/<fsname>" for df, "filesystem_summary:" for lfs df
22202                 # compare the two outputs
22203                 passed=true
22204                 for i in {1..5}; do
22205                         [ "${df_out[i]}" != "${lfs_df_out[i]}" ] && passed=false
22206                 done
22207                 $passed && break
22208         done
22209
22210         if ! $passed; then
22211                 df -P $inodes $dir
22212                 echo
22213                 lfs df $inodes $dir
22214                 error "df and lfs df $1 output mismatch: "      \
22215                       "df ${inodes}: ${df_out[*]}, "            \
22216                       "lfs df ${inodes}: ${lfs_df_out[*]}"
22217         fi
22218 }
22219
22220 test_418() {
22221         [ $PARALLEL == "yes" ] && skip "skip parallel run"
22222
22223         local dir=$DIR/$tdir
22224         local numfiles=$((RANDOM % 4096 + 2))
22225         local numblocks=$((RANDOM % 256 + 1))
22226
22227         wait_delete_completed
22228         test_mkdir $dir
22229
22230         # check block output
22231         check_lfs_df blocks $dir
22232         # check inode output
22233         check_lfs_df inodes $dir
22234
22235         # create a single file and retest
22236         echo "Creating a single file and testing"
22237         createmany -o $dir/$tfile- 1 &>/dev/null ||
22238                 error "creating 1 file in $dir failed"
22239         check_lfs_df blocks $dir
22240         check_lfs_df inodes $dir
22241
22242         # create a random number of files
22243         echo "Creating $((numfiles - 1)) files and testing"
22244         createmany -o $dir/$tfile- 1 $((numfiles - 1)) &>/dev/null ||
22245                 error "creating $((numfiles - 1)) files in $dir failed"
22246
22247         # write a random number of blocks to the first test file
22248         echo "Writing $numblocks 4K blocks and testing"
22249         dd if=/dev/urandom of=$dir/${tfile}-0 bs=4K conv=fsync \
22250                 count=$numblocks &>/dev/null ||
22251                 error "dd to $dir/${tfile}-0 failed"
22252
22253         # retest
22254         check_lfs_df blocks $dir
22255         check_lfs_df inodes $dir
22256
22257         unlinkmany $dir/$tfile- $numfiles &>/dev/null ||
22258                 error "unlinking $numfiles files in $dir failed"
22259 }
22260 run_test 418 "df and lfs df outputs match"
22261
22262 test_419()
22263 {
22264         local dir=$DIR/$tdir
22265
22266         mkdir -p $dir
22267         touch $dir/file
22268
22269         cancel_lru_locks mdc
22270
22271         #OBD_FAIL_LLITE_OPEN_BY_NAME    0x1410
22272         $LCTL set_param fail_loc=0x1410
22273         cat $dir/file
22274         $LCTL set_param fail_loc=0
22275         rm -rf $dir
22276 }
22277 run_test 419 "Verify open file by name doesn't crash kernel"
22278
22279 test_420()
22280 {
22281         [[ $MDS1_VERSION -ge $(version_code 2.12.53) ]] ||
22282                 skip "Need MDS version at least 2.12.53"
22283
22284         local SAVE_UMASK=$(umask)
22285         local dir=$DIR/$tdir
22286         local uname=$(getent passwd $RUNAS_ID | cut -d: -f1)
22287
22288         mkdir -p $dir
22289         umask 0000
22290         mkdir -m03777 $dir/testdir
22291         ls -dn $dir/testdir
22292         # Need to remove trailing '.' when SELinux is enabled
22293         local dirperms=$(ls -dn $dir/testdir |
22294                          awk '{ sub(/\.$/, "", $1); print $1}')
22295         [ $dirperms == "drwxrwsrwt" ] ||
22296                 error "incorrect perms on $dir/testdir"
22297
22298         su - $uname -c "PATH=$LUSTRE/tests:\$PATH; \
22299                 openfile -f O_RDONLY:O_CREAT -m 02755 $dir/testdir/testfile"
22300         ls -n $dir/testdir/testfile
22301         local fileperms=$(ls -n $dir/testdir/testfile |
22302                           awk '{ sub(/\.$/, "", $1); print $1}')
22303         [ $fileperms == "-rwxr-xr-x" ] ||
22304                 error "incorrect perms on $dir/testdir/testfile"
22305
22306         umask $SAVE_UMASK
22307 }
22308 run_test 420 "clear SGID bit on non-directories for non-members"
22309
22310 test_421a() {
22311         local cnt
22312         local fid1
22313         local fid2
22314
22315         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22316                 skip "Need MDS version at least 2.12.54"
22317
22318         test_mkdir $DIR/$tdir
22319         createmany -o $DIR/$tdir/f 3
22320         cnt=$(ls -1 $DIR/$tdir | wc -l)
22321         [ $cnt != 3 ] && error "unexpected #files: $cnt"
22322
22323         fid1=$(lfs path2fid $DIR/$tdir/f1)
22324         fid2=$(lfs path2fid $DIR/$tdir/f2)
22325         $LFS rmfid $DIR $fid1 $fid2 || error "rmfid failed"
22326
22327         stat $DIR/$tdir/f1 && error "f1 still visible on the client"
22328         stat $DIR/$tdir/f2 && error "f2 still visible on the client"
22329
22330         cnt=$(ls -1 $DIR/$tdir | wc -l)
22331         [ $cnt == 1 ] || error "unexpected #files after: $cnt"
22332
22333         rm -f $DIR/$tdir/f3 || error "can't remove f3"
22334         createmany -o $DIR/$tdir/f 3
22335         cnt=$(ls -1 $DIR/$tdir | wc -l)
22336         [ $cnt != 3 ] && error "unexpected #files: $cnt"
22337
22338         fid1=$(lfs path2fid $DIR/$tdir/f1)
22339         fid2=$(lfs path2fid $DIR/$tdir/f2)
22340         echo "remove using fsname $FSNAME"
22341         $LFS rmfid $FSNAME $fid1 $fid2 || error "rmfid with fsname failed"
22342
22343         cnt=$(ls -1 $DIR/$tdir | wc -l)
22344         [ $cnt == 1 ] || error "unexpected #files after: $cnt"
22345 }
22346 run_test 421a "simple rm by fid"
22347
22348 test_421b() {
22349         local cnt
22350         local FID1
22351         local FID2
22352
22353         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22354                 skip "Need MDS version at least 2.12.54"
22355
22356         test_mkdir $DIR/$tdir
22357         createmany -o $DIR/$tdir/f 3
22358         multiop_bg_pause $DIR/$tdir/f1 o_c || error "multiop failed to start"
22359         MULTIPID=$!
22360
22361         FID1=$(lfs path2fid $DIR/$tdir/f1)
22362         FID2=$(lfs path2fid $DIR/$tdir/f2)
22363         $LFS rmfid $DIR $FID1 $FID2 && error "rmfid didn't fail"
22364
22365         kill -USR1 $MULTIPID
22366         wait
22367
22368         cnt=$(ls $DIR/$tdir | wc -l)
22369         [ $cnt == 2 ] || error "unexpected #files after: $cnt"
22370 }
22371 run_test 421b "rm by fid on open file"
22372
22373 test_421c() {
22374         local cnt
22375         local FIDS
22376
22377         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22378                 skip "Need MDS version at least 2.12.54"
22379
22380         test_mkdir $DIR/$tdir
22381         createmany -o $DIR/$tdir/f 3
22382         touch $DIR/$tdir/$tfile
22383         createmany -l$DIR/$tdir/$tfile $DIR/$tdir/h 180
22384         cnt=$(ls -1 $DIR/$tdir | wc -l)
22385         [ $cnt != 184 ] && error "unexpected #files: $cnt"
22386
22387         FID1=$(lfs path2fid $DIR/$tdir/$tfile)
22388         $LFS rmfid $DIR $FID1 || error "rmfid failed"
22389
22390         cnt=$(ls $DIR/$tdir | wc -l)
22391         [ $cnt == 3 ] || error "unexpected #files after: $cnt"
22392 }
22393 run_test 421c "rm by fid against hardlinked files"
22394
22395 test_421d() {
22396         local cnt
22397         local FIDS
22398
22399         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22400                 skip "Need MDS version at least 2.12.54"
22401
22402         test_mkdir $DIR/$tdir
22403         createmany -o $DIR/$tdir/f 4097
22404         cnt=$(ls -1 $DIR/$tdir | wc -l)
22405         [ $cnt != 4097 ] && error "unexpected #files: $cnt"
22406
22407         FIDS=$(lfs path2fid $DIR/$tdir/f* | sed "s/[/][^:]*://g")
22408         $LFS rmfid $DIR $FIDS || error "rmfid failed"
22409
22410         cnt=$(ls $DIR/$tdir | wc -l)
22411         rm -rf $DIR/$tdir
22412         [ $cnt == 0 ] || error "unexpected #files after: $cnt"
22413 }
22414 run_test 421d "rmfid en masse"
22415
22416 test_421e() {
22417         local cnt
22418         local FID
22419
22420         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
22421         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22422                 skip "Need MDS version at least 2.12.54"
22423
22424         mkdir -p $DIR/$tdir
22425         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
22426         createmany -o $DIR/$tdir/striped_dir/f 512
22427         cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
22428         [ $cnt != 512 ] && error "unexpected #files: $cnt"
22429
22430         FIDS=$(lfs path2fid $DIR/$tdir/striped_dir/f* |
22431                 sed "s/[/][^:]*://g")
22432         $LFS rmfid $DIR $FIDS || error "rmfid failed"
22433
22434         cnt=$(ls $DIR/$tdir/striped_dir | wc -l)
22435         rm -rf $DIR/$tdir
22436         [ $cnt == 0 ] || error "unexpected #files after: $cnt"
22437 }
22438 run_test 421e "rmfid in DNE"
22439
22440 test_421f() {
22441         local cnt
22442         local FID
22443
22444         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22445                 skip "Need MDS version at least 2.12.54"
22446
22447         test_mkdir $DIR/$tdir
22448         touch $DIR/$tdir/f
22449         cnt=$(ls -1 $DIR/$tdir | wc -l)
22450         [ $cnt != 1 ] && error "unexpected #files: $cnt"
22451
22452         FID=$(lfs path2fid $DIR/$tdir/f)
22453         $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail (1)"
22454         # rmfid should fail
22455         cnt=$(ls -1 $DIR/$tdir | wc -l)
22456         [ $cnt != 1 ] && error "unexpected #files after (2): $cnt"
22457
22458         chmod a+rw $DIR/$tdir
22459         ls -la $DIR/$tdir
22460         $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail (2)"
22461         # rmfid should fail
22462         cnt=$(ls -1 $DIR/$tdir | wc -l)
22463         [ $cnt != 1 ] && error "unexpected #files after (3): $cnt"
22464
22465         rm -f $DIR/$tdir/f
22466         $RUNAS touch $DIR/$tdir/f
22467         FID=$(lfs path2fid $DIR/$tdir/f)
22468         echo "rmfid as root"
22469         $LFS rmfid $DIR $FID || error "rmfid as root failed"
22470         cnt=$(ls -1 $DIR/$tdir | wc -l)
22471         [ $cnt == 0 ] || error "unexpected #files after (4): $cnt"
22472
22473         rm -f $DIR/$tdir/f
22474         $RUNAS touch $DIR/$tdir/f
22475         cnt=$(ls -1 $DIR/$tdir | wc -l)
22476         [ $cnt != 1 ] && error "unexpected #files (4): $cnt"
22477         FID=$(lfs path2fid $DIR/$tdir/f)
22478         # rmfid w/o user_fid2path mount option should fail
22479         $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail(3)"
22480         cnt=$(ls -1 $DIR/$tdir | wc -l)
22481         [ $cnt == 1 ] || error "unexpected #files after (5): $cnt"
22482
22483         umount_client $MOUNT || error "failed to umount client"
22484         mount_client $MOUNT "$MOUNT_OPTS,user_fid2path" ||
22485                 error "failed to mount client'"
22486
22487         $RUNAS $LFS rmfid $DIR $FID || error "rmfid failed"
22488         # rmfid should succeed
22489         cnt=$(ls -1 $DIR/$tdir | wc -l)
22490         [ $cnt == 0 ] || error "unexpected #files after (6): $cnt"
22491
22492         # rmfid shouldn't allow to remove files due to dir's permission
22493         chmod a+rwx $DIR/$tdir
22494         touch $DIR/$tdir/f
22495         ls -la $DIR/$tdir
22496         FID=$(lfs path2fid $DIR/$tdir/f)
22497         $RUNAS $LFS rmfid $DIR $FID && error "rmfid didn't fail"
22498
22499         umount_client $MOUNT || error "failed to umount client"
22500         mount_client $MOUNT "$MOUNT_OPTS" ||
22501                 error "failed to mount client'"
22502
22503 }
22504 run_test 421f "rmfid checks permissions"
22505
22506 test_421g() {
22507         local cnt
22508         local FIDS
22509
22510         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
22511         [ $MDS1_VERSION -lt $(version_code 2.12.54) ] &&
22512                 skip "Need MDS version at least 2.12.54"
22513
22514         mkdir -p $DIR/$tdir
22515         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
22516         createmany -o $DIR/$tdir/striped_dir/f 512
22517         cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
22518         [ $cnt != 512 ] && error "unexpected #files: $cnt"
22519
22520         FIDS=$(lfs path2fid $DIR/$tdir/striped_dir/f* |
22521                 sed "s/[/][^:]*://g")
22522
22523         rm -f $DIR/$tdir/striped_dir/f1*
22524         cnt=$(ls -1 $DIR/$tdir/striped_dir | wc -l)
22525         removed=$((512 - cnt))
22526
22527         # few files have been just removed, so we expect
22528         # rmfid to fail on their fids
22529         errors=$($LFS rmfid $DIR $FIDS 2>&1 | wc -l)
22530         [ $removed != $errors ] && error "$errors != $removed"
22531
22532         cnt=$(ls $DIR/$tdir/striped_dir | wc -l)
22533         rm -rf $DIR/$tdir
22534         [ $cnt == 0 ] || error "unexpected #files after: $cnt"
22535 }
22536 run_test 421g "rmfid to return errors properly"
22537
22538 test_422() {
22539         test_mkdir -i 0 -c 1 -p $DIR/$tdir/d1
22540         test_mkdir -i 0 -c 1 -p $DIR/$tdir/d2
22541         test_mkdir -i 0 -c 1 -p $DIR/$tdir/d3
22542         dd if=/dev/zero of=$DIR/$tdir/d1/file1 bs=1k count=1
22543         dd if=/dev/zero of=$DIR/$tdir/d2/file1 bs=1k count=1
22544
22545         local amc=$(at_max_get client)
22546         local amo=$(at_max_get mds1)
22547         local timeout=`lctl get_param -n timeout`
22548
22549         at_max_set 0 client
22550         at_max_set 0 mds1
22551
22552 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
22553         do_facet mds1 $LCTL set_param fail_loc=0x8000050a \
22554                         fail_val=$(((2*timeout + 10)*1000))
22555         touch $DIR/$tdir/d3/file &
22556         sleep 2
22557 #define OBD_FAIL_TGT_REPLY_DATA_RACE     0x722
22558         do_facet mds1 $LCTL set_param fail_loc=0x80000722 \
22559                         fail_val=$((2*timeout + 5))
22560         mv $DIR/$tdir/d1/file1 $DIR/$tdir/d1/file2 &
22561         local pid=$!
22562         sleep 1
22563         kill -9 $pid
22564         sleep $((2 * timeout))
22565         echo kill $pid
22566         kill -9 $pid
22567         lctl mark touch
22568         touch $DIR/$tdir/d2/file3
22569         touch $DIR/$tdir/d2/file4
22570         touch $DIR/$tdir/d2/file5
22571
22572         wait
22573         at_max_set $amc client
22574         at_max_set $amo mds1
22575
22576         # LU-12838 - verify the ptlrpc thread watchdog is not always throttled
22577         do_facet mds1 "dmesg | grep 'Dumping the stack trace for debugging'" ||
22578                 error "Watchdog is always throttled"
22579 }
22580 run_test 422 "kill a process with RPC in progress"
22581
22582 stat_test() {
22583     df -h $MOUNT &
22584     df -h $MOUNT &
22585     df -h $MOUNT &
22586     df -h $MOUNT &
22587     df -h $MOUNT &
22588     df -h $MOUNT &
22589 }
22590
22591 test_423() {
22592     local _stats
22593     # ensure statfs cache is expired
22594     sleep 2;
22595
22596     _stats=$(stat_test | grep $MOUNT | sort -u | wc -l)
22597     [[ ${_stats} -ne 1 ]] && error "statfs wrong"
22598
22599     return 0
22600 }
22601 run_test 423 "statfs should return a right data"
22602
22603 prep_801() {
22604         [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] ||
22605         [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&
22606                 skip "Need server version at least 2.9.55"
22607
22608         start_full_debug_logging
22609 }
22610
22611 post_801() {
22612         stop_full_debug_logging
22613 }
22614
22615 barrier_stat() {
22616         if [ $MGS_VERSION -le $(version_code 2.10.0) ]; then
22617                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
22618                            awk '/The barrier for/ { print $7 }')
22619                 echo $st
22620         else
22621                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
22622                 echo \'$st\'
22623         fi
22624 }
22625
22626 barrier_expired() {
22627         local expired
22628
22629         if [ $MGS_VERSION -le $(version_code 2.10.0) ]; then
22630                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
22631                           awk '/will be expired/ { print $7 }')
22632         else
22633                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
22634         fi
22635
22636         echo $expired
22637 }
22638
22639 test_801a() {
22640         prep_801
22641
22642         echo "Start barrier_freeze at: $(date)"
22643         #define OBD_FAIL_BARRIER_DELAY          0x2202
22644         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
22645         # Do not reduce barrier time - See LU-11873
22646         do_facet mgs $LCTL barrier_freeze $FSNAME 20 &
22647
22648         sleep 2
22649         local b_status=$(barrier_stat)
22650         echo "Got barrier status at: $(date)"
22651         [ "$b_status" = "'freezing_p1'" ] ||
22652                 error "(1) unexpected barrier status $b_status"
22653
22654         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
22655         wait
22656         b_status=$(barrier_stat)
22657         [ "$b_status" = "'frozen'" ] ||
22658                 error "(2) unexpected barrier status $b_status"
22659
22660         local expired=$(barrier_expired)
22661         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
22662         sleep $((expired + 3))
22663
22664         b_status=$(barrier_stat)
22665         [ "$b_status" = "'expired'" ] ||
22666                 error "(3) unexpected barrier status $b_status"
22667
22668         # Do not reduce barrier time - See LU-11873
22669         do_facet mgs $LCTL barrier_freeze $FSNAME 20 ||
22670                 error "(4) fail to freeze barrier"
22671
22672         b_status=$(barrier_stat)
22673         [ "$b_status" = "'frozen'" ] ||
22674                 error "(5) unexpected barrier status $b_status"
22675
22676         echo "Start barrier_thaw at: $(date)"
22677         #define OBD_FAIL_BARRIER_DELAY          0x2202
22678         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
22679         do_facet mgs $LCTL barrier_thaw $FSNAME &
22680
22681         sleep 2
22682         b_status=$(barrier_stat)
22683         echo "Got barrier status at: $(date)"
22684         [ "$b_status" = "'thawing'" ] ||
22685                 error "(6) unexpected barrier status $b_status"
22686
22687         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
22688         wait
22689         b_status=$(barrier_stat)
22690         [ "$b_status" = "'thawed'" ] ||
22691                 error "(7) unexpected barrier status $b_status"
22692
22693         #define OBD_FAIL_BARRIER_FAILURE        0x2203
22694         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
22695         do_facet mgs $LCTL barrier_freeze $FSNAME
22696
22697         b_status=$(barrier_stat)
22698         [ "$b_status" = "'failed'" ] ||
22699                 error "(8) unexpected barrier status $b_status"
22700
22701         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
22702         do_facet mgs $LCTL barrier_thaw $FSNAME
22703
22704         post_801
22705 }
22706 run_test 801a "write barrier user interfaces and stat machine"
22707
22708 test_801b() {
22709         prep_801
22710
22711         mkdir $DIR/$tdir || error "(1) fail to mkdir"
22712         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
22713         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
22714         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
22715         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
22716
22717         cancel_lru_locks mdc
22718
22719         # 180 seconds should be long enough
22720         do_facet mgs $LCTL barrier_freeze $FSNAME 180
22721
22722         local b_status=$(barrier_stat)
22723         [ "$b_status" = "'frozen'" ] ||
22724                 error "(6) unexpected barrier status $b_status"
22725
22726         mkdir $DIR/$tdir/d0/d10 &
22727         mkdir_pid=$!
22728
22729         touch $DIR/$tdir/d1/f13 &
22730         touch_pid=$!
22731
22732         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
22733         ln_pid=$!
22734
22735         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
22736         mv_pid=$!
22737
22738         rm -f $DIR/$tdir/d4/f12 &
22739         rm_pid=$!
22740
22741         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
22742
22743         # To guarantee taht the 'stat' is not blocked
22744         b_status=$(barrier_stat)
22745         [ "$b_status" = "'frozen'" ] ||
22746                 error "(8) unexpected barrier status $b_status"
22747
22748         # let above commands to run at background
22749         sleep 5
22750
22751         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
22752         ps -p $touch_pid || error "(10) touch should be blocked"
22753         ps -p $ln_pid || error "(11) link should be blocked"
22754         ps -p $mv_pid || error "(12) rename should be blocked"
22755         ps -p $rm_pid || error "(13) unlink should be blocked"
22756
22757         b_status=$(barrier_stat)
22758         [ "$b_status" = "'frozen'" ] ||
22759                 error "(14) unexpected barrier status $b_status"
22760
22761         do_facet mgs $LCTL barrier_thaw $FSNAME
22762         b_status=$(barrier_stat)
22763         [ "$b_status" = "'thawed'" ] ||
22764                 error "(15) unexpected barrier status $b_status"
22765
22766         wait $mkdir_pid || error "(16) mkdir should succeed"
22767         wait $touch_pid || error "(17) touch should succeed"
22768         wait $ln_pid || error "(18) link should succeed"
22769         wait $mv_pid || error "(19) rename should succeed"
22770         wait $rm_pid || error "(20) unlink should succeed"
22771
22772         post_801
22773 }
22774 run_test 801b "modification will be blocked by write barrier"
22775
22776 test_801c() {
22777         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
22778
22779         prep_801
22780
22781         stop mds2 || error "(1) Fail to stop mds2"
22782
22783         do_facet mgs $LCTL barrier_freeze $FSNAME 30
22784
22785         local b_status=$(barrier_stat)
22786         [ "$b_status" = "'expired'" ] || [ "$b_status" = "'failed'" ] || {
22787                 do_facet mgs $LCTL barrier_thaw $FSNAME
22788                 error "(2) unexpected barrier status $b_status"
22789         }
22790
22791         do_facet mgs $LCTL barrier_rescan $FSNAME ||
22792                 error "(3) Fail to rescan barrier bitmap"
22793
22794         # Do not reduce barrier time - See LU-11873
22795         do_facet mgs $LCTL barrier_freeze $FSNAME 20
22796
22797         b_status=$(barrier_stat)
22798         [ "$b_status" = "'frozen'" ] ||
22799                 error "(4) unexpected barrier status $b_status"
22800
22801         do_facet mgs $LCTL barrier_thaw $FSNAME
22802         b_status=$(barrier_stat)
22803         [ "$b_status" = "'thawed'" ] ||
22804                 error "(5) unexpected barrier status $b_status"
22805
22806         local devname=$(mdsdevname 2)
22807
22808         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
22809
22810         do_facet mgs $LCTL barrier_rescan $FSNAME ||
22811                 error "(7) Fail to rescan barrier bitmap"
22812
22813         post_801
22814 }
22815 run_test 801c "rescan barrier bitmap"
22816
22817 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
22818 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
22819 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
22820 saved_MOUNT_OPTS=$MOUNT_OPTS
22821
22822 cleanup_802a() {
22823         trap 0
22824
22825         stopall
22826         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
22827         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
22828         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
22829         MOUNT_OPTS=$saved_MOUNT_OPTS
22830         setupall
22831 }
22832
22833 test_802a() {
22834         [[ $mds1_FSTYPE = zfs ]] || skip "ZFS specific test"
22835         [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] ||
22836         [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&
22837                 skip "Need server version at least 2.9.55"
22838
22839         [[ $ENABLE_QUOTA ]] && skip "Quota enabled for read-only test"
22840
22841         mkdir $DIR/$tdir || error "(1) fail to mkdir"
22842
22843         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
22844                 error "(2) Fail to copy"
22845
22846         trap cleanup_802a EXIT
22847
22848         # sync by force before remount as readonly
22849         sync; sync_all_data; sleep 3; sync_all_data
22850
22851         stopall
22852
22853         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
22854         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
22855         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
22856
22857         echo "Mount the server as read only"
22858         setupall server_only || error "(3) Fail to start servers"
22859
22860         echo "Mount client without ro should fail"
22861         mount_client $MOUNT &&
22862                 error "(4) Mount client without 'ro' should fail"
22863
22864         echo "Mount client with ro should succeed"
22865         MOUNT_OPTS=$(csa_add "$MOUNT_OPTS" -o ro)
22866         mount_client $MOUNT ||
22867                 error "(5) Mount client with 'ro' should succeed"
22868
22869         echo "Modify should be refused"
22870         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
22871
22872         echo "Read should be allowed"
22873         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
22874                 error "(7) Read should succeed under ro mode"
22875
22876         cleanup_802a
22877 }
22878 run_test 802a "simulate readonly device"
22879
22880 test_802b() {
22881         [ $PARALLEL == "yes" ] && skip "skip parallel run"
22882         remote_mds_nodsh && skip "remote MDS with nodsh"
22883
22884         do_facet $SINGLEMDS $LCTL get_param mdt.*.readonly ||
22885                 skip "readonly option not available"
22886
22887         $LFS mkdir -i 0 -c 1 $DIR/$tdir || error "(1) fail to mkdir"
22888
22889         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
22890                 error "(2) Fail to copy"
22891
22892         # write back all cached data before setting MDT to readonly
22893         cancel_lru_locks
22894         sync_all_data
22895
22896         do_facet $SINGLEMDS $LCTL set_param mdt.*.readonly=1
22897         stack_trap "do_facet $SINGLEMDS $LCTL set_param mdt.*.readonly=0" EXIT
22898
22899         echo "Modify should be refused"
22900         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
22901
22902         echo "Read should be allowed"
22903         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
22904                 error "(7) Read should succeed under ro mode"
22905
22906         # disable readonly
22907         do_facet $SINGLEMDS $LCTL set_param mdt.*.readonly=0
22908 }
22909 run_test 802b "be able to set MDTs to readonly"
22910
22911 test_803() {
22912         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
22913         [ $MDS1_VERSION -lt $(version_code 2.10.54) ] &&
22914                 skip "MDS needs to be newer than 2.10.54"
22915
22916         mkdir -p $DIR/$tdir
22917         # Create some objects on all MDTs to trigger related logs objects
22918         for idx in $(seq $MDSCOUNT); do
22919                 $LFS mkdir -c $MDSCOUNT -i $((idx % $MDSCOUNT)) \
22920                         $DIR/$tdir/dir${idx} ||
22921                         error "Fail to create $DIR/$tdir/dir${idx}"
22922         done
22923
22924         sync; sleep 3
22925         wait_delete_completed # ensure old test cleanups are finished
22926         echo "before create:"
22927         $LFS df -i $MOUNT
22928         local before_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
22929
22930         for i in {1..10}; do
22931                 $LFS mkdir -c 1 -i 1 $DIR/$tdir/foo$i ||
22932                         error "Fail to create $DIR/$tdir/foo$i"
22933         done
22934
22935         sync; sleep 3
22936         echo "after create:"
22937         $LFS df -i $MOUNT
22938         local after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
22939
22940         # allow for an llog to be cleaned up during the test
22941         [ $after_used -ge $((before_used + 10 - 1)) ] ||
22942                 error "before ($before_used) + 10 > after ($after_used)"
22943
22944         for i in {1..10}; do
22945                 rm -rf $DIR/$tdir/foo$i ||
22946                         error "Fail to remove $DIR/$tdir/foo$i"
22947         done
22948
22949         sleep 3 # avoid MDT return cached statfs
22950         wait_delete_completed
22951         echo "after unlink:"
22952         $LFS df -i $MOUNT
22953         after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
22954
22955         # allow for an llog to be created during the test
22956         [ $after_used -le $((before_used + 1)) ] ||
22957                 error "after ($after_used) > before ($before_used) + 1"
22958 }
22959 run_test 803 "verify agent object for remote object"
22960
22961 test_804() {
22962         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
22963         [ $MDS1_VERSION -lt $(version_code 2.10.54) ] &&
22964                 skip "MDS needs to be newer than 2.10.54"
22965         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
22966
22967         mkdir -p $DIR/$tdir
22968         $LFS mkdir -c 1 -i 1 $DIR/$tdir/dir0 ||
22969                 error "Fail to create $DIR/$tdir/dir0"
22970
22971         local fid=$($LFS path2fid $DIR/$tdir/dir0)
22972         local dev=$(mdsdevname 2)
22973
22974         do_facet mds2 "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
22975                 grep ${fid} || error "NOT found agent entry for dir0"
22976
22977         $LFS mkdir -c $MDSCOUNT -i 0 $DIR/$tdir/dir1 ||
22978                 error "Fail to create $DIR/$tdir/dir1"
22979
22980         touch $DIR/$tdir/dir1/foo0 ||
22981                 error "Fail to create $DIR/$tdir/dir1/foo0"
22982         fid=$($LFS path2fid $DIR/$tdir/dir1/foo0)
22983         local rc=0
22984
22985         for idx in $(seq $MDSCOUNT); do
22986                 dev=$(mdsdevname $idx)
22987                 do_facet mds${idx} \
22988                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
22989                         grep ${fid} && rc=$idx
22990         done
22991
22992         mv $DIR/$tdir/dir1/foo0 $DIR/$tdir/dir1/foo1 ||
22993                 error "Fail to rename foo0 to foo1"
22994         if [ $rc -eq 0 ]; then
22995                 for idx in $(seq $MDSCOUNT); do
22996                         dev=$(mdsdevname $idx)
22997                         do_facet mds${idx} \
22998                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
22999                         grep ${fid} && rc=$idx
23000                 done
23001         fi
23002
23003         mv $DIR/$tdir/dir1/foo1 $DIR/$tdir/dir1/foo2 ||
23004                 error "Fail to rename foo1 to foo2"
23005         if [ $rc -eq 0 ]; then
23006                 for idx in $(seq $MDSCOUNT); do
23007                         dev=$(mdsdevname $idx)
23008                         do_facet mds${idx} \
23009                         "$DEBUGFS -c -R 'ls /REMOTE_PARENT_DIR' $dev" |
23010                         grep ${fid} && rc=$idx
23011                 done
23012         fi
23013
23014         [ $rc -ne 0 ] || error "NOT found agent entry for foo"
23015
23016         ln $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir0/guard ||
23017                 error "Fail to link to $DIR/$tdir/dir1/foo2"
23018         mv $DIR/$tdir/dir1/foo2 $DIR/$tdir/dir1/foo0 ||
23019                 error "Fail to rename foo2 to foo0"
23020         unlink $DIR/$tdir/dir1/foo0 ||
23021                 error "Fail to unlink $DIR/$tdir/dir1/foo0"
23022         rm -rf $DIR/$tdir/dir0 ||
23023                 error "Fail to rm $DIR/$tdir/dir0"
23024
23025         for idx in $(seq $MDSCOUNT); do
23026                 dev=$(mdsdevname $idx)
23027                 rc=0
23028
23029                 stop mds${idx}
23030                 run_e2fsck $(facet_active_host mds$idx) $dev -n ||
23031                         rc=$?
23032                 start mds${idx} $dev $MDS_MOUNT_OPTS ||
23033                         error "mount mds$idx failed"
23034                 df $MOUNT > /dev/null 2>&1
23035
23036                 # e2fsck should not return error
23037                 [ $rc -eq 0 ] ||
23038                         error "e2fsck detected error on MDT${idx}: rc=$rc"
23039         done
23040 }
23041 run_test 804 "verify agent entry for remote entry"
23042
23043 cleanup_805() {
23044         do_facet $SINGLEMDS zfs set quota=$old $fsset
23045         unlinkmany $DIR/$tdir/f- 1000000
23046         trap 0
23047 }
23048
23049 test_805() {
23050         local zfs_version=$(do_facet mds1 cat /sys/module/zfs/version)
23051         [ "$mds1_FSTYPE" != "zfs" ] && skip "ZFS specific test"
23052         [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
23053                 skip "netfree not implemented before 0.7"
23054         [[ $MDS1_VERSION -ge $(version_code 2.10.57) ]] ||
23055                 skip "Need MDS version at least 2.10.57"
23056
23057         local fsset
23058         local freekb
23059         local usedkb
23060         local old
23061         local quota
23062         local pref="osd-zfs.$FSNAME-MDT0000."
23063
23064         # limit available space on MDS dataset to meet nospace issue
23065         # quickly. then ZFS 0.7.2 can use reserved space if asked
23066         # properly (using netfree flag in osd_declare_destroy()
23067         fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
23068         old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
23069                 gawk '{print $3}')
23070         freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
23071         usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
23072         let "usedkb=usedkb-freekb"
23073         let "freekb=freekb/2"
23074         if let "freekb > 5000"; then
23075                 let "freekb=5000"
23076         fi
23077         do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
23078         trap cleanup_805 EXIT
23079         mkdir $DIR/$tdir
23080         $LFS setstripe -E 1M -c2 -E 4M -c2 -E -1 -c2 $DIR/$tdir ||
23081                 error "Can't set PFL layout"
23082         createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
23083         rm -rf $DIR/$tdir || error "not able to remove"
23084         do_facet $SINGLEMDS zfs set quota=$old $fsset
23085         trap 0
23086 }
23087 run_test 805 "ZFS can remove from full fs"
23088
23089 # Size-on-MDS test
23090 check_lsom_data()
23091 {
23092         local file=$1
23093         local size=$($LFS getsom -s $file)
23094         local expect=$(stat -c %s $file)
23095
23096         [[ $size == $expect ]] ||
23097                 error "$file expected size: $expect, got: $size"
23098
23099         local blocks=$($LFS getsom -b $file)
23100         expect=$(stat -c %b $file)
23101         [[ $blocks == $expect ]] ||
23102                 error "$file expected blocks: $expect, got: $blocks"
23103 }
23104
23105 check_lsom_size()
23106 {
23107         local size=$($LFS getsom -s $1)
23108         local expect=$2
23109
23110         [[ $size == $expect ]] ||
23111                 error "$file expected size: $expect, got: $size"
23112 }
23113
23114 test_806() {
23115         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
23116                 skip "Need MDS version at least 2.11.52"
23117
23118         local bs=1048576
23119
23120         touch $DIR/$tfile || error "touch $tfile failed"
23121
23122         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
23123         save_lustre_params client "llite.*.xattr_cache" > $save
23124         lctl set_param llite.*.xattr_cache=0
23125         stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
23126
23127         # single-threaded write
23128         echo "Test SOM for single-threaded write"
23129         dd if=/dev/zero of=$DIR/$tfile bs=$bs count=1 ||
23130                 error "write $tfile failed"
23131         check_lsom_size $DIR/$tfile $bs
23132
23133         local num=32
23134         local size=$(($num * $bs))
23135         local offset=0
23136         local i
23137
23138         echo "Test SOM for single client multi-threaded($num) write"
23139         $TRUNCATE $DIR/$tfile 0
23140         for ((i = 0; i < $num; i++)); do
23141                 $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23142                 local pids[$i]=$!
23143                 offset=$((offset + $bs))
23144         done
23145         for (( i=0; i < $num; i++ )); do
23146                 wait ${pids[$i]}
23147         done
23148         check_lsom_size $DIR/$tfile $size
23149
23150         $TRUNCATE $DIR/$tfile 0
23151         for ((i = 0; i < $num; i++)); do
23152                 offset=$((offset - $bs))
23153                 $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23154                 local pids[$i]=$!
23155         done
23156         for (( i=0; i < $num; i++ )); do
23157                 wait ${pids[$i]}
23158         done
23159         check_lsom_size $DIR/$tfile $size
23160
23161         # multi-client writes
23162         num=$(get_node_count ${CLIENTS//,/ })
23163         size=$(($num * $bs))
23164         offset=0
23165         i=0
23166
23167         echo "Test SOM for multi-client ($num) writes"
23168         $TRUNCATE $DIR/$tfile 0
23169         for client in ${CLIENTS//,/ }; do
23170                 do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23171                 local pids[$i]=$!
23172                 i=$((i + 1))
23173                 offset=$((offset + $bs))
23174         done
23175         for (( i=0; i < $num; i++ )); do
23176                 wait ${pids[$i]}
23177         done
23178         check_lsom_size $DIR/$tfile $offset
23179
23180         i=0
23181         $TRUNCATE $DIR/$tfile 0
23182         for client in ${CLIENTS//,/ }; do
23183                 offset=$((offset - $bs))
23184                 do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23185                 local pids[$i]=$!
23186                 i=$((i + 1))
23187         done
23188         for (( i=0; i < $num; i++ )); do
23189                 wait ${pids[$i]}
23190         done
23191         check_lsom_size $DIR/$tfile $size
23192
23193         # verify truncate
23194         echo "Test SOM for truncate"
23195         $TRUNCATE $DIR/$tfile 1048576
23196         check_lsom_size $DIR/$tfile 1048576
23197         $TRUNCATE $DIR/$tfile 1234
23198         check_lsom_size $DIR/$tfile 1234
23199
23200         # verify SOM blocks count
23201         echo "Verify SOM block count"
23202         $TRUNCATE $DIR/$tfile 0
23203         $MULTIOP $DIR/$tfile oO_TRUNC:O_RDWR:w1048576YSc ||
23204                 error "failed to write file $tfile"
23205         check_lsom_data $DIR/$tfile
23206 }
23207 run_test 806 "Verify Lazy Size on MDS"
23208
23209 test_807() {
23210         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
23211         [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
23212                 skip "Need MDS version at least 2.11.52"
23213
23214         # Registration step
23215         changelog_register || error "changelog_register failed"
23216         local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
23217         changelog_users $SINGLEMDS | grep -q $cl_user ||
23218                 error "User $cl_user not found in changelog_users"
23219
23220         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
23221         save_lustre_params client "llite.*.xattr_cache" > $save
23222         lctl set_param llite.*.xattr_cache=0
23223         stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
23224
23225         rm -rf $DIR/$tdir || error "rm $tdir failed"
23226         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
23227         touch $DIR/$tdir/trunc || error "touch $tdir/trunc failed"
23228         $TRUNCATE $DIR/$tdir/trunc 1024 || error "truncate $tdir/trunc failed"
23229         $TRUNCATE $DIR/$tdir/trunc 1048576 ||
23230                 error "truncate $tdir/trunc failed"
23231
23232         local bs=1048576
23233         dd if=/dev/zero of=$DIR/$tdir/single_dd bs=$bs count=1 conv=fsync ||
23234                 error "write $tfile failed"
23235
23236         # multi-client wirtes
23237         local num=$(get_node_count ${CLIENTS//,/ })
23238         local offset=0
23239         local i=0
23240
23241         echo "Test SOM for multi-client ($num) writes"
23242         touch $DIR/$tfile || error "touch $tfile failed"
23243         $TRUNCATE $DIR/$tfile 0
23244         for client in ${CLIENTS//,/ }; do
23245                 do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
23246                 local pids[$i]=$!
23247                 i=$((i + 1))
23248                 offset=$((offset + $bs))
23249         done
23250         for (( i=0; i < $num; i++ )); do
23251                 wait ${pids[$i]}
23252         done
23253
23254         do_rpc_nodes "$CLIENTS" cancel_lru_locks osc
23255         do_nodes "$CLIENTS" "sync ; sleep 5 ; sync"
23256         $LSOM_SYNC -u $cl_user -m $FSNAME-MDT0000 $MOUNT
23257         check_lsom_data $DIR/$tdir/trunc
23258         check_lsom_data $DIR/$tdir/single_dd
23259         check_lsom_data $DIR/$tfile
23260
23261         rm -rf $DIR/$tdir
23262         # Deregistration step
23263         changelog_deregister || error "changelog_deregister failed"
23264 }
23265 run_test 807 "verify LSOM syncing tool"
23266
23267 check_som_nologged()
23268 {
23269         local lines=$($LFS changelog $FSNAME-MDT0000 |
23270                 grep 'x=trusted.som' | wc -l)
23271         [ $lines -ne 0 ] && error "trusted.som xattr is logged in Changelogs"
23272 }
23273
23274 test_808() {
23275         [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
23276                 skip "Need MDS version at least 2.11.55"
23277
23278         # Registration step
23279         changelog_register || error "changelog_register failed"
23280
23281         touch $DIR/$tfile || error "touch $tfile failed"
23282         check_som_nologged
23283
23284         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=1 ||
23285                 error "write $tfile failed"
23286         check_som_nologged
23287
23288         $TRUNCATE $DIR/$tfile 1234
23289         check_som_nologged
23290
23291         $TRUNCATE $DIR/$tfile 1048576
23292         check_som_nologged
23293
23294         # Deregistration step
23295         changelog_deregister || error "changelog_deregister failed"
23296 }
23297 run_test 808 "Check trusted.som xattr not logged in Changelogs"
23298
23299 check_som_nodata()
23300 {
23301         $LFS getsom $1
23302         [[ $? -eq 61 ]] || error "DoM-only file $1 has SOM xattr"
23303 }
23304
23305 test_809() {
23306         [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
23307                 skip "Need MDS version at least 2.11.56"
23308
23309         $LFS setstripe -E 1M -L mdt $DIR/$tfile ||
23310                 error "failed to create DoM-only file $DIR/$tfile"
23311         touch $DIR/$tfile || error "touch $tfile failed"
23312         check_som_nodata $DIR/$tfile
23313
23314         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 ||
23315                 error "write $tfile failed"
23316         check_som_nodata $DIR/$tfile
23317
23318         $TRUNCATE $DIR/$tfile 1234
23319         check_som_nodata $DIR/$tfile
23320
23321         $TRUNCATE $DIR/$tfile 4097
23322         check_som_nodata $DIR/$file
23323 }
23324 run_test 809 "Verify no SOM xattr store for DoM-only files"
23325
23326 test_810() {
23327         [ $PARALLEL == "yes" ] && skip "skip parallel run"
23328         $GSS && skip_env "could not run with gss"
23329         [[ $OST1_VERSION -gt $(version_code 2.12.58) ]] ||
23330                 skip "OST < 2.12.58 doesn't align checksum"
23331
23332         set_checksums 1
23333         stack_trap "set_checksums $ORIG_CSUM" EXIT
23334         stack_trap "set_checksum_type $ORIG_CSUM_TYPE" EXIT
23335
23336         local csum
23337         local before
23338         local after
23339         for csum in $CKSUM_TYPES; do
23340                 #define OBD_FAIL_OSC_NO_GRANT   0x411
23341                 $LCTL set_param osc.*.checksum_type=$csum fail_loc=0x411
23342                 for i in "10240 0" "10000 0" "4000 1" "500 1"; do
23343                         eval set -- $i
23344                         dd if=/dev/urandom of=$DIR/$tfile bs=$1 count=2 seek=$2
23345                         before=$(md5sum $DIR/$tfile)
23346                         $LCTL set_param ldlm.namespaces.*osc*.lru_size=clear
23347                         after=$(md5sum $DIR/$tfile)
23348                         [ "$before" == "$after" ] ||
23349                                 error "$csum: $before != $after bs=$1 seek=$2"
23350                 done
23351         done
23352 }
23353 run_test 810 "partial page writes on ZFS (LU-11663)"
23354
23355 test_812a() {
23356         [ $OST1_VERSION -lt $(version_code 2.12.51) ] &&
23357                 skip "OST < 2.12.51 doesn't support this fail_loc"
23358         [ "$SHARED_KEY" = true ] &&
23359                 skip "OSC connections never go IDLE with Shared-Keys enabled"
23360
23361         $LFS setstripe -c 1 -i 0 $DIR/$tfile
23362         # ensure ost1 is connected
23363         stat $DIR/$tfile >/dev/null || error "can't stat"
23364         wait_osc_import_state client ost1 FULL
23365         # no locks, no reqs to let the connection idle
23366         cancel_lru_locks osc
23367
23368         # delay OST_DISCONNECT on OST1 to put OSC into intermediate state
23369 #define OBD_FAIL_OST_DISCONNECT_DELAY    0x245
23370         do_facet ost1 "$LCTL set_param fail_loc=0x245 fail_val=8"
23371         wait_osc_import_state client ost1 CONNECTING
23372         do_facet ost1 "$LCTL set_param fail_loc=0 fail_val=0"
23373
23374         stat $DIR/$tfile >/dev/null || error "can't stat file"
23375 }
23376 run_test 812a "do not drop reqs generated when imp is going to idle (LU-11951)"
23377
23378 test_812b() { # LU-12378
23379         [ $OST1_VERSION -lt $(version_code 2.12.51) ] &&
23380                 skip "OST < 2.12.51 doesn't support this fail_loc"
23381         [ "$SHARED_KEY" = true ] &&
23382                 skip "OSC connections never go IDLE with Shared-Keys enabled"
23383
23384         $LFS setstripe -c 1 -i 0 $DIR/$tfile || error "setstripe failed"
23385         # ensure ost1 is connected
23386         stat $DIR/$tfile >/dev/null || error "can't stat"
23387         wait_osc_import_state client ost1 FULL
23388         # no locks, no reqs to let the connection idle
23389         cancel_lru_locks osc
23390
23391         # delay OST_DISCONNECT on OST1 to put OSC into intermediate state
23392 #define OBD_FAIL_OST_DISCONNECT_DELAY    0x245
23393         do_facet ost1 "$LCTL set_param fail_loc=0x245 fail_val=8"
23394         wait_osc_import_state client ost1 CONNECTING
23395         do_facet ost1 "$LCTL set_param fail_loc=0 fail_val=0"
23396
23397         $LFS quota -u 0 $DIR/ || error "lfs quota should succeed"
23398         wait_osc_import_state client ost1 IDLE
23399 }
23400 run_test 812b "do not drop no resend request for idle connect"
23401
23402 test_813() {
23403         local file_heat_sav=$($LCTL get_param -n llite.*.file_heat 2>/dev/null)
23404         [ -z "$file_heat_sav" ] && skip "no file heat support"
23405
23406         local readsample
23407         local writesample
23408         local readbyte
23409         local writebyte
23410         local readsample1
23411         local writesample1
23412         local readbyte1
23413         local writebyte1
23414
23415         local period_second=$($LCTL get_param -n llite.*.heat_period_second)
23416         local decay_pct=$($LCTL get_param -n llite.*.heat_decay_percentage)
23417
23418         $LCTL set_param -n llite.*.file_heat=1
23419         echo "Turn on file heat"
23420         echo "Period second: $period_second, Decay percentage: $decay_pct"
23421
23422         echo "QQQQ" > $DIR/$tfile
23423         echo "QQQQ" > $DIR/$tfile
23424         echo "QQQQ" > $DIR/$tfile
23425         cat $DIR/$tfile > /dev/null
23426         cat $DIR/$tfile > /dev/null
23427         cat $DIR/$tfile > /dev/null
23428         cat $DIR/$tfile > /dev/null
23429
23430         local out=$($LFS heat_get $DIR/$tfile)
23431
23432         $LFS heat_get $DIR/$tfile
23433         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23434         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23435         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23436         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23437
23438         [ $readsample -le 4 ] || error "read sample ($readsample) is wrong"
23439         [ $writesample -le 3 ] || error "write sample ($writesample) is wrong"
23440         [ $readbyte -le 20 ] || error "read bytes ($readbyte) is wrong"
23441         [ $writebyte -le 15 ] || error "write bytes ($writebyte) is wrong"
23442
23443         sleep $((period_second + 3))
23444         echo "Sleep $((period_second + 3)) seconds..."
23445         # The recursion formula to calculate the heat of the file f is as
23446         # follow:
23447         # Hi+1(f) = (1-P)*Hi(f)+ P*Ci
23448         # Where Hi is the heat value in the period between time points i*I and
23449         # (i+1)*I; Ci is the access count in the period; the symbol P refers
23450         # to the weight of Ci.
23451         out=$($LFS heat_get $DIR/$tfile)
23452         $LFS heat_get $DIR/$tfile
23453         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23454         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23455         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23456         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23457
23458         [ $(bc <<< "$readsample <= 4 * $decay_pct / 100") -eq 1 ] ||
23459                 error "read sample ($readsample) is wrong"
23460         [ $(bc <<< "$writesample <= 3 * $decay_pct / 100") -eq 1 ] ||
23461                 error "write sample ($writesample) is wrong"
23462         [ $(bc <<< "$readbyte <= 20 * $decay_pct / 100") -eq 1 ] ||
23463                 error "read bytes ($readbyte) is wrong"
23464         [ $(bc <<< "$writebyte <= 15 * $decay_pct / 100") -eq 1 ] ||
23465                 error "write bytes ($writebyte) is wrong"
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         sleep $((period_second + 3))
23476         echo "Sleep $((period_second + 3)) seconds..."
23477
23478         out=$($LFS heat_get $DIR/$tfile)
23479         $LFS heat_get $DIR/$tfile
23480         readsample1=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23481         writesample1=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23482         readbyte1=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23483         writebyte1=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23484
23485         [ $(bc <<< "$readsample1 <= ($readsample * (100 - $decay_pct) + \
23486                 4 * $decay_pct) / 100") -eq 1 ] ||
23487                 error "read sample ($readsample1) is wrong"
23488         [ $(bc <<< "$writesample1 <= ($writesample * (100 - $decay_pct) + \
23489                 3 * $decay_pct) / 100") -eq 1 ] ||
23490                 error "write sample ($writesample1) is wrong"
23491         [ $(bc <<< "$readbyte1 <= ($readbyte * (100 - $decay_pct) + \
23492                 20 * $decay_pct) / 100") -eq 1 ] ||
23493                 error "read bytes ($readbyte1) is wrong"
23494         [ $(bc <<< "$writebyte1 <= ($writebyte * (100 - $decay_pct) + \
23495                 15 * $decay_pct) / 100") -eq 1 ] ||
23496                 error "write bytes ($writebyte1) is wrong"
23497
23498         echo "Turn off file heat for the file $DIR/$tfile"
23499         $LFS heat_set -o $DIR/$tfile
23500
23501         echo "QQQQ" > $DIR/$tfile
23502         echo "QQQQ" > $DIR/$tfile
23503         echo "QQQQ" > $DIR/$tfile
23504         cat $DIR/$tfile > /dev/null
23505         cat $DIR/$tfile > /dev/null
23506         cat $DIR/$tfile > /dev/null
23507         cat $DIR/$tfile > /dev/null
23508
23509         out=$($LFS heat_get $DIR/$tfile)
23510         $LFS heat_get $DIR/$tfile
23511         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23512         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23513         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23514         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23515
23516         [ $readsample -eq 0 ] || error "read sample ($readsample) is wrong"
23517         [ $writesample -eq 0 ] || error "write sample ($writesample) is wrong"
23518         [ $readbyte -eq 0 ] || error "read bytes ($readbyte) is wrong"
23519         [ $writebyte -eq 0 ] || error "write bytes ($writebyte) is wrong"
23520
23521         echo "Trun on file heat for the file $DIR/$tfile"
23522         $LFS heat_set -O $DIR/$tfile
23523
23524         echo "QQQQ" > $DIR/$tfile
23525         echo "QQQQ" > $DIR/$tfile
23526         echo "QQQQ" > $DIR/$tfile
23527         cat $DIR/$tfile > /dev/null
23528         cat $DIR/$tfile > /dev/null
23529         cat $DIR/$tfile > /dev/null
23530         cat $DIR/$tfile > /dev/null
23531
23532         out=$($LFS heat_get $DIR/$tfile)
23533         $LFS heat_get $DIR/$tfile
23534         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23535         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23536         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23537         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23538
23539         [ $readsample -gt 0 ] || error "read sample ($readsample) is wrong"
23540         [ $writesample -gt 0 ] || error "write sample ($writesample) is wrong"
23541         [ $readbyte -gt 0 ] || error "read bytes ($readbyte) is wrong"
23542         [ $writebyte -gt 0 ] || error "write bytes ($writebyte) is wrong"
23543
23544         $LFS heat_set -c $DIR/$tfile
23545         $LCTL set_param -n llite.*.file_heat=0
23546         echo "Turn off file heat support for the Lustre filesystem"
23547
23548         echo "QQQQ" > $DIR/$tfile
23549         echo "QQQQ" > $DIR/$tfile
23550         echo "QQQQ" > $DIR/$tfile
23551         cat $DIR/$tfile > /dev/null
23552         cat $DIR/$tfile > /dev/null
23553         cat $DIR/$tfile > /dev/null
23554         cat $DIR/$tfile > /dev/null
23555
23556         out=$($LFS heat_get $DIR/$tfile)
23557         $LFS heat_get $DIR/$tfile
23558         readsample=$(echo "$out" | grep 'readsample' | awk '{ print $2 }')
23559         writesample=$(echo "$out" | grep 'writesample' | awk '{ print $2 }')
23560         readbyte=$(echo "$out" | grep 'readbyte' | awk '{ print $2 }')
23561         writebyte=$(echo "$out" | grep 'writebyte' | awk '{ print $2 }')
23562
23563         [ $readsample -eq 0 ] || error "read sample ($readsample) is wrong"
23564         [ $writesample -eq 0 ] || error "write sample ($writesample) is wrong"
23565         [ $readbyte -eq 0 ] || error "read bytes ($readbyte) is wrong"
23566         [ $writebyte -eq 0 ] || error "write bytes ($writebyte) is wrong"
23567
23568         $LCTL set_param -n llite.*.file_heat=$file_heat_sav
23569         rm -f $DIR/$tfile
23570 }
23571 run_test 813 "File heat verfication"
23572
23573 test_814()
23574 {
23575         dd of=$DIR/$tfile seek=128 bs=1k < /dev/null
23576         echo -n y >> $DIR/$tfile
23577         cp --sparse=always $DIR/$tfile $DIR/${tfile}.cp || error "copy failed"
23578         diff $DIR/$tfile $DIR/${tfile}.cp || error "files should be same"
23579 }
23580 run_test 814 "sparse cp works as expected (LU-12361)"
23581
23582 test_815()
23583 {
23584         writeme -b 100 $DIR/$tfile || error "write 100 bytes failed"
23585         writeme -b 0 $DIR/$tfile || error "write 0 byte failed"
23586 }
23587 run_test 815 "zero byte tiny write doesn't hang (LU-12382)"
23588
23589 test_816() {
23590         [ "$SHARED_KEY" = true ] &&
23591                 skip "OSC connections never go IDLE with Shared-Keys enabled"
23592
23593         $LFS setstripe -c 1 -i 0 $DIR/$tfile
23594         # ensure ost1 is connected
23595         stat $DIR/$tfile >/dev/null || error "can't stat"
23596         wait_osc_import_state client ost1 FULL
23597         # no locks, no reqs to let the connection idle
23598         cancel_lru_locks osc
23599         lru_resize_disable osc
23600         local before
23601         local now
23602         before=$($LCTL get_param -n \
23603                  ldlm.namespaces.$FSNAME-OST0000-osc-[^M]*.lru_size)
23604
23605         wait_osc_import_state client ost1 IDLE
23606         dd if=/dev/null of=$DIR/$tfile bs=1k count=1 conv=sync
23607         now=$($LCTL get_param -n \
23608               ldlm.namespaces.$FSNAME-OST0000-osc-[^M]*.lru_size)
23609         [ $before == $now ] || error "lru_size changed $before != $now"
23610 }
23611 run_test 816 "do not reset lru_resize on idle reconnect"
23612
23613 cleanup_817() {
23614         umount $tmpdir
23615         exportfs -u localhost:$DIR/nfsexp
23616         rm -rf $DIR/nfsexp
23617 }
23618
23619 test_817() {
23620         systemctl restart nfs-server.service || skip "failed to restart nfsd"
23621
23622         mkdir -p $DIR/nfsexp
23623         exportfs -orw,no_root_squash localhost:$DIR/nfsexp ||
23624                 error "failed to export nfs"
23625
23626         tmpdir=$(mktemp -d /tmp/nfs-XXXXXX)
23627         stack_trap cleanup_817 EXIT
23628
23629         mount -t nfs -orw localhost:$DIR/nfsexp $tmpdir ||
23630                 error "failed to mount nfs to $tmpdir"
23631
23632         cp /bin/true $tmpdir
23633         $DIR/nfsexp/true || error "failed to execute 'true' command"
23634 }
23635 run_test 817 "nfsd won't cache write lock for exec file"
23636
23637 test_818() {
23638         mkdir $DIR/$tdir
23639         $LFS setstripe -c1 -i0 $DIR/$tfile
23640         $LFS setstripe -c1 -i1 $DIR/$tfile
23641         stop $SINGLEMDS
23642         #define OBD_FAIL_OSP_CANT_PROCESS_LLOG          0x2105
23643         do_facet $SINGLEMDS lctl set_param fail_loc=0x80002105
23644         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
23645                 error "start $SINGLEMDS failed"
23646         rm -rf $DIR/$tdir
23647 }
23648 run_test 818 "unlink with failed llog"
23649
23650 test_819a() {
23651         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
23652         cancel_lru_locks osc
23653         #define OBD_FAIL_OST_2BIG_NIOBUF                0x248
23654         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000248
23655         dd if=$DIR/$tfile of=/dev/null bs=1M count=1
23656         rm -f $TDIR/$tfile
23657 }
23658 run_test 819a "too big niobuf in read"
23659
23660 test_819b() {
23661         #define OBD_FAIL_OST_2BIG_NIOBUF                0x248
23662         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000248
23663         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
23664         cancel_lru_locks osc
23665         sleep 1
23666         rm -f $TDIR/$tfile
23667 }
23668 run_test 819b "too big niobuf in write"
23669
23670
23671 function test_820_start_ost() {
23672         sleep 5
23673
23674         for num in $(seq $OSTCOUNT); do
23675                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS
23676         done
23677 }
23678
23679 test_820() {
23680         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
23681
23682         mkdir $DIR/$tdir
23683         umount_client $MOUNT || error "umount failed"
23684         for num in $(seq $OSTCOUNT); do
23685                 stop ost$num
23686         done
23687
23688         # mount client with no active OSTs
23689         # so that the client can't initialize max LOV EA size
23690         # from OSC notifications
23691         mount_client $MOUNT || error "mount failed"
23692         # delay OST starting to keep this 0 max EA size for a while
23693         test_820_start_ost &
23694
23695         # create a directory on MDS2
23696         test_mkdir -i 1 -c1 $DIR/$tdir/mds2 ||
23697                 error "Failed to create directory"
23698         # open intent should update default EA size
23699         # see mdc_update_max_ea_from_body()
23700         # notice this is the very first RPC to MDS2
23701         cp /etc/services $DIR/$tdir/mds2 ||
23702                 error "Failed to copy files to mds$n"
23703 }
23704 run_test 820 "update max EA from open intent"
23705
23706 #
23707 # tests that do cleanup/setup should be run at the end
23708 #
23709
23710 test_900() {
23711         [ $PARALLEL == "yes" ] && skip "skip parallel run"
23712         local ls
23713
23714         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
23715         $LCTL set_param fail_loc=0x903
23716
23717         cancel_lru_locks MGC
23718
23719         FAIL_ON_ERROR=true cleanup
23720         FAIL_ON_ERROR=true setup
23721 }
23722 run_test 900 "umount should not race with any mgc requeue thread"
23723
23724 # LUS-6253/LU-11185
23725 test_901() {
23726         local oldc
23727         local newc
23728         local olds
23729         local news
23730         [ $PARALLEL == "yes" ] && skip "skip parallel run"
23731
23732         # some get_param have a bug to handle dot in param name
23733         cancel_lru_locks MGC
23734         oldc=$($LCTL get_param -n 'ldlm.namespaces.MGC*.lock_count')
23735         olds=$(do_facet mgs $LCTL get_param -n 'ldlm.namespaces.MGS*.lock_count')
23736         umount_client $MOUNT || error "umount failed"
23737         mount_client $MOUNT || error "mount failed"
23738         cancel_lru_locks MGC
23739         newc=$($LCTL get_param -n 'ldlm.namespaces.MGC*.lock_count')
23740         news=$(do_facet mgs $LCTL get_param -n 'ldlm.namespaces.MGS*.lock_count')
23741
23742         [ $oldc -lt $newc ] && error "mgc lock leak ($oldc != $newc)"
23743         [ $olds -lt $news ] && error "mgs lock leak ($olds != $news)"
23744
23745         return 0
23746 }
23747 run_test 901 "don't leak a mgc lock on client umount"
23748
23749 # LU-13377
23750 test_902() {
23751         [ $CLIENT_VERSION -lt $(version_code 2.13.52) ] &&
23752                 skip "client does not have LU-13377 fix"
23753         #define OBD_FAIL_LLITE_SHORT_COMMIT 0x1415
23754         $LCTL set_param fail_loc=0x1415
23755         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
23756         cancel_lru_locks osc
23757         rm -f $DIR/$tfile
23758 }
23759 run_test 902 "test short write doesn't hang lustre"
23760
23761 complete $SECONDS
23762 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
23763 check_and_cleanup_lustre
23764 if [ "$I_MOUNTED" != "yes" ]; then
23765         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
23766 fi
23767 exit_status