#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/events/utils/cl_smm_ochk.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2013 
# 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 
# @(#)66       1.2 src/43haes/usr/sbin/cluster/events/utils/cl_smm_ochk.sh, hacmp.utils, 61haes_r714 5/1/13 09:49:44
################################################################################
#
#   Name:       cl_smm_ochk
#
#   Function:   Checks to see if the 'manual' option for storage subsystem 
#               recovery has been overriden by a prior choice of 'continue'
#               in response to a split.
#
#               This function is encapsulated in this routine to avoid having
#               similar logic scattered through the various storage subsystem
#               routines.
#
#               There are two parts to this test:
#               1.  Split/merge policies have been configured so that a manual
#                   response to a split or merge applies to a subsequent choice
#                   for storage subsystem recovery.
#               2.  On a split, the manual response indicated that this 
#                   partition should continue.
#
#   Notes:      The expected use of this function is:
#                   if /usr/es/sbin/cluster/events/utils/cl_smm_ochk
#                   then
#                       #
#                       :   Perform Automatic Recovery
#                       #
#                   else
#                       #
#                       :   Perform Manual Recovery
#                       #
#                   fi
#
#               The implementation in this routine depends on the fact that 
#               'manual' is an allowed policy on split or merge only for linked
#               clusters, and hence the partitions of the clusters correspond
#               to PowerHA sites.
#
#
#   Input:      *   Configuration choices in HACMPsplitmerge
#               *   Presence/absence of tracking file /usr/es/sbin/cluster/etc/smm_oflag
#                   normally created by cl_sm_continue
#
#
#   Output:     return code = 0 - 'manual' storage subsystem recovery has been
#                                 overriden; storage subsystem recovery should
#                                 proceed as though 'automatic' had been 
#                                 configured.
#               return code = 1 - 'manual' storage subsystem recover has not been
#                                 overridden; manual recovery of the storage 
#                                 subsystem is required.
#
#
#################################################################################


PATH=$(/usr/es/sbin/cluster/utilities/cl_get_path all)
. /usr/es/sbin/cluster/etc/ha_odm_constants
if [[ $VERBOSE_LOGGING == 'high' ]]
then
    set -x
    version='1.1'
fi

#
:   Setup the log file - typically /var/hacmp/log/clutils.log
#
DEFAULT_LOG_DIR="/var/hacmp/log"

clutils_log_dir=$(/usr/es/sbin/cluster/utilities/clodmget -q "name = clutils.log" -f value -n HACMPlogs)

if [[ -z $clutils_log_dir ]]
then
    clutils_log_dir=$(/usr/es/sbin/cluster/utilities/clodmget -q "name = clutils.log" -f defaultdir -n HACMPlogs)
fi

if [[ -n $clutils_log_dir ]]
then
    clutils_log_file=${clutils_log_dir}/clutils.log
else
    clutils_log_file=${DEFAULT_LOG_DIR}/clutils.log
fi

#
:   Check to see if the current active PowerHA configuration calls for a manual
:   choice on split merge to override MANUAL recovery at the storage replication
:   level.
#
if [[ -s ${ACD}/HACMPsplitmerge ]]
then
    srr_action=$(ODMDIR=${ACD} clodmget -q "policy = storage_recovery" -f value -n HACMPsplitmerge)
    if [[ -z $srr_action || $srr_action == 'N' ]]
    then
        return 1                #   No override choice configured
    fi
else
    return 1                    #   No override choice configured
fi

#
:   At this point, we know that the storage recovery option was set to 'yes'.
:   Now, check to see if a split has happened.
#
if [[ -f /usr/es/sbin/cluster/etc/smm_oflag ]]
then
    #
    :   Manual choice to continue was specified
    #
    print "$(date) ${PROGNAME}[$LINENO]: Split merge manual choice overrides manual storage system recovery" >> $clutils_log_file
    return 0
else
    return 1                    #   No manual choice to continue
fi
