Whamcloud - gitweb
LU-1538 tests: delete test files from /tmp after use
[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 init_logging
16
17 [ "$SLOW" = no ] && { nobjhi=1; thrhi=4; }
18 thrlo=${thrlo:-$(( thrhi / 2))}
19
20 # Skip these tests
21 # bug number   23791 23791
22 ALWAYS_EXCEPT="1b    2b    $OBDFILTER_SURVEY_EXCEPT"
23
24 OBDSURVEY=${OBDSURVEY:-$(which obdfilter-survey)}
25
26 build_test_filter
27 check_and_setup_lustre
28
29 # FIXME: the summary file a bit smaller than OSTSIZE, add estimation
30 minsize=$(min_ost_size)
31 if [ $(( size * 1024 )) -ge $minsize  ]; then
32     size=$((minsize * 10 / 1024 / 12 ))
33     echo min kbytesavail: $minsize using size=${size} MBytes per obd instance
34 fi
35
36 get_devs() {
37         echo $(do_nodes $1 'lctl dl | grep obdfilter' | \
38              awk '{print $4}' | sort -u)
39 }
40
41 get_targets () {
42         local targets
43         local devs
44         local nid
45         local oss
46
47         for oss in $(osts_nodes); do
48                 devs=$(get_devs $oss)
49                 nid=$(host_nids_address $oss $NETTYPE)
50                 for d in $devs; do
51                         # if oss is local -- obdfilter-survey needs dev wo/ host
52                         target=$d
53                         [[ $oss = `hostname` && "$1" == "netdisk" ]] || target=$nid:$target
54                         targets="$targets $target"
55                 done
56         done
57
58         echo $targets
59 }
60
61 obdflter_survey_targets () {
62         local case=$1
63         local targets
64
65         case $case in
66                 disk)    targets=$(get_targets $case);;
67                 netdisk) targets=$(get_targets $case);;
68                 network) targets=$(host_nids_address $(comma_list $(osts_nodes)) $NETTYPE);;
69                 *) error "unknown obdflter-survey case!" ;;
70         esac
71         echo $targets
72 }
73
74 obdflter_survey_run () {
75         local case=$1
76
77         rm -f ${TMP}/obdfilter_survey*
78
79         local targets=$(obdflter_survey_targets $case)
80         local cmd="NETTYPE=$NETTYPE thrlo=$thrlo nobjhi=$nobjhi thrhi=$thrhi size=$size case=$case rslt_loc=${TMP} targets=\"$targets\" $OBDSURVEY"
81         echo + $cmd
82         eval $cmd
83
84         cat ${TMP}/obdfilter_survey*
85 }
86 test_1a () {
87         obdflter_survey_run disk
88 }
89 run_test 1a "Object Storage Targets survey"
90
91 print_jbd () {
92         local file=$1
93         local facet=$2
94         local varsvc=${facet}_svc
95         local dev=$(ldiskfs_canon "*.${!varsvc}.mntdev" $facet)
96
97         # ext4: /proc/fs/jbd2/sda1:8/history 
98         # ext3: /proc/fs/jbd/sdb1/history
99
100         do_facet $facet cat /proc/fs/jbd*/${dev}*/$file
101 }
102
103 check_jbd_values () {
104         local facet=$1
105         local thrhi=$2
106         local rtime=$3
107
108         # last two lines from history
109         # $4: run >= 5000
110         # $8: hndls >= thrhi * 2
111         # display history of rtime/4 before, in case obd cleanup consumes time
112         local tlines=$((rtime / 5 / 4 + 1))
113         local hist=("$(print_jbd history $facet | tail -$tlines | head -1)")
114         echo "$hist"
115         local run=($(echo "${hist[*]}" | awk '{print $4}'))
116         local hndls=($(echo "${hist[*]}" | awk '{print $8}'))
117
118         local rc=0
119         for (( i=0; i<1; i++)); do
120                 [[ ${run[i]} -lt 5000 ]] && \
121                         error "$facet: run expected 5000, have ${run[i]}" && rc=1
122                 [[ ${hndls[i]} -lt $((thrhi * 2)) ]] && \
123                         error "$facet: hndls expected > $((thrhi * 2)), have ${hndls[i]}" && rc=2
124         done
125         return $rc
126 }
127
128 check_jbd_values_facets () {
129         local facets=$1
130         local thrhi=$2
131         local rtime=$3
132         local facet
133         local rc=0
134         for facet in  ${facets//,/ }; do
135                 check_jbd_values $facet $thrhi $rtime || rc=$((rc+$?))
136         done
137         return $rc
138 }
139
140 test_1b () {
141         local param_file=$TMP/$tfile-params
142
143         do_nodesv $(comma_list $(osts_nodes)) \
144                 $LCTL get_param obdfilter.${FSNAME}-*.sync_journal
145         save_lustre_params $(get_facets OST) \
146                 "obdfilter.${FSNAME}-*.sync_journal" > $param_file
147         do_nodesv $(comma_list $(osts_nodes)) \
148                 $LCTL set_param obdfilter.${FSNAME}-*.sync_journal=0
149
150         local stime=$(date +%s)
151         thrlo=4 nobjhi=1 thrhi=4 obdflter_survey_run disk
152         local etime=$(date +%s)
153         # run time of obd survey
154         local rtime=$((etime - stime))
155
156         echo "obd survey finished in $rtime seconds"
157         check_jbd_values_facets $(get_facets OST) 4 $rtime || rc=$((rc+$?))
158
159         restore_lustre_params < $param_file
160
161         rm -f $param_file
162         return $rc
163 }
164 run_test 1b "Object Storage Targets survey, async journal"
165
166 test_1c () {
167         nobjlo=1 nobjhi=1 thrlo=128 thrhi=128 rszlo=1024 rszhi=1024 size=8192\
168         obdflter_survey_run disk
169 }
170 run_test 1c "Object Storage Targets survey, big batch"
171
172 test_2a () {
173         obdflter_survey_run netdisk
174 }
175 run_test 2a "Stripe F/S over the Network"
176
177 test_2b () {
178         local param_file=$TMP/$tfile-params
179
180         do_nodesv $(comma_list $(osts_nodes)) \
181                 $LCTL get_param obdfilter.${FSNAME}-*.sync_journal
182         save_lustre_params $(get_facets OST) \
183                 "obdfilter.${FSNAME}-*.sync_journal" > $param_file
184         do_nodesv $(comma_list $(osts_nodes)) \
185                 $LCTL set_param obdfilter.${FSNAME}-*.sync_journal=0
186
187         local stime=$(date +%s)
188         thrlo=4 nobjhi=1 thrhi=4 obdflter_survey_run netdisk
189         local etime=$(date +%s)
190         local rtime=$((etime - stime))
191
192         echo "obd survey finished in $rtime seconds"
193         check_jbd_values_facets $(get_facets OST) 4 $rtime || rc=$((rc+$?))
194
195         restore_lustre_params < $param_file
196
197         rm -f $param_file
198         return $rc
199 }
200 run_test 2b "Stripe F/S over the Network, async journal"
201
202
203 # README.obdfilter-survey: In network test only automated run is supported.
204 test_3a () {
205         remote_servers || { skip "Local servers" && return 0; }
206
207         # The Network survey test needs:
208         # Start lctl and check for the device list. The device list must be empty.
209         cleanupall
210
211         obdflter_survey_run network
212
213         setupall
214 }
215 run_test 3a "Network survey"
216
217 complete $SECONDS
218 cleanup_echo_devs
219 check_and_cleanup_lustre
220 exit_status