make peers verbose by default
[archipelago] / xseg / launch
1 #!/bin/bash
2 #
3 # Launcher for xseg configurations
4
5 NI_SAVED=${NONINTERACTIVE}
6 export NONINTERACTIVE=1
7 source envsetup
8 export NONINTERACTIVE=${NI_SAVED}
9
10 set +e
11
12 function pretty_print {
13         echo "======================="
14         echo "$1"
15         echo "======================="
16 }
17
18 function fail {
19         echo "${1}"
20         exit 1
21 }
22
23 function parse_config {
24         [ -e ~/.xsegrc ] && source ~/.xsegrc
25
26         [ -z "${HOSTNAME}" ] && HOSTNAME=`hostname`
27         [ -z "${XSEG_HOME}" ] && XSEG_HOME="/root/archip/xseg"
28         [ -z "${MODULES_DIR}" ] && MODULES_DIR="${XSEG_HOME}/lib/kernel"
29         [ -z "${SPEC}" ] && SPEC="segdev:xsegbd:512:1024:12"
30         [ -z "${REQS}" ] && REQS=512
31         [ -z "${PORTS}" ] && PORTS=512
32         [ -z "${IMAGES}" ] && IMAGES="/home/user/archip/xseg/peers/user/foo"
33         [ -z "${MAPS}" ] && MAPS="/home/user/archip/xseg/peers/user/foo"
34         [ -z "${PITHOS}" ] && PITHOS="/srv/pithos/data/blocks"
35         [ -z "${PITHOSMAPS}" ] && PITHOSMAPS="/srv/pithos/data/maps"
36         [ -z "${XSEG_LOGS}" ] && XSEG_LOGS="/home/philipgian/archip/logs"
37         [ -z "${DEVICE_PREFIX}" ] && DEVICE_PREFIX="/dev/xsegbd"
38         [ -z "${XSEGBD_SYSFS}" ] && XSEGBD_SYSFS="/sys/bus/xsegbd"
39         [ -z "${CHRDEV_NAME}" ] && CHRDEV_NAME="/dev/`cat /proc/devices | grep segdev | awk '{print $2}'`"
40         [ "${CHRDEV_NAME}" = "/dev/" ] && CHRDEV_NAME="/dev/segdev"
41         [ -z "${CHRDEV_MAJOR}" ] && CHRDEV_MAJOR=`cat /proc/devices | grep segdev | awk '{print $1}'`
42         [ -z "${CHRDEV_MAJOR}" ] && CHRDEV_MAJOR=60
43         [ -z "${NR_OPS}" ] && NR_OPS=128
44         [ -z "${BPORT}" ] && BPORT=0
45         [ -z "${VPORT_START}" ] && VPORT_START=4
46         [ -z "${VPORT_END}" ] && VPORT_END=200
47         [ -z "${MPORT}" ] && MPORT=1
48         [ -z "${MBPORT}" ] && MBPORT=2
49         [ -z "${VTOOL}" ] && VTOOL=3
50 }
51
52
53 function unload_module {
54         rmmod "$1"
55 }
56
57 function unload_all {
58         unload_module "xsegbd"
59         rm "${CHRDEV_NAME}" || true
60         unload_module "xseg_segdev"
61         unload_module "xseg_posix"
62         unload_module "xseg_pthread"
63         unload_module "segdev"
64         unload_module "xseg"
65 }
66
67 function load_module {
68         (lsmod | grep "$1" > /dev/null) || insmod "${MODULES_DIR}/$1.ko" "$2" || exit 1
69 }
70
71 function mk_chardev {
72         ls "${CHRDEV_NAME}" &> /dev/null || \
73         mknod "${CHRDEV_NAME}" c "${CHRDEV_MAJOR}" 0 || exit 1
74 }
75
76 function load_all {
77         load_module "xseg"
78         load_module "segdev"
79         load_module "xseg_posix"
80         load_module "xseg_pthread"
81         load_module "xseg_segdev"
82         mk_chardev
83     "${XSEG_HOME}/peers/user/xseg" "${SPEC}" create || true
84         load_module "xsegbd" "spec=$SPEC"
85 }
86
87 function create_segment {
88         "${XSEG_HOME}/peer/users/xseg" "${SPEC}" create
89 }
90
91 function destroy_segment {
92         "${XSEG_TOOL}" "${SPEC}" destroy
93 }
94
95 function alloc_requests {
96         "${XSEG_TOOL}" "${SPEC}" $1 alloc_requests $2
97 }
98
99 function free_requests {
100         "${XSEG_TOOL}" "${SPEC}" $1 free_requests $2
101 }
102
103 function spawn_filed {
104         pgrep -f "peers/user/filed" || \
105         "${XSEG_HOME}/peers/user/filed" "$IMAGES" -p "$BPORT" -g "${SPEC}" -n \
106         ${NR_OPS}  &> "${XSEG_LOGS}/filed-${HOSTNAME}" &
107 }
108
109 function spawn_pfiled {
110         "${XSEG_HOME}/peers/user/pfiled" -p "$BPORT" -g "${SPEC}" -n \
111         ${NR_OPS} "${PITHOS}" "${IMAGES}" -v 1 &> "${XSEG_LOGS}/pfiled-${HOSTNAME}" &
112 }
113
114 function spawn_pfiledm {
115         "${XSEG_HOME}/peers/user/pfiled" -p "$MBPORT" -g "${SPEC}" -n \
116         ${NR_OPS} "${PITHOSMAPS}" "${MAPS}" -v 1  &> "${XSEG_LOGS}/pfiledm-${HOSTNAME}" &
117 }
118
119 function spawn_vlmcd {
120         pgrep -f "peers/user/st-vlmcd" || \
121         "${XSEG_HOME}/peers/user/st-vlmcd" -t 1 -sp "$VPORT_START" \
122         -ep "$VPORT_END" -bp "$BPORT" -mp "$MPORT" -g \
123         "${SPEC}" -n ${NR_OPS} -v 3 &> "${XSEG_LOGS}/vlmcd-${HOSTNAME}" &
124 #       alloc_requests "$VPORT:0" 128
125 }
126
127 function spawn_mapperdc {
128         pgrep -f "mt-mapperd" || \
129         "${XSEG_HOME}/peers/user/mt-mapperd" -t 1 -sp "$MPORT" -ep "$MPORT"\
130         -bp "$BPORT" -mbp "$MBPORT" -g "${SPEC}"\
131         -n ${NR_OPS} -v 3 &> "${XSEG_LOGS}/mapperd-${HOSTNAME}" & 
132 #       alloc_requests "$MPORT:0" 128
133 }
134
135 function spawn_mapperd {
136         pgrep -f "mapperd.py" || \
137         "${XSEG_HOME}/peers/user/mapperd.py" -p "$MPORT" -b "$BPORT" -g "${SPEC}" \
138         &> "${XSEG_LOGS}/mapperd-${HOSTNAME}" &
139 #       alloc_requests "$MPORT:0" 128
140 }
141
142 # map_volume - Map a volume to an xsegbd device
143 #
144 # @param $1             target/volume name
145 # @param $2             src port
146 # @param $3             dst port
147 function map_volume {
148         echo "$1 $2:$3:${REQS}" > "${XSEGBD_SYSFS}/add" || exit 1
149 }
150
151 # unmap_device - Unmap an xsegbd device/volume
152 #
153 # @param $1             xsegbd device id
154 function unmap_device {
155         echo "$1" > "${XSEGBD_SYSFS}/remove" || exit 1
156 }
157
158 function help {
159         echo "Usage: ./launch [list | <configuration> [start | stop] | insmod | rmmod]"
160 }
161
162 if [ -n "$NONINTERACTIVE" ]; then
163         exit 0
164 fi
165
166 parse_config
167 XSEG_TOOL="${XSEG_HOME}/peers/user/xseg"
168
169 case $1 in
170 list)
171         echo "filed [start|stop]"
172         echo "map [start|stap]"
173         echo " "
174         echo "insmod"
175         echo "rmmod"
176         ;;
177 insmod)
178         load_all
179         mk_chardev
180         ;;
181 rmmod)
182         rm ${CHRDEV_NAME}
183         unload_all
184         ;;
185 config)
186         echo "HOSTNAME=${HOSTNAME}"
187         echo "XSEG_HOME=${XSEG_HOME}"
188         echo "MODULES_DIR=${MODULES_DIR}"
189         echo "SPEC=${SPEC}"
190         echo "REQS=${REQS}"
191         echo "PORTS=${PORTS}"
192         echo "IMAGES=${IMAGES}"
193         echo "PITHOS=${PITHOS}"
194         echo "XSEG_LOGS=${XSEG_LOGS}"
195         echo "DEVICE_PREFIX=${DEVICE_PREFIX}"
196         echo "XSEGBD_SYSFS=${XSEGBD_SYSFS}"
197         echo "CHRDEV_NAME=${CHRDEV_NAME}"
198         echo "CHRDEV_MAJOR=${CHRDEV_MAJOR}"
199         echo "NR_OPS=${NR_OPS}"
200         echo "BPORT=${BPORT}"
201         echo "VPORT=${VPORT}"
202         echo "MPORT=${MPORT}"
203         ;;
204 filed)
205         case $2 in
206         start)
207                 load_all
208                 sleep 0.5
209                 spawn_filed
210                 sleep 0.5
211                 map_volume xsegvol 3 0
212                 ;;
213         stop)
214                 pkill -f peers/user/filed
215                 sleep 0.5
216                 unmap_device 3
217                 unload_all
218                 ;;
219         esac
220         ;;
221 map)
222         case $2 in
223         start)
224                 load_all
225                 sleep 0.5
226                 spawn_pfiled
227                 spawn_mapperd
228                 spawn_vlmcd
229                 ;;
230         stop)
231                 pkill -f peers/user/mt-vlmcd || true
232 #               free_requests "$VPORT:0" 128 || true
233                 pkill -f peers/user/mt-mapperd || true
234 #               free_requests "$MPORT:0" 128 || true
235                 pkill -f peers/user/pfiled || true
236                 sleep 0.5
237                 unload_all
238                 ;;
239         *)
240                 help
241                 ;;
242         esac
243         ;;
244 nomodules)
245         case $2 in
246         start)
247                 spawn_filed
248                 spawn_mapperd
249                 spawn_vlmcd
250                 ;;
251         stop)
252                 pkill -f peers/user/mt-vlmcd || true
253 #               free_requests "$VPORT:0" 128 || true
254                 pkill -f peers/user/mt-mapperd || true
255 #               free_requests "$MPORT:0" 128 || true
256                 pkill -f peers/user/filed || true
257                 ;;
258         *)
259                 help
260                 ;;
261         esac
262         ;;
263 one)
264         case $2 in
265         start)
266                 load_all
267                 sleep 1
268                 spawn_filed 
269                 spawn_mapperdc
270                 spawn_vlmcd 
271                 ;;
272         stop)
273                 pkill -f peers/user/mt-vlmcd || true
274 #               free_requests "$VPORT:0" 128 || true
275                 pkill -f peers/user/mt-mapperd || true
276 #               free_requests "$MPORT:0" 128 || true
277                 pkill -f peers/user/filed || true
278                 sleep 0.5
279                 unload_all
280                 ;;
281         *)
282                 help
283                 ;;
284         esac
285         ;;
286 doublemap)
287         case $2 in
288         start)
289                 load_all
290                 sleep 0.5
291                 spawn_pfiled
292                 spawn_pfiledm
293                 spawn_mapperdc
294                 spawn_vlmcd
295                 ;;
296         stop)
297                 pkill -f peers/user/st-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/pfiled || true
302                 sleep 0.5
303                 unload_all
304                 ;;
305         *)
306                 help
307                 ;;
308         esac
309         ;;
310 mapperd)
311         case $2 in
312         start)
313                 spawn_mapperdc
314                 ;;
315         stop)
316                 pkill -f peers/user/mt-mapperd || true
317                 ;;
318         *)
319                 help
320                 ;;
321         esac
322         ;;
323 *)
324         help
325         ;;
326 esac