#! /usr/bin/ksh
#
#pragma	ident	"@(#)rac_cvm_validate.ksh	1.5	03/01/30 SMI"
#
# Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
############################################################
#
# SUNW.rac_cvm VALIDATE method
#
############################################################

INCLUDE="."
INCLUDE_PATH=/usr/cluster/lib/ucmm

export TEXTDOMAINDIR=/usr/cluster/lib/locale
export TEXTDOMAIN=SUNW_SC_CMD

${INCLUDE} ${INCLUDE_PATH}/rac_lib

${INCLUDE} ${MYDIR}/rac_cvm_lib

validate_configuration()
{
	typeset validate_rc=0

	validate_special_properties
	if [ $? -ne 0 ]; then
		validate_rc=1
	fi 
	
	return $validate_rc
}
###############################################################
# validate_special_properties
#	This function validates properties than shold not be modified
# 	when VxVM is not running in cluster mode. 
#
# 	These special properties are used by VxVm to communicate 
#	with VxVM on other nodes. The VxVM daemons can start using these 
#	properties only on node reboot
#
#	However, if daemon on one node uses new value and on other node,
#	its is using old value, it can cause panic on node
#	and has potential to bring down all RAC nodes
#
#	If VxVM module is installed on this node and ucmmd is running,
#	it is assumed that VxVM is running in cluster mode, at the time
#	this method is invoked.
#	
#	If ucmmd is not running on this node then here is no need to 
#	validate the properties. Validate method will be called on each node
#	thus ensuring that property can be modified only when ucmmd is 
#	not running on any cluster node.
#
#	Return codes:
#		0 - OK
#		1 - Error
###############################################################
validate_special_properties()
{
	typeset old_value=""
	typeset new_value=""

	ucmmd_running
	if [ $? -ne 0 ]; then
		return 0
	fi

	#  If VALIDATE method is called at the time of adding a resource, 
	#  there is no need to check these special properties.

	resource_configured "${MY_RS}"
	if [ $? -ne 0 ]; then
		return 0
	fi

	for a_property in VXCLUST_PORT VXCLUST_NUM_PORTS VXKMSGD_PORT VXCONFIGD_PORT; do
		case ${a_property} in
			VXCLUST_PORT)
				new_value="${VXCLUST_PORT}"
				;;
			VXCLUST_NUM_PORTS)
				new_value="${VXCLUST_NUM_PORTS}"
				;;
			VXKMSGD_PORT)
				new_value="${VXKMSGD_PORT}"
				;;
			VXCONFIGD_PORT)
				new_value="${VXCONFIGD_PORT}"
				;;
			*) continue;;
		esac

		old_value=$(read_extension_property  -R ${MY_RS} ${a_property})

		if [ "${old_value}" != "${new_value}" ]; then
			# Attempt to modify value of property
			scds_syslog -p notice -t ${SYSLOG_TAG} -m \
		     		"Property %s can be changed only while ucmmd is not running on the node." "${a_property}"
			write_stderr "$(gettext \
		     		"Property %s can be changed only while ucmmd is not running on the node.")" "${a_property}"
			return 1
		fi
	done
	return 0
}

main()
{
        typeset rc=0

        initialize

        read_validate_arguments "${@:-}" || exit $?

	verify_installation || exit $?

	validate_configuration || exit $?

	return $?
}

main "${@:-}"

