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