From 2715178d01993f457574767b5bb2f2b49d7b6e07 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 27 Jul 2015 16:10:36 +0000 Subject: [PATCH] /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 --- scstadmin/init.d/scst | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scstadmin/init.d/scst b/scstadmin/init.d/scst index 6bd0915ae..2c33606e2 100755 --- a/scstadmin/init.d/scst +++ b/scstadmin/init.d/scst @@ -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"