Blame SOURCES/bz1118029-iscsi-agents.patch

c608c9
From d4a36f47b36f47a847795660653b7fbc5baab706 Mon Sep 17 00:00:00 2001
c608c9
From: David Vossel <dvossel@redhat.com>
c608c9
Date: Mon, 25 Aug 2014 14:55:50 -0500
c608c9
Subject: [PATCH 1/4] iscsi agent updates
c608c9
c608c9
---
c608c9
 heartbeat/iSCSILogicalUnit | 573 ++++++++++++++++++++++-----------------
c608c9
 heartbeat/iSCSITarget      | 661 +++++++++++++++++++++++++--------------------
c608c9
 2 files changed, 690 insertions(+), 544 deletions(-)
c608c9
c608c9
diff --git a/heartbeat/iSCSILogicalUnit b/heartbeat/iSCSILogicalUnit
c608c9
index 0ab4722..c4cee0d 100755
c608c9
--- a/heartbeat/iSCSILogicalUnit
c608c9
+++ b/heartbeat/iSCSILogicalUnit
c608c9
@@ -3,10 +3,10 @@
c608c9
 #
c608c9
 #   iSCSILogicalUnit OCF RA. Exports and manages iSCSI Logical Units.
c608c9
 #
c608c9
-#   (c) 2013	LINBIT, Lars Ellenberg
c608c9
+#   (c) 2013 LINBIT, Lars Ellenberg
c608c9
 #   (c) 2009-2010 Florian Haas, Dejan Muhamedagic,
c608c9
-#                 and Linux-HA contributors
c608c9
-#				  
c608c9
+#       and Linux-HA contributors
c608c9
+#
c608c9
 #
c608c9
 # This program is free software; you can redistribute it and/or modify
c608c9
 # it under the terms of version 2 of the GNU General Public License as
c608c9
@@ -36,11 +36,13 @@
c608c9
 # Defaults
c608c9
 # Set a default implementation based on software installed
c608c9
 if have_binary ietadm; then
c608c9
-    OCF_RESKEY_implementation_default="iet"
c608c9
+	OCF_RESKEY_implementation_default="iet"
c608c9
 elif have_binary tgtadm; then
c608c9
-    OCF_RESKEY_implementation_default="tgt"
c608c9
+	OCF_RESKEY_implementation_default="tgt"
c608c9
 elif have_binary lio_node; then
c608c9
-    OCF_RESKEY_implementation_default="lio"
c608c9
+	OCF_RESKEY_implementation_default="lio"
c608c9
+elif have_binary targetcli; then
c608c9
+	OCF_RESKEY_implementation_default="lio-t"
c608c9
 fi
c608c9
 : ${OCF_RESKEY_implementation=${OCF_RESKEY_implementation_default}}
c608c9
 
c608c9
@@ -91,9 +93,9 @@ an SCSI Target, exported via a daemon that speaks the iSCSI protocol.
c608c9
 <parameter name="implementation" required="0" unique="0">
c608c9
 <longdesc lang="en">
c608c9
 The iSCSI target daemon implementation. Must be one of "iet", "tgt",
c608c9
-or "lio".  If unspecified, an implementation is selected based on the
c608c9
+"lio", or "lio-t".  If unspecified, an implementation is selected based on the
c608c9
 availability of management utilities, with "iet" being tried first,
c608c9
-then "tgt", then "lio".
c608c9
+then "tgt", then "lio", then "lio-t".
c608c9
 </longdesc>
c608c9
 <shortdesc lang="en">iSCSI target daemon implementation</shortdesc>
c608c9
 <content type="string" default="${OCF_RESKEY_implementation_default}"/>
c608c9
@@ -228,12 +230,12 @@ in /sys/kernel/config/target/core/.
c608c9
 </parameters>
c608c9
 
c608c9
 <actions>
c608c9
-<action name="start"        timeout="10" />
c608c9
-<action name="stop"         timeout="10" />
c608c9
-<action name="status"       timeout="10" interval="10" depth="0" />
c608c9
-<action name="monitor"      timeout="10" interval="10" depth="0" />
c608c9
-<action name="meta-data"    timeout="5" />
c608c9
-<action name="validate-all"   timeout="10" />
c608c9
+<action name="start"         timeout="10" />
c608c9
+<action name="stop"          timeout="10" />
c608c9
+<action name="status"        timeout="10" interval="10" depth="0" />
c608c9
+<action name="monitor"       timeout="10" interval="10" depth="0" />
c608c9
+<action name="meta-data"     timeout="5" />
c608c9
+<action name="validate-all"  timeout="10" />
c608c9
 </actions>
c608c9
 </resource-agent>
c608c9
 END
c608c9
@@ -250,108 +252,150 @@ END
c608c9
 }
c608c9
 
c608c9
 iSCSILogicalUnit_start() {
c608c9
-    iSCSILogicalUnit_monitor
c608c9
-    if [ $? =  $OCF_SUCCESS ]; then
c608c9
-	return $OCF_SUCCESS
c608c9
-    fi
c608c9
+	iSCSILogicalUnit_monitor
c608c9
+	if [ $? =  $OCF_SUCCESS ]; then
c608c9
+		return $OCF_SUCCESS
c608c9
+	fi
c608c9
 
c608c9
-    local params
c608c9
+	local params
c608c9
 
c608c9
-    case $OCF_RESKEY_implementation in
c608c9
+	case $OCF_RESKEY_implementation in
c608c9
 	iet)
