vlmcd: Complete pending requests after "flushing"
[archipelago] / xseg / launch
1 #!/bin/bash
2
3 # Copyright 2012 GRNET S.A. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or
6 # without modification, are permitted provided that the following
7 # conditions are met:
8 #
9 #   1. Redistributions of source code must retain the above
10 #      copyright notice, this list of conditions and the following
11 #      disclaimer.
12 #
13 #   2. Redistributions in binary form must reproduce the above
14 #      copyright notice, this list of conditions and the following
15 #      disclaimer in the documentation and/or other materials
16 #      provided with the distribution.
17 #
18 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 #
31 # The views and conclusions contained in the software and
32 # documentation are those of the authors and should not be
33 # interpreted as representing official policies, either expressed
34 # or implied, of GRNET S.A.
35 #
36
37
38 NI_SAVED=${NONINTERACTIVE}
39 export NONINTERACTIVE=1
40 source envsetup
41 export NONINTERACTIVE=${NI_SAVED}
42
43 set +e
44
45 function pretty_print {
46         echo "======================="
47         echo "$1"
48         echo "======================="
49 }
50
51 function fail {
52         echo "${1}"
53         exit 1
54 }
55
56 function parse_config {
57         [ -e ~/.xsegrc ] && source ~/.xsegrc
58
59         [ -z "${HOSTNAME}" ] && HOSTNAME=`hostname`
60         [ -z "${XSEG_HOME}" ] && XSEG_HOME="/root/archip/xseg"
61         [ -z "${MODULES_DIR}" ] && MODULES_DIR="${XSEG_HOME}/lib/kernel"
62         [ -z "${SPEC}" ] && SPEC="segdev:xsegbd:512:1024:12"
63         [ -z "${REQS}" ] && REQS=512
64         [ -z "${PORTS}" ] && PORTS=512
65         [ -z "${IMAGES}" ] && IMAGES="/home/user/archip/xseg/peers/user/foo"
66         [ -z "${MAPS}" ] && MAPS="/home/user/archip/xseg/peers/user/foo"
67         [ -z "${PITHOS}" ] && PITHOS="/srv/pithos/data/blocks"
68         [ -z "${PITHOSMAPS}" ] && PITHOSMAPS="/srv/pithos/data/maps"
69         [ -z "${XSEG_LOGS}" ] && XSEG_LOGS="/srv/archip/logs"
70         [ -z "${DEVICE_PREFIX}" ] && DEVICE_PREFIX="/dev/xsegbd"
71         [ -z "${XSEGBD_SYSFS}" ] && XSEGBD_SYSFS="/sys/bus/xsegbd"
72         [ -z "${CHRDEV_NAME}" ] && CHRDEV_NAME="/dev/`cat /proc/devices | grep segdev | awk '{print $2}'`"
73         [ "${CHRDEV_NAME}" = "/dev/" ] && CHRDEV_NAME="/dev/segdev"
74         [ -z "${CHRDEV_MAJOR}" ] && CHRDEV_MAJOR=`cat /proc/devices | grep segdev | awk '{print $1}'`
75         [ -z "${CHRDEV_MAJOR}" ] && CHRDEV_MAJOR=60
76         [ -z "${NR_OPS}" ] && NR_OPS=128
77         [ -z "${BPORT}" ] && BPORT=0
78         [ -z "${VPORT_START}" ] && VPORT_START=4
79         [ -z "${VPORT_END}" ] && VPORT_END=200
80         [ -z "${MPORT}" ] && MPORT=1
81         [ -z "${MBPORT}" ] && MBPORT=2
82         [ -z "${VTOOL}" ] && VTOOL=3
83 }
84
85
86 function unload_module {
87         rmmod "$1"
88 }
89
90 function unload_all {
91         unload_module "xsegbd"
92         rm "${CHRDEV_NAME}" || true
93         unload_module "xseg_segdev"
94         unload_module "xseg_posix"
95         unload_module "xseg_pthread"
96         unload_module "segdev"
97         unload_module "xseg"
98 }
99
100 function load_module {
101         (lsmod | grep "$1" > /dev/null) || insmod "${MODULES_DIR}/$1.ko" "$2" || exit 1
102 }
103
104 function mk_chardev {
105         ls "${CHRDEV_NAME}" &> /dev/null || \
106         mknod "${CHRDEV_NAME}" c "${CHRDEV_MAJOR}" 0 || exit 1
107 }
108
109 function load_all {
110         load_module "xseg"
111         load_module "segdev"
112         load_module "xseg_posix"
113         load_module "xseg_pthread"
114         load_module "xseg_segdev"
115         mk_chardev
116     "${XSEG_HOME}/peers/user/xseg" "${SPEC}" create || true
117         load_module "xsegbd" "spec=$SPEC"
118 }
119
120 function create_segment {
121         "${XSEG_HOME}/peer/users/xseg" "${SPEC}" create
122 }
123
124 function destroy_segment {
125         "${XSEG_TOOL}" "${SPEC}" destroy
126 }
127
128 function alloc_requests {
129         "${XSEG_TOOL}" "${SPEC}" $1 alloc_requests $2
130 }
131
132 function free_requests {
133         "${XSEG_TOOL}" "${SPEC}" $1 free_requests $2
134 }
135
136 function spawn_filed {
137         pgrep -f "peers/user/filed" || \
138         "${XSEG_HOME}/peers/user/filed" "$IMAGES" -p "$BPORT" -g "${SPEC}" -n \
139         ${NR_OPS}  &> "${XSEG_LOGS}/filed-${HOSTNAME}" &
140 }
141
142 function spawn_pfiled {
143         "${XSEG_HOME}/peers/user/pfiled" -p "$BPORT" -g "${SPEC}" -n \
144         ${NR_OPS} "${PITHOS}" "${IMAGES}" -v 1 &> "${XSEG_LOGS}/pfiled-${HOSTNAME}" &
145 }
146
147 function spawn_pfiledm {
148         "${XSEG_HOME}/peers/user/pfiled" -p "$MBPORT" -g "${SPEC}" -n \
149         ${NR_OPS} "${PITHOSMAPS}" "${MAPS}" -v 1  &> "${XSEG_LOGS}/pfiledm-${HOSTNAME}" &
150 }
151
152 function spawn_sosd {
153         "${XSEG_HOME}/peers/user/mt-sosd" -p "$BPORT" -g "${SPEC}" -n \
154         ${NR_OPS} --pool "blocks" -v 3 &> "${XSEG_LOGS}/sosd-${HOSTNAME}" &
155 }
156
157 function spawn_sosdm {
158         "${XSEG_HOME}/peers/user/mt-sosd" -p "$MBPORT" -g "${SPEC}" -n \
159         ${NR_OPS} --pool "maps" -v 3  &> "${XSEG_LOGS}/sosdm-${HOSTNAME}" &
160 }
161
162 function spawn_vlmcd {
163         pgrep -f "peers/user/st-vlmcd" || \
164         "${XSEG_HOME}/peers/user/st-vlmcd" -t 1 -sp "$VPORT_START" \
165         -ep "$VPORT_END" -bp "$BPORT" -mp "$MPORT" -g \
166         "${SPEC}" -n ${NR_OPS} -v 3 &> "${XSEG_LOGS}/vlmcd-${HOSTNAME}" &
167 #       alloc_requests "$VPORT:0" 128
168 }
169
170 function spawn_mapperdc {
171         echo "\"${XSEG_HOME}/peers/user/mt-mapperd\" -t 1 -sp \"$MPORT\" -ep
172         \"$MPORT\" -bp \"$BPORT\" -mbp \"$MBPORT\" -g \"${SPEC}\" -n ${NR_OPS} -v 3" 
173         pgrep -f "mt-mapperd" || \
174         "${XSEG_HOME}/peers/user/mt-mapperd" -t 1 -sp "$MPORT" -ep "$MPORT"\
175         -bp "$BPORT" -mbp "$MBPORT" -g "${SPEC}"\
176         -n ${NR_OPS} -v 3 &> "${XSEG_LOGS}/mapperd-${HOSTNAME}" & 
177 #       alloc_requests "$MPORT:0" 128
178 }
179
180 function spawn_mapperd {
181         pgrep -f "mapperd.py" || \
182         "${XSEG_HOME}/peers/user/mapperd.py" -p "$MPORT" -b "$BPORT" -g "${SPEC}" \
183         &> "${XSEG_LOGS}/mapperd-${HOSTNAME}" &
184 #       alloc_requests "$MPORT:0" 128
185 }
186
187 # map_volume - Map a volume to an xsegbd device
188 #
189 # @param $1             target/volume name
190 # @param $2             src port
191 # @param $3             dst port
192 function map_volume {
193         echo "$1 $2:$3:${REQS}" > "${XSEGBD_SYSFS}/add" || exit 1
194 }
195
196 # unmap_device - Unmap an xsegbd device/volume
197 #
198 # @param $1             xsegbd device id
199 function unmap_device {
200         echo "$1" > "${XSEGBD_SYSFS}/remove" || exit 1
201 }
202
203 function help {
204         echo "Usage: ./launch [list | <configuration> [start | stop] | insmod | rmmod]"
205 }
206
207 if [ -n "$NONINTERACTIVE" ]; then
208         exit 0
209 fi
210
211 parse_config
212 XSEG_TOOL="${XSEG_HOME}/peers/user/xseg"
213
214 case $1 in
215 list)
216         echo "filed [start|stop]"
217         echo "map [start|stap]"
218         echo " "
219         echo "insmod"
220         echo "rmmod"
221         ;;
222 insmod)
223         load_all
224         mk_chardev
225         ;;
226 rmmod)
227         rm ${CHRDEV_NAME}
228         unload_all
229         ;;
230 config)
231         echo "HOSTNAME=${HOSTNAME}"
232         echo "XSEG_HOME=${XSEG_HOME}"
233         echo "MODULES_DIR=${MODULES_DIR}"
234         echo "SPEC=${SPEC}"
235         echo "REQS=${REQS}"
236         echo "PORTS=${PORTS}"
237         echo "IMAGES=${IMAGES}"
238         echo "PITHOS=${PITHOS}"
239         echo "XSEG_LOGS=${XSEG_LOGS}"
240         echo "DEVICE_PREFIX=${DEVICE_PREFIX}"
241         echo "XSEGBD_SYSFS=${XSEGBD_SYSFS}"
242         echo "CHRDEV_NAME=${CHRDEV_NAME}"
243         echo "CHRDEV_MAJOR=${CHRDEV_MAJOR}"
244         echo "NR_OPS=${NR_OPS}"
245         echo "BPORT=${BPORT}"
246         echo "VPORT=${VPORT}"
247         echo "MPORT=${MPORT}"
248         ;;
249 filed)
250         case $2 in
251         start)
252                 load_all
253                 sleep 0.5
254                 spawn_filed
255                 sleep 0.5
256                 map_volume xsegvol 3 0
257                 ;;
258         stop)
259                 pkill -f peers/user/filed
260                 sleep 0.5
261                 unmap_device 3
262                 unload_all
263                 ;;
264         esac
265         ;;
266 map)
267         case $2 in
268         start)
269                 load_all
270                 sleep 0.5
271                 spawn_pfiled
272                 spawn_mapperd
273                 spawn_vlmcd
274                 ;;
275         stop)
276                 pkill -f peers/user/mt-vlmcd || true
277 #               free_requests "$VPORT:0" 128 || true
278                 pkill -f peers/user/mt-mapperd || true
279 #               free_requests "$MPORT:0" 128 || true
280                 pkill -f peers/user/pfiled || true
281                 sleep 0.5
282                 unload_all
283                 ;;
284         *)
285                 help
286                 ;;
287         esac
288         ;;
289 nomodules)
290         case $2 in
291         start)
292                 spawn_filed
293                 spawn_mapperd
294                 spawn_vlmcd
295                 ;;
296         stop)
297                 pkill -f peers/user/mt-vlmcd || true
298 #               free_requests "$VPORT:0" 128 || true
299                 pkill -f peers/user/mt-mapperd || true
300 #               free_requests "$MPORT:0" 128 || true
301                 pkill -f peers/user/filed || true
302                 ;;
303         *)
304                 help
305                 ;;
306         esac
307         ;;
308 one)
309         case $2 in
310         start)
311                 load_all
312                 sleep 1
313                 spawn_filed 
314                 spawn_mapperdc
315                 spawn_vlmcd 
316                 ;;
317         stop)
318                 pkill -f peers/user/mt-vlmcd || true
319 #               free_requests "$VPORT:0" 128 || true
320                 pkill -f peers/user/mt-mapperd || true
321 #               free_requests "$MPORT:0" 128 || true
322                 pkill -f peers/user/filed || true
323                 sleep 0.5
324                 unload_all
325                 ;;
326         *)
327                 help
328                 ;;
329         esac
330         ;;
331 doublemap)
332         case $2 in
333         start)
334                 load_all
335                 sleep 0.5
336                 spawn_pfiled
337                 spawn_pfiledm
338                 spawn_mapperdc
339                 spawn_vlmcd
340                 ;;
341         stop)
342                 pkill -f peers/user/st-vlmcd || true
343 #               free_requests "$VPORT:0" 128 || true
344                 pkill -f peers/user/mt-mapperd || true
345 #               free_requests "$MPORT:0" 128 || true
346                 pkill -f peers/user/pfiled || true
347                 sleep 0.5
348                 unload_all
349                 ;;
350         *)
351                 help
352                 ;;
353         esac
354         ;;
355 mapperd)
356         case $2 in
357         start)
358                 spawn_mapperdc
359                 ;;
360         stop)
361                 pkill -f peers/user/mt-mapperd || true
362                 ;;
363         *)
364                 help
365                 ;;
366         esac
367         ;;
368 doublesosd)
369         case $2 in
370         start)
371                 load_all
372                 sleep 0.5
373                 spawn_sosd
374                 spawn_sosdm
375                 spawn_mapperdc
376                 spawn_vlmcd
377                 ;;
378         stop)
379                 pkill -f peers/user/st-vlmcd || true
380 #               free_requests "$VPORT:0" 128 || true
381                 pkill -f peers/user/mt-mapperd || true
382 #               free_requests "$MPORT:0" 128 || true
383                 pkill -f peers/user/mt-sosd || true
384                 sleep 0.5
385                 unload_all
386                 ;;
387         *)
388                 help
389                 ;;
390         esac
391         ;;
392 mtmapperd)
393         case $2 in
394         start)
395                 spawn_mapperdc
396                 ;;
397         stop)
398                 pkill -f peers/user/mt-mapperd || true
399                 ;;
400         *)
401                 help
402                 ;;
403         esac
404         ;;
405 *)
406         help
407         ;;
408 esac