#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/events/utils/cl_is_scsidisk.sh 1.10 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1990,2008 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)25	1.10  src/43haes/usr/sbin/cluster/events/utils/cl_is_scsidisk.sh, hacmp.events, 61haes_r714 6/2/08 17:50:44
#
#   COMPONENT_NAME: EVENTUTILS
#
#   FUNCTIONS: none
#
#   ORIGINS: 27
#
###############################################################################
# 
# Name: cl_is_scsidisk
#
# Check to see if a disk is a scsi disk
#	return: 0 Disk is a SCSI disk
#	return: 1 Disk is NOT a SCSI disk
#	return: 2 Error
#
# Arguments: hdisk
#
# Environment: VERBOSE_LOGGING, PATH
#
###############################################################################

PROGNAME=$(basename ${0})
[[ "$VERBOSE_LOGGING" = "high" ]] && set -x
[[ "$VERBOSE_LOGGING" = "high" ]] && version='1.10'

set -u

if [ $# -eq 0 ]
then
	cl_echo 46 "$PROGNAME usage: cl_is_scsidisk hdiskname" $PROGNAME
	exit 2
fi

if [ "$VERBOSE_LOGGING" = "high" ]
then
	set -x
	clgrep="egrep"
else
	clgrep="egrep -s"
fi

disk=$*

# We use the AIX command lsparent to find out which type of disk
# we are using. The arg -C tells lsparent to get its info from
# the Customized Data Base (which is the ODM file that contains
# the devices that are actually configured). We limit the output
# to the "name" using the -F option. If lsparent fails then 
# then $disk was not know to the system.

parent=`lsparent -C -l $disk -F "name"`
rclsparent=$?
if [ $rclsparent -ne 0 ]
then
        : exit status of lsparent -C -l $disk -F "name" : $rclsparent
	cl_log 47 "$PROGNAME: Device $disk not configured." $PROGNAME $disk
	exit 2
fi

# Finally we look for the string "scsi" in the parent name to 
# decide if it is a SCSI device. In addition to that, we also 
# need to test for SSA disks cuz they are also treated as SCSI
# devices.

echo $parent | $clgrep "^scsi|^ssar|^vscsi"

# If it's SCSI return 0, else 1. I know this is not efficient but it
# is explicit.

if [ $? -eq 0 ]
then 
	exit 0
else
	exit 1
fi
