Whamcloud - gitweb
LU-14789 tests: make sanity 133f and 133g working
[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
45 ALWAYS_EXCEPT+=" 407     312"
46
47 if $SHARED_KEY; then
48         # bug number:    LU-14181 LU-14181
49         ALWAYS_EXCEPT+=" 64e      64f"
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         # bug number:    LU-14067 LU-14067
65         ALWAYS_EXCEPT+=" 400a     400b"
66 fi
67
68 # skip nfs tests on kernels >= 4.12.0 until they are fixed
69 if [ $LINUX_VERSION_CODE -ge $(version_code 4.12.0) ]; then
70         # bug number:   LU-12661
71         ALWAYS_EXCEPT+=" 817"
72 fi
73 # skip cgroup tests on RHEL8.1 kernels until they are fixed
74 if (( $LINUX_VERSION_CODE >= $(version_code 4.18.0) &&
75       $LINUX_VERSION_CODE <  $(version_code 5.4.0) )); then
76         # bug number:   LU-13063
77         ALWAYS_EXCEPT+=" 411"
78 fi
79
80 #                                  5              12     8   12  (min)"
81 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 60i 64b 68 71 115 135 136 300o"
82
83 if [ "$mds1_FSTYPE" = "zfs" ]; then
84         # bug number for skipped test:
85         ALWAYS_EXCEPT+="              "
86         #                                               13    (min)"
87         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
88 fi
89
90 if [ "$ost1_FSTYPE" = "zfs" ]; then
91         # bug number for skipped test:  LU-1941  LU-1941  LU-1941  LU-1941
92         ALWAYS_EXCEPT+="                130a 130b 130c 130d 130e 130f 130g"
93 fi
94
95 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
96
97 # Get the SLES distro version
98 #
99 # Returns a version string that should only be used in comparing
100 # strings returned by version_code()
101 sles_version_code()
102 {
103         local version=$(grep VERSION_ID /etc/os-release | cut -d'"' -f2)
104
105         # All SuSE Linux versions have one decimal. version_code expects two
106         local sles_version=$version.0
107         version_code $sles_version
108 }
109
110 # Check if we are running on Ubuntu or SLES so we can make decisions on
111 # what tests to run
112 if [ -r /etc/SuSE-release ]; then
113         sles_version=$(sles_version_code)
114         [ $sles_version -lt $(version_code 11.4.0) ] &&
115                 # bug number for skipped test: LU-4341
116                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT  170"
117         [ $sles_version -lt $(version_code 12.0.0) ] &&
118                 # bug number for skipped test: LU-3703
119                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT  234"
120 elif [ -r /etc/os-release ]; then
121         if grep -qi ubuntu /etc/os-release; then
122                 ubuntu_version=$(version_code $(sed -n -e 's/"//g' \
123                                                 -e 's/^VERSION=//p' \
124                                                 /etc/os-release |
125                                                 awk '{ print $1 }'))
126
127                 if [[ $ubuntu_version -gt $(version_code 16.0.0) ]]; then
128                         # bug number for skipped test:
129                         #                LU-10334 LU-10366
130                         ALWAYS_EXCEPT+=" 103a     410"
131                 fi
132         fi
133 fi
134
135 build_test_filter
136 FAIL_ON_ERROR=false
137
138 cleanup() {
139         echo -n "cln.."
140         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
141         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
142 }
143 setup() {
144         echo -n "mnt.."
145         load_modules
146         setupall || exit 10
147         echo "done"
148 }
149
150 check_swap_layouts_support()
151 {
152         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
153                 skip "Does not support layout lock."
154 }
155
156 check_swap_layout_no_dom()
157 {
158         local FOLDER=$1
159         local SUPP=$(lfs getstripe $FOLDER | grep "pattern:       mdt" | wc -l)
160         [ $SUPP -eq 0 ] || skip "layout swap does not support DOM files so far"
161 }
162
163 check_and_setup_lustre
164 DIR=${DIR:-$MOUNT}
165 assert_DIR
166
167 MAXFREE=${MAXFREE:-$((300000 * $OSTCOUNT))}
168
169 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
170 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
171 rm -rf $DIR/[Rdfs][0-9]*
172
173 # $RUNAS_ID may get set incorrectly somewhere else
174 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
175         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
176
177 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
178
179 if [ "${ONLY}" = "MOUNT" ] ; then
180         echo "Lustre is up, please go on"
181         exit
182 fi
183
184 echo "preparing for tests involving mounts"
185 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
186 touch $EXT2_DEV
187 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
188 echo # add a newline after mke2fs.
189
190 umask 077
191
192 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
193 lctl set_param debug=-1 2> /dev/null || true
194 test_0a() {
195         touch $DIR/$tfile
196         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
197         rm $DIR/$tfile
198         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
199 }
200 run_test 0a "touch; rm ====================="
201
202 test_0b() {
203         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
204         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
205 }
206 run_test 0b "chmod 0755 $DIR ============================="
207
208 test_0c() {
209         $LCTL get_param mdc.*.import | grep "state: FULL" ||
210                 error "import not FULL"
211         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
212                 error "bad target"
213 }
214 run_test 0c "check import proc"
215
216 test_0d() { # LU-3397
217         [ $MGS_VERSION -lt $(version_code 2.10.57) ] &&
218                 skip "proc exports not supported before 2.10.57"
219
220         local mgs_exp="mgs.MGS.exports"
221         local client_uuid=$($LCTL get_param -n mgc.*.uuid)
222         local exp_client_nid
223         local exp_client_version
224         local exp_val
225         local imp_val
226         local temp_imp=$DIR/$tfile.import
227         local temp_exp=$DIR/$tfile.export
228
229         # save mgc import file to $temp_imp
230         $LCTL get_param mgc.*.import | tee $temp_imp
231         # Check if client uuid is found in MGS export
232         for exp_client_nid in $(do_facet mgs $LCTL get_param -N $mgs_exp.*); do
233                 [ $(do_facet mgs $LCTL get_param -n $exp_client_nid.uuid) == \
234                         $client_uuid ] &&
235                         break;
236         done
237         # save mgs export file to $temp_exp
238         do_facet mgs $LCTL get_param $exp_client_nid.export | tee $temp_exp
239
240         # Compare the value of field "connect_flags"
241         imp_val=$(grep "connect_flags" $temp_imp)
242         exp_val=$(grep "connect_flags" $temp_exp)
243         [ "$exp_val" == "$imp_val" ] ||
244                 error "export flags '$exp_val' != import flags '$imp_val'"
245
246         # Compare client versions.  Only compare top-3 fields for compatibility
247         exp_client_version=$(awk '/target_version:/ { print $2 }' $temp_exp)
248         exp_val=$(version_code $(cut -d. -f1,2,3 <<<$exp_client_version))
249         imp_val=$(version_code $(lustre_build_version client | cut -d. -f1,2,3))
250         [ "$exp_val" == "$imp_val" ] ||
251                 error "exp version '$exp_client_version'($exp_val) != " \
252                         "'$(lustre_build_version client)'($imp_val)"
253 }
254 run_test 0d "check export proc ============================="
255
256 test_1() {
257         test_mkdir $DIR/$tdir
258         test_mkdir $DIR/$tdir/d2
259         mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
260         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
261         rmdir $DIR/$tdir/d2
262         rmdir $DIR/$tdir
263         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
264 }
265 run_test 1 "mkdir; remkdir; rmdir"
266
267 test_2() {
268         test_mkdir $DIR/$tdir
269         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
270         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
271         rm -r $DIR/$tdir
272         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
273 }
274 run_test 2 "mkdir; touch; rmdir; check file"
275
276 test_3() {
277         test_mkdir $DIR/$tdir
278         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
279         touch $DIR/$tdir/$tfile
280         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
281         rm -r $DIR/$tdir
282         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
283 }
284 run_test 3 "mkdir; touch; rmdir; check dir"
285
286 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
287 test_4() {
288         test_mkdir -i 1 $DIR/$tdir
289
290         touch $DIR/$tdir/$tfile ||
291                 error "Create file under remote directory failed"
292
293         rmdir $DIR/$tdir &&
294                 error "Expect error removing in-use dir $DIR/$tdir"
295
296         test -d $DIR/$tdir || error "Remote directory disappeared"
297
298         rm -rf $DIR/$tdir || error "remove remote dir error"
299 }
300 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
301
302 test_5() {
303         test_mkdir $DIR/$tdir
304         test_mkdir $DIR/$tdir/d2
305         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
306         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
307         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
308 }
309 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2"
310
311 test_6a() {
312         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
313         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
314         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
315                 error "$tfile does not have perm 0666 or UID $UID"
316         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
317         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
318                 error "$tfile should be 0666 and owned by UID $UID"
319 }
320 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
321
322 test_6c() {
323         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
324
325         touch $DIR/$tfile
326         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
327         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
328                 error "$tfile should be owned by UID $RUNAS_ID"
329         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
330         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
331                 error "$tfile should be owned by UID $RUNAS_ID"
332 }
333 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
334
335 test_6e() {
336         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
337
338         touch $DIR/$tfile
339         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
340         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
341                 error "$tfile should be owned by GID $UID"
342         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
343         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
344                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
345 }
346 run_test 6e "touch+chgrp $tfile; $RUNAS chgrp $tfile (should return error)"
347
348 test_6g() {
349         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
350
351         test_mkdir $DIR/$tdir
352         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
353         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
354         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
355         test_mkdir $DIR/$tdir/d/subdir
356         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
357                 error "$tdir/d/subdir should be GID $RUNAS_GID"
358         if [[ $MDSCOUNT -gt 1 ]]; then
359                 # check remote dir sgid inherite
360                 $LFS mkdir -i 0 $DIR/$tdir.local ||
361                         error "mkdir $tdir.local failed"
362                 chmod g+s $DIR/$tdir.local ||
363                         error "chmod $tdir.local failed"
364                 chgrp $RUNAS_GID $DIR/$tdir.local ||
365                         error "chgrp $tdir.local failed"
366                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
367                         error "mkdir $tdir.remote failed"
368                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
369                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
370                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
371                         error "$tdir.remote should be mode 02755"
372         fi
373 }
374 run_test 6g "verify new dir in sgid dir inherits group"
375
376 test_6h() { # bug 7331
377         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
378
379         touch $DIR/$tfile || error "touch failed"
380         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
381         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
382                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
383         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
384                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
385 }
386 run_test 6h "$RUNAS chown RUNAS_ID.0 .../$tfile (should return error)"
387
388 test_7a() {
389         test_mkdir $DIR/$tdir
390         $MCREATE $DIR/$tdir/$tfile
391         chmod 0666 $DIR/$tdir/$tfile
392         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
393                 error "$tdir/$tfile should be mode 0666"
394 }
395 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
396
397 test_7b() {
398         if [ ! -d $DIR/$tdir ]; then
399                 test_mkdir $DIR/$tdir
400         fi
401         $MCREATE $DIR/$tdir/$tfile
402         echo -n foo > $DIR/$tdir/$tfile
403         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
404         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
405 }
406 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
407
408 test_8() {
409         test_mkdir $DIR/$tdir
410         touch $DIR/$tdir/$tfile
411         chmod 0666 $DIR/$tdir/$tfile
412         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
413                 error "$tfile mode not 0666"
414 }
415 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
416
417 test_9() {
418         test_mkdir $DIR/$tdir
419         test_mkdir $DIR/$tdir/d2
420         test_mkdir $DIR/$tdir/d2/d3
421         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
422 }
423 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
424
425 test_10() {
426         test_mkdir $DIR/$tdir
427         test_mkdir $DIR/$tdir/d2
428         touch $DIR/$tdir/d2/$tfile
429         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
430                 error "$tdir/d2/$tfile not a file"
431 }
432 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
433
434 test_11() {
435         test_mkdir $DIR/$tdir
436         test_mkdir $DIR/$tdir/d2
437         chmod 0666 $DIR/$tdir/d2
438         chmod 0705 $DIR/$tdir/d2
439         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
440                 error "$tdir/d2 mode not 0705"
441 }
442 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
443
444 test_12() {
445         test_mkdir $DIR/$tdir
446         touch $DIR/$tdir/$tfile
447         chmod 0666 $DIR/$tdir/$tfile
448         chmod 0654 $DIR/$tdir/$tfile
449         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
450                 error "$tdir/d2 mode not 0654"
451 }
452 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
453
454 test_13() {
455         test_mkdir $DIR/$tdir
456         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
457         >  $DIR/$tdir/$tfile
458         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
459                 error "$tdir/$tfile size not 0 after truncate"
460 }
461 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
462
463 test_14() {
464         test_mkdir $DIR/$tdir
465         touch $DIR/$tdir/$tfile
466         rm $DIR/$tdir/$tfile
467         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
468 }
469 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
470
471 test_15() {
472         test_mkdir $DIR/$tdir
473         touch $DIR/$tdir/$tfile
474         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
475         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
476                 error "$tdir/${tfile_2} not a file after rename"
477         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
478 }
479 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
480
481 test_16() {
482         test_mkdir $DIR/$tdir
483         touch $DIR/$tdir/$tfile
484         rm -rf $DIR/$tdir/$tfile
485         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
486 }
487 run_test 16 "touch .../d16/f; rm -rf .../d16/f"
488
489 test_17a() {
490         test_mkdir $DIR/$tdir
491         touch $DIR/$tdir/$tfile
492         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
493         ls -l $DIR/$tdir
494         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
495                 error "$tdir/l-exist not a symlink"
496         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
497                 error "$tdir/l-exist not referencing a file"
498         rm -f $DIR/$tdir/l-exist
499         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
500 }
501 run_test 17a "symlinks: create, remove (real)"
502
503 test_17b() {
504         test_mkdir $DIR/$tdir
505         ln -s no-such-file $DIR/$tdir/l-dangle
506         ls -l $DIR/$tdir
507         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
508                 error "$tdir/l-dangle not referencing no-such-file"
509         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
510                 error "$tdir/l-dangle not referencing non-existent file"
511         rm -f $DIR/$tdir/l-dangle
512         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
513 }
514 run_test 17b "symlinks: create, remove (dangling)"
515
516 test_17c() { # bug 3440 - don't save failed open RPC for replay
517         test_mkdir $DIR/$tdir
518         ln -s foo $DIR/$tdir/$tfile
519         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
520 }
521 run_test 17c "symlinks: open dangling (should return error)"
522
523 test_17d() {
524         test_mkdir $DIR/$tdir
525         ln -s foo $DIR/$tdir/$tfile
526         touch $DIR/$tdir/$tfile || error "creating to new symlink"
527 }
528 run_test 17d "symlinks: create dangling"
529
530 test_17e() {
531         test_mkdir $DIR/$tdir
532         local foo=$DIR/$tdir/$tfile
533         ln -s $foo $foo || error "create symlink failed"
534         ls -l $foo || error "ls -l failed"
535         ls $foo && error "ls not failed" || true
536 }
537 run_test 17e "symlinks: create recursive symlink (should return error)"
538
539 test_17f() {
540         test_mkdir $DIR/$tdir
541         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
542         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
543         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
544         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
545         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
546         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
547         ls -l  $DIR/$tdir
548 }
549 run_test 17f "symlinks: long and very long symlink name"
550
551 # str_repeat(S, N) generate a string that is string S repeated N times
552 str_repeat() {
553         local s=$1
554         local n=$2
555         local ret=''
556         while [ $((n -= 1)) -ge 0 ]; do
557                 ret=$ret$s
558         done
559         echo $ret
560 }
561
562 # Long symlinks and LU-2241
563 test_17g() {
564         test_mkdir $DIR/$tdir
565         local TESTS="59 60 61 4094 4095"
566
567         # Fix for inode size boundary in 2.1.4
568         [ $MDS1_VERSION -lt $(version_code 2.1.4) ] &&
569                 TESTS="4094 4095"
570
571         # Patch not applied to 2.2 or 2.3 branches
572         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] &&
573         [ $MDS1_VERSION -le $(version_code 2.3.55) ] &&
574                 TESTS="4094 4095"
575
576         for i in $TESTS; do
577                 local SYMNAME=$(str_repeat 'x' $i)
578                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
579                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
580         done
581 }
582 run_test 17g "symlinks: really long symlink name and inode boundaries"
583
584 test_17h() { #bug 17378
585         [ $PARALLEL == "yes" ] && skip "skip parallel run"
586         remote_mds_nodsh && skip "remote MDS with nodsh"
587
588         local mdt_idx
589
590         test_mkdir $DIR/$tdir
591         mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
592         $LFS setstripe -c -1 $DIR/$tdir
593         #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
594         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
595         touch $DIR/$tdir/$tfile || true
596 }
597 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
598
599 test_17i() { #bug 20018
600         [ $PARALLEL == "yes" ] && skip "skip parallel run"
601         remote_mds_nodsh && skip "remote MDS with nodsh"
602
603         local foo=$DIR/$tdir/$tfile
604         local mdt_idx
605
606         test_mkdir -c1 $DIR/$tdir
607         mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
608         ln -s $foo $foo || error "create symlink failed"
609 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
610         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
611         ls -l $foo && error "error not detected"
612         return 0
613 }
614 run_test 17i "don't panic on short symlink (should return error)"
615
616 test_17k() { #bug 22301
617         [ $PARALLEL == "yes" ] && skip "skip parallel run"
618         [[ -z "$(which rsync 2>/dev/null)" ]] &&
619                 skip "no rsync command"
620         rsync --help | grep -q xattr ||
621                 skip_env "$(rsync --version | head -n1) does not support xattrs"
622         test_mkdir $DIR/$tdir
623         test_mkdir $DIR/$tdir.new
624         touch $DIR/$tdir/$tfile
625         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
626         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
627                 error "rsync failed with xattrs enabled"
628 }
629 run_test 17k "symlinks: rsync with xattrs enabled"
630
631 test_17l() { # LU-279
632         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
633                 skip "no getfattr command"
634
635         test_mkdir $DIR/$tdir
636         touch $DIR/$tdir/$tfile
637         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
638         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
639                 # -h to not follow symlinks. -m '' to list all the xattrs.
640                 # grep to remove first line: '# file: $path'.
641                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
642                 do
643                         lgetxattr_size_check $path $xattr ||
644                                 error "lgetxattr_size_check $path $xattr failed"
645                 done
646         done
647 }
648 run_test 17l "Ensure lgetxattr's returned xattr size is consistent"
649
650 # LU-1540
651 test_17m() {
652         [ $PARALLEL == "yes" ] && skip "skip parallel run"
653         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
654         remote_mds_nodsh && skip "remote MDS with nodsh"
655         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] &&
656         [ $MDS1_VERSION -le $(version_code 2.2.93) ] &&
657                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks"
658
659         local short_sym="0123456789"
660         local wdir=$DIR/$tdir
661         local i
662
663         test_mkdir $wdir
664         long_sym=$short_sym
665         # create a long symlink file
666         for ((i = 0; i < 4; ++i)); do
667                 long_sym=${long_sym}${long_sym}
668         done
669
670         echo "create 512 short and long symlink files under $wdir"
671         for ((i = 0; i < 256; ++i)); do
672                 ln -sf ${long_sym}"a5a5" $wdir/long-$i
673                 ln -sf ${short_sym}"a5a5" $wdir/short-$i
674         done
675
676         echo "erase them"
677         rm -f $wdir/*
678         sync
679         wait_delete_completed
680
681         echo "recreate the 512 symlink files with a shorter string"
682         for ((i = 0; i < 512; ++i)); do
683                 # rewrite the symlink file with a shorter string
684                 ln -sf ${long_sym} $wdir/long-$i || error "long_sym failed"
685                 ln -sf ${short_sym} $wdir/short-$i || error "short_sym failed"
686         done
687
688         local mds_index=$(($($LFS getstripe -m $wdir) + 1))
689         local devname=$(mdsdevname $mds_index)
690
691         echo "stop and checking mds${mds_index}:"
692         # e2fsck should not return error
693         stop mds${mds_index}
694         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
695         rc=$?
696
697         start mds${mds_index} $devname $MDS_MOUNT_OPTS ||
698                 error "start mds${mds_index} failed"
699         df $MOUNT > /dev/null 2>&1
700         [ $rc -eq 0 ] ||
701                 error "e2fsck detected error for short/long symlink: rc=$rc"
702         rm -f $wdir/*
703 }
704 run_test 17m "run e2fsck against MDT which contains short/long symlink"
705
706 check_fs_consistency_17n() {
707         local mdt_index
708         local rc=0
709
710         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
711         # so it only check MDT1/MDT2 instead of all of MDTs.
712         for mdt_index in 1 2; do
713                 local devname=$(mdsdevname $mdt_index)
714                 # e2fsck should not return error
715                 stop mds${mdt_index}
716                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
717                         rc=$((rc + $?))
718
719                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
720                         error "mount mds$mdt_index failed"
721                 df $MOUNT > /dev/null 2>&1
722         done
723         return $rc
724 }
725
726 test_17n() {
727         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
728         [ $PARALLEL == "yes" ] && skip "skip parallel run"
729         [ "$mds1_FSTYPE" != "ldiskfs" ] && skip_env "ldiskfs only test"
730         remote_mds_nodsh && skip "remote MDS with nodsh"
731         [ $MDS1_VERSION -ge $(version_code 2.2.0) ] &&
732         [ $MDS1_VERSION -le $(version_code 2.2.93) ] &&
733                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks"
734
735         local i
736
737         test_mkdir $DIR/$tdir
738         for ((i=0; i<10; i++)); do
739                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
740                         error "create remote dir error $i"
741                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
742                         error "create files under remote dir failed $i"
743         done
744
745         check_fs_consistency_17n ||
746                 error "e2fsck report error after create files under remote dir"
747
748         for ((i = 0; i < 10; i++)); do
749                 rm -rf $DIR/$tdir/remote_dir_${i} ||
750                         error "destroy remote dir error $i"
751         done
752
753         check_fs_consistency_17n ||
754                 error "e2fsck report error after unlink files under remote dir"
755
756         [ $MDS1_VERSION -lt $(version_code 2.4.50) ] &&
757                 skip "lustre < 2.4.50 does not support migrate mv"
758
759         for ((i = 0; i < 10; i++)); do
760                 mkdir -p $DIR/$tdir/remote_dir_${i}
761                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
762                         error "create files under remote dir failed $i"
763                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
764                         error "migrate remote dir error $i"
765         done
766         check_fs_consistency_17n || error "e2fsck report error after migration"
767
768         for ((i = 0; i < 10; i++)); do
769                 rm -rf $DIR/$tdir/remote_dir_${i} ||
770                         error "destroy remote dir error $i"
771         done
772
773         check_fs_consistency_17n || error "e2fsck report error after unlink"
774 }
775 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
776
777 test_17o() {
778         remote_mds_nodsh && skip "remote MDS with nodsh"
779         [ $MDS1_VERSION -lt $(version_code 2.3.64) ] &&
780                 skip "Need MDS version at least 2.3.64"
781
782         local wdir=$DIR/${tdir}o
783         local mdt_index
784         local rc=0
785
786         test_mkdir $wdir
787         touch $wdir/$tfile
788         mdt_index=$($LFS getstripe -m $wdir/$tfile)
789         mdt_index=$((mdt_index + 1))
790
791         cancel_lru_locks mdc
792         #fail mds will wait the failover finish then set
793         #following fail_loc to avoid interfer the recovery process.
794         fail mds${mdt_index}
795
796         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
797         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
798         ls -l $wdir/$tfile && rc=1
799         do_facet mds${mdt_index} lctl set_param fail_loc=0
800         [[ $rc -eq 0 ]] || error "stat file should fail"
801 }
802 run_test 17o "stat file with incompat LMA feature"
803
804 test_18() {
805         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
806         ls $DIR || error "Failed to ls $DIR: $?"
807 }
808 run_test 18 "touch .../f ; ls ... =============================="
809
810 test_19a() {
811         touch $DIR/$tfile
812         ls -l $DIR
813         rm $DIR/$tfile
814         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
815 }
816 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
817
818 test_19b() {
819         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
820 }
821 run_test 19b "ls -l .../f19 (should return error) =============="
822
823 test_19c() {
824         [ $RUNAS_ID -eq $UID ] &&
825                 skip_env "RUNAS_ID = UID = $UID -- skipping"
826
827         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
828 }
829 run_test 19c "$RUNAS touch .../f19 (should return error) =="
830
831 test_19d() {
832         cat $DIR/f19 && error || true
833 }
834 run_test 19d "cat .../f19 (should return error) =============="
835
836 test_20() {
837         touch $DIR/$tfile
838         rm $DIR/$tfile
839         touch $DIR/$tfile
840         rm $DIR/$tfile
841         touch $DIR/$tfile
842         rm $DIR/$tfile
843         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
844 }
845 run_test 20 "touch .../f ; ls -l ..."
846
847 test_21() {
848         test_mkdir $DIR/$tdir
849         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
850         ln -s dangle $DIR/$tdir/link
851         echo foo >> $DIR/$tdir/link
852         cat $DIR/$tdir/dangle
853         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
854         $CHECKSTAT -f -t file $DIR/$tdir/link ||
855                 error "$tdir/link not linked to a file"
856 }
857 run_test 21 "write to dangling link"
858
859 test_22() {
860         local wdir=$DIR/$tdir
861         test_mkdir $wdir
862         chown $RUNAS_ID:$RUNAS_GID $wdir
863         (cd $wdir || error "cd $wdir failed";
864                 $RUNAS tar cf - /etc/hosts /etc/sysconfig/network |
865                 $RUNAS tar xf -)
866         ls -lR $wdir/etc || error "ls -lR $wdir/etc failed"
867         $CHECKSTAT -t dir $wdir/etc || error "checkstat -t dir failed"
868         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $wdir/etc ||
869                 error "checkstat -u failed"
870 }
871 run_test 22 "unpack tar archive as non-root user"
872
873 # was test_23
874 test_23a() {
875         test_mkdir $DIR/$tdir
876         local file=$DIR/$tdir/$tfile
877
878         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
879         openfile -f O_CREAT:O_EXCL $file &&
880                 error "$file recreate succeeded" || true
881 }
882 run_test 23a "O_CREAT|O_EXCL in subdir"
883
884 test_23b() { # bug 18988
885         test_mkdir $DIR/$tdir
886         local file=$DIR/$tdir/$tfile
887
888         rm -f $file
889         echo foo > $file || error "write filed"
890         echo bar >> $file || error "append filed"
891         $CHECKSTAT -s 8 $file || error "wrong size"
892         rm $file
893 }
894 run_test 23b "O_APPEND check"
895
896 # LU-9409, size with O_APPEND and tiny writes
897 test_23c() {
898         local file=$DIR/$tfile
899
900         # single dd
901         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800
902         $CHECKSTAT -s 6400 $file || error "wrong size, expected 6400"
903         rm -f $file
904
905         # racing tiny writes
906         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
907         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
908         wait
909         $CHECKSTAT -s 12800 $file || error "wrong size, expected 12800"
910         rm -f $file
911
912         #racing tiny & normal writes
913         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4096 count=4 &
914         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=100 &
915         wait
916         $CHECKSTAT -s 17184 $file || error "wrong size, expected 17184"
917         rm -f $file
918
919         #racing tiny & normal writes 2, ugly numbers
920         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4099 count=11 &
921         dd conv=notrunc oflag=append if=/dev/zero of=$file bs=17 count=173 &
922         wait
923         $CHECKSTAT -s 48030 $file || error "wrong size, expected 48030"
924         rm -f $file
925 }
926 run_test 23c "O_APPEND size checks for tiny writes"
927
928 # LU-11069 file offset is correct after appending writes
929 test_23d() {
930         local file=$DIR/$tfile
931         local offset
932
933         echo CentaurHauls > $file
934         offset=$($MULTIOP $file oO_WRONLY:O_APPEND:w13Zp)
935         if ((offset != 26)); then
936                 error "wrong offset, expected 26, got '$offset'"
937         fi
938 }
939 run_test 23d "file offset is correct after appending writes"
940
941 # rename sanity
942 test_24a() {
943         echo '-- same directory rename'
944         test_mkdir $DIR/$tdir
945         touch $DIR/$tdir/$tfile.1
946         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
947         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
948 }
949 run_test 24a "rename file to non-existent target"
950
951 test_24b() {
952         test_mkdir $DIR/$tdir
953         touch $DIR/$tdir/$tfile.{1,2}
954         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
955         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
956         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
957 }
958 run_test 24b "rename file to existing target"
959
960 test_24c() {
961         test_mkdir $DIR/$tdir
962         test_mkdir $DIR/$tdir/d$testnum.1
963         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
964         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
965         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
966 }
967 run_test 24c "rename directory to non-existent target"
968
969 test_24d() {
970         test_mkdir -c1 $DIR/$tdir
971         test_mkdir -c1 $DIR/$tdir/d$testnum.1
972         test_mkdir -c1 $DIR/$tdir/d$testnum.2
973         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
974         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
975         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
976 }
977 run_test 24d "rename directory to existing target"
978
979 test_24e() {
980         echo '-- cross directory renames --'
981         test_mkdir $DIR/R5a
982         test_mkdir $DIR/R5b
983         touch $DIR/R5a/f
984         mv $DIR/R5a/f $DIR/R5b/g
985         $CHECKSTAT -a $DIR/R5a/f || error "$DIR/R5a/f exists"
986         $CHECKSTAT -t file $DIR/R5b/g || error "$DIR/R5b/g not file type"
987 }
988 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
989
990 test_24f() {
991         test_mkdir $DIR/R6a
992         test_mkdir $DIR/R6b
993         touch $DIR/R6a/f $DIR/R6b/g
994         mv $DIR/R6a/f $DIR/R6b/g
995         $CHECKSTAT -a $DIR/R6a/f || error "$DIR/R6a/f exists"
996         $CHECKSTAT -t file $DIR/R6b/g || error "$DIR/R6b/g not file type"
997 }
998 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
999
1000 test_24g() {
1001         test_mkdir $DIR/R7a
1002         test_mkdir $DIR/R7b
1003         test_mkdir $DIR/R7a/d
1004         mv $DIR/R7a/d $DIR/R7b/e
1005         $CHECKSTAT -a $DIR/R7a/d || error "$DIR/R7a/d exists"
1006         $CHECKSTAT -t dir $DIR/R7b/e || error "$DIR/R7b/e not dir type"
1007 }
1008 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
1009
1010 test_24h() {
1011         test_mkdir -c1 $DIR/R8a
1012         test_mkdir -c1 $DIR/R8b
1013         test_mkdir -c1 $DIR/R8a/d
1014         test_mkdir -c1 $DIR/R8b/e
1015         mrename $DIR/R8a/d $DIR/R8b/e
1016         $CHECKSTAT -a $DIR/R8a/d || error "$DIR/R8a/d exists"
1017         $CHECKSTAT -t dir $DIR/R8b/e || error "$DIR/R8b/e not dir type"
1018 }
1019 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
1020
1021 test_24i() {
1022         echo "-- rename error cases"
1023         test_mkdir $DIR/R9
1024         test_mkdir $DIR/R9/a
1025         touch $DIR/R9/f
1026         mrename $DIR/R9/f $DIR/R9/a
1027         $CHECKSTAT -t file $DIR/R9/f || error "$DIR/R9/f not file type"
1028         $CHECKSTAT -t dir  $DIR/R9/a || error "$DIR/R9/a not dir type"
1029         $CHECKSTAT -a $DIR/R9/a/f || error "$DIR/R9/a/f exists"
1030 }
1031 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
1032
1033 test_24j() {
1034         test_mkdir $DIR/R10
1035         mrename $DIR/R10/f $DIR/R10/g
1036         $CHECKSTAT -t dir $DIR/R10 || error "$DIR/R10 not dir type"
1037         $CHECKSTAT -a $DIR/R10/f || error "$DIR/R10/f exists"
1038         $CHECKSTAT -a $DIR/R10/g || error "$DIR/R10/g exists"
1039 }
1040 run_test 24j "source does not exist ============================"
1041
1042 test_24k() {
1043         test_mkdir $DIR/R11a
1044         test_mkdir $DIR/R11a/d
1045         touch $DIR/R11a/f
1046         mv $DIR/R11a/f $DIR/R11a/d
1047         $CHECKSTAT -a $DIR/R11a/f || error "$DIR/R11a/f exists"
1048         $CHECKSTAT -t file $DIR/R11a/d/f || error "$DIR/R11a/d/f not file type"
1049 }
1050 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
1051
1052 # bug 2429 - rename foo foo foo creates invalid file
1053 test_24l() {
1054         f="$DIR/f24l"
1055         $MULTIOP $f OcNs || error "rename of ${f} to itself failed"
1056 }
1057 run_test 24l "Renaming a file to itself ========================"
1058
1059 test_24m() {
1060         f="$DIR/f24m"
1061         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
1062         # on ext3 this does not remove either the source or target files
1063         # though the "expected" operation would be to remove the source
1064         $CHECKSTAT -t file ${f} || error "${f} missing"
1065         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
1066 }
1067 run_test 24m "Renaming a file to a hard link to itself ========="
1068
1069 test_24n() {
1070     f="$DIR/f24n"
1071     # this stats the old file after it was renamed, so it should fail
1072     touch ${f}
1073     $CHECKSTAT ${f} || error "${f} missing"
1074     mv ${f} ${f}.rename
1075     $CHECKSTAT ${f}.rename || error "${f}.rename missing"
1076     $CHECKSTAT -a ${f} || error "${f} exists"
1077 }
1078 run_test 24n "Statting the old file after renaming (Posix rename 2)"
1079
1080 test_24o() {
1081         test_mkdir $DIR/$tdir
1082         rename_many -s random -v -n 10 $DIR/$tdir
1083 }
1084 run_test 24o "rename of files during htree split"
1085
1086 test_24p() {
1087         test_mkdir $DIR/R12a
1088         test_mkdir $DIR/R12b
1089         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
1090         mrename $DIR/R12a $DIR/R12b
1091         $CHECKSTAT -a $DIR/R12a || error "$DIR/R12a exists"
1092         $CHECKSTAT -t dir $DIR/R12b || error "$DIR/R12b not dir type"
1093         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
1094         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
1095 }
1096 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
1097
1098 cleanup_multiop_pause() {
1099         trap 0
1100         kill -USR1 $MULTIPID
1101 }
1102
1103 test_24q() {
1104         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1105
1106         test_mkdir $DIR/R13a
1107         test_mkdir $DIR/R13b
1108         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
1109         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
1110         MULTIPID=$!
1111
1112         trap cleanup_multiop_pause EXIT
1113         mrename $DIR/R13a $DIR/R13b
1114         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1115         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1116         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1117         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1118         cleanup_multiop_pause
1119         wait $MULTIPID || error "multiop close failed"
1120 }
1121 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1122
1123 test_24r() { #bug 3789
1124         test_mkdir $DIR/R14a
1125         test_mkdir $DIR/R14a/b
1126         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1127         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1128         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1129 }
1130 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1131
1132 test_24s() {
1133         test_mkdir $DIR/R15a
1134         test_mkdir $DIR/R15a/b
1135         test_mkdir $DIR/R15a/b/c
1136         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1137         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1138         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1139 }
1140 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1141 test_24t() {
1142         test_mkdir $DIR/R16a
1143         test_mkdir $DIR/R16a/b
1144         test_mkdir $DIR/R16a/b/c
1145         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1146         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1147         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1148 }
1149 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1150
1151 test_24u() { # bug12192
1152         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error "multiop failed"
1153         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1154 }
1155 run_test 24u "create stripe file"
1156
1157 simple_cleanup_common() {
1158         local rc=0
1159         trap 0
1160         [ -z "$DIR" ] || [ -z "$tdir" ] && return 0
1161
1162         local start=$SECONDS
1163         rm -rf $DIR/$tdir
1164         rc=$?
1165         wait_delete_completed
1166         echo "cleanup time $((SECONDS - start))"
1167         return $rc
1168 }
1169
1170 max_pages_per_rpc() {
1171         local mdtname="$(printf "MDT%04x" ${1:-0})"
1172         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1173 }
1174
1175 test_24v() {
1176         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1177
1178         local nrfiles=${COUNT:-100000}
1179         local fname="$DIR/$tdir/$tfile"
1180
1181         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1182         [ "$mds1_FSTYPE" = "zfs" ] && nrfiles=${COUNT:-10000}
1183
1184         test_mkdir "$(dirname $fname)"
1185         # assume MDT0000 has the fewest inodes
1186         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1187         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1188         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1189
1190         trap simple_cleanup_common EXIT
1191
1192         createmany -m "$fname" $nrfiles
1193
1194         cancel_lru_locks mdc
1195         lctl set_param mdc.*.stats clear
1196
1197         # was previously test_24D: LU-6101
1198         # readdir() returns correct number of entries after cursor reload
1199         local num_ls=$(ls $DIR/$tdir | wc -l)
1200         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1201         local num_all=$(ls -a $DIR/$tdir | wc -l)
1202         if [ $num_ls -ne $nrfiles ] || [ $num_uniq -ne $nrfiles ] ||
1203                 [ $num_all -ne $((nrfiles + 2)) ]; then
1204                         error "Expected $nrfiles files, got $num_ls " \
1205                                 "($num_uniq unique $num_all .&..)"
1206         fi
1207         # LU-5 large readdir
1208         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1209         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1210         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1211         # take into account of overhead in lu_dirpage header and end mark in
1212         # each page, plus one in rpc_num calculation.
1213         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1214         local page_entries=$(((PAGE_SIZE - 24) / dirent_size))
1215         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1216         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1217         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1218         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1219         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1220         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1221                 error "large readdir doesn't take effect: " \
1222                       "$mds_readpage should be about $rpc_max"
1223
1224         simple_cleanup_common
1225 }
1226 run_test 24v "list large directory (test hash collision, b=17560)"
1227
1228 test_24w() { # bug21506
1229         SZ1=234852
1230         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1231         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1232         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1233         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1234         [[ "$SZ1" -eq "$SZ2" ]] ||
1235                 error "Error reading at the end of the file $tfile"
1236 }
1237 run_test 24w "Reading a file larger than 4Gb"
1238
1239 test_24x() {
1240         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1241         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1242         [[ $MDS1_VERSION -lt $(version_code 2.7.56) ]] &&
1243                 skip "Need MDS version at least 2.7.56"
1244
1245         local MDTIDX=1
1246         local remote_dir=$DIR/$tdir/remote_dir
1247
1248         test_mkdir $DIR/$tdir
1249         $LFS mkdir -i $MDTIDX $remote_dir ||
1250                 error "create remote directory failed"
1251
1252         test_mkdir $DIR/$tdir/src_dir
1253         touch $DIR/$tdir/src_file
1254         test_mkdir $remote_dir/tgt_dir
1255         touch $remote_dir/tgt_file
1256
1257         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1258                 error "rename dir cross MDT failed!"
1259
1260         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1261                 error "rename file cross MDT failed!"
1262
1263         touch $DIR/$tdir/ln_file
1264         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1265                 error "ln file cross MDT failed"
1266
1267         rm -rf $DIR/$tdir || error "Can not delete directories"
1268 }
1269 run_test 24x "cross MDT rename/link"
1270
1271 test_24y() {
1272         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1273         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1274
1275         local remote_dir=$DIR/$tdir/remote_dir
1276         local mdtidx=1
1277
1278         test_mkdir $DIR/$tdir
1279         $LFS mkdir -i $mdtidx $remote_dir ||
1280                 error "create remote directory failed"
1281
1282         test_mkdir $remote_dir/src_dir
1283         touch $remote_dir/src_file
1284         test_mkdir $remote_dir/tgt_dir
1285         touch $remote_dir/tgt_file
1286
1287         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1288                 error "rename subdir in the same remote dir failed!"
1289
1290         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1291                 error "rename files in the same remote dir failed!"
1292
1293         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1294                 error "link files in the same remote dir failed!"
1295
1296         rm -rf $DIR/$tdir || error "Can not delete directories"
1297 }
1298 run_test 24y "rename/link on the same dir should succeed"
1299
1300 test_24z() {
1301         [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1302         [[ $MDS1_VERSION -lt $(version_code 2.12.51) ]] &&
1303                 skip "Need MDS version at least 2.12.51"
1304
1305         local index
1306
1307         for index in 0 1; do
1308                 $LFS mkdir -i $index $DIR/$tdir.$index || error "mkdir failed"
1309                 touch $DIR/$tdir.0/$tfile.$index || error "touch failed"
1310         done
1311
1312         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1 || error "mv $tfile.0 failed"
1313
1314         index=$($LFS getstripe -m $DIR/$tdir.1/$tfile.0)
1315         [ $index -eq 0 ] || error "$tfile.0 is on MDT$index"
1316
1317         local mdts=$(comma_list $(mdts_nodes))
1318
1319         do_nodes $mdts $LCTL set_param mdt.*.enable_remote_rename=0
1320         stack_trap "do_nodes $mdts $LCTL \
1321                 set_param mdt.*.enable_remote_rename=1" EXIT
1322
1323         mv $DIR/$tdir.0/$tfile.1 $DIR/$tdir.1 || error "mv $tfile.1 failed"
1324
1325         index=$($LFS getstripe -m $DIR/$tdir.1/$tfile.1)
1326         [ $index -eq 1 ] || error "$tfile.1 is on MDT$index"
1327 }
1328 run_test 24z "cross-MDT rename is done as cp"
1329
1330 test_24A() { # LU-3182
1331         local NFILES=5000
1332
1333         rm -rf $DIR/$tdir
1334         test_mkdir $DIR/$tdir
1335         trap simple_cleanup_common EXIT
1336         createmany -m $DIR/$tdir/$tfile $NFILES
1337         local t=$(ls $DIR/$tdir | wc -l)
1338         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1339         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1340         if [ $t -ne $NFILES ] || [ $u -ne $NFILES ] ||
1341            [ $v -ne $((NFILES + 2)) ] ; then
1342                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1343         fi
1344
1345         simple_cleanup_common || error "Can not delete directories"
1346 }
1347 run_test 24A "readdir() returns correct number of entries."
1348
1349 test_24B() { # LU-4805
1350         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
1351
1352         local count
1353
1354         test_mkdir $DIR/$tdir
1355         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1356                 error "create striped dir failed"
1357
1358         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1359         [ $count -eq 2 ] || error "Expected 2, got $count"
1360
1361         touch $DIR/$tdir/striped_dir/a
1362
1363         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1364         [ $count -eq 3 ] || error "Expected 3, got $count"
1365
1366         touch $DIR/$tdir/striped_dir/.f
1367
1368         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1369         [ $count -eq 4 ] || error "Expected 4, got $count"
1370
1371         rm -rf $DIR/$tdir || error "Can not delete directories"
1372 }
1373 run_test 24B "readdir for striped dir return correct number of entries"
1374
1375 test_24C() {
1376         [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
1377
1378         mkdir $DIR/$tdir
1379         mkdir $DIR/$tdir/d0
1380         mkdir $DIR/$tdir/d1
1381
1382         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1383                 error "create striped dir failed"
1384
1385         cd $DIR/$tdir/d0/striped_dir
1386
1387         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1388         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1389         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1390
1391         [ "$d0_ino" = "$parent_ino" ] ||
1392                 error ".. wrong, expect $d0_ino, get $parent_ino"
1393
1394         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1395                 error "mv striped dir failed"
1396
1397         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1398
1399         [ "$d1_ino" = "$parent_ino" ] ||
1400                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1401 }
1402 run_test 24C "check .. in striped dir"
1403
1404 test_24E() {
1405         [[ $MDSCOUNT -lt 4 ]] && skip_env "needs >= 4 MDTs"
1406         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1407
1408         mkdir -p $DIR/$tdir
1409         mkdir $DIR/$tdir/src_dir
1410         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1411                 error "create remote source failed"
1412
1413         touch $DIR/$tdir/src_dir/src_child/a
1414
1415         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1416                 error "create remote target dir failed"
1417
1418         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1419                 error "create remote target child failed"
1420
1421         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1422                 error "rename dir cross MDT failed!"
1423
1424         find $DIR/$tdir
1425
1426         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1427                 error "src_child still exists after rename"
1428
1429         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1430                 error "missing file(a) after rename"
1431
1432         rm -rf $DIR/$tdir || error "Can not delete directories"
1433 }
1434 run_test 24E "cross MDT rename/link"
1435
1436 test_24F () {
1437         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1438
1439         local repeats=1000
1440         [ "$SLOW" = "no" ] && repeats=100
1441
1442         mkdir -p $DIR/$tdir
1443
1444         echo "$repeats repeats"
1445         for ((i = 0; i < repeats; i++)); do
1446                 $LFS mkdir -i0 -c2 $DIR/$tdir/test || error "mkdir fails"
1447                 touch $DIR/$tdir/test/a || error "touch fails"
1448                 mkdir $DIR/$tdir/test/b || error "mkdir fails"
1449                 rm -rf $DIR/$tdir/test || error "rmdir fails"
1450         done
1451
1452         true
1453 }
1454 run_test 24F "hash order vs readdir (LU-11330)"
1455
1456 test_24G () {
1457         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
1458
1459         local ino1
1460         local ino2
1461
1462         $LFS mkdir -i 0 $DIR/$tdir-0 || error "mkdir $tdir-0"
1463         $LFS mkdir -i 1 $DIR/$tdir-1 || error "mkdir $tdir-1"
1464         touch $DIR/$tdir-0/f1 || error "touch f1"
1465         ln -s $DIR/$tdir-0/f1 $DIR/$tdir-0/s1 || error "ln s1"
1466         ino1=$(stat -c%i $DIR/$tdir-0/s1)
1467         mv $DIR/$tdir-0/s1 $DIR/$tdir-1 || error "mv s1"
1468         ino2=$(stat -c%i $DIR/$tdir-1/s1)
1469         [ $ino1 -ne $ino2 ] || error "s1 should be migrated"
1470 }
1471 run_test 24G "migrate symlink in rename"
1472
1473 test_25a() {
1474         echo '== symlink sanity ============================================='
1475
1476         test_mkdir $DIR/d25
1477         ln -s d25 $DIR/s25
1478         touch $DIR/s25/foo ||
1479                 error "File creation in symlinked directory failed"
1480 }
1481 run_test 25a "create file in symlinked directory ==============="
1482
1483 test_25b() {
1484         [ ! -d $DIR/d25 ] && test_25a
1485         $CHECKSTAT -t file $DIR/s25/foo || error "$DIR/s25/foo not file type"
1486 }
1487 run_test 25b "lookup file in symlinked directory ==============="
1488
1489 test_26a() {
1490         test_mkdir $DIR/d26
1491         test_mkdir $DIR/d26/d26-2
1492         ln -s d26/d26-2 $DIR/s26
1493         touch $DIR/s26/foo || error "File creation failed"
1494 }
1495 run_test 26a "multiple component symlink ======================="
1496
1497 test_26b() {
1498         test_mkdir -p $DIR/$tdir/d26-2
1499         ln -s $tdir/d26-2/foo $DIR/s26-2
1500         touch $DIR/s26-2 || error "File creation failed"
1501 }
1502 run_test 26b "multiple component symlink at end of lookup ======"
1503
1504 test_26c() {
1505         test_mkdir $DIR/d26.2
1506         touch $DIR/d26.2/foo
1507         ln -s d26.2 $DIR/s26.2-1
1508         ln -s s26.2-1 $DIR/s26.2-2
1509         ln -s s26.2-2 $DIR/s26.2-3
1510         chmod 0666 $DIR/s26.2-3/foo
1511 }
1512 run_test 26c "chain of symlinks"
1513
1514 # recursive symlinks (bug 439)
1515 test_26d() {
1516         ln -s d26-3/foo $DIR/d26-3
1517 }
1518 run_test 26d "create multiple component recursive symlink"
1519
1520 test_26e() {
1521         [ ! -h $DIR/d26-3 ] && test_26d
1522         rm $DIR/d26-3
1523 }
1524 run_test 26e "unlink multiple component recursive symlink"
1525
1526 # recursive symlinks (bug 7022)
1527 test_26f() {
1528         test_mkdir $DIR/$tdir
1529         test_mkdir $DIR/$tdir/$tfile
1530         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1531         test_mkdir -p lndir/bar1
1532         test_mkdir $DIR/$tdir/$tfile/$tfile
1533         cd $tfile                || error "cd $tfile failed"
1534         ln -s .. dotdot          || error "ln dotdot failed"
1535         ln -s dotdot/lndir lndir || error "ln lndir failed"
1536         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1537         output=`ls $tfile/$tfile/lndir/bar1`
1538         [ "$output" = bar1 ] && error "unexpected output"
1539         rm -r $tfile             || error "rm $tfile failed"
1540         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1541 }
1542 run_test 26f "rm -r of a directory which has recursive symlink"
1543
1544 test_27a() {
1545         test_mkdir $DIR/$tdir
1546         $LFS getstripe $DIR/$tdir
1547         $LFS setstripe -c 1 $DIR/$tdir/$tfile || error "setstripe failed"
1548         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1549         cp /etc/hosts $DIR/$tdir/$tfile || error "Can't copy to one stripe file"
1550 }
1551 run_test 27a "one stripe file"
1552
1553 test_27b() {
1554         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1555
1556         test_mkdir $DIR/$tdir
1557         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1558         $LFS getstripe -c $DIR/$tdir/$tfile
1559         [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
1560                 error "two-stripe file doesn't have two stripes"
1561
1562         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1563 }
1564 run_test 27b "create and write to two stripe file"
1565
1566 # 27c family tests specific striping, setstripe -o
1567 test_27ca() {
1568         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test"
1569         test_mkdir -p $DIR/$tdir
1570         local osts="1"
1571
1572         $LFS setstripe -o $osts $DIR/$tdir/$tfile  || error "setstripe failed"
1573         $LFS getstripe -i $DIR/$tdir/$tfile
1574         [ $($LFS getstripe -i $DIR/$tdir/$tfile ) -eq $osts ] ||
1575                 error "stripe not on specified OST"
1576
1577         dd if=/dev/zero of=$DIR/$tdir/$tfile  bs=1M count=4 || error "dd failed"
1578 }
1579 run_test 27ca "one stripe on specified OST"
1580
1581 test_27cb() {
1582         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test"
1583         test_mkdir -p $DIR/$tdir
1584         local osts="1,0"
1585         $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
1586         local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
1587         echo "$getstripe"
1588
1589         # Strip getstripe output to a space separated list of OSTs
1590         local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
1591                 awk '{print $1}' | tr '\n' ' ' | sed -e 's/[[:space:]]*$//')
1592         [ "$getstripe_osts" = "${osts//,/ }" ] ||
1593                 error "stripes not on specified OSTs"
1594
1595         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
1596 }
1597 run_test 27cb "two stripes on specified OSTs"
1598
1599 test_27cc() {
1600         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test"
1601         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
1602                 skip "server does not support overstriping"
1603
1604         test_mkdir -p $DIR/$tdir
1605         local osts="0,0"
1606         $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
1607         local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
1608         echo "$getstripe"
1609
1610         # Strip getstripe output to a space separated list of OSTs
1611         local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
1612                 awk '{print $1}' | tr '\n' ' ' | sed -e 's/[[:space:]]*$//')
1613         [ "$getstripe_osts" = "${osts//,/ }" ] ||
1614                 error "stripes not on specified OSTs"
1615
1616         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
1617 }
1618 run_test 27cc "two stripes on the same OST"
1619
1620 test_27cd() {
1621         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test"
1622         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
1623                 skip "server does not support overstriping"
1624         test_mkdir -p $DIR/$tdir
1625         local osts="0,1,1,0"
1626         $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
1627         local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
1628         echo "$getstripe"
1629
1630         # Strip getstripe output to a space separated list of OSTs
1631         local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
1632                 awk '{print $1}' | tr '\n' ' ' | sed -e 's/[[:space:]]*$//')
1633         [ "$getstripe_osts" = "${osts//,/ }" ] ||
1634                 error "stripes not on specified OSTs"
1635
1636         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
1637 }
1638 run_test 27cd "four stripes on two OSTs"
1639
1640 test_27ce() {
1641         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
1642                 skip_env "too many osts, skipping"
1643         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
1644                 skip "server does not support overstriping"
1645         # We do one more stripe than we have OSTs
1646         [ $OSTCOUNT -lt 159 ] || large_xattr_enabled ||
1647                 skip_env "ea_inode feature disabled"
1648
1649         test_mkdir -p $DIR/$tdir
1650         local osts=""
1651         for i in $(seq 0 $OSTCOUNT);
1652         do
1653                 osts=$osts"0"
1654                 if [ $i -ne $OSTCOUNT ]; then
1655                         osts=$osts","
1656                 fi
1657         done
1658         $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
1659         local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
1660         echo "$getstripe"
1661
1662         # Strip getstripe output to a space separated list of OSTs
1663         local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
1664                 awk '{print $1}' | tr '\n' ' ' | sed -e 's/[[:space:]]*$//')
1665         [ "$getstripe_osts" = "${osts//,/ }" ] ||
1666                 error "stripes not on specified OSTs"
1667
1668         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
1669 }
1670 run_test 27ce "more stripes than OSTs with -o"
1671
1672 test_27cf() {
1673         local osp_proc="osp.$FSNAME-OST0000-osc-MDT000*.active"
1674         local pid=0
1675
1676         test_mkdir -p $DIR/$tdir || error "failed to mkdir $DIR/$tdir"
1677         do_facet $SINGLEMDS "$LCTL set_param -n $osp_proc=0"
1678         stack_trap "do_facet $SINGLEMDS $LCTL set_param -n $osp_proc=1" EXIT
1679         wait_update_facet $SINGLEMDS "$LCTL get_param -n $osp_proc | grep 1" ||
1680                 error "failed to set $osp_proc=0"
1681
1682         $LFS setstripe -o 0 $DIR/$tdir/$tfile &
1683         pid=$!
1684         sleep 1
1685         do_facet $SINGLEMDS "$LCTL set_param -n $osp_proc=1"
1686         wait_update_facet $SINGLEMDS "$LCTL get_param -n $osp_proc | grep 0" ||
1687                 error "failed to set $osp_proc=1"
1688         wait $pid
1689         [[ $pid -ne 0 ]] ||
1690                 error "should return error due to $osp_proc=0"
1691 }
1692 run_test 27cf "'setstripe -o' on inactive OSTs should return error"
1693
1694 test_27d() {
1695         test_mkdir $DIR/$tdir
1696         $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile ||
1697                 error "setstripe failed"
1698         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1699         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1700 }
1701 run_test 27d "create file with default settings"
1702
1703 test_27e() {
1704         # LU-5839 adds check for existed layout before setting it
1705         [[ $MDS1_VERSION -lt $(version_code 2.7.56) ]] &&
1706                 skip "Need MDS version at least 2.7.56"
1707
1708         test_mkdir $DIR/$tdir
1709         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1710         $LFS setstripe -c 2 $DIR/$tdir/$tfile && error "setstripe worked twice"
1711         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1712 }
1713 run_test 27e "setstripe existing file (should return error)"
1714
1715 test_27f() {
1716         test_mkdir $DIR/$tdir
1717         $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1718                 error "$LFS setstripe $DIR/$tdir/$tfile failed"
1719         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1720                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1721         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1722         $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1723 }
1724 run_test 27f "setstripe with bad stripe size (should return error)"
1725
1726 test_27g() {
1727         test_mkdir $DIR/$tdir
1728         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1729         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "no stripe info" ||
1730                 error "$DIR/$tdir/$tfile has object"
1731 }
1732 run_test 27g "$LFS getstripe with no objects"
1733
1734 test_27ga() {
1735         test_mkdir $DIR/$tdir
1736         touch $DIR/$tdir/$tfile || error "touch failed"
1737         ln -s bogus $DIR/$tdir/$tfile.2 || error "ln failed"
1738         $LFS getstripe -m $DIR/$tdir/$tfile $DIR/$tdir/$tfile.2
1739         local rc=$?
1740         (( rc == 2 )) || error "getstripe did not return ENOENT"
1741 }
1742 run_test 27ga "$LFS getstripe with missing file (should return error)"
1743
1744 test_27i() {
1745         test_mkdir $DIR/$tdir
1746         touch $DIR/$tdir/$tfile || error "touch failed"
1747         [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1748                 error "missing objects"
1749 }
1750 run_test 27i "$LFS getstripe with some objects"
1751
1752 test_27j() {
1753         test_mkdir $DIR/$tdir
1754         $LFS setstripe -i $OSTCOUNT $DIR/$tdir/$tfile &&
1755                 error "setstripe failed" || true
1756 }
1757 run_test 27j "setstripe with bad stripe offset (should return error)"
1758
1759 test_27k() { # bug 2844
1760         test_mkdir $DIR/$tdir
1761         local file=$DIR/$tdir/$tfile
1762         local ll_max_blksize=$((4 * 1024 * 1024))
1763         $LFS setstripe -S 67108864 $file || error "setstripe failed"
1764         local blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1765         [ $blksize -le $ll_max_blksize ] || error "1:$blksize > $ll_max_blksize"
1766         dd if=/dev/zero of=$file bs=4k count=1
1767         blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1768         [ $blksize -le $ll_max_blksize ] || error "2:$blksize > $ll_max_blksize"
1769 }
1770 run_test 27k "limit i_blksize for broken user apps"
1771
1772 test_27l() {
1773         mcreate $DIR/$tfile || error "creating file"
1774         $RUNAS $LFS setstripe -c 1 $DIR/$tfile &&
1775                 error "setstripe should have failed" || true
1776 }
1777 run_test 27l "check setstripe permissions (should return error)"
1778
1779 test_27m() {
1780         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1781
1782         [ -n "$RCLIENTS" -o -n "$MOUNT_2" ] &&
1783                 skip_env "multiple clients -- skipping"
1784
1785         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1786                    head -n1)
1787         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1788                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1789         fi
1790         trap simple_cleanup_common EXIT
1791         test_mkdir $DIR/$tdir
1792         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.1
1793         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
1794                 error "dd should fill OST0"
1795         i=2
1796         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.$i; do
1797                 i=$((i + 1))
1798                 [ $i -gt 256 ] && break
1799         done
1800         i=$((i + 1))
1801         touch $DIR/$tdir/$tfile.$i
1802         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1803             awk '{print $1}'| grep -w "0") ] &&
1804                 error "OST0 was full but new created file still use it"
1805         i=$((i + 1))
1806         touch $DIR/$tdir/$tfile.$i
1807         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1808             awk '{print $1}'| grep -w "0") ] &&
1809                 error "OST0 was full but new created file still use it"
1810         simple_cleanup_common
1811 }
1812 run_test 27m "create file while OST0 was full"
1813
1814 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1815 # if the OST isn't full anymore.
1816 reset_enospc() {
1817         local ostidx=${1:-""}
1818         local delay
1819         local ready
1820         local get_prealloc
1821
1822         local list=$(comma_list $(osts_nodes))
1823         [ "$ostidx" ] && list=$(facet_host ost$((ostidx + 1)))
1824
1825         do_nodes $list lctl set_param fail_loc=0
1826         wait_delete_completed   # initiate all OST_DESTROYs from MDS to OST
1827         delay=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1828                 awk '{print $1 * 2;exit;}')
1829         get_prealloc="$LCTL get_param -n osc.*MDT*.prealloc_status |
1830                         grep -v \"^0$\""
1831         wait_update_facet $SINGLEMDS "$get_prealloc" "" $delay
1832 }
1833
1834 __exhaust_precreations() {
1835         local OSTIDX=$1
1836         local FAILLOC=$2
1837         local FAILIDX=${3:-$OSTIDX}
1838         local ofacet=ost$((OSTIDX + 1))
1839
1840         mkdir_on_mdt0 $DIR/$tdir
1841         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
1842         local mfacet=mds$((mdtidx + 1))
1843         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1844
1845         local OST=$(ostname_from_index $OSTIDX)
1846
1847         # on the mdt's osc
1848         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1849         local last_id=$(do_facet $mfacet lctl get_param -n \
1850                         osp.$mdtosc_proc1.prealloc_last_id)
1851         local next_id=$(do_facet $mfacet lctl get_param -n \
1852                         osp.$mdtosc_proc1.prealloc_next_id)
1853
1854         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1855         do_facet $mfacet lctl get_param osp.$mdtosc_proc2.prealloc*
1856
1857         test_mkdir -p $DIR/$tdir/${OST}
1858         $LFS setstripe -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1859 #define OBD_FAIL_OST_ENOSPC              0x215
1860         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1861         echo "Creating to objid $last_id on ost $OST..."
1862         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1863         do_facet $mfacet lctl get_param osp.$mdtosc_proc2.prealloc*
1864         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1865 }
1866
1867 exhaust_precreations() {
1868         __exhaust_precreations $1 $2 $3
1869         sleep_maxage
1870 }
1871
1872 exhaust_all_precreations() {
1873         local i
1874         for (( i=0; i < OSTCOUNT; i++ )) ; do
1875                 __exhaust_precreations $i $1 -1
1876         done
1877         sleep_maxage
1878 }
1879
1880 test_27n() {
1881         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1882         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1883         remote_mds_nodsh && skip "remote MDS with nodsh"
1884         remote_ost_nodsh && skip "remote OST with nodsh"
1885
1886         reset_enospc
1887         rm -f $DIR/$tdir/$tfile
1888         exhaust_precreations 0 0x80000215
1889         $LFS setstripe -c -1 $DIR/$tdir || error "setstripe failed"
1890         touch $DIR/$tdir/$tfile || error "touch failed"
1891         $LFS getstripe $DIR/$tdir/$tfile
1892         reset_enospc
1893 }
1894 run_test 27n "create file with some full OSTs"
1895
1896 test_27o() {
1897         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1898         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1899         remote_mds_nodsh && skip "remote MDS with nodsh"
1900         remote_ost_nodsh && skip "remote OST with nodsh"
1901
1902         reset_enospc
1903         rm -f $DIR/$tdir/$tfile
1904         exhaust_all_precreations 0x215
1905
1906         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1907
1908         reset_enospc
1909         rm -rf $DIR/$tdir/*
1910 }
1911 run_test 27o "create file with all full OSTs (should error)"
1912
1913 function create_and_checktime() {
1914         local fname=$1
1915         local loops=$2
1916         local i
1917
1918         for ((i=0; i < $loops; i++)); do
1919                 local start=$SECONDS
1920                 multiop $fname-$i Oc
1921                 ((SECONDS-start < TIMEOUT)) ||
1922                         error "creation took " $((SECONDS-$start)) && return 1
1923         done
1924 }
1925
1926 test_27oo() {
1927         local mdts=$(comma_list $(mdts_nodes))
1928
1929         [ $MDS1_VERSION -lt $(version_code 2.13.57) ] &&
1930                 skip "Need MDS version at least 2.13.57"
1931
1932         local f0=$DIR/${tfile}-0
1933         local f1=$DIR/${tfile}-1
1934
1935         wait_delete_completed
1936
1937         # refill precreated objects
1938         $LFS setstripe -i0 -c1 $f0
1939
1940         saved=$(do_facet mds1 $LCTL get_param -n lov.*0000*.qos_threshold_rr)
1941         # force QoS allocation policy
1942         do_nodes $mdts $LCTL set_param lov.*.qos_threshold_rr=0%
1943         stack_trap "do_nodes $mdts $LCTL set_param \
1944                 lov.*.qos_threshold_rr=$saved" EXIT
1945         sleep_maxage
1946
1947         # one OST is unavailable, but still have few objects preallocated
1948         stop ost1
1949         stack_trap "start ost1 $(ostdevname 1) $OST_MOUNT_OPTS; \
1950                 rm -rf $f1 $DIR/$tdir*" EXIT
1951
1952         for ((i=0; i < 7; i++)); do
1953                 mkdir $DIR/$tdir$i || error "can't create dir"
1954                 $LFS setstripe -c$((OSTCOUNT-1)) $DIR/$tdir$i ||
1955                         error "can't set striping"
1956         done
1957         for ((i=0; i < 7; i++)); do
1958                 create_and_checktime $DIR/$tdir$i/$tfile 100 &
1959         done
1960         wait
1961 }
1962 run_test 27oo "don't let few threads to reserve too many objects"
1963
1964 test_27p() {
1965         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1966         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1967         remote_mds_nodsh && skip "remote MDS with nodsh"
1968         remote_ost_nodsh && skip "remote OST with nodsh"
1969
1970         reset_enospc
1971         rm -f $DIR/$tdir/$tfile
1972         test_mkdir $DIR/$tdir
1973
1974         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1975         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1976         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1977
1978         exhaust_precreations 0 0x80000215
1979         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1980         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1981         $LFS getstripe $DIR/$tdir/$tfile
1982
1983         reset_enospc
1984 }
1985 run_test 27p "append to a truncated file with some full OSTs"
1986
1987 test_27q() {
1988         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1989         [ $PARALLEL == "yes" ] && skip "skip parallel run"
1990         remote_mds_nodsh && skip "remote MDS with nodsh"
1991         remote_ost_nodsh && skip "remote OST with nodsh"
1992
1993         reset_enospc
1994         rm -f $DIR/$tdir/$tfile
1995
1996         mkdir_on_mdt0 $DIR/$tdir
1997         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1998         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1999                 error "truncate $DIR/$tdir/$tfile failed"
2000         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
2001
2002         exhaust_all_precreations 0x215
2003
2004         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
2005         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
2006
2007         reset_enospc
2008 }
2009 run_test 27q "append to truncated file with all OSTs full (should error)"
2010
2011 test_27r() {
2012         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2013         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2014         remote_mds_nodsh && skip "remote MDS with nodsh"
2015         remote_ost_nodsh && skip "remote OST with nodsh"
2016
2017         reset_enospc
2018         rm -f $DIR/$tdir/$tfile
2019         exhaust_precreations 0 0x80000215
2020
2021         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
2022
2023         reset_enospc
2024 }
2025 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
2026
2027 test_27s() { # bug 10725
2028         test_mkdir $DIR/$tdir
2029         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
2030         local stripe_count=0
2031         [ $OSTCOUNT -eq 1 ] || stripe_count=2
2032         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
2033                 error "stripe width >= 2^32 succeeded" || true
2034
2035 }
2036 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
2037
2038 test_27t() { # bug 10864
2039         WDIR=$(pwd)
2040         WLFS=$(which lfs)
2041         cd $DIR
2042         touch $tfile
2043         $WLFS getstripe $tfile
2044         cd $WDIR
2045 }
2046 run_test 27t "check that utils parse path correctly"
2047
2048 test_27u() { # bug 4900
2049         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2050         remote_mds_nodsh && skip "remote MDS with nodsh"
2051
2052         local index
2053         local list=$(comma_list $(mdts_nodes))
2054
2055 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
2056         do_nodes $list $LCTL set_param fail_loc=0x139
2057         test_mkdir -p $DIR/$tdir
2058         trap simple_cleanup_common EXIT
2059         createmany -o $DIR/$tdir/t- 1000
2060         do_nodes $list $LCTL set_param fail_loc=0
2061
2062         TLOG=$TMP/$tfile.getstripe
2063         $LFS getstripe $DIR/$tdir > $TLOG
2064         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
2065         unlinkmany $DIR/$tdir/t- 1000
2066         trap 0
2067         [[ $OBJS -gt 0 ]] &&
2068                 error "$OBJS objects created on OST-0. See $TLOG" ||
2069                 rm -f $TLOG
2070 }
2071 run_test 27u "skip object creation on OSC w/o objects"
2072
2073 test_27v() { # bug 4900
2074         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2075         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2076         remote_mds_nodsh && skip "remote MDS with nodsh"
2077         remote_ost_nodsh && skip "remote OST with nodsh"
2078
2079         exhaust_all_precreations 0x215
2080         reset_enospc
2081
2082         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
2083
2084         touch $DIR/$tdir/$tfile
2085         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
2086         # all except ost1
2087         for (( i=1; i < OSTCOUNT; i++ )); do
2088                 do_facet ost$i lctl set_param fail_loc=0x705
2089         done
2090         local START=`date +%s`
2091         createmany -o $DIR/$tdir/$tfile 32
2092
2093         local FINISH=`date +%s`
2094         local TIMEOUT=`lctl get_param -n timeout`
2095         local PROCESS=$((FINISH - START))
2096         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
2097                error "$FINISH - $START >= $TIMEOUT / 2"
2098         sleep $((TIMEOUT / 2 - PROCESS))
2099         reset_enospc
2100 }
2101 run_test 27v "skip object creation on slow OST"
2102
2103 test_27w() { # bug 10997
2104         test_mkdir $DIR/$tdir
2105         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
2106         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
2107                 error "stripe size $size != 65536" || true
2108         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
2109                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
2110 }
2111 run_test 27w "check $LFS setstripe -S and getstrip -d options"
2112
2113 test_27wa() {
2114         [[ $OSTCOUNT -lt 2 ]] &&
2115                 skip_env "skipping multiple stripe count/offset test"
2116
2117         test_mkdir $DIR/$tdir
2118         for i in $(seq 1 $OSTCOUNT); do
2119                 offset=$((i - 1))
2120                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
2121                         error "setstripe -c $i -i $offset failed"
2122                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
2123                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
2124                 [ $count -ne $i ] && error "stripe count $count != $i" || true
2125                 [ $index -ne $offset ] &&
2126                         error "stripe offset $index != $offset" || true
2127         done
2128 }
2129 run_test 27wa "check $LFS setstripe -c -i options"
2130
2131 test_27x() {
2132         remote_ost_nodsh && skip "remote OST with nodsh"
2133         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2134         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2135
2136         OFFSET=$(($OSTCOUNT - 1))
2137         OSTIDX=0
2138         local OST=$(ostname_from_index $OSTIDX)
2139
2140         test_mkdir $DIR/$tdir
2141         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
2142         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
2143         sleep_maxage
2144         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
2145         for i in $(seq 0 $OFFSET); do
2146                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
2147                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
2148                 error "OST0 was degraded but new created file still use it"
2149         done
2150         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
2151 }
2152 run_test 27x "create files while OST0 is degraded"
2153
2154 test_27y() {
2155         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2156         remote_mds_nodsh && skip "remote MDS with nodsh"
2157         remote_ost_nodsh && skip "remote OST with nodsh"
2158         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2159
2160         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
2161         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
2162                 osp.$mdtosc.prealloc_last_id)
2163         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
2164                 osp.$mdtosc.prealloc_next_id)
2165         local fcount=$((last_id - next_id))
2166         [[ $fcount -eq 0 ]] && skip "not enough space on OST0"
2167         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
2168
2169         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
2170                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
2171         local OST_DEACTIVE_IDX=-1
2172         local OSC
2173         local OSTIDX
2174         local OST
2175
2176         for OSC in $MDS_OSCS; do
2177                 OST=$(osc_to_ost $OSC)
2178                 OSTIDX=$(index_from_ostuuid $OST)
2179                 if [ $OST_DEACTIVE_IDX == -1 ]; then
2180                         OST_DEACTIVE_IDX=$OSTIDX
2181                 fi
2182                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
2183                         echo $OSC "is Deactivated:"
2184                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
2185                 fi
2186         done
2187
2188         OSTIDX=$(index_from_ostuuid $OST)
2189         test_mkdir $DIR/$tdir
2190         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
2191
2192         for OSC in $MDS_OSCS; do
2193                 OST=$(osc_to_ost $OSC)
2194                 OSTIDX=$(index_from_ostuuid $OST)
2195                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
2196                         echo $OST "is degraded:"
2197                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
2198                                                 obdfilter.$OST.degraded=1
2199                 fi
2200         done
2201
2202         sleep_maxage
2203         createmany -o $DIR/$tdir/$tfile $fcount
2204
2205         for OSC in $MDS_OSCS; do
2206                 OST=$(osc_to_ost $OSC)
2207                 OSTIDX=$(index_from_ostuuid $OST)
2208                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
2209                         echo $OST "is recovered from degraded:"
2210                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
2211                                                 obdfilter.$OST.degraded=0
2212                 else
2213                         do_facet $SINGLEMDS lctl --device %$OSC activate
2214                 fi
2215         done
2216
2217         # all osp devices get activated, hence -1 stripe count restored
2218         local stripe_count=0
2219
2220         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
2221         # devices get activated.
2222         sleep_maxage
2223         $LFS setstripe -c -1 $DIR/$tfile
2224         stripe_count=$($LFS getstripe -c $DIR/$tfile)
2225         rm -f $DIR/$tfile
2226         [ $stripe_count -ne $OSTCOUNT ] &&
2227                 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
2228         return 0
2229 }
2230 run_test 27y "create files while OST0 is degraded and the rest inactive"
2231
2232 check_seq_oid()
2233 {
2234         log "check file $1"
2235
2236         lmm_count=$($LFS getstripe -c $1)
2237         lmm_seq=$($LFS getstripe -v $1 | awk '/lmm_seq/ { print $2 }')
2238         lmm_oid=$($LFS getstripe -v $1 | awk '/lmm_object_id/ { print $2 }')
2239
2240         local old_ifs="$IFS"
2241         IFS=$'[:]'
2242         fid=($($LFS path2fid $1))
2243         IFS="$old_ifs"
2244
2245         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
2246         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
2247
2248         # compare lmm_seq and lu_fid->f_seq
2249         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
2250         # compare lmm_object_id and lu_fid->oid
2251         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
2252
2253         # check the trusted.fid attribute of the OST objects of the file
2254         local have_obdidx=false
2255         local stripe_nr=0
2256         $LFS getstripe $1 | while read obdidx oid hex seq; do
2257                 # skip lines up to and including "obdidx"
2258                 [ -z "$obdidx" ] && break
2259                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
2260                 $have_obdidx || continue
2261
2262                 local ost=$((obdidx + 1))
2263                 local dev=$(ostdevname $ost)
2264                 local oid_hex
2265
2266                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
2267
2268                 seq=$(echo $seq | sed -e "s/^0x//g")
2269                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
2270                         oid_hex=$(echo $oid)
2271                 else
2272                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
2273                 fi
2274                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
2275
2276                 local ff=""
2277                 #
2278                 # Don't unmount/remount the OSTs if we don't need to do that.
2279                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
2280                 # update too, until that use mount/ll_decode_filter_fid/mount.
2281                 # Re-enable when debugfs will understand new filter_fid.
2282                 #
2283                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
2284                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
2285                                 $dev 2>/dev/null" | grep "parent=")
2286                 fi
2287                 if [ -z "$ff" ]; then
2288                         stop ost$ost
2289                         mount_fstype ost$ost
2290                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
2291                                 $(facet_mntpt ost$ost)/$obj_file)
2292                         unmount_fstype ost$ost
2293                         start ost$ost $dev $OST_MOUNT_OPTS
2294                         clients_up
2295                 fi
2296
2297                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
2298
2299                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
2300
2301                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
2302                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
2303                 #
2304                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
2305                 #       stripe_size=1048576 component_id=1 component_start=0 \
2306                 #       component_end=33554432
2307                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
2308                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
2309                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
2310                 local ff_pstripe
2311                 if grep -q 'stripe=' <<<$ff; then
2312                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
2313                 else
2314                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
2315                         # into f_ver in this case.  See comment on ff_parent.
2316                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
2317                 fi
2318
2319                 # compare lmm_seq and filter_fid->ff_parent.f_seq
2320                 [ $ff_pseq = $lmm_seq ] ||
2321                         error "FF parent SEQ $ff_pseq != $lmm_seq"
2322                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
2323                 [ $ff_poid = $lmm_oid ] ||
2324                         error "FF parent OID $ff_poid != $lmm_oid"
2325                 (($ff_pstripe == $stripe_nr)) ||
2326                         error "FF stripe $ff_pstripe != $stripe_nr"
2327
2328                 stripe_nr=$((stripe_nr + 1))
2329                 [ $CLIENT_VERSION -lt $(version_code 2.9.55) ] &&
2330                         continue
2331                 if grep -q 'stripe_count=' <<<$ff; then
2332                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
2333                                             -e 's/ .*//' <<<$ff)
2334                         [ $lmm_count = $ff_scnt ] ||
2335                                 error "FF stripe count $lmm_count != $ff_scnt"
2336                 fi
2337         done
2338 }
2339
2340 test_27z() {
2341         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2342         remote_ost_nodsh && skip "remote OST with nodsh"
2343
2344         test_mkdir $DIR/$tdir
2345         $LFS setstripe -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
2346                 { error "setstripe -c -1 failed"; return 1; }
2347         # We need to send a write to every object to get parent FID info set.
2348         # This _should_ also work for setattr, but does not currently.
2349         # touch $DIR/$tdir/$tfile-1 ||
2350         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
2351                 { error "dd $tfile-1 failed"; return 2; }
2352         $LFS setstripe -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
2353                 { error "setstripe -c -1 failed"; return 3; }
2354         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
2355                 { error "dd $tfile-2 failed"; return 4; }
2356
2357         # make sure write RPCs have been sent to OSTs
2358         sync; sleep 5; sync
2359
2360         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
2361         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
2362 }
2363 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
2364
2365 test_27A() { # b=19102
2366         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2367
2368         save_layout_restore_at_exit $MOUNT
2369         $LFS setstripe -c 0 -i -1 -S 0 $MOUNT
2370         wait_update $HOSTNAME "$LFS getstripe -c $MOUNT | sed 's/  *//g'" "1" 20 ||
2371                 error "stripe count $($LFS getstripe -c $MOUNT) != 1"
2372         local default_size=$($LFS getstripe -S $MOUNT)
2373         local default_offset=$($LFS getstripe -i $MOUNT)
2374         local dsize=$(do_facet $SINGLEMDS \
2375                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
2376         [ $default_size -eq $dsize ] ||
2377                 error "stripe size $default_size != $dsize"
2378         [ $default_offset -eq -1 ] ||
2379                 error "stripe offset $default_offset != -1"
2380 }
2381 run_test 27A "check filesystem-wide default LOV EA values"
2382
2383 test_27B() { # LU-2523
2384         test_mkdir $DIR/$tdir
2385         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
2386         touch $DIR/$tdir/f0
2387         # open f1 with O_LOV_DELAY_CREATE
2388         # rename f0 onto f1
2389         # call setstripe ioctl on open file descriptor for f1
2390         # close
2391         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
2392                 $DIR/$tdir/f0
2393
2394         rm -f $DIR/$tdir/f1
2395         # open f1 with O_LOV_DELAY_CREATE
2396         # unlink f1
2397         # call setstripe ioctl on open file descriptor for f1
2398         # close
2399         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2400
2401         # Allow multiop to fail in imitation of NFS's busted semantics.
2402         true
2403 }
2404 run_test 27B "call setstripe on open unlinked file/rename victim"
2405
2406 # 27C family tests full striping and overstriping
2407 test_27Ca() { #LU-2871
2408         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2409
2410         declare -a ost_idx
2411         local index
2412         local found
2413         local i
2414         local j
2415
2416         test_mkdir $DIR/$tdir
2417         cd $DIR/$tdir
2418         for i in $(seq 0 $((OSTCOUNT - 1))); do
2419                 # set stripe across all OSTs starting from OST$i
2420                 $LFS setstripe -i $i -c -1 $tfile$i
2421                 # get striping information
2422                 ost_idx=($($LFS getstripe $tfile$i |
2423                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2424                 echo ${ost_idx[@]}
2425
2426                 # check the layout
2427                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2428                         error "${#ost_idx[@]} != $OSTCOUNT"
2429
2430                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2431                         found=0
2432                         for j in $(echo ${ost_idx[@]}); do
2433                                 if [ $index -eq $j ]; then
2434                                         found=1
2435                                         break
2436                                 fi
2437                         done
2438                         [ $found = 1 ] ||
2439                                 error "Can not find $index in ${ost_idx[@]}"
2440                 done
2441         done
2442 }
2443 run_test 27Ca "check full striping across all OSTs"
2444
2445 test_27Cb() {
2446         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2447                 skip "server does not support overstriping"
2448         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
2449                 skip_env "too many osts, skipping"
2450
2451         test_mkdir -p $DIR/$tdir
2452         local setcount=$(($OSTCOUNT * 2))
2453         [ $setcount -lt 160 ] || large_xattr_enabled ||
2454                 skip_env "ea_inode feature disabled"
2455
2456         $LFS setstripe -C $setcount $DIR/$tdir/$tfile ||
2457                 error "setstripe failed"
2458
2459         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2460         [ $count -eq $setcount ] ||
2461                 error "stripe count $count, should be $setcount"
2462
2463         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" ||
2464                 error "overstriped should be set in pattern"
2465
2466         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2467                 error "dd failed"
2468 }
2469 run_test 27Cb "more stripes than OSTs with -C"
2470
2471 test_27Cc() {
2472         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2473                 skip "server does not support overstriping"
2474         [[ $OSTCOUNT -lt 2 ]] && skip_env "need > 1 OST"
2475
2476         test_mkdir -p $DIR/$tdir
2477         local setcount=$(($OSTCOUNT - 1))
2478
2479         [ $setcount -lt 160 ] || large_xattr_enabled ||
2480                 skip_env "ea_inode feature disabled"
2481
2482         $LFS setstripe -C $setcount $DIR/$tdir/$tfile ||
2483                 error "setstripe failed"
2484
2485         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2486         [ $count -eq $setcount ] ||
2487                 error "stripe count $count, should be $setcount"
2488
2489         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" &&
2490                 error "overstriped should not be set in pattern"
2491
2492         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2493                 error "dd failed"
2494 }
2495 run_test 27Cc "fewer stripes than OSTs does not set overstriping"
2496
2497 test_27Cd() {
2498         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2499                 skip "server does not support overstriping"
2500         [[ $OSTCOUNT -lt 2 ]] && skip_env "need > 1 OST"
2501         large_xattr_enabled || skip_env "ea_inode feature disabled"
2502
2503         test_mkdir -p $DIR/$tdir
2504         local setcount=$LOV_MAX_STRIPE_COUNT
2505
2506         $LFS setstripe -C $setcount $DIR/$tdir/$tfile ||
2507                 error "setstripe failed"
2508
2509         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2510         [ $count -eq $setcount ] ||
2511                 error "stripe count $count, should be $setcount"
2512
2513         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" ||
2514                 error "overstriped should be set in pattern"
2515
2516         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2517                 error "dd failed"
2518
2519         rm -f $DIR/$tdir/$tfile || error "Delete $tfile failed"
2520 }
2521 run_test 27Cd "test maximum stripe count"
2522
2523 test_27Ce() {
2524         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2525                 skip "server does not support overstriping"
2526         test_mkdir -p $DIR/$tdir
2527
2528         pool_add $TESTNAME || error "Pool creation failed"
2529         pool_add_targets $TESTNAME 0 || error "pool_add_targets failed"
2530
2531         local setcount=8
2532
2533         $LFS setstripe  -C $setcount -p "$TESTNAME" $DIR/$tdir/$tfile ||
2534                 error "setstripe failed"
2535
2536         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2537         [ $count -eq $setcount ] ||
2538                 error "stripe count $count, should be $setcount"
2539
2540         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" ||
2541                 error "overstriped should be set in pattern"
2542
2543         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2544                 error "dd failed"
2545
2546         rm -f $DIR/$tdir/$tfile || error "Delete $tfile failed"
2547 }
2548 run_test 27Ce "test pool with overstriping"
2549
2550 test_27Cf() {
2551         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2552                 skip "server does not support overstriping"
2553         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
2554                 skip_env "too many osts, skipping"
2555
2556         test_mkdir -p $DIR/$tdir
2557
2558         local setcount=$(($OSTCOUNT * 2))
2559         [ $setcount -lt 160 ] || large_xattr_enabled ||
2560                 skip_env "ea_inode feature disabled"
2561
2562         $LFS setstripe  -C $setcount $DIR/$tdir/ ||
2563                 error "setstripe failed"
2564
2565         echo 1 > $DIR/$tdir/$tfile
2566
2567         local count=$($LFS getstripe -c $DIR/$tdir/$tfile)
2568         [ $count -eq $setcount ] ||
2569                 error "stripe count $count, should be $setcount"
2570
2571         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "overstriped" ||
2572                 error "overstriped should be set in pattern"
2573
2574         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 conv=notrunc ||
2575                 error "dd failed"
2576
2577         rm -f $DIR/$tdir/$tfile || error "Delete $tfile failed"
2578 }
2579 run_test 27Cf "test default inheritance with overstriping"
2580
2581 test_27D() {
2582         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2583         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
2584         remote_mds_nodsh && skip "remote MDS with nodsh"
2585
2586         local POOL=${POOL:-testpool}
2587         local first_ost=0
2588         local last_ost=$(($OSTCOUNT - 1))
2589         local ost_step=1
2590         local ost_list=$(seq $first_ost $ost_step $last_ost)
2591         local ost_range="$first_ost $last_ost $ost_step"
2592
2593         test_mkdir $DIR/$tdir
2594         pool_add $POOL || error "pool_add failed"
2595         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2596
2597         local skip27D
2598         [ $MDS1_VERSION -lt $(version_code 2.8.55) ] &&
2599                 skip27D+="-s 29"
2600         [ $MDS1_VERSION -lt $(version_code 2.9.55) ] ||
2601                 [ $CLIENT_VERSION -lt $(version_code 2.9.55) ] &&
2602                         skip27D+=" -s 30,31"
2603         [[ ! $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ||
2604           $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
2605                 skip27D+=" -s 32,33"
2606         [[ $MDS_VERSION -lt $(version_code $SEL_VER) ]] &&
2607                 skip27D+=" -s 34"
2608         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2609                 error "llapi_layout_test failed"
2610
2611         destroy_test_pools || error "destroy test pools failed"
2612 }
2613 run_test 27D "validate llapi_layout API"
2614
2615 # Verify that default_easize is increased from its initial value after
2616 # accessing a widely striped file.
2617 test_27E() {
2618         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2619         [ $CLIENT_VERSION -lt $(version_code 2.5.57) ] &&
2620                 skip "client does not have LU-3338 fix"
2621
2622         # 72 bytes is the minimum space required to store striping
2623         # information for a file striped across one OST:
2624         # (sizeof(struct lov_user_md_v3) +
2625         #  sizeof(struct lov_user_ost_data_v1))
2626         local min_easize=72
2627         $LCTL set_param -n llite.*.default_easize $min_easize ||
2628                 error "lctl set_param failed"
2629         local easize=$($LCTL get_param -n llite.*.default_easize)
2630
2631         [ $easize -eq $min_easize ] ||
2632                 error "failed to set default_easize"
2633
2634         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2635                 error "setstripe failed"
2636         # In order to ensure stat() call actually talks to MDS we need to
2637         # do something drastic to this file to shake off all lock, e.g.
2638         # rename it (kills lookup lock forcing cache cleaning)
2639         mv $DIR/$tfile $DIR/${tfile}-1
2640         ls -l $DIR/${tfile}-1
2641         rm $DIR/${tfile}-1
2642
2643         easize=$($LCTL get_param -n llite.*.default_easize)
2644
2645         [ $easize -gt $min_easize ] ||
2646                 error "default_easize not updated"
2647 }
2648 run_test 27E "check that default extended attribute size properly increases"
2649
2650 test_27F() { # LU-5346/LU-7975
2651         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2652         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs"
2653         [[ $MDS1_VERSION -lt $(version_code 2.8.51) ]] &&
2654                 skip "Need MDS version at least 2.8.51"
2655         remote_ost_nodsh && skip "remote OST with nodsh"
2656
2657         test_mkdir $DIR/$tdir
2658         rm -f $DIR/$tdir/f0
2659         $LFS setstripe -c 2 $DIR/$tdir
2660
2661         # stop all OSTs to reproduce situation for LU-7975 ticket
2662         for num in $(seq $OSTCOUNT); do
2663                 stop ost$num
2664         done
2665
2666         # open/create f0 with O_LOV_DELAY_CREATE
2667         # truncate f0 to a non-0 size
2668         # close
2669         multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2670
2671         $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2672         # open/write it again to force delayed layout creation
2673         cat /etc/hosts > $DIR/$tdir/f0 &
2674         catpid=$!
2675
2676         # restart OSTs
2677         for num in $(seq $OSTCOUNT); do
2678                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2679                         error "ost$num failed to start"
2680         done
2681
2682         wait $catpid || error "cat failed"
2683
2684         cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2685         [[ $($LFS getstripe -c $DIR/$tdir/f0) == 2 ]] ||
2686                 error "wrong stripecount"
2687
2688 }
2689 run_test 27F "Client resend delayed layout creation with non-zero size"
2690
2691 test_27G() { #LU-10629
2692         [ $MDS1_VERSION -lt $(version_code 2.11.51) ] &&
2693                 skip "Need MDS version at least 2.11.51"
2694         [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
2695         remote_mds_nodsh && skip "remote MDS with nodsh"
2696         local POOL=${POOL:-testpool}
2697         local ostrange="0 0 1"
2698
2699         test_mkdir $DIR/$tdir
2700         touch $DIR/$tdir/$tfile.nopool
2701         pool_add $POOL || error "pool_add failed"
2702         pool_add_targets $POOL $ostrange || error "pool_add_targets failed"
2703         $LFS setstripe -p $POOL $DIR/$tdir
2704
2705         local pool=$($LFS getstripe -p $DIR/$tdir)
2706
2707         [ "$pool" = "$POOL" ] || error "Striping failed got '$pool' not '$POOL'"
2708         touch $DIR/$tdir/$tfile.default
2709         $LFS setstripe -E 1M --pool $POOL -c 1 -E eof -c 1 $DIR/$tdir/$tfile.pfl
2710         $LFS find $DIR/$tdir -type f --pool $POOL
2711         local found=$($LFS find $DIR/$tdir -type f --pool $POOL | wc -l)
2712         [[ "$found" == "2" ]] ||
2713                 error "found $found != 2 files in '$DIR/$tdir' in '$POOL'"
2714
2715         $LFS setstripe -d $DIR/$tdir
2716
2717         pool=$($LFS getstripe -p -d $DIR/$tdir)
2718
2719         [[ "$pool" != "$POOL" ]] || error "$DIR/$tdir is still '$pool'"
2720 }
2721 run_test 27G "Clear OST pool from stripe"
2722
2723 test_27H() {
2724         [[ $MDS1_VERSION -le $(version_code 2.11.54) ]] &&
2725                 skip "Need MDS version newer than 2.11.54"
2726         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs"
2727         test_mkdir $DIR/$tdir
2728         $LFS setstripe -o 0 -o 2 $DIR/$tdir || error "setstripe failed"
2729         touch $DIR/$tdir/$tfile
2730         $LFS getstripe -c $DIR/$tdir/$tfile
2731         [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
2732                 error "two-stripe file doesn't have two stripes"
2733
2734         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
2735         $LFS getstripe -y $DIR/$tdir/$tfile
2736         (( $($LFS getstripe -y $DIR/$tdir/$tfile |
2737              egrep -c "l_ost_idx: [02]$") == "2" )) ||
2738                 error "expected l_ost_idx: [02]$ not matched"
2739
2740         # make sure ost list has been cleared
2741         local stripesize=$($LFS getstripe -S $DIR/$tdir)
2742         $LFS setstripe -S $((stripesize * 4)) -i 1 \
2743                 -c $((OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
2744         touch $DIR/$tdir/f3
2745         $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
2746 }
2747 run_test 27H "Set specific OSTs stripe"
2748
2749 test_27I() {
2750         [ $PARALLEL == "yes" ] && skip "skip parallel run"
2751         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2752         [[ $MDS1_VERSION -gt $(version_code 2.12.52) ]] ||
2753                 skip "Need MDS version newer than 2.12.52"
2754         local pool=$TESTNAME
2755         local ostrange="1 1 1"
2756
2757         save_layout_restore_at_exit $MOUNT
2758         $LFS setstripe -c 2 -i 0 $MOUNT
2759         pool_add $pool || error "pool_add failed"
2760         pool_add_targets $pool $ostrange ||
2761                 error "pool_add_targets failed"
2762         test_mkdir $DIR/$tdir
2763         $LFS setstripe -p $pool $DIR/$tdir
2764         $MULTIOP $DIR/$tdir/$tfile Oc || error "multiop failed"
2765         $LFS getstripe $DIR/$tdir/$tfile
2766 }
2767 run_test 27I "check that root dir striping does not break parent dir one"
2768
2769 test_27J() {
2770         [[ $MDS1_VERSION -le $(version_code 2.12.51) ]] &&
2771                 skip "Need MDS version newer than 2.12.51"
2772
2773         test_mkdir $DIR/$tdir
2774         local uuid1=$(cat /proc/sys/kernel/random/uuid)
2775         local uuid2=$(cat /proc/sys/kernel/random/uuid)
2776
2777         # create foreign file (raw way)
2778         ! $LFS setstripe --flags 0xda08 $DIR/$tdir/$tfile ||
2779                 error "creating $tfile w/ hex flags w/o --foreign should fail"
2780
2781         ! $LFS setstripe --foreign --flags foo \
2782                 --xattr ${uuid1}@${uuid2} $DIR/$tdir/$tfile ||
2783                         error "creating $tfile with '--flags foo' should fail"
2784
2785         ! $LFS setstripe --foreign --flags 0xffffffff \
2786                 --xattr ${uuid1}@${uuid2} $DIR/$tdir/$tfile ||
2787                         error "creating $tfile w/ 0xffffffff flags should fail"
2788
2789         create_foreign_file -f $DIR/$tdir/$tfile -x "${uuid1}@${uuid2}" \
2790                 -t 1 -F 0xda08 || error "create_foreign_file failed"
2791
2792         # verify foreign file (raw way)
2793         parse_foreign_file -f $DIR/$tdir/$tfile |
2794                 grep "lov_foreign_magic: 0x0BD70BD0" ||
2795                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign magic"
2796         parse_foreign_file -f $DIR/$tdir/$tfile | grep "lov_xattr_size: 89" ||
2797                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign size"
2798         parse_foreign_file -f $DIR/$tdir/$tfile |
2799                 grep "lov_foreign_size: 73" ||
2800                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign size"
2801         parse_foreign_file -f $DIR/$tdir/$tfile |
2802                 grep "lov_foreign_type: 1" ||
2803                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign type"
2804         parse_foreign_file -f $DIR/$tdir/$tfile |
2805                 grep "lov_foreign_flags: 0x0000DA08" ||
2806                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign flags"
2807         local lov=$(parse_foreign_file -f $DIR/$tdir/$tfile |
2808                 grep "lov_foreign_value: 0x" |
2809                 sed -e 's/lov_foreign_value: 0x//')
2810         local lov2=$(echo -n "${uuid1}@${uuid2}" | od -A n -t x1 -w160)
2811         [[ $lov = ${lov2// /} ]] ||
2812                 error "$DIR/$tdir/$tfile: invalid LOV EA foreign value"
2813
2814         # create foreign file (lfs + API)
2815         $LFS setstripe --foreign=none --flags 0xda08 \
2816                 -x "${uuid1}@${uuid2}" $DIR/$tdir/${tfile}2 ||
2817                 error "$DIR/$tdir/${tfile}2: create failed"
2818
2819         $LFS getstripe -v $DIR/$tdir/${tfile}2 |
2820                 grep "lfm_magic:.*0x0BD70BD0" ||
2821                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign magic"
2822         # lfm_length is LOV EA size - sizeof(lfm_magic) - sizeof(lfm_length)
2823         $LFS getstripe -v $DIR/$tdir/${tfile}2 | grep "lfm_length:.*73" ||
2824                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign size"
2825         $LFS getstripe -v $DIR/$tdir/${tfile}2 | grep "lfm_type:.*none" ||
2826                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign type"
2827         $LFS getstripe -v $DIR/$tdir/${tfile}2 |
2828                 grep "lfm_flags:.*0x0000DA08" ||
2829                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign flags"
2830         $LFS getstripe $DIR/$tdir/${tfile}2 |
2831                 grep "lfm_value:.*${uuid1}@${uuid2}" ||
2832                 error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign value"
2833
2834         # modify striping should fail
2835         $LFS setstripe -c 2 $DIR/$tdir/$tfile &&
2836                 error "$DIR/$tdir/$tfile: setstripe should fail"
2837         $LFS setstripe -c 2 $DIR/$tdir/${tfile}2 &&
2838                 error "$DIR/$tdir/${tfile}2: setstripe should fail"
2839
2840         # R/W should fail
2841         cat $DIR/$tdir/$tfile && error "$DIR/$tdir/$tfile: read should fail"
2842         cat $DIR/$tdir/${tfile}2 &&
2843                 error "$DIR/$tdir/${tfile}2: read should fail"
2844         cat /etc/passwd > $DIR/$tdir/$tfile &&
2845                 error "$DIR/$tdir/$tfile: write should fail"
2846         cat /etc/passwd > $DIR/$tdir/${tfile}2 &&
2847                 error "$DIR/$tdir/${tfile}2: write should fail"
2848
2849         # chmod should work
2850         chmod 222 $DIR/$tdir/$tfile ||
2851                 error "$DIR/$tdir/$tfile: chmod failed"
2852         chmod 222 $DIR/$tdir/${tfile}2 ||
2853                 error "$DIR/$tdir/${tfile}2: chmod failed"
2854
2855         # chown should work
2856         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/$tfile ||
2857                 error "$DIR/$tdir/$tfile: chown failed"
2858         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/${tfile}2 ||
2859                 error "$DIR/$tdir/${tfile}2: chown failed"
2860
2861         # rename should work
2862         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}.new ||
2863                 error "$DIR/$tdir/$tfile: rename of foreign file has failed"
2864         mv $DIR/$tdir/${tfile}2 $DIR/$tdir/${tfile}2.new ||
2865                 error "$DIR/$tdir/${tfile}2: rename of foreign file has failed"
2866
2867         #remove foreign file
2868         rm $DIR/$tdir/${tfile}.new ||
2869                 error "$DIR/$tdir/${tfile}.new: remove of foreign file has failed"
2870         rm $DIR/$tdir/${tfile}2.new ||
2871                 error "$DIR/$tdir/${tfile}2.new: remove of foreign file has failed"
2872 }
2873 run_test 27J "basic ops on file with foreign LOV"
2874
2875 test_27K() {
2876         [[ $MDS1_VERSION -le $(version_code 2.12.49) ]] &&
2877                 skip "Need MDS version newer than 2.12.49"
2878
2879         test_mkdir $DIR/$tdir
2880         local uuid1=$(cat /proc/sys/kernel/random/uuid)
2881         local uuid2=$(cat /proc/sys/kernel/random/uuid)
2882
2883         # create foreign dir (raw way)
2884         ! $LFS setdirstripe --flags 0xda08 $DIR/$tdir/$tdir ||
2885                 error "creating $tdir w/ hex flags w/o --foreign should fail"
2886
2887         ! $LFS setdirstripe --foreign --flags foo \
2888                 --xattr ${uuid1}@${uuid2} $DIR/$tdir/$tdir ||
2889                         error "creating $tdir with '--flags foo' should fail"
2890
2891         ! $LFS setdirstripe --foreign --flags 0xffffffff \
2892                 --xattr ${uuid1}@${uuid2} $DIR/$tdir/$tdir ||
2893                         error "creating $tdir w/ 0xffffffff flags should fail"
2894
2895         create_foreign_dir -d $DIR/$tdir/$tdir -x "${uuid1}@${uuid2}" -t 1 ||
2896                 error "create_foreign_dir FAILED"
2897
2898         # verify foreign dir (raw way)
2899         parse_foreign_dir -d $DIR/$tdir/$tdir |
2900                 grep "lmv_foreign_magic:.*0xcd50cd0" ||
2901                 error "$DIR/$tdir/$tfile: invalid LMV EA magic"
2902         parse_foreign_dir -d $DIR/$tdir/$tdir | grep "lmv_xattr_size:.*89$" ||
2903                 error "$DIR/$tdir/$tdir: invalid LMV EA size"
2904         parse_foreign_dir -d $DIR/$tdir/$tdir | grep "lmv_foreign_type: 1$" ||
2905                 error "$DIR/$tdir/$tdir: invalid LMV EA type"
2906         parse_foreign_dir -d $DIR/$tdir/$tdir |
2907                 grep "lmv_foreign_flags: 55813$" ||
2908                 error "$DIR/$tdir/$tdir: invalid LMV EA flags"
2909         local lmv=$(parse_foreign_dir -d $DIR/$tdir/$tdir |
2910                 grep "lmv_foreign_value: 0x" |
2911                 sed 's/lmv_foreign_value: 0x//')
2912         local lmv2=$(echo -n "${uuid1}@${uuid2}" | od -A n -t x1 -w160 |
2913                 sed 's/ //g')
2914         [[ $lmv == $lmv2 ]] || error "$DIR/$tdir/$tdir: invalid LMV EA value"
2915
2916         # create foreign dir (lfs + API)
2917         $LFS mkdir --foreign=none --xattr="${uuid1}@${uuid2}" --flags=0xda05 \
2918                 $DIR/$tdir/${tdir}2 ||
2919                 error "$DIR/$tdir/${tdir}2: create failed"
2920
2921         $LFS getdirstripe -v $DIR/$tdir/${tdir}2 |
2922                 grep "lfm_magic:.*0x0CD50CD0" ||
2923                 error "$DIR/$tdir/${tdir}2: invalid LMV EA magic"
2924         # lfm_length is LMV EA size - sizeof(lfm_magic) - sizeof(lfm_length)
2925         # - sizeof(lfm_type) - sizeof(lfm_flags)
2926         $LFS getdirstripe -v $DIR/$tdir/${tdir}2 | grep "lfm_length:.*73" ||
2927                 error "$DIR/$tdir/${tdir}2: invalid LMV EA size"
2928         $LFS getdirstripe -v $DIR/$tdir/${tdir}2 | grep "lfm_type:.*none" ||
2929                 error "$DIR/$tdir/${tdir}2: invalid LMV EA type"
2930         $LFS getdirstripe -v $DIR/$tdir/${tdir}2 |
2931                 grep "lfm_flags:.*0x0000DA05" ||
2932                 error "$DIR/$tdir/${tdir}2: invalid LMV EA flags"
2933         $LFS getdirstripe $DIR/$tdir/${tdir}2 |
2934                 grep "lfm_value.*${uuid1}@${uuid2}" ||
2935                 error "$DIR/$tdir/${tdir}2: invalid LMV EA value"
2936
2937         # file create in dir should fail
2938         touch $DIR/$tdir/$tdir/$tfile && "$DIR/$tdir: file create should fail"
2939         touch $DIR/$tdir/${tdir}2/$tfile &&
2940                 "$DIR/${tdir}2: file create should fail"
2941
2942         # chmod should work
2943         chmod 777 $DIR/$tdir/$tdir ||
2944                 error "$DIR/$tdir: chmod failed"
2945         chmod 777 $DIR/$tdir/${tdir}2 ||
2946                 error "$DIR/${tdir}2: chmod failed"
2947
2948         # chown should work
2949         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/$tdir ||
2950                 error "$DIR/$tdir: chown failed"
2951         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/${tdir}2 ||
2952                 error "$DIR/${tdir}2: chown failed"
2953
2954         # rename should work
2955         mv $DIR/$tdir/$tdir $DIR/$tdir/${tdir}.new ||
2956                 error "$DIR/$tdir/$tdir: rename of foreign dir has failed"
2957         mv $DIR/$tdir/${tdir}2 $DIR/$tdir/${tdir}2.new ||
2958                 error "$DIR/$tdir/${tdir}2: rename of foreign dir has failed"
2959
2960         #remove foreign dir
2961         rmdir $DIR/$tdir/${tdir}.new ||
2962                 error "$DIR/$tdir/${tdir}.new: remove of foreign dir has failed"
2963         rmdir $DIR/$tdir/${tdir}2.new ||
2964                 error "$DIR/$tdir/${tdir}2.new: remove of foreign dir has failed"
2965 }
2966 run_test 27K "basic ops on dir with foreign LMV"
2967
2968 test_27L() {
2969         remote_mds_nodsh && skip "remote MDS with nodsh"
2970
2971         local POOL=${POOL:-$TESTNAME}
2972
2973         pool_add $POOL || error "pool_add failed"
2974
2975         lfs pool_list $MOUNT | grep -Fx "${FSNAME}.${POOL}" ||
2976                  error "pool_list does not contain ${FSNAME}.${POOL}:" \
2977                        "$(lfs pool_list $MOUNT | grep -F "${POOL}")"
2978 }
2979 run_test 27L "lfs pool_list gives correct pool name"
2980
2981 test_27M() {
2982         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.12.57) ]] &&
2983                 skip "Need MDS version >= than 2.12.57"
2984         remote_mds_nodsh && skip "remote MDS with nodsh"
2985         [[ $OSTCOUNT -lt 2 ]] && skip_env "need > 1 OST"
2986
2987         test_mkdir $DIR/$tdir
2988
2989         # Set default striping on directory
2990         $LFS setstripe -C 4 $DIR/$tdir
2991
2992         echo 1 > $DIR/$tdir/${tfile}.1
2993         local count=$($LFS getstripe -c $DIR/$tdir/${tfile}.1)
2994         local setcount=4
2995         [ $count -eq $setcount ] ||
2996                 error "(1) stripe count $count, should be $setcount"
2997
2998         # Capture existing append_stripe_count setting for restore
2999         local orig_count=$(do_facet mds1 $LCTL get_param -n mdd.$FSNAME-MDT0000.append_stripe_count)
3000         local mdts=$(comma_list $(mdts_nodes))
3001         stack_trap "do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=$orig_count" EXIT
3002
3003         local appendcount=$orig_count
3004         echo 1 >> $DIR/$tdir/${tfile}.2_append
3005         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.2_append)
3006         [ $count -eq $appendcount ] ||
3007                 error "(2)stripe count $count, should be $appendcount for append"
3008
3009         # Disable O_APPEND striping, verify it works
3010         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=0
3011
3012         # Should now get the default striping, which is 4
3013         setcount=4
3014         echo 1 >> $DIR/$tdir/${tfile}.3_append
3015         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.3_append)
3016         [ $count -eq $setcount ] ||
3017                 error "(3) stripe count $count, should be $setcount"
3018
3019         # Try changing the stripe count for append files
3020         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=2
3021
3022         # Append striping is now 2 (directory default is still 4)
3023         appendcount=2
3024         echo 1 >> $DIR/$tdir/${tfile}.4_append
3025         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.4_append)
3026         [ $count -eq $appendcount ] ||
3027                 error "(4) stripe count $count, should be $appendcount for append"
3028
3029         # Test append stripe count of -1
3030         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=-1
3031         appendcount=$OSTCOUNT
3032         echo 1 >> $DIR/$tdir/${tfile}.5
3033         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.5)
3034         [ $count -eq $appendcount ] ||
3035                 error "(5) stripe count $count, should be $appendcount for append"
3036
3037         # Set append striping back to default of 1
3038         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=1
3039
3040         # Try a new default striping, PFL + DOM
3041         $LFS setstripe -L mdt -E 1M -E -1 -c 2 $DIR/$tdir
3042
3043         # Create normal DOM file, DOM returns stripe count == 0
3044         setcount=0
3045         touch $DIR/$tdir/${tfile}.6
3046         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.6)
3047         [ $count -eq $setcount ] ||
3048                 error "(6) stripe count $count, should be $setcount"
3049
3050         # Show
3051         appendcount=1
3052         echo 1 >> $DIR/$tdir/${tfile}.7_append
3053         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.7_append)
3054         [ $count -eq $appendcount ] ||
3055                 error "(7) stripe count $count, should be $appendcount for append"
3056
3057         # Clean up DOM layout
3058         $LFS setstripe -d $DIR/$tdir
3059
3060         # Now test that append striping works when layout is from root
3061         $LFS setstripe -c 2 $MOUNT
3062         # Make a special directory for this
3063         mkdir $DIR/${tdir}/${tdir}.2
3064         stack_trap "$LFS setstripe -d $MOUNT" EXIT
3065
3066         # Verify for normal file
3067         setcount=2
3068         echo 1 > $DIR/${tdir}/${tdir}.2/${tfile}.8
3069         count=$($LFS getstripe -c $DIR/$tdir/${tdir}.2/${tfile}.8)
3070         [ $count -eq $setcount ] ||
3071                 error "(8) stripe count $count, should be $setcount"
3072
3073         appendcount=1
3074         echo 1 >> $DIR/${tdir}/${tdir}.2/${tfile}.9_append
3075         count=$($LFS getstripe -c $DIR/${tdir}/${tdir}.2/${tfile}.9_append)
3076         [ $count -eq $appendcount ] ||
3077                 error "(9) stripe count $count, should be $appendcount for append"
3078
3079         # Now test O_APPEND striping with pools
3080         do_nodes $mdts $LCTL set_param mdd.*.append_pool="$TESTNAME"
3081         stack_trap "do_nodes $mdts $LCTL set_param mdd.*.append_pool='none'" EXIT
3082
3083         # Create the pool
3084         pool_add $TESTNAME || error "pool creation failed"
3085         pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
3086
3087         echo 1 >> $DIR/$tdir/${tfile}.10_append
3088
3089         pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.10_append)
3090         [ "$pool" = "$TESTNAME" ] || error "(10) incorrect pool: $pool"
3091
3092         # Check that count is still correct
3093         appendcount=1
3094         echo 1 >> $DIR/$tdir/${tfile}.11_append
3095         count=$($LFS getstripe -c $DIR/$tdir/${tfile}.11_append)
3096         [ $count -eq $appendcount ] ||
3097                 error "(11) stripe count $count, should be $appendcount for append"
3098
3099         # Disable O_APPEND stripe count, verify pool works separately
3100         do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=0
3101
3102         echo 1 >> $DIR/$tdir/${tfile}.12_append
3103
3104         pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.12_append)
3105         [ "$pool" = "$TESTNAME" ] || error "(12) incorrect pool: $pool"
3106
3107         # Remove pool setting, verify it's not applied
3108         do_nodes $mdts $LCTL set_param mdd.*.append_pool='none'
3109
3110         echo 1 >> $DIR/$tdir/${tfile}.13_append
3111
3112         pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.13_append)
3113         [ "$pool" = "" ] || error "(13) pool found: $pool"
3114 }
3115 run_test 27M "test O_APPEND striping"
3116
3117 test_27N() {
3118         combined_mgs_mds && skip "needs separate MGS/MDT"
3119
3120         pool_add $TESTNAME || error "pool_add failed"
3121         do_facet mgs "$LCTL pool_list $FSNAME" |
3122                 grep -Fx "${FSNAME}.${TESTNAME}" ||
3123                 error "lctl pool_list on MGS failed"
3124 }
3125 run_test 27N "lctl pool_list on separate MGS gives correct pool name"
3126
3127 clean_foreign_symlink() {
3128         trap 0
3129         lctl set_param llite/$FSNAME-*/foreign_symlink_enable=0
3130         for i in $DIR/$tdir/* ; do
3131                 $LFS unlink_foreign $i || true
3132         done
3133 }
3134
3135 test_27O() {
3136         [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.12.51) ]] &&
3137                 skip "Need MDS version newer than 2.12.51"
3138
3139         test_mkdir $DIR/$tdir
3140         local uuid1=$(cat /proc/sys/kernel/random/uuid)
3141         local uuid2=$(cat /proc/sys/kernel/random/uuid)
3142
3143         trap clean_foreign_symlink EXIT
3144
3145         # enable foreign_symlink behaviour
3146         $LCTL set_param llite/$FSNAME-*/foreign_symlink_enable=1
3147
3148         # foreign symlink LOV format is a partial path by default
3149
3150         # create foreign file (lfs + API)
3151         $LFS setstripe --foreign=symlink --flags 0xda05 \
3152                 -x "${uuid1}/${uuid2}" --mode 0600 $DIR/$tdir/${tfile} ||
3153                 error "$DIR/$tdir/${tfile}: create failed"
3154
3155         $LFS getstripe -v $DIR/$tdir/${tfile} |
3156                 grep "lfm_magic:.*0x0BD70BD0" ||
3157                 error "$DIR/$tdir/${tfile}: invalid LOV EA foreign magic"
3158         $LFS getstripe -v $DIR/$tdir/${tfile} | grep "lfm_type:.*symlink" ||
3159                 error "$DIR/$tdir/${tfile}: invalid LOV EA foreign type"
3160         $LFS getstripe -v $DIR/$tdir/${tfile} |
3161                 grep "lfm_flags:.*0x0000DA05" ||
3162                 error "$DIR/$tdir/${tfile}: invalid LOV EA foreign flags"
3163         $LFS getstripe $DIR/$tdir/${tfile} |
3164                 grep "lfm_value:.*${uuid1}/${uuid2}" ||
3165                 error "$DIR/$tdir/${tfile}: invalid LOV EA foreign value"
3166
3167         # modify striping should fail
3168         $LFS setstripe -c 2 $DIR/$tdir/$tfile &&
3169                 error "$DIR/$tdir/$tfile: setstripe should fail"
3170
3171         # R/W should fail ("/{foreign_symlink_prefix}/${uuid1}/" missing)
3172         cat $DIR/$tdir/$tfile && error "$DIR/$tdir/$tfile: read should fail"
3173         cat /etc/passwd > $DIR/$tdir/$tfile &&
3174                 error "$DIR/$tdir/$tfile: write should fail"
3175
3176         # rename should succeed
3177         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}.new ||
3178                 error "$DIR/$tdir/$tfile: rename has failed"
3179
3180         #remove foreign_symlink file should fail
3181         rm $DIR/$tdir/${tfile}.new &&
3182                 error "$DIR/$tdir/${tfile}.new: remove of foreign_symlink file should fail"
3183
3184         #test fake symlink
3185         mkdir /tmp/${uuid1} ||
3186                 error "/tmp/${uuid1}: mkdir has failed"
3187         echo FOOFOO > /tmp/${uuid1}/${uuid2} ||
3188                 error "/tmp/${uuid1}/${uuid2}: echo has failed"
3189         $LCTL set_param llite/$FSNAME-*/foreign_symlink_prefix=/tmp/
3190         $CHECKSTAT -t link -l /tmp/${uuid1}/${uuid2} $DIR/$tdir/${tfile}.new ||
3191                 error "$DIR/$tdir/${tfile}.new: not seen as a symlink"
3192         #read should succeed now
3193         cat $DIR/$tdir/${tfile}.new | grep FOOFOO ||
3194                 error "$DIR/$tdir/${tfile}.new: symlink resolution has failed"
3195         #write should succeed now
3196         cat /etc/passwd > $DIR/$tdir/${tfile}.new ||
3197                 error "$DIR/$tdir/${tfile}.new: write should succeed"
3198         diff /etc/passwd $DIR/$tdir/${tfile}.new ||
3199                 error "$DIR/$tdir/${tfile}.new: diff has failed"
3200         diff /etc/passwd /tmp/${uuid1}/${uuid2} ||
3201                 error "/tmp/${uuid1}/${uuid2}: diff has failed"
3202
3203         #check that getstripe still works
3204         $LFS getstripe $DIR/$tdir/${tfile}.new ||
3205                 error "$DIR/$tdir/${tfile}.new: getstripe should still work with foreign_symlink enabled"
3206
3207         # chmod should still succeed
3208         chmod 644 $DIR/$tdir/${tfile}.new ||
3209                 error "$DIR/$tdir/${tfile}.new: chmod has failed"
3210
3211         # chown should still succeed
3212         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/${tfile}.new ||
3213                 error "$DIR/$tdir/${tfile}.new: chown has failed"
3214
3215         # rename should still succeed
3216         mv $DIR/$tdir/${tfile}.new $DIR/$tdir/${tfile} ||
3217                 error "$DIR/$tdir/${tfile}.new: rename has failed"
3218
3219         #remove foreign_symlink file should still fail
3220         rm $DIR/$tdir/${tfile} &&
3221                 error "$DIR/$tdir/${tfile}: remove of foreign_symlink file should fail"
3222
3223         #use special ioctl() to unlink foreign_symlink file
3224         $LFS unlink_foreign $DIR/$tdir/${tfile} ||
3225                 error "$DIR/$tdir/$tfile: unlink/ioctl failed"
3226
3227 }
3228 run_test 27O "basic ops on foreign file of symlink type"
3229
3230 test_27P() {
3231         [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.12.49) ]] &&
3232                 skip "Need MDS version newer than 2.12.49"
3233
3234         test_mkdir $DIR/$tdir
3235         local uuid1=$(cat /proc/sys/kernel/random/uuid)
3236         local uuid2=$(cat /proc/sys/kernel/random/uuid)
3237
3238         trap clean_foreign_symlink EXIT
3239
3240         # enable foreign_symlink behaviour
3241         $LCTL set_param llite/$FSNAME-*/foreign_symlink_enable=1
3242
3243         # foreign symlink LMV format is a partial path by default
3244
3245         # create foreign dir (lfs + API)
3246         $LFS mkdir --foreign=symlink --xattr="${uuid1}/${uuid2}" \
3247                 --flags=0xda05 --mode 0750 $DIR/$tdir/${tdir} ||
3248                 error "$DIR/$tdir/${tdir}: create failed"
3249
3250         $LFS getdirstripe -v $DIR/$tdir/${tdir} |
3251                 grep "lfm_magic:.*0x0CD50CD0" ||
3252                 error "$DIR/$tdir/${tdir}: invalid LMV EA magic"
3253         $LFS getdirstripe -v $DIR/$tdir/${tdir} | grep "lfm_type:.*symlink" ||
3254                 error "$DIR/$tdir/${tdir}: invalid LMV EA type"
3255         $LFS getdirstripe -v $DIR/$tdir/${tdir} |
3256                 grep "lfm_flags:.*0x0000DA05" ||
3257                 error "$DIR/$tdir/${tdir}: invalid LMV EA flags"
3258         $LFS getdirstripe $DIR/$tdir/${tdir} |
3259                 grep "lfm_value.*${uuid1}/${uuid2}" ||
3260                 error "$DIR/$tdir/${tdir}: invalid LMV EA value"
3261
3262         # file create in dir should fail
3263         # ("/{foreign_symlink_prefix}/${uuid1}/${uuid2}/" missing)
3264         touch $DIR/$tdir/$tdir/$tfile && "$DIR/$tdir: file create should fail"
3265
3266         # rename should succeed
3267         mv $DIR/$tdir/$tdir $DIR/$tdir/${tdir}.new ||
3268                 error "$DIR/$tdir/$tdir: rename of foreign_symlink dir has failed"
3269
3270         #remove foreign_symlink dir should fail
3271         rmdir $DIR/$tdir/${tdir}.new &&
3272                 error "$DIR/$tdir/${tdir}.new: remove of foreign_symlink dir should fail"
3273
3274         #test fake symlink
3275         mkdir -p /tmp/${uuid1}/${uuid2} ||
3276                 error "/tmp/${uuid1}/${uuid2}: mkdir has failed"
3277         echo FOOFOO > /tmp/${uuid1}/${uuid2}/foo ||
3278                 error "/tmp/${uuid1}/${uuid2}/foo: echo has failed"
3279         $LCTL set_param llite/$FSNAME-*/foreign_symlink_prefix=/tmp/
3280         $CHECKSTAT -t link -l /tmp/${uuid1}/${uuid2} $DIR/$tdir/${tdir}.new ||
3281                 error "$DIR/$tdir/${tdir}.new: not seen as a symlink"
3282         cat $DIR/$tdir/${tdir}.new/foo | grep FOOFOO ||
3283                 error "$DIR/$tdir/${tdir}.new: symlink resolution has failed"
3284
3285         #check that getstripe fails now that foreign_symlink enabled
3286         $LFS getdirstripe $DIR/$tdir/${tdir}.new ||
3287                 error "$DIR/$tdir/${tdir}.new: getdirstripe should still work with foreign_symlink enabled"
3288
3289         # file create in dir should work now
3290         cp /etc/passwd $DIR/$tdir/${tdir}.new/$tfile ||
3291                 error "$DIR/$tdir/${tdir}.new/$tfile: file create should fail"
3292         diff /etc/passwd $DIR/$tdir/${tdir}.new/$tfile ||
3293                 error "$DIR/$tdir/${tdir}.new/$tfile: diff has failed"
3294         diff /etc/passwd /tmp/${uuid1}/${uuid2}/$tfile ||
3295                 error "/tmp/${uuid1}/${uuid2}/$tfile: diff has failed"
3296
3297         # chmod should still succeed
3298         chmod 755 $DIR/$tdir/${tdir}.new ||
3299                 error "$DIR/$tdir/${tdir}.new: chmod has failed"
3300
3301         # chown should still succeed
3302         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/${tdir}.new ||
3303                 error "$DIR/$tdir/${tdir}.new: chown has failed"
3304
3305         # rename should still succeed
3306         mv $DIR/$tdir/${tdir}.new $DIR/$tdir/${tdir} ||
3307                 error "$DIR/$tdir/${tdir}.new: rename of foreign_symlink dir has failed"
3308
3309         #remove foreign_symlink dir should still fail
3310         rmdir $DIR/$tdir/${tdir} &&
3311                 error "$DIR/$tdir/${tdir}: remove of foreign_symlink dir should fail"
3312
3313         #use special ioctl() to unlink foreign_symlink file
3314         $LFS unlink_foreign $DIR/$tdir/${tdir} ||
3315                 error "$DIR/$tdir/$tdir: unlink/ioctl failed"
3316
3317         #created file should still exist
3318         [[ -f /tmp/${uuid1}/${uuid2}/$tfile ]] ||
3319                 error "/tmp/${uuid1}/${uuid2}/$tfile has been removed"
3320         diff /etc/passwd /tmp/${uuid1}/${uuid2}/$tfile ||
3321                 error "/tmp/${uuid1}/${uuid2}/$tfile: diff has failed"
3322 }
3323 run_test 27P "basic ops on foreign dir of foreign_symlink type"
3324
3325 test_27Q() {
3326         rm -f $TMP/$tfile $TMP/$tfile.loop $TMP/$tfile.none $TMP/$tfile.broken
3327         stack_trap "rm -f $TMP/$tfile*"
3328
3329         test_mkdir $DIR/$tdir-1
3330         test_mkdir $DIR/$tdir-2
3331
3332         echo 'It is what it is' > $DIR/$tdir-1/$tfile
3333         lov_getstripe_old $DIR/$tdir-1/$tfile || error "$DIR/$tdir-1/$tfile: rc = $?"
3334
3335         ln -s $DIR/$tdir-1/$tfile $DIR/$tdir-2/$tfile
3336         lov_getstripe_old $DIR/$tdir-2/$tfile || error "$DIR/$tdir-2/$tfile: rc = $?"
3337
3338         ln -s $DIR/$tdir-1/$tfile $TMP/$tfile
3339         lov_getstripe_old $TMP/$tfile || error "$TMP/$tfile: rc = $?"
3340