Make helper_ip and monitor_port configurable
authorNikos Skalkotos <skalkoto@grnet.gr>
Thu, 7 Mar 2013 09:42:36 +0000 (11:42 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Thu, 7 Mar 2013 09:42:36 +0000 (11:42 +0200)
Let the host system provide those values to the helper through the
kernel command line.

snf-image-helper/common.sh
snf-image-host/xen-common.sh

index 5be1b39..80603a0 100644 (file)
@@ -44,11 +44,6 @@ MSG_TYPE_TASK_END="TASK_END"
 
 STDERR_LINE_SIZE=10
 
-IP="10.0.0.1"
-NETWORK="$IP/24"
-BROADCAST="${IP%.*}.255"
-PORT="48000"
-
 add_cleanup() {
     local cmd=""
     for arg; do cmd+=$(printf "%q " "$arg"); done
@@ -75,7 +70,7 @@ send_result_xen() {
 
 send_monitor_message_xen() {
     #Broadcast the message
-    echo "$@" | socat STDIO UDP-DATAGRAM:${BROADCAST}:${PORT},broadcast
+    echo "$@" | socat "STDIO" "UDP-DATAGRAM:${BROADCAST}:${MONITOR_PORT},broadcast"
 }
 
 prepare_helper() {
@@ -83,14 +78,22 @@ prepare_helper() {
 
        read -a cmdline  < /proc/cmdline
        for item in "${cmdline[@]}"; do
-        key=$(cut -d= -f1 <<< "$item")
-        val=$(cut -d= -f2 <<< "$item")
-        if [ "$key" = "hypervisor" ]; then
-            hypervisor="$val"
-        fi
-        if [ "$key" = "rules_dev" ]; then
-            export RULES_DEV="$val"
-        fi
+            key=$(cut -d= -f1 <<< "$item")
+            val=$(cut -d= -f2 <<< "$item")
+            if [ "$key" = "hypervisor" ]; then
+                hypervisor="$val"
+            fi
+            if [ "$key" = "rules_dev" ]; then
+                export RULES_DEV="$val"
+            fi
+            if [ "$key" = "helper_ip" ]; then
+                export IP="$val"
+                export NETWORK="$IP/24"
+                export BROADCAST="${IP%.*}.255"
+            fi
+            if [ "$key" = "monitor_port" ]; then
+                export MONITOR_PORT="$val"
+            fi
        done
 
     case "$hypervisor" in
@@ -98,6 +101,14 @@ prepare_helper() {
         HYPERVISOR=kvm
         ;;
     xen-hvm|xen-pvm)
+        if [ -z "$IP" ]; then
+            echo "ERROR: \`helper_ip' not defined or empty" >&2
+            exit 1
+        fi
+        if [ -z "$MONITOR_PORT" ]; then
+            echo "ERROR: \`monitor_port' not defined or empty" >&2
+            exit 1
+        fi
         $MOUNT -t xenfs xenfs /proc/xen
         ip addr add "$NETWORK" dev eth0
         ip link set eth0 up
index 42e257d..be8293f 100644 (file)
@@ -22,7 +22,8 @@ launch_helper() {
       kernel="$HELPER_DIR/kernel-xen" ramdisk="$HELPER_DIR/initrd-xen" \
          root="/dev/xvda1" memory="256" boot="c" vcpus=1 name="$name" \
       extra="console=hvc0 hypervisor=$HYPERVISOR snf_image_activate_helper \
-         ipv6.disable=1 rules_dev=/dev/xvdc ro boot=local init=/usr/bin/snf-image-helper" \
+         ipv6.disable=1 rules_dev=/dev/xvdc ro boot=local helper_ip=10.0.0.1 \
+          monitor_port=48888 init=/usr/bin/snf-image-helper" \
       disk="file:$HELPER_DIR/image,xvda,r" disk="phy:$blockdev,xvdb,w" \
       disk="file:$floppy,xvdc,r" vif="script=${XEN_SCRIPTS_DIR}/vif-snf-image"
     add_cleanup suppress_errors xm destroy "$name"
@@ -37,7 +38,7 @@ launch_helper() {
     add_cleanup xenstore-rm snf-image-helper/${helperid}
     xenstore-chmod snf-image-helper/${helperid} r0 w${helperid}
 
-    filter='udp and dst port 48000 and dst host 10.0.0.255 and src host 10.0.0.1'
+    filter='udp and dst port 48888 and dst host 10.0.0.255 and src host 10.0.0.1'
     $TIMEOUT -k $HELPER_HARD_TIMEOUT $HELPER_SOFT_TIMEOUT \
       ./helper-monitor.py -i "vif${helperid}.0" -f "$filter" ${MONITOR_FD} &
     monitor_pid=$!
@@ -57,7 +58,7 @@ launch_helper() {
     monitor_rc=$?
     set -e
 
-    if [ $monitor_rc -ne 0 ];
+    if [ $monitor_rc -ne 0 ]; then
        log_error "Helper VM monitoring failed"
        report_error "Helper VM monitoring failed"
        exit 1