From 23e68262550e6001e455fd3a7ba30d8d8dbc44e6 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Tue, 2 Oct 2012 09:14:48 +0200
Subject: [PATCH 1/9] Remove tcm_snap reference

We're not supporting tcm_snap, so remove references to it.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 debian/README.debian |    2 +-
 tcm-py/tcm_node.py   |  195 --------------------------------------------------
 2 files changed, 1 insertions(+), 196 deletions(-)

diff --git a/debian/README.debian b/debian/README.debian
index 62f0455..0fe7013 100644
--- a/debian/README.debian
+++ b/debian/README.debian
@@ -3,7 +3,7 @@ lio-utils for Debian
 
 The Debian lio-utils package provides
 
-*) tcm-py and lio-py CLI modules for with /usr/sbin symlinks for tcm_node, tcm_dump, tcm_snap, lio_node, lio_dump 
+*) tcm-py and lio-py CLI modules for with /usr/sbin symlinks for tcm_node, tcm_dump, lio_node, lio_dump 
 
 *) SCSI and iSCSI net-snmp dlmod objects and txt MIBs
 
diff --git a/tcm-py/tcm_node.py b/tcm-py/tcm_node.py
index a8cd7b8..c114645 100755
--- a/tcm-py/tcm_node.py
+++ b/tcm-py/tcm_node.py
@@ -11,8 +11,6 @@ import tcm_iblock
 import tcm_ramdisk
 import tcm_fileio
 
-import tcm_snap
-
 tcm_root = "/sys/kernel/config/target/core"
 
 def tcm_cat(fname):
@@ -569,10 +567,6 @@ def __tcm_freevirtdev(option, opt_str, value, parser):
 	if (os.path.isdir(cfs_dev_path) == False):
 		tcm_err("TCM/ConfigFS storage object does not exist: " + cfs_dev_path)
 
-	snap_attr_path = cfs_dev_path + "/snap"
-	if os.path.isdir(snap_attr_path) == True:
-		tcm_snapshot_stop(None, None, value, None)
-
 	if os.path.isdir(cfs_dev_path + "/alua/") == True:
 		for tg_pt_gp in os.listdir(cfs_dev_path + "/alua/"):
 			if tg_pt_gp == "default_tg_pt_gp":
@@ -779,183 +773,6 @@ def tcm_list_alua_tgptgps(option, opt_str, value, parser):
 
 	return
 
