Whamcloud - gitweb
New tag 2.15.63
[fs/lustre-release.git] / lustre / scripts / lustre_rmmod
index 637c6a0..9dca753 100755 (executable)
@@ -8,6 +8,7 @@
 SCRIPT_NAME="$(basename "$0")"
 LCTL=${LCTL:-lctl}
 DEBUG='false'
+[[ -n $DEBUG_RMMOD ]] && DEBUG='true'
 
 # Print help message
 print_usage() {
@@ -23,8 +24,14 @@ print_usage() {
 
 # Print kernel debug message for lustre modules
 print_debug() {
+       local debug_file
        $LCTL mark "$SCRIPT_NAME : Stop debug"
-       $LCTL debug_kernel
+       if [[ $DEBUG_RMMOD == "-" ]]; then
+               debug_file="" # dump to stdout
+       else
+               debug_file=$DEBUG_RMMOD
+       fi
+       $LCTL debug_kernel $debug_file
        DEBUG='false'
 }
 
@@ -88,7 +95,10 @@ done
 # 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 [ "${#modules[@]}" -eq 0 ] || [ "${modules[*]}" = "ldiskfs" ]; then
-       modules=('ptlrpc' 'lnet_selftest' 'ldiskfs' 'libcfs')
+       unload_all=true
+       modules=('lnet_selftest' 'ldiskfs' 'libcfs')
+else
+       unload_all=false
 fi
 
 if [ -f /sys/kernel/debug/kmemleak ] ; then
@@ -111,17 +121,18 @@ if $DEBUG; then
        $LCTL mark "$SCRIPT_NAME : Start debug"
 fi
 
-# LNet may have an internal ref which can prevent LND modules from
-# unloading. Try to drop it before unloading modules.
-# NB: we squelch stderr because lnetctl/lctl may complain about
-# LNet being "busy", but this is normal. We're making a best effort
-# here.
-if lsmod | grep -q lnet; then
+if $unload_all; then
+       unload_dep_modules_inclusive 'ptlrpc' || exit 1
+       # LNet may have an internal ref which can prevent LND modules from
+       # unloading. Try to drop it before unloading modules.
+       # NB: we squelch stderr because lnetctl/lctl may complain about
+       # LNet being "busy", but this is normal. We're making a best effort
+       # here.
        # Prefer lnetctl if it is present
        if [ -n "$(which lnetctl 2>/dev/null)" ]; then
                lnetctl lnet unconfigure 2>/dev/null
        elif [ -n "$(which lctl 2>/dev/null)" ]; then
-               lctl net down 2>/dev/null
+               lctl net down 2>/dev/null | grep -v "LNET ready to unload"
        fi
 fi