/etc/init.d/scst: Introduce function unload_kmod()

git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6429 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2015-07-27 16:10:36 +00:00
parent 7a2d9043f6
commit 2715178d01

View File

@@ -164,6 +164,21 @@ parse_scst_conf() {
fi
}
# Keep trying to unload kernel module $1 for up to $2 seconds. Return true
# if and only if the kernel module was unloaded before the timeout expired.
unload_kmod() {
local i m t
m="$1"
t="$2"
i=0
while [ -e "/sys/module/$m/refcnt" ] && ! rmmod "$m" && [ $i -lt "$t" ]; do
sleep 1
i=$((i+1))
done
[ ! -e "/sys/module/$m/refcnt" ]
}
# Unload SCST. parse_scst_conf must already have been invoked.
unload_scst() {
for d in $SCST_DAEMONS; do
@@ -182,14 +197,7 @@ unload_scst() {
# occurs, sleep for a short time.
sleep 1
fi
i=0
while [ -e /sys/module/$m/refcnt ] && ! rmmod $m && [ $i -lt 30 ]; do
sleep 1
i=$((i+1))
done
if [ -e /sys/module/$m/refcnt ]; then
return 1
fi
unload_kmod $m 30 || return 1
done
for m in $SCST_OPT_MODULES; do
reverse_list="$m $reverse_list"