--- iSCSILogicalUnit	2012-05-25 09:23:59.000000000 -0700
+++ ../../iSCSILogicalUnit	2012-06-28 10:04:45.962058896 -0700
@@ -250,23 +250,44 @@
 	    fi
 	    ;;
 	lio)
+	    # use iblock if path points to a block device, fileio otherwise
+	    if [ -b "${OCF_RESKEY_path}" ]; then
+		backstoreType="iblock"
+	    else
+		backstoreType="fileio"
+	    fi
 	    # For lio, we first have to create a target device, then
 	    # add it to the Target Portal Group as an LU.
-	    ocf_run tcm_node --createdev=iblock_0/${OCF_RESOURCE_INSTANCE} \
-		${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC
+	    if [ "${backstoreType}" = "iblock" ]; then
+		ocf_run tcm_node --createdev=${backstoreType}_0/${OCF_RESOURCE_INSTANCE} \
+		    ${OCF_RESKEY_path} || exit $OCF_ERR_GENERIC
+	    elif [ "${backstoreType}" = "fileio" ]; then
+		# Do nothing if the file isn't there
+		if [ -f "${OCF_RESKEY_path}" ]; then
+		    # This might not be the best way to identify file size
+		    fileSize="$(ls -l ${OCF_RESKEY_path} | cut -d ' ' -f 5)"
+			ocf_run tcm_node --fileio ${backstoreType}_0/${OCF_RESOURCE_INSTANCE} \
+			    ${OCF_RESKEY_path} ${fileSize} || exit $OCF_ERR_GENERIC
+		else
+		    ocf_log error "Missing file ${OCF_RESKEY_path}"
+		    exit $OCF_ERR_GENERIC
+		fi
+	    else
+		ocf_log error "Unknown backstoreType: ${backstoreType}"
+		exit $OCF_ERR_GENERIC
+	    fi
 	    if [ -n "${OCF_RESKEY_scsi_sn}" ]; then
-		ocf_run tcm_node --setunitserial=iblock_0/${OCF_RESOURCE_INSTANCE} \
+		ocf_run tcm_node --setunitserial=${backstoreType}_0/${OCF_RESOURCE_INSTANCE} \
 		    ${OCF_RESKEY_scsi_sn} || exit $OCF_ERR_GENERIC
 	    fi
 	    ocf_run lio_node --addlun=${OCF_RESKEY_target_iqn} 1 ${OCF_RESKEY_lun} \
-		${OCF_RESOURCE_INSTANCE} iblock_0/${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
-
-           if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
-               for initiator in ${OCF_RESKEY_allowed_initiators}; do
-                       ocf_run lio_node --addlunacl=${OCF_RESKEY_target_iqn} 1 \
-                       ${initiator} ${OCF_RESKEY_lun} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
-               done
-           fi
+		${OCF_RESOURCE_INSTANCE} ${backstoreType}_0/${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
+	    if [ -n "${OCF_RESKEY_allowed_initiators}" ]; then
+		for initiator in ${OCF_RESKEY_allowed_initiators}; do
+		    ocf_run lio_node --addlunacl=${OCF_RESKEY_target_iqn} 1 \
+			${initiator} ${OCF_RESKEY_lun} ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
+		done
+	    fi
 	    ;;
     esac
 
@@ -304,7 +325,12 @@
                        done
                fi
 		ocf_run lio_node --dellun=${OCF_RESKEY_target_iqn} 1 ${OCF_RESKEY_lun} || exit $OCF_ERR_GENERIC
-		ocf_run tcm_node --freedev=iblock_0/${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
+		if [ -b "${OCF_RESKEY_path}" ]; then
+		    backstoreType="iblock"
+		else
+		    backstoreType="fileio"
+		fi
+		ocf_run tcm_node --freedev=${backstoreType}_0/${OCF_RESOURCE_INSTANCE} || exit $OCF_ERR_GENERIC
 	esac
     fi
     
@@ -340,8 +366,14 @@
 		| grep -E -q "[[:space:]]+Backing store.*: ${OCF_RESKEY_path}$" && return $OCF_SUCCESS
 	    ;;
 	lio)
-	    configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/lun/lun_${OCF_RESKEY_lun}/${OCF_RESOURCE_INSTANCE}/udev_path"
-	    [ -e ${configfs_path} ] && [ `cat ${configfs_path}` = "${OCF_RESKEY_path}" ] && return $OCF_SUCCESS
+	    if [ -b "${OCF_RESKEY_path}" ]; then
+		configfs_path="/sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/lun/lun_${OCF_RESKEY_lun}/${OCF_RESOURCE_INSTANCE}/udev_path"
+		[ -e ${configfs_path} ] && [ `cat ${configfs_path}` = "${OCF_RESKEY_path}" ] && return $OCF_SUCCESS
+	    else
+		# This may not be the best way to identify the file
+		configfs_path="$(cat /sys/kernel/config/target/iscsi/${OCF_RESKEY_target_iqn}/tpgt_1/lun/lun_${OCF_RESKEY_lun}/${OCF_RESOURCE_INSTANCE}/info |grep File|cut -d : -f 3|cut -d ' ' -f 2)"
+		[ -e ${configfs_path} ] && [ `echo ${configfs_path}` = "${OCF_RESKEY_path}" ] && return $OCF_SUCCESS
+	    fi
 	    ;;
     esac
     
