Whamcloud - gitweb
LU-9100 lnet: lctl net down success when lnet not loaded
[fs/lustre-release.git] / lustre / scripts / lnet
index af08125..10e91c9 100644 (file)
 # Check for and source configuration file otherwise set defaults
 [ -f /etc/sysconfig/lnet ] && . /etc/sysconfig/lnet
 
-declare -r TOP_MODULES=(       \
-       obdecho                 \
-       llite                   \
-       lustre                  \
-       osc                     \
-       lov                     \
-       mds                     \
-       mdc                     \
-       mgs                     \
-       mgc                     \
-       ost                     \
-       obdfilter               \
-       lquota                  \
-       ptlrpc                  \
-)
-declare -r BOTTOM_MODULES=(    \
-       ksocklnd                \
-       kqswlnd                 \
-       ko2iblnd                \
-       obdclass                \
-       lnet                    \
-       lvfs                    \
-       libcfs                  \
-       ldiskfs                 \
-)
-
 declare -r awkprog='BEGIN { rc = -1 }
                       { if ( $1 == module_name ) { rc = $3; exit; } }
                    END { print rc }'
@@ -78,58 +52,6 @@ run_postexec_check ()
        fi
 }
 
-remove_modules ()
-{
-       local modules="${@}"
-       local ref_cnt
-
-       for mod in $modules; do
-               ref_cnt=`/sbin/lsmod | awk "$awkprog" "module_name=$mod"`
-               if [ $ref_cnt -lt 0 ]; then
-                       # module not loaded, skip it
-                       continue
-               fi
-               if [ $ref_cnt -gt 0 ]; then
-                       # module in use.  maybe it just needs a few seconds
-                       # after removal of previous modules.
-                       sleep 5
-                       ref_cnt=`/sbin/lsmod | awk "$awkprog" module_name=$mod`
-               fi
-               if [ $ref_cnt -eq 0 ]; then
-                       # unload the module
-                       echo "Removing module $mod"
-                       /sbin/rmmod $mod
-                       if [ $? -ne 0 ]; then
-                               echo "ERROR: Failed to remove module $mod."
-                               return 1
-                       fi
-               else
-                       # boo!  module still in use.
-                       echo "ERROR: Module $mod has non-zero reference count."
-                       return 1
-               fi
-       done
-
-       return 0
-}
-
-stop_lnet ()
-{
-       local errmsg=`/usr/sbin/lctl network unconfigure 2>&1`
-       if [ $? -gt 0 ]; then
-               # The following error message means that lnet is already
-               # unconfigured, and the modules are not loaded.
-               echo $errmsg | grep "LNET unconfigure error 19" > /dev/null
-               if [ $? -gt 0 ]; then
-                       return 0
-               else
-                       echo "$errmsg"
-                       return 1
-               fi
-       fi
-       return 0
-}
-
 status ()
 {
        old_nullglob="`shopt -p nullglob`"
@@ -174,6 +96,8 @@ status ()
 }
 
 LUSTRE_ROUTES_CONFIG_FILE="/etc/sysconfig/lnet_routes.conf"
+LUSTRE_LNET_CONFIG_FILE="/etc/sysconfig/lnet.conf"
+LUSTRE_LNET_CONFIG_UTILITY="/usr/sbin/lnetctl"
 
 # See how we were called.
 case "$1" in
@@ -181,7 +105,21 @@ case "$1" in
        run_preexec_check "start"
        touch /var/lock/subsys/lnet
        modprobe lnet || exit 1
-       lctl network up || exit 1
+       # if lnet.conf file exists then use lnetctl lnet configure, since
+       # that doesn't load the networks and routes defined in the mod
+       # params.  The appropriate configuration will be picked up from
+       # the lnet.conf YAML file.
+       if [ -x $LUSTRE_LNET_CONFIG_UTILITY -a -f "$LUSTRE_LNET_CONFIG_FILE" ]; then
+               $LUSTRE_LNET_CONFIG_UTILITY lnet configure || exit 1
+       else
+               lctl network up || exit 1
+       fi
+       # if an lnet.conf file exists then pass that to the lnetctl
+       # utility for parsing.  This will configure the items defined
+       # in YAML format in the config file.
+       if [ -x $LUSTRE_LNET_CONFIG_UTILITY -a -f "$LUSTRE_LNET_CONFIG_FILE" ]; then
+               $LUSTRE_LNET_CONFIG_UTILITY import < $LUSTRE_LNET_CONFIG_FILE
+       fi
        # if a routes config file is given then use it to configure the
        # routes if not then default to LUSTRE_ROUTES_CONFIG_FILE
        if [ -f "$2" ]; then
@@ -193,9 +131,8 @@ case "$1" in
        ;;
   stop)
        run_preexec_check "stop"
-       remove_modules ${TOP_MODULES[*]} || exit 1
-       stop_lnet || exit 1
-       remove_modules ${BOTTOM_MODULES[*]} || exit 1
+       lctl network down || exit 1
+       lustre_rmmod || exit 1
        rm -f /var/lock/subsys/lnet
        run_postexec_check "stop"
        ;;
@@ -221,7 +158,7 @@ case "$1" in
        }
        ;;
   *)
-       echo $"Usage: lustre {start|stop|status|restart|reload|condrestart}"
+       echo $"Usage: lnet {start|stop|status|restart|reload|condrestart}"
        exit 1
 esac