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