File 0114-tcm_node-Unload-tcm-modules-recursively.patch of Package lio-utils.216
From 043ab42daefb274029cb4cc3e96805a2b6dc29db Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Tue, 9 Oct 2012 13:57:03 -0700
Subject: tcm_node: Unload tcm modules recursively
There might be different modules loaded and we might not know
all module names. So better parse the list of dependent modules
and try to unload them recursively.
(nab: Fix unload_modules typo in tcm_unload_modules)
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Nicholas Bellinger <nab@risingtidesystems.com>
---
tcm-py/tcm_node.py | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/tcm-py/tcm_node.py b/tcm-py/tcm_node.py
index 7cd0217..86eeef4 100755
--- a/tcm-py/tcm_node.py
+++ b/tcm-py/tcm_node.py
@@ -578,6 +578,21 @@ def tcm_show_wwn_info(dev_path):
if info:
print info
+def tcm_unload_modules(mod):
+ p = sub.Popen(["lsmod"], stdout=sub.PIPE)
+ o = p.communicate()[0]
+ for l in o.splitlines():
+ m = l.split()
+ if m[0] == mod:
+ if len(m) > 3:
+ for d in m[3].split(","):
+ tcm_unload_modules(d)
+ rmmod_op = "rmmod " + mod
+ ret = os.system(rmmod_op)
+ if ret:
+ tcm_err("Unable to " + rmmod_op)
+ return
+
def tcm_unload():
if not os.path.isdir(tcm_root):
tcm_err("Unable to access tcm_root: " + tcm_root)
@@ -596,15 +611,8 @@ def tcm_unload():
tcm_del_alua_lugp(lu_gp)
- # Unload TCM subsystem plugin modules
- for module in ("iblock", "file", "pscsi"):
- os.system("rmmod target_core_%s" % module)
-
- # Unload TCM Core
- rmmod_op = "rmmod target_core_mod"
- ret = os.system(rmmod_op)
- if ret:
- tcm_err("Unable to rmmod target_core_mod")
+ # Unload TCM subsystem plugin modules + TCM core
+ tcm_unload_modules("target_core_mod")
def tcm_version():
return tcm_read("/sys/kernel/config/target/version").strip()
--
1.8.1.4