3 # Launcher for xseg configurations
5 NI_SAVED=${NONINTERACTIVE}
6 export NONINTERACTIVE=1
8 export NONINTERACTIVE=${NI_SAVED}
12 function pretty_print {
13 echo "======================="
15 echo "======================="
23 function parse_config {
24 [ -e ~/.xsegrc ] && source ~/.xsegrc
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:16:1024:12"
30 [ -z "${REQS}" ] && REQS=512
31 [ -z "${PORTS}" ] && PORTS=16
32 [ -z "${IMAGES}" ] && IMAGES="/home/user/archip/xseg/peers/user/foo"
33 [ -z "${MAPS}" ] && IMAGES="/home/user/archip/xseg/peers/user/foo"
34 [ -z "${PITHOS}" ] && PITHOS="/srv/pithos/data/blocks"
35 [ -z "${PITHOSMAPS}" ] && PITHOS="/srv/pithos/data/maps"
36 [ -z "${XSEG_LOGS}" ] && XSEG_LOGS="/home/user/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=16
44 [ -z "${BPORT}" ] && BPORT=0
45 [ -z "${VPORT}" ] && VPORT=2
46 [ -z "${MPORT}" ] && MPORT=1
47 [ -z "${MBPORT}" ] && MBPORT=3
48 [ -z "${VTOOL}" ] && VTOOL=15
52 function unload_module {
57 unload_module "xsegbd"
58 rm "${CHRDEV_NAME}" || true
59 unload_module "xseg_segdev"
60 unload_module "xseg_posix"
61 unload_module "xseg_pthread"
62 unload_module "segdev"
66 function load_module {
67 (lsmod | grep "$1" > /dev/null) || insmod "${MODULES_DIR}/$1.ko" "$2" || exit 1
71 ls "${CHRDEV_NAME}" &> /dev/null || \
72 mknod "${CHRDEV_NAME}" c "${CHRDEV_MAJOR}" 0 || exit 1
78 load_module "xseg_posix"
79 load_module "xseg_pthread"
80 load_module "xseg_segdev"
82 "${XSEG_HOME}/peers/user/xseg" "${SPEC}" create || true
83 load_module "xsegbd" "spec=$SPEC"
86 function create_segment {
87 "${XSEG_HOME}/peer/users/xseg" "${SPEC}" create
90 function destroy_segment {
91 "${XSEG_TOOL}" "${SPEC}" destroy
94 function alloc_requests {
95 "${XSEG_TOOL}" "${SPEC}" $1 alloc_requests $2
98 function free_requests {
99 "${XSEG_TOOL}" "${SPEC}" $1 free_requests $2
102 function spawn_filed {
103 pgrep -f "peers/user/filed" || \
104 "${XSEG_HOME}/peers/user/filed" "$IMAGES" -p "$BPORT" -g "${SPEC}" -n \
105 ${NR_OPS} &> "${XSEG_LOGS}/filed-${HOSTNAME}" &
108 function spawn_pfiled {
109 pgrep -f "peers/user/pfiled" || \
110 "${XSEG_HOME}/peers/user/pfiled" -p "$BPORT" -g "${SPEC}" -n \
111 ${NR_OPS} "${PITHOS}" "${IMAGES}" &> "${XSEG_LOGS}/pfiled-${HOSTNAME}" &
113 function spawn_pfiledm {
114 pgrep -f "peers/user/pfiled" || \
115 "${XSEG_HOME}/peers/user/pfiled" -p "$MBPORT" -g "${SPEC}" -n \
116 ${NR_OPS} "${PITHOSMAPS}" "${MAPS}" &> "${XSEG_LOGS}/pfiledm-${HOSTNAME}" &
118 function spawn_vlmcd {
119 pgrep -f "peers/user/mt-vlmcd" || \
120 "${XSEG_HOME}/peers/user/mt-vlmcd" -t 1 -p "$VPORT" -bp "$BPORT" -mp "$MPORT" -g \
121 "${SPEC}" -n ${NR_OPS} &> "${XSEG_LOGS}/vlmcd-${HOSTNAME}" &
122 # alloc_requests "$VPORT:0" 128
125 function spawn_mapperdc {
126 pgrep -f "mt-mapperd" || \
127 "${XSEG_HOME}/peers/user/mt-mapperd" -t 1 -p "$MPORT" -bp "$BPORT" -g "${SPEC}"\
128 &> "${XSEG_LOGS}/mapperd-${HOSTNAME}" &
129 # alloc_requests "$MPORT:0" 128
132 function spawn_mapperd {
133 pgrep -f "mapperd.py" || \
134 "${XSEG_HOME}/peers/user/mapperd.py" -p "$MPORT" -b "$BPORT" -g "${SPEC}" \
135 &> "${XSEG_LOGS}/mapperd-${HOSTNAME}" &
136 # alloc_requests "$MPORT:0" 128
139 # map_volume - Map a volume to an xsegbd device
141 # @param $1 target/volume name
144 function map_volume {
145 echo "$1 $2:$3:${REQS}" > "${XSEGBD_SYSFS}/add" || exit 1
148 # unmap_device - Unmap an xsegbd device/volume
150 # @param $1 xsegbd device id
151 function unmap_device {
152 echo "$1" > "${XSEGBD_SYSFS}/remove" || exit 1
156 echo "Usage: ./launch [list | <configuration> [start | stop] | insmod | rmmod]"
159 if [ -n "$NONINTERACTIVE" ]; then
164 XSEG_TOOL="${XSEG_HOME}/peers/user/xseg"
168 echo "filed [start|stop]"
169 echo "map [start|stap]"
183 echo "HOSTNAME=${HOSTNAME}"
184 echo "XSEG_HOME=${XSEG_HOME}"
185 echo "MODULES_DIR=${MODULES_DIR}"
188 echo "PORTS=${PORTS}"
189 echo "IMAGES=${IMAGES}"
190 echo "PITHOS=${PITHOS}"
191 echo "XSEG_LOGS=${XSEG_LOGS}"
192 echo "DEVICE_PREFIX=${DEVICE_PREFIX}"
193 echo "XSEGBD_SYSFS=${XSEGBD_SYSFS}"
194 echo "CHRDEV_NAME=${CHRDEV_NAME}"
195 echo "CHRDEV_MAJOR=${CHRDEV_MAJOR}"
196 echo "NR_OPS=${NR_OPS}"
197 echo "BPORT=${BPORT}"
198 echo "VPORT=${VPORT}"
199 echo "MPORT=${MPORT}"
208 map_volume xsegvol 3 0
211 pkill -f peers/user/filed
228 pkill -f peers/user/mt-vlmcd || true
229 # free_requests "$VPORT:0" 128 || true
230 pkill -f peers/user/mt-mapperd || true
231 # free_requests "$MPORT:0" 128 || true
232 pkill -f peers/user/pfiled || true
249 pkill -f peers/user/mt-vlmcd || true
250 # free_requests "$VPORT:0" 128 || true
251 pkill -f peers/user/mt-mapperd || true
252 # free_requests "$MPORT:0" 128 || true
253 pkill -f peers/user/filed || true
270 pkill -f peers/user/mt-vlmcd || true
271 # free_requests "$VPORT:0" 128 || true
272 pkill -f peers/user/mt-mapperd || true
273 # free_requests "$MPORT:0" 128 || true
274 pkill -f peers/user/filed || true
294 pkill -f peers/user/mt-vlmcd || true
295 # free_requests "$VPORT:0" 128 || true
296 pkill -f peers/user/mt-mapperd || true
297 # free_requests "$MPORT:0" 128 || true
298 pkill -f peers/user/pfiled || true