#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/clgetvpathid.sh 1.5 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2002,2005 
# 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 
# @(#)35        1.5 src/43haes/usr/sbin/cluster/cspoc/utilities/clgetvpathid.sh, hacmp.cspoc, 61haes_r714 12/6/05 13:17:11
# \$Id\$

###############################################################################
#
#   COMPONENT_NAME: hacmp.cspoc
#
#
#   Function:    returns a list of the known vpath disks not currently in a
#                volume group, along with an indication of whether they can
#                support a concurrent mode volume group
#
#                returns a list of the free major numbers for logical volumes
#
#                get_pvls   Get physical volumes for vpath.
#
#   Origins:     27
#
#   Arguments:   None
#
#   Environment: None
#
###############################################################################

###############################################################################
#
#  FUNCTION:    get_pvls
#
#  Description: Get physical volumes for vpath.
#
#  Arguments:   
#
#  Returns:
#
#  Environment: VPATH
#               PVLS
#
###############################################################################
get_pvls()
{
   [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
   #
   # Get physical volumes for vpath.
   #
   PVLS=$(odmget -q"name=${VPATH} AND attribute=active_hdisk" CuAt | \
         awk '
         {
            gsub(/"/,"")
            sub(/\/.*$/,"")
            if ($1=="value")
            {
               printf("%s ",$3)
            }
         }')
}

###############################################################################
#
#  Main
#
###############################################################################
PROGNAME=${0##*/}
export PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"
VPATH=""
PVID=""
CONC=""
ECON=""
PVLS=""
DISK=""
[[ ${VERBOSE_LOGGING} == high ]] && set -x
[[ ${VERBOSE_LOGGING} == high ]] && version='1.5'
if [[ -x /usr/sbin/lsvpcfg ]]
then
   #
   # Get vpaths and PVIDs if no VG.
   #
   lspv | awk '($1~/^vpath/ && $3~/^None$/){printf("%s %s\n",$1,$2)}' | \
   while read VPATH PVID
   do
      get_pvls
      if [[ -n ${PVLS} ]]
      then
         DISK=$(echo ${PVLS}|awk '{print $1}')
      fi
      if [[ "1" == $(lquerypv -C $DISK) ]]
      then
         #
         # The ones that LVM says are concurrent capable
         #
         CONC="C"
         ECON="N"
      elif [[ -x /usr/sbin/gsclvmd ]]
      then
         #
         # Otherwise, if the group services CLVM daemon is present,
         # pretty much anything can be used in a concurrent
         # volume group
         #
         CONC="C"
         ECON="Y"
      else
         #
         # Anything else can't be used in a concurrent volume group
         #
         CONC="N"
         ECON="Y"
      fi
      echo ${VPATH}:${PVID}:${PVLS}:${CONC}:${ECON}
   done
fi
FREEMAJOR=$(lvlstmajor)
echo "FREEMAJORS:$FREEMAJOR"
exit 0
