Page Menu
Home
ClusterLabs Projects
Search
Configure Global Search
Log In
Files
F4624548
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
30 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/heartbeat/iSCSILogicalUnit b/heartbeat/iSCSILogicalUnit
index 1129d8421..dc04c0d6d 100644
--- a/heartbeat/iSCSILogicalUnit
+++ b/heartbeat/iSCSILogicalUnit
@@ -1,431 +1,438 @@
#!/bin/bash
#
#
# iSCSILogicalUnit OCF RA. Exports and manages iSCSI Logical Units.
#
# Copyright (c) 2009 LINBIT HA-Solutions GmbH, Florian Haas
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like. Any license provided herein, whether implied or
# otherwise, applies only to this software file. Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
#######################################################################
# Initialization:
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
LC_ALL="C"
LANG="C"
# Defaults
# Set a default implementation based on software installed
if have_binary ietadm; then
OCF_RESKEY_implementation_default="iet"
elif have_binary tgtadm; then
OCF_RESKEY_implementation_default="tgt"
fi
: ${OCF_RESKEY_implementation=${OCF_RESKEY_implementation_default}}
#######################################################################
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="iSCSILogicalUnit" version="0.9">
<version>0.9</version>
<longdesc lang="en">
Manages iSCSI targets. An iSCSI target is a collection of SCSI Logical
Units (LUs) exported via a daemon that speaks the iSCSI protocol.
</longdesc>
<shortdesc lang="en">iSCSI target export agent</shortdesc>
<parameters>
<parameter name="implementation" required="0" unique="0">
<longdesc lang="en">
The iSCSI target daemon implementation. Must be one of "iet" or "tgt".
If unspecified, an implementation is selected based on the
availability of management utilities, with "iet" being tried first,
then "tgt".
</longdesc>
<shortdesc lang="en">iSCSI target daemon implementation</shortdesc>
<content type="string" default="${OCF_RESKEY_implementation_default}"/>
</parameter>
-<parameter name="tid" required="1" unique="0">
+<parameter name="target_iqn" required="1" unique="0">
<longdesc lang="en">
-The numeric target ID. Must not be zero.
+The iSCSI Qualified Name (IQN) that this Logical Unit belongs to.
</longdesc>
-<shortdesc lang="en">iSCSI target ID</shortdesc>
-<content type="integer" />
+<shortdesc lang="en">iSCSI target IQN</shortdesc>
+<content type="string" />
</parameter>
<parameter name="lun" required="1" unique="0">
<longdesc lang="en">
The Logical Unit number (LUN) exposed to initiators.
</longdesc>
<shortdesc lang="en">Logical Unit number (LUN)</shortdesc>
<content type="integer" />
</parameter>
<parameter name="path" required="1" unique="0">
<longdesc lang="en">
The path to the block device exposed. Some implementations allow this
to be a regular file, too.
</longdesc>
<shortdesc lang="en">Block device (or file) path</shortdesc>
<content type="string" />
</parameter>
<parameter name="scsi_id" required="0" unique="0">
<longdesc lang="en">
The SCSI ID to be configured for this Logical Unit.
</longdesc>
<shortdesc lang="en">SCSI ID</shortdesc>
<content type="string" />
</parameter>
<parameter name="scsi_sn" required="0" unique="0">
<longdesc lang="en">
The SCSI serial number to be configured for this Logical Unit.
</longdesc>
<shortdesc lang="en">SCSI serial number</shortdesc>
<content type="string" />
</parameter>
<parameter name="vendor_id" required="0" unique="0">
<longdesc lang="en">
The SCSI vendor ID to be configured for this Logical Unit.
</longdesc>
<shortdesc lang="en">SCSI vendor ID</shortdesc>
<content type="string" />
</parameter>
<parameter name="product_id" required="0" unique="0">
<longdesc lang="en">
The SCSI product ID to be configured for this Logical Unit.
</longdesc>
<shortdesc lang="en">SCSI product ID</shortdesc>
<content type="string" />
</parameter>
<parameter name="additional_parameters" required="0" unique="0">
<longdesc lang="en">
Additional LU parameters. A space-separated list of "name=value" pairs
which will be passed through to the iSCSI daemon's management
interface. The supported parameters are implementation
dependent. Neither the name nor the value may contain whitespace.
</longdesc>
<shortdesc lang="en">List of iSCSI LU parameters</shortdesc>
<content type="string" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="10" />
<action name="stop" timeout="10" />
<action name="monitor" timeout="10" interval="10" depth="0" start-delay="0" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="10" />
</actions>
</resource-agent>
END
}
#######################################################################
do_cmd() {
# Wrap local commands to capture their exit code and output. Some
# implementations (IET, notably) have management commands with
# very terse output. It helps to at least capture exit codes in
# the logs.
local cmd="$*"
ocf_log debug "Calling $cmd"
local cmd_out
cmd_out=$($cmd 2>&1)
ret=$?
if [ $ret -ne 0 ]; then
ocf_log err "Called \"$cmd\""
ocf_log err "Exit code $ret"
ocf_log err "Command output: \"$cmd_out\""
else
ocf_log debug "Exit code $ret"
ocf_log debug "Command output: \"$cmd_out\""
fi
echo $cmd_out
return $ret
}
iSCSILogicalUnit_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
iSCSILogicalUnit_start() {
iSCSILogicalUnit_monitor
if [ $? = $OCF_SUCCESS ]; then
return $OCF_SUCCESS
fi
local params
case $OCF_RESKEY_implementation in
iet)
- # in IET, we have to set LU parameters on creation
params="Path=${OCF_RESKEY_path}"
+ # use blockio if path points to a block device, fileio
+ # otherwise.
+ if [ -b "${OCF_RESKEY_path}" ]; then
+ params="${params} Type=blockio"
+ else
+ params="${params} Type=fileio"
+ fi
+ # in IET, we have to set LU parameters on creation
if [ -n "${OCF_RESKEY_scsi_id}" ]; then
params="${params} ScsiId=${OCF_RESKEY_scsi_id}"
fi
if [ -n "${OCF_RESKEY_scsi_sn}" ]; then
params="${params} ScsiSN=${OCF_RESKEY_scsi_sn}"
fi
params="${params} ${OCF_RESKEY_additional_parameters}"
do_cmd ietadm --op new \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${TID} \
--lun=${OCF_RESKEY_lun} \
--params ${params// /,} && return $OCF_SUCCESS
;;
tgt)
# tgt requires that we create the LU first, then set LU
# parameters
params=""
local var
local envar
for var in scsi_id scsi_sn vendor_id product_id; do
envar="OCF_RESKEY_${var}"
if [ -n "${!envar}" ]; then
params="${params} ${var}=${!envar}"
fi
done
params="${params} ${OCF_RESKEY_additional_parameters}"
do_cmd tgtadm --lld iscsi --op new --mode logicalunit \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${TID} \
--lun=${OCF_RESKEY_lun} \
--backing-store ${OCF_RESKEY_path} || return $OCF_ERR_GENERIC
if [ -z "$params" ]; then
return $OCF_SUCCESS
else
do_cmd tgtadm --lld iscsi --op update --mode logicalunit \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${TID} \
--lun=${OCF_RESKEY_lun} \
--params ${params// /,} && return $OCF_SUCCESS
fi
;;
esac
return $OCF_ERR_GENERIC
}
iSCSILogicalUnit_stop() {
iSCSILogicalUnit_monitor
if [ $? = $OCF_SUCCESS ]; then
case $OCF_RESKEY_implementation in
iet)
# IET allows us to remove LUs while they are in use
do_cmd ietadm --op delete \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${TID} \
--lun=${OCF_RESKEY_lun} && return $OCF_SUCCESS
;;
tgt)
# tgt will fail to remove an LU while it is in use,
# but at the same time does not allow us to
# selectively shut down a connection that is using a
# specific LU. Thus, we need to loop here until tgtd
# decides that the LU is no longer in use, or we get
# timed out by the LRM.
while ! do_cmd tgtadm --lld iscsi --op delete --mode logicalunit \
- --tid ${OCF_RESKEY_tid} \
+ --tid ${TID} \
--lun=${OCF_RESKEY_lun}; do
sleep 1
done
return $OCF_SUCCESS
;;
esac
else
return $OCF_SUCCESS
fi
return $OCF_ERR_GENERIC
}
iSCSILogicalUnit_monitor() {
case $OCF_RESKEY_implementation in
iet)
+ # Figure out and set the target ID
+ TID=`sed -ne "s/tid:\([[:digit:]]\+\) name:${OCF_RESKEY_target_iqn}/\1/p" < /proc/net/iet/volume`
+ if [ -z "${TID}" ]; then
+ # Our target is not configured, thus we're not
+ # running.
+ return $OCF_NOT_RUNNING
+ fi
# FIXME: this looks for a matching LUN and path, but does
# not actually test for the correct target ID.
grep -E -q "[[:space:]]+lun:${OCF_RESKEY_lun}.*path:${OCF_RESKEY_path}" /proc/net/iet/volume && return $OCF_SUCCESS
;;
tgt)
+ # Figure out and set the target ID
+ TID=`tgtadm --lld iscsi --op show --mode target \
+ | sed -ne "s/^Target \([[:digit:]]\+\): ${OCF_RESKEY_target_iqn}/\1/p"`
+ if [ -z "$TID" ]; then
+ # Our target is not configured, thus we're not
+ # running.
+ return $OCF_NOT_RUNNING
+ fi
# This only looks for the backing store, but does not test
# for the correct target ID and LUN.
tgtadm --lld iscsi --op show --mode target \
| grep -E -q "[[:space:]]+Backing store: ${OCF_RESKEY_path}" && return $OCF_SUCCESS
;;
esac
return $OCF_NOT_RUNNING
}
iSCSILogicalUnit_validate() {
# Do we have all required variables?
- for var in implementation tid lun path; do
+ for var in implementation target_iqn lun path; do
param="OCF_RESKEY_${var}"
if [ -z "${!param}" ]; then
ocf_log error "Missing resource parameter \"$var\"!"
return $OCF_ERR_CONFIGURED
fi
done
# Do we have all required binaries?
case $OCF_RESKEY_implementation in
iet)
check_binary ietadm
;;
tgt)
check_binary tgtadm
;;
*)
# and by the way, is the implementation supported?
ocf_log error "Unsupported iSCSI target implementation \"$OCF_RESKEY_implementation\"!"
return $OCF_ERR_CONFIGURED
esac
- # Do we have a valid target ID?
- [ $OCF_RESKEY_tid -ge 1 ]
- case $? in
- 0)
- # OK
- ;;
- 1)
- ocf_log err "Invalid target ID $OCF_RESKEY_tid (must be greater than 0)."
- return $OCF_ERR_CONFIGURED
- ;;
- *)
- ocf_log err "Invalid target ID $OCF_RESKEY_tid (must be an integer)."
- return $OCF_ERR_CONFIGURED
- esac
-
# Do we have a valid LUN?
case $OCF_RESKEY_implementation in
iet)
# IET allows LUN 0 and up
[ $OCF_RESKEY_lun -ge 0 ]
case $? in
0)
# OK
;;
1)
ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be a non-negative integer)."
return $OCF_ERR_CONFIGURED
;;
*)
ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be an integer)."
return $OCF_ERR_CONFIGURED
;;
esac
;;
tgt)
# tgt reserves LUN 0 for its own purposes
[ $OCF_RESKEY_lun -ge 1 ]
case $? in
0)
# OK
;;
1)
ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be greater than 0)."
return $OCF_ERR_CONFIGURED
;;
*)
ocf_log err "Invalid LUN $OCF_RESKEY_lun (must be an integer)."
return $OCF_ERR_CONFIGURED
;;
esac
;;
esac
# Is the required kernel functionality available?
case $OCF_RESKEY_implementation in
iet)
[ -d /proc/net/iet ]
if [ $? -ne 0 ]; then
ocf_log err "/proc/net/iet does not exist or is not a directory -- check if required modules are loaded."
return $OCF_ERR_INSTALLED
fi
;;
tgt)
# tgt is userland only
;;
esac
# Do we have any configuration parameters that the current
# implementation does not support?
case $OCF_RESKEY_implementation in
iet)
# IET does not support setting the vendor and product ID
# (it always uses "IET" and "VIRTUAL-DISK")
local var
local envar
for var in vendor_id product_id; do
envar=OCF_RESKEY_${var}
if [ -n "${!envar}" ]; then
ocf_log warn "Configuration parameter \"${var}\"" \
"is not supported by the iSCSI implementation" \
"and will be ignored."
fi
done
;;
esac
return $OCF_SUCCESS
}
case $1 in
meta-data)
meta_data
exit $OCF_SUCCESS
;;
usage|help)
iSCSILogicalUnit_usage
exit $OCF_SUCCESS
;;
esac
# Everything except usage and meta-data must pass the validate test
iSCSILogicalUnit_validate || exit $?
case $__OCF_ACTION in
start) iSCSILogicalUnit_start;;
stop) iSCSILogicalUnit_stop;;
monitor) iSCSILogicalUnit_monitor;;
reload) ocf_log err "Reloading..."
iSCSILogicalUnit_start
;;
validate-all) ;;
*) iSCSILogicalUnit_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
diff --git a/heartbeat/iSCSITarget b/heartbeat/iSCSITarget
index 5f042c67e..dd50afe69 100644
--- a/heartbeat/iSCSITarget
+++ b/heartbeat/iSCSITarget
@@ -1,435 +1,443 @@
#!/bin/bash
#
#
# iSCSITarget OCF RA. Exports and manages iSCSI targets.
#
# Copyright (c) 2009 LINBIT HA-Solutions GmbH, Florian Haas
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like. Any license provided herein, whether implied or
# otherwise, applies only to this software file. Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
#######################################################################
# Initialization:
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
LC_ALL="C"
LANG="C"
# Defaults
# Set a default implementation based on software installed
if have_binary ietadm; then
OCF_RESKEY_implementation_default="iet"
elif have_binary tgtadm; then
OCF_RESKEY_implementation_default="tgt"
fi
: ${OCF_RESKEY_implementation=${OCF_RESKEY_implementation_default}}
#######################################################################
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="iSCSITarget" version="0.9">
<version>0.9</version>
<longdesc lang="en">
Manages iSCSI targets. An iSCSI target is a collection of SCSI Logical
Units (LUs) exported via a daemon that speaks the iSCSI protocol.
</longdesc>
<shortdesc lang="en">iSCSI target export agent</shortdesc>
<parameters>
<parameter name="implementation" required="0" unique="0">
<longdesc lang="en">
The iSCSI target daemon implementation. Must be one of "iet" or "tgt".
If unspecified, an implementation is selected based on the
availability of management utilities, with "iet" being tried first,
then "tgt".
</longdesc>
<shortdesc lang="en">iSCSI target daemon implementation</shortdesc>
<content type="string" default="${OCF_RESKEY_implementation_default}"/>
</parameter>
-<parameter name="tid" required="1" unique="0">
+<parameter name="iqn" required="1" unique="1">
<longdesc lang="en">
-The numeric target ID. Must not be zero.
-</longdesc>
-<shortdesc lang="en">iSCSI target ID</shortdesc>
-<content type="integer" />
-</parameter>
-
-<parameter name="name" required="1" unique="1">
-<longdesc lang="en">
-The logical target name. Should follow the conventional
+The target iSCSI Qualified Name (IQN). Should follow the conventional
"iqn.yyyy-mm.<reversed domain name>[:identifier]" syntax.
</longdesc>
-<shortdesc lang="en">iSCSI target name</shortdesc>
+<shortdesc lang="en">iSCSI target IQN</shortdesc>
<content type="string" />
</parameter>
<parameter name="allowed_initiators" required="0" unique="0">
<longdesc lang="en">
Allowed initiators. A space-separated list of initiators allowed to
connect to this target. Initiators may be listed in any syntax
the target implementation allows. If this parameter is empty or
not set, access to this target will be allowed from any initiator.
</longdesc>
<shortdesc lang="en">List of iSCSI initiators allowed to connect
to this target</shortdesc>
<content type="string" default=""/>
</parameter>
<parameter name="username" required="0" unique="0">
<longdesc lang="en">
A username used for initiator authentication. If unspecified,
allowed initiators will be able to log in without authentication.
</longdesc>
<shortdesc lang="en">Incoming account username</shortdesc>
<content type="string"/>
</parameter>
<parameter name="password" required="0" unique="0">
<longdesc lang="en">
A password used for initiator authentication.
</longdesc>
<shortdesc lang="en">Incoming account password</shortdesc>
<content type="string"/>
</parameter>
<parameter name="additional_parameters" required="0" unique="0">
<longdesc lang="en">
Additional target parameters. A space-separated list of "name=value"
pairs which will be passed through to the iSCSI daemon's management
interface. The supported parameters are implementation
dependent. Neither the name nor the value may contain whitespace.
</longdesc>
<shortdesc lang="en">List of iSCSI target parameters</shortdesc>
<content type="string" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="10" />
<action name="stop" timeout="10" />
<action name="monitor" timeout="10" interval="10" depth="0" start-delay="0" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="10" />
</actions>
</resource-agent>
END
}
#######################################################################
do_cmd() {
# Wrap local commands to capture their exit code and output. Some
# implementations (IET, notably) have management commands with
# very terse output. It helps to at least capture exit codes in
# the logs.
local cmd="$*"
ocf_log debug "Calling $cmd"
local cmd_out
cmd_out=$($cmd 2>&1)
ret=$?
if [ $ret -ne 0 ]; then
ocf_log err "Called \"$cmd\""
ocf_log err "Exit code $ret"
ocf_log err "Command output: \"$cmd_out\""
else
ocf_log debug "Exit code $ret"
ocf_log debug "Command output: \"$cmd_out\""
fi
echo $cmd_out
return $ret
}
iSCSITarget_usage() {
cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
iSCSITarget_start() {
iSCSITarget_monitor
if [ $? = $OCF_SUCCESS ]; then
return $OCF_SUCCESS
fi
local param
local name
local value
local initiator
case $OCF_RESKEY_implementation in
iet)
+ local lasttid
+ local tid
+ # Figure out the last used target ID, add 1 to get the new
+ # target ID.
+ lasttid=`sed -ne "s/tid:\([[:digit:]]\+\) name:.*/\1/p" < /proc/net/iet/volume | sort -n | tail -n1`
+ [ -z "${lasttid}" ] && lasttid=0
+ tid=$((++lasttid))
+ # Create the target.
do_cmd ietadm --op new \
- --tid=${OCF_RESKEY_tid} \
- --params Name=${OCF_RESKEY_name} || return $OCF_ERR_GENERIC
+ --tid=${tid} \
+ --params Name=${OCF_RESKEY_iqn} || return $OCF_ERR_GENERIC
+ # Set additional parameters.
for param in ${OCF_RESKEY_additional_parameters}; do
name=${param%=*}
value=${param#*=}
do_cmd ietadm --op update \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${tid} \
--params ${name}=${value} || return $OCF_ERR_GENERIC
done
# For iet, access to new targets is allowed by default. To
# specifically enable access based on initiator address,
# we must first deny access to the target globally, then
# re-enable by specific initiator.
- if [ -n ${OCF_RESKEY_allowed_initiators} ]; then
- echo "${OCF_RESKEY_name} ALL" >> /etc/initiators.deny
- echo "${OCF_RESKEY_name} ${OCF_RESKEY_initiators// /,}" >> /etc/initiators.allow
+ if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
+ echo "${OCF_RESKEY_iqn} ALL" >> /etc/initiators.deny
+ echo "${OCF_RESKEY_iqn} ${OCF_RESKEY_allowed_initiators// /,}" >> /etc/initiators.allow
fi
# In iet, adding a new user and assigning it to a target
# is one operation.
if [ -n "${OCF_RESKEY_username}" ]; then
do_cmd ietadm --op new --user \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${tid} \
--params=IncomingUser=${OCF_RESKEY_username},Password=${OCF_RESKEY_password} \
|| return $OCF_ERR_GENERIC
fi
return $OCF_SUCCESS
;;
tgt)
+ local lasttid
+ local tid
+ # Figure out the last used target ID, add 1 to get the new
+ # target ID.
+ lasttid=`tgtadm --lld iscsi --op show --mode target \
+ | sed -ne "s/^Target \([[:digit:]]\+\): .*/\1/p" | sort -n | tail -n1`
+ [ -z "${lasttid}" ] && lasttid=0
+ tid=$((++lasttid))
+ # Create the target.
do_cmd tgtadm --lld iscsi --op new --mode target \
- --tid=${OCF_RESKEY_tid} \
- --targetname ${OCF_RESKEY_name} || return $OCF_ERR_GENERIC
+ --tid=${tid} \
+ --targetname ${OCF_RESKEY_iqn} || return $OCF_ERR_GENERIC
+ # Set parameters.
for param in ${OCF_RESKEY_additional_parameters}; do
name=${param%=*}
value=${param#*=}
do_cmd tgtadm --lld iscsi --op update --mode target \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${tid} \
--name=${name} --value=${value} || return $OCF_ERR_GENERIC
done
# For tgt, we always have to add access per initiator;
# access to targets is denied by default. If
# "allowed_initiators" is unset, we must use the special
# keyword ALL.
for initiator in ${OCF_RESKEY_allowed_initiators=ALL}; do
do_cmd tgtadm --lld iscsi --op bind --mode target \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${tid} \
--initiator-address=${initiator} || return $OCF_ERR_GENERIC
done
# In tgt, we must first create a user account, then assign
# it to a target using the "bind" operation.
if [ -n "${OCF_RESKEY_username}" ]; then
do_cmd tgtadm --lld iscsi --mode account --op new \
--user=${OCF_RESKEY_username} \
--password=${OCF_RESKEY_password} || return $OCF_ERR_GENERIC
do_cmd tgtadm --lld iscsi --mode account --op bind \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${tid} \
--user=${OCF_RESKEY_username} || return $OCF_ERR_GENERIC
fi
return $OCF_SUCCESS
;;
esac
return $OCF_ERR_GENERIC
}
iSCSITarget_stop() {
iSCSITarget_monitor
if [ $? = $OCF_SUCCESS ]; then
+ local tid
case $OCF_RESKEY_implementation in
iet)
+ # Figure out the target ID
+ tid=`sed -ne "s/tid:\([[:digit:]]\+\) name:${OCF_RESKEY_iqn}/\1/p" < /proc/net/iet/volume`
+ if [ -z "${tid}" ]; then
+ ocf_log err "Failed to retrieve target ID for IQN ${OCF_RESKEY_iqn}"
+ return $OCF_ERR_GENERIC
+ fi
# Close existing connections. There is no other way to
# do this in IET than to parse the contents of
# /proc/net/iet/session.
- set -- $(sed -ne '/^tid:'${OCF_RESKEY_tid}' /,/^tid/ {
+ set -- $(sed -ne '/^tid:'${tid}' /,/^tid/ {
/^[[:space:]]*sid:\([0-9]\+\)/ {
s/^[[:space:]]*sid:\([0-9]*\).*/--sid=\1/; h;
};
/^[[:space:]]*cid:\([0-9]\+\)/ {
s/^[[:space:]]*cid:\([0-9]*\).*/--cid=\1/; G; p;
};
}' < /proc/net/iet/session)
while [[ -n $2 ]]; do
# $2 $1 looks like "--sid=X --cid=Y"
do_cmd ietadm --op delete \
- --tid=${OCF_RESKEY_tid} $2 $1
+ --tid=${tid} $2 $1
shift 2
done
# In iet, unassigning a user from a target and
# deleting the user account is one operation.
if [ -n "${OCF_RESKEY_username}" ]; then
do_cmd ietadm --op delete --user \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${tid} \
--params=IncomingUser=${OCF_RESKEY_username} \
|| return $OCF_ERR_GENERIC
fi
do_cmd ietadm --op delete \
- --tid=${OCF_RESKEY_tid} || return $OCF_ERR_GENERIC
- if [ -n ${OCF_RESKEY_allowed_initiators} ]; then
- # Avoid stale /etc/initiators.{allow,deny} entries
- # for this target
- do_cmd sed -e "/^${OCF_RESKEY_name}[[:space:]]/d" \
- -i /etc/initiators.deny
- do_cmd sed -e "/^${OCF_RESKEY_name}[[:space:]]/d" \
- -i /etc/initiators.allow
- fi
+ --tid=${tid} || return $OCF_ERR_GENERIC
+ # Avoid stale /etc/initiators.{allow,deny} entries
+ # for this target
+ do_cmd sed -e "/^${OCF_RESKEY_iqn}[[:space:]]/d" \
+ -i /etc/initiators.deny
+ do_cmd sed -e "/^${OCF_RESKEY_iqn}[[:space:]]/d" \
+ -i /etc/initiators.allow
return $OCF_SUCCESS
;;
tgt)
+ # Figure out the target ID
+ tid=`tgtadm --lld iscsi --op show --mode target \
+ | sed -ne "s/^Target \([[:digit:]]\+\): ${OCF_RESKEY_iqn}/\1/p"`
+ if [ -z "$tid" ]; then
+ ocf_log err "Failed to retrieve target ID for IQN ${OCF_RESKEY_iqn}"
+ return $OCF_ERR_GENERIC
+ fi
# Close existing connections. There is no other way to
# do this in tgt than to parse the output of "tgtadm --op
# show".
set -- $(tgtadm --lld iscsi --op show --mode target \
- | sed -ne '/^Target '${OCF_RESKEY_tid}':/,/^Target/ {
+ | sed -ne '/^Target '${tid}':/,/^Target/ {
/^[[:space:]]*I_T nexus: \([0-9]\+\)/ {
s/^.*: \([0-9]*\).*/--sid=\1/; h;
};
/^[[:space:]]*Connection: \([0-9]\+\)/ {
s/^.*: \([0-9]*\).*/--cid=\1/; G; p;
};
/^[[:space:]]*LUN information:/ q;
}')
while [[ -n $2 ]]; do
# $2 $1 looks like "--sid=X --cid=Y"
do_cmd tgtadm --lld iscsi --op delete --mode connection \
- --tid=${OCF_RESKEY_tid} $2 $1
+ --tid=${tid} $2 $1
shift 2
done
# In tgt, we must first unbind the user account from
# the target, then remove the account itself.
if [ -n "${OCF_RESKEY_username}" ]; then
do_cmd tgtadm --lld iscsi --mode account --op unbind \
- --tid=${OCF_RESKEY_tid} \
+ --tid=${tid} \
--user=${OCF_RESKEY_username} || return $OCF_ERR_GENERIC
do_cmd tgtadm --lld iscsi --mode account --op delete \
--user=${OCF_RESKEY_username} || return $OCF_ERR_GENERIC
fi
do_cmd tgtadm --lld iscsi --op delete --mode target \
- --tid=${OCF_RESKEY_tid} && return $OCF_SUCCESS
+ --tid=${tid} && return $OCF_SUCCESS
# In tgt, we don't have to worry about our ACL
# entries. They are automatically removed upon target
# deletion.
;;
esac
else
return $OCF_SUCCESS
fi
return $OCF_ERR_GENERIC
}
iSCSITarget_monitor() {
case $OCF_RESKEY_implementation in
iet)
- grep -q "tid:${OCF_RESKEY_tid} name:${OCF_RESKEY_name}" /proc/net/iet/volume && return $OCF_SUCCESS
+ grep -Eq "tid:[0-9]+ name:${OCF_RESKEY_iqn}" /proc/net/iet/volume && return $OCF_SUCCESS
;;
tgt)
- do_cmd tgtadm --lld iscsi --op show --mode target \
- | grep -q "Target ${OCF_RESKEY_tid}: ${OCF_RESKEY_name}" && return $OCF_SUCCESS
+ tgtadm --lld iscsi --op show --mode target \
+ | grep -Eq "Target [0-9]+: ${OCF_RESKEY_iqn}" && return $OCF_SUCCESS
;;
esac
return $OCF_NOT_RUNNING
}
iSCSITarget_validate() {
# Do we have all required variables?
- for var in implementation tid name; do
+ for var in implementation iqn; do
param="OCF_RESKEY_${var}"
if [ -z "${!param}" ]; then
ocf_log error "Missing resource parameter \"$var\"!"
return $OCF_ERR_CONFIGURED
fi
done
# Do we have all required binaries?
case $OCF_RESKEY_implementation in
iet)
check_binary ietadm
;;
tgt)
check_binary tgtadm
;;
*)
# and by the way, is the implementation supported?
ocf_log error "Unsupported iSCSI target implementation \"$OCF_RESKEY_implementation\"!"
return $OCF_ERR_CONFIGURED
esac
- # Do we have a valid target ID?
- [ $OCF_RESKEY_tid -ge 1 ]
- case $? in
- 0)
- # OK
- ;;
- 1)
- ocf_log err "Invalid target ID $OCF_RESKEY_tid (must be greater than 0)."
- return $OCF_ERR_CONFIGURED
- ;;
- *)
- ocf_log err "Invalid target ID $OCF_RESKEY_tid (must be an integer)."
- return $OCF_ERR_CONFIGURED
- esac
-
# Is the required kernel functionality available?
case $OCF_RESKEY_implementation in
iet)
[ -d /proc/net/iet ]
if [ $? -ne 0 ]; then
ocf_log err "/proc/net/iet does not exist or is not a directory -- check if required modules are loaded."
return $OCF_ERR_INSTALLED
fi
;;
tgt)
# tgt is userland only
;;
esac
return $OCF_SUCCESS
}
case $1 in
meta-data)
meta_data
exit $OCF_SUCCESS
;;
usage|help)
iSCSITarget_usage
exit $OCF_SUCCESS
;;
esac
# Everything except usage and meta-data must pass the validate test
iSCSITarget_validate || exit $?
case $__OCF_ACTION in
start) iSCSITarget_start;;
stop) iSCSITarget_stop;;
monitor) iSCSITarget_monitor;;
reload) ocf_log err "Reloading..."
iSCSITarget_start
;;
validate-all) ;;
*) iSCSITarget_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jul 8, 6:32 PM (7 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1994775
Default Alt Text
(30 KB)
Attached To
Mode
rR Resource Agents
Attached
Detach File
Event Timeline
Log In to Comment