ACC SHELL

Path : /etc/sysconfig/network/scripts/
File Upload :
Current File : //etc/sysconfig/network/scripts/ifup-infiniband

#! /bin/bash
#
# Copyright (c) 2007 SUSE LINUX Products GmbH, Germany.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Authors: Marius Tomaschewski <mt@suse.de>
#          Moni Shoua <monis@voltaire.com>
#
# $Id$
#

unset POSIXLY_CORRECT ; set +o posix # we're using non-posix bash features

usage () {
	echo $@
	echo "Usage: if{up,down,status}-infiniband [<config>] <interface> [-o <options>]"
	echo ""
	echo "Options are:"
	echo "    [on]boot : we are currently booting (or shutting down)"
	echo "    hotplug  : we are handling a hotplug event"
	echo "    auto     : alias for onboot"
	echo "    debug    : be verbose"
	echo ""
	exit $R_USAGE
}

######################################################################
# change the working direcory and source some common files
#
R_INTERNAL=1      # internal error, e.g. no config or missing scripts
cd /etc/sysconfig/network || exit $R_INTERNAL
test -f ./config && . ./config
test -f scripts/functions && . scripts/functions || exit $R_INTERNAL

######################################################################
# check arguments and how we are called (in case of links)
#
SCRIPTNAME=${0##*/}
debug $*
ACTION=${SCRIPTNAME#if}
ACTION=${ACTION%%-*}
case "${ACTION}" in
	up|status|down|check) ;;
	*) usage
esac
case "$1" in ""|-h|*help*) usage; esac
CONFIG=$1
shift
if [ -n "$1" -a "$1" != "-o" ] ; then
	INTERFACE=$1
else
	INTERFACE=$CONFIG
fi
shift
test "$1" = "-o" && shift
OPTIONS="$@"
MODE=manual
while [ $# -gt 0 ]; do
	case $1 in
		boot|onboot) MODE=auto ;;
		hotplug)     MODE=auto ;;
		auto)        MODE=auto ;;
		quiet)       be_quiet_has_gone ;;
		debug)       DEBUG=yes ;;
		*)           debug unknown option $1 ;;
	esac
	shift
done

######################################################################
# get the interface and check if it is available or up
#
# if ! is_iface_available  $INTERFACE ; then
# 	logerror "interface ${INTERFACE} is not available"
# 	exit $R_NODEV
# fi
# if ! is_iface_up $INTERFACE ; then
# 	logerror "interface ${INTERFACE} is not up"
# 	exit $R_NOTRUNNING
# fi

######################################################################
# check presence of configuration file and source it
#
if [ -f ifcfg-$CONFIG ] ; then
	. ifcfg-$CONFIG
else
	message "could not find configuration file ifcfg-$CONFIG"
fi

######################################################################
# Check needed tools
#

######################################################################
# Helper functions
create_ib_child_iface() {
	# e.g. ib0.8001
	IBIFACE=$1

	IBPARENT=${IBIFACE%%\.*}
	IBCHILD=${IBIFACE#*\.}

	# Check if the device name is ib0, ib1 etc.
	if [ "${IBPARENT:0:2}" != "ib" ] ; then
		return 1
	fi
	# Check if the devices does not contain a "."
	if [ "${IBCHILD}" == "${IBIFACE}" ] ; then
		return  1
	fi
	if [ -d "/sys/class/net/${IBPARENT}.${IBCHILD}" ] ; then
		return 0
	fi
	if [ -e "/sys/class/net/${IBPARENT}/create_child" ] ; then
		echo "0x${IBCHILD}" > "/sys/class/net/${IBPARENT}/create_child"
		ip link show dev "${IBPARENT}.${IBCHILD}" &>/dev/null
	else
		return 1
	fi
}
delete_ib_child_iface() {
	# e.g. ib0.8001
	IBIFACE=$1

	IBPARENT=${IBIFACE%%\.*}
	IBCHILD=${IBIFACE#*\.}

	# Check if the device name is ib0, ib1 etc.
	if [ "${IBPARENT:0:2}" != "ib" ] ; then
		return 1
	fi
	# Check if the devices does not contain a "."
	if [ "${IBCHILD}" == "${IBIFACE}" ] ; then
		return 1
	fi
	if [ ! -d "/sys/class/net/${IBPARENT}.${IBCHILD}" ] ; then
		return 0
	fi
	if [ -e "/sys/class/net/${IBPARENT}/delete_child" ] ; then
		echo "0x${IBCHILD}" > "/sys/class/net/${IBPARENT}/delete_child"
		[ -d "/sys/class/net/${IBPARENT}.${IBCHILD}" ] || return 0
	else
		return 1
	fi
}


######################################################################
# now do what has to be done
#
RETVAL=$R_SUCCESS

case $ACTION in
up)
	# verify values of interface parameters
	case $IPOIB_MODE in
	connected|datagram|"") ;;
	*)
		message "illegal value for IPOIB_MODE: $IPOIB_MODE"
		exit $R_ERROR
	;;
	esac
	case $IPOIB_UMCAST in
	0|1|"") ;;
	*)
		message "illegal value for IPOIB_UMCAST: $IPOIB_UMCAST"
		exit $R_ERROR
	;;
	esac

	# create ib-child interfaces, report non-existing parents
	case "$INTERFACE" in
	ib*.*)	# ib child interface
		create_ib_child_iface "$INTERFACE" || RETVAL=$R_ERROR
	;;
	*)	# ib parent interface
		if ! is_iface_available  $INTERFACE ; then
			logerror "interface ${INTERFACE} is not available"
			exit $R_NODEV
		fi
	;;
	esac

	# set interface parameters
	if test -n "$IPOIB_MODE" ; then
		echo "$IPOIB_MODE"   > "/sys/class/net/$INTERFACE/mode"
	fi
	if test -n "$IPOIB_UMCAST" ; then
		echo "$IPOIB_UMCAST" > "/sys/class/net/$INTERFACE/umcast"
	fi
;;
down)
	case "$INTERFACE" in
	ib*.*)	# ib child interface
		delete_ib_child_iface "$INTERFACE" || RETVAL=$R_ERROR
	;;
	*)	# ib parent interface
		:
	;;
	esac
;;
status)
	: action not implemented for $INTERFACE
;;
check)
	: check action not implemented for $INTERFACE
;;
esac

exit $RETVAL

ACC SHELL 2018