Whamcloud - gitweb
b=18468
[fs/lustre-release.git] / lustre / tests / oos2.sh
1 #!/bin/bash
2
3 set -e
4
5 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
6 . $LUSTRE/tests/test-framework.sh
7
8 export PATH=$LUSTRE/utils:$PATH
9 LFS=${LFS:-lfs}
10 LCTL=${LCTL:-lctl}
11 MOUNT=${MOUNT:-$1}
12 MOUNT=${MOUNT:-/mnt/lustre}
13 MOUNT2=${MOUNT2:-$2}
14 MOUNT2=${MOUNT2:-${MOUNT}2}
15 OOS=$MOUNT/oosfile
16 OOS2=$MOUNT2/oosfile2
17 TMP=${TMP:-/tmp}
18 LOG=$TMP/$(basename $0 .sh).log
19 LOG2=${LOG}2
20
21 SUCCESS=1
22
23 rm -f $OOS $OOS2 $LOG $LOG2
24
25 sync; sleep 1; sync     # to ensure we get up-to-date statfs info
26
27 STRIPECOUNT=`$LCTL get_param -n lov.*.activeobd | head -n 1`
28 ORIGFREE=`$LCTL get_param -n llite.*.kbytesavail | head -n 1`
29 MAXFREE=${MAXFREE:-$((400000 * $STRIPECOUNT))}
30 echo STRIPECOUNT=$STRIPECOUNT ORIGFREE=$ORIGFREE MAXFREE=$MAXFREE
31 if [ $ORIGFREE -gt $MAXFREE ]; then
32         skip "$0: ${ORIGFREE}kB free gt MAXFREE ${MAXFREE}kB, increase $MAXFREE (or reduce test fs size) to proceed"
33         exit 0
34 fi
35
36 export LANG=C LC_LANG=C # for "No space left on device" message
37
38 # make sure we stripe over all OSTs to avoid OOS on only a subset of OSTs
39 $LFS setstripe $OOS -c $STRIPECOUNT
40 $LFS setstripe $OOS2 -c $STRIPECOUNT
41 dd if=/dev/zero of=$OOS count=$((3 * $ORIGFREE / 4 + 100)) bs=1k 2>> $LOG &
42 DDPID=$!
43 if dd if=/dev/zero of=$OOS2 count=$((3*$ORIGFREE/4 + 100)) bs=1k 2>> $LOG2; then
44         echo "ERROR: dd2 did not fail"
45         SUCCESS=0
46 fi
47 if wait $DDPID; then
48         echo "ERROR: dd did not fail"
49         SUCCESS=0
50 fi
51
52 [ ! -s "$LOG" ] && error "LOG file is empty!"
53 [ ! -s "$LOG2" ] && error "LOG2 file is empty!"
54
55 if [ "`cat $LOG $LOG2 | grep -c 'No space left on device'`" -ne 2 ]; then
56         echo "ERROR: dd not return ENOSPC"
57         SUCCESS=0
58 fi
59
60 # flush cache to OST(s) so avail numbers are correct
61 sync; sleep 1 ; sync
62
63 for OSC in `$LCTL get_param -N osc.*-osc-*.kbytesavail | cut -d"." -f1-2`; do
64         AVAIL=`$LCTL get_param -n $OSC.kbytesavail`
65         GRANT=$((`$LCTL get_param -n $OSC.cur_grant_bytes` / 1024))
66         echo -n "$(echo $OSC | cut -d"." -f2) avl=$AVAIL grnt=$GRANT diff=$(($AVAIL - $GRANT))"
67         [ $(($AVAIL - $GRANT)) -lt 400 ] && OSCFULL=full && echo -n " FULL"
68         echo " "
69 done
70
71 # FIXME - This test reports false failures
72 # The grants from multiple clients need to be added together and compared 
73 # against the kbytesavail.
74 #/proc/fs/lustre/osc/lustre-OST0001-osc-c3b04200/kbytesavail:16248
75 #/proc/fs/lustre/osc/lustre-OST0001-osc-c3b04200/cur_grant_bytes:4313088
76 #/proc/fs/lustre/osc/lustre-OST0001-osc-c3b04e00/cur_grant_bytes:12660736
77
78 if [ -z "$OSCFULL" ]; then
79         echo "no OSTs are close to full"
80         $LCTL get_param "osc.*-osc-*.kbytesavail"
81         $LCTL get_param "osc.*-osc-*.cur*"
82         SUCCESS=0
83 fi
84
85 RECORDSOUT=$((`grep "records out" $LOG | cut -d+ -f 1` + \
86               `grep "records out" $LOG2 | cut -d+ -f 1`))
87
88 FILESIZE=$((`ls -l $OOS | awk '{print $5}'` + `ls -l $OOS2 | awk '{print $5}'`))
89 if [ "$RECORDSOUT" -ne $(($FILESIZE / 1024)) ]; then
90         echo "ERROR: blocks written by dd not equal to the size of file"
91         SUCCESS=0
92 fi
93
94 echo LOG LOG2 file
95 cat $LOG $LOG2
96
97 rm -f $OOS $OOS2
98 sync; sleep 1; sync
99
100 if [ $SUCCESS -eq 1 ]; then
101         echo "Success!"
102         rm -f $LOG $LOG2
103 else
104         exit 1
105 fi