c608c9
-	    params="Path=${OCF_RESKEY_path}"
c608c9
-	    # use blockio if path points to a block device, fileio
c608c9
-	    # otherwise.
c608c9
-	    if [ -b "${OCF_RESKEY_path}" ]; then
c608c9
-		params="${params} Type=blockio"
c608c9
-	    else
c608c9
-		params="${params} Type=fileio"
c608c9
-	    fi
c608c9
-	    # in IET, we have to set LU parameters on creation
c608c9
-	    if [ -n "${OCF_RESKEY_scsi_id}" ]; then
c608c9
-		params="${params} ScsiId=${OCF_RESKEY_scsi_id}"
c608c9
-	    fi
c608c9
-	    if [ -n "${OCF_RESKEY_scsi_sn}" ]; then
c608c9
-		params="${params} ScsiSN=${OCF_RESKEY_scsi_sn}"
c608c9
-	    fi
c608c9
-	    params="${params} ${OCF_RESKEY_additional_parameters}"
c608c9
-	    ocf_run ietadm --op new \
c608c9
-		--tid=${TID} \
c608c9
-		--lun=${OCF_RESKEY_lun} \
c608c9
-		--params ${params// /,} || exit $OCF_ERR_GENERIC
c608c9
-	    ;;
c608c9
+		params="Path=${OCF_RESKEY_path}"
c608c9
+		# use blockio if path points to a block device, fileio
c608c9
+		# otherwise.
c608c9
+		if [ -b "${OCF_RESKEY_path}" ]; then
c608c9
+			params="${params} Type=blockio"
c608c9
+		else
c608c9
+			params="${params} Type=fileio"
c608c9
+		fi
c608c9
+		# in IET, we have to set LU parameters on creation
c608c9
+		if [ -n "${OCF_RESKEY_scsi_id}" ]; then
c608c9
+			params="${params} ScsiId=${OCF_RESKEY_scsi_id}"
c608c9
+		fi
c608c9
+		if [ -n "${OCF_RESKEY_scsi_sn}" ]; then
c608c9
+			params="${params} ScsiSN=${OCF_RESKEY_scsi_sn}"
c608c9
+		fi
c608c9
+		params="${params} ${OCF_RESKEY_additional_parameters}"
c608c9
+		ocf_run ietadm --op new \
c608c9
+			--tid=${TID} \
c608c9
+			--lun=${OCF_RESKEY_lun} \
c608c9
+			--params ${params// /,} || exit $OCF_ERR_GENERIC
c608c9
+		;;
c608c9
 	tgt)
c608c9
-	    # tgt requires that we create the LU first, then set LU
c608c9
-	    # parameters
c608c9
-	    params=""
c608c9
-	    local var
c608c9
-            local envar
c608c9
-	    for var in scsi_id scsi_sn vendor_id product_id; do
c608c9
-		envar="OCF_RESKEY_${var}"
c608c9
-		if [ -n "${!envar}" ]; then
c608c9
-		    params="${params} ${var}=${!envar}"
c608c9
+		# tgt requires that we create the LU first, then set LU
c608c9
+		# parameters
c608c9
+		params=""
c608c9
+		local var
c608c9
+		local envar
c608c9
+		for var in scsi_id scsi_sn vendor_id product_id; do
c608c9
+			envar="OCF_RESKEY_${var}"
c608c9
+			if [ -n "${!envar}" ]; then
c608c9
+				params="${params} ${var}=${!envar}"
c608c9
+			fi
c608c9
+		done
c608c9
+		params="${params} ${OCF_RESKEY_additional_parameters}"
c608c9
+
c608c9
+		# cleanup: tgt (as of tgtadm version 1.0.24) does not like an explicit "bsoflags=direct"
c608c9
+		# when used with "bstype=aio" (which always uses O_DIRECT)
c608c9
+		[[ $OCF_RESKEY_tgt_bstype/$OCF_RESKEY_tgt_bsoflags = "aio/direct" ]] && OCF_RESKEY_tgt_bsoflags=""
c608c9
+
c608c9
+		tgt_args=""
c608c9
+		[[ $OCF_RESKEY_tgt_bstype ]]	&& tgt_args="$tgt_args --bstype=$OCF_RESKEY_tgt_bstype"
c608c9
+		[[ $OCF_RESKEY_tgt_bsoflags ]]	&& tgt_args="$tgt_args --bsoflags=$OCF_RESKEY_tgt_bsoflags"
c608c9
+		[[ $OCF_RESKEY_tgt_device_type ]]	&& tgt_args="$tgt_args --device-type=$OCF_RESKEY_tgt_device_type"
c608c9
+
c608c9
+		ocf_run tgtadm --lld iscsi --op new --mode logicalunit \
c608c9
+			--tid=${TID} \
c608c9
+			--lun=${OCF_RESKEY_lun} \
c608c9
+			$tgt_args \
c608c9
+			--backing-store ${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC
c608c9
+		if [ -z "$params" ]; then
c608c9
+			return $OCF_SUCCESS
c608c9
+		else
c608c9
+			ocf_run tgtadm --lld iscsi --op update --mode logicalunit \
c608c9
+				--tid=${TID} \
c608c9
+				--lun=${OCF_RESKEY_lun} \
c608c9
+				--params ${params// /,} || exit $OCF_ERR_GENERIC
c608c9
+		fi
c608c9
+		;;
c608c9
+	lio)
c608c9
+		# For lio, we first have to create a target device, then
c608c9
+		# add it to the Target Portal Group as an LU.
c608c9
+
c608c9
+		block_configfs_path="/sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}/udev_path"
c608c9
+		if [ ! -e "${block_configfs_path}" ]; then
c608c9
+			ocf_run tcm_node --createdev=iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} \
c608c9
+				${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC
c608c9
+		elif [ -e "$block_configfs_path" ] && [ $(cat "$block_configfs_path") != "${OCF_RESKEY_path}" ]; then
c608c9
+			ocf_exit_reason "Existing iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} has incorrect path: $(cat "$block_configfs_path") != ${OCF_RESKEY_path}"
c608c9
+			exit $OCF_ERR_GENERIC
c608c9
+		else
c608c9
+			ocf_log info "iscsi iblock already exists: ${block_configfs_path}"
c608c9
 		fi
c608c9
-	    done
c608c9
-	    params="${params} ${OCF_RESKEY_additional_parameters}"
c608c9
 
c608c9
-	    # cleanup: tgt (as of tgtadm version 1.0.24) does not like an explicit "bsoflags=direct"
c608c9
-	    # when used with "bstype=aio" (which always uses O_DIRECT)
c608c9
-	    [[ $OCF_RESKEY_tgt_bstype/$OCF_RESKEY_tgt_bsoflags = "aio/direct" ]] && OCF_RESKEY_tgt_bsoflags=""
c608c9
+		if [ -n "${OCF_RESKEY_scsi_sn}" ]; then
c608c9
+			ocf_run tcm_node --setunitserial=iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} \
c608c9
+				${OCF_RESKEY_scsi_sn} || exit $OCF_ERR_GENERIC
c608c9
+		fi
c608c9
 
c608c9
-	    tgt_args=""
c608c9
-	    [[ $OCF_RESKEY_tgt_bstype ]]	&& tgt_args="$tgt_args --bstype=$OCF_RESKEY_tgt_bstype"
c608c9
-	    [[ $OCF_RESKEY_tgt_bsoflags ]]	&& tgt_args="$tgt_args --bsoflags=$OCF_RESKEY_tgt_bsoflags"
c608c9
-	    [[ $OCF_RESKEY_tgt_device_type ]]	&& tgt_args="$tgt_args --device-type=$OCF_RESKEY_tgt_device_type"
c608c9
+		lun_configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/lun/lun_${OCF_RESKEY_lun}/${OCF_RESOURCE_INSTANCE}/udev_path"
c608c9
+		if [ ! -e "${lun_configfs_path}" ]; then
c608c9
+			ocf_run lio_node --addlun=${OCF_RESKEY_target_iqn} 1 ${OCF_RESKEY_lun} \
c608c9
+				${OCF_RESOURCE_INSTANCE} iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
c608c9
+		else
c608c9
+			ocf_log info "iscsi lun already exists: ${lun_configfs_path}"
c608c9
+		fi
c608c9
 
c608c9
-	    ocf_run tgtadm --lld iscsi --op new --mode logicalunit \
c608c9
-		--tid=${TID} \
c608c9
-		--lun=${OCF_RESKEY_lun} \
c608c9
-		$tgt_args \
c608c9
-	    	--backing-store ${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC
c608c9
-	    if [ -z "$params" ]; then
c608c9
-		return $OCF_SUCCESS
c608c9
-	    else
c608c9
-		ocf_run tgtadm --lld iscsi --op update --mode logicalunit \
c608c9
-		    --tid=${TID} \
c608c9
-		    --lun=${OCF_RESKEY_lun} \
c608c9
-		    --params ${params// /,} || exit $OCF_ERR_GENERIC
c608c9
-	    fi
c608c9
-	    ;;
c608c9
-	lio)
c608c9
-	    # For lio, we first have to create a target device, then
c608c9
-	    # add it to the Target Portal Group as an LU.
c608c9
-	    ocf_run tcm_node --createdev=iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} \
c608c9
-		${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC
c608c9
-	    if [ -n "${OCF_RESKEY_scsi_sn}" ]; then
c608c9
-		ocf_run tcm_node --setunitserial=iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} \
c608c9
-		    ${OCF_RESKEY_scsi_sn} || exit $OCF_ERR_GENERIC
c608c9
-	    fi
c608c9
-	    ocf_run lio_node --addlun=${OCF_RESKEY_target_iqn} 1 ${OCF_RESKEY_lun} \
c608c9
-		${OCF_RESOURCE_INSTANCE} iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
c608c9
-
c608c9
-           if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
-               for initiator in ${OCF_RESKEY_allowed_initiators}; do
c608c9
-                       ocf_run lio_node --addlunacl=${OCF_RESKEY_target_iqn} 1 \
c608c9
-                       ${initiator} ${OCF_RESKEY_lun} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
-               done
c608c9
-           fi
c608c9
-	    ;;
c608c9
-    esac
c608c9
-
c608c9
-    return $OCF_SUCCESS
c608c9
+		if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
+			for initiator in ${OCF_RESKEY_allowed_initiators}; do
c608c9
+				acl_configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/acls/${initiator}/lun_${OCF_RESKEY_lun}"
c608c9
+				if [ ! -e "${acl_configfs_path}" ]; then
c608c9
+					ocf_run lio_node --addlunacl=${OCF_RESKEY_target_iqn} 1 \
c608c9
+					${initiator} ${OCF_RESKEY_lun} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
+				else
c608c9
+					ocf_log info "iscsi acl already exists: ${acl_configfs_path}"
c608c9
+				fi
c608c9
+			done
c608c9
+		fi
c608c9
+		;;
c608c9
+	lio-t)
c608c9
+		# For lio, we first have to create a target device, then
c608c9
+		# add it to the Target Portal Group as an LU.
c608c9
+		ocf_run targetcli /backstores/block create name=${OCF_RESOURCE_INSTANCE} dev=${OCF_RESKEY_path} write_back=False || exit $OCF_ERR_GENERIC
c608c9
+		if [ -n "${OCF_RESKEY_scsi_sn}" ]; then
c608c9
+			echo ${OCF_RESKEY_scsi_sn} > /sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}/wwn/vpd_unit_serial
c608c9
+		fi
c608c9
+		ocf_run targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/luns create /backstores/block/${OCF_RESOURCE_INSTANCE} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
+
c608c9
+		if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
+			for initiator in ${OCF_RESKEY_allowed_initiators}; do
c608c9
+				ocf_run targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/acls create ${initiator} add_mapped_luns=False || exit $OCF_ERR_GENERIC
c608c9
+				ocf_run targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/acls/${initiator} create ${OCF_RESKEY_lun} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
+			done
c608c9
+		fi
c608c9
+		;;
c608c9
+	esac
c608c9
+
c608c9
+	# Force the monitor operation to pass before start is considered a success.
c608c9
+	iSCSILogicalUnit_monitor
c608c9
 }
c608c9
 
c608c9
 iSCSILogicalUnit_stop() {
c608c9
-    iSCSILogicalUnit_monitor
c608c9
-    if [ $? =  $OCF_SUCCESS ]; then
c608c9
+	iSCSILogicalUnit_monitor
c608c9
+	if [ $? -eq $OCF_NOT_RUNNING ]; then
c608c9
+		return $OCF_SUCCESS
c608c9
+	fi
c608c9
+
c608c9
 	case $OCF_RESKEY_implementation in
c608c9
-	    iet)
c608c9
-		# IET allows us to remove LUs while they are in use
c608c9
-		ocf_run ietadm --op delete \
c608c9
-		    --tid=${TID} \
c608c9
-		    --lun=${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
+
c608c9
+	iet)
c608c9
+	# IET allows us to remove LUs while they are in use
c608c9
+	ocf_run ietadm --op delete \
c608c9
+		--tid=${TID} \
c608c9
+		--lun=${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
 		;;
c608c9
-	    tgt)
c608c9
+	tgt)
c608c9
 		# tgt will fail to remove an LU while it is in use,
c608c9
 		# but at the same time does not allow us to
c608c9
 		# selectively shut down a connection that is using a
