Whamcloud - gitweb
LU-14286 osd-ldiskfs: don't read unwritten blocks
[fs/lustre-release.git] / lustre / tests / oos.sh
index ba9bec3..504f2fe 100755 (executable)
@@ -1,15 +1,15 @@
 #!/bin/bash
 
 set -e
-#set -vx
 
-export PATH=`dirname $0`/../utils:$PATH
-LFS=${LFS:-lfs}
+LUSTRE=${LUSTRE:-$(dirname $0)/..}
+. $LUSTRE/tests/test-framework.sh
+init_test_env $@
+
 MOUNT=${MOUNT:-$1}
 MOUNT=${MOUNT:-/mnt/lustre}
 OOS=$MOUNT/oosfile
-TMP=${TMP:-/tmp}
-LOG=$TMP/ooslog
+LOG=$TMP/$(basename $0 .sh).log
 
 SUCCESS=1
 
@@ -17,32 +17,35 @@ rm -f $OOS $LOG
 
 sync; sleep 1; sync    # to ensure we get up-to-date statfs info
 
-#echo -1 > /proc/sys/lnet/debug
-#echo 0x40a8 > /proc/sys/lnet/subsystem_debug
-#lctl clear
-#lctl debug_daemon start /r/tmp/debug 1024
-
-STRIPECOUNT=`cat /proc/fs/lustre/lov/*/activeobd | head -n 1`
-ORIGFREE=`cat /proc/fs/lustre/llite/*/kbytesavail | head -n 1`
+STRIPECOUNT=$($LCTL get_param -n lov.*.activeobd | head -n 1)
+ORIGFREE=$($LCTL get_param -n llite.*.kbytesavail | head -n 1)
 MAXFREE=${MAXFREE:-$((400000 * $STRIPECOUNT))}
+echo STRIPECOUNT=$STRIPECOUNT ORIGFREE=$ORIGFREE MAXFREE=$MAXFREE
 if [ $ORIGFREE -gt $MAXFREE ]; then
-       echo "skipping out-of-space test on $OSC"
-       echo "reports ${ORIGFREE}kB free, more than MAXFREE ${MAXFREE}kB"
-       echo "increase $MAXFREE (or reduce test fs size) to proceed"
+       skip "$0: ${ORIGFREE}kB free gt MAXFREE ${MAXFREE}kB, increase $MAXFREE (or reduce test fs size) to proceed"
        exit 0
 fi
 
 export LANG=C LC_LANG=C # for "No space left on device" message
 
-[ -f $LOG ] && echo "ERROR: log file wasn't removed?" && exit 1
+[ -f $LOG ] && error "log file wasn't removed?"
+
+echo BEFORE dd started
+oos_full || true
 
 # make sure we stripe over all OSTs to avoid OOS on only a subset of OSTs
 $LFS setstripe $OOS -c $STRIPECOUNT
-if dd if=/dev/zero of=$OOS count=$(($ORIGFREE + 100)) bs=1k 2> $LOG; then
+# add 20% of margin since the metadata overhead estimated in bavail might be
+# too aggressive and we might be able to write more than reported initially
+# by statfs.
+echo dd size $((ORIGFREE * 120 / 100))kB
+if dd if=/dev/zero of=$OOS count=$((ORIGFREE * 120 / 100)) bs=1k 2> $LOG; then
        echo "ERROR: dd did not fail"
        SUCCESS=0
 fi
 
+[ ! -s "$LOG" ] && error "LOG file is empty!"
+
 if [ "`grep -c 'No space left on device' $LOG`" -ne 1 ]; then
        echo "ERROR: dd not return ENOSPC"
        sed "s/^/LOG: /" $LOG
@@ -52,17 +55,9 @@ fi
 # flush cache to OST(s) so avail numbers are correct
 sync; sleep 1 ; sync
 
-for OSC in /proc/fs/lustre/osc/*-osc-*; do
-       AVAIL=`cat $OSC/kbytesavail`
-       GRANT=$((`cat $OSC/cur_grant_bytes` / 1024))
-       echo -n "$(basename $OSC) avl=$AVAIL grnt=$GRANT diff=$(($AVAIL - $GRANT))"
-       [ $(($AVAIL - $GRANT)) -lt 400 ] && OSCFULL=full && echo -n " FULL"
-       echo " "
-done
-
-if [ -z "$OSCFULL" ]; then
+echo AFTER dd
+if ! oos_full; then
        echo "no OSTs are close to full"
-       grep "[0-9]" /proc/fs/lustre/osc/*-osc-*/{kbytesavail,cur*}
        SUCCESS=0
 fi
 
@@ -77,13 +72,15 @@ elif [ "$RECORDSOUT" -ne $((FILESIZE / 1024)) ]; then
        SUCCESS=0
 fi
 
-#lctl debug_daemon stop
+#$LCTL debug_daemon stop
 
+[ $SUCCESS != 0 ] && echo LOG file && sed "s/^/LOG: /" $LOG
 rm -f $OOS
-sync; sleep 1; sync
 
 sync; sleep 3; sync
 
+wait_delete_completed 300
+
 if [ $SUCCESS -eq 1 ]; then
        echo "Success!"
        rm -f $LOG