-def tcm_snapshot_attr_set(option, opt_str, value, parser):
-	cfs_unsplit = str(value[0])
-	cfs_dev_path = tcm_get_cfs_prefix(cfs_unsplit)
-	tmp = str(value[1])
-	
-	out = tmp.split('=')
-	if not out:
-		tcm_err("Unable to locate snapshot attr=value")
-
-	attr = out[0]
-	value = out[1]
-
-	if (os.path.isdir(cfs_dev_path) == False):
-		tcm_err("TCM/ConfigFS storage object does not exist: " + cfs_dev_path)
-	
-	p = open(cfs_dev_path + "/snap/" + attr, 'w')
-	val = p.write(value)
-	if val:
-		p.close()
-		tcm_err("Unable to write to snap_attr: " + cfs_dev_path + "/snap/" + attr)
-
-	p.close()
-	print "Successfully updated snapshot attribute: " + attr + "=" + value + " for " + cfs_dev_path
-	return
-
-def tcm_snapshot_attr_show(option, opt_str, value, parser):
-	cfs_unsplit = str(value)
-	cfs_dev_path = tcm_get_cfs_prefix(cfs_unsplit)
-
-	if (os.path.isdir(cfs_dev_path) == False):
-		tcm_err("TCM/ConfigFS storage object does not exist: " + cfs_dev_path)
-
-	snap_attr_path = cfs_dev_path + "/snap"
-	for snap_attr in os.listdir(snap_attr_path):
-		p = open(snap_attr_path + "/" + snap_attr, 'rU')
-		val = p.read()
-		p.close()
-		print snap_attr +"=" + val.rstrip()	
-
-	return
-
-def tcm_snapshot_init(option, opt_str, value, parser):
-	cfs_unsplit = str(value[0])
-	cfs_dev_path = tcm_get_cfs_prefix(cfs_unsplit)
-
-	if (os.path.isdir(cfs_dev_path) == False):
-		tcm_err("TCM/ConfigFS storage object does not exist: " + cfs_dev_path)
-
-	max_snapshots = int(value[1])
-	lv_size = str(value[2])
-	snap_interval = str(value[3])
-
-	ret = tcm_snap.snap_set_cfs_defaults(cfs_dev_path, max_snapshots, lv_size, snap_interval)
-	if ret:
-		tcm_err("Unable to initialize snapshot attributes for " + cfs_dev_path)
-	
-	return
-
-def tcm_snapshot_start(option, opt_str, value, parser):
-	cfs_unsplit = str(value)
-	cfs_dev_path = tcm_get_cfs_prefix(cfs_unsplit)
-
-	if (os.path.isdir(cfs_dev_path) == False):
-		tcm_err("TCM/ConfigFS storage object does not exist: " + cfs_dev_path)
-
-	ret = tcm_snap.get_cfs_snap_enabled(cfs_dev_path)
-	if ret:
-		tcm_err("Not starting snapshot daemon because it is already enabled")
-
-	lv_group = tcm_snap.get_cfs_snap_lvgroup(cfs_dev_path)
-	if not lv_group:
-		tcm_err("lv_group for snapshot not set, please initialize configfs snapshot attrs with --lvsnapinit");
-
-	snap_size = tcm_snap.get_cfs_snap_size(cfs_dev_path)
-	if not snap_size:
-		tcm_err("size for snapshot not set, please initialize configfs snapshot attrs with --lvsnapinit");
-
-	max_snapshots = tcm_snap.get_cfs_max_snapshots(cfs_dev_path)
-	if not max_snapshots:
-		tcm_err("max rotating snapshots value not set, please initialize configfs snapshot attrs with --lvsnapinit");
-
-	ret = os.spawnlp(os.P_NOWAIT,"/usr/sbin/tcm_snap","tcm_snap","--p",cfs_dev_path)
-	if not ret:
-		tcm_err("Unable to start tcm_snap for: " + cfs_dev_path)
-
-	print "Started tcm_snap daemon at pid: " + str(ret) + " for " + cfs_dev_path
-	
-	enabled_attr = cfs_dev_path + "/snap/enabled"
-	p = open(enabled_attr, 'w')
-	if not p:
-		tcm_err("Unable to open enabled_attr: " + enabled_attr)
-
-	val = p.write("1")
-	if val:
-		p.close()
-		tcm_err("Unable to set snap/enabled for " + cfs_dev_path)
-
-	p.close()
-	return
-
-def tcm_snapshot_status(option, opt_str, value, parser):
-	cfs_unsplit = str(value)
-	cfs_dev_path = tcm_get_cfs_prefix(cfs_unsplit)
-
-	if (os.path.isdir(cfs_dev_path) == False):
-		tcm_err("TCM/ConfigFS storage object does not exist: " + cfs_dev_path)
-
-	udev_path = tcm_snap.get_cfs_udev_path(cfs_dev_path)
-	if not udev_path:
-		tcm_err("Unable to locate udev path for LV snapshot")
-
-	val = udev_path.split('/')
-	if not val:
-		tcm_err("Unable to split udev_path")
-
-	# Assume that udev_path is in '/dev/$VG_GROUP/$LV_NAME' format
-	vg_group = val[2]
-#	print "vg_group: " + vg_group
-	lv_name = val[3]
-#	print "lv_name: " + lv_name
-	
-	tcm_snap.snap_dump_lvs_info(vg_group, lv_name)
-	return
-
-def tcm_snapshot_stop(option, opt_str, value, parser):
-	cfs_unsplit = str(value)
-	cfs_dev_path = tcm_get_cfs_prefix(cfs_unsplit)
-
-	if (os.path.isdir(cfs_dev_path) == False):
-		tcm_err("TCM/ConfigFS storage object does not exist: " + cfs_dev_path)
-
-	enabled_attr = cfs_dev_path + "/snap/enabled"
-	p = open(enabled_attr, 'rU')
-	if not p:
-		tcm_err("Unable to open enabled_attr: " + enabled_attr)
-
-        val = p.read()
-        p.close()
-	if val.rstrip() == "0":
-		return
-
-	pid_attr = cfs_dev_path + "/snap/pid"
-	p = open(pid_attr, 'rU')
-	if not p:
-		tcm_err("Unable to open pid_attr: " + pid_attr)
-
-	val = p.read()
-	pid = int(val.rstrip())
-	p.close()
-#	print "Located tcm_snap pid: " + str(pid) + " for " + cfs_dev_path
-	try:
-		os.kill(pid, signal.SIGKILL)
-	except OSError, err:
-		return err.errno == errno.EPERM
-
-	print "Successfully stopped tcm_snap daemon for " + cfs_dev_path
-	p = open(pid_attr, 'w')
-	if not p:
-		tcm_err("Unable to open pid_attr: " + pid_attr)
-
-	val = p.write("0")
-	if val:
-		print "Unable to clear snap pid"
-	p.close()
-
-	enabled_attr = cfs_dev_path + "/snap/enabled"
-	p = open(enabled_attr, 'w')
-	if not p:
-		tcm_err("Unable to open enabled_attr: " + enabled_attr)
-		
-	val = p.write("0")
-	if val:
-		p.close()
-		tcm_err("Unable to set snap/enabled for " + cfs_dev_path)
-	p.close()
-	return
-
 def tcm_show_persistent_reserve_info(option, opt_str, value, parser):
 	cfs_unsplit = str(value)
 	cfs_dev_path = tcm_get_cfs_prefix(cfs_unsplit)
