3 # Takes a list of modules and unloads them and all dependent modules.
4 # If a module cannot be unloaded (e.g. it's in use), an error is
6 ###############################################################################
8 SCRIPT_NAME="$(basename "$0")"
14 echo "$SCRIPT_NAME -h|--help"
15 echo "$SCRIPT_NAME [-d|--debug-kernel] [modulesname...]"
17 echo -e "\t-h, --help\t\tDisplay this help message"
18 echo -e "\t-d, --debug-kernel\tDisplay lustre kernel debug messages"
19 echo -e "\tmodulesname\t\tList of lustre modules to unload. By default"
20 echo -e "\t\t\t\tldiskfs and libcfs (and their dependencies) are"
21 echo -e "\t\t\t\tselected."
24 # Print kernel debug message for lustre modules
26 $LCTL mark "$SCRIPT_NAME : Stop debug"
31 # Unload all modules dependent on $1 (exclude removal of $1)
32 unload_dep_modules_exclusive() {
35 local DEPS="$(lsmod | awk '($1 == "'$MODULE'") { print $4 }')"
36 for SUBMOD in $(echo $DEPS | tr ',' ' '); do
37 unload_dep_modules_inclusive $SUBMOD || return 1
42 # Unload all modules dependent on $1 (include removal of $1)
43 unload_dep_modules_inclusive() {
46 # if $MODULE not loaded, return 0
47 lsmod | egrep -q "^\<$MODULE\>" || return 0
48 unload_dep_modules_exclusive $MODULE || return 1
51 if [ "$MODULE" = 'libcfs' ]; then
54 $LCTL mark "$SCRIPT_NAME : Unload $MODULE"
57 rmmod $MODULE || return 1
62 while [ $# -gt 0 ]; do
69 if lsmod | egrep -q '^libcfs'; then
72 echo "Debug unavailable: libcfs is not loaded" >&2
76 echo "Error invalid option" >&2
87 # To maintain backwards compatibility, ldiskfs and libcfs must be
88 # unloaded if no parameters are given, or if only the ldiskfs parameter
89 # is given. It's ugly, but is needed to emulate the prior functionality
90 if [ "${#modules[@]}" -eq 0 ] || [ "${modules[*]}" = "ldiskfs" ]; then
91 modules=('ptlrpc' 'lnet_selftest' 'ldiskfs' 'libcfs')
94 if [ -f /sys/kernel/debug/kmemleak ] ; then
95 cat /proc/modules >/tmp/kmemleak-modules-list.txt
96 echo scan > /sys/kernel/debug/kmemleak
97 cat /sys/kernel/debug/kmemleak > /tmp/kmemleak-before-unload.txt
98 test -s /tmp/kmemleak-before-unload.txt && logger -t leak-pre -f /tmp/kmemleak-before-unload.txt
99 rm /tmp/kmemleak-before-unload.txt
100 # Clear everything here so that only new leaks show up
101 # after module unload
102 echo clear > /sys/kernel/debug/kmemleak
107 echo "Lustre debug parameters:" >&2
108 $LCTL get_param debug >&2
109 $LCTL get_param debug_mb >&2
111 $LCTL mark "$SCRIPT_NAME : Start debug"
114 for mod in ${modules[*]}; do
115 unload_dep_modules_inclusive $mod || exit 1
122 if [ -f /sys/kernel/debug/kmemleak ] ; then
123 echo scan > /sys/kernel/debug/kmemleak
124 cat /sys/kernel/debug/kmemleak > /tmp/kmemleak-after-unload.txt
125 test -s /tmp/kmemleak-after-unload.txt && logger -t leak-mods -f /tmp/kmemleak-modules-list.txt && logger -t leak-post -f /tmp/kmemleak-after-unload.txt
126 rm -f /tmp/kmemleak-after-unload.txt /tmp/kmemleak-modules-list.txt