direct-io.hg

changeset 7544:4722eae11abb

Added xen-script-common.sh, for functions common to all scripts, not just the
hotplug ones. Added evalVariables and findCommand functions to that, which we
use to clarify the handling of variables being passed in as command line
variables.

Make vif-bridge able to find the bridge for itself if only one bridge is in
use. This means that it is not necessary to specify a bridge in many
configurations. Allow the bridge to be specified on the command line, meaning
that a default may be provided in the xend-config.sxp if desired.

Added xenstore_read_default to xen-hotplug-common.sh, which reads from the
store but uses a given default if the path in the store is not present. This
is used by vif-bridge to allow the store details (i.e. those given to xm create)
to override the default value given in the xend-config.sxp.

Remove vif-bridge setting -- the value can be specified on the vif-script
command line if necessary.

Added examples for network-nat/vif-nat.

Added lots of big comments.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Sun Oct 30 13:33:17 2005 +0100 (2005-10-30)
parents 6304291cf08b
children ab8768317e20
files tools/examples/Makefile tools/examples/network-bridge tools/examples/vif-bridge tools/examples/vif-common.sh tools/examples/xen-hotplug-common.sh tools/examples/xen-script-common.sh tools/examples/xend-config.sxp
line diff
     1.1 --- a/tools/examples/Makefile	Sun Oct 30 13:24:45 2005 +0100
     1.2 +++ b/tools/examples/Makefile	Sun Oct 30 13:33:17 2005 +0100
     1.3 @@ -25,6 +25,7 @@ XEN_SCRIPTS += network-route vif-route
     1.4  XEN_SCRIPTS += network-nat vif-nat
     1.5  XEN_SCRIPTS += block
     1.6  XEN_SCRIPTS += block-enbd block-nbd
     1.7 +XEN_SCRIPTS += xen-script-common.sh
     1.8  XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
     1.9  XEN_SCRIPTS += block-common.sh
    1.10  
     2.1 --- a/tools/examples/network-bridge	Sun Oct 30 13:24:45 2005 +0100
     2.2 +++ b/tools/examples/network-bridge	Sun Oct 30 13:33:17 2005 +0100
     2.3 @@ -42,18 +42,13 @@
     2.4  #
     2.5  #============================================================================
     2.6  
     2.7 +
     2.8  dir=$(dirname "$0")
     2.9 +. "$dir/xen-script-common.sh"
    2.10  . "$dir/xen-network-common.sh"
    2.11  
    2.12 -# Exit if anything goes wrong.
    2.13 -set -e 
    2.14 -
    2.15 -# First arg is the operation.
    2.16 -OP=$1
    2.17 -shift
    2.18 -
    2.19 -# Pull variables in args in to environment.
    2.20 -for arg ; do export "${arg}" ; done
    2.21 +findCommand "$@"
    2.22 +evalVariables "$@"
    2.23  
    2.24  vifnum=${vifnum:-0}
    2.25  bridge=${bridge:-xenbr${vifnum}}
    2.26 @@ -289,7 +284,7 @@ op_stop () {
    2.27      brctl delbr ${bridge}
    2.28  }
    2.29  
    2.30 -case ${OP} in
    2.31 +case "$command" in
    2.32      start)
    2.33  	op_start
    2.34  	;;
    2.35 @@ -303,7 +298,7 @@ case ${OP} in
    2.36  	;;
    2.37  
    2.38      *)
    2.39 -	echo 'Unknown command: ' ${OP} >&2
    2.40 +	echo "Unknown command: $command" >&2
    2.41  	echo 'Valid commands are: start, stop, status' >&2
    2.42  	exit 1
    2.43  esac
     3.1 --- a/tools/examples/vif-bridge	Sun Oct 30 13:24:45 2005 +0100
     3.2 +++ b/tools/examples/vif-bridge	Sun Oct 30 13:33:17 2005 +0100
     3.3 @@ -16,7 +16,8 @@
     3.4  # XENBUS_PATH path to this device's details in the XenStore (required).
     3.5  #
     3.6  # Read from the store:
     3.7 -# bridge  bridge to add the vif to (required).
     3.8 +# bridge  bridge to add the vif to (optional).  Defaults to searching for the
     3.9 +#         bridge itself.
    3.10  # ip      list of IP networks for the vif, space-separated (optional).
    3.11  #
    3.12  # up:
    3.13 @@ -31,7 +32,19 @@
    3.14  dir=$(dirname "$0")
    3.15  . "$dir/vif-common.sh"
    3.16  
    3.17 -bridge=$(xenstore_read "$XENBUS_PATH/bridge")
    3.18 +bridge=${bridge:-}
    3.19 +bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
    3.20 +
    3.21 +if [ -z "$bridge" ]
    3.22 +then
    3.23 +  bridge=$(brctl show | cut -d "
    3.24 +" -f 2 | cut -f 1)
    3.25 +
    3.26 +  if [ -z "$bridge" ]
    3.27 +  then
    3.28 +     fatal "Could not find bridge, and none was specified"
    3.29 +  fi
    3.30 +fi
    3.31  
    3.32  case "$command" in
    3.33      up)
    3.34 @@ -54,4 +67,4 @@ esac
    3.35  
    3.36  handle_iptable
    3.37  
    3.38 -log debug "vif-bridge operation for $vif successful."
    3.39 +log debug "Successful vif-bridge operation for $vif, bridge $bridge."
     4.1 --- a/tools/examples/vif-common.sh	Sun Oct 30 13:24:45 2005 +0100
     4.2 +++ b/tools/examples/vif-common.sh	Sun Oct 30 13:33:17 2005 +0100
     4.3 @@ -20,7 +20,7 @@ dir=$(dirname "$0")
     4.4  . "$dir/xen-hotplug-common.sh"
     4.5  . "$dir/xen-network-common.sh"
     4.6  
     4.7 -command="$1"
     4.8 +findCommand "$@"
     4.9  
    4.10  if [ "$command" != "up" ] && [ "$command" != "down" ]
    4.11  then
    4.12 @@ -29,11 +29,20 @@ then
    4.13  fi
    4.14  
    4.15  
    4.16 +# Parameters may be read from the environment, the command line arguments, and
    4.17 +# the store, with overriding in that order.  The environment is given by the
    4.18 +# driver, the command line is given by the Xend global configuration, and
    4.19 +# store details are given by the per-domain or per-device configuration.
    4.20 +
    4.21 +evalVariables "$@"
    4.22 +
    4.23 +ip=${ip:-}
    4.24 +ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip")
    4.25 +
    4.26 +# Check presence of compulsory args.
    4.27  XENBUS_PATH="${XENBUS_PATH:?}"
    4.28  vif="${vif:?}"
    4.29  
    4.30 -ip=$(xenstore-read "$XENBUS_PATH/ip" >&/dev/null || true)
    4.31 -
    4.32  
    4.33  function frob_iptable()
    4.34  {
     5.1 --- a/tools/examples/xen-hotplug-common.sh	Sun Oct 30 13:24:45 2005 +0100
     5.2 +++ b/tools/examples/xen-hotplug-common.sh	Sun Oct 30 13:33:17 2005 +0100
     5.3 @@ -16,7 +16,8 @@
     5.4  #
     5.5  
     5.6  
     5.7 -set -e
     5.8 +dir=$(dirname "$0")
     5.9 +. "$dir/xen-script-common.sh"
    5.10  
    5.11  export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
    5.12  export LANG="POSIX"
    5.13 @@ -33,15 +34,39 @@ fatal() {
    5.14    exit 1
    5.15  }
    5.16  
    5.17 +##
    5.18 +# xenstore_read <path>+
    5.19 +#
    5.20 +# Read each of the given paths, returning each result on a separate line, or
    5.21 +# exit this script if any of the paths is missing.
    5.22 +#
    5.23  xenstore_read() {
    5.24    local v=$(xenstore-read "$@" || true)
    5.25    [ "$v" != "" ] || fatal "xenstore-read $@ failed."
    5.26    echo "$v"
    5.27  }
    5.28  
    5.29 +
    5.30 +##
    5.31 +# xenstore_read_default <path> <default>
    5.32 +#
    5.33 +# Read the given path, returning the value there or the given default if the
    5.34 +# path is not present.
    5.35 +#
    5.36 +xenstore_read_default() {
    5.37 +  xenstore-read "$1" || echo "$2"
    5.38 +}
    5.39 +
    5.40 +
    5.41 +##
    5.42 +# xenstore_write (<path> <value>)+
    5.43 +#
    5.44 +# Write each of the key/value pairs to the store, and exit this script if any
    5.45 +# such writing fails.
    5.46 +#
    5.47  xenstore_write() {
    5.48    log debug "Writing $@ to xenstore."
    5.49 -  xenstore-write "$@" || log err "Writing $@ to xenstore failed."
    5.50 +  xenstore-write "$@" || fatal "Writing $@ to xenstore failed."
    5.51  }
    5.52  
    5.53  log debug "$@" "XENBUS_PATH=$XENBUS_PATH"
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/examples/xen-script-common.sh	Sun Oct 30 13:33:17 2005 +0100
     6.3 @@ -0,0 +1,44 @@
     6.4 +#
     6.5 +# Copyright (c) 2005 XenSource Ltd.
     6.6 +#
     6.7 +# This library is free software; you can redistribute it and/or
     6.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     6.9 +# License as published by the Free Software Foundation.
    6.10 +#
    6.11 +# This library is distributed in the hope that it will be useful,
    6.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.14 +# Lesser General Public License for more details.
    6.15 +#
    6.16 +# You should have received a copy of the GNU Lesser General Public
    6.17 +# License along with this library; if not, write to the Free Software
    6.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.19 +#
    6.20 +
    6.21 +
    6.22 +set -e
    6.23 +
    6.24 +
    6.25 +evalVariables()
    6.26 +{
    6.27 +  for arg in "$@"
    6.28 +  do
    6.29 +    if expr 'index' "$arg" '=' '>' '1' >/dev/null
    6.30 +    then
    6.31 +      eval "$arg"
    6.32 +    fi
    6.33 +  done
    6.34 +}
    6.35 +
    6.36 +
    6.37 +findCommand()
    6.38 +{
    6.39 +  for arg in "$@"
    6.40 +  do
    6.41 +    if ! expr 'index' "$arg" '=' >/dev/null
    6.42 +    then
    6.43 +      command="$arg"
    6.44 +      return
    6.45 +    fi
    6.46 +  done
    6.47 +}
     7.1 --- a/tools/examples/xend-config.sxp	Sun Oct 30 13:24:45 2005 +0100
     7.2 +++ b/tools/examples/xend-config.sxp	Sun Oct 30 13:33:17 2005 +0100
     7.3 @@ -48,19 +48,62 @@
     7.4  # The limit (in kilobytes) on the size of the console buffer
     7.5  #(console-limit 1024)
     7.6  
     7.7 -## Use the following if VIF traffic is routed.
     7.8 -# The script used to start/stop networking for xend.
     7.9 -#(network-script     network-route)
    7.10 -# The default script used to control virtual interfaces.
    7.11 -#(vif-script         vif-route)
    7.12 +##
    7.13 +# To bridge network traffic, like this:
    7.14 +#
    7.15 +# dom0: fake eth0 -> vif0.0 -+
    7.16 +#                            |
    7.17 +#                          bridge -> real eth0 -> the network
    7.18 +#                            |
    7.19 +# domU: fake eth0 -> vifN.0 -+
    7.20 +#
    7.21 +# use
    7.22 +#
    7.23 +# (network-script network-bridge)
    7.24 +#
    7.25 +# Your eth0 is used as the outgoing interface, by default.  To use a different
    7.26 +# one (e.g. eth1) use
    7.27 +#
    7.28 +# (network-script 'network-bridge netdev=eth1')
    7.29 +#
    7.30 +# The bridge is named xenbr0, by default.  To rename the bridge, use
    7.31 +#
    7.32 +# (network-script 'network-bridge bridge=<name>')
    7.33 +#
    7.34 +# It is possible to use the network-bridge script in more complicated
    7.35 +# scenarios, such as having two outgoing interfaces, with two bridges, and
    7.36 +# two fake interfaces per guest domain.  To do things like this, write
    7.37 +# yourself a wrapper script, and call network-bridge from it, as appropriate.
    7.38 +#
    7.39 +(network-script network-bridge)
    7.40  
    7.41 -## Use the following if VIF traffic is bridged.
    7.42 -# The script used to start/stop networking for xend.
    7.43 -(network-script    network-bridge)
    7.44 -# The default bridge that virtual interfaces should be connected to.
    7.45 -(vif-bridge        xenbr0)
    7.46 -# The default script used to control virtual interfaces.
    7.47 -(vif-script        vif-bridge)
    7.48 +# The script used to control virtual interfaces.  This can be overridden on a
    7.49 +# per-vif basis when creating a domain or a configuring a new vif.  The
    7.50 +# vif-bridge script is designed for use with the network-bridge script, or
    7.51 +# similar configurations.
    7.52 +#
    7.53 +# If you have overridden the bridge name using
    7.54 +# (network-script 'network-bridge bridge=<name>') then you may wish to do the
    7.55 +# same here.  The bridge name can also be set when creating a domain or
    7.56 +# configuring a new vif, but a value specified here would act as a default.
    7.57 +#
    7.58 +# If you are using only one bridge, the vif-bridge script will discover that,
    7.59 +# so there is no need to specify it explicitly.
    7.60 +#
    7.61 +(vif-script vif-bridge)
    7.62 +
    7.63 +
    7.64 +## Use the following if network traffic is routed, as an alternative to the
    7.65 +# settings for bridged networking given above.
    7.66 +#(network-script network-route)
    7.67 +#(vif-script     vif-route)
    7.68 +
    7.69 +
    7.70 +## Use the following if network traffic is routed with NAT, as an alternative
    7.71 +# to the settings for bridged networking given above.
    7.72 +#(network-script network-nat)
    7.73 +#(vif-script     vif-nat)
    7.74 +
    7.75  
    7.76  # Dom0 will balloon out when needed to free memory for domU.
    7.77  # dom0-min-mem is the lowest memory level (in MB) dom0 will get down to.