#!/bin/sh

#ident "$script: configure-lvm Build 5.81.0.5 06/08/30 12:00:00 $"

#----------------------------------------------------------------------------#
# PRODUCT :  HDLM Driver 0540                                                #
#----------------------------------------------------------------------------#
# NAME :     configure-lvm                                                   #
# FUNCTION : To initialize lvm for HDLM                                      #
# INSTANCE :                                                                 #
# MEMO :                                                                     #
# DATE :     2004/06/19                                                      #
# AUTHOR :   Sandhya Suman                                          	     #
# HISTORY :                                                                  #
#                                                                            #
#@ All Rights Reserved, Copyright (C) 2004, 2006 Hitachi, Ltd.                     #
#----------------------------------------------------------------------------#

# REVAMP ACTIVITY PERFORMED. SO ALL PREVIOUS FDOCS & COMMENTS ARE REMOVED. PLEASE LOOKUP 
# PREVIOUS VERSIONS CODES FOR REFERENCE.

# This script is called from /etc/rc.d/rc.sysinit.
# This script will not run individually from command line
# because it requires a prior sourcing of /etc/rc.d/init.d/functions in the same
# shell.

#Using common-defines for command variable declaration
if [ -f /etc/redhat-release ]; then
    if [ -f /etc/sysconfig/hdlm-scripts/common-defines ]; then
	    . /etc/sysconfig/hdlm-scripts/common-defines
    else
	    failure $"Attempting to source /etc/sysconfig/hdlm-scripts/common-defines: "
	    return
    fi
fi

#############################
# Kernel and HDLM version check start
#############################
if [ "$HDLM_COMMON_RESULT" != "SUPPORT" ]; then
	return
fi
#############################
# Kernel and HDLM version check end
#############################

MDLIST=""
TMPMDLIST=""
RAIDTAB=/etc/raidtab
MDENABLE=1

if [ -f /etc/redhat-release ]; then

	RH_AS3_STRING="Red Hat Enterprise Linux AS release 3"
	RH_ES3_STRING="Red Hat Enterprise Linux ES release 3"
	RH_AS4_STRING="Red Hat Enterprise Linux AS release 4"
	RH_ES4_STRING="Red Hat Enterprise Linux ES release 4"

	$CMD_GREP -q -e "$RH_AS3_STRING" -e "$RH_ES3_STRING" -e "$RH_AS4_STRING" -e "$RH_ES4_STRING" /etc/redhat-release > /dev/null 2>&1
	if [ "$?" = "0" ]; then

		#######################################################################
		#TO GET THE LIST OF MDS START                                         #  
		#######################################################################
		if [ -s $RAIDTAB ] ; then
		MDCOUNT=`$CMD_GREP -c "^[ 	]*raiddev" $RAIDTAB`
	      if [ $MDCOUNT -ne 0 ]; then 
			while read line; do 
				$CMD_ECHO $line | $CMD_GREP "^[ 	]*raiddev" > /dev/null 2>&1
		     		if [ $? -eq 0 ]; then
		  			TMPMDLIST=`$CMD_ECHO $line | $CMD_GREP "^[   ]*raiddev" | $CMD_GAWK '{print $2}'` 
	        			STATUS_FLAG=TRUE
	        		fi
	        		if [ "$STATUS_FLAG" != "FALSE" ]; then
					$CMD_ECHO $line | $CMD_GREP "^[     ]*device" |  $CMD_GREP "sddlm[a-p][a-p]" > /dev/null 2>&1 
		        		if [ $? -eq 0 ]; then  
	      	  			MDLIST="$MDLIST $TMPMDLIST"
		        			TMPMDLIST=" "
						STATUS_FLAG=FALSE  
		        		fi
		        	fi
			done < $RAIDTAB
	  	fi #end of MDCOUNT
            fi #End of raidtab

		#######################################################################
		#TO GET THE LIST OF MDS END                                           #  
		#######################################################################

		MDENABLE=0 #for AS3 the MDENABLE Flag is Reset and Set again if raidstart passes for any one MD
	
		if [ -f /proc/mdstat -a -x /sbin/raidstart ]; then
		
			
			for i in $MDLIST
			do
		      	INFSTAB=`LC_ALL=C $CMD_GREP -c "^$i" /etc/fstab`
				if [ $INFSTAB -eq 0 ] ; then
					/sbin/raidstart $i 
					if [ "$?" -eq 0 ] ; then
					  MDENABLE=1
					fi  
				fi
			done

			
		fi
		
	fi #AS 3 check

	if [ $MDENABLE -eq 1 ] ; then 
		# LVM initialization...start
		$CMD_GREP -q -e "$RH_AS4_STRING" -e "$RH_ES4_STRING" /etc/redhat-release > /dev/null 2>&1
		if [ "$?" = "0" ]; then
			/sbin/lvm.static vgchange -a n && /sbin/lvm.static vgscan > /dev/null 2>&1 && /sbin/lvm.static vgchange -a y
		elif [ -e /proc/lvm -a -x $CMD_VGCHANGE -a -f /etc/lvmtab ]; then
		        $CMD_VGCHANGE -a n && $CMD_VGSCAN >/dev/null 2>&1 && $CMD_VGCHANGE -a y 
		fi
		# LVM initialization...end
	fi

fi # REDHAT Release check
