Skip to content

Commit 30fecf6

Browse files
authored
Merge pull request #1890 from chrboe/cbo/scst
iSCSI: add support for scst
2 parents 3a427e9 + b306804 commit 30fecf6

File tree

2 files changed

+110
-7
lines changed

2 files changed

+110
-7
lines changed

heartbeat/iSCSILogicalUnit.in

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ elif have_binary lio_node; then
4343
OCF_RESKEY_implementation_default="lio"
4444
elif have_binary targetcli; then
4545
OCF_RESKEY_implementation_default="lio-t"
46+
elif have_binary scstadmin; then
47+
OCF_RESKEY_implementation_default="scst"
4648
fi
4749
: ${OCF_RESKEY_implementation=${OCF_RESKEY_implementation_default}}
4850

@@ -104,9 +106,9 @@ an SCSI Target, exported via a daemon that speaks the iSCSI protocol.
104106
<parameter name="implementation" required="0" unique="0">
105107
<longdesc lang="en">
106108
The iSCSI target daemon implementation. Must be one of "iet", "tgt",
107-
"lio", or "lio-t". If unspecified, an implementation is selected based on the
109+
"lio", "lio-t", or "scst". If unspecified, an implementation is selected based on the
108110
availability of management utilities, with "iet" being tried first,
109-
then "tgt", then "lio", then "lio-t".
111+
then "tgt", then "lio", then "lio-t", then "scst".
110112
</longdesc>
111113
<shortdesc lang="en">iSCSI target daemon implementation</shortdesc>
112114
<content type="string" default="${OCF_RESKEY_implementation_default}"/>
@@ -483,6 +485,23 @@ iSCSILogicalUnit_start() {
483485
echo ${OCF_RESKEY_emulate_caw} > ${iblock_attrib_path}/emulate_caw || exit $OCF_ERR_GENERIC
484486
fi
485487
;;
488+
scst)
489+
ocf_run scstadmin -open_dev "${OCF_RESOURCE_INSTANCE}" -handler vdisk_blockio -attributes "filename=${OCF_RESKEY_path},nv_cache=0,write_through=1"
490+
if [ -n "${OCF_RESKEY_scsi_sn}" ]; then
491+
ocf_run scstadmin -set_dev_attr "${OCF_RESOURCE_INSTANCE}" -attributes "usn=${OCF_RESKEY_scsi_sn}" -force -noprompt
492+
fi
493+
if [ -n "${OCF_RESKEY_vendor_id}" ]; then
494+
ocf_run scstadmin -set_dev_attr "${OCF_RESOURCE_INSTANCE}" -attributes "t10_vend_id=${OCF_RESKEY_vendor_id}" -force -noprompt
495+
fi
496+
if [ -n "${OCF_RESKEY_product_id}" ]; then
497+
ocf_run scstadmin -set_dev_attr "${OCF_RESOURCE_INSTANCE}" -attributes "t10_dev_id=${OCF_RESKEY_product_id}" -force -noprompt
498+
fi
499+
if [ -d "/sys/kernel/scst_tgt/targets/iscsi/${OCF_RESKEY_target_iqn}/ini_groups/allowed/" ]; then
500+
# if an initiator group exists for the target, add the new LUN to it.
501+
ocf_run scstadmin -add_lun ${OCF_RESKEY_lun} -driver iscsi -target "${OCF_RESKEY_target_iqn}" -device "${OCF_RESOURCE_INSTANCE}" -group allowed -force -noprompt
502+
fi
503+
ocf_run scstadmin -add_lun ${OCF_RESKEY_lun} -driver iscsi -target "${OCF_RESKEY_target_iqn}" -device "${OCF_RESOURCE_INSTANCE}" $group_arg -force -noprompt
504+
;;
486505
esac
487506

