+count_ost_writes() {
+ cat /proc/fs/lustre/osc/*/stats |
+ awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
+}
+start_kupdated() {
+ # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs
+ kill -CONT `pidof kupdated`
+}
+stop_kupdated() {
+ # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
+ kill -STOP `pidof kupdated`
+ trap start_kupdated EXIT
+}
+
+# Tests 42* verify that our behaviour is correct WRT caching, file closure,
+# file truncation, and file removal.
+test_42a() {
+ cancel_lru_locks OSC
+ stop_kupdated
+ sync # just to be safe
+ BEFOREWRITES=`count_ost_writes`
+ dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
+ AFTERWRITES=`count_ost_writes`
+ [ $BEFOREWRITES -eq $AFTERWRITES ] || \
+ error "$BEFOREWRITES < $AFTERWRITES"
+ start_kupdated
+}
+run_test 42a "ensure that we don't flush on close =============="
+
+test_42b() {
+ cancel_lru_locks OSC
+ stop_kupdated
+ sync
+ dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
+ BEFOREWRITES=`count_ost_writes`
+ $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
+ AFTERWRITES=`count_ost_writes`
+ [ $BEFOREWRITES -eq $AFTERWRITES ] ||
+ error "$BEFOREWRITES < $AFTERWRITES on unlink"
+ BEFOREWRITES=`count_ost_writes`
+ sync || error "sync: $?"
+ AFTERWRITES=`count_ost_writes`
+ [ $BEFOREWRITES -eq $AFTERWRITES ] ||
+ error "$BEFOREWRITES < $AFTERWRITES on sync"
+ dmesg | grep 'error from obd_brw_async' && error 'error writing back'
+ start_kupdated
+ return 0
+}
+run_test 42b "test destroy of file with cached dirty data ======"
+
+# if these tests just want to test the effect of truncation,
+# they have to be very careful. consider:
+# - the first open gets a {0,EOF}PR lock
+# - the first write conflicts and gets a {0, count-1}PW
+# - the rest of the writes are under {count,EOF}PW
+# - the open for truncate tries to match a {0,EOF}PR
+# for the filesize and cancels the PWs.
+# any number of fixes (don't get {0,EOF} on open, match
+# composite locks, do smarter file size management) fix
+# this, but for now we want these tests to verify that
+# the cancelation with truncate intent works, so we
+# start the file with a full-file pw lock to match against
+# until the truncate.
+trunc_test() {
+ test=$1
+ file=$DIR/$test
+ offset=$2
+ cancel_lru_locks OSC
+ stop_kupdated
+ # prime the file with 0,EOF PW to match
+ touch $file
+ $TRUNCATE $file 0
+ sync; sync
+ # now the real test..
+ dd if=/dev/zero of=$file bs=1024 count=100
+ BEFOREWRITES=`count_ost_writes`
+ $TRUNCATE $file $offset
+ cancel_lru_locks OSC
+ AFTERWRITES=`count_ost_writes`
+ start_kupdated
+}
+
+test_42c() {
+ trunc_test 42c 1024
+ [ $BEFOREWRITES -eq $AFTERWRITES ] && \
+ error "$BEFOREWRITES < $AFTERWRITES on truncate"
+ rm $file
+}
+run_test 42c "test partial truncate of file with cached dirty data ===="
+
+test_42d() {
+ trunc_test 42d 0
+ [ $BEFOREWRITES -eq $AFTERWRITES ] || \
+ error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
+ rm $file
+}
+run_test 42d "test complete truncate of file with cached dirty data ===="
+
+test_43() {
+ mkdir $DIR/d43
+ cp -p /bin/ls $DIR/d43/f
+ exec 100>> $DIR/d43/f
+ $DIR/d43/f && error || true
+ exec 100<&-
+}
+run_test 43 "execution of file opened for write should return -ETXTBSY=="
+
+test_43a() {
+ mkdir -p $DIR/d43
+ cp -p `which multiop` $DIR/d43/multiop
+ touch $DIR/d43/g
+ $DIR/d43/multiop $DIR/d43/g o_c &
+ MULTIPID=$!
+ sleep 1
+ multiop $DIR/d43/multiop Oc && error "expected error, got success"
+ kill -USR1 $MULTIPID || return 2
+ wait $MULTIPID || return 3
+}
+run_test 43a "open(RDWR) of file being executed should return -ETXTBSY=="
+
+test_43b() {
+ mkdir -p $DIR/d43
+ cp -p `which multiop` $DIR/d43/multiop
+ touch $DIR/d43/g
+ $DIR/d43/multiop $DIR/d43/g o_c &
+ MULTIPID=$!
+ sleep 1
+ truncate $DIR/d43/multiop 0 && error "expected error, got success"
+ kill -USR1 $MULTIPID || return 2
+ wait $MULTIPID || return 3
+}
+run_test 43b "truncate of file being executed should return -ETXTBSY===="
+
+test_43c() {
+ local testdir="$DIR/43a"
+ mkdir -p $testdir
+ cp $SHELL $testdir/
+ ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
+ ( cd $testdir && md5sum -c)
+}
+run_test 43c "md5sum of copy into lustre================================"
+
+test_44() {
+ [ "$STRIPECOUNT" -lt "2" ] && echo "skipping 2-stripe test" && return
+ dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=127
+ dd if=$DIR/f1 bs=4k count=1
+}
+run_test 44 "zero length read from a sparse stripe ============="
+
+test_44a() {
+ local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
+ awk '{print $2}'`
+ local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
+ awk '{print $2}'`
+ if [ $nstripe -eq 0 ] ; then
+ nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
+ fi
+
+ OFFSETS="0 $((stride/2)) $((stride-1))"
+ for offset in $OFFSETS ; do
+ for i in `seq 0 $((nstripe-1))`; do
+ rm -f $DIR/44a
+ local GLOBALOFFSETS=""
+ local size=$((((i + 2 * $nstripe )*$stride + $offset))) # Bytes
+ ll_sparseness_write $DIR/44a $size || error "ll_sparseness_write"
+ GLOBALOFFSETS="$GLOBALOFFSETS $size"
+ ll_sparseness_verify $DIR/44a $GLOBALOFFSETS \
+ || error "ll_sparseness_verify $GLOBALOFFSETS"
+
+ for j in `seq 0 $((nstripe-1))`; do
+ size=$((((j + $nstripe )*$stride + $offset))) # Bytes
+ ll_sparseness_write $DIR/44a $size || error "ll_sparseness_write"
+ GLOBALOFFSETS="$GLOBALOFFSETS $size"
+ done
+ ll_sparseness_verify $DIR/44a $GLOBALOFFSETS \
+ || error "ll_sparseness_verify $GLOBALOFFSETS"
+ done
+ done
+}
+run_test 44a "test sparse pwrite ==============================="
+
+dirty_osc_total() {
+ tot=0
+ for d in /proc/fs/lustre/osc/*/cur_dirty_bytes; do
+ tot=$(($tot + `cat $d`))
+ done
+ echo $tot
+}
+do_dirty_record() {
+ before=`dirty_osc_total`
+ echo executing "\"$*\""
+ eval $*
+ after=`dirty_osc_total`
+ echo before $before, after $after
+}
+test_45() {
+ f="$DIR/45"
+ stop_kupdated
+ sync
+ do_dirty_record "echo blah > $f"
+ [ $before -eq $after ] && error "write wasn't cached"
+ do_dirty_record "> $f"
+ [ $before -gt $after ] || error "truncate didn't lower dirty count"
+ do_dirty_record "echo blah > $f"
+ [ $before -eq $after ] && error "write wasn't cached"
+ do_dirty_record "sync"
+ [ $before -gt $after ] || error "writeback didn't lower dirty count"
+ do_dirty_record "echo blah > $f"
+ [ $before -eq $after ] && error "write wasn't cached"
+ do_dirty_record "cancel_lru_locks OSC"
+ [ $before -gt $after ] || error "lock cancelation didn't lower dirty count"
+ start_kupdated
+}
+run_test 45 "osc io page accounting ============================"
+
+page_size() {
+ getconf PAGE_SIZE
+}
+
+# in a 2 stripe file (lov.sh), page 63 maps to page 31 in its object. this
+# test tickles a bug where re-dirtying a page was failing to be mapped to the
+# objects offset and an assert hit when an rpc was built with 63's mapped
+# offset 31 and 31's raw 31 offset. it also found general redirtying bugs.
+test_46() {
+ f="$DIR/46"
+ stop_kupdated
+ sync
+ dd if=/dev/zero of=$f bs=`page_size` seek=31 count=1
+ sync
+ dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=63 count=1
+ dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=31 count=1
+ sync
+ start_kupdated
+}
+run_test 46 "dirtying a previously written page ================"
+
+# Check that device nodes are created and then visible correctly (#2091)
+test_47() {
+ cmknod $DIR/test_47_node || error
+}
+run_test 47 "Device nodes check ================================"
+
+test_48() {
+ mkdir $DIR/d48
+ cd $DIR/d48
+ mv $DIR/d48 $DIR/d48.new || error "move directory failed"
+ mkdir $DIR/d48 || error "recreate diectory failed"
+ ls || error "can't list after recreate directory"
+}
+run_test 48 "Access renamed current working directory ========="
+
+test_50() {
+ # bug 1485
+ mkdir $DIR/d50
+ cd $DIR/d50
+ ls /proc/$$/cwd || error
+}
+run_test 50 "special situations: /proc symlinks ==============="
+
+test_51() {
+ # bug 1516 - create an empty entry right after ".." then split dir
+ mkdir $DIR/d49
+ touch $DIR/d49/foo
+ $MCREATE $DIR/d49/bar
+ rm $DIR/d49/foo
+ createmany -m $DIR/d49/longfile 201
+ FNUM=202
+ while [ `ls -sd $DIR/d49 | awk '{ print $1 }'` -eq 4 ]; do
+ $MCREATE $DIR/d49/longfile$FNUM
+ FNUM=$(($FNUM + 1))
+ echo -n "+"
+ done
+ ls -l $DIR/d49 > /dev/null || error
+}
+run_test 51 "special situations: split htree with empty entry =="
+
+test_52a() {
+ [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
+ mkdir -p $DIR/d52a
+ touch $DIR/d52a/foo
+ chattr =a $DIR/d52a/foo || error
+ echo bar >> $DIR/d52a/foo || error
+ cp /etc/hosts $DIR/d52a/foo && error
+ rm -f $DIR/d52a/foo 2>/dev/null && error
+ link $DIR/d52a/foo $DIR/d52a/foo_link 2>/dev/null && error
+ echo foo >> $DIR/d52a/foo || error
+ mrename $DIR/d52a/foo $DIR/d52a/foo_ren && error
+ lsattr $DIR/d52a/foo | egrep -q "^-+a-+ $DIR/d52a/foo" || error
+ chattr -a $DIR/d52a/foo || error
+
+ rm -fr $DIR/d52a || error
+}
+run_test 52a "append-only flag test ============================"
+
+test_52b() {
+ [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
+ mkdir -p $DIR/d52b
+ touch $DIR/d52b/foo
+ chattr =i $DIR/d52b/foo || error
+ cat test > $DIR/d52b/foo && error
+ cp /etc/hosts $DIR/d52b/foo && error
+ rm -f $DIR/d52b/foo 2>/dev/null && error
+ link $DIR/d52b/foo $DIR/d52b/foo_link 2>/dev/null && error
+ echo foo >> $DIR/d52b/foo && error
+ mrename $DIR/d52b/foo $DIR/d52b/foo_ren && error
+ [ -f $DIR/d52b/foo ] || error
+ [ -f $DIR/d52b/foo_ren ] && error
+ lsattr $DIR/d52b/foo | egrep -q "^-+i-+ $DIR/d52b/foo" || error
+ chattr -i $DIR/d52b/foo || error
+
+ rm -fr $DIR/d52b || error
+}
+run_test 52b "immutable flag test =============================="
+
+test_53() {
+ for i in /proc/fs/lustre/osc/OSC*mds1 ; do
+ ostname=`echo $i | cut -d _ -f 3-4 | sed -e s/_mds1//`
+ ost_last=`cat /proc/fs/lustre/obdfilter/$ostname/last_id`
+ mds_last=`cat $i/prealloc_last_id`
+ echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
+ if [ $ost_last != $mds_last ]; then
+ error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
+ fi
+ done
+}
+run_test 53 "verify that MDS and OSTs agree on pre-creation====="
+
+test_54a() {
+ $SOCKETSERVER $DIR/socket &
+ sleep 1
+ $SOCKETCLIENT $DIR/socket || error
+ $MUNLINK $DIR/socket
+}
+run_test 54a "unix damain socket test ==========================="
+
+test_54b() {
+ f="$DIR/f54b"
+ mknod $f c 1 3
+ chmod 0666 $f
+ dd if=/dev/zero of=$f bs=`page_size` count=1
+}
+run_test 54b "char device works in lustre"
+
+test_54c() {
+ f="$DIR/f54c"
+ dir="$DIR/dir54c"
+ loopdev="$DIR/loop54c"
+
+ mknod $loopdev b 7 1
+ dd if=/dev/zero of=$f bs=`page_size` count=1024 > /dev/null
+ chmod 0666 $f
+ losetup $loopdev $f
+ echo "make a loop file system..."
+ mkfs.ext2 -F $f > /dev/null
+ mkdir -p $dir
+ mount $loopdev $dir
+ dd if=/dev/zero of=$dir/tmp bs=`page_size` count=30 || error
+ dd if=$dir/tmp of=/dev/zero bs=`page_size` count=30 || error
+ umount $dir
+}
+run_test 54c "loop device works in lustre"
+
+test_54d() {
+ f="$DIR/f54d"
+ string="aaaaaa"
+ mknod $f p
+ [ "$string" = `echo $string > $f | cat $f` ] || error
+}
+run_test 54d "fifo device works in lustre"
+
+test_55() {
+ for i in `ls $TMP|grep -E 'mds|ost'` ; do
+ rm -rf $DIR/d55
+ mkdir $DIR/d55
+ mount -o loop,iopen $TMP/$i $DIR/d55
+ touch $DIR/d55/foo
+ $IOPENTEST1 $DIR/d55/foo $DIR/d55
+ $IOPENTEST2 $DIR/d55
+ echo "check for $TMP/$i. Please wait..."
+ sleep 6
+ rm -rf $DIR/d55/*
+ umount $DIR/d55
+ done
+}
+run_test 55 "check iopen_connect_dentry()======================="
+
+test_59() {
+ echo "touch 130 files"
+ for i in `seq 1 130` ; do
+ touch $DIR/59-$i
+ done
+ echo "rm 130 files"
+ for i in `seq 1 130` ; do
+ rm -f $DIR/59-$i
+ done
+ sync
+ sleep 2
+ # wait for commitment of removal
+}
+run_test 59 "verify cancellation of llog records async=========="
+
+test_60() {
+ echo 60 "llog tests run from kernel mode"
+ sh run-llog.sh
+}
+run_test 60 "llog sanity tests run from kernel module =========="
+
+test_61() {
+ f="$DIR/f61"
+ dd if=/dev/zero of=$f bs=`page_size` count=1
+ cancel_lru_locks OSC
+ multiop $f OSMWUc || error
+ sync
+}
+run_test 61 "mmap() writes don't make sync hang =========="
+
+# bug 2330 - insufficient obd_match error checking causes LBUG
+test_62() {
+ f="$DIR/f62"
+ echo foo > $f
+ cancel_lru_locks OSC
+ echo 0x405 > /proc/sys/lustre/fail_loc
+ cat $f && error # expect -EIO
+ multiop $f Owc && error
+ echo 0 > /proc/sys/lustre/fail_loc
+}
+run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
+
+# bug 2319 - osic_wait() interrupted causes crash because of invalid waitq.
+test_63() {
+ for i in /proc/fs/lustre/osc/*/max_dirty_mb ; do
+ echo 0 > $i
+ done
+ for i in `seq 10` ; do
+ dd if=/dev/zero of=$DIR/syncwrite_testfile bs=8k &
+ sleep 5
+ kill $!
+ sleep 1
+ done
+
+ for i in /proc/fs/lustre/osc/*/max_dirty_mb ; do
+ echo $[ 64 ] > $i
+ done
+ true
+}
+run_test 63 "Verify osic_wait interruption does not crash"
+