c608c9
@@ -359,202 +403,240 @@ iSCSILogicalUnit_stop() {
c608c9
 		# decides that the LU is no longer in use, or we get
c608c9
 		# timed out by the LRM.
c608c9
 		while ! ocf_run -warn tgtadm --lld iscsi --op delete --mode logicalunit \
c608c9
-		    --tid ${TID} \
c608c9
-		    --lun=${OCF_RESKEY_lun}; do
c608c9
-		    sleep 1
c608c9
+			--tid ${TID} \
c608c9
+			--lun=${OCF_RESKEY_lun}; do
c608c9
+			sleep 1
c608c9
+		done
c608c9
+		;;
c608c9
+	lio)
c608c9
+
c608c9
+		acls_configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/acls"
c608c9
+		for initiatorpath in ${acls_configfs_path}/*; do
c608c9
+			initiator=$(basename "${initiatorpath}")
c608c9
+			if [ -e "${initiatorpath}/lun_${OCF_RESKEY_lun}" ]; then
c608c9
+				ocf_log info "deleting acl at ${initiatorpath}/lun_${OCF_RESKEY_lun}"
c608c9
+				ocf_run lio_node --dellunacl=${OCF_RESKEY_target_iqn} 1 \
c608c9
+					${initiator} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
+			fi
c608c9
 		done
c608c9
+		lun_configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/lun/lun_#{${OCF_RESKEY_lun}/"
c608c9
+		if [ -e "${lun_configfs_path}" ]; then
c608c9
+			ocf_run lio_node --dellun=${OCF_RESKEY_target_iqn} 1 ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
+		fi
c608c9
+		block_configfs_path="/sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESKEY_INSTANCE}/udev_path"
c608c9
+		if [ -e "${block_configfs_path}" ]; then
c608c9
+			ocf_run tcm_node --freedev=iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
c608c9
+		fi
c608c9
+		;;
c608c9
+	lio-t)
c608c9
+		ocf_run targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/luns delete ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
+		if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
+			for initiator in ${OCF_RESKEY_allowed_initiators}; do
c608c9
+				if targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/acls/${initiator} status | grep "Mapped LUNs: 0" >/dev/null ; then
c608c9
+					ocf_run targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/acls/ delete ${initiator}
c608c9
+				fi
c608c9
+			done
c608c9
+		fi
c608c9
+
c608c9
+		ocf_run targetcli /backstores/block delete ${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
c608c9
 		;;
c608c9
-	    lio)
c608c9
-               if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
-                       for initiator in ${OCF_RESKEY_allowed_initiators}; do
c608c9
-                               ocf_run lio_node --dellunacl=${OCF_RESKEY_target_iqn} 1 \
c608c9
-                               ${initiator} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
-                       done
c608c9
-               fi
c608c9
-		ocf_run lio_node --dellun=${OCF_RESKEY_target_iqn} 1 ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
c608c9
-		ocf_run tcm_node --freedev=iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
c608c9
 	esac
c608c9
-    fi
c608c9
-    
c608c9
-    return $OCF_SUCCESS
c608c9
+
c608c9
+	return $OCF_SUCCESS
c608c9
 }
c608c9
 
c608c9
 iSCSILogicalUnit_monitor() {
c608c9
-    case $OCF_RESKEY_implementation in
c608c9
+	case $OCF_RESKEY_implementation in
c608c9
 	iet)
c608c9
- 	    # Figure out and set the target ID
c608c9
-	    TID=`sed -ne "s/tid:\([[:digit:]]\+\) name:${OCF_RESKEY_target_iqn}$/\1/p" < /proc/net/iet/volume`
c608c9
-	    if [ -z "${TID}" ]; then
c608c9
-		# Our target is not configured, thus we're not
c608c9
-		# running.
c608c9
-		return $OCF_NOT_RUNNING
c608c9
-	    fi
c608c9
-	    # FIXME: this looks for a matching LUN and path, but does
c608c9
-	    # not actually test for the correct target ID.
c608c9
-	    grep -E -q "[[:space:]]+lun:${OCF_RESKEY_lun}.*path:${OCF_RESKEY_path}$" /proc/net/iet/volume && return $OCF_SUCCESS
c608c9
-	    ;;
c608c9
+		# Figure out and set the target ID
c608c9
+		TID=`sed -ne "s/tid:\([[:digit:]]\+\) name:${OCF_RESKEY_target_iqn}$/\1/p" < /proc/net/iet/volume`
c608c9
+		if [ -z "${TID}" ]; then
c608c9
+			# Our target is not configured, thus we're not
c608c9
+			# running.
c608c9
+			return $OCF_NOT_RUNNING
c608c9
+		fi
c608c9
+		# FIXME: this looks for a matching LUN and path, but does
c608c9
+		# not actually test for the correct target ID.
c608c9
+		grep -E -q "[[:space:]]+lun:${OCF_RESKEY_lun}.*path:${OCF_RESKEY_path}$" /proc/net/iet/volume && return $OCF_SUCCESS
c608c9
+		;;
c608c9
 	tgt)
c608c9
-	    # Figure out and set the target ID
c608c9
-	    TID=`tgtadm --lld iscsi --op show --mode target \
c608c9
-		| sed -ne "s/^Target \([[:digit:]]\+\): ${OCF_RESKEY_target_iqn}$/\1/p"`
c608c9
-	    if [ -z "$TID" ]; then
c608c9
-		# Our target is not configured, thus we're not
c608c9
-		# running.
c608c9
-		return $OCF_NOT_RUNNING
c608c9
-	    fi
c608c9
-	    # This only looks for the backing store, but does not test
c608c9
-	    # for the correct target ID and LUN.
c608c9
-	    tgtadm --lld iscsi --op show --mode target \
c608c9
-		| grep -E -q "[[:space:]]+Backing store.*: ${OCF_RESKEY_path}$" && return $OCF_SUCCESS
c608c9
-	    ;;
c608c9
+		# Figure out and set the target ID
c608c9
+		TID=`tgtadm --lld iscsi --op show --mode target \
c608c9
+			| sed -ne "s/^Target \([[:digit:]]\+\): ${OCF_RESKEY_target_iqn}$/\1/p"`
c608c9
+		if [ -z "$TID" ]; then
c608c9
+			# Our target is not configured, thus we're not
c608c9
+			# running.
c608c9
+			return $OCF_NOT_RUNNING
c608c9
+		fi
c608c9
+		# This only looks for the backing store, but does not test
c608c9
+		# for the correct target ID and LUN.
c608c9
+		tgtadm --lld iscsi --op show --mode target \
c608c9
+			| grep -E -q "[[:space:]]+Backing store.*: ${OCF_RESKEY_path}$" && return $OCF_SUCCESS
c608c9
+		;;
c608c9
 	lio)
c608c9
-	    configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/lun/lun_${OCF_RESKEY_lun}/${OCF_RESOURCE_INSTANCE}/udev_path"
c608c9
-	    [ -e ${configfs_path} ] && [ `cat ${configfs_path}` = "${OCF_RESKEY_path}" ] && return $OCF_SUCCESS
c608c9
-	    ;;
c608c9
-    esac
c608c9
-    
c608c9
-    return $OCF_NOT_RUNNING
c608c9
+		configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/lun/lun_${OCF_RESKEY_lun}/${OCF_RESOURCE_INSTANCE}/udev_path"
c608c9
+		[ -e ${configfs_path} ] && [ `cat ${configfs_path}` = "${OCF_RESKEY_path}" ] && return $OCF_SUCCESS
c608c9
+
c608c9
+		# if we aren't activated, is a block device still left over?
c608c9
+		block_configfs_path="/sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESKEY_INSTANCE}/udev_path"
c608c9
+		[ -e ${block_configfs_path} ] && ocf_log warn "existing block without an active lun: ${block_configfs_path}"
c608c9
+		[ -e ${block_configfs_path} ] && return $OCF_ERR_GENERIC
c608c9
+
c608c9
+		;;
c608c9
+	lio-t)
c608c9
+		configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/lun/lun_${OCF_RESKEY_lun}/*/udev_path"
c608c9
+		[ -e ${configfs_path} ] && [ `cat ${configfs_path}` = "${OCF_RESKEY_path}" ] && return $OCF_SUCCESS
c608c9
+		;;
c608c9
+	esac
c608c9
+
c608c9
+	return $OCF_NOT_RUNNING
c608c9
 }
c608c9
 
c608c9
 iSCSILogicalUnit_validate() {
c608c9
-    # Do we have all required variables?
c608c9
-    for var in target_iqn lun path; do
c608c9
+	# Do we have all required variables?
c608c9
+	for var in target_iqn lun path; do
c608c9
 	param="OCF_RESKEY_${var}"
c608c9
 	if [ -z "${!param}" ]; then
c608c9
-	    ocf_log error "Missing resource parameter \"$var\"!"
c608c9
-	    exit $OCF_ERR_CONFIGURED
c608c9
+		ocf_exit_reason "Missing resource parameter \"$var\"!"
c608c9
+		exit $OCF_ERR_CONFIGURED
c608c9
 	fi
c608c9
-    done
c608c9
+	done
c608c9
 
c608c9
-    # Is the configured implementation supported?
c608c9
-    case "$OCF_RESKEY_implementation" in
c608c9
-	"iet"|"tgt"|"lio")
c608c9
-	    ;;
c608c9
+	# Is the configured implementation supported?
c608c9
+	case "$OCF_RESKEY_implementation" in
c608c9
+	"iet"|"tgt"|"lio"|"lio-t")
c608c9
+		;;
c608c9
 	"")
c608c9
-	    # The user didn't specify an implementation, and we were
c608c9
-	    # unable to determine one from installed binaries (in
c608c9
-	    # other words: no binaries for any supported
c608c9
-	    # implementation could be found)
c608c9
-	    ocf_log error "Undefined iSCSI target implementation"
c608c9
-	    exit $OCF_ERR_INSTALLED
c608c9
-	    ;;
c608c9
+		# The user didn't specify an implementation, and we were
c608c9
+		# unable to determine one from installed binaries (in
c608c9
+		# other words: no binaries for any supported
c608c9
+		# implementation could be found)
c608c9
+		ocf_exit_reason "Undefined iSCSI target implementation"
c608c9
+		exit $OCF_ERR_INSTALLED
c608c9
+		;;
c608c9
 	*)
c608c9
-	    ocf_log error "Unsupported iSCSI target implementation \"$OCF_RESKEY_implementation\"!"
c608c9
-	    exit $OCF_ERR_CONFIGURED
c608c9
-	    ;;
c608c9
-    esac
c608c9
+		ocf_exit_reason "Unsupported iSCSI target implementation \"$OCF_RESKEY_implementation\"!"
c608c9
+		exit $OCF_ERR_CONFIGURED
c608c9
+		;;
c608c9
+	esac
c608c9
 
c608c9
-    # Do we have a valid LUN?
c608c9
-    case $OCF_RESKEY_implementation in
c608c9
+	# Do we have a valid LUN?
c608c9
+	case $OCF_RESKEY_implementation in
c608c9
 	iet)
c608c9
-	    # IET allows LUN 0 and up
c608c9
-	    [ $OCF_RESKEY_lun -ge 0 ]
c608c9
-	    case $? in
c608c9
+		# IET allows LUN 0 and up
c608c9
+		[ $OCF_RESKEY_lun -ge 0 ]
c608c9
+		case $? in
c608c9
 		0)
c608c9
-	            # OK
c608c9
-		    ;;
c608c9
+			# OK
c608c9
+			;;
c608c9
 		1)
c608c9
-		    ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be a non-negative integer)."
c608c9
-		    exit $OCF_ERR_CONFIGURED
c608c9
-		    ;;
c608c9
+			ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be a non-negative integer)."
c608c9
+			exit $OCF_ERR_CONFIGURED
c608c9
+			;;
c608c9
 		*)
c608c9
-		    ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be an integer)."
c608c9
-		    exit $OCF_ERR_CONFIGURED
c608c9
-		    ;;
c608c9
-	    esac
c608c9
-	    ;;
c608c9
+			ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be an integer)."
c608c9
+			exit $OCF_ERR_CONFIGURED
c608c9
+			;;
c608c9
+		esac
c608c9
+		;;
c608c9
 	tgt)
c608c9
-	    # tgt reserves LUN 0 for its own purposes
c608c9
-	    [ $OCF_RESKEY_lun -ge 1 ]
c608c9
-	    case $? in
c608c9
+		# tgt reserves LUN 0 for its own purposes
c608c9
+		[ $OCF_RESKEY_lun -ge 1 ]
c608c9
+		case $? in
c608c9
 		0)
