#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/cllsvgname.sh 1.5 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1999,2009 
# 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 
# @(#)80  1.5  src/43haes/usr/sbin/cluster/cspoc/utilities/cllsvgname.sh, hacmp.cspoc, 61haes_r714 1/6/09 06:11:33
###############################################################################

###############################################################################
#
#   Name:	cllsvgname
#
#   Component:  hacmp.cspoc
#
#   Function:   Find the volume group, and, if possible, an accessable hdisk 
#		from that volume group, owning a given logical volume
#
#   Arguments:  logical volume name, e.g., "lv01"
#
#   Output:	The volume group name and an accessable hdisk name from that
#   		volume group (if present) are printed out.
#
#   Returns:    0 - Given logical volume was located
#		1 - Given logical volume could not be located
#
###############################################################################

[[ "$VERBOSE_LOGGING" = "high" ]] && set -x
PROGNAME=$(basename ${0})
PATH="$($(dirname ${0})/../utilities/cl_get_path all)"
HA_DIR="$(cl_get_path)"

set -u

#
#	Pick up the passed logical volume name, and determine its owning
#	volume group based on its definition
#
LVNAME=$1			# passed logical volume name
VGNAME=$(LC_ALL=C odmget -q "name = $LVNAME" CuDv | grep 'parent =' | cut -f2 -d'"')

if [[ -n $VGNAME ]]		# if found owning volume group
then
    #
    #	Having found the owning volume group, now find a readable disk that
    #	could be used by other nodes as a basis for importvg
    #
    for HDISKNAME in $(lspv | grep -w $VGNAME | read hdisk rest ; echo $hdisk)
    do
	#
	#	Make sure this disk is readable
	#
	if cl_querypv -q /dev/$HDISKNAME 
	then
	    #
	    #	The disk is readable, so pass back its name along with
	    #	the volume group name
	    #
	    echo "${VGNAME}:${HDISKNAME}"
	    return 0
	fi
    done
    #
    #	We were unable to find a readable hdisk, so return only the volume
    #	group name
    #
    echo "${VGNAME}:"		# only pass back volume group name
    return 0

else
    #
    #	It was not possible to find a volume group that owned the given
    #	logical volume in ODM.  
    #
    return 1			# logical volume not known on this node
fi