File 0013-lio_node-Silence-output.patch of Package lio-utils

From 352f47122913bf6749106766de6ca5c186a79048 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Thu, 17 Apr 2014 09:08:08 +0200
Subject: lio_node: Silence output

Add option '--debug' to silence lio_node for the standard case.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 lio-py/lio_node.py | 81 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 48 insertions(+), 33 deletions(-)

diff --git a/lio-py/lio_node.py b/lio-py/lio_node.py
index 78c7592..d58213f 100755
--- a/lio-py/lio_node.py
+++ b/lio-py/lio_node.py
@@ -8,11 +8,18 @@ from optparse import OptionParser
 tcm_root = "/sys/kernel/config/target/core"
 lio_root = "/sys/kernel/config/target/iscsi"
 alua_secondary_md_dir = "/var/target/alua/iSCSI/"
+lio_debug = 0
 
 def lio_err(msg):
 	print msg
 	sys.exit(1)
 
+def lio_dbg(msg):
+	global lio_debug
+
+	if lio_debug:
+		print msg
+
 def lio_alua_check_secondary_md(iqn, tpgt):
 	alua_sec_md_path = alua_secondary_md_dir + iqn + "+" + tpgt + "/"
 	if os.path.isdir(alua_sec_md_path) == False:
@@ -85,7 +92,7 @@ def lio_alua_process_secondary_md(option, opt_str, value, parser):
 
 	p = open(alua_sec_md_file, 'rU')
 	if not p:
-		print "Unable to process ALUA secondary metadata for: " + alua_sec_md_file
+		lio_dbg("Unable to process ALUA secondary metadata for: " + alua_sec_md_file)
 
 	line = p.readline()
 	while line:
@@ -152,7 +159,7 @@ def __lio_target_del_iqn(option, opt_str, value, parser, delete_tpg_md):
 #	print "rmdir_op: " + rmdir_op
 	ret = os.system(rmdir_op)
 	if not ret:
-		print "Successfully released iSCSI Target Endpoint IQN: " + iqn
+		lio_dbg("Successfully released iSCSI Target Endpoint IQN: " + iqn)
 	else:
 		lio_err("Unable to release iSCSI Target Endpoint IQN: " + iqn)
 
@@ -214,7 +221,7 @@ def __lio_target_del_tpg(option, opt_str, value, parser, delete_tpg_md):
 #	print "rmdir_op: " + rmdir_op
 	ret = os.system(rmdir_op)
 	if not ret:
-		print "Successfully released iSCSI Target Portal Group: " + iqn + " TPGT: " + tpgt
+		lio_dbg("Successfully released iSCSI Target Portal Group: " + iqn + " TPGT: " + tpgt)
 	else:
 		lio_err("Unable to release iSCSI Target Portal Group: " + iqn + " TPGT: " + tpgt)
 	
@@ -266,7 +273,7 @@ def lio_target_add_np(option, opt_str, value, parser):
 #	print "mkdir_op: " + mkdir_op
 	ret = os.system(mkdir_op)
 	if not ret:
-		print "Successfully created network portal: " + np + " created " + iqn + " TPGT: " + tpgt 
+		lio_dbg("Successfully created network portal: " + np + " created " + iqn + " TPGT: " + tpgt )
 		lio_alua_check_secondary_md(iqn, tpgt)
 	else:
 		lio_err("Unable to create network portal: " + np + " created " + iqn + " TPGT: " + tpgt)
@@ -296,7 +303,7 @@ def lio_target_del_np(option, opt_str, value, parser):
 #	print "rmdir_op: " + rmdir_op
 	ret = os.system(rmdir_op)
 	if not ret:
-		print "Successfully released network portal: " + np + " created " + iqn + " TPGT: " + tpgt
+		lio_dbg("Successfully released network portal: " + np + " created " + iqn + " TPGT: " + tpgt)
 	else:
 		lio_err("Unable to release network portal: " + np + " created " + iqn + " TPGT: " + tpgt)
 
@@ -326,7 +333,7 @@ def lio_target_add_port(option, opt_str, value, parser):
 #	print "link_op: " + link_op
 	ret = os.system(link_op)
 	if not ret:
-		print "Successfully created iSCSI Target Logical Unit"
+		lio_dbg("Successfully created iSCSI Target Logical Unit")
 		lio_alua_check_secondary_md(iqn, tpgt)
 		lio_alua_set_secondary_write_md(iqn, tpgt, lun)
 	else:
