[PATCH 3/3] tcm_node: Unload tcm modules recursively

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Hannes Reinecke <hare@xxxxxxx>

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@xxxxxxx>
Signed-off-by: Nicholas Bellinger <nab@xxxxxxxxxxxxxxxxxxxxx>
---
 tcm-py/tcm_node.py |   26 +++++++++++++++++---------
 1 files 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.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux