ia64/xen-unstable

changeset 16072:b629d7a2bcc7

[NW scripts] Choose alternative interface if NFSroot is used.

Allow the network bridging setup script to choose an alternative
network interface if it is determined that the root is mounted using
NFS, which is assumed to be done over the NIC serving the default
gw. In this case the prefix of the device is used to find other
devices, i.e., if eth0 is the default device an alternative device may
be an other ones starting with 'eth'.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author Keir Fraser <keir@xensource.com>
date Fri Oct 05 10:31:25 2007 +0100 (2007-10-05)
parents 2d761ca771fb
children 1d120f6807ba
files tools/examples/network-bridge
line diff
     1.1 --- a/tools/examples/network-bridge	Thu Oct 04 17:58:16 2007 +0100
     1.2 +++ b/tools/examples/network-bridge	Fri Oct 05 10:31:25 2007 +0100
     1.3 @@ -56,8 +56,32 @@ dir=$(dirname "$0")
     1.4  findCommand "$@"
     1.5  evalVariables "$@"
     1.6  
     1.7 +is_network_root () {
     1.8 +    local rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab)
     1.9 +    local rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
    1.10 +
    1.11 +    [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && return 0 || return 1
    1.12 +}
    1.13 +
    1.14 +find_alt_device () {
    1.15 +    local interf=$1
    1.16 +    local prefix=${interf%[[:digit:]]}
    1.17 +    local ifs=$(ip link show | grep " $prefix" |\
    1.18 +                gawk '{ printf ("%s",substr($2,1,length($2)-1)) }' |\
    1.19 +                sed s/$interf//)
    1.20 +    echo "$ifs"
    1.21 +}
    1.22 +
    1.23  netdev=${netdev:-$(ip route list | awk '/^default / { print $NF }' |
    1.24  		   sed 's/.* dev //')}
    1.25 +if is_network_root ; then
    1.26 +    altdevs=$(find_alt_device $netdev)
    1.27 +    for netdev in $altdevs; do break; done
    1.28 +    if [ -z "$netdev" ]; then
    1.29 +        [ -x /usr/bin/logger ] && /usr/bin/logger "network-bridge: bridging not supported on network root; not starting"
    1.30 +        exit
    1.31 +    fi
    1.32 +fi
    1.33  netdev=${netdev:-eth0}
    1.34  bridge=${bridge:-${netdev}}
    1.35  antispoof=${antispoof:-no}
    1.36 @@ -173,23 +197,11 @@ show_status () {
    1.37      echo '============================================================'
    1.38  }
    1.39  
    1.40 -is_network_root () {
    1.41 -    local rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab)
    1.42 -    local rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
    1.43 -
    1.44 -    [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && return 0 || return 1
    1.45 -}
    1.46 -
    1.47  op_start () {
    1.48      if [ "${bridge}" = "null" ] ; then
    1.49  	return
    1.50      fi
    1.51  
    1.52 -    if is_network_root ; then
    1.53 -        [ -x /usr/bin/logger ] && /usr/bin/logger "network-bridge: bridging not supported on network root; not starting"
    1.54 -        return
    1.55 -    fi
    1.56 -
    1.57      if link_exists "$pdev"; then
    1.58          # The device is already up.
    1.59          return