@@ -1304,18 +1121,6 @@ def main():
 			type="string", dest="HBA/DEV <TG_PT_GP_NAME>", help="List specific ALUA Target Port Group for Storage Object")
         parser.add_option("--listtgptgps","--listaluatpgs", action="callback", callback=tcm_list_alua_tgptgps, nargs=1,
                         type="string", dest="HBA/DEV", help="List all ALUA Target Port Groups for Storage Object");
-	parser.add_option("--lvsnapattrset", action="callback", callback=tcm_snapshot_attr_set, nargs=2,
-			type="string", dest="HBA/DEV ATTR=VALUE", help="Set LV snapshot configfs attributes for TCM/IBLOCK storage object");
-	parser.add_option("--lvsnapattrshow", action="callback", callback=tcm_snapshot_attr_show, nargs=1,
-			type="string", dest="HBA/DEV", help="Show LV snapshot configfs attributes for TCM/IBLOCK storage object");
-	parser.add_option("--lvsnapinit", action="callback", callback=tcm_snapshot_init, nargs=4,
-			type="string", dest="HBA/DEV MAX_SNAPSHOTS SNAP_SIZE_STR SNAP_INTERVAL_STR", help="Initialize snapshot with default attributes");
-	parser.add_option("--lvsnapstart", action="callback", callback=tcm_snapshot_start, nargs=1,
-			type="string", dest="HBA/DEV", help="Enable snapshot daemon for TCM/IBLOCK LVM storage object");
-	parser.add_option("--lvsnapstat", action="callback", callback=tcm_snapshot_status, nargs=1,
-			type="string", dest="HBA/DEV", help="Display LV snapshot status for TCM/IBLOCK LVM storage object");
-	parser.add_option("--lvsnapstop", action="callback", callback=tcm_snapshot_stop, nargs=1,
-			type="string", dest="HBA/DEV", help="Disable snapshot daemon for TCM/IBLOCK LVM storage object");
 	parser.add_option("--pr", action="callback", callback=tcm_show_persistent_reserve_info, nargs=1,
 			type="string", dest="HBA/DEV", help="Show Persistent Reservation info")
 	parser.add_option("--praptpl", action="callback", callback=tcm_process_aptpl_metadata, nargs=1,
-- 
1.7.4.2

