Whamcloud - gitweb
b=23049 various t-f.sh patches
[fs/lustre-release.git] / lustre / tests / obdfilter-survey.sh
1 #!/bin/bash
2 #set -x
3 set -e
4
5 LUSTRE=${LUSTRE:-`dirname $0`/..}
6 . $LUSTRE/tests/test-framework.sh
7 init_test_env $@
8
9 nobjhi=${nobjhi:-1}
10 thrhi=${thrhi:-16} 
11 size=${size:-1024}
12
13 # the summary file a bit smaller than OSTSIZE  
14 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
15
16 [ "$SLOW" = no ] && { nobjhi=1; thrhi=4; }
17 thrlo=${thrlo:-$(( thrhi / 2))}
18
19 # Skip these tests
20 ALWAYS_EXCEPT="$OBDFILTER_SURVEY_EXCEPT"
21
22 OBDSURVEY=${OBDSURVEY:-$(which obdfilter-survey)}
23
24 build_test_filter
25 check_and_setup_lustre
26
27 min_ost_size () {
28     $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
29 }
30
31 # FIXME: the summary file a bit smaller than OSTSIZE, add estimation
32 minsize=$(min_ost_size)
33 if [ $(( size * 1024 )) -ge $minsize  ]; then
34     size=$((minsize * 10 / 1024 / 12 ))
35     echo min kbytesavail: $minsize using size=${size} MBytes per obd instance
36 fi
37
38 get_targets () {
39         local targets
40         local devs
41         local oss
42
43         for oss in $(osts_nodes); do
44                 devs=$(do_node $oss "lctl dl |grep obdfilter |sort" | awk '{print $4}')
45                 for d in $devs; do
46                         # if oss is local -- obdfilter-survey needs dev wo/ host
47                         target=$d
48                         [[ $oss = `hostname` ]] || target=$oss:$target
49                         targets="$targets $target"
50                 done
51         done
52
53         echo $targets
54 }
55
56 obdflter_survey_targets () {
57         local case=$1
58         local targets
59
60         case $case in
61                 disk)    targets=$(get_targets);;
62                 netdisk) targets=$(get_targets);;
63                 network) targets="$(osts_nodes)";;
64                 *) error "unknown obdflter-survey case!" ;;
65         esac
66         echo $targets
67 }
68
69 obdflter_survey_run () {
70         local case=$1
71
72         rm -f ${TMP}/obdfilter_survey*
73
74         local targets=$(obdflter_survey_targets $case)
75         local cmd="NETTYPE=$NETTYPE thrlo=$thrlo nobjhi=$nobjhi thrhi=$thrhi size=$size case=$case rslt_loc=${TMP} targets=\"$targets\" $OBDSURVEY"
76         echo + $cmd
77         eval $cmd
78
79         cat ${TMP}/obdfilter_survey*
80 }
81 test_1a () {
82         obdflter_survey_run disk
83 }
84 run_test 1a "Object Storage Targets survey"
85
86 print_jbd () {
87         local file=$1
88         local facet=$2
89         local varsvc=${facet}_svc
90         local dev=$(basename $(do_facet $facet lctl get_param -n *.${!varsvc}.mntdev))
91
92         # ext4: /proc/fs/jbd2/sda1:8/history 
93         # ext3: /proc/fs/jbd/sdb1/history
94
95         do_facet $facet cat /proc/fs/jbd*/${dev}*/$file
96 }
97
98 check_jbd_values () {
99         local facet=$1
100         local thrhi=$2
101
102         # last two lines from history
103         # $4: run >= 5000
104         # $8: hndls >= thrhi * 2
105         local hist=("$(print_jbd history $facet | tail -3 | head -2)")
106         echo "$hist"
107         local run=($(echo "${hist[*]}" | awk '{print $4}'))
108         local hndls=($(echo "${hist[*]}" | awk '{print $8}'))
109
110         local rc=0
111         for (( i=0; i<1; i++)); do
112                 [[ ${run[i]} -lt 5000 ]] && \
113                         error "$facet: run expected 5000, have ${run[i]}" && rc=1
114                 [[ ${hndls[i]} -lt $((thrhi * 2)) ]] && \
115                         error "$facet: hndls expected > $((thrhi * 2)), have ${hndls[i]}" && rc=2
116         done
117         return $rc
118 }
119
120 check_jbd_values_facets () {
121         local facets=$1
122         local thrhi=$2
123         local facet
124         local rc=0
125         for facet in  ${facets//,/ }; do
126                 check_jbd_values $facet $thrhi || rc=$((rc+$?))
127         done
128         return $rc
129 }
130
131 test_1b () {
132         local major=$(get_mds_kernel_major)
133         local minor=$(get_mds_kernel_minor)
134         [ "$major"=="2.6" -a $minor -eq 32 ]  && \
135                 skip "There is no jbd history in this kernel version." && return
136         local param_file=$TMP/$tfile-params
137
138         do_nodesv $(comma_list $(osts_nodes)) lctl get_param obdfilter.${FSNAME}-*.sync_journal
139
140         save_lustre_params $(comma_list $(osts_nodes)) "obdfilter.${FSNAME}-*.sync_journal" >$param_file
141         do_nodesv $(comma_list $(osts_nodes)) lctl set_param obdfilter.${FSNAME}-*.sync_journal=0
142
143         thrlo=4 nobjhi=1 thrhi=4 obdflter_survey_run disk
144
145         check_jbd_values_facets $(get_facets OST) 4 || rc=$((rc+$?))
146
147         restore_lustre_params < $param_file
148
149         rm -f $param_file
150         return $rc
151 }
152 run_test 1b "Object Storage Targets survey, async journal"
153
154 test_2a () {
155         obdflter_survey_run netdisk
156 }
157 run_test 2a "Stripe F/S over the Network"
158
159 test_2b () {
160         local major=$(get_mds_kernel_major)
161         local minor=$(get_mds_kernel_minor)
162         [ "$major"=="2.6" -a $minor -eq 32 ]  && \
163                 skip "There is no jbd history in this kernel version." && return
164         local param_file=$TMP/$tfile-params
165
166         do_nodesv $(comma_list $(osts_nodes)) lctl get_param obdfilter.${FSNAME}-*.sync_journal
167
168         save_lustre_params $(comma_list $(osts_nodes)) "obdfilter.${FSNAME}-*.sync_journal" >$param_file
169         do_nodesv $(comma_list $(osts_nodes)) lctl set_param obdfilter.${FSNAME}-*.sync_journal=0
170
171         thrlo=4 nobjhi=1 thrhi=4 obdflter_survey_run netdisk
172
173         check_jbd_values_facets $(get_facets OST) 4 || rc=$((rc+$?))
174
175         restore_lustre_params < $param_file
176
177         rm -f $param_file
178         return $rc
179 }
180 run_test 2b "Stripe F/S over the Network, async journal"
181
182
183 # README.obdfilter-survey: In network test only automated run is supported.
184 test_3a () {
185         remote_servers || { skip "Local servers" && return 0; }
186
187         # The Network survey test needs:
188         # Start lctl and check for the device list. The device list must be empty.
189         cleanupall
190
191         obdflter_survey_run network
192
193         setupall
194 }
195 run_test 3a "Network survey"
196
197 equals_msg `basename $0`: test complete, cleaning up
198 cleanup_echo_devs
199 check_and_cleanup_lustre
200 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true