From d862d75c452ba4016d81fdd14981b2515b2d0e07 Mon Sep 17 00:00:00 2001
From: grev <grev>
Date: Tue, 15 Jul 2008 17:16:41 +0000
Subject: [PATCH] b=16001 (made by Adilger) unload modules in order based on
 dependencies

---
 lustre/tests/test-framework.sh | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh
index eab0e0aac6..39518fc1df 100644
--- a/lustre/tests/test-framework.sh
+++ b/lustre/tests/test-framework.sh
@@ -282,18 +282,26 @@ wait_for_lnet() {
     done
 }
 
+unload_dep_module() {
+    #lsmod output
+    #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
+}
+
 unload_modules() {
     wait_exit_ST client # bug 12845
 
     lsmod | grep libcfs > /dev/null && $LCTL dl
-    local MODULES=$($LCTL modules | awk '{ print $2 }' | grep -v libcfs) || true
-    $RMMOD $MODULES > /dev/null 2>&1 || true
-     # do it again, in case we tried to unload ksocklnd too early
-    MODULES=$($LCTL modules | awk '{ print $2 }' | grep -v libcfs) || true
-    [ -n "$MODULES" ] && $RMMOD $MODULES > /dev/null 2>&1 || true
-    lsmod | grep libcfs > /dev/null && $LCTL dk $TMP/debug
-    $RMMOD libcfs
-    MODULES=$($LCTL modules | awk '{ print $2 }')
+    unload_dep_module $FSTYPE
+    unload_dep_module libcfs
+
+    local MODULES=$($LCTL modules | awk '{ print $2 }')
     if [ -n "$MODULES" ]; then
         echo "Modules still loaded: "
         echo $MODULES 
-- 
GitLab