Whamcloud - gitweb
LU-9439 scripts: Change behavior of lustre_rmmod 13/27213/4
authorPrakash Surya <surya1@llnl.gov>
Wed, 20 Feb 2013 17:18:13 +0000 (09:18 -0800)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 3 Jun 2017 03:58:29 +0000 (03:58 +0000)
The lustre_rmmod script was modified to take an arbitrary list of
modules and try to remove them and any modules dependent on them.
Previously its behavior was to always remove the libcfs module,
along with either the ldiskfs or another module passed as a
parameter.

The old interface was roughly maintained. Any of the following
commands will remove the ldiskfs, libcfs, and all dependent modules:

    $ lustre_rmmod
    $ lustre_rmmod ldiskfs
    $ lustre_rmmod ldiskfs libcfs

The benefit now, is that any other list of modules can be specified
without removing libcfs. For example, the following command will only
remove ptlrpc and its dependent modules (leaving libcfs intact):

    $ lustre_rmmod ptlrpc

The lnet init script was modified to perform a lustre_rmmod ptlrpc
before performing an lctl network down. By removing the ptlrpc
module, we can ensure that lnet is not in use. This will help
systems running lustre to shut down cleanly.

Signed-off-by: Prakash Surya <surya1@llnl.gov>
Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Change-Id: I3fbb33ccb00eb96c255c702b238af9d46768954b
Reviewed-on: https://review.whamcloud.com/27213
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
lustre/scripts/lnet
lustre/scripts/lustre_rmmod

index 01f7e4f..43ad5bf 100644 (file)
@@ -131,8 +131,9 @@ case "$1" in
        ;;
   stop)
        run_preexec_check "stop"
+       lustre_rmmod ptlrpc || exit 1
        lctl network down || exit 1
-       lustre_rmmod || exit 1
+       lustre_rmmod libcfs ldiskfs || exit 1
        rm -f /var/lock/subsys/lnet
        run_postexec_check "stop"
        ;;
index 76a9d11..a2dfd0a 100755 (executable)
@@ -1,38 +1,42 @@
-#!/bin/sh
+#!/bin/bash
 #
-# remove all lustre modules.  Won't succeed if they're in use, or if you
-# manually did a 'lctl network up'.
+# Takes a list of modules and unloads them and all dependent modules.
+# If a module cannot be unloaded (e.g. it's in use), an error is
+# returned.
 ###############################################################################
 
-FSTYPE=${1:-ldiskfs}
+# Unload all modules dependent on $1 (exclude removal of $1)
+unload_dep_modules_exclusive() {
+       local MODULE=$1
+       local DEPS="$(lsmod | awk '($1 == "'$MODULE'") { print $4 }')"
+       for SUBMOD in $(echo $DEPS | tr ',' ' '); do
+               unload_dep_modules_inclusive $SUBMOD || return 1
+       done
+       return 0
+}
 
-TMP=${TMP:-/tmp}
-LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
-LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
-[ ! -f "$LCTL" ] && export LCTL=$(which lctl 2> /dev/null)
+# Unload all modules dependent on $1 (include removal of $1)
+unload_dep_modules_inclusive() {
+       local MODULE=$1
 
-unload_dep_module() {
-    # libcfs                107852  17 lustre,obdfilter,ost,...
-    local MODULE=$1
-    local DEPS="$(lsmod | awk '($1 == "'$MODULE'") { print $4 }' | tr ',' ' ')"
-    for SUBMOD in $DEPS; do
-        unload_dep_module $SUBMOD
-    done
-    [ "$MODULE" = "libcfs" ] && $LCTL dk $TMP/debug >/dev/null || true
-    rmmod $MODULE 2>/dev/null || true
-    return 0
+       # if $MODULE not loaded, return 0
+       lsmod | egrep -q "^\<$MODULE\>" || return 0
+       unload_dep_modules_exclusive $MODULE || return 1
+       rmmod $MODULE || return 1
+       return 0
 }
 
-lsmod | grep obdclass > /dev/null && $LCTL dl
-lsmod | grep $FSTYPE > /dev/null && unload_dep_module $FSTYPE
-lsmod | grep ptlrpc > /dev/null && unload_dep_module ptlrpc
-lsmod | grep libcfs > /dev/null && unload_dep_module libcfs
+modules="$@"
 
-MODULES=$($LCTL modules | awk '{ print $2 }')
-if [ -n "$MODULES" ]; then
-    echo "Modules still loaded: "
-    echo $MODULES
-    exit 1
+# To maintain backwards compatibility, ldiskfs and libcfs must be
+# unloaded if no parameters are given, or if only the ldiskfs parameter
+# is given. It's ugly, but is needed to emulate the prior functionality
+if [ -z "$modules" ] || [ "$modules" = "ldiskfs" ]; then
+       modules="ptlrpc lnet_selftest ldiskfs libcfs"
 fi
-exit 0
 
+for mod in $modules; do
+       unload_dep_modules_inclusive $mod || exit 1
+done
+
+exit 0