#!/bin/sh ################################################################################ # # This file is part of the vhacs project. # Jerome Martin # ################################################################################ # # iSCSI initiator-based filesystem mount OCF resource agent # Logs into an iSCSI target and locally mount the corresponding filesystem # ################################################################################ # # OCF instance parameters: # OCF_RESKEY_target: the iSCSI target (required) # OCF_RESKEY_portal: the iSCSI portal address (required) # OCF_RESKEY_mountpoint: the filesystem mountpoint (required) # OCF_RESKEY_fstype: the filesystem type (required) # OCF_RESKEY_iscsiadm: iscsiadm program path (optional) # ################################################################################ # # Source common vhacs OCF RA code. . ${OCF_ROOT}/resource.d/vhacs/.ocf-vhacs # ################################################################################ rsc_meta_data() { cat <<- EOF 1.0 OCF Resource Agent for mounting iSCSI devices. iscsi filesystem mount resource agent The iSCSI target iqn. target The iSCSI portal ip address portal The mountpoint for iSCSI device. If the mountpoint does not exist, it will be created. In all cases, the mountpoint will be deleted upon umount action. mountpoint The filesystem type on the iSCSI device. fstype iscsiadm program path. iscsiadm EOF } rsc_start() { ocf_lock_RA # do some cleanup before discovery rm -f "/etc/iscsi/send_targets/${OCF_RESKEY_portal},3260" &>/dev/null rm -f "/etc/iscsi/nodes/${OCF_RESKEY_target}" &>/dev/null # update discovery information ocf_cmd "iscsiadm -m discovery -t st -p ${OCF_RESKEY_portal}" || return ${OCF_ERR_GENERIC} ocf_unlock_RA # start the iscsi session ocf_cmd "iscsiadm -m node -p ${OCF_RESKEY_portal} -T ${OCF_RESKEY_target} -l" || return ${OCF_ERR_GENERIC} # wait for udev to create the device or fails after a few seconds local tries=0 local maxtries=10 while [ ${tries} -lt ${maxtries} ] ; do let tries++ sleep 0.5 ls ${DEVICE_PATH} &>/dev/null && break done ocf_cmd "ls ${DEVICE_PATH}" || return ${OCF_ERR_GENERIC} # make sure the mountpoint exists ocf_cmd "mkdir -p ${OCF_RESKEY_mountpoint}" || return ${OCF_ERR_GENERIC} # mount the device ocf_cmd "mount -o errors=continue ${DEVICE_PATH} ${OCF_RESKEY_mountpoint} -t ${OCF_RESKEY_fstype}" || return ${OCF_ERR_GENERIC} # If there where no errors, return success return ${OCF_SUCCESS} } rsc_stop() { # umount the device and delete the mountpoint ocf_log info "rsc_stop trying to umount and delete ${OCF_RESKEY_mountpoint}" fuser -k -m ${OCF_RESKEY_mountpoint} &>/dev/null # this fails most of the time ocf_cmd "umount ${OCF_RESKEY_mountpoint}" ocf_cmd "rm -rf ${OCF_RESKEY_mountpoint}" #ocf_lock_RA # tear down the iscsi session ocf_log info "rsc_stop trying to tear down the iscsi session with ${OCF_RESKEY_target} on ${OCF_RESKEY_portal}" ocf_cmd "iscsiadm -m node -p ${OCF_RESKEY_portal} -T ${OCF_RESKEY_target} -u" # cleanup after stop rm -f "/etc/iscsi/send_targets/${OCF_RESKEY_portal},3260" &>/dev/null rm -f "/etc/iscsi/nodes/${OCF_RESKEY_target}" &>/dev/null #ocf_unlock_RA # We've done all we could to stop that resource, let monitor check it return ${OCF_SUCCESS} } rsc_monitor() { # Reset checks count ocf_checks_reset # Check if the session is up iscsiadm -m session 2>/dev/null | grep -qs "$OCF_RESKEY_target$" &>/dev/null ocf_checks_checkrc "Does iscsi session for $OCF_RESKEY_target exist with ${OCF_RESKEY_portal} ?" # Check if the device is mounted rw on the proper mountpoint grep "${DEVICE_PATH} ${OCF_RESKEY_mountpoint} ${OCF_RESKEY_fstype} rw" /proc/mounts &>/dev/null ocf_checks_checkrc "Is the device ${DEVICE_PATH} mounted rw on ${OCF_RESKEY_mountpoint} as ${OCF_RESKEY_fstype} ?" # Return checks result ocf_checks_result return $? } rsc_setup() { DEVICE_PATH="/dev/disk/by-path/ip-${OCF_RESKEY_portal}:3260-iscsi-${OCF_RESKEY_target}-lun-0" return ${OCF_SUCCESS} } ################################################################################ # # Call the main ocf RA logic # ################################################################################ ocf_main $1