3 # Copyright 2012 GRNET S.A. All rights reserved.
5 # Redistribution and use in source and binary forms, with or
6 # without modification, are permitted provided that the following
9 # 1. Redistributions of source code must retain the above
10 # copyright notice, this list of conditions and the following
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.
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.
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.
38 NI_SAVED=${NONINTERACTIVE}
39 export NONINTERACTIVE=1
41 export NONINTERACTIVE=${NI_SAVED}
45 function pretty_print {
46 echo "======================="
48 echo "======================="
56 function parse_config {
57 [ -e ~/.xsegrc ] && source ~/.xsegrc
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
86 function unload_module {
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"
100 function load_module {
101 (lsmod | grep "$1" > /dev/null) || insmod "${MODULES_DIR}/$1.ko" "$2" || exit 1
104 function mk_chardev {
105 ls "${CHRDEV_NAME}" &> /dev/null || \
106 mknod "${CHRDEV_NAME}" c "${CHRDEV_MAJOR}" 0 || exit 1
112 load_module "xseg_posix"
113 load_module "xseg_pthread"
114 load_module "xseg_segdev"
116 "${XSEG_HOME}/peers/user/xseg" "${SPEC}" create || true
117 load_module "xsegbd" "spec=$SPEC"
120 function create_segment {
121 "${XSEG_HOME}/peer/users/xseg" "${SPEC}" create
124 function destroy_segment {
125 "${XSEG_TOOL}" "${SPEC}" destroy
128 function alloc_requests {
129 "${XSEG_TOOL}" "${SPEC}" $1 alloc_requests $2
132 function free_requests {
133 "${XSEG_TOOL}" "${SPEC}" $1 free_requests $2
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}" &
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}" &
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}" &
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}" &
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}" &
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
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
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
187 # map_volume - Map a volume to an xsegbd device
189 # @param $1 target/volume name
192 function map_volume {
193 echo "$1 $2:$3:${REQS}" > "${XSEGBD_SYSFS}/add" || exit 1
196 # unmap_device - Unmap an xsegbd device/volume
198 # @param $1 xsegbd device id
199 function unmap_device {
200 echo "$1" > "${XSEGBD_SYSFS}/remove" || exit 1
204 echo "Usage: ./launch [list | <configuration> [start | stop] | insmod | rmmod]"
207 if [ -n "$NONINTERACTIVE" ]; then
212 XSEG_TOOL="${XSEG_HOME}/peers/user/xseg"
216 echo "filed [start|stop]"
217 echo "map [start|stap]"
231 echo "HOSTNAME=${HOSTNAME}"
232 echo "XSEG_HOME=${XSEG_HOME}"
233 echo "MODULES_DIR=${MODULES_DIR}"
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}"
256 map_volume xsegvol 3 0
259 pkill -f peers/user/filed
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
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
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
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
361 pkill -f peers/user/mt-mapperd || true
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
398 pkill -f peers/user/mt-mapperd || true