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