Whamcloud - gitweb
b=14512
[fs/lustre-release.git] / lustre / tests / oos.sh
1 #!/bin/bash
2
3 set -e
4 #set -vx
5
6 export PATH=`dirname $0`/../utils:$PATH
7 LFS=${LFS:-lfs}
8 MOUNT=${MOUNT:-$1}
9 MOUNT=${MOUNT:-/mnt/lustre}
10 OOS=$MOUNT/oosfile
11 TMP=${TMP:-/tmp}
12 LOG=$TMP/ooslog
13
14 SUCCESS=1
15
16 rm -f $OOS $LOG
17
18 sync; sleep 1; sync     # to ensure we get up-to-date statfs info
19
20 #echo -1 > /proc/sys/lnet/debug
21 #echo 0x40a8 > /proc/sys/lnet/subsystem_debug
22 #lctl clear
23 #lctl debug_daemon start /r/tmp/debug 1024
24
25 STRIPECOUNT=`cat /proc/fs/lustre/lov/*/activeobd | head -n 1`
26 ORIGFREE=`cat /proc/fs/lustre/llite/*/kbytesavail | head -n 1`
27 MAXFREE=${MAXFREE:-$((400000 * $STRIPECOUNT))}
28 if [ $ORIGFREE -gt $MAXFREE ]; then
29         echo "skipping out-of-space test on $OSC"
30         echo "reports ${ORIGFREE}kB free, more than MAXFREE ${MAXFREE}kB"
31         echo "increase $MAXFREE (or reduce test fs size) to proceed"
32         exit 0
33 fi
34
35 export LANG=C LC_LANG=C # for "No space left on device" message
36
37 [ -f $LOG ] && echo "ERROR: log file wasn't removed?" && exit 1
38
39 # make sure we stripe over all OSTs to avoid OOS on only a subset of OSTs
40 $LFS setstripe $OOS -c $STRIPECOUNT
41 if dd if=/dev/zero of=$OOS count=$(($ORIGFREE + 100)) bs=1k 2> $LOG; then
42         echo "ERROR: dd did not fail"
43         SUCCESS=0
44 fi
45
46 if [ "`grep -c 'No space left on device' $LOG`" -ne 1 ]; then
47         echo "ERROR: dd not return ENOSPC"
48         sed "s/^/LOG: /" $LOG
49         SUCCESS=0
50 fi
51
52 # flush cache to OST(s) so avail numbers are correct
53 sync; sleep 1 ; sync
54
55 for OSC in /proc/fs/lustre/osc/*-osc-*; do
56         AVAIL=`cat $OSC/kbytesavail`
57         GRANT=$((`cat $OSC/cur_grant_bytes` / 1024))
58         echo -n "$(basename $OSC) avl=$AVAIL grnt=$GRANT diff=$(($AVAIL - $GRANT))"
59         [ $(($AVAIL - $GRANT)) -lt 400 ] && OSCFULL=full && echo -n " FULL"
60         echo " "
61 done
62
63 if [ -z "$OSCFULL" ]; then
64         echo "no OSTs are close to full"
65         grep "[0-9]" /proc/fs/lustre/osc/*-osc-*/{kbytesavail,cur*}
66         SUCCESS=0
67 fi
68
69 RECORDSOUT=`grep "records out" $LOG | cut -d + -f1`
70 FILESIZE=`ls -l $OOS | awk '{ print $5 }'`
71 if [ -z "$RECORDSOUT" ]; then
72         echo "ERROR: no blocks written by dd?"
73         sed "s/^/LOG: /" $LOG
74         SUCCESS=0
75 elif [ "$RECORDSOUT" -ne $((FILESIZE / 1024)) ]; then
76         echo "ERROR: blocks written by dd not equal to the size of file"
77         SUCCESS=0
78 fi
79
80 #lctl debug_daemon stop
81
82 rm -f $OOS
83 sync; sleep 1; sync
84
85 sync; sleep 3; sync
86
87 if [ $SUCCESS -eq 1 ]; then
88         echo "Success!"
89         rm -f $LOG
90 else
91         exit 1
92 fi