ia64/xen-unstable

view tools/examples/vif-nat @ 7595:286946489e5d

From Murillo Fernandes Bernardes <mfb@br.ibm.com>:

The problem is: There is no mechanism to detect block device setup failure

Network devices have the same problem, and are fixed with this too.

I handling this problem in the way suggested by aliguori:
- hotplug scripts write a "hotplug-status" node on store
- Xend DevController.createDevice() check verify this node and return success
or throw an exception on failure.
- If no changes in "hotplug-status" node after DEVICE_CREATE_TIMEOUT seconds
Xend throw an exception showing the problem with hotplug scripts.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Mon Oct 31 17:10:57 2005 +0100 (2005-10-31)
parents 19af31a59537
children 1444adb1c407
line source
1 #!/bin/sh
2 #============================================================================
3 # /etc/xen/vif-nat
4 #
5 # Script for configuring a vif in routed-nat mode.
6 # The hotplugging system will call this script if it is specified either in
7 # the device configuration given to Xend, or the default Xend configuration
8 # in /etc/xen/xend-config.sxp. If the script is specified in neither of those
9 # places, then vif-bridge is the default.
10 #
11 # Usage:
12 # vif-nat (up|down)
13 #
14 # Environment vars:
15 # vif vif interface name (required).
16 # XENBUS_PATH path to this device's details in the XenStore (required).
17 #
18 # Read from the store:
19 # ip list of IP networks for the vif, space-separated (default given in
20 # this script).
21 #============================================================================
23 dir=$(dirname "$0")
24 . "$dir/vif-common.sh"
26 if [ "$ip" == "" ]
27 then
28 ip='169.254.1.1/24'
29 fi
31 #determine ip address and netmask
32 vif_ip=`echo ${ip} | awk -F/ '{print $1}'`
33 bits=`echo ${ip} | awk -F/ '{print $2}'`
34 intmask=$(( ((0xFFFFFFFF << ((32 - $bits)))) & 0xFFFFFFFF ))
35 netmask=$(( (($intmask & 0xFF000000)) >> 24 ))
36 netmask=$netmask.$(( (($intmask & 0x00FF0000)) >> 16 ))
37 netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 ))
38 netmask=$netmask.$(( $intmask & 0x000000FF ))
40 main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
42 case "$command" in
43 up)
44 ifconfig ${vif} ${vif_ip} netmask ${netmask} up
45 echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
46 ipcmd='a'
47 ;;
48 down)
49 ifconfig ${vif} down
50 ipcmd='d'
51 ;;
52 esac
54 ip r ${ipcmd} ${ip} dev ${vif} src ${main_ip}
56 handle_iptable()
58 success