Whamcloud - gitweb
LU-1798 tests: add set_and_check to test-framework
[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 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
8
9 export PATH=$LUSTRE/utils:$PATH
10 LFS=${LFS:-lfs}
11 LCTL=${LCTL:-lctl}
12 MOUNT=${MOUNT:-$1}
13 MOUNT=${MOUNT:-/mnt/lustre}
14 MOUNT2=${MOUNT2:-$2}
15 MOUNT2=${MOUNT2:-${MOUNT}2}
16 OOS=$MOUNT/oosfile
17 OOS2=$MOUNT2/oosfile2
18 TMP=${TMP:-/tmp}
19 LOG=$TMP/$(basename $0 .sh).log
20 LOG2=${LOG}2
21
22 SUCCESS=1
23
24 rm -f $OOS $OOS2 $LOG $LOG2
25
26 sync; sleep 1; sync     # to ensure we get up-to-date statfs info
27
28 STRIPECOUNT=`$LCTL get_param -n lov.*.activeobd | head -n 1`
29 ORIGFREE=`$LCTL get_param -n llite.*.kbytesavail | head -n 1`
30 MAXFREE=${MAXFREE:-$((400000 * $STRIPECOUNT))}
31 echo STRIPECOUNT=$STRIPECOUNT ORIGFREE=$ORIGFREE MAXFREE=$MAXFREE
32 if [ $ORIGFREE -gt $MAXFREE ]; then
33         skip "$0: ${ORIGFREE}kB free gt MAXFREE ${MAXFREE}kB, increase $MAXFREE (or reduce test fs size) to proceed"
34         exit 0
35 fi
36
37 export LANG=C LC_LANG=C # for "No space left on device" message
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 $LFS setstripe $OOS2 -c $STRIPECOUNT
42 dd if=/dev/zero of=$OOS count=$((3 * $ORIGFREE / 4 + 100)) bs=1k 2>> $LOG &
43 DDPID=$!
44 if dd if=/dev/zero of=$OOS2 count=$((3*$ORIGFREE/4 + 100)) bs=1k 2>> $LOG2; then
45         echo "ERROR: dd2 did not fail"
46         SUCCESS=0
47 fi
48 if wait $DDPID; then
49         echo "ERROR: dd did not fail"
50         SUCCESS=0
51 fi
52
53 [ ! -s "$LOG" ] && error "LOG file is empty!"
54 [ ! -s "$LOG2" ] && error "LOG2 file is empty!"
55
56 if [ "`cat $LOG $LOG2 | grep -c 'No space left on device'`" -ne 2 ]; then
57         echo "ERROR: dd not return ENOSPC"
58         SUCCESS=0
59 fi
60
61 # flush cache to OST(s) so avail numbers are correct
62 sync; sleep 1 ; sync
63
64 if ! oos_full; then
65         echo "no OSTs are close to full"
66         SUCCESS=0
67 fi
68
69 RECORDSOUT=$((`grep "records out" $LOG | cut -d+ -f 1` + \
70               `grep "records out" $LOG2 | cut -d+ -f 1`))
71
72 FILESIZE=$((`ls -l $OOS | awk '{print $5}'` + `ls -l $OOS2 | awk '{print $5}'`))
73 if [ "$RECORDSOUT" -ne $(($FILESIZE / 1024)) ]; then
74         echo "ERROR: blocks written by dd not equal to the size of file"
75         SUCCESS=0
76 fi
77
78 echo LOG LOG2 file
79 cat $LOG $LOG2
80
81 rm -f $OOS $OOS2
82 sync; sleep 1; sync
83
84 if [ $SUCCESS -eq 1 ]; then
85         echo "Success!"
86         rm -f $LOG $LOG2
87 else
88         exit 1
89 fi