@@ -41,6 +41,8 @@ elif have_binary lio_node; then
4141 OCF_RESKEY_implementation_default="lio"
4242elif have_binary targetcli; then
4343 OCF_RESKEY_implementation_default="lio-t"
44+ elif have_binary scstadmin; then
45+ OCF_RESKEY_implementation_default="scst"
4446fi
4547: ${OCF_RESKEY_implementation=${OCF_RESKEY_implementation_default}}
4648
@@ -56,6 +58,9 @@ LOCKFILE=${HA_RSCTMP}/iSCSITarget-${OCF_RESKEY_implementation}.lock
5658
5759# targetcli: iSCSITarget and iSCSILogicalUnit must use the same lockfile
5860TARGETLOCKFILE=${HA_RSCTMP}/targetcli.lock
61+
62+ # Timeout for waiting for initiators to log out (only used in scst)
63+ INIT_LOGOUT_TIMEOUT=20
5964#######################################################################
6065
6166meta_data() {
@@ -75,12 +80,12 @@ Units (LUs) exported via a daemon that speaks the iSCSI protocol.
7580<parameter name="implementation" required="0" unique="0">
7681<longdesc lang="en">
7782The iSCSI target daemon implementation. Must be one of "iet", "tgt",
78- "lio", or "lio-t". If unspecified, an implementation is selected based on the
83+ "lio", "lio-t", or "scst ". If unspecified, an implementation is selected based on the
7984availability of management utilities, with "iet" being tried first,
80- then "tgt", then "lio", then "lio-t".
85+ then "tgt", then "lio", then "lio-t", then "scst" .
8186</longdesc>
8287<shortdesc lang="en">Specifies the iSCSI target implementation
83- ("iet", "tgt", "lio", or "lio-t").</shortdesc>
88+ ("iet", "tgt", "lio", "lio-t", or "scst ").</shortdesc>
8489<content type="string" default="${OCF_RESKEY_implementation_default}"/>
8590</parameter>
8691
@@ -402,6 +407,28 @@ iSCSITarget_start() {
402407 fi
403408 fi
404409 ;;
410+ scst)
411+ ocf_run scstadmin -add_target ${OCF_RESKEY_iqn} -driver iscsi
412+
413+ for portal in ${OCF_RESKEY_portals}; do
414+ # scst only wants the IP address for some reason, so strip the port
415+ portal_ip="${portal%%:*}"
416+ ocf_run scstadmin -add_tgt_attr ${OCF_RESKEY_iqn} -driver iscsi -attributes "allowed_portal=${portal_ip}"
417+ done
418+ ocf_run scstadmin -add_group allowed -driver iscsi -target ${OCF_RESKEY_iqn}
419+ if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
420+ for initiator in ${OCF_RESKEY_allowed_initiators}; do
421+ ocf_run scstadmin -add_init ${initiator} -group allowed -driver iscsi -target ${OCF_RESKEY_iqn}
422+ done
423+ fi
424+
425+ if [ "${OCF_RESKEY_incoming_username}" != "" ]; then
426+ ocf_run scstadmin -add_tgt_attr ${OCF_RESKEY_iqn} -driver iscsi -attributes "IncomingUser ${OCF_RESKEY_incoming_username} ${OCF_RESKEY_incoming_password}"
427+ fi
428+
429+ ocf_run scstadmin -enable_target ${OCF_RESKEY_iqn} -driver iscsi
430+ echo 1 > /sys/kernel/scst_tgt/targets/iscsi/enabled
431+ ;;
405432 esac
406433
407434 iSCSITarget_monitor
@@ -524,6 +551,24 @@ iSCSITarget_stop() {
524551 ocf_release_lock_on_exit $TARGETLOCKFILE
525552 ocf_run targetcli /iscsi delete ${OCF_RESKEY_iqn} || exit $OCF_ERR_GENERIC
526553 ;;
554+ scst)
555+ ocf_run scstadmin -disable_target ${OCF_RESKEY_iqn} -driver iscsi -force -noprompt
556+ for i in $(find /sys/kernel/scst_tgt/targets/iscsi/${OCF_RESKEY_iqn}/ -name force_close); do
557+ echo 1 > ${i}
558+ done
559+
560+ timer=0
561+ while ls -Ad /sys/kernel/scst_tgt/targets/iscsi/${OCF_RESKEY_iqn}/sessions/* > /dev/null 2>&1; do
562+ if [ ${timer} -gt ${INIT_LOGOUT_TIMEOUT} ]; then
563+ ocf_log warn "Some initiators still logged in after ${INIT_LOGOUT_TIMEOUT} seconds. Continuing."
564+ break
565+ fi
566+ timer=$((timer + 1))
567+ sleep 1
568+ done
569+
570+ scstadmin -rem_target ${OCF_RESKEY_iqn} -driver iscsi -force -noprompt
571+ ;;
527572 esac
528573
529574 return $OCF_SUCCESS
@@ -547,6 +592,11 @@ iSCSITarget_monitor() {
547592 [ `cat /sys/kernel/config/target/iscsi/${OCF_RESKEY_iqn}/tpgt_1/enable` -eq 1 ] || return $OCF_NOT_RUNNING
548593 return $OCF_SUCCESS
549594 ;;
595+ scst)
596+ [ -d /sys/kernel/scst_tgt/targets/iscsi/${OCF_RESKEY_iqn} ] || return $OCF_NOT_RUNNING
597+ [ $(cat /sys/kernel/scst_tgt/targets/iscsi/${OCF_RESKEY_iqn}/enabled) -eq 1 ] || return $OCF_NOT_RUNNING
598+ return $OCF_SUCCESS
599+ ;;
550600 esac
551601
552602 return $OCF_NOT_RUNNING
@@ -574,7 +624,7 @@ iSCSITarget_validate() {
574624
575625 # Is the configured implementation supported?
576626 case "$OCF_RESKEY_implementation" in
577- "iet"|"tgt"|"lio"|"lio-t")
627+ "iet"|"tgt"|"lio"|"lio-t"|"scst" )
578628 ;;
579629 "")
580630 # The user didn't specify an implementation, and we were
@@ -604,6 +654,9 @@ iSCSITarget_validate() {
604654 lio|lio-t)
605655 unsupported_params="tid"
606656 ;;
657+ scst)
658+ unsupported_params="tid iser_portals"
659+ ;;
607660 esac
608661
609662 for var in ${unsupported_params}; do
@@ -637,6 +690,9 @@ iSCSITarget_validate() {
637690 lio-t)
638691 check_binary targetcli
639692 ;;
693+ scst)
694+ check_binary scstadmin
695+ ;;
640696 esac
641697
642698 # Is the required kernel functionality available?
@@ -666,6 +722,12 @@ iSCSITarget_validate() {
666722 lio-t)
667723 #targetcli loads the needed kernel modules
668724 ;;
725+ scst)
726+ if [ ! -d /sys/kernel/scst_tgt ]; then
727+ ocf_log err "/sys/kernel/scst_tgt does not exist or is not a directory -- check if required modules are loaded."
728+ exit $OCF_ERR_INSTALLED
729+ fi
730+ ;;
669731 esac
670732 fi
671733
0 commit comments