From: Stefan Berger Subject: [PATCH] [NW scripts] [RFC] Choose alternative interface if NFSroot is used Date: Thu, 04 Oct 2007 16:58:30 -0400 Message-ID: <1191531510.22691.12.camel@gsal-3.watson.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-cmDcHe/sFqv3a0r5g2g1" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org --=-cmDcHe/sFqv3a0r5g2g1 Content-Type: text/plain Content-Transfer-Encoding: 7bit I am proposing this patch for allowing 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 --=-cmDcHe/sFqv3a0r5g2g1 Content-Disposition: attachment; filename=network_bridge_alternativ_interface_if_nfsroot.diff Content-Type: text/x-patch; name=network_bridge_alternativ_interface_if_nfsroot.diff; charset=UTF-8 Content-Transfer-Encoding: 7bit Index: root/xen-unstable.hg/tools/examples/network-bridge =================================================================== --- root.orig/xen-unstable.hg/tools/examples/network-bridge +++ root/xen-unstable.hg/tools/examples/network-bridge @@ -56,8 +56,32 @@ dir=$(dirname "$0") findCommand "$@" evalVariables "$@" +is_network_root () { + local rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab) + local rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab) + + [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && return 0 || return 1 +} + +find_alt_device () { + local interf=$1 + local prefix=${interf%[[:digit:]]} + local ifs=$(ip link show | grep " $prefix" |\ + gawk '{ printf ("%s",substr($2,1,length($2)-1)) }' |\ + sed s/$interf//) + echo "$ifs" +} + netdev=${netdev:-$(ip route list | awk '/^default / { print $NF }' | sed 's/.* dev //')} +if is_network_root ; then + altdevs=$(find_alt_device $netdev) + for netdev in $altdevs; do break; done + if [ -z "$netdev" ]; then + [ -x /usr/bin/logger ] && /usr/bin/logger "network-bridge: bridging not supported on network root; not starting" + exit + fi +fi bridge=${bridge:-${netdev}} antispoof=${antispoof:-no} @@ -172,23 +196,11 @@ show_status () { echo '============================================================' } -is_network_root () { - local rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab) - local rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab) - - [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && return 0 || return 1 -} - op_start () { if [ "${bridge}" = "null" ] ; then return fi - if is_network_root ; then - [ -x /usr/bin/logger ] && /usr/bin/logger "network-bridge: bridging not supported on network root; not starting" - return - fi - if link_exists "$pdev"; then # The device is already up. return --=-cmDcHe/sFqv3a0r5g2g1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-cmDcHe/sFqv3a0r5g2g1--