Whamcloud - gitweb
b=21890 Remove bash -TE flags from acceptance-small.sh
[fs/lustre-release.git] / lustre / tests / qos.sh
1 #!/bin/bash
2
3 set -e
4
5 export PATH=`dirname $0`/../utils:$PATH
6
7 LFS=${LFS:-lfs}
8 LCTL=${LCTL:-lctl}
9 MOUNT=${MOUNT:-/mnt/lustre}
10 MAXAGE=${MAXAGE:-1}
11
12 QOSFILE=$MOUNT/qos_file
13 TAB='--'
14
15 echo "remove all files on $MOUNT..."
16 rm -fr $MOUNT/*
17 sleep 1         # to ensure we get up-to-date statfs info
18
19 set_qos() {
20         for i in `ls /proc/fs/lustre/lov/*/qos_threshold`; do
21                 echo $(($1/1024)) > $i 
22         done
23         for i in `ls /proc/fs/lustre/lov/*/qos_maxage`; do
24                 echo $2 > $i
25         done
26 }
27
28 # assume all osts has same free space 
29 OSTCOUNT=`cat /proc/fs/lustre/lov/*/activeobd | head -n 1`
30 TOTALAVAIL=`cat /proc/fs/lustre/llite/*/kbytesavail | head -n 1`
31 SINGLEAVAIL=$(($TOTALAVAIL/$OSTCOUNT))
32 MINFREE=$((1024 * 4))   # 4M
33 TOTALFFREE=`cat /proc/fs/lustre/llite/*/filesfree | head -n 1`
34
35 if [ $SINGLEAVAIL -lt $MINFREE ]; then
36         echo "ERROR: single ost free size($SINGLEAVAIL kb) is too low!"
37         exit 1;
38 fi
39 if [ $OSTCOUNT -lt 3 ]; then
40         echo "WARN: ost count($OSTCOUNT) must be greater than 2!"
41         exit 0;
42 fi
43
44 qos_test_1() {
45         echo "[qos test 1]: creation skip almost full OST (avail space < threshold)"
46
47         # set qos_threshold as half ost size
48         THRESHOLD=$(($SINGLEAVAIL/2))
49         set_qos $THRESHOLD $MAXAGE
50
51         # set stripe number to 1
52         $LFS setstripe $QOSFILE 65536 -1 1
53         FULLOST=`$LFS getstripe -q $QOSFILE | awk '/\s*\d*/ {print $1}'`
54         
55         # floodfill the FULLOST
56         echo "$TAB fill the OST $FULLOST to almost fullness..."
57         dd if=/dev/zero of=$QOSFILE count=$(($SINGLEAVAIL - $THRESHOLD + 1500)) bs=1k > /dev/null 2>&1 || return 1
58         echo "$TAB done"
59         
60         sleep $(($MAXAGE * 2))
61         echo "$TAB create 10 files with 1 stripe"
62         for i in `seq 10`; do
63                 rm -f $MOUNT/file-$i
64                 $LFS setstripe $MOUNT/file-$i 65536 -1 1
65                 idx=`$LFS getstripe -q $MOUNT/file-$i | awk '/\s*\d*/ {print $1}'`
66                 if [ $idx -eq $FULLOST ]; then
67                         echo "$TAB ERROR: create object on full OST $FULLOST"
68                         return 1
69                 fi
70         done
71         echo "$TAB no object created on OST $FULLOST"
72
73         # cleanup
74         for i in `seq 10`; do
75                 rm -f $MOUNT/file-$i
76         done
77         rm -f $QOSFILE
78         # set threshold and maxage to normal value
79         set_qos 10240 1
80         
81         sleep 1
82         return 0
83 }
84
85 qos_test_2 () {
86         echo "[qos test 2]: creation balancing over all OSTs by free space"
87
88         if [ $OSTCOUNT -lt 3 ]; then
89                 echo "$TAB WARN: OST count < 3, test skipped"
90                 return 0
91         fi
92         
93         WADSZ=$(($SINGLEAVAIL * 3 / 4))
94         TOTALSZ=$(($WADSZ * $OSTCOUNT - 1))
95
96         # fill all OST 0 to 3/4 fulness
97         $LFS setstripe $QOSFILE 65536 0 1
98         echo "$TAB fill the OST 0 to 3/4 fulness..."
99         dd if=/dev/zero of=$QOSFILE count=$WADSZ bs=1k > /dev/null 2>&1 || return 1
100         echo "$TAB done"
101
102         # write 2 stripe files to fill up other OSTs
103         LOOPCNT=500
104         echo "$TAB create $LOOPCNT files with 2 stripe..."
105         for i in `seq $LOOPCNT`; do
106                 rm -f $MOUNT/file-$i
107                 $LFS setstripe $MOUNT/file-$i 65536 -1 2
108         done
109         echo "$TAB done"
110
111         # the objects created on OST 0 should be 1/4 of on other OSTs'
112         CNT0=`$LFS getstripe -q /mnt/lustre | awk '/\s*\d*/ {print $1}'| grep -c 0`
113         CNT0=$(($CNT0 - 1))
114         echo "$TAB object created on OST 0: $CNT0"
115         
116         # the object count of other osts must be greater than 2 times 
117         CNT0=$(($CNT0 * 2))
118         for i in `seq $(($OSTCOUNT - 1))`; do
119                 CNT=`$LFS getstripe -q /mnt/lustre | awk '/\s*\d*/ {print $1}'| grep -c $i`
120                 echo "$TAB object created on OST $i: $CNT"
121                 if [ $CNT0 -gt $CNT ] ; then
122                         echo "$TAB ERROR: too much objects created on OST 0"
123                         return 1
124                 fi
125         done
126         echo "$TAB objects created on OST 0 is about 1/4 of others'"
127         
128         # cleanup
129         for i in `seq $LOOPCNT`; do
130                 rm -f $MOUNT/file-$i
131         done
132         rm -f $QOSFILE
133         return 0
134 }
135         
136
137 # run tests
138 for j in `seq 2`; do
139         qos_test_$j
140         [ $? -ne 0 ] && exit 1 
141 done
142 exit 0