#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/events/utils/cl_cfgvg.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2007,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 

# @(#)73  1.4  src/43haes/usr/sbin/cluster/events/utils/cl_cfgvg.sh, hacmp.events, 61haes_r714 5/14/08 00:48:27

#########################################################################
#       Name:		cl_cfgvg 
#
#       Description:	This script is written to varyonvg all VG with
#			auto_on=y and parent=$1. This is mainly used to
#			varyonvg all iSCSI VG with auto_on=y after the
#			TCPIP is up.
#
#       Called by:	acquire_service_addr node_up process_resources
#
#       Arguments:	parent_dev (like iscsi0)
#
#########################################################################

[[ $VERBOSE_LOGGING == "high" ]] && set -x
[[ $VERBOSE_LOGGING == "high" ]] && version="1.4"

# Parent device we are interested in.
parent_dev=$1

# Fetch all VG on this node.
all_vgs=$(lsvg)

# Fetch all active VG on this node.
active_vgs=$(lsvg -o)

# Fetch all Inactive VG on this node.
for all_vg in $all_vgs
do
	inact=1

	for act_vg in $active_vgs
	do
		if [[ $act_vg == $all_vg ]]
		then
			inact=0
			break
		fi
	done

	if [[ $inact == 1 ]]
	then
		inact_vgs="$inact_vgs $all_vg"
	fi
done

# Fetch Inactive VGs with auto_on TRUE using lsattr
for inact_vg in $inact_vgs
do
	auto_on=$(LC_ALL=C lsattr -El $inact_vg | awk '($1 == "auto_on") {print $2}')
	if [[ $auto_on == "y" ]]
	then
		autoon_vgs="$autoon_vgs $inact_vg"
	fi
done

# Check if autoon_vgs VG have disks with parent as in $1. If
# Yes then varyonvg such VG.

for autoon_vg in $autoon_vgs
do
	auto_disks=$(lspv | awk -v avg=$autoon_vg '($3 ==  avg) {print $1}')
	for auto_disk in $auto_disks
	do
		parent=$(lsdev -l $auto_disk -F parent)
		if [[ $parent == $parent_dev ]]
		then
			varyonvg $autoon_vg
			break
		fi
	done
done