c608c9
-	            # OK
c608c9
-		    ;;
c608c9
+				# OK
c608c9
+			;;
c608c9
 		1)
c608c9
-		    ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be greater than 0)."
c608c9
-		    exit $OCF_ERR_CONFIGURED
c608c9
-		    ;;
c608c9
+			ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be greater than 0)."
c608c9
+			exit $OCF_ERR_CONFIGURED
c608c9
+			;;
c608c9
 		*)
c608c9
-		    ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be an integer)."
c608c9
-		    exit $OCF_ERR_CONFIGURED
c608c9
-		    ;;
c608c9
-	    esac
c608c9
-	    ;;
c608c9
-    esac
c608c9
-
c608c9
-    # Do we have any configuration parameters that the current
c608c9
-    # implementation does not support?
c608c9
-    local unsupported_params
c608c9
-    local var
c608c9
-    local envar
c608c9
-    case $OCF_RESKEY_implementation in
c608c9
+			ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be an integer)."
c608c9
+			exit $OCF_ERR_CONFIGURED
c608c9
+			;;
c608c9
+		esac
c608c9
+		;;
c608c9
+	esac
c608c9
+
c608c9
+	# Do we have any configuration parameters that the current
c608c9
+	# implementation does not support?
c608c9
+	local unsupported_params
c608c9
+	local var
c608c9
+	local envar
c608c9
+	case $OCF_RESKEY_implementation in
c608c9
 	iet)
c608c9
-	    # IET does not support setting the vendor and product ID
c608c9
-	    # (it always uses "IET" and "VIRTUAL-DISK")
c608c9
-	    unsupported_params="vendor_id product_id allowed_initiators lio_iblock tgt_bstype tgt_bsoflags tgt_device_type"
c608c9
-	    ;;
c608c9
+		# IET does not support setting the vendor and product ID
c608c9
+		# (it always uses "IET" and "VIRTUAL-DISK")
c608c9
+		unsupported_params="vendor_id product_id allowed_initiators lio_iblock tgt_bstype tgt_bsoflags tgt_device_type"
c608c9
+		;;
c608c9
 	tgt)
c608c9
-	    unsupported_params="allowed_initiators lio_iblock"
c608c9
-	    ;;
c608c9
+		unsupported_params="allowed_initiators lio_iblock"
c608c9
+		;;
c608c9
 	lio)
c608c9
-	    unsupported_params="scsi_id vendor_id product_id tgt_bstype tgt_bsoflags tgt_device_type"
c608c9
-	    ;;
c608c9
-    esac
c608c9
-    for var in ${unsupported_params}; do
c608c9
-	envar=OCF_RESKEY_${var}
c608c9
-	defvar=OCF_RESKEY_${var}_default
c608c9
-	if [ -n "${!envar}" ]; then
c608c9
-	    if  [[ "${!envar}" != "${!defvar}" ]];then 
c608c9
-	        case "$__OCF_ACTION" in
c608c9
-                    start|validate-all)
c608c9
-                      ocf_log warn "Configuration parameter \"${var}\"" \
c608c9
-                       "is not supported by the iSCSI implementation" \
c608c9
-                       "and will be ignored." ;;
c608c9
-	        esac
c608c9
-	    fi
c608c9
-	fi
c608c9
-    done
c608c9
+		unsupported_params="scsi_id vendor_id product_id tgt_bstype tgt_bsoflags tgt_device_type"
c608c9
+		;;
c608c9
+	lio-t)
c608c9
+		unsupported_params="scsi_id vendor_id product_id tgt_bstype tgt_bsoflags tgt_device_type lio_iblock"
c608c9
+		;;
c608c9
+	esac
c608c9
+
c608c9
+	for var in ${unsupported_params}; do
c608c9
+		envar=OCF_RESKEY_${var}
c608c9
+		defvar=OCF_RESKEY_${var}_default
c608c9
+		if [ -n "${!envar}" ]; then
c608c9
+			if  [[ "${!envar}" != "${!defvar}" ]];then 
c608c9
+				case "$__OCF_ACTION" in
c608c9
+				start|validate-all)
c608c9
+					ocf_log warn "Configuration parameter \"${var}\"" \
c608c9
+						"is not supported by the iSCSI implementation" \
c608c9
+						"and will be ignored." ;;
c608c9
+				esac
c608c9
+			fi
c608c9
+		fi
c608c9
+	done
c608c9
 
c608c9
-    if ! ocf_is_probe; then
c608c9
-    # Do we have all required binaries?
c608c9
+	if ! ocf_is_probe; then
c608c9
+	# Do we have all required binaries?
c608c9
 	case $OCF_RESKEY_implementation in
c608c9
-	    iet)
c608c9
+	iet)
c608c9
 		check_binary ietadm
c608c9
 		;;
c608c9
-	    tgt)
c608c9
+	tgt)
c608c9
 		check_binary tgtadm
c608c9
 		;;
c608c9
-	    lio)
c608c9
+	lio)
c608c9
 		check_binary tcm_node
c608c9
 		check_binary lio_node
c608c9
 		;;
c608c9
+	lio-t)
c608c9
+		check_binary targetcli
c608c9
+		;;
c608c9
 	esac
c608c9
 
c608c9
-        # Is the required kernel functionality available?
c608c9
+	# Is the required kernel functionality available?
c608c9
 	case $OCF_RESKEY_implementation in
c608c9
-	    iet)
c608c9
+	iet)
c608c9
 		[ -d /proc/net/iet ]
c608c9
 		if [ $? -ne 0 ]; then
c608c9
-		    ocf_log err "/proc/net/iet does not exist or is not a directory -- check if required modules are loaded."
c608c9
-		    exit $OCF_ERR_INSTALLED
c608c9
+			ocf_log err "/proc/net/iet does not exist or is not a directory -- check if required modules are loaded."
c608c9
+			exit $OCF_ERR_INSTALLED
c608c9
 		fi
c608c9
 		;;
c608c9
-	    tgt)
c608c9
-	        # tgt is userland only
c608c9
+	tgt)
c608c9
+		# tgt is userland only
c608c9
 		;;
c608c9
 	esac
c608c9
-    fi
c608c9
+	fi
c608c9
 
c608c9
-    return $OCF_SUCCESS
c608c9
+	return $OCF_SUCCESS
c608c9
 }
c608c9
 
c608c9
-
c608c9
 case $1 in
c608c9
-  meta-data)
c608c9
+meta-data)
c608c9
 	meta_data
c608c9
 	exit $OCF_SUCCESS
c608c9
 	;;
c608c9
-  usage|help)
c608c9
+usage|help)
c608c9
 	iSCSILogicalUnit_usage
c608c9
 	exit $OCF_SUCCESS
c608c9
 	;;
c608c9
@@ -568,13 +650,14 @@ start)		iSCSILogicalUnit_start;;
c608c9
 stop)		iSCSILogicalUnit_stop;;
c608c9
 monitor|status)	iSCSILogicalUnit_monitor;;
c608c9
 reload)		ocf_log err "Reloading..."
c608c9
-	        iSCSILogicalUnit_start
c608c9
+			iSCSILogicalUnit_start
c608c9
 		;;
c608c9
 validate-all)	;;
c608c9
 *)		iSCSILogicalUnit_usage
c608c9
 		exit $OCF_ERR_UNIMPLEMENTED
c608c9
 		;;
c608c9
 esac
c608c9
+
c608c9
 rc=$?
c608c9
 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
c608c9
 exit $rc
c608c9
diff --git a/heartbeat/iSCSITarget b/heartbeat/iSCSITarget
c608c9
index a988fb2..72ec64a 100755
c608c9
--- a/heartbeat/iSCSITarget
c608c9
+++ b/heartbeat/iSCSITarget
c608c9
@@ -1,7 +1,7 @@
c608c9
 #!/bin/bash
c608c9
 #
c608c9
 #
c608c9
-# 	iSCSITarget OCF RA. Exports and manages iSCSI targets.
c608c9
+#     iSCSITarget OCF RA. Exports and manages iSCSI targets.
c608c9
 #
c608c9
 #   (c) 2009-2010 Florian Haas, Dejan Muhamedagic,
c608c9
 #                 and Linux-HA contributors
c608c9
@@ -34,11 +34,13 @@
c608c9
 # Defaults
c608c9
 # Set a default implementation based on software installed
c608c9
 if have_binary ietadm; then
c608c9
-    OCF_RESKEY_implementation_default="iet"
c608c9
+	OCF_RESKEY_implementation_default="iet"
c608c9
 elif have_binary tgtadm; then
c608c9
-    OCF_RESKEY_implementation_default="tgt"
c608c9
+	OCF_RESKEY_implementation_default="tgt"
c608c9
 elif have_binary lio_node; then
c608c9
-    OCF_RESKEY_implementation_default="lio"
c608c9
+	OCF_RESKEY_implementation_default="lio"
c608c9
+elif have_binary targetcli; then
c608c9
+	OCF_RESKEY_implementation_default="lio-t"
c608c9
 fi
c608c9
 : ${OCF_RESKEY_implementation=${OCF_RESKEY_implementation_default}}
c608c9
 
c608c9
@@ -67,12 +69,12 @@ Units (LUs) exported via a daemon that speaks the iSCSI protocol.
c608c9
 <parameter name="implementation" required="0" unique="0">
c608c9
 <longdesc lang="en">
c608c9
 The iSCSI target daemon implementation. Must be one of "iet", "tgt",
c608c9
-or "lio".  If unspecified, an implementation is selected based on the
c608c9
+"lio", or "lio-t".  If unspecified, an implementation is selected based on the
c608c9
 availability of management utilities, with "iet" being tried first,
c608c9
-then "tgt", then "lio".
c608c9
+then "tgt", then "lio", then "lio-t".
c608c9
 </longdesc>
c608c9
 <shortdesc lang="en">Specifies the iSCSI target implementation
c608c9
-("iet", "tgt" or "lio").</shortdesc>
c608c9
+("iet", "tgt", "lio", or "lio-t").</shortdesc>
c608c9
 <content type="string" default="${OCF_RESKEY_implementation_default}"/>
c608c9
 </parameter>
c608c9
 
c608c9
@@ -148,11 +150,11 @@ dependent. Neither the name nor the value may contain whitespace.
c608c9
 </parameters>
c608c9
 
c608c9
 <actions>
