#! /usr/bin/ksh
#
#pragma	ident	"@(#)rac_udlm_validate.ksh	1.6	03/04/15 SMI"
#
# Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
############################################################
#
# SUNW.rac_udlm 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_udlm_lib

validate_configuration()
{
	typeset validate_rc=0
	typeset udlmbin="/opt/SUNWcluster/bin"

	validate_special_properties
	if [ $? -ne 0 ]; then
		validate_rc=1
	fi 
	
	if [ -n "${ORACLE_CONFIG_FILE:-}" ]; then
		if [ ! -f "${ORACLE_CONFIG_FILE}" ]; then
			 scds_syslog -p error -t ${SYSLOG_TAG} -m \
			     "Validation failed. Oracle_config_file %s not found " "${ORACLE_CONFIG_FILE}"
			 write_stderr "$(gettext "Validation failed. Oracle_config_file %s not found ")" "${ORACLE_CONFIG_FILE}"

			validate_rc=1
		fi
	fi

	if [ ! -x ${udlmbin}/lkmgr ]; then
		scds_syslog -p error -t ${SYSLOG_TAG} -m \
		    "The %s file of the Oracle UNIX Distributed Lock Manager not found or is not executable." \
		    "${udlmbin}/lkmgr";

		write_stderr "$(gettext \
		    "The %s file of the Oracle UNIX Distributed Lock Manager not found or is not executable.")" \
		    "${udlmbin}/lkmgr";

		validate_rc=1
        fi

	return $validate_rc
}
###############################################################
# validate_special_properties
#	This function validates properties than shold not be modified
# 	when ucmmd  & UDLM are running on the node.
#
# 	These special properties are used by UDLM to communicate 
#	with UDLM on other nodes. The UDLM can start using these 
#	properties only on node reboot
#
#	However, if UDLM on one node uses new value and UDLM on
#	other nodes are using old value, it can cause panic on node
#	and has potental to bring down all RAC nodes
#
#	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_port=""
	typeset old_num_ports=""

	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


	# Read old value of property
	old_port=$(read_extension_property  -R ${MY_RS} PORT)

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

	old_num_ports=$(read_extension_property  -R ${MY_RS} NUM_PORTS)
	if [ "${old_num_ports}" != "${NUM_PORTS}" ]; then
		# Attempt to modify value of property NUM_PORTS
		scds_syslog -p notice -t ${SYSLOG_TAG} -m \
		     "Property %s can be changed only while UNIX Distributed Lock Manager is not running on the node." "NUM_PORTS"
		write_stderr "$(gettext \
		     "Property %s can be changed only while UNIX Distributed Lock Manager is not running on the node.")" "NUM_PORTS"
		return 1
	fi

	return 0
}

main()
{
        typeset rc=0

        initialize

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

	verify_installation || exit $?

	validate_configuration || exit $?

	return $?
}

main "${@:-}"

