X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fscripts%2Flustre_rmmod;h=a2dfd0a2b7a1360e1f6d24ba4415b8ebd58a55b5;hp=b1020f44dfb6e41af7d9bf80ff0f7f9e6ef9045a;hb=25ee73e7733214f7a46f81b2540b7fca67b0eef1;hpb=69cf4a311196f841c3016c526f1e79a9812b6912 diff --git a/lustre/scripts/lustre_rmmod b/lustre/scripts/lustre_rmmod index b1020f4..a2dfd0a 100755 --- a/lustre/scripts/lustre_rmmod +++ b/lustre/scripts/lustre_rmmod @@ -1,41 +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} - -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 (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 +} -RMMOD=rmmod -if [ `uname -r | cut -c 3` -eq 4 ]; then - RMMOD="modprobe -r" -fi +# Unload all modules dependent on $1 (include removal of $1) +unload_dep_modules_inclusive() { + local MODULE=$1 -unload_dep_module() { - # libcfs 107852 17 llite_lloop,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 || true - $RMMOD $MODULE || true + # 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 libcfs > /dev/null && $LCTL dl -lsmod | grep $FSTYPE && unload_dep_module $FSTYPE -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