2 # -*- tab-width: 4; 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: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT=" 42a 42b 42c 42d 45 51d 68b $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT=" 76 $ALWAYS_EXCEPT"
20 SRCDIR=$(cd $(dirname $0); echo $PWD)
21 export PATH=$PATH:/sbin
25 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
26 CREATETEST=${CREATETEST:-createtest}
28 LFIND=${LFIND:-"$LFS find"}
29 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
31 MCREATE=${MCREATE:-mcreate}
32 OPENFILE=${OPENFILE:-openfile}
33 OPENUNLINK=${OPENUNLINK:-openunlink}
34 export MULTIOP=${MULTIOP:-multiop}
35 READS=${READS:-"reads"}
36 MUNLINK=${MUNLINK:-munlink}
37 SOCKETSERVER=${SOCKETSERVER:-socketserver}
38 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
39 MEMHOG=${MEMHOG:-memhog}
40 DIRECTIO=${DIRECTIO:-directio}
41 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
42 UMOUNT=${UMOUNT:-"umount -d"}
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/test-framework.sh
58 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
61 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b"
63 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
64 # bug number for skipped test: LU-1593 LU-2610 LU-2833 LU-1957 LU-2805
65 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h 40 48a 180 184c"
71 pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
72 cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
81 check_kernel_version() {
83 GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
85 patchless|patchless_client) return 0;;
86 *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
88 log "test needs at least kernel version $WANT_VER, running $GOT_VER"
92 check_swap_layouts_support()
94 $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
95 { skip "Does not support layout lock."; return 0; }
99 if [ "$ONLY" == "cleanup" ]; then
104 check_and_setup_lustre
109 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
110 awk '{gsub(/_UUID/,""); print $1}' | head -1)
111 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
112 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
113 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
114 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
115 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
116 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
118 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
119 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
120 rm -rf $DIR/[Rdfs][0-9]*
122 # $RUNAS_ID may get set incorrectly somewhere else
123 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
125 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
129 if [ "${ONLY}" = "MOUNT" ] ; then
130 echo "Lustre is up, please go on"
134 echo "preparing for tests involving mounts"
135 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
137 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
138 echo # add a newline after mke2fs.
142 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
143 lctl set_param debug=-1 2> /dev/null || true
146 $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
148 $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
150 run_test 0a "touch; rm ====================="
153 chmod 0755 $DIR || error "chmod 0755 $DIR failed"
154 $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
156 run_test 0b "chmod 0755 $DIR ============================="
159 $LCTL get_param mdc.*.import | grep "state: FULL" ||
160 error "import not FULL"
161 $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
164 run_test 0c "check import proc ============================="
167 test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
168 test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
169 test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
170 $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
173 $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
175 run_test 1 "mkdir; remkdir; rmdir =============================="
178 test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
179 touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
180 $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
182 $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
184 run_test 2 "mkdir; touch; rmdir; check file ===================="
187 test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
188 $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
189 touch $DIR/$tdir/$tfile
190 $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
192 $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
194 run_test 3 "mkdir; touch; rmdir; check dir ====================="
197 test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
198 test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
199 chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
200 $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
201 $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
203 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
206 touch $DIR/$tfile || error "touch $DIR/$tfile failed"
207 chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
208 $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
209 error "$tfile does not have perm 0666 or UID $UID"
210 $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
211 $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
212 error "$tfile should be 0666 and owned by UID $UID"
214 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
217 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
219 chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
220 $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
221 error "$tfile should be owned by UID $RUNAS_ID"
222 $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
223 $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
224 error "$tfile should be owned by UID $RUNAS_ID"
226 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
229 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
231 chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
232 $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
233 error "$tfile should be owned by GID $UID"
234 $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
235 $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
236 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
238 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
241 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
242 test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
243 chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
244 $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
245 chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
246 test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
247 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
248 error "$tdir/d/subdir should be GID $RUNAS_GID"
250 run_test 6g "Is new dir in sgid dir inheriting group?"
252 test_6h() { # bug 7331
253 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
254 touch $DIR/$tfile || error "touch failed"
255 chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
256 $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
257 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
258 $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
259 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
261 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
264 test_mkdir $DIR/$tdir
265 $MCREATE $DIR/$tdir/$tfile
266 chmod 0666 $DIR/$tdir/$tfile
267 $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
268 error "$tdir/$tfile should be mode 0666"
270 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
273 if [ ! -d $DIR/$tdir ]; then
276 $MCREATE $DIR/$tdir/$tfile
277 echo -n foo > $DIR/$tdir/$tfile
278 [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
279 $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
281 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
284 test_mkdir $DIR/$tdir
285 touch $DIR/$tdir/$tfile
286 chmod 0666 $DIR/$tdir/$tfile
287 $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
288 error "$tfile mode not 0666"
290 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
293 test_mkdir $DIR/$tdir
294 test_mkdir $DIR/$tdir/d2
295 test_mkdir $DIR/$tdir/d2/d3
296 $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
298 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
301 test_mkdir $DIR/$tdir
302 test_mkdir $DIR/$tdir/d2
303 touch $DIR/$tdir/d2/$tfile
304 $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
305 error "$tdir/d2/$tfile not a file"
307 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
310 test_mkdir $DIR/$tdir
311 test_mkdir $DIR/$tdir/d2
312 chmod 0666 $DIR/$tdir/d2
313 chmod 0705 $DIR/$tdir/d2
314 $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
315 error "$tdir/d2 mode not 0705"
317 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
320 test_mkdir $DIR/$tdir
321 touch $DIR/$tdir/$tfile
322 chmod 0666 $DIR/$tdir/$tfile
323 chmod 0654 $DIR/$tdir/$tfile
324 $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
325 error "$tdir/d2 mode not 0654"
327 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
330 test_mkdir $DIR/$tdir
331 dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
333 $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
334 error "$tdir/$tfile size not 0 after truncate"
336 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
339 test_mkdir $DIR/$tdir
340 touch $DIR/$tdir/$tfile
342 $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
344 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
347 test_mkdir $DIR/$tdir
348 touch $DIR/$tdir/$tfile
349 mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
350 $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
351 error "$tdir/${tfile_2} not a file after rename"
353 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
356 test_mkdir $DIR/$tdir
357 touch $DIR/$tdir/$tfile
358 rm -rf $DIR/$tdir/$tfile
359 $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
361 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
364 test_mkdir -p $DIR/$tdir
365 touch $DIR/$tdir/$tfile
366 ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
368 $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
369 error "$tdir/l-exist not a symlink"
370 $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
371 error "$tdir/l-exist not referencing a file"
372 rm -f $DIR/$tdir/l-exist
373 $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
375 run_test 17a "symlinks: create, remove (real) =================="
378 test_mkdir -p $DIR/$tdir
379 ln -s no-such-file $DIR/$tdir/l-dangle
381 $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
382 error "$tdir/l-dangle not referencing no-such-file"
383 $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
384 error "$tdir/l-dangle not referencing non-existent file"
385 rm -f $DIR/$tdir/l-dangle
386 $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
388 run_test 17b "symlinks: create, remove (dangling) =============="
390 test_17c() { # bug 3440 - don't save failed open RPC for replay
391 test_mkdir -p $DIR/$tdir
392 ln -s foo $DIR/$tdir/$tfile
393 cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
395 run_test 17c "symlinks: open dangling (should return error) ===="
398 test_mkdir -p $DIR/$tdir
399 ln -s foo $DIR/$tdir/$tfile
400 touch $DIR/$tdir/$tfile || error "creating to new symlink"
402 run_test 17d "symlinks: create dangling ========================"
405 test_mkdir -p $DIR/$tdir
406 local foo=$DIR/$tdir/$tfile
407 ln -s $foo $foo || error "create symlink failed"
408 ls -l $foo || error "ls -l failed"
409 ls $foo && error "ls not failed" || true
411 run_test 17e "symlinks: create recursive symlink (should return error) ===="
414 test_mkdir -p $DIR/d17f
415 ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
416 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
417 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
418 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
419 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/555
420 ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/d17f/666
423 run_test 17f "symlinks: long and very long symlink name ========================"
425 # str_repeat(S, N) generate a string that is string S repeated N times
430 while [ $((n -= 1)) -ge 0 ]; do
436 # Long symlinks and LU-2241
438 test_mkdir -p $DIR/$tdir
439 local TESTS="59 60 61 4094 4095"
441 # Fix for inode size boundary in 2.1.4
442 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
445 # Patch not applied to 2.2 or 2.3 branches
446 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
447 [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
451 local SYMNAME=$(str_repeat 'x' $i)
452 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
453 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
456 run_test 17g "symlinks: really long symlink name and inode boundaries"
458 test_17h() { #bug 17378
459 remote_mds_nodsh && skip "remote MDS with nodsh" && return
460 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
462 test_mkdir -p $DIR/$tdir
463 if [ $MDSCOUNT -gt 1 ]; then
464 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
468 $SETSTRIPE -c -1 $DIR/$tdir
469 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
470 do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
471 touch $DIR/$tdir/$tfile || true
473 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
475 test_17i() { #bug 20018
476 remote_mds_nodsh && skip "remote MDS with nodsh" && return
477 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
478 test_mkdir -p $DIR/$tdir
479 local foo=$DIR/$tdir/$tfile
481 if [ $MDSCOUNT -gt 1 ]; then
482 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
486 ln -s $foo $foo || error "create symlink failed"
487 #define OBD_FAIL_MDS_READLINK_EPROTO 0x143
488 do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
489 ls -l $foo && error "error not detected"
492 run_test 17i "don't panic on short symlink"
494 test_17k() { #bug 22301
495 rsync --help | grep -q xattr ||
496 skip_env "$(rsync --version| head -1) does not support xattrs"
497 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
498 test_mkdir -p $DIR/$tdir
499 test_mkdir -p $DIR/$tdir.new
500 touch $DIR/$tdir/$tfile
501 ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
502 rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
503 error "rsync failed with xattrs enabled"
505 run_test 17k "symlinks: rsync with xattrs enabled ========================="
507 test_17l() { # LU-279
509 touch $DIR/$tdir/$tfile
510 ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
511 for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
512 # -h to not follow symlinks. -m '' to list all the xattrs.
513 # grep to remove first line: '# file: $path'.
514 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
516 lgetxattr_size_check $path $xattr ||
517 error "lgetxattr_size_check $path $xattr failed"
521 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
525 local short_sym="0123456789"
526 local WDIR=$DIR/${tdir}m
533 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
534 [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
535 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
537 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
538 skip "only for ldiskfs MDT" && return 0
540 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
544 # create a long symlink file
545 for ((i = 0; i < 4; ++i)); do
546 long_sym=${long_sym}${long_sym}
549 echo "create 512 short and long symlink files under $WDIR"
550 for ((i = 0; i < 256; ++i)); do
551 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
552 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
558 wait_delete_completed
560 echo "recreate the 512 symlink files with a shorter string"
561 for ((i = 0; i < 512; ++i)); do
562 # rewrite the symlink file with a shorter string
563 ln -sf ${long_sym} $WDIR/long-$i
564 ln -sf ${short_sym} $WDIR/short-$i
567 mds_index=$($LFS getstripe -M $WDIR)
568 mds_index=$((mds_index+1))
569 devname=$(mdsdevname $mds_index)
570 cmd="$E2FSCK -fnvd $devname"
572 echo "stop and checking mds${mds_index}: $cmd"
573 # e2fsck should not return error
574 stop mds${mds_index} -f
575 do_facet mds${mds_index} $cmd || rc=$?
577 start mds${mds_index} $devname $MDS_MOUNT_OPTS
578 df $MOUNT > /dev/null 2>&1
579 [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
580 "short/long symlink MDT: rc=$rc"
583 run_test 17m "run e2fsck against MDT which contains short/long symlink"
585 check_fs_consistency_17n() {
591 for mdt_index in $(seq 1 $MDSCOUNT); do
592 devname=$(mdsdevname $mdt_index)
593 cmd="$E2FSCK -fnvd $devname"
595 echo "stop and checking mds${mdt_index}: $cmd"
596 # e2fsck should not return error
598 do_facet mds${mdt_index} $cmd || rc=$?
600 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
601 df $MOUNT > /dev/null 2>&1
602 [ $rc -ne 0 ] && break
610 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
611 [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
612 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
614 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
615 skip "only for ldiskfs MDT" && return 0
617 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
619 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
622 for ((i=0; i<10; i++)); do
623 $LFS mkdir -i 1 $DIR/$tdir/remote_dir_${i} ||
624 error "create remote dir error $i"
625 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
626 error "create files under remote dir failed $i"
629 check_fs_consistency_17n || error "e2fsck report error"
631 for ((i=0;i<10;i++)); do
632 rm -rf $DIR/$tdir/remote_dir_${i} ||
633 error "destroy remote dir error $i"
636 check_fs_consistency_17n || error "e2fsck report error"
638 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
641 local WDIR=$DIR/${tdir}o
647 mdt_index=$($LFS getstripe -M $WDIR)
648 mdt_index=$((mdt_index+1))
649 mdtdevname=$(mdsdevname $mdt_index)
653 start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
655 #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
656 do_facet mds${mdt_index} lctl set_param fail_loc=0x194
657 ls -l $WDIR/$tfile && rc=1
658 do_facet mds${mdt_index} lctl set_param fail_loc=0
659 [[ $rc -ne 0 ]] && error "stat file should fail"
662 run_test 17o "stat file with incompat LMA feature"
665 touch $DIR/f || error "Failed to touch $DIR/f: $?"
666 ls $DIR || error "Failed to ls $DIR: $?"
668 run_test 18 "touch .../f ; ls ... =============================="
674 $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
676 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
679 ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
681 run_test 19b "ls -l .../f19 (should return error) =============="
684 [ $RUNAS_ID -eq $UID ] &&
685 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
686 $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
688 run_test 19c "$RUNAS touch .../f19 (should return error) =="
691 cat $DIR/f19 && error || true
693 run_test 19d "cat .../f19 (should return error) =============="
705 $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
707 run_test 20 "touch .../f ; ls -l ... ==========================="
710 test_mkdir -p $DIR/$tdir
711 [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
712 ln -s dangle $DIR/$tdir/link
713 echo foo >> $DIR/$tdir/link
714 cat $DIR/$tdir/dangle
715 $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
716 $CHECKSTAT -f -t file $DIR/$tdir/link ||
717 error "$tdir/link not linked to a file"
719 run_test 21 "write to dangling link ============================"
723 test_mkdir -p $DIR/$tdir
724 chown $RUNAS_ID:$RUNAS_GID $WDIR
725 (cd $WDIR || error "cd $WDIR failed";
726 $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
728 ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
729 $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
730 $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
732 run_test 22 "unpack tar archive as non-root user ==============="
736 test_mkdir -p $DIR/$tdir
737 local file=$DIR/$tdir/$tfile
739 openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
740 openfile -f O_CREAT:O_EXCL $file &&
741 error "$file recreate succeeded" || true
743 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
745 test_23b() { # bug 18988
746 test_mkdir -p $DIR/$tdir
747 local file=$DIR/$tdir/$tfile
750 echo foo > $file || error "write filed"
751 echo bar >> $file || error "append filed"
752 $CHECKSTAT -s 8 $file || error "wrong size"
755 run_test 23b "O_APPEND check =========================="
759 echo '-- same directory rename'
760 test_mkdir $DIR/$tdir
761 touch $DIR/$tdir/$tfile.1
762 mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
763 $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
765 run_test 24a "rename file to non-existent target"
768 test_mkdir $DIR/$tdir
769 touch $DIR/$tdir/$tfile.{1,2}
770 mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
771 $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
772 $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
774 run_test 24b "rename file to existing target"
777 test_mkdir $DIR/$tdir
778 test_mkdir $DIR/$tdir/d$testnum.1
779 mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
780 $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
781 $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
783 run_test 24c "rename directory to non-existent target"
786 test_mkdir $DIR/$tdir
787 test_mkdir $DIR/$tdir/d$testnum.1
788 test_mkdir $DIR/$tdir/d$ttestnum.2
789 mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
790 $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
791 $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
793 run_test 24d "rename directory to existing target"
796 echo '-- cross directory renames --'
800 mv $DIR/R5a/f $DIR/R5b/g
801 $CHECKSTAT -a $DIR/R5a/f || error
802 $CHECKSTAT -t file $DIR/R5b/g || error
804 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
809 touch $DIR/R6a/f $DIR/R6b/g
810 mv $DIR/R6a/f $DIR/R6b/g
811 $CHECKSTAT -a $DIR/R6a/f || error
812 $CHECKSTAT -t file $DIR/R6b/g || error
814 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
819 test_mkdir $DIR/R7a/d
820 mv $DIR/R7a/d $DIR/R7b/e
821 $CHECKSTAT -a $DIR/R7a/d || error
822 $CHECKSTAT -t dir $DIR/R7b/e || error
824 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
829 test_mkdir $DIR/R8a/d
830 test_mkdir $DIR/R8b/e
831 mrename $DIR/R8a/d $DIR/R8b/e
832 $CHECKSTAT -a $DIR/R8a/d || error
833 $CHECKSTAT -t dir $DIR/R8b/e || error
835 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
838 echo "-- rename error cases"
842 mrename $DIR/R9/f $DIR/R9/a
843 $CHECKSTAT -t file $DIR/R9/f || error
844 $CHECKSTAT -t dir $DIR/R9/a || error
845 $CHECKSTAT -a $DIR/R9/a/f || error
847 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
851 mrename $DIR/R10/f $DIR/R10/g
852 $CHECKSTAT -t dir $DIR/R10 || error
853 $CHECKSTAT -a $DIR/R10/f || error
854 $CHECKSTAT -a $DIR/R10/g || error
856 run_test 24j "source does not exist ============================"
860 test_mkdir $DIR/R11a/d
862 mv $DIR/R11a/f $DIR/R11a/d
863 $CHECKSTAT -a $DIR/R11a/f || error
864 $CHECKSTAT -t file $DIR/R11a/d/f || error
866 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
868 # bug 2429 - rename foo foo foo creates invalid file
871 $MULTIOP $f OcNs || error
873 run_test 24l "Renaming a file to itself ========================"
877 $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
878 # on ext3 this does not remove either the source or target files
879 # though the "expected" operation would be to remove the source
880 $CHECKSTAT -t file ${f} || error "${f} missing"
881 $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
883 run_test 24m "Renaming a file to a hard link to itself ========="
887 # this stats the old file after it was renamed, so it should fail
891 $CHECKSTAT ${f}.rename
894 run_test 24n "Statting the old file after renaming (Posix rename 2)"
897 check_kernel_version 37 || return 0
898 test_mkdir -p $DIR/d24o
899 rename_many -s random -v -n 10 $DIR/d24o
901 run_test 24o "rename of files during htree split ==============="
906 DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
907 mrename $DIR/R12a $DIR/R12b
908 $CHECKSTAT -a $DIR/R12a || error
909 $CHECKSTAT -t dir $DIR/R12b || error
910 DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
911 [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
913 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
915 cleanup_multiop_pause() {
921 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
924 local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
925 multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
928 trap cleanup_multiop_pause EXIT
929 mrename $DIR/R13a $DIR/R13b
930 $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
931 $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
932 local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
933 [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
934 cleanup_multiop_pause
935 wait $MULTIPID || error "multiop close failed"
937 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
939 test_24r() { #bug 3789
941 test_mkdir $DIR/R14a/b
942 mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
943 $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
944 $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
946 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
950 test_mkdir $DIR/R15a/b
951 test_mkdir $DIR/R15a/b/c
952 mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
953 $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
954 $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
956 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
959 test_mkdir $DIR/R16a/b
960 test_mkdir $DIR/R16a/b/c
961 mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
962 $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
963 $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
965 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
967 test_24u() { # bug12192
969 $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
970 $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
972 run_test 24u "create stripe file"
978 simple_cleanup_common() {
981 wait_delete_completed
984 max_pages_per_rpc() {
985 $LCTL get_param -n mdc.*.max_pages_per_rpc | head -1
990 local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
991 [ $FREE_INODES -lt $NRFILES ] && \
992 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
995 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
996 trap simple_cleanup_common EXIT
999 createmany -m $DIR/$tdir/$tfile $NRFILES
1001 cancel_lru_locks mdc
1002 lctl set_param mdc.*.stats clear
1004 ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1006 # LU-5 large readdir
1007 # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1008 # 8 bytes for name(filename is mostly 5 in this test) +
1009 # 8 bytes for luda_type
1010 # take into account of overhead in lu_dirpage header and end mark in
1011 # each page, plus one in RPC_NUM calculation.
1013 RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1014 RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1015 mds_readpage=$(lctl get_param mdc.*MDT0000*.stats | \
1016 awk '/^mds_readpage/ {print $2}')
1017 [ $mds_readpage -gt $RPC_NUM ] && \
1018 error "large readdir doesn't take effect"
1020 simple_cleanup_common
1022 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1024 test_24w() { # bug21506
1026 dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1027 dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1028 dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1029 SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1030 [ "$SZ1" = "$SZ2" ] || \
1031 error "Error reading at the end of the file $tfile"
1033 run_test 24w "Reading a file larger than 4Gb"
1036 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1037 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1039 local remote_dir=$DIR/$tdir/remote_dir
1042 $LFS mkdir -i $MDTIDX $remote_dir ||
1043 error "create remote directory failed"
1045 mkdir -p $DIR/$tdir/src_dir
1046 touch $DIR/$tdir/src_file
1047 mkdir -p $remote_dir/tgt_dir
1048 touch $remote_dir/tgt_file
1050 mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1051 error "rename dir cross MDT works!"
1053 mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1054 error "rename file cross MDT works!"
1056 ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1057 error "ln file cross MDT should not work!"
1059 rm -rf $DIR/$tdir || error "Can not delete directories"
1061 run_test 24x "cross rename/link should be failed"
1064 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1065 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1067 local remote_dir=$DIR/$tdir/remote_dir
1070 $LFS mkdir -i $MDTIDX $remote_dir ||
1071 error "create remote directory failed"
1073 mkdir -p $remote_dir/src_dir
1074 touch $remote_dir/src_file
1075 mkdir -p $remote_dir/tgt_dir
1076 touch $remote_dir/tgt_file
1078 mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1079 error "rename subdir in the same remote dir failed!"
1081 mrename $remote_dir/src_file $remote_dir/tgt_file ||
1082 error "rename files in the same remote dir failed!"
1084 ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1085 error "link files in the same remote dir failed!"
1087 rm -rf $DIR/$tdir || error "Can not delete directories"
1089 run_test 24y "rename/link on the same dir should succeed"
1092 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1093 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1095 local remote_src=$DIR/$tdir/remote_dir
1096 local remote_tgt=$DIR/$tdir/remote_tgt
1099 $LFS mkdir -i $MDTIDX $remote_src ||
1100 error "create remote directory failed"
1102 $LFS mkdir -i $MDTIDX $remote_tgt ||
1103 error "create remote directory failed"
1105 mrename $remote_src $remote_tgt &&
1106 error "rename remote dirs should not work!"
1108 # If target dir does not exists, it should succeed
1110 mrename $remote_src $remote_tgt ||
1111 error "rename remote dirs(tgt dir does not exists) failed!"
1113 rm -rf $DIR/$tdir || error "Can not delete directories"
1115 run_test 24z "rename one remote dir to another remote dir should fail"
1118 echo '== symlink sanity ============================================='
1122 touch $DIR/s25/foo || error
1124 run_test 25a "create file in symlinked directory ==============="
1127 [ ! -d $DIR/d25 ] && test_25a
1128 $CHECKSTAT -t file $DIR/s25/foo || error
1130 run_test 25b "lookup file in symlinked directory ==============="
1134 test_mkdir $DIR/d26/d26-2
1135 ln -s d26/d26-2 $DIR/s26
1136 touch $DIR/s26/foo || error
1138 run_test 26a "multiple component symlink ======================="
1141 test_mkdir -p $DIR/d26b/d26-2
1142 ln -s d26b/d26-2/foo $DIR/s26-2
1143 touch $DIR/s26-2 || error
1145 run_test 26b "multiple component symlink at end of lookup ======"
1148 test_mkdir $DIR/d26.2
1149 touch $DIR/d26.2/foo
1150 ln -s d26.2 $DIR/s26.2-1
1151 ln -s s26.2-1 $DIR/s26.2-2
1152 ln -s s26.2-2 $DIR/s26.2-3
1153 chmod 0666 $DIR/s26.2-3/foo
1155 run_test 26c "chain of symlinks ================================"
1157 # recursive symlinks (bug 439)
1159 ln -s d26-3/foo $DIR/d26-3
1161 run_test 26d "create multiple component recursive symlink ======"
1164 [ ! -h $DIR/d26-3 ] && test_26d
1167 run_test 26e "unlink multiple component recursive symlink ======"
1169 # recursive symlinks (bug 7022)
1171 test_mkdir -p $DIR/$tdir
1172 test_mkdir $DIR/$tdir/$tfile || error "mkdir $DIR/$tdir/$tfile failed"
1173 cd $DIR/$tdir/$tfile || error "cd $DIR/$tdir/$tfile failed"
1174 test_mkdir -p lndir bar1 || error "mkdir lndir/bar1 failed"
1175 test_mkdir $DIR/$tdir/$tfile/$tfile || error "mkdir $tfile failed"
1176 cd $tfile || error "cd $tfile failed"
1177 ln -s .. dotdot || error "ln dotdot failed"
1178 ln -s dotdot/lndir lndir || error "ln lndir failed"
1179 cd $DIR/$tdir || error "cd $DIR/$tdir failed"
1180 output=`ls $tfile/$tfile/lndir/bar1`
1181 [ "$output" = bar1 ] && error "unexpected output"
1182 rm -r $tfile || error "rm $tfile failed"
1183 $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1185 run_test 26f "rm -r of a directory which has recursive symlink ="
1188 echo '== stripe sanity =============================================='
1189 test_mkdir -p $DIR/d27 || error "mkdir failed"
1191 $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1192 $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1194 log "== test_27a: write to one stripe file ========================="
1195 cp /etc/hosts $DIR/d27/f0 || error
1197 run_test 27a "one stripe file =================================="
1200 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1201 test_mkdir -p $DIR/d27
1202 $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1203 $GETSTRIPE -c $DIR/d27/f01
1204 [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1205 error "two-stripe file doesn't have two stripes"
1207 run_test 27b "create two stripe file"
1210 [ -f $DIR/d27/f01 ] || skip "test_27b not run" && return
1212 dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1214 run_test 27c "write to two stripe file"
1217 test_mkdir -p $DIR/d27
1218 $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1219 $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1220 dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1222 run_test 27d "create file with default settings ================"
1225 test_mkdir -p $DIR/d27
1226 $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1227 $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1228 $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1230 run_test 27e "setstripe existing file (should return error) ======"
1233 test_mkdir -p $DIR/d27
1234 $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1235 dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1236 $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1238 run_test 27f "setstripe with bad stripe size (should return error)"
1241 test_mkdir -p $DIR/d27
1242 $MCREATE $DIR/d27/fnone || error "mcreate failed"
1243 $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1244 error "$DIR/d27/fnone has object"
1246 run_test 27g "$GETSTRIPE with no objects"
1249 touch $DIR/d27/fsome || error "touch failed"
1250 [ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ] || error "missing objects"
1252 run_test 27i "$GETSTRIPE with some objects"
1255 test_mkdir -p $DIR/d27
1256 $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1258 run_test 27j "setstripe with bad stripe offset (should return error)"
1260 test_27k() { # bug 2844
1261 test_mkdir -p $DIR/d27
1263 LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1264 [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1265 $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1266 BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1267 [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1268 dd if=/dev/zero of=$FILE bs=4k count=1
1269 BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1270 [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "$BLKSIZE > $LL_MAX_BLKSIZE"
1272 run_test 27k "limit i_blksize for broken user apps ============="
1275 test_mkdir -p $DIR/d27
1276 mcreate $DIR/f27l || error "creating file"
1277 $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1278 error "setstripe should have failed" || true
1280 run_test 27l "check setstripe permissions (should return error)"
1283 [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1285 if [ $ORIGFREE -gt $MAXFREE ]; then
1286 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1289 trap simple_cleanup_common EXIT
1290 test_mkdir -p $DIR/$tdir
1291 $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1292 dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1293 error "dd should fill OST0"
1295 while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1297 [ $i -gt 256 ] && break
1300 touch $DIR/$tdir/f27m_$i
1301 [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1302 error "OST0 was full but new created file still use it"
1304 touch $DIR/$tdir/f27m_$i
1305 [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1306 error "OST0 was full but new created file still use it"
1307 simple_cleanup_common
1309 run_test 27m "create file while OST0 was full =================="
1312 local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1316 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1317 # if the OST isn't full anymore.
1319 local OSTIDX=${1:-""}
1321 local list=$(comma_list $(osts_nodes))
1322 [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1324 do_nodes $list lctl set_param fail_loc=0
1325 sync # initiate all OST_DESTROYs from MDS to OST
1329 exhaust_precreations() {
1332 local FAILIDX=${3:-$OSTIDX}
1334 test_mkdir -p $DIR/$tdir
1335 local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1336 echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1338 local OST=$(ostname_from_index $OSTIDX)
1339 local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1340 sed -e 's/_UUID$//;s/^.*-//')
1343 local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1344 local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1345 osc.$mdtosc_proc1.prealloc_last_id)
1346 local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1347 osc.$mdtosc_proc1.prealloc_next_id)
1349 local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1350 do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1352 test_mkdir -p $DIR/$tdir/${OST}
1353 $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1354 #define OBD_FAIL_OST_ENOSPC 0x215
1355 do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1356 do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1357 echo "Creating to objid $last_id on ost $OST..."
1358 createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1359 do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1360 do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1364 exhaust_all_precreations() {
1366 for (( i=0; i < OSTCOUNT; i++ )) ; do
1367 exhaust_precreations $i $1 -1
1372 [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1373 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1374 remote_mds_nodsh && skip "remote MDS with nodsh" && return
1375 remote_ost_nodsh && skip "remote OST with nodsh" && return
1378 rm -f $DIR/$tdir/$tfile
1379 exhaust_precreations 0 0x80000215
1380 $SETSTRIPE -c -1 $DIR/$tdir
1381 touch $DIR/$tdir/$tfile || error
1382 $GETSTRIPE $DIR/$tdir/$tfile
1385 run_test 27n "create file with some full OSTs =================="
1388 [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1389 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1390 remote_mds_nodsh && skip "remote MDS with nodsh" && return
1391 remote_ost_nodsh && skip "remote OST with nodsh" && return
1394 rm -f $DIR/$tdir/$tfile
1395 exhaust_all_precreations 0x215
1397 touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1402 run_test 27o "create file with all full OSTs (should error) ===="
1405 [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1406 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1407 remote_mds_nodsh && skip "remote MDS with nodsh" && return
1408 remote_ost_nodsh && skip "remote OST with nodsh" && return
1411 rm -f $DIR/$tdir/$tfile
1412 test_mkdir -p $DIR/$tdir
1414 $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1415 $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1416 $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1418 exhaust_precreations 0 0x80000215
1419 echo foo >> $DIR/$tdir/$tfile || error "append failed"
1420 $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1421 $GETSTRIPE $DIR/$tdir/$tfile
1425 run_test 27p "append to a truncated file with some full OSTs ==="
1428 [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1429 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1430 remote_mds_nodsh && skip "remote MDS with nodsh" && return
1431 remote_ost_nodsh && skip "remote OST with nodsh" && return
1434 rm -f $DIR/$tdir/$tfile
1436 test_mkdir -p $DIR/$tdir
1437 $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1438 $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1439 $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1441 exhaust_all_precreations 0x215
1443 echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1444 $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1448 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1451 [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1452 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1453 remote_mds_nodsh && skip "remote MDS with nodsh" && return
1454 remote_ost_nodsh && skip "remote OST with nodsh" && return
1457 rm -f $DIR/$tdir/$tfile
1458 exhaust_precreations 0 0x80000215
1460 $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1464 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1466 test_27s() { # bug 10725
1467 test_mkdir -p $DIR/$tdir
1468 local stripe_size=$((4096 * 1024 * 1024)) # 2^32
1469 local stripe_count=0
1470 [ $OSTCOUNT -eq 1 ] || stripe_count=2
1471 $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1472 error "stripe width >= 2^32 succeeded" || true
1475 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1477 test_27t() { # bug 10864
1482 $WLFS getstripe $tfile
1485 run_test 27t "check that utils parse path correctly"
1487 test_27u() { # bug 4900
1488 [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1489 remote_mds_nodsh && skip "remote MDS with nodsh" && return
1491 local list=$(comma_list $(mdts_nodes))
1493 #define OBD_FAIL_MDS_OSC_PRECREATE 0x139
1494 do_nodes $list $LCTL set_param fail_loc=0x139
1495 test_mkdir -p $DIR/$tdir
1497 createmany -o $DIR/$tdir/t- 1000
1498 do_nodes $list $LCTL set_param fail_loc=0
1500 TLOG=$DIR/$tfile.getstripe
1501 $GETSTRIPE $DIR/$tdir > $TLOG
1502 OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1503 unlinkmany $DIR/$tdir/t- 1000
1504 [ $OBJS -gt 0 ] && \
1505 error "$OBJS objects created on OST-0. See $TLOG" || pass
1507 run_test 27u "skip object creation on OSC w/o objects =========="
1509 test_27v() { # bug 4900
1510 [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1511 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1512 remote_mds_nodsh && skip "remote MDS with nodsh" && return
1513 remote_ost_nodsh && skip "remote OST with nodsh" && return
1515 exhaust_all_precreations 0x215
1518 test_mkdir -p $DIR/$tdir
1519 $SETSTRIPE -c 1 $DIR/$tdir # 1 stripe / file
1521 touch $DIR/$tdir/$tfile
1522 #define OBD_FAIL_TGT_DELAY_PRECREATE 0x705
1524 for (( i=1; i < OSTCOUNT; i++ )); do
1525 do_facet ost$i lctl set_param fail_loc=0x705
1527 local START=`date +%s`
1528 createmany -o $DIR/$tdir/$tfile 32
1530 local FINISH=`date +%s`
1531 local TIMEOUT=`lctl get_param -n timeout`
1532 local PROCESS=$((FINISH - START))
1533 [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1534 error "$FINISH - $START >= $TIMEOUT / 2"
1535 sleep $((TIMEOUT / 2 - PROCESS))
1538 run_test 27v "skip object creation on slow OST ================="
1540 test_27w() { # bug 10997
1541 test_mkdir -p $DIR/$tdir || error "mkdir failed"
1542 $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1543 [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1544 error "stripe size $size != 65536" || true
1545 [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1546 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1548 run_test 27w "check $SETSTRIPE -S option"
1551 [ "$OSTCOUNT" -lt "2" ] &&
1552 skip_env "skipping multiple stripe count/offset test" && return
1554 test_mkdir -p $DIR/$tdir || error "mkdir failed"
1555 for i in $(seq 1 $OSTCOUNT); do
1557 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1558 error "setstripe -c $i -i $offset failed"
1559 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1560 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1561 [ $count -ne $i ] && error "stripe count $count != $i" || true
1562 [ $index -ne $offset ] &&
1563 error "stripe offset $index != $offset" || true
1566 run_test 27wa "check $SETSTRIPE -c -i options"
1569 remote_ost_nodsh && skip "remote OST with nodsh" && return
1570 [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1571 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1572 OFFSET=$(($OSTCOUNT - 1))
1574 local OST=$(ostname_from_index $OSTIDX)
1576 test_mkdir -p $DIR/$tdir
1577 $SETSTRIPE -c 1 $DIR/$tdir # 1 stripe per file
1578 do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1580 createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1581 for i in `seq 0 $OFFSET`; do
1582 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1583 error "OST0 was degraded but new created file still use it"
1585 do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1587 run_test 27x "create files while OST0 is degraded"
1590 [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1591 remote_mds_nodsh && skip "remote MDS with nodsh" && return
1592 remote_ost_nodsh && skip "remote OST with nodsh" && return
1593 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1595 local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1596 local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1597 osc.$mdtosc.prealloc_last_id)
1598 local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1599 osc.$mdtosc.prealloc_next_id)
1600 local fcount=$((last_id - next_id))
1601 [ $fcount -eq 0 ] && skip "not enough space on OST0" && return
1602 [ $fcount -gt $OSTCOUNT ] && fcount=$OSTCOUNT
1604 local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1605 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1606 local OST_DEACTIVE_IDX=-1
1611 for OSC in $MDS_OSCS; do
1612 OST=$(osc_to_ost $OSC)
1613 OSTIDX=$(index_from_ostuuid $OST)
1614 if [ $OST_DEACTIVE_IDX == -1 ]; then
1615 OST_DEACTIVE_IDX=$OSTIDX
1617 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1618 echo $OSC "is Deactivated:"
1619 do_facet $SINGLEMDS lctl --device %$OSC deactivate
1623 OSTIDX=$(index_from_ostuuid $OST)
1625 $SETSTRIPE -c 1 $DIR/$tdir # 1 stripe / file
1627 for OSC in $MDS_OSCS; do
1628 OST=$(osc_to_ost $OSC)
1629 OSTIDX=$(index_from_ostuuid $OST)
1630 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1631 echo $OST "is degraded:"
1632 do_facet ost$((OSTIDX+1)) lctl set_param -n \
1633 obdfilter.$OST.degraded=1
1638 createmany -o $DIR/$tdir/$tfile $fcount
1640 for OSC in $MDS_OSCS; do
1641 OST=$(osc_to_ost $OSC)
1642 OSTIDX=$(index_from_ostuuid $OST)
1643 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1644 echo $OST "is recovered from degraded:"
1645 do_facet ost$((OSTIDX+1)) lctl set_param -n \
1646 obdfilter.$OST.degraded=0
1648 do_facet $SINGLEMDS lctl --device %$OSC activate
1652 # all osp devices get activated, hence -1 stripe count restored
1655 # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1656 # devices get activated.
1658 $SETSTRIPE -c -1 $DIR/$tfile
1659 stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1661 [ $stripecnt -ne $OSTCOUNT ] &&
1662 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1665 run_test 27y "create files while OST0 is degraded and the rest inactive"
1671 lmm_count=$($GETSTRIPE -c $1)
1672 lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1673 lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1675 local old_ifs="$IFS"
1677 fid=($($LFS path2fid $1))
1680 log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1681 log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1683 # compare lmm_seq and lu_fid->f_seq
1684 [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1685 # compare lmm_object_id and lu_fid->oid
1686 [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1688 # check the trusted.fid attribute of the OST objects of the file
1689 local have_obdidx=false
1691 $GETSTRIPE $1 | while read obdidx oid hex seq; do
1692 # skip lines up to and including "obdidx"
1693 [ -z "$obdidx" ] && break
1694 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1695 $have_obdidx || continue
1697 local ost=$((obdidx + 1))
1698 local dev=$(ostdevname $ost)
1701 if [ $(facet_fstype ost$ost) != ldiskfs ]; then
1702 echo "Currently only works with ldiskfs-based OSTs"
1706 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1708 #don't unmount/remount the OSTs if we don't need to do that
1709 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1710 # update too, until that use mount/ll_decode_filter_fid/mount
1711 local dir=$(facet_mntpt ost$ost)
1712 local opts=${OST_MOUNT_OPTS}
1714 if ! do_facet ost$ost test -b ${dev}; then
1715 opts=$(csa_add "$opts" -o loop)
1719 do_facet ost$ost mount -t $(facet_fstype ost$ost) $opts $dev $dir ||
1720 { error "mounting $dev as $FSTYPE failed"; return 3; }
1722 seq=$(echo $seq | sed -e "s/^0x//g")
1723 if [ $seq == 0 ]; then
1724 oid_hex=$(echo $oid)
1726 oid_hex=$(echo $hex | sed -e "s/^0x//g")
1728 local obj_file=$(do_facet ost$ost find $dir/O/$seq -name $oid_hex)
1729 local ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID $obj_file)
1730 do_facet ost$ost umount -d $dir
1731 start ost$ost $dev $OST_MOUNT_OPTS
1733 # re-enable when debugfs will understand new filter_fid
1734 #local ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1735 # $dev 2>/dev/null" | grep "parent=")
1737 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1739 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1741 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1742 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1743 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1744 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1745 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1746 local ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1748 # compare lmm_seq and filter_fid->ff_parent.f_seq
1749 [ $ff_pseq = $lmm_seq ] ||
1750 error "FF parent SEQ $ff_pseq != $lmm_seq"
1751 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1752 [ $ff_poid = $lmm_oid ] ||
1753 error "FF parent OID $ff_poid != $lmm_oid"
1754 [ $ff_pstripe = $stripe_nr ] ||
1755 error "FF stripe $ff_pstripe != $stripe_nr"
1757 stripe_nr=$((stripe_nr + 1))
1762 remote_ost_nodsh && skip "remote OST with nodsh" && return
1763 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1764 test_mkdir -p $DIR/$tdir
1766 $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1767 { error "setstripe -c -1 failed"; return 1; }
1768 # We need to send a write to every object to get parent FID info set.
1769 # This _should_ also work for setattr, but does not currently.
1770 # touch $DIR/$tdir/$tfile-1 ||
1771 dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1772 { error "dd $tfile-1 failed"; return 2; }
1773 $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1774 { error "setstripe -c -1 failed"; return 3; }
1775 dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1776 { error "dd $tfile-2 failed"; return 4; }
1778 # make sure write RPCs have been sent to OSTs
1781 check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1782 check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1784 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1786 test_27A() { # b=19102
1787 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1788 local restore_size=$($GETSTRIPE -S $MOUNT)
1789 local restore_count=$($GETSTRIPE -c $MOUNT)
1790 local restore_offset=$($GETSTRIPE -i $MOUNT)
1791 $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1792 local default_size=$($GETSTRIPE -S $MOUNT)
1793 local default_count=$($GETSTRIPE -c $MOUNT)
1794 local default_offset=$($GETSTRIPE -i $MOUNT)
1795 local dsize=$((1024 * 1024))
1796 [ $default_size -eq $dsize ] ||
1797 error "stripe size $default_size != $dsize"
1798 [ $default_count -eq 1 ] || error "stripe count $default_count != 1"
1799 [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1800 $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1802 run_test 27A "check filesystem-wide default LOV EA values"
1804 test_27B() { # LU-2523
1805 test_mkdir -p $DIR/$tdir
1806 rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1808 # open f1 with O_LOV_DELAY_CREATE
1810 # call setstripe ioctl on open file descriptor for f1
1812 multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1816 # open f1 with O_LOV_DELAY_CREATE
1818 # call setstripe ioctl on open file descriptor for f1
1820 multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1822 # Allow multiop to fail in imitation of NFS's busted semantics.
1825 run_test 27B "call setstripe on open unlinked file/rename victim"
1827 test_27C() { #LU-2871
1828 [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1836 test_mkdir -p $DIR/$tdir
1838 for i in $(seq 0 $((OSTCOUNT - 1))); do
1839 # set stripe across all OSTs starting from OST$i
1840 $SETSTRIPE -i $i -c -1 $tfile$i
1841 # get striping information
1842 ost_idx=($($GETSTRIPE $tfile$i |
1843 tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1847 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1848 error "${#ost_idx[@]} != $OSTCOUNT"
1850 for index in $(seq 0 $((OSTCOUNT - 1))); do
1852 for j in $(echo ${ost_idx[@]}); do
1853 if [ $index -eq $j ]; then
1859 error "Can not find $index in ${ost_idx[@]}"
1863 run_test 27C "check full striping across all OSTs"
1865 # createtest also checks that device nodes are created and
1866 # then visible correctly (#2091)
1867 test_28() { # bug 2091
1869 $CREATETEST $DIR/d28/ct || error
1871 run_test 28 "create/mknod/mkdir with bad file types ============"
1874 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1875 cancel_lru_locks mdc
1881 declare -i LOCKCOUNTORIG=0
1882 for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1883 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1885 [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1887 declare -i LOCKUNUSEDCOUNTORIG=0
1888 for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1889 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1896 declare -i LOCKCOUNTCURRENT=0
1897 for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1898 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1901 declare -i LOCKUNUSEDCOUNTCURRENT=0
1902 for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1903 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1906 if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1907 lctl set_param -n ldlm.dump_namespaces ""
1908 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1909 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1910 log "dumped log to $TMP/test_29.dk (bug 5793)"
1913 if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1914 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1915 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1916 log "dumped log to $TMP/test_29.dk (bug 5793)"
1920 run_test 29 "IT_GETATTR regression ============================"
1922 test_30a() { # was test_30
1923 cp `which ls` $DIR || cp /bin/ls $DIR
1927 run_test 30a "execute binary from Lustre (execve) =============="
1930 cp `which ls` $DIR || cp /bin/ls $DIR
1932 $RUNAS $DIR/ls / || error
1935 run_test 30b "execute binary from Lustre as non-root ==========="
1937 test_30c() { # b=22376
1938 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1939 cp `which ls` $DIR || cp /bin/ls $DIR
1941 cancel_lru_locks mdc
1942 cancel_lru_locks osc
1943 $RUNAS $DIR/ls / || error
1946 run_test 30c "execute binary from Lustre without read perms ===="
1949 $OPENUNLINK $DIR/f31 $DIR/f31 || error
1950 $CHECKSTAT -a $DIR/f31 || error
1952 run_test 31a "open-unlink file =================================="
1955 touch $DIR/f31 || error
1956 ln $DIR/f31 $DIR/f31b || error
1957 $MULTIOP $DIR/f31b Ouc || error
1958 $CHECKSTAT -t file $DIR/f31 || error
1960 run_test 31b "unlink file with multiple links while open ======="
1963 touch $DIR/f31 || error
1964 ln $DIR/f31 $DIR/f31c || error
1965 multiop_bg_pause $DIR/f31 O_uc || return 1
1967 $MULTIOP $DIR/f31c Ouc
1968 kill -USR1 $MULTIPID
1971 run_test 31c "open-unlink file with multiple links ============="
1974 opendirunlink $DIR/d31d $DIR/d31d || error
1975 $CHECKSTAT -a $DIR/d31d || error
1977 run_test 31d "remove of open directory ========================="
1979 test_31e() { # bug 2904
1980 check_kernel_version 34 || return 0
1981 openfilleddirunlink $DIR/d31e || error
1983 run_test 31e "remove of open non-empty directory ==============="
1985 test_31f() { # bug 4554
1986 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1988 test_mkdir $DIR/d31f
1989 $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
1990 cp /etc/hosts $DIR/d31f
1992 $GETSTRIPE $DIR/d31f/hosts
1993 multiop_bg_pause $DIR/d31f D_c || return 1
1996 rm -rv $DIR/d31f || error "first of $DIR/d31f"
1997 test_mkdir $DIR/d31f
1998 $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
1999 cp /etc/hosts $DIR/d31f
2001 $GETSTRIPE $DIR/d31f/hosts
2002 multiop_bg_pause $DIR/d31f D_c || return 1
2005 kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2006 wait $MULTIPID || error "first opendir $MULTIPID failed"
2010 kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2011 wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2014 run_test 31f "remove of open directory with open-unlink file ==="
2017 echo "-- cross directory link --"
2018 test_mkdir $DIR/d31ga
2019 test_mkdir $DIR/d31gb
2021 ln $DIR/d31ga/f $DIR/d31gb/g
2022 $CHECKSTAT -t file $DIR/d31ga/f || error "source"
2023 [ `stat -c%h $DIR/d31ga/f` == '2' ] || error "source nlink"
2024 $CHECKSTAT -t file $DIR/d31gb/g || error "target"
2025 [ `stat -c%h $DIR/d31gb/g` == '2' ] || error "target nlink"
2027 run_test 31g "cross directory link==============="
2030 echo "-- cross directory link --"
2031 test_mkdir $DIR/d31h
2032 test_mkdir $DIR/d31h/dir
2034 ln $DIR/d31h/f $DIR/d31h/dir/g
2035 $CHECKSTAT -t file $DIR/d31h/f || error "source"
2036 [ `stat -c%h $DIR/d31h/f` == '2' ] || error "source nlink"
2037 $CHECKSTAT -t file $DIR/d31h/dir/g || error "target"
2038 [ `stat -c%h $DIR/d31h/dir/g` == '2' ] || error "target nlink"
2040 run_test 31h "cross directory link under child==============="
2043 echo "-- cross directory link --"
2044 test_mkdir $DIR/d31i
2045 test_mkdir $DIR/d31i/dir
2046 touch $DIR/d31i/dir/f
2047 ln $DIR/d31i/dir/f $DIR/d31i/g
2048 $CHECKSTAT -t file $DIR/d31i/dir/f || error "source"
2049 [ `stat -c%h $DIR/d31i/dir/f` == '2' ] || error "source nlink"
2050 $CHECKSTAT -t file $DIR/d31i/g || error "target"
2051 [ `stat -c%h $DIR/d31i/g` == '2' ] || error "target nlink"
2053 run_test 31i "cross directory link under parent==============="
2057 test_mkdir $DIR/d31j
2058 test_mkdir $DIR/d31j/dir1
2059 ln $DIR/d31j/dir1 $DIR/d31j/dir2 && error "ln for dir"
2060 link $DIR/d31j/dir1 $DIR/d31j/dir3 && error "link for dir"
2061 mlink $DIR/d31j/dir1 $DIR/d31j/dir4 && error "mlink for dir"
2062 mlink $DIR/d31j/dir1 $DIR/d31j/dir1 && error "mlink to the same dir"
2065 run_test 31j "link for directory==============="
2069 test_mkdir $DIR/d31k
2071 touch $DIR/d31k/exist
2072 mlink $DIR/d31k/s $DIR/d31k/t || error "mlink"
2073 mlink $DIR/d31k/s $DIR/d31k/exist && error "mlink to exist file"
2074 mlink $DIR/d31k/s $DIR/d31k/s && error "mlink to the same file"
2075 mlink $DIR/d31k/s $DIR/d31k && error "mlink to parent dir"
2076 mlink $DIR/d31k $DIR/d31k/s && error "mlink parent dir to target"
2077 mlink $DIR/d31k/not-exist $DIR/d31k/foo && error "mlink non-existing to new"
2078 mlink $DIR/d31k/not-exist $DIR/d31k/s && error "mlink non-existing to exist"
2081 run_test 31k "link to file: the same, non-existing, dir==============="
2084 test_mkdir $DIR/d31m
2086 test_mkdir $DIR/d31m2
2087 touch $DIR/d31m2/exist
2088 mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2089 mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2090 mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2091 mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2092 mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2093 mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2096 run_test 31m "link to file: the same, non-existing, dir==============="
2099 [ -e /proc/self/fd/173 ] && echo "skipping, fd 173 is in use" && return
2100 touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2101 nlink=$(stat --format=%h $DIR/$tfile)
2102 [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2103 exec 173<$DIR/$tfile
2104 trap "exec 173<&-" EXIT
2105 nlink=$(stat --dereference --format=%h /proc/self/fd/173)
2106 [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2107 rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2108 nlink=$(stat --dereference --format=%h /proc/self/fd/173)
2109 [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2112 run_test 31n "check link count of unlinked file"
2115 local TEMPNAME=$(mktemp $1_XXXXXX)
2116 mlink $TEMPNAME $1 2> /dev/null &&
2117 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2121 test_31o() { # LU-2901
2123 for LOOP in $(seq 100); do
2124 rm -f $DIR/$tdir/$tfile*
2125 for THREAD in $(seq 8); do
2126 link_one $DIR/$tdir/$tfile.$LOOP &
2129 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2130 [ $LINKS -gt 1 ] && ls $DIR/$tdir &&
2131 error "$LINKS duplicate links to $tfile.$LOOP" &&
2135 run_test 31o "duplicate hard links with same filename"
2137 cleanup_test32_mount() {
2139 $UMOUNT $DIR/$tdir/ext2-mountpoint
2143 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2144 echo "== more mountpoints and symlinks ================="
2145 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2146 trap cleanup_test32_mount EXIT
2147 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2148 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2149 $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2150 cleanup_test32_mount
2152 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2155 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2156 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2157 trap cleanup_test32_mount EXIT
2158 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2159 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2160 ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2161 cleanup_test32_mount
2163 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2166 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2167 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2168 trap cleanup_test32_mount EXIT
2169 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2170 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2171 test_mkdir -p $DIR/$tdir/d2/test_dir
2172 $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2173 cleanup_test32_mount
2175 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2178 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2179 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2180 trap cleanup_test32_mount EXIT
2181 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2182 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2183 test_mkdir -p $DIR/$tdir/d2/test_dir
2184 ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2185 cleanup_test32_mount
2187 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2190 [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2191 test_mkdir -p $DIR/d32e/tmp
2192 TMP_DIR=$DIR/d32e/tmp
2193 ln -s $DIR/d32e $TMP_DIR/symlink11
2194 ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2195 $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2196 $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2198 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2201 [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2202 test_mkdir -p $DIR/d32f/tmp
2203 TMP_DIR=$DIR/d32f/tmp
2204 ln -s $DIR/d32f $TMP_DIR/symlink11
2205 ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2206 ls $DIR/d32f/tmp/symlink11 || error
2207 ls $DIR/d32f/symlink01 || error
2209 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2212 TMP_DIR=$DIR/$tdir/tmp
2213 test_mkdir -p $DIR/$tdir/tmp
2214 test_mkdir $DIR/${tdir}2
2215 ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2216 ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2217 $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2218 $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2219 $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2220 $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2222 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2225 rm -fr $DIR/$tdir $DIR/${tdir}2
2226 TMP_DIR=$DIR/$tdir/tmp
2227 test_mkdir -p $DIR/$tdir/tmp
2228 test_mkdir $DIR/${tdir}2
2229 ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2230 ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2231 ls $TMP_DIR/symlink12 || error
2232 ls $DIR/$tdir/symlink02 || error
2234 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2237 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2238 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2239 trap cleanup_test32_mount EXIT
2240 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2241 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2242 touch $DIR/$tdir/test_file
2243 $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2244 cleanup_test32_mount
2246 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2249 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2250 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2251 trap cleanup_test32_mount EXIT
2252 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2253 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2254 touch $DIR/$tdir/test_file
2255 cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2256 cleanup_test32_mount
2258 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2261 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2263 trap cleanup_test32_mount EXIT
2264 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2265 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2266 test_mkdir -p $DIR/$tdir/d2
2267 touch $DIR/$tdir/d2/test_file || error
2268 $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2269 cleanup_test32_mount
2271 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2274 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2276 trap cleanup_test32_mount EXIT
2277 test_mkdir -p $DIR/$tdir/ext2-mountpoint
2278 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2279 test_mkdir -p $DIR/$tdir/d2
2280 touch $DIR/$tdir/d2/test_file
2281 cat $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2282 cleanup_test32_mount
2284 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2288 test_mkdir -p $DIR/d32m/tmp
2289 TMP_DIR=$DIR/d32m/tmp
2290 ln -s $DIR $TMP_DIR/symlink11
2291 ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2292 $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2293 $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2295 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2299 test_mkdir -p $DIR/d32n/tmp
2300 TMP_DIR=$DIR/d32n/tmp
2301 ln -s $DIR $TMP_DIR/symlink11
2302 ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2303 ls -l $DIR/d32n/tmp/symlink11 || error
2304 ls -l $DIR/d32n/symlink01 || error
2306 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2309 rm -fr $DIR/d32o $DIR/$tfile
2311 test_mkdir -p $DIR/d32o/tmp
2312 TMP_DIR=$DIR/d32o/tmp
2313 ln -s $DIR/$tfile $TMP_DIR/symlink12
2314 ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2315 $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2316 $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2317 $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2318 $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2320 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2330 test_mkdir -p $DIR/d32p/tmp
2332 TMP_DIR=$DIR/d32p/tmp
2334 ln -s $DIR/$tfile $TMP_DIR/symlink12
2336 ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2338 cat $DIR/d32p/tmp/symlink12 || error
2340 cat $DIR/d32p/symlink02 || error
2343 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2345 cleanup_testdir_mount() {
2351 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2352 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2353 trap cleanup_testdir_mount EXIT
2354 test_mkdir -p $DIR/$tdir
2355 touch $DIR/$tdir/under_the_mount
2356 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2357 ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2358 cleanup_testdir_mount
2360 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2363 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2364 [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2365 trap cleanup_testdir_mount EXIT
2366 test_mkdir -p $DIR/$tdir
2367 touch $DIR/$tdir/under_the_mount
2368 mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2369 ls $DIR/$tdir | grep -q under_the_mount && error || true
2370 cleanup_testdir_mount
2372 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2377 chmod 444 $DIR/$tfile
2378 chown $RUNAS_ID $DIR/$tfile
2380 $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2383 run_test 33aa "write file with mode 444 (should return error) ===="
2387 test_mkdir -p $DIR/d33
2388 chown $RUNAS_ID $DIR/d33
2389 $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2390 $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2391 error "open RDWR" || true
2393 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2397 test_mkdir -p $DIR/d33
2398 chown $RUNAS_ID $DIR/d33
2399 $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2401 run_test 33b "test open file with malformed flags (No panic and return error)"
2404 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2410 remote_ost_nodsh && skip "remote OST with nodsh" && return
2413 test_mkdir -p $DIR/d33
2414 # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2417 for ostnum in $(seq $OSTCOUNT); do
2418 # test-framework's OST numbering is one-based, while Lustre's
2420 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2421 # Parsing llobdstat's output sucks; we could grep the /proc
2422 # path, but that's likely to not be as portable as using the
2423 # llobdstat utility. So we parse lctl output instead.
2424 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2425 obdfilter/$ostname/stats |
2426 awk '/^write_bytes/ {print $7}' )
2427 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2428 if (( ${write_bytes:-0} > 0 ))
2435 $all_zeros || return 0
2438 echo foo > $DIR/d33/bar
2442 # Total up write_bytes after writing. We'd better find non-zeros.
2443 for ostnum in $(seq $OSTCOUNT); do
2444 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2445 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2446 obdfilter/$ostname/stats |
2447 awk '/^write_bytes/ {print $7}' )
2448 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2449 if (( ${write_bytes:-0} > 0 ))
2458 for ostnum in $(seq $OSTCOUNT); do
2459 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2460 echo "Check that write_bytes is present in obdfilter/*/stats:"
2461 do_facet ost$ostnum lctl get_param -n \
2462 obdfilter/$ostname/stats
2464 error "OST not keeping write_bytes stats (b22312)"
2467 run_test 33c "test llobdstat and write_bytes"
2470 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2471 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2473 local remote_dir=$DIR/$tdir/remote_dir
2476 $LFS mkdir -i $MDTIDX $remote_dir ||
2477 error "create remote directory failed"
2479 touch $remote_dir/$tfile
2480 chmod 444 $remote_dir/$tfile
2481 chown $RUNAS_ID $remote_dir/$tfile
2483 $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2485 chown $RUNAS_ID $remote_dir
2486 $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2487 error "create" || true
2488 $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2489 error "open RDWR" || true
2490 $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2491 error "create" || true
2493 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2495 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2498 $MCREATE $DIR/f34 || error
2499 $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2500 $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2501 $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2502 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2504 run_test 34a "truncate file that has not been opened ==========="
2507 [ ! -f $DIR/f34 ] && test_34a
2508 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2509 $OPENFILE -f O_RDONLY $DIR/f34
2510 $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2511 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2513 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2516 [ ! -f $DIR/f34 ] && test_34a
2517 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2518 $OPENFILE -f O_RDWR $DIR/f34
2519 $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2520 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2522 run_test 34c "O_RDWR opening file-with-size works =============="
2525 [ ! -f $DIR/f34 ] && test_34a
2526 dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2527 $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2530 run_test 34d "write to sparse file ============================="
2534 $MCREATE $DIR/f34e || error
2535 $TRUNCATE $DIR/f34e 1000 || error
2536 $CHECKSTAT -s 1000 $DIR/f34e || error
2537 $OPENFILE -f O_RDWR $DIR/f34e
2538 $CHECKSTAT -s 1000 $DIR/f34e || error
2540 run_test 34e "create objects, some with size and some without =="
2542 test_34f() { # bug 6242, 6243
2543 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2546 $MCREATE $DIR/f34f || error
2547 $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2548 dd if=$DIR/f34f of=$TMP/f34f
2549 $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2550 dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2551 cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2552 cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2553 rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2555 run_test 34f "read from a file with no objects until EOF ======="
2558 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2559 dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2560 $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2561 $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2562 cancel_lru_locks osc
2563 $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2564 error "wrong size after lock cancel"
2566 $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2567 $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2568 error "expanding truncate failed"
2569 cancel_lru_locks osc
2570 $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2571 error "wrong expanded size after lock cancel"
2573 run_test 34g "truncate long file ==============================="
2576 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2580 dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2581 sync # Flush the cache so that multiop below does not block on cache
2582 # flush when getting the group lock
2583 $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2586 # Since just timed wait is not good enough, let's do a sync write
2587 # that way we are sure enough time for a roundtrip + processing
2588 # passed + 2 seconds of extra margin.
2589 dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2593 if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2594 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2598 local nsz=`stat -c %s $DIR/$tfile`
2599 [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2601 run_test 34h "ftruncate file under grouplock should not block"
2604 cp /bin/sh $DIR/f35a
2606 chown $RUNAS_ID $DIR/f35a
2607 $RUNAS $DIR/f35a && error || true
2610 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2614 utime $DIR/f36 || error
2616 run_test 36a "MDS utime check (mknod, utime) ==================="
2620 utime $DIR/f36 || error
2622 run_test 36b "OST utime check (open, utime) ===================="
2627 chown $RUNAS_ID $DIR/d36
2628 $RUNAS utime $DIR/d36/f36 || error
2630 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2633 [ ! -d $DIR/d36 ] && test_36c
2634 echo "" > $DIR/d36/f36
2635 $RUNAS utime $DIR/d36/f36 || error
2637 run_test 36d "non-root OST utime check (open, utime) ==========="
2640 [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2641 test_mkdir -p $DIR/$tdir
2642 touch $DIR/$tdir/$tfile
2643 $RUNAS utime $DIR/$tdir/$tfile && \
2644 error "utime worked, expected failure" || true
2646 run_test 36e "utime on non-owned file (should return error) ===="
2650 local LANG_SAVE=$LANG
2651 local LC_LANG_SAVE=$LC_LANG
2652 export LANG=C LC_LANG=C # for date language
2654 DATESTR="Dec 20 2000"
2655 test_mkdir -p $DIR/$tdir
2656 lctl set_param fail_loc=$fl
2658 cp /etc/hosts $DIR/$tdir/$tfile
2659 sync & # write RPC generated with "current" inode timestamp, but delayed
2661 touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2662 LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2663 cancel_lru_locks osc
2664 LS_AFTER="`ls -l $DIR/$tdir/$tfile`" # timestamp from OST object
2666 [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2667 echo "BEFORE: $LS_BEFORE" && \
2668 echo "AFTER : $LS_AFTER" && \
2669 echo "WANT : $DATESTR" && \
2670 error "$DIR/$tdir/$tfile timestamps changed" || true
2672 export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2676 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2677 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2678 subr_36fh "0x80000214"
2680 run_test 36f "utime on file racing with OST BRW write =========="
2683 remote_ost_nodsh && skip "remote OST with nodsh" && return
2684 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2689 test_mkdir -p $DIR/$tdir
2690 fmd_max_age=$(do_facet ost1 \
2691 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2694 fmd_before=$(do_facet ost1 \
2695 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2696 touch $DIR/$tdir/$tfile
2697 sleep $((fmd_max_age + 12))
2698 fmd_after=$(do_facet ost1 \
2699 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2701 echo "fmd_before: $fmd_before"
2702 echo "fmd_after: $fmd_after"
2703 [ "$fmd_after" -gt "$fmd_before" ] && \
2704 echo "AFTER: $fmd_after > BEFORE: $fmd_before" && \
2705 error "fmd didn't expire after ping" || true
2707 run_test 36g "filter mod data cache expiry ====================="
2710 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2711 #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2712 subr_36fh "0x80000227"
2714 run_test 36h "utime on file racing with OST BRW write =========="
2716 # test_37 - duplicate with tests 32q 32r
2719 local file=$DIR/$tfile
2721 openfile -f O_DIRECTORY $file
2724 [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2725 [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2727 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2731 touch $DIR/${tfile}2
2732 # ls -l $DIR/$tfile $DIR/${tfile}2
2733 # ls -lu $DIR/$tfile $DIR/${tfile}2
2734 # ls -lc $DIR/$tfile $DIR/${tfile}2
2736 $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2737 if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2739 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2741 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2743 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2744 error "O_TRUNC didn't change timestamps"
2747 run_test 39 "mtime changed on create ==========================="
2750 test_mkdir -p $DIR/$tdir
2751 cp -p /etc/passwd $DIR/$tdir/fopen
2752 cp -p /etc/passwd $DIR/$tdir/flink
2753 cp -p /etc/passwd $DIR/$tdir/funlink
2754 cp -p /etc/passwd $DIR/$tdir/frename
2755 ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2758 echo "aaaaaa" >> $DIR/$tdir/fopen
2759 echo "aaaaaa" >> $DIR/$tdir/flink
2760 echo "aaaaaa" >> $DIR/$tdir/funlink
2761 echo "aaaaaa" >> $DIR/$tdir/frename
2763 local open_new=`stat -c %Y $DIR/$tdir/fopen`
2764 local link_new=`stat -c %Y $DIR/$tdir/flink`
2765 local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2766 local rename_new=`stat -c %Y $DIR/$tdir/frename`
2768 cat $DIR/$tdir/fopen > /dev/null
2769 ln $DIR/$tdir/flink $DIR/$tdir/flink2
2770 rm -f $DIR/$tdir/funlink2
2771 mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2773 for (( i=0; i < 2; i++ )) ; do
2774 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2775 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2776 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2777 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2779 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2780 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2781 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2782 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2784 cancel_lru_locks osc
2785 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2788 run_test 39b "mtime change on open, link, unlink, rename ======"
2790 # this should be set to past
2791 TEST_39_MTIME=`date -d "1 year ago" +%s`
2797 local mtime0=`stat -c %Y $DIR1/$tfile`
2799 touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2800 local mtime1=`stat -c %Y $DIR1/$tfile`
2801 [ "$mtime1" = $TEST_39_MTIME ] || \
2802 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2805 echo hello >> $DIR1/$tfile
2807 local mtime2=`stat -c %Y $DIR1/$tfile`
2808 [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2809 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2811 mv $DIR1/$tfile $DIR1/$tfile-1
2813 for (( i=0; i < 2; i++ )) ; do
2814 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2815 [ "$mtime2" = "$mtime3" ] || \
2816 error "mtime ($mtime2) changed (to $mtime3) on rename"
2818 cancel_lru_locks osc
2819 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2822 run_test 39c "mtime change on rename ==========================="
2826 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2829 touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2831 for (( i=0; i < 2; i++ )) ; do
2832 local mtime=`stat -c %Y $DIR1/$tfile`
2833 [ $mtime = $TEST_39_MTIME ] || \
2834 error "mtime($mtime) is not set to $TEST_39_MTIME"
2836 cancel_lru_locks osc
2837 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2840 run_test 39d "create, utime, stat =============================="
2844 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2846 local mtime1=`stat -c %Y $DIR1/$tfile`
2848 touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2850 for (( i=0; i < 2; i++ )) ; do
2851 local mtime2=`stat -c %Y $DIR1/$tfile`
2852 [ $mtime2 = $TEST_39_MTIME ] || \
2853 error "mtime($mtime2) is not set to $TEST_39_MTIME"
2855 cancel_lru_locks osc
2856 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2859 run_test 39e "create, stat, utime, stat ========================"
2863 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2865 mtime1=`stat -c %Y $DIR1/$tfile`
2868 touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2870 for (( i=0; i < 2; i++ )) ; do
2871 local mtime2=`stat -c %Y $DIR1/$tfile`
2872 [ $mtime2 = $TEST_39_MTIME ] || \
2873 error "mtime($mtime2) is not set to $TEST_39_MTIME"
2875 cancel_lru_locks osc
2876 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2879 run_test 39f "create, stat, sleep, utime, stat ================="
2883 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2884 echo hello >> $DIR1/$tfile
2885 local mtime1=`stat -c %Y $DIR1/$tfile`
2888 chmod o+r $DIR1/$tfile
2890 for (( i=0; i < 2; i++ )) ; do
2891 local mtime2=`stat -c %Y $DIR1/$tfile`
2892 [ "$mtime1" = "$mtime2" ] || \
2893 error "lost mtime: $mtime2, should be $mtime1"
2895 cancel_lru_locks osc
2896 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2899 run_test 39g "write, chmod, stat ==============================="
2903 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2908 echo hello >> $DIR1/$tfile
2909 local mtime1=`stat -c %Y $DIR1/$tfile`
2911 touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2913 if [ "$d1" != "$d2" ]; then
2914 echo "write and touch not within one second"
2916 for (( i=0; i < 2; i++ )) ; do
2917 local mtime2=`stat -c %Y $DIR1/$tfile`
2918 [ "$mtime2" = $TEST_39_MTIME ] || \
2919 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
2921 cancel_lru_locks osc
2922 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2926 run_test 39h "write, utime within one second, stat ============="
2929 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2933 echo hello >> $DIR1/$tfile
2934 local mtime1=`stat -c %Y $DIR1/$tfile`
2936 mv $DIR1/$tfile $DIR1/$tfile-1
2938 for (( i=0; i < 2; i++ )) ; do
2939 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2941 [ "$mtime1" = "$mtime2" ] || \
2942 error "lost mtime: $mtime2, should be $mtime1"
2944 cancel_lru_locks osc
2945 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2948 run_test 39i "write, rename, stat =============================="
2951 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2952 start_full_debug_logging
2956 #define OBD_FAIL_OSC_DELAY_SETTIME 0x412
2957 lctl set_param fail_loc=0x80000412
2958 multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
2959 error "multiop failed"
2961 local mtime1=`stat -c %Y $DIR1/$tfile`
2963 mv $DIR1/$tfile $DIR1/$tfile-1
2965 kill -USR1 $multipid
2966 wait $multipid || error "multiop close failed"
2968 for (( i=0; i < 2; i++ )) ; do
2969 local mtime2=`stat -c %Y $DIR1/$tfile-1`
2970 [ "$mtime1" = "$mtime2" ] ||
2971 error "mtime is lost on close: $mtime2, " \
2974 cancel_lru_locks osc
2975 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2977 lctl set_param fail_loc=0
2978 stop_full_debug_logging
2980 run_test 39j "write, rename, close, stat ======================="
2983 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2987 multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
2989 local mtime1=`stat -c %Y $DIR1/$tfile`
2991 touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2993 kill -USR1 $multipid
2994 wait $multipid || error "multiop close failed"
2996 for (( i=0; i < 2; i++ )) ; do
2997 local mtime2=`stat -c %Y $DIR1/$tfile`
2999 [ "$mtime2" = $TEST_39_MTIME ] || \
3000 error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3002 cancel_lru_locks osc
3003 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3006 run_test 39k "write, utime, close, stat ========================"
3008 # this should be set to future
3009 TEST_39_ATIME=`date -d "1 year" +%s`
3012 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3013 remote_mds_nodsh && skip "remote MDS with nodsh" && return
3014 local atime_diff=$(do_facet $SINGLEMDS \
3015 lctl get_param -n mdd.*MDT0000*.atime_diff)
3019 # test setting directory atime to future
3020 touch -a -d @$TEST_39_ATIME $DIR/$tdir
3021 local atime=$(stat -c %X $DIR/$tdir)
3022 [ "$atime" = $TEST_39_ATIME ] || \
3023 error "atime is not set to future: $atime, $TEST_39_ATIME"
3025 # test setting directory atime from future to now
3026 local d1=$(date +%s)
3028 local d2=$(date +%s)
3030 cancel_lru_locks mdc
3031 atime=$(stat -c %X $DIR/$tdir)
3032 [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3033 error "atime is not updated from future: $atime, $d1<atime<$d2"
3035 do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3038 # test setting directory atime when now > dir atime + atime_diff
3042 cancel_lru_locks mdc
3043 atime=$(stat -c %X $DIR/$tdir)
3044 [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3045 error "atime is not updated : $atime, should be $d2"
3047 do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3050 # test not setting directory atime when now < dir atime + atime_diff
3052 cancel_lru_locks mdc
3053 atime=$(stat -c %X $DIR/$tdir)
3054 [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3055 error "atime is updated to $atime, should remain $d1<atime<$d2"
3057 do_facet $SINGLEMDS \
3058 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3060 run_test 39l "directory atime update ==========================="
3063 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3066 local far_past_mtime=$(date -d "May 29 1953" +%s)
3067 local far_past_atime=$(date -d "Dec 17 1903" +%s)
3069 touch -m -d @$far_past_mtime $DIR1/$tfile
3070 touch -a -d @$far_past_atime $DIR1/$tfile
3072 for (( i=0; i < 2; i++ )) ; do
3073 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3074 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3075 error "atime or mtime set incorrectly"
3077 cancel_lru_locks osc
3078 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3081 run_test 39m "test atime and mtime before 1970"
3084 dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3085 $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3086 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3087 $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3088 error "$tfile is not 4096 bytes in size"
3090 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3094 small_write $DIR/f41 18
3096 run_test 41 "test small file write + fstat ====================="
3098 count_ost_writes() {
3099 lctl get_param -n osc.*.stats |
3100 awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
3107 BG_DIRTY_RATIO_SAVE=10
3108 MAX_BG_DIRTY_RATIO=25
3112 # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3113 # dirty_ratio, dirty_background_ratio
3114 if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3115 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3116 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3117 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3119 # if file not here, we are a 2.4 kernel
3120 kill -CONT `pidof kupdated`
3125 # setup the trap first, so someone cannot exit the test at the
3126 # exact wrong time and mess up a machine
3127 trap start_writeback EXIT
3128 # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3129 if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3130 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3131 sysctl -w vm.dirty_writeback_centisecs=0
3132 sysctl -w vm.dirty_writeback_centisecs=0
3133 # save and increase /proc/sys/vm/dirty_ratio
3134 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3135 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3136 # save and increase /proc/sys/vm/dirty_background_ratio
3137 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3138 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3140 # if file not here, we are a 2.4 kernel
3141 kill -STOP `pidof kupdated`
3145 # ensure that all stripes have some grant before we test client-side cache
3147 for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3148 dd if=/dev/zero of=$i bs=4k count=1
3153 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3154 # file truncation, and file removal.
3156 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3158 cancel_lru_locks osc
3160 sync; sleep 1; sync # just to be safe
3161 BEFOREWRITES=`count_ost_writes`
3162 lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3163 dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3164 AFTERWRITES=`count_ost_writes`
3165 [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3166 error "$BEFOREWRITES < $AFTERWRITES"
3169 run_test 42a "ensure that we don't flush on close =============="
3172 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3174 cancel_lru_locks osc
3177 dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3178 BEFOREWRITES=`count_ost_writes`
3179 $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3180 AFTERWRITES=`count_ost_writes`
3181 if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3182 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3184 BEFOREWRITES=`count_ost_writes`
3185 sync || error "sync: $?"
3186 AFTERWRITES=`count_ost_writes`
3187 if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3188 error "$BEFOREWRITES < $AFTERWRITES on sync"
3190 dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3194 run_test 42b "test destroy of file with cached dirty data ======"
3196 # if these tests just want to test the effect of truncation,
3197 # they have to be very careful. consider:
3198 # - the first open gets a {0,EOF}PR lock
3199 # - the first write conflicts and gets a {0, count-1}PW
3200 # - the rest of the writes are under {count,EOF}PW
3201 # - the open for truncate tries to match a {0,EOF}PR
3202 # for the filesize and cancels the PWs.
3203 # any number of fixes (don't get {0,EOF} on open, match
3204 # composite locks, do smarter file size management) fix
3205 # this, but for now we want these tests to verify that
3206 # the cancellation with truncate intent works, so we
3207 # start the file with a full-file pw lock to match against
3208 # until the truncate.
3213 cancel_lru_locks osc
3215 # prime the file with 0,EOF PW to match
3219 # now the real test..
3220 dd if=/dev/zero of=$file bs=1024 count=100
3221 BEFOREWRITES=`count_ost_writes`
3222 $TRUNCATE $file $offset
3223 cancel_lru_locks osc
3224 AFTERWRITES=`count_ost_writes`
3229 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3231 [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3232 error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3235 run_test 42c "test partial truncate of file with cached dirty data"
3238 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3240 [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3241 error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3244 run_test 42d "test complete truncate of file with cached dirty data"
3246 test_42e() { # bug22074
3247 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3248 local TDIR=$DIR/${tdir}e
3249 local pagesz=$(page_size)
3250 local pages=16 # hardcoded 16 pages, don't change it.
3251 local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3252 local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3256 test_mkdir -p $DIR/${tdir}e
3257 $SETSTRIPE -c 1 $TDIR
3258 createmany -o $TDIR/f $files
3260 max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3262 # we assume that with $OSTCOUNT files, at least one of them will
3263 # be allocated on OST0.
3264 warmup_files=$((OSTCOUNT * max_dirty_mb))
3265 createmany -o $TDIR/w $warmup_files
3267 # write a large amount of data into one file and sync, to get good
3268 # avail_grant number from OST.
3269 for ((i=0; i<$warmup_files; i++)); do
3270 idx=$($GETSTRIPE -i $TDIR/w$i)
3271 [ $idx -ne 0 ] && continue
3272 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3275 [ $i -gt $warmup_files ] && error "OST0 is still cold"
3277 $LCTL get_param $proc_osc0/cur_dirty_bytes
3278 $LCTL get_param $proc_osc0/cur_grant_bytes
3280 # create as much dirty pages as we can while not to trigger the actual
3281 # RPCs directly. but depends on the env, VFS may trigger flush during this
3282 # period, hopefully we are good.
3283 for ((i=0; i<$warmup_files; i++)); do
3284 idx=$($GETSTRIPE -i $TDIR/w$i)
3285 [ $idx -ne 0 ] && continue
3286 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3288 $LCTL get_param $proc_osc0/cur_dirty_bytes
3289 $LCTL get_param $proc_osc0/cur_grant_bytes
3291 # perform the real test
3292 $LCTL set_param $proc_osc0/rpc_stats 0
3293 for ((;i<$files; i++)); do
3294 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3295 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3298 $LCTL get_param $proc_osc0/rpc_stats
3301 local have_ppr=false
3302 $LCTL get_param $proc_osc0/rpc_stats |
3303 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3304 # skip lines until we are at the RPC histogram data
3305 [ "$PPR" == "pages" ] && have_ppr=true && continue
3306 $have_ppr || continue
3308 # we only want the percent stat for < 16 pages
3309 [ $(echo $PPR | tr -d ':') -ge $pages ] && break
3311 percent=$((percent + WPCT))
3312 if [ $percent -gt 15 ]; then
3313 error "less than 16-pages write RPCs" \
3320 run_test 42e "verify sub-RPC writes are not done synchronously"
3323 test_mkdir -p $DIR/$tdir
3324 cp -p /bin/ls $DIR/$tdir/$tfile
3325 $MULTIOP $DIR/$tdir/$tfile Ow_c &
3327 # give multiop a chance to open
3330 $DIR/$tdir/$tfile && error || true
3333 run_test 43 "execution of file opened for write should return -ETXTBSY"
3336 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3337 test_mkdir -p $DIR/$tdir
3338 cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3339 cp -p multiop $DIR/$tdir/multiop
3340 MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/test43.junk O_c ||
3343 $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3344 kill -USR1 $MULTIOP_PID || return 2
3345 wait $MULTIOP_PID || return 3
3348 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3351 [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3352 test_mkdir -p $DIR/$tdir
3353 cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3354 cp -p multiop $DIR/$tdir/multiop
3355 MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/test43.junk O_c ||
3358 $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3359 kill -USR1 $MULTIOP_PID || return 2
3360 wait $MULTIOP_PID || return 3
3363 run_test 43b "truncate of file being executed should return -ETXTBSY"
3366 local testdir="$DIR/$tdir"
3367 test_mkdir -p $DIR/$tdir
3369 ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3370 ( cd $testdir && md5sum -c)
3372 run_test 43c "md5sum of copy into lustre========================"
3375 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
3376 dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3377 dd if=$DIR/f1 bs=4k count=1 > /dev/null
3379 run_test 44 "zero length read from a sparse stripe ============="
3382 local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
3384 [ -z "$nstripe" ] && skip "can't get stripe info" && return
3385 [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
3386 local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
3388 if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
3389 nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
3392 OFFSETS="0 $((stride/2)) $((stride-1))"
3393 for offset in $OFFSETS ; do
3394 for i in `seq 0 $((nstripe-1))`; do