Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / lustre / scripts / lustre_rmmod
index 9da25ff..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,6 +121,21 @@ if $DEBUG; then
        $LCTL mark "$SCRIPT_NAME : Start debug"
 fi
 
+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 | grep -v "LNET ready to unload"
+       fi
+fi
+
 for mod in ${modules[*]}; do
        unload_dep_modules_inclusive $mod || exit 1
 done