#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/clhd2vp.sh 1.3 
#  
# 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 
# @(#)13	1.3 src/43haes/usr/sbin/cluster/cspoc/utilities/clhd2vp.sh, hacmp.cspoc, 61haes_r714 5/26/05 11:37:02
# $Id$
# @(#)59  1.0.0.0  src/43haes/usr/sbin/cluster/cspoc/utilities/clhd2vp.sh, hacmp.cspoc, 51haes_r510 6/21/02 19:50:09
###############################################################################
#
# Name:
#       clhd2vp
#
# Description:
#   The clhd2vp command takes the given volume group and converts it from
#   ESS hdisks to SDD vapths and back. This is used to be called by a C-SPOC
#   scripts, initially by cl_hd2vp C-SPOC plan.
#
#   Usage: clhd2vp 
#
# Arguments:
#   The clhd2vp command argumens are the conversion type and the VG name
#   -f/-b	Conversion type, "forward"/"backward"
#	-f	Convert from hdisks to vpaths (hd2vp)
#	-b	Convert back from vpaths to hdisks (vp2hd)
#
# Return Values:
#       0       	success
#       non-zero    	failure
#
# Suggested run example:
#       clhd2vp -f vg1 
#
################################################################################

FLAG=$1 #Convertion type
VG=$2	#VG name to convert

VPATHS=$(lspv | grep $VG | cut -f1 -d' ' | grep vpath) #See if there are VPaths already in VG's config
HDISKS=$(lspv | grep $VG | cut -f1 -d' ' | grep hdisk) #See if there are hdisks already in VG's config

if [ "$FLAG" = "-f" ] #If configuring from hdisks to vpaths
then
	if [ -z "$HDISKS" ] 	#if it already has no any hdisks
	then
		print "${PROGNAME}: Volume group $VG has already been converted to vpaths."
        elif [ -z "$VPATHS" ]	#If there are no vpaths yet
        then
                hd2vp $VG	#Smply convert
        elif [ -n "$HDISKS" ]	#If there are both vpaths and hdisks
        then
                dpovgfix $VG	#Run fixing utility - everything will move to vpath
        fi
elif [ "$FLAG" = "-b" ]	#If converting from vpaths to hdisks	
then
        if [ -n "$VPATHS" ] #If there are VPaths - we need to do something
        then
                if [ -n "$HDISKS" ] #If there are also hdisks 
                then
                        dpovgfix $VG #then fix first - get everything to vpaths
                fi
                vp2hd $VG #Convert from hdisks to vpaths
	else
		print "${PROGNAME}: Volume group $VG has already been converted to hdisks."
        fi
fi

exit $?
