#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/lib/ksh93/aix/KLIB_AIX_get_vg_by_disk.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2005,2011 
# 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 
# @(#)72	1.4 src/43haes/lib/ksh93/aix/KLIB_AIX_get_vg_by_disk.sh, hacmp, 61haes_r714 11/28/11 15:24:58
#
#=head1 NAME
#
# KLIB_AIX_get_vg_by_disk - Obtain the volume group name for the
#                           specified device name
#
#=head1 SYNOPSIS
#
# vg=$(KLIB_AIX_get_vg_by_disk "/dev/rdevtbsp1")
#
#=head1 DESCRIPTION
#
# Echo's to stdout the volume group name for the specified raw disk device
#
#=head1 ARGUMENTS
#
# 	1: [scalar] raw disk device name
#
#=head1 RETURN
#
#   0: success, stdout contains the name of the volume group
#   1: failed, unable to find the volume group info in the local AIX odms
#
#=head1 COPYRIGHT
#
#(C) COPYRIGHT International Business Machines Corp. 2005
#All Rights Reserved
#
#=cut
#
function KLIB_AIX_get_vg_by_disk
{
	. /usr/es/lib/ksh93/func_include

        typeset disk=$1
        if [[ -z $disk ]]; then
                return 1
        fi

	# If the disk device is /dev/rdevtblsp1 then the CuDv entry is devtblsp1
	typeset CuDvDisk=${disk/\/dev\/r/}
	typeset name
	typeset value

        odmget -q name=$CuDvDisk CuDv | while IFS='=' read name value; do
                value=$(eval echo $value)    # strip the "" from any values in CuAt
                name=$(eval echo $name)      # strip any whitespace
                if [[ "$name" == "parent" ]]; then
                        echo $value
                        return 0
                fi
        done

        return 1
}
