+if [ "${#modules[@]}" -eq 0 ] || [ "${modules[*]}" = "ldiskfs" ]; then
+ unload_all=true
+ modules=('lnet_selftest' 'ldiskfs' 'libcfs')
+else
+ unload_all=false
+fi
+
+if [ -f /sys/kernel/debug/kmemleak ] ; then
+ cat /proc/modules >/tmp/kmemleak-modules-list.txt
+ echo scan > /sys/kernel/debug/kmemleak
+ cat /sys/kernel/debug/kmemleak > /tmp/kmemleak-before-unload.txt
+ test -s /tmp/kmemleak-before-unload.txt && logger -t leak-pre -f /tmp/kmemleak-before-unload.txt
+ rm /tmp/kmemleak-before-unload.txt
+ # Clear everything here so that only new leaks show up
+ # after module unload
+ echo clear > /sys/kernel/debug/kmemleak
+fi
+
+# Manage debug
+if $DEBUG; then
+ echo "Lustre debug parameters:" >&2
+ $LCTL get_param debug >&2
+ $LCTL get_param debug_mb >&2
+
+ $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