488507
# Force the monitor operation to pass before start is considered a success.
@@ -556,6 +575,10 @@ iSCSILogicalUnit_stop() {
556575
# (potentially causing fencing)
557576
ocf_run targetcli /backstores/${OCF_RESKEY_liot_bstype} delete ${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
558577
;;
578+
scst)
579+
ocf_run -warn scstadmin -rem_lun ${OCF_RESKEY_lun} -driver iscsi -target "${OCF_RESKEY_target_iqn}" -force -noprompt
580+
ocf_run scstadmin -close_dev "${OCF_RESOURCE_INSTANCE}" -handler vdisk_blockio -force -noprompt
581+
;;
559582
esac
560583

561584
return $OCF_SUCCESS
@@ -613,6 +636,12 @@ iSCSILogicalUnit_monitor() {
613636
[ -e ${block_configfs_path} ] && ocf_log warn "existing block without an active lun: ${block_configfs_path}"
614637
[ -e ${block_configfs_path} ] && return $OCF_ERR_GENERIC
615638
;;
639+
scst)
640+
[ -d /sys/kernel/scst_tgt/devices/${OCF_RESOURCE_INSTANCE} ] || return $OCF_NOT_RUNNING
641+
[ $(cat /sys/kernel/scst_tgt/devices/${OCF_RESOURCE_INSTANCE}/active) -eq 1 ] || return $OCF_NOT_RUNNING
642+
[ $(head -n1 /sys/kernel/scst_tgt/devices/${OCF_RESOURCE_INSTANCE}/filename) = "${OCF_RESKEY_path}" ] || return $OCF_NOT_RUNNING
643+
[ -d /sys/kernel/scst_tgt/targets/iscsi/${OCF_RESKEY_target_iqn}/luns/${OCF_RESKEY_lun} ] && return $OCF_SUCCESS
644+
;;
616645
esac
617646

618647
return $OCF_NOT_RUNNING
@@ -630,7 +659,7 @@ iSCSILogicalUnit_validate() {
630659

631660
# Is the configured implementation supported?
632661
case "$OCF_RESKEY_implementation" in
633-
"iet"|"tgt"|"lio"|"lio-t")
662+
"iet"|"tgt"|"lio"|"lio-t"|"scst")
634663
;;
635664
"")
636665
# The user didn't specify an implementation, and we were
@@ -704,6 +733,9 @@ iSCSILogicalUnit_validate() {
704733
lio-t)
705734
unsupported_params="scsi_id vendor_id tgt_bstype tgt_bsoflags tgt_bsopts tgt_device_type lio_iblock"
706735
;;
736+
scst)
737+
unsupported_params="scsi_id emulate_tpu emulate_3pc emulate_caw"
738+
;;
707739
esac
708740

709741
for var in ${unsupported_params}; do
@@ -737,6 +769,9 @@ iSCSILogicalUnit_validate() {
737769
lio-t)
738770
check_binary targetcli
739771
;;
772+
scst)
773+
check_binary scstadmin
774+
;;
740775
esac
741776

742777
# Is the required kernel functionality available?
@@ -751,6 +786,12 @@ iSCSILogicalUnit_validate() {
751786
tgt)
752787
# tgt is userland only
753788
;;
789+
scst)
790+
if [ ! -d /sys/kernel/scst_tgt ]; then
791+
ocf_log err "/sys/kernel/scst_tgt does not exist or is not a directory -- check if required modules are loaded."
792+
exit $OCF_ERR_INSTALLED
793+
fi
794+
;;
754795
esac
755796
fi
756797

heartbeat/iSCSITarget.in

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ elif have_binary lio_node; then
4141
OCF_RESKEY_implementation_default="lio"
4242
elif have_binary targetcli; then
4343
OCF_RESKEY_implementation_default="lio-t"
44+
elif have_binary scstadmin; then
45+
OCF_RESKEY_implementation_default="scst"
4446
fi
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
5860
TARGETLOCKFILE=${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

6166
meta_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">
7782
The 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
7984
availability 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

Comments
 (0)