#!/bin/ksh -p
#*******************************************************************************
#
# NAME:		rdac_name_delete
# SUMMARY:	%description%
# COMPONENT:	solsysd
# VERSION:	rm6_1
# UPDATE DATE:	%date_modified: Fri May 25 11:15:19 2001 %
# PROGRAMMER:	%created_by:    awilner %
# 
#		Copyright 1998 by Symbios Logic Inc.
#
# DESCRIPTION:
# rdac_name_delete carries out those operations needed for SYMplicity storage manager
# to be able to delete a raid module.  
#
# NOTES:
#
# REFERENCE:
#
# CODING STANDARD WAIVERS:
#
#*******************************************************************************

#*******************************************************************************
# PROCEDURE:	MutexAcquire
# SUMMARY:	get exclusive ownership of mutex file
#
# DESCRIPTION:
# MutexAcquire will try repeatedly to acquire a "mutex file" - success means
# the thread has been admitted to a "critical region"
#
# SYNTAX:
# MutexAcquire <mutex file>
# <mutex file> - name of the mutex guarding the critical region
#
# NOTES:
# MutexAcquire and the program it calls, rm_mutex_acquire, rely on O_CREAT
# semantics
#
# RETURNS:
# Nothing

MutexAcquire()
{
	while true
	do
		$RM_HOME/bin/rm_mutex_acquire $1
		if [ $? = 0 ]
		then
			break;
		fi
		sleep 1
	done;
}

#*******************************************************************************
# PROCEDURE:	MutexRelease
# SUMMARY:	relenquish mutex file ownership
#
# DESCRIPTION:
# MutexRelease releases mutex file ownership, so another thread can enter the
# critical region
#
# SYNTAX:
# MutexRelease <mutex file>
# <mutex file> - name of the mutex guarding the critical region
#
# NOTES:
#
# RETURNS:
# Nothing

MutexRelease()
{
	/bin/rm $1;
}

#*******************************************************************************
# PROCEDURE:	rdac_name_delete (main)
# SUMMARY:	Change RAID Module names in the rdac_address file
#
# DESCRIPTION:
# 
#
# SYNTAX:
# rdac_name_delete Name 
#
# NOTES:
#
# RETURNS:
# 0     - success
# non-0 - failure (currently not returned)


# R D A C _ N A M E _ C H A N G E   M A I N   P R O C E D U R E
#

ADDRESS_FILE="/etc/raid/rdac_address"
CONF_FILE="/kernel/drv/rdriver.conf"
RMPARAMS_FILE=/etc/raid/rmparams
RM_HOME=`grep -v "^#" $RMPARAMS_FILE | grep System_RmHomeDirectory | cut -d= -f2`
RM_BOOT_HOME=`grep -v "^#" $RMPARAMS_FILE | grep System_RmBootHomeDirectory | cut -d= -f2`

ISALIST_EXIST=`which isalist | grep no`
if [ -z "${ISALIST_EXIST}" ]
then
        ISALIST="isalist"
else
        ISALIST="echo not"
fi

NAME=$1

if [ -n "${NAME}" ]
then
	MutexAcquire /tmp/mutex.rdac_name_change	# Begin critical region
	cat $ADDRESS_FILE | grep -v "^${NAME}:" >/tmp/rdac_address.$$
	cp  /tmp/rdac_address.$$ $ADDRESS_FILE
	rm  /tmp/rdac_address.$$
	MutexRelease /tmp/mutex.rdac_name_change	# End of critical region

	MutexAcquire /tmp/mutex.hot_add	# Begin critical region
	cat $CONF_FILE | grep -v "^${NAME}:" >/tmp/rdriver.conf.$$
	cp  /tmp/rdriver.conf.$$ $CONF_FILE
	rm  /tmp/rdriver.conf.$$
	MutexRelease /tmp/mutex.hot_add	# End of critical region
fi

exit 0
