From 480f59c74238fa987a909c5551704453a1ef4444 Mon Sep 17 00:00:00 2001 From: Jiri Lunacek Date: Tue, 26 Mar 2019 16:33:21 +0100 Subject: [PATCH 1/7] enable fileio backing store for lio-t type iSCSI logical unit --- heartbeat/iSCSILogicalUnit.in | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/heartbeat/iSCSILogicalUnit.in b/heartbeat/iSCSILogicalUnit.in index 5838c8738e..f030435548 100644 --- a/heartbeat/iSCSILogicalUnit.in +++ b/heartbeat/iSCSILogicalUnit.in @@ -402,14 +402,26 @@ iSCSILogicalUnit_start() { lio-t) ocf_take_lock $TARGETLOCKFILE ocf_release_lock_on_exit $TARGETLOCKFILE - iblock_attrib_path="/sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}/attrib" + if [ -d /sys/kernel/config/target/core/fileio_${OCF_RESKEY_lio_iblock} ]; then + iblock_path="/sys/kernel/config/target/core/fileio_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}" + else + iblock_path="/sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}" + fi + iblock_attrib_path="$iblock_path/attrib" # For lio, we first have to create a target device, then # add it to the Target Portal Group as an LU. - ocf_run targetcli /backstores/block create name=${OCF_RESOURCE_INSTANCE} dev=${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC + local backstore_type + if [ -b "${OCF_RESKEY_path}" ]; then + ocf_run targetcli /backstores/block create name=${OCF_RESOURCE_INSTANCE} dev=${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC + backstore_type=block + else + ocf_run targetcli /backstores/fileio create name=${OCF_RESOURCE_INSTANCE} file_or_dev=${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC + backstore_type=fileio + fi if [ -n "${OCF_RESKEY_scsi_sn}" ]; then - echo ${OCF_RESKEY_scsi_sn} > /sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}/wwn/vpd_unit_serial + echo ${OCF_RESKEY_scsi_sn} > $iblock_path/wwn/vpd_unit_serial fi - ocf_run targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/luns create /backstores/block/${OCF_RESOURCE_INSTANCE} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC + ocf_run targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/luns create /backstores/$backstore_type/${OCF_RESOURCE_INSTANCE} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC if $(ip a | grep -q inet6); then ocf_run -q targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/portals delete 0.0.0.0 3260 @@ -491,6 +503,14 @@ iSCSILogicalUnit_stop() { ocf_release_lock_on_exit $TARGETLOCKFILE # "targetcli delete" will fail if the LUN is already # gone. Log a warning and still push ahead. + + local backstore_type + if targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/luns/lun${OCF_RESKEY_lun} status | grep ' fileio/' >/dev/null; then + backstore_type=fileio + else + backstore_type=block + fi + ocf_run -warn targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/luns delete ${OCF_RESKEY_lun} if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then for initiator in ${OCF_RESKEY_allowed_initiators}; do @@ -504,7 +524,7 @@ iSCSILogicalUnit_stop() { # delete the backstore, then something is seriously # wrong and we need to fail the stop operation # (potentially causing fencing) - ocf_run targetcli /backstores/block delete ${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC + ocf_run targetcli /backstores/$backstore_type delete ${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC ;; esac @@ -559,7 +579,7 @@ iSCSILogicalUnit_monitor() { [ -e ${configfs_path} ] && [ `cat ${configfs_path}` = "${OCF_RESKEY_path}" ] && return $OCF_SUCCESS # if we aren't activated, is a block device still left over? - block_configfs_path="/sys/kernel/config/target/core/iblock_*/${OCF_RESOURCE_INSTANCE}/udev_path" + block_configfs_path="/sys/kernel/config/target/core/{iblock,fileio}_*/${OCF_RESOURCE_INSTANCE}/udev_path" [ -e ${block_configfs_path} ] && ocf_log warn "existing block without an active lun: ${block_configfs_path}" [ -e ${block_configfs_path} ] && return $OCF_ERR_GENERIC ;; From b1c9c4aae25463ea1d8c612166ac4779d44d1f45 Mon Sep 17 00:00:00 2001 From: Jiri Lunacek Date: Tue, 26 Mar 2019 17:48:30 +0100 Subject: [PATCH 2/7] fixed attrib path compilation for fileio backing store --- heartbeat/iSCSILogicalUnit.in | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/heartbeat/iSCSILogicalUnit.in b/heartbeat/iSCSILogicalUnit.in index f030435548..ad5e0ae39e 100644 --- a/heartbeat/iSCSILogicalUnit.in +++ b/heartbeat/iSCSILogicalUnit.in @@ -402,22 +402,19 @@ iSCSILogicalUnit_start() { lio-t) ocf_take_lock $TARGETLOCKFILE ocf_release_lock_on_exit $TARGETLOCKFILE - if [ -d /sys/kernel/config/target/core/fileio_${OCF_RESKEY_lio_iblock} ]; then - iblock_path="/sys/kernel/config/target/core/fileio_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}" - else - iblock_path="/sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}" - fi - iblock_attrib_path="$iblock_path/attrib" # For lio, we first have to create a target device, then # add it to the Target Portal Group as an LU. local backstore_type if [ -b "${OCF_RESKEY_path}" ]; then ocf_run targetcli /backstores/block create name=${OCF_RESOURCE_INSTANCE} dev=${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC + iblock_path="/sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}" backstore_type=block else ocf_run targetcli /backstores/fileio create name=${OCF_RESOURCE_INSTANCE} file_or_dev=${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC + iblock_path="/sys/kernel/config/target/core/fileio_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}" backstore_type=fileio fi + iblock_attrib_path="$iblock_path/attrib" if [ -n "${OCF_RESKEY_scsi_sn}" ]; then echo ${OCF_RESKEY_scsi_sn} > $iblock_path/wwn/vpd_unit_serial fi From 6d8fab39826ad83238c0a274f49e0513c894b5f9 Mon Sep 17 00:00:00 2001 From: Jiri Lunacek Date: Wed, 27 Mar 2019 09:48:25 +0100 Subject: [PATCH 3/7] set authentication for target without specific initiator acls --- heartbeat/iSCSITarget.in | 1 + 1 file changed, 1 insertion(+) diff --git a/heartbeat/iSCSITarget.in b/heartbeat/iSCSITarget.in index 9128fdc555..b29e55a769 100644 --- a/heartbeat/iSCSITarget.in +++ b/heartbeat/iSCSITarget.in @@ -391,6 +391,7 @@ iSCSITarget_start() { done else 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 + ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/ set auth userid=${OCF_RESKEY_incoming_username} password=${OCF_RESKEY_incoming_password} || exit $OCF_ERR_GENERIC fi ;; esac From 62b74bc52dd1d9dd009a2fb667167c91a735546f Mon Sep 17 00:00:00 2001 From: Jiri Lunacek Date: Wed, 3 Apr 2019 14:14:05 +0200 Subject: [PATCH 4/7] add check of username before setting auth on target --- heartbeat/iSCSITarget.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/heartbeat/iSCSITarget.in b/heartbeat/iSCSITarget.in index b29e55a769..693a8e3d71 100644 --- a/heartbeat/iSCSITarget.in +++ b/heartbeat/iSCSITarget.in @@ -390,8 +390,10 @@ iSCSITarget_start() { fi done else - 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 - ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/ set auth userid=${OCF_RESKEY_incoming_username} password=${OCF_RESKEY_incoming_password} || exit $OCF_ERR_GENERIC + if [ -n "${OCF_RESKEY_incoming_username}" ]; then + 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 + ocf_run targetcli /iscsi/${OCF_RESKEY_iqn}/tpg1/ set auth userid=${OCF_RESKEY_incoming_username} password=${OCF_RESKEY_incoming_password} || exit $OCF_ERR_GENERIC + fi fi ;; esac From 67f2c9bbfab15cf08397a721dfa969eb5341b56b Mon Sep 17 00:00:00 2001 From: Jiri Lunacek Date: Wed, 3 Apr 2019 14:15:53 +0200 Subject: [PATCH 5/7] if lio_iblock is unset, it defaults to 0, this this config path compilation does not work if more than one backing store exist. Switched to discovery by OCF_RESOURCE_INSTANCE which should be unique --- heartbeat/iSCSILogicalUnit.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/heartbeat/iSCSILogicalUnit.in b/heartbeat/iSCSILogicalUnit.in index ad5e0ae39e..641484b272 100644 --- a/heartbeat/iSCSILogicalUnit.in +++ b/heartbeat/iSCSILogicalUnit.in @@ -407,13 +407,12 @@ iSCSILogicalUnit_start() { local backstore_type if [ -b "${OCF_RESKEY_path}" ]; then ocf_run targetcli /backstores/block create name=${OCF_RESOURCE_INSTANCE} dev=${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC - iblock_path="/sys/kernel/config/target/core/iblock_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}" backstore_type=block else ocf_run targetcli /backstores/fileio create name=${OCF_RESOURCE_INSTANCE} file_or_dev=${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC - iblock_path="/sys/kernel/config/target/core/fileio_${OCF_RESKEY_lio_iblock}/${OCF_RESOURCE_INSTANCE}" backstore_type=fileio fi + iblock_path=`ls -1d /sys/kernel/config/target/core/*/${OCF_RESOURCE_INSTANCE}` iblock_attrib_path="$iblock_path/attrib" if [ -n "${OCF_RESKEY_scsi_sn}" ]; then echo ${OCF_RESKEY_scsi_sn} > $iblock_path/wwn/vpd_unit_serial From 93589a19120f95eeaa93d5cc2fb9409166586d42 Mon Sep 17 00:00:00 2001 From: Jiri Lunacek Date: Tue, 9 Apr 2019 16:55:48 +0200 Subject: [PATCH 6/7] better detection of backstore type - mainly in failed resource state --- heartbeat/iSCSILogicalUnit.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heartbeat/iSCSILogicalUnit.in b/heartbeat/iSCSILogicalUnit.in index 641484b272..24d5cff57b 100644 --- a/heartbeat/iSCSILogicalUnit.in +++ b/heartbeat/iSCSILogicalUnit.in @@ -501,7 +501,7 @@ iSCSILogicalUnit_stop() { # gone. Log a warning and still push ahead. local backstore_type - if targetcli /iscsi/${OCF_RESKEY_target_iqn}/tpg1/luns/lun${OCF_RESKEY_lun} status | grep ' fileio/' >/dev/null; then + if targetcli /backstores/fileio/${OCF_RESOURCE_INSTANCE} status >/dev/null 2>&1 ; then backstore_type=fileio else backstore_type=block From f2f551c676a6a69cea8d36fbced58b99e800ffb1 Mon Sep 17 00:00:00 2001 From: Jiri Lunacek Date: Tue, 9 Apr 2019 16:57:19 +0200 Subject: [PATCH 7/7] when resource is in failed state this prevents targetcli cleanup --- heartbeat/iSCSILogicalUnit.in | 4 ---- 1 file changed, 4 deletions(-) diff --git a/heartbeat/iSCSILogicalUnit.in b/heartbeat/iSCSILogicalUnit.in index 24d5cff57b..79baacece7 100644 --- a/heartbeat/iSCSILogicalUnit.in +++ b/heartbeat/iSCSILogicalUnit.in @@ -448,10 +448,6 @@ iSCSILogicalUnit_start() { } iSCSILogicalUnit_stop() { - iSCSILogicalUnit_monitor - if [ $? -eq $OCF_NOT_RUNNING ]; then - return $OCF_SUCCESS - fi case $OCF_RESKEY_implementation in