c608c9
-<action name="start"        timeout="10" />
c608c9
-<action name="stop"         timeout="10" />
c608c9
-<action name="status"       timeout="10" interval="10" depth="0" />
c608c9
-<action name="monitor"      timeout="10" interval="10" depth="0" />
c608c9
-<action name="meta-data"    timeout="5" />
c608c9
+<action name="start"		timeout="10" />
c608c9
+<action name="stop"		 timeout="10" />
c608c9
+<action name="status"	   timeout="10" interval="10" depth="0" />
c608c9
+<action name="monitor"	  timeout="10" interval="10" depth="0" />
c608c9
+<action name="meta-data"	timeout="5" />
c608c9
 <action name="validate-all"   timeout="10" />
c608c9
 </actions>
c608c9
 </resource-agent>
c608c9
@@ -170,182 +172,233 @@ END
c608c9
 }
c608c9
 
c608c9
 iSCSITarget_start() {
c608c9
-    iSCSITarget_monitor
c608c9
-    if [ $? =  $OCF_SUCCESS ]; then
c608c9
-	return $OCF_SUCCESS
c608c9
-    fi
c608c9
+	iSCSITarget_monitor
c608c9
+	if [ $? =  $OCF_SUCCESS ]; then
c608c9
+		return $OCF_SUCCESS
c608c9
+	fi
c608c9
 
c608c9
-    local param
c608c9
-    local name
c608c9
-    local value
c608c9
-    local initiator
c608c9
-    local portal
c608c9
+	local param
c608c9
+	local name
c608c9
+	local value
c608c9
+	local initiator
c608c9
+	local portal
c608c9
 
c608c9
-    case $OCF_RESKEY_implementation in
c608c9
+	case $OCF_RESKEY_implementation in
c608c9
 	iet)