@@ -349,7 +356,7 @@ def lio_target_add_tpg(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to create iSCSI Target Portal Group ConfigFS directory")
 	else:
-		print "Successfully created iSCSI Target Portal Group"
+		lio_dbg("Successfully created iSCSI Target Portal Group")
 		lio_alua_check_secondary_md(iqn, tpgt)
 
 	return
@@ -386,7 +393,7 @@ def __lio_target_del_port(option, opt_str, value, parser):
 #	print "del_port rmdir_op: " + rmdir_op
 	ret = os.system(rmdir_op);
 	if not ret:
-		print "Successfully deleted iSCSI Target Logical Unit"
+		lio_dbg("Successfully deleted iSCSI Target Logical Unit")
 	else:
 		lio_err("Unable to rmdir iSCSI Target Logical Unit configfs directory")
 
@@ -419,7 +426,7 @@ def lio_target_tpg_disableauth(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to disable iSCSI Authentication on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully disabled iSCSI Authentication on iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully disabled iSCSI Authentication on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -433,7 +440,7 @@ def lio_target_tpg_demomode(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to disable Initiator ACL mode (Enable DemoMode) on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully disabled Initiator ACL mode (Enabled DemoMode) on iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully disabled Initiator ACL mode (Enabled DemoMode) on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -450,7 +457,7 @@ def lio_target_disable_lunwp(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to disable WriteProtect for Mapped LUN: " + mapped_lun + " for " + initiator_iqn + " on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully disabled WRITE PROTECT for Mapped LUN: " + mapped_lun + " for " + initiator_iqn + " on iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully disabled WRITE PROTECT for Mapped LUN: " + mapped_lun + " for " + initiator_iqn + " on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -464,7 +471,7 @@ def lio_target_enable_auth(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to enable iSCSI Authentication on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully enabled iSCSI Authentication on iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully enabled iSCSI Authentication on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	return
 
 def lio_target_enable_lunwp(option, opt_str, value, parser):
@@ -480,7 +487,7 @@ def lio_target_enable_lunwp(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to enable WriteProtect for Mapped LUN: " + mapped_lun + " for " + initiator_iqn + " on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully enabled WRITE PROTECT for Mapped LUN: " + mapped_lun + " for " + initiator_iqn + " on iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully enabled WRITE PROTECT for Mapped LUN: " + mapped_lun + " for " + initiator_iqn + " on iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -494,7 +501,7 @@ def lio_target_enable_tpg(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to enable iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully enabled iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully enabled iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -508,7 +515,7 @@ def lio_target_disable_tpg(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to disable iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully disabled iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully disabled iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -522,7 +529,7 @@ def lio_target_enableaclmode(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to enable Initiator ACL mode (Disabled DemoMode) on iSCSI Target Portal Group: " + iqn + " " + tpgt)
         else:
-                print "Successfully enabled Initiator ACL mode (Disabled DemoMode) on iSCSI Target Portal Group: " + iqn + " " + tpgt
+                lio_dbg("Successfully enabled Initiator ACL mode (Disabled DemoMode) on iSCSI Target Portal Group: " + iqn + " " + tpgt)
         return
 
 
@@ -546,7 +553,7 @@ def lio_target_add_lunacl(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to add iSCSI Initiator Mapped LUN: " + mapped_lun + " ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully added iSCSI Initiator Mapped LUN: " + mapped_lun + " ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully added iSCSI Initiator Mapped LUN: " + mapped_lun + " ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 		lio_alua_check_secondary_md(iqn, tpgt)
 
 	return
@@ -578,7 +585,7 @@ def lio_target_del_lunacl(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to delete iSCSI Initiator Mapped LUN: " + mapped_lun + " ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully deleted iSCSI Initiator Mapped LUN: " + mapped_lun + " ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully deleted iSCSI Initiator Mapped LUN: " + mapped_lun + " ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -594,7 +601,7 @@ def lio_target_add_nodeacl(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to add iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully added iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully added iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 		lio_alua_check_secondary_md(iqn, tpgt)
 
 	return
@@ -620,7 +627,7 @@ def lio_target_del_nodeacl(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to delete iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully deleted iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully deleted iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -648,7 +655,7 @@ def lio_target_set_chap_auth(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to set CHAP password for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully set CHAP authentication for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully set CHAP authentication for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -676,7 +683,7 @@ def lio_target_set_chap_mutual_auth(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to set mutual CHAP password for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully set mutual CHAP authentication for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt	
+		lio_dbg("Successfully set mutual CHAP authentication for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	
 	return
 
@@ -698,7 +705,7 @@ def lio_target_set_chap_discovery_auth(option, opt_str, value, parser):
         if ret:
                 lio_err("Unable to set CHAP password for iSCSI Discovery Authentication")
         else:
-                print "Successfully set CHAP authentication for iSCSI Discovery Authentication"
+                lio_dbg("Successfully set CHAP authentication for iSCSI Discovery Authentication")
 
 	return
 
@@ -720,7 +727,7 @@ def lio_target_set_chap_mutual_discovery_auth(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to set mutual CHAP password for iSCSI Discovery Authentication")
 	else:
-		print "Successfully set mutual CHAP authentication for iSCSI Discovery Authentication"
+		lio_dbg("Successfully set mutual CHAP authentication for iSCSI Discovery Authentication")
 
 	return
 
@@ -737,9 +744,9 @@ def lio_target_set_enforce_discovery_auth(option, opt_str, value, parser):
 		lio_err("Unable to set da_attr: " + da_attr)
 
 	if value == "1":
-		print "Successfully enabled iSCSI Discovery Authentication enforcement"
+		lio_dbg("Successfully enabled iSCSI Discovery Authentication enforcement")
 	else:
-		print "Successfully disabled iSCSI Discovery Authentication enforcement"
+		lio_dbg("Successfully disabled iSCSI Discovery Authentication enforcement")
 
 	return
 
@@ -757,7 +764,7 @@ def lio_target_set_node_tcq(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to set TCQ: " + depth + " for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 	else:
-		print "Successfully set TCQ: " + depth + " for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt
+		lio_dbg("Successfully set TCQ: " + depth + " for iSCSI Initaitor ACL " + initiator_iqn + " for iSCSI Target Portal Group: " + iqn + " " + tpgt)
 
 	return
 
@@ -777,7 +784,7 @@ def lio_target_alua_set_tgptgp(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to set ALUA Target Port Group: " + tg_pt_gp_name + " for LUN: " + lun + " on " + iqn + " " + tpgt)
 	else:
-		print "Successfully set ALUA Target Port Group: " + tg_pt_gp_name + " for LUN: " + lun + " on " + iqn + " " + tpgt
+		lio_dbg("Successfully set ALUA Target Port Group: " + tg_pt_gp_name + " for LUN: " + lun + " on " + iqn + " " + tpgt)
 
 	return
 
@@ -796,7 +803,7 @@ def lio_target_alua_set_tgpt_offline(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to set ALUA secondary state OFFLINE bit for LUN: " + lun + " on " + iqn + " " + tpgt)
 	else:
-		print "Successfully set ALUA secondary state OFFLINE for LUN: " + lun + " on " + iqn + " " + tpgt
+		lio_dbg("Successfully set ALUA secondary state OFFLINE for LUN: " + lun + " on " + iqn + " " + tpgt)
 
 	return
 
@@ -815,7 +822,7 @@ def lio_target_alua_clear_tgpt_offline(option, opt_str, value, parser):
 	if ret:
 		lio_err("Unable to clear ALUA secondary state OFFLINE for LUN: " + lun + " on " + iqn + " " + tpgt)
 	else:
-		print "Successfully cleared ALUA secondary state OFFLINE for LUN: " + lun + " on " + iqn + " " + tpgt
+		lio_dbg("Successfully cleared ALUA secondary state OFFLINE for LUN: " + lun + " on " + iqn + " " + tpgt)
 	return
 
 def lio_target_show_chap_auth(option, opt_str, value, parser):
@@ -1106,7 +1113,7 @@ def lio_target_set_node_attr(option, opt_str, value, parser):
 		lio_err("Unable to set node attr: " + attr_dir + "/" + attr)
 
 	p.close()
-	print "Successfully set Initiator Node attribute: " + attr + " to: " + val
+	lio_dbg("Successfully set Initiator Node attribute: " + attr + " to: " + val)
 
 	return
 
@@ -1174,7 +1181,7 @@ def lio_target_set_tpg_attr(option, opt_str, value, parser):
 		lio_err("Unable to set tpg attr: " + attr_dir + "/" + attr)
 
 	p.close()
-	print "Successfully set TPG attribute: " + attr + " to: " + val
+	lio_dbg("Successfully set TPG attribute: " + attr + " to: " + val)
 
 	return
 
@@ -1220,7 +1227,7 @@ def lio_target_set_tpg_param(option, opt_str, value, parser):
 		lio_err("Unable to write tpg attr: " + param_dir + "/" + param)
 
 	p.close()
-	print "Successfully set TPG parameter: " + param + " to: " + val
+	lio_dbg("Successfully set TPG parameter: " + param + " to: " + val)
 
 	return
 
@@ -1279,6 +1286,12 @@ def lio_target_version(option, opt_str, value, parser):
 	os.system("cat /sys/kernel/config/target/iscsi/lio_version")
 	return
 
+def lio_target_enable_debug(option, opt_str, value, parser):
+	global lio_debug
+
+	lio_debug = 1
+	return
+
 def main():
 
 	parser = OptionParser()
@@ -1374,6 +1387,8 @@ def main():
 		type="string", dest="TARGET_IQN TPGT LUN", help="Show ALUA Target Port Group for LIO-Target Port/LUN")
 	parser.add_option("--unload", action="callback", callback=lio_target_unload, nargs=0,
 		help="Unload LIO-Target")
+	parser.add_option("--debug", action="callback", callback=lio_target_enable_debug, nargs=0,
+			  help="Enable debugging output")
 	parser.add_option("--version", action="callback", callback=lio_target_version, nargs=0,
 		help="Display LIO-Target version information")
 
-- 
1.8.1.4