# HG changeset patch
# User Florian Haas <[email protected]>
# Date 1245083304 -7200
# Node ID a146156739068ce5c0718d5e8de431ecb03f1e95
# Parent  f86cda383abb14cd8ecdce20cc123a202ff13524
Linux SCSI Target Framework support for iSCSITarget and iSCSILogicalUnit.

Uses the tgtadm utility to manage targets and LUs.

See http://stgt.berlios.de/ for details on tgt.

diff -r f86cda383abb -r a14615673906 resources/OCF/iSCSILogicalUnit
--- a/resources/OCF/iSCSILogicalUnit    Mon Jun 15 18:28:24 2009 +0200
+++ b/resources/OCF/iSCSILogicalUnit    Mon Jun 15 18:28:24 2009 +0200
@@ -36,6 +36,8 @@
 # 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}}
 #######################################################################
@@ -151,6 +153,12 @@
                --lun=${OCF_RESKEY_lun} \
                --params Path=${OCF_RESKEY_path} && return $OCF_SUCCESS
            ;;
+       tgt)
+           do_cmd tgtadm --lld iscsi --op new --mode logicalunit \
+               --tid=${OCF_RESKEY_tid} \
+               --lun=${OCF_RESKEY_lun} \
+               --backing-store ${OCF_RESKEY_path} && return $OCF_SUCCESS
+           ;;
     esac
     return $OCF_ERR_GENERIC
 }
@@ -164,6 +172,11 @@
                    --tid=${OCF_RESKEY_tid} \
                    --lun=${OCF_RESKEY_lun} && return $OCF_SUCCESS
                ;;
+           tgt)
+               do_cmd tgtadm --lld iscsi --op delete --mode logicalunit \
+                   --tid ${OCF_RESKEY_tid} \
+                   --lun=${OCF_RESKEY_lun} && return $OCF_SUCCESS
+               ;;
        esac
     else
        return $OCF_SUCCESS
@@ -178,6 +191,12 @@
            # 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)
+           # 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
@@ -198,6 +217,9 @@
        iet)
            check_binary ietadm || return $OCF_ERR_INSTALLED
            ;;
+       tgt)
+           check_binary tgtadm || return $OCF_ERR_INSTALLED
+           ;;
        *)
            # and by the way, is the implementation supported?
            ocf_log error "Unsupported iSCSI target implementation 
\"$OCF_RESKEY_implementation\"!"
@@ -238,6 +260,23 @@
                    ;;
            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?
@@ -249,6 +288,9 @@
                return $OCF_ERR_INSTALLED
            fi
            ;;
+       tgt)
+           # tgt is userland only
+           ;;
     esac
 
     return $OCF_SUCCESS
diff -r f86cda383abb -r a14615673906 resources/OCF/iSCSITarget
--- a/resources/OCF/iSCSITarget Mon Jun 15 18:28:24 2009 +0200
+++ b/resources/OCF/iSCSITarget Mon Jun 15 18:28:24 2009 +0200
@@ -36,6 +36,8 @@
 # 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}}
 #######################################################################
@@ -164,6 +166,21 @@
            done
            return $OCF_SUCCESS
            ;;
+       tgt)
+           do_cmd tgtadm --lld iscsi --op new --mode target \
+               --tid=${OCF_RESKEY_tid} \
+               --targetname ${OCF_RESKEY_name} || return $OCF_ERR_GENERIC
+           for param in ${OCF_RESKEY_params}; do
+               name=${param%=*}
+               value=${param#*=}
+               do_cmd tgtadm --lld iscsi --op update --mode target \
+                   --tid=${OCF_RESKEY_tid} \
+                   --name=${name} --value=${value} || return $OCF_ERR_GENERIC
+           done
+           do_cmd tgtadm --lld iscsi --op bind --mode target \
+               --tid=${OCF_RESKEY_tid} \
+               --initiator-address=ALL && return $OCF_SUCCESS
+           ;;
     esac
     return $OCF_ERR_GENERIC
 }
@@ -193,6 +210,29 @@
                do_cmd ietadm --op delete \
                    --tid=${OCF_RESKEY_tid} && return $OCF_SUCCESS
                ;;
+           tgt)
+               # Close existing connections. There is no other way to
+               # do this in tgt than to parse the output of "tgtadm --op
+               # show".
+               local line
+               tgtadm --lld iscsi --op show --mode target \
+                   | sed -ne '/^Target '${OCF_RESKEY_tid}':/,/^Target/ {
+                          /^[[:space:]]*I_T nexus: \([0-9]\+\)/ {
+                             s/^.*: \([0-9]*\).*/--sid=\1/; h;
+                          };
+                          /^[[:space:]]*Connection: \([0-9]\+\)/ { 
+                              s/^.*: \([0-9]*\).*/--cid=\1/; G; s/\n/ /;p; 
+                          }; 
+                          /^[[:space:]]*LUN information:/ q; 
+                      }' \
+                   | while read line; do
+                        # $line looks like "--sid=X --cid=Y"
+                        do_cmd tgtadm --lld iscsi --op delete --mode 
connection \
+                            --tid ${OCF_RESKEY_tid} $line
+               done
+               do_cmd tgtadm --lld iscsi --op delete --mode target \
+                   --tid ${OCF_RESKEY_tid} && return $OCF_SUCCESS
+               ;;
        esac
     else
        return $OCF_SUCCESS
@@ -205,6 +245,10 @@
        iet)
            grep -q "tid:${OCF_RESKEY_tid} name:${OCF_RESKEY_name}" 
/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
+           ;;
     esac
     
     return $OCF_NOT_RUNNING
@@ -225,6 +269,9 @@
        iet)
            check_binary ietadm || return $OCF_ERR_INSTALLED
            ;;
+       tgt)
+           check_binary tgtadm || return $OCF_ERR_INSTALLED
+           ;;
        *)
            # and by the way, is the implementation supported?
            ocf_log error "Unsupported iSCSI target implementation 
\"$OCF_RESKEY_implementation\"!"
@@ -255,6 +302,9 @@
                return $OCF_ERR_INSTALLED
            fi
            ;;
+       tgt)
+           # tgt is userland only
+           ;;
     esac
 
     return $OCF_SUCCESS
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to