c608c9
-	    local lasttid
c608c9
-	    local tid
c608c9
-	    if [ "${OCF_RESKEY_tid}" ]; then
c608c9
-		tid="${OCF_RESKEY_tid}"
c608c9
-	    else
c608c9
-    	        # Figure out the last used target ID, add 1 to get the new
c608c9
-	        # target ID.
c608c9
-		ocf_take_lock $LOCKFILE
c608c9
-		ocf_release_lock_on_exit $LOCKFILE
c608c9
-		lasttid=`sed -ne "s/tid:\([[:digit:]]\+\) name:.*/\1/p" < /proc/net/iet/volume | sort -n | tail -n1`
c608c9
-		[ -z "${lasttid}" ] && lasttid=0
c608c9
-		tid=$((++lasttid))
c608c9
-	    fi
c608c9
-	    # Create the target.
c608c9
-	    ocf_run ietadm --op new \
c608c9
-		--tid=${tid} \
c608c9
-		--params Name=${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
c608c9
-	    # Set additional parameters.
c608c9
-	    for param in ${OCF_RESKEY_additional_parameters}; do
c608c9
-		name=${param%=*}
c608c9
-		value=${param#*=}
c608c9
-		ocf_run ietadm --op update \
c608c9
-		    --tid=${tid} \
c608c9
-		    --params ${name}=${value} || exit $OCF_ERR_GENERIC
c608c9
-	    done
c608c9
-	    # Legacy versions of IET allow targets by default, current
c608c9
-	    # versions deny. To be safe we manage both the .allow and
c608c9
-	    # .deny files.
c608c9
-	    if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
-		echo "${OCF_RESKEY_iqn} ALL" >> /etc/initiators.deny
c608c9
-		echo "${OCF_RESKEY_iqn} ${OCF_RESKEY_allowed_initiators// /,}" >> /etc/initiators.allow
c608c9
-	    else
c608c9
-		echo "${OCF_RESKEY_iqn} ALL" >> /etc/initiators.allow
c608c9
-	    fi
c608c9
-	    # In iet, adding a new user and assigning it to a target
c608c9
-	    # is one operation.
c608c9
-	    if [ -n "${OCF_RESKEY_incoming_username}" ]; then
c608c9
-		ocf_run ietadm --op new --user \
c608c9
-		    --tid=${tid} \
c608c9
-		    --params=IncomingUser=${OCF_RESKEY_incoming_username},Password=${OCF_RESKEY_incoming_password} \
c608c9
-		    || exit $OCF_ERR_GENERIC
c608c9
-	    fi
c608c9
-	    ;;
c608c9
+		local lasttid
c608c9
+		local tid
c608c9
+		if [ "${OCF_RESKEY_tid}" ]; then
c608c9
+			tid="${OCF_RESKEY_tid}"
c608c9
+		else
c608c9
+			# Figure out the last used target ID, add 1 to get the new
c608c9
+			# target ID.
c608c9
+			ocf_take_lock $LOCKFILE
c608c9
+			ocf_release_lock_on_exit $LOCKFILE
c608c9
+			lasttid=`sed -ne "s/tid:\([[:digit:]]\+\) name:.*/\1/p" < /proc/net/iet/volume | sort -n | tail -n1`
c608c9
+			[ -z "${lasttid}" ] && lasttid=0
c608c9
+			tid=$((++lasttid))
c608c9
+		fi
c608c9
+
c608c9
+		# Create the target.
c608c9
+		ocf_run ietadm --op new \
c608c9
+			--tid=${tid} \
c608c9
+			--params Name=${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
c608c9
+
c608c9
+		# Set additional parameters.
c608c9
+		for param in ${OCF_RESKEY_additional_parameters}; do
c608c9
+			name=${param%=*}
c608c9
+			value=${param#*=}
c608c9
+			ocf_run ietadm --op update \
c608c9
+				--tid=${tid} \
c608c9
+				--params ${name}=${value} || exit $OCF_ERR_GENERIC
c608c9
+		done
c608c9
+
c608c9
+		# Legacy versions of IET allow targets by default, current
c608c9
+		# versions deny. To be safe we manage both the .allow and
c608c9
+		# .deny files.
c608c9
+		if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
+			echo "${OCF_RESKEY_iqn} ALL" >> /etc/initiators.deny
c608c9
+			echo "${OCF_RESKEY_iqn} ${OCF_RESKEY_allowed_initiators// /,}" >> /etc/initiators.allow
c608c9
+		else
c608c9
+			echo "${OCF_RESKEY_iqn} ALL" >> /etc/initiators.allow
c608c9
+		fi
c608c9
+		# In iet, adding a new user and assigning it to a target
c608c9
+		# is one operation.
c608c9
+		if [ -n "${OCF_RESKEY_incoming_username}" ]; then
c608c9
+			ocf_run ietadm --op new --user \
c608c9
+				--tid=${tid} \
c608c9
+				--params=IncomingUser=${OCF_RESKEY_incoming_username},Password=${OCF_RESKEY_incoming_password} \
c608c9
+				|| exit $OCF_ERR_GENERIC
c608c9
+		fi
c608c9
+		;;
c608c9
 	tgt)
c608c9
-	    local tid
c608c9
-	    tid="${OCF_RESKEY_tid}"
c608c9
-	    # Create the target.
c608c9
-	    ocf_run tgtadm --lld iscsi --op new --mode target \
c608c9
-		--tid=${tid} \
c608c9
-		--targetname ${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
c608c9
-	    # Set parameters.
c608c9
-	    for param in ${OCF_RESKEY_additional_parameters}; do
c608c9
-		name=${param%=*}
c608c9
-		value=${param#*=}
c608c9
-		ocf_run tgtadm --lld iscsi --op update --mode target \
c608c9
-		    --tid=${tid} \
c608c9
-		    --name=${name} --value=${value} || exit $OCF_ERR_GENERIC
c608c9
-	    done
c608c9
-	    # For tgt, we always have to add access per initiator;
c608c9
-	    # access to targets is denied by default. If
c608c9
-	    # "allowed_initiators" is unset, we must use the special
c608c9
-	    # keyword ALL.
c608c9
-	    for initiator in ${OCF_RESKEY_allowed_initiators=ALL}; do
c608c9
-		ocf_run tgtadm --lld iscsi --op bind --mode target \
c608c9
-		    --tid=${tid} \
c608c9
-		    --initiator-address=${initiator} || exit $OCF_ERR_GENERIC
c608c9
-	    done
c608c9
-	    # In tgt, we must first create a user account, then assign
c608c9
-	    # it to a target using the "bind" operation.
c608c9
-	    if [ -n "${OCF_RESKEY_incoming_username}" ]; then
c608c9
-		ocf_run tgtadm --lld iscsi --mode account --op new \
c608c9
-		    --user=${OCF_RESKEY_incoming_username} \
c608c9
-		    --password=${OCF_RESKEY_incoming_password} || exit $OCF_ERR_GENERIC
c608c9
-		ocf_run tgtadm --lld iscsi --mode account --op bind \
c608c9
-		    --tid=${tid} \
c608c9
-		    --user=${OCF_RESKEY_incoming_username} || exit $OCF_ERR_GENERIC
c608c9
-	    fi
c608c9
-	    ;;
c608c9
+		local tid
c608c9
+		tid="${OCF_RESKEY_tid}"
c608c9
+		# Create the target.
c608c9
+		ocf_run tgtadm --lld iscsi --op new --mode target \
c608c9
+			--tid=${tid} \
c608c9
+			--targetname ${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
c608c9
+
c608c9
+		# Set parameters.
c608c9
+		for param in ${OCF_RESKEY_additional_parameters}; do
c608c9
+			name=${param%=*}
c608c9
+			value=${param#*=}
c608c9
+			ocf_run tgtadm --lld iscsi --op update --mode target \
c608c9
+				--tid=${tid} \
c608c9
+				--name=${name} --value=${value} || exit $OCF_ERR_GENERIC
c608c9
+		done
c608c9
+
c608c9
+		# For tgt, we always have to add access per initiator;
c608c9
+		# access to targets is denied by default. If
c608c9
+		# "allowed_initiators" is unset, we must use the special
c608c9
+		# keyword ALL.
c608c9
+		for initiator in ${OCF_RESKEY_allowed_initiators=ALL}; do
c608c9
+			ocf_run tgtadm --lld iscsi --op bind --mode target \
c608c9
+				--tid=${tid} \
c608c9
+				--initiator-address=${initiator} || exit $OCF_ERR_GENERIC
c608c9
+		done
c608c9
+
c608c9
+		# In tgt, we must first create a user account, then assign
c608c9
+		# it to a target using the "bind" operation.
c608c9
+		if [ -n "${OCF_RESKEY_incoming_username}" ]; then
c608c9
+			ocf_run tgtadm --lld iscsi --mode account --op new \
c608c9
+				--user=${OCF_RESKEY_incoming_username} \
c608c9
+				--password=${OCF_RESKEY_incoming_password} || exit $OCF_ERR_GENERIC
c608c9
+			ocf_run tgtadm --lld iscsi --mode account --op bind \
c608c9
+				--tid=${tid} \
c608c9
+				--user=${OCF_RESKEY_incoming_username} || exit $OCF_ERR_GENERIC
c608c9
+		fi
c608c9
+		;;
c608c9
 	lio)
c608c9
-	    # lio distinguishes between targets and target portal
c608c9
-	    # groups (TPGs). We will always create one TPG, with the
c608c9
-	    # number 1. In lio, creating a network portal
c608c9
-	    # automatically creates the corresponding target if it
c608c9
-	    # doesn't already exist.
c608c9
-	    for portal in ${OCF_RESKEY_portals}; do
c608c9
-		ocf_run lio_node --addnp ${OCF_RESKEY_iqn} 1 \
c608c9
-		    ${portal} || exit $OCF_ERR_GENERIC
c608c9
-	    done
c608c9
-	    # in lio, we can set target parameters by manipulating
c608c9
-	    # the appropriate configfs entries
c608c9
-	    for param in ${OCF_RESKEY_additional_parameters}; do
c608c9
-		name=${param%=*}
c608c9
-		value=${param#*=}
c608c9
-		configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/param/${name}"
c608c9
-		if [ -e ${configfs_path} ]; then
c608c9
-		    echo ${value} > ${configfs_path} || exit $OCF_ERR_GENERIC
c608c9
+		# lio distinguishes between targets and target portal
c608c9
+		# groups (TPGs). We will always create one TPG, with the
c608c9
+		# number 1. In lio, creating a network portal
c608c9
+		# automatically creates the corresponding target if it
c608c9
+		# doesn't already exist.
c608c9
+		for portal in ${OCF_RESKEY_portals}; do
c608c9
+			ocf_run lio_node --addnp ${OCF_RESKEY_iqn} 1 \
c608c9
+				${portal} || exit $OCF_ERR_GENERIC
c608c9
+		done
c608c9
+
c608c9
+		# in lio, we can set target parameters by manipulating
c608c9
+		# the appropriate configfs entries
c608c9
+		for param in ${OCF_RESKEY_additional_parameters}; do
c608c9
+			name=${param%=*}
c608c9
+			value=${param#*=}
c608c9
+			configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/param/${name}"
c608c9
+			if [ -e ${configfs_path} ]; then
c608c9
+				echo ${value} > ${configfs_path} || exit $OCF_ERR_GENERIC
c608c9
+			else
c608c9
+				ocf_log warn "Unsupported iSCSI target parameter ${name}: will be ignored."
c608c9
+			fi
c608c9
+		done
c608c9
+
c608c9
+		# lio does per-initiator filtering by default. To disable
c608c9
+		# this, we need to switch the target to "permissive mode".
c608c9
+		if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
+			for initiator in ${OCF_RESKEY_allowed_initiators}; do
c608c9
+				ocf_run lio_node --addnodeacl ${OCF_RESKEY_iqn} 1 \
c608c9
+				${initiator} || exit $OCF_ERR_GENERIC
c608c9
+			done
c608c9
 		else
c608c9
-		    ocf_log warn "Unsupported iSCSI target parameter ${name}: will be ignored."
c608c9
+			ocf_run lio_node --permissive ${OCF_RESKEY_iqn} 1 || exit $OCF_ERR_GENERIC
c608c9
+			# permissive mode enables read-only access by default,
c608c9
+			# so we need to change that to RW to be in line with
c608c9
+			# the other implementations.
c608c9
+			echo 0 > "/sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/attrib/demo_mode_write_protect"
c608c9
+			if [ `cat /sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/attrib/demo_mode_write_protect` -ne 0 ]; then
c608c9
+				ocf_log err "Failed to disable write protection for target ${OCF_RESKEY_iqn}."
c608c9
+				exit $OCF_ERR_GENERIC
c608c9
+			fi
c608c9
 		fi
c608c9
-	    done
c608c9
-	    # lio does per-initiator filtering by default. To disable
c608c9
-	    # this, we need to switch the target to "permissive mode".
c608c9
-	    if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
-		for initiator in ${OCF_RESKEY_allowed_initiators}; do
c608c9
-		    ocf_run lio_node --addnodeacl ${OCF_RESKEY_iqn} 1 \
c608c9
-			${initiator} || exit $OCF_ERR_GENERIC
c608c9
+
c608c9
+		# TODO: add CHAP authentication support when it gets added
c608c9
+		# back into LIO
c608c9
+		ocf_run lio_node --disableauth ${OCF_RESKEY_iqn} 1 || exit $OCF_ERR_GENERIC
c608c9
+		# Finally, we need to enable the target to allow
c608c9
+		# initiators to connect
c608c9
+		ocf_run lio_node --enabletpg=${OCF_RESKEY_iqn} 1 || exit $OCF_ERR_GENERIC
c608c9
+		;;
c608c9
+	lio-t)
c608c9
+		# lio distinguishes between targets and target portal
c608c9
+		# groups (TPGs). We will always create one TPG, with the
c608c9
+		# number 1. In lio, creating a network portal
c608c9
+		# automatically creates the corresponding target if it
c608c9
+		# doesn't already exist.
c608c9
+		for portal in ${OCF_RESKEY_portals}; do
c608c9
+			ocf_run targetcli /iscsi create ${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
c608c9
+			if [ $portal != ${OCF_RESKEY_portals_default} ] ; then
c608c9
+				IFS=':' read -a sep_portal <<< "$portal"
c608c9
+				ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/portals create "${sep_portal[0]}" "${sep_portal[1]}" || exit $OCF_ERR_GENERIC
c608c9
+			fi
c608c9
 		done
c608c9
-	    else
c608c9
-		ocf_run lio_node --permissive ${OCF_RESKEY_iqn} 1 || exit $OCF_ERR_GENERIC
c608c9
-		# permissive mode enables read-only access by default,
c608c9
-		# so we need to change that to RW to be in line with
c608c9
-		# the other implementations.
c608c9
-		echo 0 > "/sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/attrib/demo_mode_write_protect"
c608c9
-		if [ `cat /sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/attrib/demo_mode_write_protect` -ne 0 ]; then
c608c9
-		    ocf_log err "Failed to disable write protection for target ${OCF_RESKEY_iqn}."
c608c9
-		    exit $OCF_ERR_GENERIC
c608c9
+		# in lio, we can set target parameters by manipulating
c608c9
+		# the appropriate configfs entries
c608c9
+		for param in ${OCF_RESKEY_additional_parameters}; do
c608c9
+			name=${param%=*}
c608c9
+			value=${param#*=}
c608c9
+			configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/param/${name}"
c608c9
+			if [ -e ${configfs_path} ]; then
c608c9
+				echo ${value} > ${configfs_path} || exit $OCF_ERR_GENERIC
c608c9
+			else
c608c9
+				ocf_log warn "Unsupported iSCSI target parameter ${name}: will be ignored."
c608c9
+			fi
c608c9
+		done
c608c9
+		# lio does per-initiator filtering by default. To disable
c608c9
+		# this, we need to switch the target to "permissive mode".
c608c9
+		if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
c608c9
+			for initiator in ${OCF_RESKEY_allowed_initiators}; do
c608c9
+				ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/acls create ${initiator} || exit $OCF_ERR_GENERIC
c608c9
+			done
c608c9
+		else
c608c9
+			ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/ set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1 || exit $OCF_ERR_GENERIC
c608c9
 		fi
c608c9
-	    fi
c608c9
-	    # TODO: add CHAP authentication support when it gets added
c608c9
-	    # back into LIO
c608c9
-	    ocf_run lio_node --disableauth ${OCF_RESKEY_iqn} 1 || exit $OCF_ERR_GENERIC
c608c9
-	    # Finally, we need to enable the target to allow
c608c9
-	    # initiators to connect
c608c9
-	    ocf_run lio_node --enabletpg=${OCF_RESKEY_iqn} 1 || exit $OCF_ERR_GENERIC
c608c9
-	    ;;
c608c9
-    esac
c608c9
-
c608c9
-    return $OCF_SUCCESS
c608c9
+		# TODO: add CHAP authentication support when it gets added
c608c9
+		# back into LIO
c608c9
+		ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/ set attribute authentication=0 || exit $OCF_ERR_GENERIC
c608c9
+#			   ocf_run targetcli /iscsi 
c608c9
+		;;
c608c9
+	esac
c608c9
+
c608c9
+	iSCSITarget_monitor
c608c9
 }
c608c9
 
c608c9
 iSCSITarget_stop() {
c608c9
-    iSCSITarget_monitor
c608c9
-    if [ $? =  $OCF_SUCCESS ]; then
c608c9
+	iSCSITarget_monitor
c608c9
+	if [ $? -eq $OCF_NOT_RUNNING ]; then
c608c9
+		return $OCF_SUCCESS
c608c9
+	fi
c608c9
+
c608c9
 	local tid
c608c9
 	case $OCF_RESKEY_implementation in
c608c9
-	    iet)
c608c9
+	iet)
c608c9
 		# Figure out the target ID
c608c9
 		tid=`sed -ne "s/tid:\([[:digit:]]\+\) name:${OCF_RESKEY_iqn}/\1/p" < /proc/net/iet/volume`
c608c9
 		if [ -z "${tid}" ]; then
c608c9
-		    ocf_log err "Failed to retrieve target ID for IQN ${OCF_RESKEY_iqn}"
c608c9
-		    exit $OCF_ERR_GENERIC
c608c9
+			ocf_log err "Failed to retrieve target ID for IQN ${OCF_RESKEY_iqn}"
c608c9
+			exit $OCF_ERR_GENERIC
c608c9
 		fi
c608c9
 		# Close existing connections. There is no other way to
c608c9
 		# do this in IET than to parse the contents of
c608c9
 		# /proc/net/iet/session.
c608c9
 		set -- $(sed -ne '/^tid:'${tid}' /,/^tid/ {
c608c9
-                          /^[[:space:]]*sid:\([0-9]\+\)/ {
c608c9
-                             s/^[[:space:]]*sid:\([0-9]*\).*/--sid=\1/; h;
c608c9
-                          };
c608c9
-                          /^[[:space:]]*cid:\([0-9]\+\)/ { 
c608c9
-                              s/^[[:space:]]*cid:\([0-9]*\).*/--cid=\1/; G; p; 
c608c9
-                          }; 
c608c9
-                      }' < /proc/net/iet/session)
c608c9
+						  /^[[:space:]]*sid:\([0-9]\+\)/ {
c608c9
+							 s/^[[:space:]]*sid:\([0-9]*\).*/--sid=\1/; h;
c608c9
+						  };
c608c9
+						  /^[[:space:]]*cid:\([0-9]\+\)/ { 
c608c9
+							  s/^[[:space:]]*cid:\([0-9]*\).*/--cid=\1/; G; p; 
c608c9
+						  }; 
c608c9
+					  }' < /proc/net/iet/session)
c608c9
 		while [[ -n $2 ]]; do
c608c9
-                    # $2 $1 looks like "--sid=X --cid=Y"
c608c9
-		    ocf_run ietadm --op delete \
c608c9
-			     --tid=${tid} $2 $1
c608c9
-		    shift 2
c608c9
+			# $2 $1 looks like "--sid=X --cid=Y"
c608c9
+			ocf_run ietadm --op delete \
c608c9
+				 --tid=${tid} $2 $1
c608c9
+			shift 2
c608c9
 		done
c608c9
-   	        # In iet, unassigning a user from a target and
c608c9
+			# In iet, unassigning a user from a target and
c608c9
 		# deleting the user account is one operation.
c608c9
 		if [ -n "${OCF_RESKEY_incoming_username}" ]; then
c608c9
-		    ocf_run ietadm --op delete --user \
c608c9
+			ocf_run ietadm --op delete --user \
c608c9
 			--tid=${tid} \
c608c9
 			--params=IncomingUser=${OCF_RESKEY_incoming_username} \
c608c9
 			|| exit $OCF_ERR_GENERIC
c608c9
@@ -353,216 +406,226 @@ iSCSITarget_stop() {
c608c9
 		# Loop on delete. Keep trying until we time out, if
c608c9
 		# necessary.
c608c9
 		while true; do
c608c9
-		    if ietadm --op delete --tid=${tid}; then
c608c9
-			ocf_log debug "Removed target ${OCF_RESKEY_iqn}."
c608c9
-			break
c608c9
-		    else
c608c9
-			ocf_log warn "Failed to remove target ${OCF_RESKEY_iqn}, retrying."
c608c9
-			sleep 1
c608c9
-		    fi
c608c9
+			if ietadm --op delete --tid=${tid}; then
c608c9
+				ocf_log debug "Removed target ${OCF_RESKEY_iqn}."
c608c9
+				break
c608c9
+			else
c608c9
+				ocf_log warn "Failed to remove target ${OCF_RESKEY_iqn}, retrying."
c608c9
+				sleep 1
c608c9
+			fi
c608c9
 		done
c608c9
 		# Avoid stale /etc/initiators.{allow,deny} entries
c608c9
 		# for this target
c608c9
 		if [ -e /etc/initiators.deny ]; then
c608c9
-		    ocf_run sed -e "/^${OCF_RESKEY_iqn}[[:space:]]/d" \
c608c9
+			ocf_run sed -e "/^${OCF_RESKEY_iqn}[[:space:]]/d" \
c608c9
 			-i /etc/initiators.deny
c608c9
 		fi
c608c9
 		if [ -e /etc/initiators.allow ]; then
c608c9
-		    ocf_run sed -e "/^${OCF_RESKEY_iqn}[[:space:]]/d" \
c608c9
+			ocf_run sed -e "/^${OCF_RESKEY_iqn}[[:space:]]/d" \
c608c9
 			-i /etc/initiators.allow
c608c9
 		fi
c608c9
 		;;
c608c9
-	    tgt)
c608c9
+	tgt)
c608c9
 		tid="${OCF_RESKEY_tid}"
c608c9
 		# Close existing connections. There is no other way to
c608c9
 		# do this in tgt than to parse the output of "tgtadm --op
c608c9
 		# show".
c608c9
 		set -- $(tgtadm --lld iscsi --op show --mode target \
c608c9
-		    | sed -ne '/^Target '${tid}':/,/^Target/ {
c608c9
-                          /^[[:space:]]*I_T nexus: \([0-9]\+\)/ {
c608c9
-                             s/^.*: \([0-9]*\).*/--sid=\1/; h;
c608c9
-                          };
c608c9
-                          /^[[:space:]]*Connection: \([0-9]\+\)/ { 
c608c9
-                              s/^.*: \([0-9]*\).*/--cid=\1/; G; p; 
c608c9
-                          }; 
c608c9
-                          /^[[:space:]]*LUN information:/ q; 
c608c9
-                      }')
c608c9
+			| sed -ne '/^Target '${tid}':/,/^Target/ {
c608c9
+						  /^[[:space:]]*I_T nexus: \([0-9]\+\)/ {
c608c9
+							 s/^.*: \([0-9]*\).*/--sid=\1/; h;
c608c9
+						  };
c608c9
+						  /^[[:space:]]*Connection: \([0-9]\+\)/ { 
c608c9
+							  s/^.*: \([0-9]*\).*/--cid=\1/; G; p; 
c608c9
+						  }; 
c608c9
+						  /^[[:space:]]*LUN information:/ q; 
c608c9
+					  }')
c608c9
 		while [[ -n $2 ]]; do
c608c9
-                    # $2 $1 looks like "--sid=X --cid=Y"
c608c9
-		    ocf_run tgtadm --lld iscsi --op delete --mode connection \
c608c9
+			# $2 $1 looks like "--sid=X --cid=Y"
c608c9
+			ocf_run tgtadm --lld iscsi --op delete --mode connection \
c608c9
 			--tid=${tid} $2 $1
c608c9
-		    shift 2
c608c9
+			shift 2
c608c9
 		done
c608c9
-	        # In tgt, we must first unbind the user account from
c608c9
+			# In tgt, we must first unbind the user account from
c608c9
 		# the target, then remove the account itself.
c608c9
 		if [ -n "${OCF_RESKEY_incoming_username}" ]; then
c608c9
-		    ocf_run tgtadm --lld iscsi --mode account --op unbind \
c608c9
-			--tid=${tid} \
c608c9
-			--user=${OCF_RESKEY_incoming_username} || exit $OCF_ERR_GENERIC
c608c9
-		    ocf_run tgtadm --lld iscsi --mode account --op delete \
c608c9
-			--user=${OCF_RESKEY_incoming_username} || exit $OCF_ERR_GENERIC
c608c9
+			ocf_run tgtadm --lld iscsi --mode account --op unbind \
c608c9
+				--tid=${tid} \
c608c9
+				--user=${OCF_RESKEY_incoming_username} || exit $OCF_ERR_GENERIC
c608c9
+			ocf_run tgtadm --lld iscsi --mode account --op delete \
c608c9
+				--user=${OCF_RESKEY_incoming_username} || exit $OCF_ERR_GENERIC
c608c9
 		fi
c608c9
 		# Loop on delete. Keep trying until we time out, if
c608c9
 		# necessary.
c608c9
 		while true; do
c608c9
-		    if tgtadm --lld iscsi --op delete --mode target --tid=${tid}; then
c608c9
-			ocf_log debug "Removed target ${OCF_RESKEY_iqn}."
c608c9
-			break
c608c9
-		    else
c608c9
-			ocf_log warn "Failed to remove target ${OCF_RESKEY_iqn}, retrying."
c608c9
-			sleep 1
c608c9
-		    fi
c608c9
+			if tgtadm --lld iscsi --op delete --mode target --tid=${tid}; then
c608c9
+				ocf_log debug "Removed target ${OCF_RESKEY_iqn}."
c608c9
+				break
c608c9
+			else
c608c9
+				ocf_log warn "Failed to remove target ${OCF_RESKEY_iqn}, retrying."
c608c9
+				sleep 1
c608c9
+			fi
c608c9
 		done
c608c9
 		# In tgt, we don't have to worry about our ACL
c608c9
 		# entries. They are automatically removed upon target
c608c9
 		# deletion.
c608c9
 		;;
c608c9
-	    lio)
c608c9
+	lio)
c608c9
 		# In lio, removing a target automatically removes all
c608c9
 		# associated TPGs, network portals, and LUNs.
c608c9
 		ocf_run lio_node --deliqn ${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
c608c9
 		;;
c608c9
+	lio-t)
c608c9
+		ocf_run targetcli /iscsi delete ${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
c608c9
+		;;
c608c9
 	esac
c608c9
-    fi
c608c9
 
c608c9
-    return $OCF_SUCCESS
c608c9
+	return $OCF_SUCCESS
c608c9
 }
c608c9
 
c608c9
 iSCSITarget_monitor() {
c608c9
-    case $OCF_RESKEY_implementation in
c608c9
+	case $OCF_RESKEY_implementation in
c608c9
 	iet)
c608c9
-	    grep -Eq "tid:[0-9]+ name:${OCF_RESKEY_iqn}" /proc/net/iet/volume && return $OCF_SUCCESS
c608c9
-	    ;;
c608c9
+		grep -Eq "tid:[0-9]+ name:${OCF_RESKEY_iqn}" /proc/net/iet/volume && return $OCF_SUCCESS
c608c9
+		;;
c608c9
 	tgt)
c608c9
-	    tgtadm --lld iscsi --op show --mode target \
c608c9
+		tgtadm --lld iscsi --op show --mode target \
c608c9
 		| grep -Eq "Target [0-9]+: ${OCF_RESKEY_iqn}" && return $OCF_SUCCESS
c608c9
-	    ;;
c608c9
-	lio)
c608c9
-	    # if we have no configfs entry for the target, it's
c608c9
-	    # definitely stopped
c608c9
-	    [ -d /sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn} ] || return $OCF_NOT_RUNNING
c608c9
-	    # if the target is there, but its TPG is not enabled, then
c608c9
-	    # we also consider it stopped
c608c9
-	    [ `cat /sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/enable` -eq 1 ] || return $OCF_NOT_RUNNING
c608c9
-	    return $OCF_SUCCESS
c608c9
-	    ;;
c608c9
-    esac
c608c9
-    
c608c9
-    return $OCF_NOT_RUNNING
c608c9
+		;;
c608c9
+	lio | lio-t)
c608c9
+		# if we have no configfs entry for the target, it's
c608c9
+		# definitely stopped
c608c9
+		[ -d /sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn} ] || return $OCF_NOT_RUNNING
c608c9
+		# if the target is there, but its TPG is not enabled, then
c608c9
+		# we also consider it stopped
c608c9
+		[ `cat /sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/enable` -eq 1 ] || return $OCF_NOT_RUNNING
c608c9
+		return $OCF_SUCCESS
c608c9
+		;;
c608c9
+	esac
c608c9
+	
c608c9
+	return $OCF_NOT_RUNNING
c608c9
 }
