ia64/xen-unstable

changeset 7791:e2e7f47e6f79

Rename the commands inside the hotplug scripts to match those used by hotplug
and udev. Pass all commands through from xen-backend.agent or
xen-backend.rules rather than second-guessing the individual scripts. This
should make it easier to tear down devices cleanly, especially the dangling
vifs we are seeing at the moment.

Cope with a missing type node inside the block script, as we don't want to
resurrect a removed node by writing a hotplug error message.

Log failure of iptables command.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Fri Nov 11 18:01:44 2005 +0100 (2005-11-11)
parents 9523e6d10511
children bf7c16e761fc
files tools/examples/block tools/examples/block-common.sh tools/examples/vif-bridge tools/examples/vif-common.sh tools/examples/vif-nat tools/examples/vif-route tools/examples/xen-backend.agent tools/examples/xen-backend.rules
line diff
     1.1 --- a/tools/examples/block	Fri Nov 11 17:59:20 2005 +0100
     1.2 +++ b/tools/examples/block	Fri Nov 11 18:01:44 2005 +0100
     1.3 @@ -3,6 +3,12 @@
     1.4  dir=$(dirname "$0")
     1.5  . "$dir/block-common.sh"
     1.6  
     1.7 +case "$command" in
     1.8 +    online | offline)
     1.9 +        exit 0
    1.10 +        ;;
    1.11 +esac
    1.12 +
    1.13  expand_dev() {
    1.14    local dev
    1.15    case $1 in
    1.16 @@ -16,10 +22,10 @@ expand_dev() {
    1.17    echo -n $dev
    1.18  }
    1.19  
    1.20 -t=$(xenstore_read "$XENBUS_PATH"/type || true)
    1.21 +t=$(xenstore_read_default "$XENBUS_PATH"/type "MISSING")
    1.22  
    1.23  case "$command" in 
    1.24 -  bind)
    1.25 +  add)
    1.26      p=$(xenstore_read "$XENBUS_PATH"/params)
    1.27      case $t in 
    1.28        phy)
    1.29 @@ -38,32 +44,25 @@ case "$command" in
    1.30  	done
    1.31  	exit 1
    1.32  	;;
    1.33 -
    1.34 -      *)
    1.35 -        [ -x /etc/xen/scripts/block-"$t" ] && \
    1.36 -	    /etc/xen/scripts/block-"$t" bind $p
    1.37 -	;;
    1.38      esac
    1.39      ;;
    1.40  
    1.41 -  unbind)
    1.42 -    node=$(xenstore_read "$XENBUS_PATH"/node)
    1.43 +  remove)
    1.44      case $t in 
    1.45        phy)
    1.46  	exit 0
    1.47  	;;
    1.48  
    1.49        file)
    1.50 +        node=$(xenstore_read "$XENBUS_PATH"/node)
    1.51  	losetup -d $node
    1.52  	exit 0
    1.53  	;;
    1.54 -
    1.55 -      *)
    1.56 -        [ -x /etc/xen/scripts/block-"$t" ] && \
    1.57 -	    /etc/xen/scripts/block-"$t" unbind $node
    1.58 -	;;
    1.59 -
    1.60      esac
    1.61      ;;
    1.62  
    1.63  esac
    1.64 +
    1.65 +# If we've reached here, $t is neither phy nor file, so fire a helper script.
    1.66 +[ -x /etc/xen/scripts/block-"$t" ] && \
    1.67 +  /etc/xen/scripts/block-"$t" "$command" $node
     2.1 --- a/tools/examples/block-common.sh	Fri Nov 11 17:59:20 2005 +0100
     2.2 +++ b/tools/examples/block-common.sh	Fri Nov 11 18:01:44 2005 +0100
     2.3 @@ -19,9 +19,12 @@
     2.4  dir=$(dirname "$0")
     2.5  . "$dir/xen-hotplug-common.sh"
     2.6  
     2.7 -command="$1"
     2.8 +findCommand "$@"
     2.9  
    2.10 -if [ "$command" != "bind" ] && [ "$command" != "unbind" ]
    2.11 +if [ "$command" != "online" ]  &&
    2.12 +   [ "$command" != "offline" ] &&
    2.13 +   [ "$command" != "add" ]     &&
    2.14 +   [ "$command" != "remove" ]
    2.15  then
    2.16    log err "Invalid command: $command"
    2.17    exit 1
     3.1 --- a/tools/examples/vif-bridge	Fri Nov 11 17:59:20 2005 +0100
     3.2 +++ b/tools/examples/vif-bridge	Fri Nov 11 18:01:44 2005 +0100
     3.3 @@ -9,7 +9,7 @@
     3.4  # places, then this script is the default.
     3.5  #
     3.6  # Usage:
     3.7 -# vif-bridge (up|down)
     3.8 +# vif-bridge (add|remove|online|offline)
     3.9  #
    3.10  # Environment vars:
    3.11  # vif         vif interface name (required).
    3.12 @@ -47,7 +47,7 @@ then
    3.13  fi
    3.14  
    3.15  case "$command" in
    3.16 -    up)
    3.17 +    online)
    3.18          if brctl show "$bridge" | grep "$vif" >&/dev/null
    3.19          then
    3.20            log debug "$vif already attached to $bridge"
    3.21 @@ -58,9 +58,9 @@ case "$command" in
    3.22            fatal "brctl addif $bridge $vif failed"
    3.23  
    3.24          ifconfig "$vif" up || fatal "ifconfig $vif up failed"
    3.25 -        success
    3.26          ;;
    3.27 -    down)
    3.28 +
    3.29 +    remove)
    3.30          # vifs are auto-removed from bridge.
    3.31          ifconfig "$vif" down || fatal "ifconfig $vif down failed"
    3.32          ;;
    3.33 @@ -69,3 +69,4 @@ esac
    3.34  handle_iptable
    3.35  
    3.36  log debug "Successful vif-bridge operation for $vif, bridge $bridge."
    3.37 +success
     4.1 --- a/tools/examples/vif-common.sh	Fri Nov 11 17:59:20 2005 +0100
     4.2 +++ b/tools/examples/vif-common.sh	Fri Nov 11 18:01:44 2005 +0100
     4.3 @@ -22,12 +22,21 @@ dir=$(dirname "$0")
     4.4  
     4.5  findCommand "$@"
     4.6  
     4.7 -if [ "$command" != "up" ] && [ "$command" != "down" ]
     4.8 +if [ "$command" != "online" ]  &&
     4.9 +   [ "$command" != "offline" ] &&
    4.10 +   [ "$command" != "add" ]     &&
    4.11 +   [ "$command" != "remove" ]
    4.12  then
    4.13    log err "Invalid command: $command"
    4.14    exit 1
    4.15  fi
    4.16  
    4.17 +case "$command" in
    4.18 +    add | offline)
    4.19 +        exit 0
    4.20 +        ;;
    4.21 +esac
    4.22 +
    4.23  
    4.24  # Parameters may be read from the environment, the command line arguments, and
    4.25  # the store, with overriding in that order.  The environment is given by the
    4.26 @@ -46,7 +55,7 @@ vif="${vif:?}"
    4.27  
    4.28  function frob_iptable()
    4.29  {
    4.30 -  if [ "$command" == "up" ]
    4.31 +  if [ "$command" == "online" ]
    4.32    then
    4.33      local c="-A"
    4.34    else
     5.1 --- a/tools/examples/vif-nat	Fri Nov 11 17:59:20 2005 +0100
     5.2 +++ b/tools/examples/vif-nat	Fri Nov 11 18:01:44 2005 +0100
     5.3 @@ -9,7 +9,7 @@
     5.4  # places, then vif-bridge is the default.
     5.5  #
     5.6  # Usage:
     5.7 -# vif-nat (up|down)
     5.8 +# vif-nat (add|remove|online|offline)
     5.9  #
    5.10  # Environment vars:
    5.11  # vif         vif interface name (required).
    5.12 @@ -40,12 +40,12 @@ netmask=$netmask.$(( $intmask & 0x000000
    5.13  main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
    5.14  
    5.15  case "$command" in
    5.16 -    up)
    5.17 +    online)
    5.18          ifconfig ${vif} ${vif_ip} netmask ${netmask} up
    5.19          echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
    5.20          ipcmd='a'
    5.21          ;;
    5.22 -    down)
    5.23 +    remove)
    5.24          ifconfig ${vif} down
    5.25          ipcmd='d'
    5.26          ;;
     6.1 --- a/tools/examples/vif-route	Fri Nov 11 17:59:20 2005 +0100
     6.2 +++ b/tools/examples/vif-route	Fri Nov 11 18:01:44 2005 +0100
     6.3 @@ -9,7 +9,7 @@
     6.4  # places, then vif-bridge is the default.
     6.5  #
     6.6  # Usage:
     6.7 -# vif-route (up|down)
     6.8 +# vif-route (add|remove|online|offline)
     6.9  #
    6.10  # Environment vars:
    6.11  # vif         vif interface name (required).
    6.12 @@ -26,12 +26,12 @@ dir=$(dirname "$0")
    6.13  main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
    6.14  
    6.15  case "$command" in
    6.16 -    up)
    6.17 +    online)
    6.18          ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up
    6.19          echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
    6.20          ipcmd='a'
    6.21          ;;
    6.22 -    down)
    6.23 +    remove)
    6.24          ifdown ${vif}
    6.25          ipcmd='d'
    6.26          ;;
     7.1 --- a/tools/examples/xen-backend.agent	Fri Nov 11 17:59:20 2005 +0100
     7.2 +++ b/tools/examples/xen-backend.agent	Fri Nov 11 18:01:44 2005 +0100
     7.3 @@ -2,35 +2,25 @@
     7.4  
     7.5  PATH=/etc/xen/scripts:$PATH
     7.6  
     7.7 +case "$XENBUS_TYPE" in
     7.8 +  vbd)
     7.9 +    /etc/xen/scripts/block "$ACTION"
    7.10 +    ;;
    7.11 +  vif)
    7.12 +    [ -n "$script" ] && $script "$ACTION"
    7.13 +    ;;
    7.14 +esac
    7.15 +
    7.16  case "$ACTION" in
    7.17    add)
    7.18 -    case "$XENBUS_TYPE" in
    7.19 -      vbd)
    7.20 -	/etc/xen/scripts/block bind
    7.21 -        ;;
    7.22 -    esac
    7.23      ;;
    7.24    remove)
    7.25 -    case "$XENBUS_TYPE" in
    7.26 -      vbd)
    7.27 -	/etc/xen/scripts/block unbind
    7.28 -        ;;
    7.29 -      vif)
    7.30 -        [ -n "$script" ] && $script down
    7.31 -        ;;
    7.32 -    esac
    7.33      # remove device backend store entries
    7.34 -    xenstore-rm -t "$XENBUS_PATH"
    7.35 -    xenstore-rm -t "error/$XENBUS_PATH"
    7.36 +    xenstore-rm -t "$XENBUS_PATH"       || true
    7.37 +    xenstore-rm -t "error/$XENBUS_PATH" || true
    7.38      ;;
    7.39    online)
    7.40 -    case "$XENBUS_TYPE" in
    7.41 -      vif)
    7.42 -        [ -n "$script" ] && $script up
    7.43 -        ;;
    7.44 -    esac
    7.45      ;;
    7.46    offline)
    7.47      ;;
    7.48  esac
    7.49 -
     8.1 --- a/tools/examples/xen-backend.rules	Fri Nov 11 17:59:20 2005 +0100
     8.2 +++ b/tools/examples/xen-backend.rules	Fri Nov 11 18:01:44 2005 +0100
     8.3 @@ -1,4 +1,5 @@
     8.4 -SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ACTION=="add", RUN+="/etc/xen/scripts/block bind"
     8.5 -SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ACTION=="remove", RUN+="/etc/xen/scripts/block unbind"
     8.6 -SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} up"
     8.7 +SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
     8.8 +SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online"
     8.9 +SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline"
    8.10  SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/usr/bin/xenstore-rm -t $env{XENBUS_PATH}"
    8.11 +SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/usr/bin/xenstore-rm -t error/$env{XENBUS_PATH}"