2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
11 # bug number for skipped test: LU-9693 LU-6493 LU-9693
12 ALWAYS_EXCEPT="$SANITY_EXCEPT 42a 42b 42c"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15 # skipped tests: LU-8411 LU-9096 LU-9054 LU-10680 ..
16 ALWAYS_EXCEPT=" 407 253 312 160f 160g $ALWAYS_EXCEPT"
18 # Check Grants after these tests
19 GRANT_CHECK_LIST="$GRANT_CHECK_LIST 42a 42b 42c 42d 42e 63a 63b 64a 64b 64c"
21 SRCDIR=$(cd $(dirname $0); echo $PWD)
22 export PATH=$PATH:/sbin
28 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
29 CREATETEST=${CREATETEST:-createtest}
31 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
33 OPENFILE=${OPENFILE:-openfile}
34 OPENUNLINK=${OPENUNLINK:-openunlink}
35 export MULTIOP=${MULTIOP:-multiop}
36 READS=${READS:-"reads"}
37 MUNLINK=${MUNLINK:-munlink}
38 SOCKETSERVER=${SOCKETSERVER:-socketserver}
39 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
40 MEMHOG=${MEMHOG:-memhog}
41 DIRECTIO=${DIRECTIO:-directio}
42 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
44 CHECK_GRANT=${CHECK_GRANT:-"yes"}
45 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
46 export PARALLEL=${PARALLEL:-"no"}
48 export NAME=${NAME:-local}
55 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
56 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
57 . $LUSTRE/tests/test-framework.sh
59 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
65 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
66 # bug number for skipped test: LU-1957
67 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 180"
69 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
72 # Get the SLES distro version
74 # Returns a version string that should only be used in comparing
75 # strings returned by version_code()
78 local version=$(grep VERSION_ID /etc/os-release | cut -d'"' -f2)
80 # All SuSE Linux versions have one decimal. version_code expects two
81 local sles_version=$version.0
82 version_code $sles_version
85 # Check if we are running on Ubuntu or SLES so we can make decisions on
87 if [ -r /etc/SuSE-release ]; then
88 sles_version=$(sles_version_code)
89 [ $sles_version -lt $(version_code 11.4.0) ] &&
90 # bug number for skipped test: LU-4341
91 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 170"
92 [ $sles_version -lt $(version_code 12.0.0) ] &&
93 # bug number for skipped test: LU-3703
94 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 234"
95 elif [ -r /etc/os-release ]; then
96 if grep -qi ubuntu /etc/os-release; then
97 ubuntu_version=$(version_code $(sed -n -e 's/"//g' \
102 if [[ $ubuntu_version -gt $(version_code 16.0.0) ]]; then
103 # bug number for skipped test:
104 # LU-10334 LU-10335 LU-10335 LU-10335
105 ALWAYS_EXCEPT+=" 103a 130a 130b 130c"
106 # LU-10335 LU-10335 LU-10365 LU-10366
107 ALWAYS_EXCEPT+=" 130d 130e 400a 410"
116 pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
117 cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
126 check_swap_layouts_support()
128 $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
129 skip "Does not support layout lock."
132 check_and_setup_lustre
136 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
138 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
139 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
140 rm -rf $DIR/[Rdfs][0-9]*
142 # $RUNAS_ID may get set incorrectly somewhere else
143 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
145 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
149 if [ "${ONLY}" = "MOUNT" ] ; then
150 echo "Lustre is up, please go on"
154 echo "preparing for tests involving mounts"
155 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
157 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
158 echo # add a newline after mke2fs.
162 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
163 lctl set_param debug=-1 2> /dev/null || true
166 $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
168 $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
170 run_test 0a "touch; rm ====================="
173 chmod 0755 $DIR || error "chmod 0755 $DIR failed"
174 $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
176 run_test 0b "chmod 0755 $DIR ============================="
179 $LCTL get_param mdc.*.import | grep "state: FULL" ||
180 error "import not FULL"
181 $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
184 run_test 0c "check import proc"
186 test_0d() { # LU-3397
187 [ $(lustre_version_code mgs) -lt $(version_code 2.10.57) ] &&
188 skip "proc exports not supported before 2.10.57"
190 local mgs_exp="mgs.MGS.exports"
191 local client_uuid=$($LCTL get_param -n mgc.*.uuid)
193 local exp_client_version
196 local temp_imp=$DIR/$tfile.import
197 local temp_exp=$DIR/$tfile.export
199 # save mgc import file to $temp_imp
200 $LCTL get_param mgc.*.import | tee $temp_imp
201 # Check if client uuid is found in MGS export
202 for exp_client_nid in $(do_facet mgs $LCTL get_param -N $mgs_exp.*); do
203 [ $(do_facet mgs $LCTL get_param $exp_client_nid.uuid) == \
207 # save mgs export file to $temp_exp
208 do_facet mgs $LCTL get_param $exp_client_nid.export | tee $temp_exp
210 # Compare the value of field "connect_flags"
211 imp_val=$(grep "connect_flags" $temp_imp)
212 exp_val=$(grep "connect_flags" $temp_exp)
213 [ "$exp_val" == "$imp_val" ] ||
214 error "export flags '$exp_val' != import flags '$imp_val'"
216 # Compare the value of client version
217 exp_client_version=$(awk '/target_version:/ { print $2 }' $temp_exp)
218 exp_val=$(version_code $exp_client_version)
219 imp_val=$(lustre_version_code client)
220 [ "$exp_val" == "$imp_val" ] ||
221 error "export client version '$exp_val' != '$imp_val'"
223 run_test 0d "check export proc ============================="
226 test_mkdir $DIR/$tdir
227 test_mkdir $DIR/$tdir/d2
228 mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
229 $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
232 $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
234 run_test 1 "mkdir; remkdir; rmdir"
237 test_mkdir $DIR/$tdir
238 touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
239 $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
241 $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
243 run_test 2 "mkdir; touch; rmdir; check file"
246 test_mkdir $DIR/$tdir
247 $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
248 touch $DIR/$tdir/$tfile
249 $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
251 $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
253 run_test 3 "mkdir; touch; rmdir; check dir"
255 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
257 test_mkdir -i 1 $DIR/$tdir
259 touch $DIR/$tdir/$tfile ||
260 error "Create file under remote directory failed"
263 error "Expect error removing in-use dir $DIR/$tdir"
265 test -d $DIR/$tdir || error "Remote directory disappeared"
267 rm -rf $DIR/$tdir || error "remove remote dir error"
269 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
272 test_mkdir $DIR/$tdir
273 test_mkdir $DIR/$tdir/d2
274 chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
275 $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
276 $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
278 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2"
281 touch $DIR/$tfile || error "touch $DIR/$tfile failed"
282 chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
283 $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
284 error "$tfile does not have perm 0666 or UID $UID"
285 $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
286 $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
287 error "$tfile should be 0666 and owned by UID $UID"
289 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
292 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
295 chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
296 $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
297 error "$tfile should be owned by UID $RUNAS_ID"
298 $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
299 $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
300 error "$tfile should be owned by UID $RUNAS_ID"
302 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
305 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
308 chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
309 $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
310 error "$tfile should be owned by GID $UID"
311 $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
312 $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
313 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
315 run_test 6e "touch+chgrp $tfile; $RUNAS chgrp $tfile (should return error)"
318 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
320 test_mkdir $DIR/$tdir
321 chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
322 $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
323 chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
324 test_mkdir $DIR/$tdir/d/subdir
325 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
326 error "$tdir/d/subdir should be GID $RUNAS_GID"
327 if [[ $MDSCOUNT -gt 1 ]]; then
328 # check remote dir sgid inherite
329 $LFS mkdir -i 0 $DIR/$tdir.local ||
330 error "mkdir $tdir.local failed"
331 chmod g+s $DIR/$tdir.local ||
332 error "chmod $tdir.local failed"
333 chgrp $RUNAS_GID $DIR/$tdir.local ||
334 error "chgrp $tdir.local failed"
335 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
336 error "mkdir $tdir.remote failed"
337 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
338 error "$tdir.remote should be owned by $UID.$RUNAS_ID"
339 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
340 error "$tdir.remote should be mode 02755"
343 run_test 6g "verify new dir in sgid dir inherits group"
345 test_6h() { # bug 7331
346 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID"
348 touch $DIR/$tfile || error "touch failed"
349 chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
350 $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
351 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
352 $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
353 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
355 run_test 6h "$RUNAS chown RUNAS_ID.0 .../$tfile (should return error)"
358 test_mkdir $DIR/$tdir
359 $MCREATE $DIR/$tdir/$tfile
360 chmod 0666 $DIR/$tdir/$tfile
361 $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
362 error "$tdir/$tfile should be mode 0666"
364 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
367 if [ ! -d $DIR/$tdir ]; then
368 test_mkdir $DIR/$tdir
370 $MCREATE $DIR/$tdir/$tfile
371 echo -n foo > $DIR/$tdir/$tfile
372 [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
373 $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
375 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
378 test_mkdir $DIR/$tdir
379 touch $DIR/$tdir/$tfile
380 chmod 0666 $DIR/$tdir/$tfile
381 $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
382 error "$tfile mode not 0666"
384 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
387 test_mkdir $DIR/$tdir
388 test_mkdir $DIR/$tdir/d2
389 test_mkdir $DIR/$tdir/d2/d3
390 $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
392 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
395 test_mkdir $DIR/$tdir
396 test_mkdir $DIR/$tdir/d2
397 touch $DIR/$tdir/d2/$tfile
398 $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
399 error "$tdir/d2/$tfile not a file"
401 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
404 test_mkdir $DIR/$tdir
405 test_mkdir $DIR/$tdir/d2
406 chmod 0666 $DIR/$tdir/d2
407 chmod 0705 $DIR/$tdir/d2
408 $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
409 error "$tdir/d2 mode not 0705"
411 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
414 test_mkdir $DIR/$tdir
415 touch $DIR/$tdir/$tfile
416 chmod 0666 $DIR/$tdir/$tfile
417 chmod 0654 $DIR/$tdir/$tfile
418 $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
419 error "$tdir/d2 mode not 0654"
421 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
424 test_mkdir $DIR/$tdir
425 dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
427 $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
428 error "$tdir/$tfile size not 0 after truncate"
430 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
433 test_mkdir $DIR/$tdir
434 touch $DIR/$tdir/$tfile
436 $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
438 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
441 test_mkdir $DIR/$tdir
442 touch $DIR/$tdir/$tfile
443 mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
444 $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
445 error "$tdir/${tfile_2} not a file after rename"
446 rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
448 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
451 test_mkdir $DIR/$tdir
452 touch $DIR/$tdir/$tfile
453 rm -rf $DIR/$tdir/$tfile
454 $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
456 run_test 16 "touch .../d16/f; rm -rf .../d16/f"
459 test_mkdir $DIR/$tdir
460 touch $DIR/$tdir/$tfile
461 ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
463 $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
464 error "$tdir/l-exist not a symlink"
465 $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
466 error "$tdir/l-exist not referencing a file"
467 rm -f $DIR/$tdir/l-exist
468 $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
470 run_test 17a "symlinks: create, remove (real)"
473 test_mkdir $DIR/$tdir
474 ln -s no-such-file $DIR/$tdir/l-dangle
476 $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
477 error "$tdir/l-dangle not referencing no-such-file"
478 $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
479 error "$tdir/l-dangle not referencing non-existent file"
480 rm -f $DIR/$tdir/l-dangle
481 $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
483 run_test 17b "symlinks: create, remove (dangling)"
485 test_17c() { # bug 3440 - don't save failed open RPC for replay
486 test_mkdir $DIR/$tdir
487 ln -s foo $DIR/$tdir/$tfile
488 cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
490 run_test 17c "symlinks: open dangling (should return error)"
493 test_mkdir $DIR/$tdir
494 ln -s foo $DIR/$tdir/$tfile
495 touch $DIR/$tdir/$tfile || error "creating to new symlink"
497 run_test 17d "symlinks: create dangling"
500 test_mkdir $DIR/$tdir
501 local foo=$DIR/$tdir/$tfile
502 ln -s $foo $foo || error "create symlink failed"
503 ls -l $foo || error "ls -l failed"
504 ls $foo && error "ls not failed" || true
506 run_test 17e "symlinks: create recursive symlink (should return error)"
509 test_mkdir $DIR/$tdir
510 ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
511 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
512 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
513 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
514 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
515 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
518 run_test 17f "symlinks: long and very long symlink name"
520 # str_repeat(S, N) generate a string that is string S repeated N times
525 while [ $((n -= 1)) -ge 0 ]; do
531 # Long symlinks and LU-2241
533 test_mkdir $DIR/$tdir
534 local TESTS="59 60 61 4094 4095"
536 # Fix for inode size boundary in 2.1.4
537 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
540 # Patch not applied to 2.2 or 2.3 branches
541 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
542 [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
545 # skip long symlink name for rhel6.5.
546 # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
547 grep -q '6.5' /etc/redhat-release &>/dev/null &&
548 TESTS="59 60 61 4062 4063"
551 local SYMNAME=$(str_repeat 'x' $i)
552 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
553 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
556 run_test 17g "symlinks: really long symlink name and inode boundaries"
558 test_17h() { #bug 17378
559 [ $PARALLEL == "yes" ] && skip "skip parallel run"
560 remote_mds_nodsh && skip "remote MDS with nodsh"
564 test_mkdir $DIR/$tdir
565 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
566 $LFS setstripe -c -1 $DIR/$tdir
567 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
568 do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
569 touch $DIR/$tdir/$tfile || true
571 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
573 test_17i() { #bug 20018
574 [ $PARALLEL == "yes" ] && skip "skip parallel run"
575 remote_mds_nodsh && skip "remote MDS with nodsh"
577 local foo=$DIR/$tdir/$tfile
580 test_mkdir -c1 $DIR/$tdir
581 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
582 ln -s $foo $foo || error "create symlink failed"
583 #define OBD_FAIL_MDS_READLINK_EPROTO 0x143
584 do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
585 ls -l $foo && error "error not detected"
588 run_test 17i "don't panic on short symlink (should return error)"
590 test_17k() { #bug 22301
591 [ $PARALLEL == "yes" ] && skip "skip parallel run"
592 [[ -z "$(which rsync 2>/dev/null)" ]] &&
593 skip "no rsync command"
594 rsync --help | grep -q xattr ||
595 skip_env "$(rsync --version | head -n1) does not support xattrs"
596 test_mkdir $DIR/$tdir
597 test_mkdir $DIR/$tdir.new
598 touch $DIR/$tdir/$tfile
599 ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
600 rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
601 error "rsync failed with xattrs enabled"
603 run_test 17k "symlinks: rsync with xattrs enabled"
605 test_17l() { # LU-279
606 [[ -z "$(which getfattr 2>/dev/null)" ]] &&
607 skip "no getfattr command"
609 test_mkdir $DIR/$tdir
610 touch $DIR/$tdir/$tfile
611 ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
612 for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
613 # -h to not follow symlinks. -m '' to list all the xattrs.
614 # grep to remove first line: '# file: $path'.
615 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
617 lgetxattr_size_check $path $xattr ||
618 error "lgetxattr_size_check $path $xattr failed"
622 run_test 17l "Ensure lgetxattr's returned xattr size is consistent"
626 [ $PARALLEL == "yes" ] && skip "skip parallel run"
627 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
628 skip_env "ldiskfs only test"
629 remote_mds_nodsh && skip "remote MDS with nodsh"
630 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
631 [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
632 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks"
634 local short_sym="0123456789"
635 local wdir=$DIR/$tdir
640 # create a long symlink file
641 for ((i = 0; i < 4; ++i)); do
642 long_sym=${long_sym}${long_sym}
645 echo "create 512 short and long symlink files under $wdir"
646 for ((i = 0; i < 256; ++i)); do
647 ln -sf ${long_sym}"a5a5" $wdir/long-$i
648 ln -sf ${short_sym}"a5a5" $wdir/short-$i
654 wait_delete_completed
656 echo "recreate the 512 symlink files with a shorter string"
657 for ((i = 0; i < 512; ++i)); do
658 # rewrite the symlink file with a shorter string
659 ln -sf ${long_sym} $wdir/long-$i || error "long_sym failed"
660 ln -sf ${short_sym} $wdir/short-$i || error "short_sym failed"
663 local mds_index=$(($($LFS getstripe -M $wdir) + 1))
664 local devname=$(mdsdevname $mds_index)
666 echo "stop and checking mds${mds_index}:"
667 # e2fsck should not return error
669 run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
672 start mds${mds_index} $devname $MDS_MOUNT_OPTS ||
673 error "start mds${mds_index} failed"
674 df $MOUNT > /dev/null 2>&1
676 error "e2fsck detected error for short/long symlink: rc=$rc"
679 run_test 17m "run e2fsck against MDT which contains short/long symlink"
681 check_fs_consistency_17n() {
685 # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
686 # so it only check MDT1/MDT2 instead of all of MDTs.
687 for mdt_index in 1 2; do
688 local devname=$(mdsdevname $mdt_index)
689 # e2fsck should not return error
691 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
694 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
695 error "mount mds$mdt_index failed"
696 df $MOUNT > /dev/null 2>&1
702 [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
703 [ $PARALLEL == "yes" ] && skip "skip parallel run"
704 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
705 skip_env "ldiskfs only test"
706 remote_mds_nodsh && skip "remote MDS with nodsh"
707 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
708 [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
709 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks"
713 test_mkdir $DIR/$tdir
714 for ((i=0; i<10; i++)); do
715 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
716 error "create remote dir error $i"
717 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
718 error "create files under remote dir failed $i"
721 check_fs_consistency_17n ||
722 error "e2fsck report error after create files under remote dir"
724 for ((i = 0; i < 10; i++)); do
725 rm -rf $DIR/$tdir/remote_dir_${i} ||
726 error "destroy remote dir error $i"
729 check_fs_consistency_17n ||
730 error "e2fsck report error after unlink files under remote dir"
732 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
733 skip "lustre < 2.4.50 does not support migrate mv"
735 for ((i = 0; i < 10; i++)); do
736 mkdir -p $DIR/$tdir/remote_dir_${i}
737 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
738 error "create files under remote dir failed $i"
739 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
740 error "migrate remote dir error $i"
742 check_fs_consistency_17n || error "e2fsck report error after migration"
744 for ((i = 0; i < 10; i++)); do
745 rm -rf $DIR/$tdir/remote_dir_${i} ||
746 error "destroy remote dir error $i"
749 check_fs_consistency_17n || error "e2fsck report error after unlink"
751 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
754 remote_mds_nodsh && skip "remote MDS with nodsh"
755 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
756 skip "Need MDS version at least 2.3.64"
758 local wdir=$DIR/${tdir}o
764 mdt_index=$($LFS getstripe -M $wdir/$tfile)
765 mdt_index=$((mdt_index + 1))
768 #fail mds will wait the failover finish then set
769 #following fail_loc to avoid interfer the recovery process.
772 #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
773 do_facet mds${mdt_index} lctl set_param fail_loc=0x194
774 ls -l $wdir/$tfile && rc=1
775 do_facet mds${mdt_index} lctl set_param fail_loc=0
776 [[ $rc -eq 0 ]] || error "stat file should fail"
778 run_test 17o "stat file with incompat LMA feature"
781 touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
782 ls $DIR || error "Failed to ls $DIR: $?"
784 run_test 18 "touch .../f ; ls ... =============================="
790 $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
792 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
795 ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
797 run_test 19b "ls -l .../f19 (should return error) =============="
800 [ $RUNAS_ID -eq $UID ] &&
801 skip_env "RUNAS_ID = UID = $UID -- skipping"
803 $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
805 run_test 19c "$RUNAS touch .../f19 (should return error) =="
808 cat $DIR/f19 && error || true
810 run_test 19d "cat .../f19 (should return error) =============="
819 $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
821 run_test 20 "touch .../f ; ls -l ..."
824 test_mkdir $DIR/$tdir
825 [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
826 ln -s dangle $DIR/$tdir/link
827 echo foo >> $DIR/$tdir/link
828 cat $DIR/$tdir/dangle
829 $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
830 $CHECKSTAT -f -t file $DIR/$tdir/link ||
831 error "$tdir/link not linked to a file"
833 run_test 21 "write to dangling link"
836 local wdir=$DIR/$tdir
838 chown $RUNAS_ID:$RUNAS_GID $wdir
839 (cd $wdir || error "cd $wdir failed";
840 $RUNAS tar cf - /etc/hosts /etc/sysconfig/network |
842 ls -lR $wdir/etc || error "ls -lR $wdir/etc failed"
843 $CHECKSTAT -t dir $wdir/etc || error "checkstat -t dir failed"
844 $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $wdir/etc ||
845 error "checkstat -u failed"
847 run_test 22 "unpack tar archive as non-root user"
851 test_mkdir $DIR/$tdir
852 local file=$DIR/$tdir/$tfile
854 openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
855 openfile -f O_CREAT:O_EXCL $file &&
856 error "$file recreate succeeded" || true
858 run_test 23a "O_CREAT|O_EXCL in subdir"
860 test_23b() { # bug 18988
861 test_mkdir $DIR/$tdir
862 local file=$DIR/$tdir/$tfile
865 echo foo > $file || error "write filed"
866 echo bar >> $file || error "append filed"
867 $CHECKSTAT -s 8 $file || error "wrong size"
870 run_test 23b "O_APPEND check"
872 # LU-9409, size with O_APPEND and tiny writes
874 local file=$DIR/$tfile
877 dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800
878 $CHECKSTAT -s 6400 $file || error "wrong size, expected 6400"
882 dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
883 dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
885 $CHECKSTAT -s 12800 $file || error "wrong size, expected 12800"
888 #racing tiny & normal writes
889 dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4096 count=4 &
890 dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=100 &
892 $CHECKSTAT -s 17184 $file || error "wrong size, expected 17184"
895 #racing tiny & normal writes 2, ugly numbers
896 dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4099 count=11 &
897 dd conv=notrunc oflag=append if=/dev/zero of=$file bs=17 count=173 &
899 $CHECKSTAT -s 48030 $file || error "wrong size, expected 48030"
902 run_test 23c "O_APPEND size checks for tiny writes"
906 echo '-- same directory rename'
907 test_mkdir $DIR/$tdir
908 touch $DIR/$tdir/$tfile.1
909 mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
910 $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
912 run_test 24a "rename file to non-existent target"
915 test_mkdir $DIR/$tdir
916 touch $DIR/$tdir/$tfile.{1,2}
917 mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
918 $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
919 $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
921 run_test 24b "rename file to existing target"
924 test_mkdir $DIR/$tdir
925 test_mkdir $DIR/$tdir/d$testnum.1
926 mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
927 $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
928 $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
930 run_test 24c "rename directory to non-existent target"
933 test_mkdir -c1 $DIR/$tdir
934 test_mkdir -c1 $DIR/$tdir/d$testnum.1
935 test_mkdir -c1 $DIR/$tdir/d$testnum.2
936 mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
937 $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
938 $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
940 run_test 24d "rename directory to existing target"
943 echo '-- cross directory renames --'
947 mv $DIR/R5a/f $DIR/R5b/g
948 $CHECKSTAT -a $DIR/R5a/f || error "$DIR/R5a/f exists"
949 $CHECKSTAT -t file $DIR/R5b/g || error "$DIR/R5b/g not file type"
951 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
956 touch $DIR/R6a/f $DIR/R6b/g
957 mv $DIR/R6a/f $DIR/R6b/g
958 $CHECKSTAT -a $DIR/R6a/f || error "$DIR/R6a/f exists"
959 $CHECKSTAT -t file $DIR/R6b/g || error "$DIR/R6b/g not file type"
961 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
966 test_mkdir $DIR/R7a/d
967 mv $DIR/R7a/d $DIR/R7b/e
968 $CHECKSTAT -a $DIR/R7a/d || error "$DIR/R7a/d exists"
969 $CHECKSTAT -t dir $DIR/R7b/e || error "$DIR/R7b/e not dir type"
971 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
974 test_mkdir -c1 $DIR/R8a
975 test_mkdir -c1 $DIR/R8b
976 test_mkdir -c1 $DIR/R8a/d
977 test_mkdir -c1 $DIR/R8b/e
978 mrename $DIR/R8a/d $DIR/R8b/e
979 $CHECKSTAT -a $DIR/R8a/d || error "$DIR/R8a/d exists"
980 $CHECKSTAT -t dir $DIR/R8b/e || error "$DIR/R8b/e not dir type"
982 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
985 echo "-- rename error cases"
989 mrename $DIR/R9/f $DIR/R9/a
990 $CHECKSTAT -t file $DIR/R9/f || error "$DIR/R9/f not file type"
991 $CHECKSTAT -t dir $DIR/R9/a || error "$DIR/R9/a not dir type"
992 $CHECKSTAT -a $DIR/R9/a/f || error "$DIR/R9/a/f exists"
994 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
998 mrename $DIR/R10/f $DIR/R10/g
999 $CHECKSTAT -t dir $DIR/R10 || error "$DIR/R10 not dir type"
1000 $CHECKSTAT -a $DIR/R10/f || error "$DIR/R10/f exists"
1001 $CHECKSTAT -a $DIR/R10/g || error "$DIR/R10/g exists"
1003 run_test 24j "source does not exist ============================"
1006 test_mkdir $DIR/R11a
1007 test_mkdir $DIR/R11a/d
1009 mv $DIR/R11a/f $DIR/R11a/d
1010 $CHECKSTAT -a $DIR/R11a/f || error "$DIR/R11a/f exists"
1011 $CHECKSTAT -t file $DIR/R11a/d/f || error "$DIR/R11a/d/f not file type"
1013 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
1015 # bug 2429 - rename foo foo foo creates invalid file
1018 $MULTIOP $f OcNs || error "rename of ${f} to itself failed"
1020 run_test 24l "Renaming a file to itself ========================"
1024 $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
1025 # on ext3 this does not remove either the source or target files
1026 # though the "expected" operation would be to remove the source
1027 $CHECKSTAT -t file ${f} || error "${f} missing"
1028 $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
1030 run_test 24m "Renaming a file to a hard link to itself ========="
1034 # this stats the old file after it was renamed, so it should fail
1036 $CHECKSTAT ${f} || error "${f} missing"
1038 $CHECKSTAT ${f}.rename || error "${f}.rename missing"
1039 $CHECKSTAT -a ${f} || error "${f} exists"
1041 run_test 24n "Statting the old file after renaming (Posix rename 2)"
1044 test_mkdir $DIR/$tdir
1045 rename_many -s random -v -n 10 $DIR/$tdir
1047 run_test 24o "rename of files during htree split"
1050 test_mkdir $DIR/R12a
1051 test_mkdir $DIR/R12b
1052 DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
1053 mrename $DIR/R12a $DIR/R12b
1054 $CHECKSTAT -a $DIR/R12a || error "$DIR/R12a exists"
1055 $CHECKSTAT -t dir $DIR/R12b || error "$DIR/R12b not dir type"
1056 DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
1057 [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
1059 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
1061 cleanup_multiop_pause() {
1063 kill -USR1 $MULTIPID
1067 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1069 test_mkdir $DIR/R13a
1070 test_mkdir $DIR/R13b
1071 local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
1072 multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
1075 trap cleanup_multiop_pause EXIT
1076 mrename $DIR/R13a $DIR/R13b
1077 $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1078 $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1079 local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1080 [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1081 cleanup_multiop_pause
1082 wait $MULTIPID || error "multiop close failed"
1084 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1086 test_24r() { #bug 3789
1087 test_mkdir $DIR/R14a
1088 test_mkdir $DIR/R14a/b
1089 mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1090 $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1091 $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1093 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1096 test_mkdir $DIR/R15a
1097 test_mkdir $DIR/R15a/b
1098 test_mkdir $DIR/R15a/b/c
1099 mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1100 $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1101 $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1103 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1105 test_mkdir $DIR/R16a
1106 test_mkdir $DIR/R16a/b
1107 test_mkdir $DIR/R16a/b/c
1108 mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1109 $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1110 $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1112 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1114 test_24u() { # bug12192
1115 $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error "multiop failed"
1116 $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1118 run_test 24u "create stripe file"
1122 size=$(getconf PAGE_SIZE 2>/dev/null)
1123 echo -n ${size:-4096}
1126 simple_cleanup_common() {
1129 [ -z "$DIR" -o -z "$tdir" ] && return 0
1131 local start=$SECONDS
1134 wait_delete_completed
1135 echo "cleanup time $((SECONDS - start))"
1139 max_pages_per_rpc() {
1140 local mdtname="$(printf "MDT%04x" ${1:-0})"
1141 $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1145 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1147 local nrfiles=${COUNT:-100000}
1148 local fname="$DIR/$tdir/$tfile"
1150 # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1151 [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
1153 test_mkdir "$(dirname $fname)"
1154 # assume MDT0000 has the fewest inodes
1155 local stripes=$($LFS getdirstripe -c $(dirname $fname))
1156 local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1157 [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1159 trap simple_cleanup_common EXIT
1161 createmany -m "$fname" $nrfiles
1163 cancel_lru_locks mdc
1164 lctl set_param mdc.*.stats clear
1166 # was previously test_24D: LU-6101
1167 # readdir() returns correct number of entries after cursor reload
1168 local num_ls=$(ls $DIR/$tdir | wc -l)
1169 local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1170 local num_all=$(ls -a $DIR/$tdir | wc -l)
1171 if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
1172 $num_all -ne $((nrfiles + 2)) ]; then
1173 error "Expected $nrfiles files, got $num_ls " \
1174 "($num_uniq unique $num_all .&..)"
1176 # LU-5 large readdir
1177 # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1178 # N bytes for name (len($nrfiles) rounded to 8 bytes) +
1179 # 8 bytes for luda_type (4 bytes rounded to 8 bytes)
1180 # take into account of overhead in lu_dirpage header and end mark in
1181 # each page, plus one in rpc_num calculation.
1182 local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1183 local page_entries=$((($(page_size) - 24) / dirent_size))
1184 local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1185 local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1186 local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1187 local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1188 echo "readpages: $mds_readpage rpc_max: $rpc_max"
1189 (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1190 error "large readdir doesn't take effect: " \
1191 "$mds_readpage should be about $rpc_max"
1193 simple_cleanup_common
1195 run_test 24v "list large directory (test hash collision, b=17560)"
1197 test_24w() { # bug21506
1199 dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1200 dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1201 dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1202 SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1203 [[ "$SZ1" -eq "$SZ2" ]] ||
1204 error "Error reading at the end of the file $tfile"
1206 run_test 24w "Reading a file larger than 4Gb"
1209 [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1210 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1211 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1212 skip "Need MDS version at least 2.7.56"
1215 local remote_dir=$DIR/$tdir/remote_dir
1217 test_mkdir $DIR/$tdir
1218 $LFS mkdir -i $MDTIDX $remote_dir ||
1219 error "create remote directory failed"
1221 test_mkdir $DIR/$tdir/src_dir
1222 touch $DIR/$tdir/src_file
1223 test_mkdir $remote_dir/tgt_dir
1224 touch $remote_dir/tgt_file
1226 mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1227 error "rename dir cross MDT failed!"
1229 mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1230 error "rename file cross MDT failed!"
1232 touch $DIR/$tdir/ln_file
1233 ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1234 error "ln file cross MDT failed"
1236 rm -rf $DIR/$tdir || error "Can not delete directories"
1238 run_test 24x "cross MDT rename/link"
1241 [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
1242 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1244 local remote_dir=$DIR/$tdir/remote_dir
1247 test_mkdir $DIR/$tdir
1248 $LFS mkdir -i $mdtidx $remote_dir ||
1249 error "create remote directory failed"
1251 test_mkdir $remote_dir/src_dir
1252 touch $remote_dir/src_file
1253 test_mkdir $remote_dir/tgt_dir
1254 touch $remote_dir/tgt_file
1256 mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1257 error "rename subdir in the same remote dir failed!"
1259 mrename $remote_dir/src_file $remote_dir/tgt_file ||
1260 error "rename files in the same remote dir failed!"
1262 ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1263 error "link files in the same remote dir failed!"
1265 rm -rf $DIR/$tdir || error "Can not delete directories"
1267 run_test 24y "rename/link on the same dir should succeed"
1269 test_24A() { # LU-3182
1273 test_mkdir $DIR/$tdir
1274 trap simple_cleanup_common EXIT
1275 createmany -m $DIR/$tdir/$tfile $NFILES
1276 local t=$(ls $DIR/$tdir | wc -l)
1277 local u=$(ls $DIR/$tdir | sort -u | wc -l)
1278 local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1279 if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1280 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1283 simple_cleanup_common || error "Can not delete directories"
1285 run_test 24A "readdir() returns correct number of entries."
1287 test_24B() { # LU-4805
1288 [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
1292 test_mkdir $DIR/$tdir
1293 $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1294 error "create striped dir failed"
1296 count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1297 [ $count -eq 2 ] || error "Expected 2, got $count"
1299 touch $DIR/$tdir/striped_dir/a
1301 count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1302 [ $count -eq 3 ] || error "Expected 3, got $count"
1304 touch $DIR/$tdir/striped_dir/.f
1306 count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1307 [ $count -eq 4 ] || error "Expected 4, got $count"
1309 rm -rf $DIR/$tdir || error "Can not delete directories"
1311 run_test 24B "readdir for striped dir return correct number of entries"
1314 [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
1320 $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1321 error "create striped dir failed"
1323 cd $DIR/$tdir/d0/striped_dir
1325 local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1326 local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1327 local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1329 [ "$d0_ino" = "$parent_ino" ] ||
1330 error ".. wrong, expect $d0_ino, get $parent_ino"
1332 mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1333 error "mv striped dir failed"
1335 parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1337 [ "$d1_ino" = "$parent_ino" ] ||
1338 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1340 run_test 24C "check .. in striped dir"
1343 [[ $MDSCOUNT -lt 4 ]] && skip_env "needs >= 4 MDTs"
1344 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1347 mkdir $DIR/$tdir/src_dir
1348 $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1349 error "create remote source failed"
1351 touch $DIR/$tdir/src_dir/src_child/a
1353 $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1354 error "create remote target dir failed"
1356 $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1357 error "create remote target child failed"
1359 mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1360 error "rename dir cross MDT failed!"
1364 $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1365 error "src_child still exists after rename"
1367 $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1368 error "missing file(a) after rename"
1370 rm -rf $DIR/$tdir || error "Can not delete directories"
1372 run_test 24E "cross MDT rename/link"
1375 echo '== symlink sanity ============================================='
1379 touch $DIR/s25/foo ||
1380 error "File creation in symlinked directory failed"
1382 run_test 25a "create file in symlinked directory ==============="
1385 [ ! -d $DIR/d25 ] && test_25a
1386 $CHECKSTAT -t file $DIR/s25/foo || error "$DIR/s25/foo not file type"
1388 run_test 25b "lookup file in symlinked directory ==============="
1392 test_mkdir $DIR/d26/d26-2
1393 ln -s d26/d26-2 $DIR/s26
1394 touch $DIR/s26/foo || error "File creation failed"
1396 run_test 26a "multiple component symlink ======================="
1399 test_mkdir -p $DIR/$tdir/d26-2
1400 ln -s $tdir/d26-2/foo $DIR/s26-2
1401 touch $DIR/s26-2 || error "File creation failed"
1403 run_test 26b "multiple component symlink at end of lookup ======"
1406 test_mkdir $DIR/d26.2
1407 touch $DIR/d26.2/foo
1408 ln -s d26.2 $DIR/s26.2-1
1409 ln -s s26.2-1 $DIR/s26.2-2
1410 ln -s s26.2-2 $DIR/s26.2-3
1411 chmod 0666 $DIR/s26.2-3/foo
1413 run_test 26c "chain of symlinks"
1415 # recursive symlinks (bug 439)
1417 ln -s d26-3/foo $DIR/d26-3
1419 run_test 26d "create multiple component recursive symlink"
1422 [ ! -h $DIR/d26-3 ] && test_26d
1425 run_test 26e "unlink multiple component recursive symlink"
1427 # recursive symlinks (bug 7022)
1429 test_mkdir $DIR/$tdir
1430 test_mkdir $DIR/$tdir/$tfile
1431 cd $DIR/$tdir/$tfile || error "cd $DIR/$tdir/$tfile failed"
1432 test_mkdir -p lndir/bar1
1433 test_mkdir $DIR/$tdir/$tfile/$tfile
1434 cd $tfile || error "cd $tfile failed"
1435 ln -s .. dotdot || error "ln dotdot failed"
1436 ln -s dotdot/lndir lndir || error "ln lndir failed"
1437 cd $DIR/$tdir || error "cd $DIR/$tdir failed"
1438 output=`ls $tfile/$tfile/lndir/bar1`
1439 [ "$output" = bar1 ] && error "unexpected output"
1440 rm -r $tfile || error "rm $tfile failed"
1441 $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1443 run_test 26f "rm -r of a directory which has recursive symlink"
1446 test_mkdir $DIR/$tdir
1447 $LFS getstripe $DIR/$tdir
1448 $LFS setstripe -c 1 $DIR/$tdir/$tfile || error "setstripe failed"
1449 $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1450 cp /etc/hosts $DIR/$tdir/$tfile || error "Can't copy to one stripe file"
1452 run_test 27a "one stripe file"
1455 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1457 test_mkdir $DIR/$tdir
1458 $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1459 $LFS getstripe -c $DIR/$tdir/$tfile
1460 [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
1461 error "two-stripe file doesn't have two stripes"
1463 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1465 run_test 27b "create and write to two stripe file"
1468 test_mkdir $DIR/$tdir
1469 $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile ||
1470 error "setstripe failed"
1471 $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1472 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1474 run_test 27d "create file with default settings"
1477 # LU-5839 adds check for existed layout before setting it
1478 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1479 skip "Need MDS version at least 2.7.56"
1481 test_mkdir $DIR/$tdir
1482 $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1483 $LFS setstripe -c 2 $DIR/$tdir/$tfile && error "setstripe worked twice"
1484 $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1486 run_test 27e "setstripe existing file (should return error)"
1489 test_mkdir $DIR/$tdir
1490 $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1491 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1492 $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1493 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1494 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1495 $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1497 run_test 27f "setstripe with bad stripe size (should return error)"
1500 test_mkdir $DIR/$tdir
1501 $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1502 $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "no stripe info" ||
1503 error "$DIR/$tdir/$tfile has object"
1505 run_test 27g "$LFS getstripe with no objects"
1508 test_mkdir $DIR/$tdir
1509 touch $DIR/$tdir/$tfile || error "touch failed"
1510 [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1511 error "missing objects"
1513 run_test 27i "$LFS getstripe with some objects"
1516 test_mkdir $DIR/$tdir
1517 $LFS setstripe -i $OSTCOUNT $DIR/$tdir/$tfile &&
1518 error "setstripe failed" || true
1520 run_test 27j "setstripe with bad stripe offset (should return error)"
1522 test_27k() { # bug 2844
1523 test_mkdir $DIR/$tdir
1524 local file=$DIR/$tdir/$tfile
1525 local ll_max_blksize=$((4 * 1024 * 1024))
1526 $LFS setstripe -S 67108864 $file || error "setstripe failed"
1527 local blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1528 [ $blksize -le $ll_max_blksize ] || error "1:$blksize > $ll_max_blksize"
1529 dd if=/dev/zero of=$file bs=4k count=1
1530 blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1531 [ $blksize -le $ll_max_blksize ] || error "2:$blksize > $ll_max_blksize"
1533 run_test 27k "limit i_blksize for broken user apps"
1536 mcreate $DIR/$tfile || error "creating file"
1537 $RUNAS $LFS setstripe -c 1 $DIR/$tfile &&
1538 error "setstripe should have failed" || true
1540 run_test 27l "check setstripe permissions (should return error)"
1543 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1545 ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1547 if [[ $ORIGFREE -gt $MAXFREE ]]; then
1548 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1550 trap simple_cleanup_common EXIT
1551 test_mkdir $DIR/$tdir
1552 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.1
1553 dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
1554 error "dd should fill OST0"
1556 while $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.$i; do
1558 [ $i -gt 256 ] && break
1561 touch $DIR/$tdir/$tfile.$i
1562 [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1563 awk '{print $1}'| grep -w "0") ] &&
1564 error "OST0 was full but new created file still use it"
1566 touch $DIR/$tdir/$tfile.$i
1567 [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1568 awk '{print $1}'| grep -w "0") ] &&
1569 error "OST0 was full but new created file still use it"
1570 simple_cleanup_common
1572 run_test 27m "create file while OST0 was full"
1575 local delay=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1576 awk '{ print $1 * 2; exit; }')
1580 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1581 # if the OST isn't full anymore.
1583 local OSTIDX=${1:-""}
1585 local list=$(comma_list $(osts_nodes))
1586 [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1588 do_nodes $list lctl set_param fail_loc=0
1589 sync # initiate all OST_DESTROYs from MDS to OST
1593 exhaust_precreations() {
1596 local FAILIDX=${3:-$OSTIDX}
1597 local ofacet=ost$((OSTIDX + 1))
1599 test_mkdir -p -c1 $DIR/$tdir
1600 local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1601 local mfacet=mds$((mdtidx + 1))
1602 echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1604 local OST=$(ostname_from_index $OSTIDX)
1607 local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1608 local last_id=$(do_facet $mfacet lctl get_param -n \
1609 osc.$mdtosc_proc1.prealloc_last_id)
1610 local next_id=$(do_facet $mfacet lctl get_param -n \
1611 osc.$mdtosc_proc1.prealloc_next_id)
1613 local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1614 do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1616 test_mkdir -p $DIR/$tdir/${OST}
1617 $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1618 #define OBD_FAIL_OST_ENOSPC 0x215
1619 do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1620 echo "Creating to objid $last_id on ost $OST..."
1621 createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1622 do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1623 do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1627 exhaust_all_precreations() {
1629 for (( i=0; i < OSTCOUNT; i++ )) ; do
1630 exhaust_precreations $i $1 -1
1635 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1636 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1637 remote_mds_nodsh && skip "remote MDS with nodsh"
1638 remote_ost_nodsh && skip "remote OST with nodsh"
1641 rm -f $DIR/$tdir/$tfile
1642 exhaust_precreations 0 0x80000215
1643 $LFS setstripe -c -1 $DIR/$tdir || error "setstripe failed"
1644 touch $DIR/$tdir/$tfile || error "touch failed"
1645 $LFS getstripe $DIR/$tdir/$tfile
1648 run_test 27n "create file with some full OSTs"
1651 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1652 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1653 remote_mds_nodsh && skip "remote MDS with nodsh"
1654 remote_ost_nodsh && skip "remote OST with nodsh"
1657 rm -f $DIR/$tdir/$tfile
1658 exhaust_all_precreations 0x215
1660 touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1665 run_test 27o "create file with all full OSTs (should error)"
1668 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1669 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1670 remote_mds_nodsh && skip "remote MDS with nodsh"
1671 remote_ost_nodsh && skip "remote OST with nodsh"
1674 rm -f $DIR/$tdir/$tfile
1675 test_mkdir $DIR/$tdir
1677 $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1678 $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1679 $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1681 exhaust_precreations 0 0x80000215
1682 echo foo >> $DIR/$tdir/$tfile || error "append failed"
1683 $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1684 $LFS getstripe $DIR/$tdir/$tfile
1688 run_test 27p "append to a truncated file with some full OSTs"
1691 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1692 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1693 remote_mds_nodsh && skip "remote MDS with nodsh"
1694 remote_ost_nodsh && skip "remote OST with nodsh"
1697 rm -f $DIR/$tdir/$tfile
1699 test_mkdir $DIR/$tdir
1700 $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1701 $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1702 error "truncate $DIR/$tdir/$tfile failed"
1703 $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1705 exhaust_all_precreations 0x215
1707 echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1708 $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1712 run_test 27q "append to truncated file with all OSTs full (should error)"
1715 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1716 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1717 remote_mds_nodsh && skip "remote MDS with nodsh"
1718 remote_ost_nodsh && skip "remote OST with nodsh"
1721 rm -f $DIR/$tdir/$tfile
1722 exhaust_precreations 0 0x80000215
1724 $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1728 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1730 test_27s() { # bug 10725
1731 test_mkdir $DIR/$tdir
1732 local stripe_size=$((4096 * 1024 * 1024)) # 2^32
1733 local stripe_count=0
1734 [ $OSTCOUNT -eq 1 ] || stripe_count=2
1735 $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1736 error "stripe width >= 2^32 succeeded" || true
1739 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1741 test_27t() { # bug 10864
1746 $WLFS getstripe $tfile
1749 run_test 27t "check that utils parse path correctly"
1751 test_27u() { # bug 4900
1752 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1753 remote_mds_nodsh && skip "remote MDS with nodsh"
1756 local list=$(comma_list $(mdts_nodes))
1758 #define OBD_FAIL_MDS_OSC_PRECREATE 0x139
1759 do_nodes $list $LCTL set_param fail_loc=0x139
1760 test_mkdir -p $DIR/$tdir
1761 trap simple_cleanup_common EXIT
1762 createmany -o $DIR/$tdir/t- 1000
1763 do_nodes $list $LCTL set_param fail_loc=0
1765 TLOG=$TMP/$tfile.getstripe
1766 $LFS getstripe $DIR/$tdir > $TLOG
1767 OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1768 unlinkmany $DIR/$tdir/t- 1000
1770 [[ $OBJS -gt 0 ]] &&
1771 error "$OBJS objects created on OST-0. See $TLOG" ||
1774 run_test 27u "skip object creation on OSC w/o objects"
1776 test_27v() { # bug 4900
1777 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1778 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1779 remote_mds_nodsh && skip "remote MDS with nodsh"
1780 remote_ost_nodsh && skip "remote OST with nodsh"
1782 exhaust_all_precreations 0x215
1785 $LFS setstripe -c 1 $DIR/$tdir # 1 stripe / file
1787 touch $DIR/$tdir/$tfile
1788 #define OBD_FAIL_TGT_DELAY_PRECREATE 0x705
1790 for (( i=1; i < OSTCOUNT; i++ )); do
1791 do_facet ost$i lctl set_param fail_loc=0x705
1793 local START=`date +%s`
1794 createmany -o $DIR/$tdir/$tfile 32
1796 local FINISH=`date +%s`
1797 local TIMEOUT=`lctl get_param -n timeout`
1798 local PROCESS=$((FINISH - START))
1799 [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1800 error "$FINISH - $START >= $TIMEOUT / 2"
1801 sleep $((TIMEOUT / 2 - PROCESS))
1804 run_test 27v "skip object creation on slow OST"
1806 test_27w() { # bug 10997
1807 test_mkdir $DIR/$tdir
1808 $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1809 [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
1810 error "stripe size $size != 65536" || true
1811 [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
1812 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
1814 run_test 27w "check $LFS setstripe -S and getstrip -d options"
1817 [[ $OSTCOUNT -lt 2 ]] &&
1818 skip_env "skipping multiple stripe count/offset test"
1820 test_mkdir $DIR/$tdir
1821 for i in $(seq 1 $OSTCOUNT); do
1823 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
1824 error "setstripe -c $i -i $offset failed"
1825 count=$($LFS getstripe -c $DIR/$tdir/f$i)
1826 index=$($LFS getstripe -i $DIR/$tdir/f$i)
1827 [ $count -ne $i ] && error "stripe count $count != $i" || true
1828 [ $index -ne $offset ] &&
1829 error "stripe offset $index != $offset" || true
1832 run_test 27wa "check $LFS setstripe -c -i options"
1835 remote_ost_nodsh && skip "remote OST with nodsh"
1836 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1837 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1839 OFFSET=$(($OSTCOUNT - 1))
1841 local OST=$(ostname_from_index $OSTIDX)
1843 test_mkdir $DIR/$tdir
1844 $LFS setstripe -c 1 $DIR/$tdir # 1 stripe per file
1845 do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1847 createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1848 for i in $(seq 0 $OFFSET); do
1849 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
1850 awk '{print $1}' | grep -w "$OSTIDX") ] &&
1851 error "OST0 was degraded but new created file still use it"
1853 do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1855 run_test 27x "create files while OST0 is degraded"
1858 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
1859 remote_mds_nodsh && skip "remote MDS with nodsh"
1860 remote_ost_nodsh && skip "remote OST with nodsh"
1861 [ $PARALLEL == "yes" ] && skip "skip parallel run"
1863 local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1864 local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1865 osc.$mdtosc.prealloc_last_id)
1866 local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1867 osc.$mdtosc.prealloc_next_id)
1868 local fcount=$((last_id - next_id))
1869 [[ $fcount -eq 0 ]] && skip "not enough space on OST0"
1870 [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1872 local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1873 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1874 local OST_DEACTIVE_IDX=-1
1879 for OSC in $MDS_OSCS; do
1880 OST=$(osc_to_ost $OSC)
1881 OSTIDX=$(index_from_ostuuid $OST)
1882 if [ $OST_DEACTIVE_IDX == -1 ]; then
1883 OST_DEACTIVE_IDX=$OSTIDX
1885 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1886 echo $OSC "is Deactivated:"
1887 do_facet $SINGLEMDS lctl --device %$OSC deactivate
1891 OSTIDX=$(index_from_ostuuid $OST)
1892 test_mkdir $DIR/$tdir
1893 $LFS setstripe -c 1 $DIR/$tdir # 1 stripe / file
1895 for OSC in $MDS_OSCS; do
1896 OST=$(osc_to_ost $OSC)
1897 OSTIDX=$(index_from_ostuuid $OST)
1898 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1899 echo $OST "is degraded:"
1900 do_facet ost$((OSTIDX+1)) lctl set_param -n \
1901 obdfilter.$OST.degraded=1
1906 createmany -o $DIR/$tdir/$tfile $fcount
1908 for OSC in $MDS_OSCS; do
1909 OST=$(osc_to_ost $OSC)
1910 OSTIDX=$(index_from_ostuuid $OST)
1911 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1912 echo $OST "is recovered from degraded:"
1913 do_facet ost$((OSTIDX+1)) lctl set_param -n \
1914 obdfilter.$OST.degraded=0
1916 do_facet $SINGLEMDS lctl --device %$OSC activate
1920 # all osp devices get activated, hence -1 stripe count restored
1921 local stripe_count=0
1923 # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1924 # devices get activated.
1926 $LFS setstripe -c -1 $DIR/$tfile
1927 stripe_count=$($LFS getstripe -c $DIR/$tfile)
1929 [ $stripe_count -ne $OSTCOUNT ] &&
1930 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
1933 run_test 27y "create files while OST0 is degraded and the rest inactive"
1939 lmm_count=$($GETSTRIPE -c $1)
1940 lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1941 lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1943 local old_ifs="$IFS"
1945 fid=($($LFS path2fid $1))
1948 log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1949 log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1951 # compare lmm_seq and lu_fid->f_seq
1952 [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1953 # compare lmm_object_id and lu_fid->oid
1954 [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1956 # check the trusted.fid attribute of the OST objects of the file
1957 local have_obdidx=false
1959 $GETSTRIPE $1 | while read obdidx oid hex seq; do
1960 # skip lines up to and including "obdidx"
1961 [ -z "$obdidx" ] && break
1962 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1963 $have_obdidx || continue
1965 local ost=$((obdidx + 1))
1966 local dev=$(ostdevname $ost)
1969 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1971 seq=$(echo $seq | sed -e "s/^0x//g")
1972 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1973 oid_hex=$(echo $oid)
1975 oid_hex=$(echo $hex | sed -e "s/^0x//g")
1977 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1981 # Don't unmount/remount the OSTs if we don't need to do that.
1982 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1983 # update too, until that use mount/ll_decode_filter_fid/mount.
1984 # Re-enable when debugfs will understand new filter_fid.
1986 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
1987 ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1988 $dev 2>/dev/null" | grep "parent=")
1990 if [ -z "$ff" ]; then
1992 mount_fstype ost$ost
1993 ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1994 $(facet_mntpt ost$ost)/$obj_file)
1995 unmount_fstype ost$ost
1996 start ost$ost $dev $OST_MOUNT_OPTS
2000 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
2002 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
2004 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
2005 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
2007 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
2008 # stripe_size=1048576 component_id=1 component_start=0 \
2009 # component_end=33554432
2010 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
2011 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
2012 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
2014 if grep -q 'stripe=' <<<$ff; then
2015 ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
2017 # $LL_DECODE_FILTER_FID does not print "stripe="; look
2018 # into f_ver in this case. See comment on ff_parent.
2019 ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
2022 # compare lmm_seq and filter_fid->ff_parent.f_seq
2023 [ $ff_pseq = $lmm_seq ] ||
2024 error "FF parent SEQ $ff_pseq != $lmm_seq"
2025 # compare lmm_object_id and filter_fid->ff_parent.f_oid
2026 [ $ff_poid = $lmm_oid ] ||
2027 error "FF parent OID $ff_poid != $lmm_oid"
2028 (($ff_pstripe == $stripe_nr)) ||
2029 error "FF stripe $ff_pstripe != $stripe_nr"
2031 stripe_nr=$((stripe_nr + 1))
2032 [ $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2034 if grep -q 'stripe_count=' <<<$ff; then
2035 local ff_scnt=$(sed -e 's/.*stripe_count=//' \
2036 -e 's/ .*//' <<<$ff)
2037 [ $lmm_count = $ff_scnt ] ||
2038 error "FF stripe count $lmm_count != $ff_scnt"
2044 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2045 remote_ost_nodsh && skip "remote OST with nodsh"
2047 test_mkdir $DIR/$tdir
2048 $LFS setstripe -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
2049 { error "setstripe -c -1 failed"; return 1; }
2050 # We need to send a write to every object to get parent FID info set.
2051 # This _should_ also work for setattr, but does not currently.
2052 # touch $DIR/$tdir/$tfile-1 ||
2053 dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
2054 { error "dd $tfile-1 failed"; return 2; }
2055 $LFS setstripe -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
2056 { error "setstripe -c -1 failed"; return 3; }
2057 dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
2058 { error "dd $tfile-2 failed"; return 4; }
2060 # make sure write RPCs have been sent to OSTs
2063 check_seq_oid $DIR/$tdir/$tfile-1 || return 5
2064 check_seq_oid $DIR/$tdir/$tfile-2 || return 6
2066 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
2068 test_27A() { # b=19102
2069 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2071 save_layout_restore_at_exit $MOUNT
2072 $LFS setstripe -c 0 -i -1 -S 0 $MOUNT
2073 wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/ *//g'" "1" 20 ||
2074 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
2075 local default_size=$($GETSTRIPE -S $MOUNT)
2076 local default_offset=$($GETSTRIPE -i $MOUNT)
2077 local dsize=$(do_facet $SINGLEMDS \
2078 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
2079 [ $default_size -eq $dsize ] ||
2080 error "stripe size $default_size != $dsize"
2081 [ $default_offset -eq -1 ] ||
2082 error "stripe offset $default_offset != -1"
2084 run_test 27A "check filesystem-wide default LOV EA values"
2086 test_27B() { # LU-2523
2087 test_mkdir $DIR/$tdir
2088 rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
2090 # open f1 with O_LOV_DELAY_CREATE
2092 # call setstripe ioctl on open file descriptor for f1
2094 multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
2098 # open f1 with O_LOV_DELAY_CREATE
2100 # call setstripe ioctl on open file descriptor for f1
2102 multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2104 # Allow multiop to fail in imitation of NFS's busted semantics.
2107 run_test 27B "call setstripe on open unlinked file/rename victim"
2109 test_27C() { #LU-2871
2110 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2118 test_mkdir $DIR/$tdir
2120 for i in $(seq 0 $((OSTCOUNT - 1))); do
2121 # set stripe across all OSTs starting from OST$i
2122 $SETSTRIPE -i $i -c -1 $tfile$i
2123 # get striping information
2124 ost_idx=($($GETSTRIPE $tfile$i |
2125 tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2129 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2130 error "${#ost_idx[@]} != $OSTCOUNT"
2132 for index in $(seq 0 $((OSTCOUNT - 1))); do
2134 for j in $(echo ${ost_idx[@]}); do
2135 if [ $index -eq $j ]; then
2141 error "Can not find $index in ${ost_idx[@]}"
2145 run_test 27C "check full striping across all OSTs"
2148 [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2149 [ -n "$FILESET" ] && skip "SKIP due to FILESET set"
2150 remote_mds_nodsh && skip "remote MDS with nodsh"
2152 local POOL=${POOL:-testpool}
2154 local last_ost=$(($OSTCOUNT - 1))
2156 local ost_list=$(seq $first_ost $ost_step $last_ost)
2157 local ost_range="$first_ost $last_ost $ost_step"
2159 if ! combined_mgs_mds ; then
2163 test_mkdir $DIR/$tdir
2164 pool_add $POOL || error "pool_add failed"
2165 pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2168 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
2170 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) -o \
2171 $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2172 skip27D+=" -s 30,31"
2173 llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2174 error "llapi_layout_test failed"
2176 destroy_test_pools || error "destroy test pools failed"
2178 if ! combined_mgs_mds ; then
2182 run_test 27D "validate llapi_layout API"
2184 # Verify that default_easize is increased from its initial value after
2185 # accessing a widely striped file.
2187 [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2188 [ $(lustre_version_code client) -lt $(version_code 2.5.57) ] &&
2189 skip "client does not have LU-3338 fix"
2191 # 72 bytes is the minimum space required to store striping
2192 # information for a file striped across one OST:
2193 # (sizeof(struct lov_user_md_v3) +
2194 # sizeof(struct lov_user_ost_data_v1))
2196 $LCTL set_param -n llite.*.default_easize $min_easize ||
2197 error "lctl set_param failed"
2198 local easize=$($LCTL get_param -n llite.*.default_easize)
2200 [ $easize -eq $min_easize ] ||
2201 error "failed to set default_easize"
2203 $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2204 error "setstripe failed"
2208 easize=$($LCTL get_param -n llite.*.default_easize)
2210 [ $easize -gt $min_easize ] ||
2211 error "default_easize not updated"
2213 run_test 27E "check that default extended attribute size properly increases"
2215 test_27F() { # LU-5346/LU-7975
2216 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2217 [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs"
2218 [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
2219 skip "Need MDS version at least 2.8.51"
2220 remote_ost_nodsh && skip "remote OST with nodsh"
2222 test_mkdir $DIR/$tdir
2224 $SETSTRIPE -c 2 $DIR/$tdir
2226 # stop all OSTs to reproduce situation for LU-7975 ticket
2227 for num in $(seq $OSTCOUNT); do
2231 # open/create f0 with O_LOV_DELAY_CREATE
2232 # truncate f0 to a non-0 size
2234 multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2236 $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2237 # open/write it again to force delayed layout creation
2238 cat /etc/hosts > $DIR/$tdir/f0 &
2242 for num in $(seq $OSTCOUNT); do
2243 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2244 error "ost$num failed to start"
2247 wait $catpid || error "cat failed"
2249 cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2250 [[ $($GETSTRIPE -c $DIR/$tdir/f0) == 2 ]] || error "wrong stripecount"
2253 run_test 27F "Client resend delayed layout creation with non-zero size"
2255 # createtest also checks that device nodes are created and
2256 # then visible correctly (#2091)
2257 test_28() { # bug 2091
2259 $CREATETEST $DIR/d28/ct || error "createtest failed"
2261 run_test 28 "create/mknod/mkdir with bad file types ============"
2264 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2266 sync; sleep 1; sync # flush out any dirty pages from previous tests
2273 declare -i LOCKCOUNTORIG=0
2274 for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2275 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2277 [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
2279 declare -i LOCKUNUSEDCOUNTORIG=0
2280 for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2281 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2288 declare -i LOCKCOUNTCURRENT=0
2289 for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2290 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2293 declare -i LOCKUNUSEDCOUNTCURRENT=0
2294 for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2295 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2298 if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2299 $LCTL set_param -n ldlm.dump_namespaces ""
2300 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2301 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2302 log "dumped log to $TMP/test_29.dk (bug 5793)"
2305 if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2306 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2307 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2308 log "dumped log to $TMP/test_29.dk (bug 5793)"
2312 run_test 29 "IT_GETATTR regression ============================"
2314 test_30a() { # was test_30
2315 cp $(which ls) $DIR || cp /bin/ls $DIR
2316 $DIR/ls / || error "Can't execute binary from lustre"
2319 run_test 30a "execute binary from Lustre (execve) =============="
2322 cp `which ls` $DIR || cp /bin/ls $DIR
2324 $RUNAS $DIR/ls / || error "Can't execute binary from lustre as non-root"
2327 run_test 30b "execute binary from Lustre as non-root ==========="
2329 test_30c() { # b=22376
2330 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2332 cp `which ls` $DIR || cp /bin/ls $DIR
2334 cancel_lru_locks mdc
2335 cancel_lru_locks osc
2336 $RUNAS $DIR/ls / || error "Can't execute binary from lustre"
2339 run_test 30c "execute binary from Lustre without read perms ===="
2342 $OPENUNLINK $DIR/f31 $DIR/f31 || error "openunlink failed"
2343 $CHECKSTAT -a $DIR/f31 || error "$DIR/f31 exists"
2345 run_test 31a "open-unlink file =================================="
2348 touch $DIR/f31 || error "touch $DIR/f31 failed"
2349 ln $DIR/f31 $DIR/f31b || error "ln failed"
2350 $MULTIOP $DIR/f31b Ouc || error "multiop failed"
2351 $CHECKSTAT -t file $DIR/f31 || error "$DIR/f31 not file type"
2353 run_test 31b "unlink file with multiple links while open ======="
2356 touch $DIR/f31 || error "touch $DIR/f31 failed"
2357 ln $DIR/f31 $DIR/f31c || error "ln failed"
2358 multiop_bg_pause $DIR/f31 O_uc ||
2359 error "multiop_bg_pause for $DIR/f31 failed"
2361 $MULTIOP $DIR/f31c Ouc
2362 kill -USR1 $MULTIPID
2365 run_test 31c "open-unlink file with multiple links ============="
2368 opendirunlink $DIR/d31d $DIR/d31d || error "opendirunlink failed"
2369 $CHECKSTAT -a $DIR/d31d || error "$DIR/d31d exists"
2371 run_test 31d "remove of open directory ========================="
2373 test_31e() { # bug 2904
2374 openfilleddirunlink $DIR/d31e || error "openfilleddirunlink failed"
2376 run_test 31e "remove of open non-empty directory ==============="
2378 test_31f() { # bug 4554
2379 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2382 test_mkdir $DIR/d31f
2383 $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2384 cp /etc/hosts $DIR/d31f
2386 $GETSTRIPE $DIR/d31f/hosts
2387 multiop_bg_pause $DIR/d31f D_c || return 1
2390 rm -rv $DIR/d31f || error "first of $DIR/d31f"
2391 test_mkdir $DIR/d31f
2392 $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2393 cp /etc/hosts $DIR/d31f
2395 $GETSTRIPE $DIR/d31f/hosts
2396 multiop_bg_pause $DIR/d31f D_c || return 1
2399 kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2400 wait $MULTIPID || error "first opendir $MULTIPID failed"
2404 kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2405 wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2408 run_test 31f "remove of open directory with open-unlink file ==="
2411 echo "-- cross directory link --"
2412 test_mkdir -c1 $DIR/${tdir}ga
2413 test_mkdir -c1 $DIR/${tdir}gb
2414 touch $DIR/${tdir}ga/f
2415 ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2416 $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2417 [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2418 $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2419 [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2421 run_test 31g "cross directory link==============="
2424 echo "-- cross directory link --"
2425 test_mkdir -c1 $DIR/${tdir}
2426 test_mkdir -c1 $DIR/${tdir}/dir
2427 touch $DIR/${tdir}/f
2428 ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2429 $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2430 [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2431 $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2432 [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2434 run_test 31h "cross directory link under child==============="
2437 echo "-- cross directory link --"
2438 test_mkdir -c1 $DIR/$tdir
2439 test_mkdir -c1 $DIR/$tdir/dir
2440 touch $DIR/$tdir/dir/f
2441 ln $DIR/$tdir/dir/f $DIR/$tdir/g
2442 $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2443 [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2444 $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2445 [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2447 run_test 31i "cross directory link under parent==============="
2450 test_mkdir -c1 -p $DIR/$tdir
2451 test_mkdir -c1 -p $DIR/$tdir/dir1
2452 ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2453 link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2454 mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2455 mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2458 run_test 31j "link for directory==============="
2461 test_mkdir -c1 -p $DIR/$tdir
2463 touch $DIR/$tdir/exist
2464 mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2465 mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2466 mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2467 mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2468 mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2469 mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2470 mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2473 run_test 31k "link to file: the same, non-existing, dir==============="
2479 touch $DIR/d31m2/exist
2480 mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2481 mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2482 mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2483 mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2484 mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2485 mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2488 run_test 31m "link to file: the same, non-existing, dir==============="
2491 touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2492 nlink=$(stat --format=%h $DIR/$tfile)
2493 [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2495 local cmd="exec $fd<$DIR/$tfile"
2498 trap "eval $cmd" EXIT
2499 nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2500 [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2501 rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2502 nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2503 [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2506 run_test 31n "check link count of unlinked file"
2509 local TEMPNAME=$(mktemp $1_XXXXXX)
2510 mlink $TEMPNAME $1 2> /dev/null &&
2511 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2515 test_31o() { # LU-2901
2516 test_mkdir $DIR/$tdir
2517 for LOOP in $(seq 100); do
2518 rm -f $DIR/$tdir/$tfile*
2519 for THREAD in $(seq 8); do
2520 link_one $DIR/$tdir/$tfile.$LOOP &
2523 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2524 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2525 error "$LINKS duplicate links to $tfile.$LOOP" &&
2529 run_test 31o "duplicate hard links with same filename"
2532 [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
2534 test_mkdir $DIR/$tdir
2535 $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2536 $LFS setdirstripe -D -c2 -H all_char $DIR/$tdir/striped_dir
2538 opendirunlink $DIR/$tdir/striped_dir/test1 ||
2539 error "open unlink test1 failed"
2540 opendirunlink $DIR/$tdir/striped_dir/test2 ||
2541 error "open unlink test2 failed"
2543 $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2544 error "test1 still exists"
2545 $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2546 error "test2 still exists"
2548 run_test 31p "remove of open striped directory"
2550 cleanup_test32_mount() {
2553 local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
2554 $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
2555 losetup -d $loopdev || true
2561 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2563 echo "== more mountpoints and symlinks ================="
2564 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2565 trap cleanup_test32_mount EXIT
2566 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2567 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2568 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2569 $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. ||
2570 error "$DIR/$tdir/ext2-mountpoint/.. not dir type"
2571 cleanup_test32_mount
2573 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2576 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2578 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2579 trap cleanup_test32_mount EXIT
2580 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2581 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2582 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2583 ls -al $DIR/$tdir/ext2-mountpoint/.. ||
2584 error "Can't list $DIR/$tdir/ext2-mountpoint/.."
2585 cleanup_test32_mount
2587 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2590 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2592 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2593 trap cleanup_test32_mount EXIT
2594 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2595 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2596 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2597 test_mkdir -p $DIR/$tdir/d2/test_dir
2598 $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
2599 error "$DIR/$tdir/ext2-mountpoint/../d2/test_dir not dir type"
2600 cleanup_test32_mount
2602 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2605 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2607 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2608 trap cleanup_test32_mount EXIT
2609 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2610 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2611 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2612 test_mkdir -p $DIR/$tdir/d2/test_dir
2613 ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
2614 error "Can't list $DIR/$tdir/ext2-mountpoint/../d2/test_dir"
2615 cleanup_test32_mount
2617 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir"
2621 test_mkdir -p $DIR/$tdir/tmp
2622 local tmp_dir=$DIR/$tdir/tmp
2623 ln -s $DIR/$tdir $tmp_dir/symlink11
2624 ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2625 $CHECKSTAT -t link $DIR/$tdir/tmp/symlink11 || error "symlink11 bad"
2626 $CHECKSTAT -t link $DIR/$tdir/symlink01 || error "symlink01 bad"
2628 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir"
2632 test_mkdir -p $DIR/$tdir/tmp
2633 local tmp_dir=$DIR/$tdir/tmp
2634 ln -s $DIR/$tdir $tmp_dir/symlink11
2635 ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2636 ls $DIR/$tdir/tmp/symlink11 || error "symlink11 bad"
2637 ls $DIR/$tdir/symlink01 || error "symlink01 bad"
2639 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir"
2642 local tmp_dir=$DIR/$tdir/tmp
2643 test_mkdir -p $tmp_dir
2644 test_mkdir $DIR/${tdir}2
2645 ln -s $DIR/${tdir}2 $tmp_dir/symlink12
2646 ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
2647 $CHECKSTAT -t link $tmp_dir/symlink12 || error "symlink12 not a link"
2648 $CHECKSTAT -t link $DIR/$tdir/symlink02 || error "symlink02 not a link"
2649 $CHECKSTAT -t dir -f $tmp_dir/symlink12 || error "symlink12 not a dir"
2650 $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error "symlink12 not a dir"
2652 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2655 rm -fr $DIR/$tdir $DIR/${tdir}2
2656 tmp_dir=$DIR/$tdir/tmp
2657 test_mkdir -p $tmp_dir
2658 test_mkdir $DIR/${tdir}2
2659 ln -s $DIR/${tdir}2 $tmp_dir/symlink12
2660 ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
2661 ls $tmp_dir/symlink12 || error "listing symlink12"
2662 ls $DIR/$tdir/symlink02 || error "listing symlink02"
2664 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2667 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2669 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2670 trap cleanup_test32_mount EXIT
2671 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2672 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2673 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2674 touch $DIR/$tdir/test_file
2675 $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file ||
2676 error "$DIR/$tdir/ext2-mountpoint/../test_file not file type"
2677 cleanup_test32_mount
2679 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2682 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2684 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2685 trap cleanup_test32_mount EXIT
2686 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2687 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2688 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2689 touch $DIR/$tdir/test_file
2690 cat $DIR/$tdir/ext2-mountpoint/../test_file ||
2691 error "Can't open $DIR/$tdir/ext2-mountpoint/../test_file"
2692 cleanup_test32_mount
2694 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2697 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2700 trap cleanup_test32_mount EXIT
2701 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2702 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2703 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2704 test_mkdir -p $DIR/$tdir/d2
2705 touch $DIR/$tdir/d2/test_file || error "touch failed"
2706 $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
2707 error "$DIR/$tdir/ext2-mountpoint/../d2/test_file not file type"
2708 cleanup_test32_mount
2710 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2713 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2716 trap cleanup_test32_mount EXIT
2717 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2718 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2719 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2720 test_mkdir -p $DIR/$tdir/d2
2721 touch $DIR/$tdir/d2/test_file || error "touch failed"
2722 cat $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
2723 error "Can't open $DIR/$tdir/ext2-mountpoint/../d2/test_file"
2724 cleanup_test32_mount
2726 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2730 test_mkdir -p $DIR/d32m/tmp
2731 TMP_DIR=$DIR/d32m/tmp
2732 ln -s $DIR $TMP_DIR/symlink11
2733 ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2734 $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 ||
2735 error "symlink11 not a link"
2736 $CHECKSTAT -t link $DIR/d32m/symlink01 ||
2737 error "symlink01 not a link"
2739 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2743 test_mkdir -p $DIR/d32n/tmp
2744 TMP_DIR=$DIR/d32n/tmp
2745 ln -s $DIR $TMP_DIR/symlink11
2746 ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2747 ls -l $DIR/d32n/tmp/symlink11 || error "listing symlink11"
2748 ls -l $DIR/d32n/symlink01 || error "listing symlink01"
2750 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2754 test_mkdir -p $DIR/d32o/tmp
2755 TMP_DIR=$DIR/d32o/tmp
2756 ln -s $DIR/$tfile $TMP_DIR/symlink12
2757 ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2758 $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 ||
2759 error "symlink12 not a link"
2760 $CHECKSTAT -t link $DIR/d32o/symlink02 || error "symlink02 not a link"
2761 $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 ||
2762 error "$DIR/d32o/tmp/symlink12 not file type"
2763 $CHECKSTAT -t file -f $DIR/d32o/symlink02 ||
2764 error "$DIR/d32o/symlink02 not file type"
2766 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2776 test_mkdir -p $DIR/d32p/tmp
2778 TMP_DIR=$DIR/d32p/tmp
2780 ln -s $DIR/$tfile $TMP_DIR/symlink12
2782 ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2784 cat $DIR/d32p/tmp/symlink12 ||
2785 error "Can't open $DIR/d32p/tmp/symlink12"
2787 cat $DIR/d32p/symlink02 || error "Can't open $DIR/d32p/symlink02"
2790 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2793 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2795 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2796 trap cleanup_test32_mount EXIT
2797 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2798 touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
2799 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2800 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2801 ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
2802 cleanup_test32_mount
2804 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2807 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2809 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2810 trap cleanup_test32_mount EXIT
2811 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2812 touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
2813 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
2814 error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
2815 ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
2816 cleanup_test32_mount
2818 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2823 chmod 444 $DIR/$tfile
2824 chown $RUNAS_ID $DIR/$tfile
2826 $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2829 run_test 33aa "write file with mode 444 (should return error)"
2833 test_mkdir $DIR/$tdir
2834 chown $RUNAS_ID $DIR/$tdir
2835 $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile ||
2836 error "$RUNAS create $tdir/$tfile failed"
2837 $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile &&
2838 error "open RDWR" || true
2840 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2844 test_mkdir $DIR/$tdir
2845 chown $RUNAS_ID $DIR/$tdir
2846 $RUNAS $OPENFILE -f 1286739555 $DIR/$tdir/$tfile || true
2848 run_test 33b "test open file with malformed flags (No panic)"
2851 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2852 remote_ost_nodsh && skip "remote OST with nodsh"
2861 test_mkdir $DIR/$tdir
2862 # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2865 for ostnum in $(seq $OSTCOUNT); do
2866 # test-framework's OST numbering is one-based, while Lustre's
2868 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2869 # Parsing llobdstat's output sucks; we could grep the /proc
2870 # path, but that's likely to not be as portable as using the
2871 # llobdstat utility. So we parse lctl output instead.
2872 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2873 obdfilter/$ostname/stats |
2874 awk '/^write_bytes/ {print $7}' )
2875 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2876 if (( ${write_bytes:-0} > 0 ))
2883 $all_zeros || return 0
2886 echo foo > $DIR/$tdir/bar
2890 # Total up write_bytes after writing. We'd better find non-zeros.
2891 for ostnum in $(seq $OSTCOUNT); do
2892 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2893 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2894 obdfilter/$ostname/stats |
2895 awk '/^write_bytes/ {print $7}' )
2896 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2897 if (( ${write_bytes:-0} > 0 ))
2906 for ostnum in $(seq $OSTCOUNT); do
2907 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2908 echo "Check that write_bytes is present in obdfilter/*/stats:"
2909 do_facet ost$ostnum lctl get_param -n \
2910 obdfilter/$ostname/stats
2912 error "OST not keeping write_bytes stats (b22312)"
2915 run_test 33c "test llobdstat and write_bytes"
2918 [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
2919 [ $PARALLEL == "yes" ] && skip "skip parallel run"
2922 local remote_dir=$DIR/$tdir/remote_dir
2924 test_mkdir $DIR/$tdir
2925 $LFS mkdir -i $MDTIDX $remote_dir ||
2926 error "create remote directory failed"
2928 touch $remote_dir/$tfile
2929 chmod 444 $remote_dir/$tfile
2930 chown $RUNAS_ID $remote_dir/$tfile
2932 $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2934 chown $RUNAS_ID $remote_dir
2935 $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2936 error "create" || true
2937 $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2938 error "open RDWR" || true
2939 $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2941 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2944 [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
2948 $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2949 $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2950 mkdir $DIR/$tdir/local_dir
2952 local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2953 local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2954 local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2956 [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2957 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2959 rmdir $DIR/$tdir/* || error "rmdir failed"
2962 $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2963 $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2964 mkdir $DIR/$tdir/local_dir
2966 s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2967 s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2968 l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2970 [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2971 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2973 rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2976 $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2977 $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2978 mkdir $DIR/$tdir/local_dir
2980 s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2981 s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2982 l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2984 [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2985 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2987 run_test 33e "mkdir and striped directory should have same mode"
2991 do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2995 [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
2996 remote_mds_nodsh && skip "remote MDS with nodsh"
2999 chmod go+rwx $DIR/$tdir
3000 do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
3001 trap cleanup_33f EXIT
3003 $RUNAS lfs mkdir -i 0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
3004 error "cannot create striped directory"
3006 $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
3007 error "cannot create files in striped directory"
3009 $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
3010 error "cannot remove files in striped directory"
3012 $RUNAS rmdir $DIR/$tdir/striped_dir ||
3013 error "cannot remove striped directory"
3017 run_test 33f "nonroot user can create, access, and remove a striped directory"
3020 mkdir -p $DIR/$tdir/dir2
3022 local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
3024 [[ $err =~ "exists" ]] || error "Not exists error"
3026 run_test 33g "nonroot user create already existing root created file"
3028 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
3031 $MCREATE $DIR/f34 || error "mcreate failed"
3032 $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
3033 error "getstripe failed"
3034 $TRUNCATE $DIR/f34 $TEST_34_SIZE || error "truncate failed"
3035 $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
3036 error "getstripe failed"
3037 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3038 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3040 run_test 34a "truncate file that has not been opened ==========="
3043 [ ! -f $DIR/f34 ] && test_34a
3044 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3045 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3046 $OPENFILE -f O_RDONLY $DIR/f34
3047 $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
3048 error "getstripe failed"
3049 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3050 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3052 run_test 34b "O_RDONLY opening file doesn't create objects ====="
3055 [ ! -f $DIR/f34 ] && test_34a
3056 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3057 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3058 $OPENFILE -f O_RDWR $DIR/f34
3059 $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
3060 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3061 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3063 run_test 34c "O_RDWR opening file-with-size works =============="
3066 [ ! -f $DIR/f34 ] && test_34a
3067 dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 ||
3069 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
3070 error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
3073 run_test 34d "write to sparse file ============================="
3077 $MCREATE $DIR/f34e || error "mcreate failed"
3078 $TRUNCATE $DIR/f34e 1000 || error "truncate failed"
3079 $CHECKSTAT -s 1000 $DIR/f34e ||
3080 error "Size of $DIR/f34e not equal to 1000 bytes"
3081 $OPENFILE -f O_RDWR $DIR/f34e
3082 $CHECKSTAT -s 1000 $DIR/f34e ||
3083 error "Size of $DIR/f34e not equal to 1000 bytes"
3085 run_test 34e "create objects, some with size and some without =="
3087 test_34f() { # bug 6242, 6243
3088 [ $PARALLEL == "yes" ] && skip "skip parallel run"
3092 $MCREATE $DIR/f34f || error "mcreate failed"
3093 $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
3094 dd if=$DIR/f34f of=$TMP/f34f
3095 $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
3096 dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
3097 cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
3098 cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
3099 rm $TMP/f34f $TMP/f34fzero $DIR/f34f
3101 run_test 34f "read from a file with no objects until EOF ======="
3104 [ $PARALLEL == "yes" ] && skip "skip parallel run"
3106 dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE ||
3108 $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error "truncate failed"
3109 $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3110 error "Size of $DIR/$tfile not equal to $((TEST_34_SIZE / 2))"
3111 cancel_lru_locks osc
3112 $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
3113 error "wrong size after lock cancel"
3115 $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error "truncate failed"
3116 $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3117 error "expanding truncate failed"
3118 cancel_lru_locks osc
3119 $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
3120 error "wrong expanded size after lock cancel"
3122 run_test 34g "truncate long file ==============================="
3125 [ $PARALLEL == "yes" ] && skip "skip parallel run"
3130 dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error "dd failed"
3131 sync # Flush the cache so that multiop below does not block on cache
3132 # flush when getting the group lock
3133 $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
3136 # Since just timed wait is not good enough, let's do a sync write
3137 # that way we are sure enough time for a roundtrip + processing
3138 # passed + 2 seconds of extra margin.
3139 dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
3143 if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
3144 error "Multiop blocked on ftruncate, pid=$MULTIPID"
3148 local nsz=`stat -c %s $DIR/$tfile`
3149 [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
3151 run_test 34h "ftruncate file under grouplock should not block"
3154 cp /bin/sh $DIR/f35a
3156 chown $RUNAS_ID $DIR/f35a
3157 $RUNAS $DIR/f35a && error || true
3160 run_test 35a "exec file with mode 444 (should return and not leak)"
3164 utime $DIR/f36 || error "utime failed for MDS"
3166 run_test 36a "MDS utime check (mknod, utime)"
3170 utime $DIR/f36 || error "utime failed for OST"
3172 run_test 36b "OST utime check (open, utime)"
3177 chown $RUNAS_ID $DIR/d36
3178 $RUNAS utime $DIR/d36/f36 || error "utime failed for MDS as non-root"
3180 run_test 36c "non-root MDS utime check (mknod, utime)"
3183 [ ! -d $DIR/d36 ] && test_36c
3184 echo "" > $DIR/d36/f36
3185 $RUNAS utime $DIR/d36/f36 || error "utime failed for OST as non-root"
3187 run_test 36d "non-root OST utime check (open, utime)"
3190 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping"
3192 test_mkdir $DIR/$tdir
3193 touch $DIR/$tdir/$tfile
3194 $RUNAS utime $DIR/$tdir/$tfile &&
3195 error "utime worked, expected failure" || true
3197 run_test 36e "utime on non-owned file (should return error)"
3201 local LANG_SAVE=$LANG
3202 local LC_LANG_SAVE=$LC_LANG
3203 export LANG=C LC_LANG=C # for date language
3205 DATESTR="Dec 20 2000"
3206 test_mkdir $DIR/$tdir
3207 lctl set_param fail_loc=$fl
3209 cp /etc/hosts $DIR/$tdir/$tfile
3210 sync & # write RPC generated with "current" inode timestamp, but delayed
3212 touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
3213 LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
3214 cancel_lru_locks osc
3215 LS_AFTER="`ls -l $DIR/$tdir/$tfile`" # timestamp from OST object
3217 [ "$LS_BEFORE" != "$LS_AFTER" ] && \
3218 echo "BEFORE: $LS_BEFORE" && \
3219 echo "AFTER : $LS_AFTER" && \
3220 echo "WANT : $DATESTR" && \
3221 error "$DIR/$tdir/$tfile timestamps changed" || true
3223 export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
3227 [ $PARALLEL == "yes" ] && skip "skip parallel run"
3229 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3230 subr_36fh "0x80000214"
3232 run_test 36f "utime on file racing with OST BRW write =========="
3235 remote_ost_nodsh && skip "remote OST with nodsh"
3236 [ $PARALLEL == "yes" ] && skip "skip parallel run"
3242 test_mkdir $DIR/$tdir
3243 fmd_max_age=$(do_facet ost1 \
3244 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
3247 fmd_before=$(do_facet ost1 \
3248 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3249 touch $DIR/$tdir/$tfile
3250 sleep $((fmd_max_age + 12))
3251 fmd_after=$(do_facet ost1 \
3252 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3254 echo "fmd_before: $fmd_before"
3255 echo "fmd_after: $fmd_after"
3256 [[ $fmd_after -gt $fmd_before ]] &&
3257 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3258 error "fmd didn't expire after ping" || true
3260 run_test 36g "filter mod data cache expiry ====================="
3263 [ $PARALLEL == "yes" ] && skip "skip parallel run"
3265 #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3266 subr_36fh "0x80000227"
3268 run_test 36h "utime on file racing with OST BRW write =========="
3271 [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
3273 test_mkdir $DIR/$tdir
3274 $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3276 local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3277 local new_mtime=$((mtime + 200))
3279 #change Modify time of striped dir
3280 touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3281 error "change mtime failed"
3283 local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3285 [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3287 run_test 36i "change mtime on striped directory"
3289 # test_37 - duplicate with tests 32q 32r
3292 local file=$DIR/$tfile
3294 openfile -f O_DIRECTORY $file
3297 [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3298 [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3300 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3302 test_39a() { # was test_39
3304 touch $DIR/${tfile}2
3305 # ls -l $DIR/$tfile $DIR/${tfile}2
3306 # ls -lu $DIR/$tfile $DIR/${tfile}2
3307 # ls -lc $DIR/$tfile $DIR/${tfile}2
3309 $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3310 if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3312 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3314 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3316 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3317 error "O_TRUNC didn't change timestamps"
3320 run_test 39a "mtime changed on create"
3323 test_mkdir -c1 $DIR/$tdir
3324 cp -p /etc/passwd $DIR/$tdir/fopen
3325 cp -p /etc/passwd $DIR/$tdir/flink
3326 cp -p /etc/passwd $DIR/$tdir/funlink
3327 cp -p /etc/passwd $DIR/$tdir/frename
3328 ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3331 echo "aaaaaa" >> $DIR/$tdir/fopen
3332 echo "aaaaaa" >> $DIR/$tdir/flink
3333 echo "aaaaaa" >> $DIR/$tdir/funlink
3334 echo "aaaaaa" >> $DIR/$tdir/frename
3336 local open_new=`stat -c %Y $DIR/$tdir/fopen`
3337 local link_new=`stat -c %Y $DIR/$tdir/flink`
3338 local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3339 local rename_new=`stat -c %Y $DIR/$tdir/frename`
3341 cat $DIR/$tdir/fopen > /dev/null
3342 ln $DIR/$tdir/flink $DIR/$tdir/flink2
3343 rm -f $DIR/$tdir/funlink2
3344 mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3346 for (( i=0; i < 2; i++ )) ; do
3347 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3348 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3349 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3350 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3352 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3353 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3354 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3355 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3357 cancel_lru_locks osc
3358 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3361 run_test 39b "mtime change on open, link, unlink, rename ======"
3363 # this should be set to past
3364 TEST_39_MTIME=`date -d "1 year ago" +%s`
3370 local mtime0=`stat -c %Y $DIR1/$tfile`
3372 touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3373 local mtime1=`stat -c %Y $DIR1/$tfile`
3374 [ "$mtime1" = $TEST_39_MTIME ] || \
3375 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3378 echo hello >> $DIR1/$tfile
3380 local mtime2=`stat -c %Y $DIR1/$tfile`
3381 [ "$mtime2" -ge "$d1" ] && [ "