c608c9
 
c608c9
 iSCSITarget_validate() {
c608c9
-    # Do we have all required variables?
c608c9
-    local required_vars
c608c9
-    case $OCF_RESKEY_implementation in
c608c9
+	# Do we have all required variables?
c608c9
+	local required_vars
c608c9
+	case $OCF_RESKEY_implementation in
c608c9
 	iet)
c608c9
-	    required_vars="iqn"
c608c9
-	    ;;
c608c9
+		required_vars="iqn"
c608c9
+		;;
c608c9
 	tgt)
c608c9
-	    required_vars="iqn tid"
c608c9
-	    ;;
c608c9
-    esac
c608c9
-    for var in ${required_vars}; do
c608c9
-	param="OCF_RESKEY_${var}"
c608c9
-	if [ -z "${!param}" ]; then
c608c9
-	    ocf_log error "Missing resource parameter \"$var\"!"
c608c9
-	    exit $OCF_ERR_CONFIGURED
c608c9
-	fi
c608c9
-    done
c608c9
+		required_vars="iqn tid"
c608c9
+		;;
c608c9
+	esac
c608c9
+
c608c9
+	for var in ${required_vars}; do
c608c9
+		param="OCF_RESKEY_${var}"
c608c9
+		if [ -z "${!param}" ]; then
c608c9
+			ocf_exit_reason "Missing resource parameter \"$var\"!"
c608c9
+			exit $OCF_ERR_CONFIGURED
c608c9
+		fi
c608c9
+	done
c608c9
 
c608c9
-    # Is the configured implementation supported?
c608c9
-    case "$OCF_RESKEY_implementation" in
c608c9
-	"iet"|"tgt"|"lio")
c608c9
-	    ;;
c608c9
+	# Is the configured implementation supported?
c608c9
+	case "$OCF_RESKEY_implementation" in
c608c9
+	"iet"|"tgt"|"lio"|"lio-t")
c608c9
+		;;
c608c9
 	"")
c608c9
-	    # The user didn't specify an implementation, and we were
c608c9
-	    # unable to determine one from installed binaries (in
c608c9
-	    # other words: no binaries for any supported
c608c9
-	    # implementation could be found)
c608c9
-	    ocf_log error "Undefined iSCSI target implementation"
c608c9
-	    exit $OCF_ERR_INSTALLED
c608c9
-	    ;;
c608c9
+		# The user didn't specify an implementation, and we were
c608c9
+		# unable to determine one from installed binaries (in
c608c9
+		# other words: no binaries for any supported
c608c9
+		# implementation could be found)
c608c9
+		ocf_exit_reason "Undefined iSCSI target implementation"
c608c9
+		exit $OCF_ERR_INSTALLED
c608c9
+		;;
c608c9
 	*)
c608c9
-	    ocf_log error "Unsupported iSCSI target implementation \"$OCF_RESKEY_implementation\"!"
c608c9
-	    exit $OCF_ERR_CONFIGURED
c608c9
-	    ;;
c608c9
-    esac
c608c9
-
c608c9
-    # Do we have any configuration parameters that the current
c608c9
-    # implementation does not support?
c608c9
-    local unsupported_params
c608c9
-    local var
c608c9
-    local envar
c608c9
-    case $OCF_RESKEY_implementation in
c608c9
+		ocf_exit_reason "Unsupported iSCSI target implementation \"$OCF_RESKEY_implementation\"!"
c608c9
+		exit $OCF_ERR_CONFIGURED
c608c9
+		;;
c608c9
+	esac
c608c9
+
c608c9
+	# Do we have any configuration parameters that the current
c608c9
+	# implementation does not support?
c608c9
+	local unsupported_params
c608c9
+	local var
c608c9
+	local envar
c608c9
+	case $OCF_RESKEY_implementation in
c608c9
 	iet|tgt)
c608c9
-	    # IET and tgt do not support binding a target portal to a
c608c9
-	    # specific IP address.
c608c9
-	    unsupported_params="portals"
c608c9
-	    ;;
c608c9
-	lio)
c608c9
-	    # TODO: Remove incoming_username and incoming_password
c608c9
-	    # from this check when LIO 3.0 gets CHAP authentication
c608c9
-	    unsupported_params="tid incoming_username incoming_password"
c608c9
-	    ;;
c608c9
-    esac
c608c9
-    for var in ${unsupported_params}; do
c608c9
-	envar=OCF_RESKEY_${var}
c608c9
-	defvar=OCF_RESKEY_${var}_default
c608c9
-	if [ -n "${!envar}" ]; then
c608c9
-            if  [[ "${!envar}" != "${!defvar}" ]];then
c608c9
-                    case "$__OCF_ACTION" in
c608c9
-                        start|validate-all)
c608c9
-                          ocf_log warn "Configuration parameter \"${var}\"" \
c608c9
-                            "is not supported by the iSCSI implementation" \
c608c9
-                            "and will be ignored." ;;
c608c9
-                    esac
c608c9
-            fi
c608c9
-	fi
c608c9
-    done
c608c9
+		# IET and tgt do not support binding a target portal to a
c608c9
+		# specific IP address.
c608c9
+		unsupported_params="portals"
c608c9
+		;;
c608c9
+	lio|lio-t)
c608c9
+		# TODO: Remove incoming_username and incoming_password
c608c9
+		# from this check when LIO 3.0 gets CHAP authentication
c608c9
+		unsupported_params="tid incoming_username incoming_password"
c608c9
+		;;
c608c9
+	esac
c608c9
 
c608c9
-    if ! ocf_is_probe; then
c608c9
-        # Do we have all required binaries?
c608c9
+	for var in ${unsupported_params}; do
c608c9
+		envar=OCF_RESKEY_${var}
c608c9
+		defvar=OCF_RESKEY_${var}_default
c608c9
+		if [ -n "${!envar}" ]; then
c608c9
+			if  [[ "${!envar}" != "${!defvar}" ]];then
c608c9
+				case "$__OCF_ACTION" in
c608c9
+					start|validate-all)
c608c9
+						ocf_log warn "Configuration parameter \"${var}\"" \
c608c9
+							"is not supported by the iSCSI implementation" \
c608c9
+							"and will be ignored." ;;
c608c9
+				esac
c608c9
+			fi
c608c9
+		fi
c608c9
+	done
c608c9
+
c608c9
+	if ! ocf_is_probe; then
c608c9
+		# Do we have all required binaries?
c608c9
 	case $OCF_RESKEY_implementation in
c608c9
-	    iet)
c608c9
+	iet)
c608c9
 		check_binary ietadm
c608c9
 		;;
c608c9
-	    tgt)
c608c9
+	tgt)
c608c9
 		check_binary tgtadm
c608c9
 		;;
c608c9
-	    lio)
c608c9
+	lio)
c608c9
 		check_binary tcm_node
c608c9
 		check_binary lio_node
c608c9
 		;;
c608c9
+	lio-t)
c608c9
+		check_binary targetcli
c608c9
+		;;
c608c9
 	esac
c608c9
 
c608c9
-        # Is the required kernel functionality available?
c608c9
+	# Is the required kernel functionality available?
c608c9
 	case $OCF_RESKEY_implementation in
c608c9
-	    iet)
c608c9
+	iet)
c608c9
 		[ -d /proc/net/iet ]
c608c9
 		if [ $? -ne 0 ]; then
c608c9
-		    ocf_log err "/proc/net/iet does not exist or is not a directory -- check if required modules are loaded."
c608c9
-		    exit $OCF_ERR_INSTALLED
c608c9
+			ocf_log err "/proc/net/iet does not exist or is not a directory -- check if required modules are loaded."
c608c9
+			exit $OCF_ERR_INSTALLED
c608c9
 		fi
c608c9
 		;;
c608c9
-	    tgt)
c608c9
-	        # tgt is userland only
c608c9
+	tgt)
c608c9
+			# tgt is userland only
c608c9
 		;;
c608c9
-	    lio)
c608c9
-	        # lio needs configfs to be mounted
c608c9
+	lio)
c608c9
+			# lio needs configfs to be mounted
c608c9
 		if ! grep -Eq "^.*/sys/kernel/config[[:space:]]+configfs" /proc/mounts; then
c608c9
-		    ocf_log err "configfs not mounted at /sys/kernel/config -- check if required modules are loaded."
c608c9
-		    exit $OCF_ERR_INSTALLED
c608c9
+			ocf_log err "configfs not mounted at /sys/kernel/config -- check if required modules are loaded."
c608c9
+			exit $OCF_ERR_INSTALLED
c608c9
 		fi
c608c9
-	        # check for configfs entries created by target_core_mod
c608c9
+			# check for configfs entries created by target_core_mod
c608c9
 		if [ ! -d /sys/kernel/config/target ]; then
c608c9
-		    ocf_log err "/sys/kernel/config/target does not exist or is not a directory -- check if required modules are loaded."
c608c9
-		    exit $OCF_ERR_INSTALLED
c608c9
+			ocf_log err "/sys/kernel/config/target does not exist or is not a directory -- check if required modules are loaded."
c608c9
+			exit $OCF_ERR_INSTALLED
c608c9
 		fi
c608c9
 		;;
c608c9
+	lio-t)
c608c9
+		#targetcli loads the needed kernel modules
c608c9
+		;;
c608c9
 	esac
c608c9
-    fi
c608c9
+	fi
c608c9
 
c608c9
-    return $OCF_SUCCESS
c608c9
+	return $OCF_SUCCESS
c608c9
 }
c608c9
 
c608c9
 
c608c9
@@ -585,7 +648,7 @@ start)		iSCSITarget_start;;
c608c9
 stop)		iSCSITarget_stop;;
c608c9
 monitor|status)	iSCSITarget_monitor;;
c608c9
 reload)		ocf_log err "Reloading..."
c608c9
-	        iSCSITarget_start
c608c9
+			iSCSITarget_start
c608c9
 		;;
c608c9
 validate-all)	;;
c608c9
 *)		iSCSITarget_usage
c608c9
-- 
c608c9
1.8.4.2
c608c9