#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2007 
# 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 
# @(#)46 1.13.1.1 src/avs/fs/mmfs/ts/admin/mmlsconfig.sh, mmfs, avs_rgpfs24, rgpfs24s011a 3/28/07 19:15:23
##########################################################################
#
#  List the GPFS configuration data for the cluster.
#
#  Usage:  mmlsconfig [Attribute[,Attribute...] [-Y]
#
##########################################################################

# Include global declarations and service routines
. /usr/lpp/mmfs/bin/mmglobfuncs
. /usr/lpp/mmfs/bin/mmsdrfsdef

sourceFile="mmlsconfig.sh"
[[ -n $DEBUG || -n $DEBUGmmlsconfig ]] && set -x
$mmTRACE_ENTER "$*"

# Local work files.  Names should be of the form:
#   fn=${tmpDir}fn.${mmcmd}.$$

LOCAL_FILES=" "

# Local variables
usageMsg=370
underline="----------------------------------------------------------"
underline="${underline}----------------------------------------------"

typeset -l cfgParm_lc

# Local routines

#############################################################################
#
# Function:  Determine the value of the specified mmfs.cfg parameter.
#
# Input:     $1 - mmfs.cfg parameter name.
#            $2 - default value
#            $3 - mmfs.cfg file to use.
#            $4 - line prefix string (implies colon separated output)
#
# Output:    The value of the mmfs.cfg parameter.  Multiple lines are possible
#            if there are node overrides.
#
# Returns:   0 - worked
#            1 - unexpected error
#
#############################################################################
function listCfgValue  # <parmName> <default> <cfgFile> [<prefix>]
{
  typeset sourceFile="mmlsconfig.sh"
  [[ -n $DEBUG || -n $DEBUGlistCfgValue ]] && set -x
  $mmTRACE_ENTER "$*"
  typeset parm=$1
  typeset defaultValue=$2
  typeset cfgFile=$3
  typeset linePrefix=$4

  typeset separatorChar=" "

  # Verify input parameters.
  if [[ $# -lt 3 ]]
  then
    operands="<parmName> <default> <cfgFile> [<prefix>]"
    printErrorMsg 260 listCfgValue "$operands"
    cleanupAndExit
  fi

  [[ -n $linePrefix ]] && separatorChar=":"

  # Find the setting of the parameter from the specified config file.
  $awk -v parm="$parm" -v defaultValue="$defaultValue" \
       -v sep="$separatorChar" -v prefix="$linePrefix" '
    BEGIN {
      { globalScope = 1 }
      { nodeList = "" }
      { n = 0 }
      { value[0] = defaultValue }
      { nodes[0] = "" }
    }

    # If this is the end of a node-override section,
    # set the flag to accept parameter values.
    $1 == "[common]" {
      { globalScope = 1 }
      { next }
    }

    # If this is the start of a node-override section,
    # save the node list.
    /^\[.*]/ || /^[     ]*\[.*]/ {
      { globalScope = 0 }
      nodeList = $1
      if (prefix) {
        # Remove the brackets.
        sub("\\[","",nodeList)
        sub("]","",nodeList)
      }
      { next }
    }

    # If this is a declaration for our parameter, save the value.
    $1 == parm {
      if (globalScope) {
        { nodeList = "" }
        { n = 0 }
      }
      else {
        { n++ }
      }
      # Add code to save the entire line minus $1
      { value[n] = $2 }
      { nodes[n] = nodeList }
    }

    END {
      # Print the result.
      for (i=0; i<=n; i++) {
        print prefix parm sep value[i] sep nodes[i] sep
      }
    }
  ' $cfgFile
  checkForErrors awk $?

  return 0

}  #----- end of function listCfgValue ---------------------------


#############################
# Check the input arguments.
#############################
[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
  syntaxError "help" $usageMsg

if [[ $arg1 = '-Y' ]]
then
  Yopt=true
  parmList="$arg2"
  [[ -n $arg3 ]] && syntaxError "extraArg"  $usageMsg "$arg3"
else
  parmList="$arg1"
  [[ $arg2 = '-Y' ]] && Yopt=true
  if [[ $arg2 = '-Y' ]]
  then
    Yopt=true
    [[ -n $arg3 ]] && syntaxError "extraArg"  $usageMsg "$arg3"
  else
    [[ -n $arg2 ]] && syntaxError "extraArg"  $usageMsg "$arg2"
  fi
fi  # end of if [[ $arg1 = '-Y' ]]


#######################################################################
# Set up trap exception handling and call the gpfsInit function.
# It will ensure that the local copy of the mmsdrfs and the rest
# of the GPFS system files are up-to-date.  No need to lock the sdr.
#######################################################################
trap pretrap2 HUP INT QUIT KILL
gpfsInitOutput=$(gpfsInit nolock)
setGlobalVar $? $gpfsInitOutput


#################################################################
# Loop through the mmsdrfs file and collect needed information.
#################################################################
$rm -f $tmpfile
IFS=":"         # Change the field separator to ':'
exec 3<&-
exec 3< $mmsdrfsFile
while read -u3 sdrfsLine
do
  # Parse the line.
  set -f ; set -A v -- - $sdrfsLine ; set +f

  IFS="$IFS_sv"    # Restore the default IFS settings.

  case ${v[$LINE_TYPE_Field]} in

    $VERSION_LINE )
       # Extract the cluster name.
       clusterName=${v[$CLUSTER_NAME_Field]}
       ;;

    $SG_HEADR )
       # Collect the names of all local file systems.
       if [[ ${v[$NODESETID_Field]} = $HOME_CLUSTER ]]
       then
         print -- "/dev/${v[$DEV_NAME_Field]}" >> $tmpfile
         checkForErrors "writing to file $tmpfile" $?
       fi
       ;;

    * )  # No need to look at any of the other lines
      ;;

  esac  # end case ${v[$LINE_TYPE_Field]} in

  IFS=":"  # Change the separator back to ":" for the next iteration

done  # end while read -u3

IFS="$IFS_sv"  # Restore the default IFS settings.


# The config information is in the file mmfscfgFile.
# If the traditional default output is desired, display
# the content skipping comment and empty lines.
if [[ -z $parmList && -z $Yopt ]]
then
  header=$(printInfoMsg 407 $clusterName)
  printf "%s\n%.${#header}s\n" "$header" "$underline"

  $egrep -v -e "^([$BLANKchar$TABchar])*#"  \
            -e "^([$BLANKchar$TABchar])*$" $mmfscfgFile

  # Display the names of the locally owned file systems.
  header=$(printInfoMsg 408 $clusterName)
  printf "\n%s\n%.${#header}s\n" "$header" "$underline"
  if [[ -s $tmpfile ]]
  then
    $cat $tmpfile
  else
    # There are no file systems
    printInfoMsg 409
  fi

  cleanupAndExit 0
fi  # end of if [[ -z $parmList && -z $separatorChar ]]


# If we are here, either specific paramters were requested
# and/or colon separated output is desired.
if [[ -n $Yopt ]]
then
  # Generate and print the header line.
  hdrLine="mmlsconfig::HEADER:version:reserved:reserved"
  hdrLine="${hdrLine}:configParameter:value:nodeList"
  print -- "${hdrLine}:"

  # Generate the prefix for the data lines.
  linePrefix="mmlsconfig::0:1:::"
fi  # end of if [[ -n $Yopt ]]

# If no specific parameters were requested, show all
# offciallly supported and documented paramters.
if [[ -z $parmList || $parmList = all ]]
then
  parmList="autoload,automountDir,cipherList,clusterId,clusterName"
  parmList="${parmList},dataStructureDump,distributedTokenServer"
  parmList="${parmList},dmapiEventTimeout,dmapiMountTimeout,dmapiSessionFailureTimeout"
  parmList="${parmList},maxblocksize,maxFilesToCache,maxMBpS,maxStatCache"
  parmList="${parmList},nsdServerWaitTimeForMount,nsdServerWaitTimeWindowOnMount"
  parmList="${parmList},pagepool,prefetchThreads,subnets,uidDomain"
  parmList="${parmList},unmountOnDiskFail,worker1Threads"
fi  # end of if [[ -z $parmList ]]


IFS=","
for cfgParm in $parmList
do
  IFS="$IFS_sv"
  cfgParm_lc=$cfgParm

  case $cfgParm_lc in
    autoload )
      defaultValue="no"; cfgParm=autoload ;;
    allowdummyconnections )
      defaultValue="no"; cfgParm=allowDummyConnections ;;
    allowremoteconnections )
      defaultValue="no"; cfgParm=allowRemoteConnections ;;
    allowsynchronousfcntlretries )
      defaultValue="yes"; cfgParm=allowSynchronousFcntlRetries ;;
    assertonstructureerror )
      defaultValue="no"; cfgParm=assertOnStructureError ;;
    asyncsocketnotify )
      defaultValue="no"; cfgParm=asyncSocketNotify ;;
    automountdir )
      defaultValue="/gpfs/automountdir"; cfgParm=automountDir ;;
    autosgloadbalance )
      defaultValue="no"; cfgParm=autoSgLoadBalance ;;
    cipherlist )
      defaultValue="(undefined)"; cfgParm=cipherList ;;
    clusterid )
      defaultValue="(undefined)"; cfgParm=clusterId ;;
    clustername )
      defaultValue="(undefined)"; cfgParm=clusterName ;;
    crashdump )
      defaultValue="0"; cfgParm=crashdump ;;
    datastructuredump )
      defaultValue="yes"; cfgParm=dataStructureDump ;;
    datastructuredumponsgpanic )
      defaultValue="no"; cfgParm=dataStructureDumpOnSGPanic ;;
    distributedtokenserver )
      defaultValue="yes"; cfgParm=distributedTokenServer ;;
    dmapienable )
      defaultValue="yes"; cfgParm=dmapiEnable ;;
    dmapieventbuffers )
      defaultValue="64"; cfgParm=dmapiEventBuffers ;;
    dmapieventtimeout )
      defaultValue="86400000"; cfgParm=dmapiEventTimeout ;;
    dmapimounttimeout )
      defaultValue="60"; cfgParm=dmapiMountTimeout ;;
    dmapisessionfailuretimeout )
      defaultValue="0"; cfgParm=dmapiSessionFailureTimeout ;;
    dmapiworkerthreads )
      defaultValue="12"; cfgParm=dmapiWorkerThreads ;;
    eewatchdoghungthreadcutoff )
      defaultValue="60"; cfgParm=eeWatchDogHungThreadCutoff ;;
    eewatchdoginterval )
      defaultValue="90"; cfgParm=eeWatchDogInterval ;;
    enableuidremap )
      defaultValue="no"; cfgParm=enableUIDremap ;;
    enablestatuidremap )
      defaultValue="no"; cfgParm=enableStatUIDremap ;;
    enabletreebasedquotas )
      defaultValue="no"; cfgParm=enableTreeBasedQuotas ;;
    envvar )
      defaultValue="(undefined)"; cfgParm=envVar ;;
    flusheddatatarget )
      defaultValue="32"; cfgParm=flushedDataTarget ;;
    flushedinodetarget )
      defaultValue="32"; cfgParm=flushedInodeTarget ;;
    healthcheckinterval )
      defaultValue="0"; cfgParm=healthCheckInterval ;;
    hotlistpct )
      defaultValue="10"; cfgParm=hotlistPct ;;
    ignorereplicaspaceonstat )
      defaultValue="no"; cfgParm=IgnoreReplicaSpaceOnStat ;;
    iohistorysize )
      defaultValue="512"; cfgParm=ioHistorySize ;;
    leasedmstimeout )
      defaultValue="2/3 leaseDuration"; cfgParm=leaseDMSTimeout ;;
    leaseduration )
      defaultValue="35"; cfgParm=leaseDuration ;;
    leaserecoverywait )
      defaultValue="35"; cfgParm=leaseRecoveryWait ;;
    license )
      defaultValue="(undefined)"; cfgParm=LICENSE ;;
    listenonallinterfaces )
      defaultValue="yes"; cfgParm=listenOnAllInterfaces ;;
    maxallocpcttocache )
      defaultValue="0"; cfgParm=maxAllocPctToCache ;;
    maxbackgrounddeletionthreads )
      defaultValue="4"; cfgParm=maxBackgroundDeletionThreads ;;
    maxblocksize )
      defaultValue="1M"; cfgParm=maxblocksize ;;
    maxbufferdescs )
      defaultValue="-1"; cfgParm=maxBufferDescs ;;
    maxdatashippoolsize )
      defaultValue="266240"; cfgParm=maxDataShipPoolSize ;;
    maxdiskaddrbuffs )
      defaultValue="-1"; cfgParm=maxDiskAddrBuffs ;;
    maxfcntlrangesperfile )
      defaultValue="200"; cfgParm=maxFcntlRangesPerFile ;;
    maxfilecleaners )
      defaultValue="8"; cfgParm=maxFileCleaners ;;
    maxfilestocache )
      defaultValue="1000"; cfgParm=maxFilesToCache ;;
    maxinodedeallochistory )
      defaultValue="50"; cfgParm=maxInodeDeallocHistory ;;
    maxinodedeallocprefetch )
      defaultValue="8"; cfgParm=maxInodeDeallocPrefetch ;;
    maxmbps )
      defaultValue="150"; cfgParm=maxMBpS ;;
    maxmissedpingtimeout )
      defaultValue="60"; cfgParm=maxMissedPingTimeout ;;
    maxnfsdelegationtimeout )
      defaultValue="60"; cfgParm=maxNFSDelegationTimeout ;;
    maxreceiverthreads )
      defaultValue="16"; cfgParm=maxReceiverThreads ;;
    maxsgdesciobufsize )
      defaultValue="262144"; cfgParm=maxSGDescIOBufSize ;;
    maxstatcache )
      defaultValue="4*maxFilesToCache"; cfgParm=maxStatCache ;;
    maxtokenservers )
      defaultValue="128"; cfgParm=maxTokenServers ;;
    minmissedpingtimeout )
      defaultValue="8"; cfgParm=minMissedPingTimeout ;;
    minquorumnodes )
      defaultValue="1"; cfgParm=minQuorumNodes ;;
    mmapkprocs )
      defaultValue="3"; cfgParm=mmapKprocs ;;
    mmsdrservtimeout )
      defaultValue="10"; cfgParm=mmsdrservTimeout ;;
    mmsdrservworkerpool )
      defaultValue="10"; cfgParm=mmsdrservWorkerPool ;;
    multitmmountthreshold )
      defaultValue="2"; cfgParm=multiTMMountThreshold ;;
    nfsprefetchstrategy )
      defaultValue="0"; cfgParm=nfsPrefetchStrategy ;;
    nsdbufspace )
      defaultValue="30"; cfgParm=nsdbufspace ;;
    nsdinlinewritemax )
      defaultValue="1024"; cfgParm=nsdInlineWriteMax ;;
    nsdmaxworkerthreads )
      defaultValue="32"; cfgParm=nsdMaxWorkerThreads ;;
    nsdminworkerthreads )
      defaultValue="8"; cfgParm=nsdMinWorkerThreads ;;
    nsdservercheckingintervalformount )
      defaultValue="10"; cfgParm=nsdServerCheckingIntervalForMount ;;
    nsdserverwaitconfig )
      defaultValue="2"; cfgParm=nsdServerWaitConfig ;;
    nsdserverwaittimeformount )
      defaultValue="300"; cfgParm=nsdServerWaitTimeForMount ;;
    nsdserverwaittimewindowonmount )
      defaultValue="600"; cfgParm=nsdServerWaitTimeWindowOnMount ;;
    nsdthreadsperdisk )
      defaultValue="3"; cfgParm=nsdThreadsPerDisk ;;
    opensslenginename )
      defaultValue="(undefined)"; cfgParm=opensslEngineName ;;
    openssllibname )
      defaultValue="(undefined)"; cfgParm=openssllibname ;;
    pagepool )
      defaultValue="64M"; cfgParm=pagepool ;;
    panicondiskfail )
      defaultValue="no"; cfgParm=unmountOnDiskFail ;;
    pcttokenmgrstorageuse )
      defaultValue="25"; cfgParm=pctTokenMgrStorageUse ;;
    pindaemon )
      defaultValue="no"; cfgParm=pindaemon ;;
    pingperiod )
      defaultValue="2"; cfgParm=pingPeriod ;;
    pinmaster )
      defaultValue="stack 256K data 4096K"; cfgParm=pinmaster ;;
    prefetchpct )
      defaultValue="20"; cfgParm=prefetchPct ;;
    prefetchthreads )
      defaultValue="72"; cfgParm=prefetchThreads ;;
    prefetchtimeout )
      defaultValue="5"; cfgParm=prefetchTimeout ;;
    priority )
      defaultValue="40"; cfgParm=priority ;;
    readreplicapolicy )
      defaultValue="default"; cfgParm=readReplicaPolicy ;;
    res )
      defaultValue="(undefined)"; cfgParm=res ;;
    retryfcntltokenthreshold )
      defaultValue="3"; cfgParm=retryFcntlTokenThreshold ;;
    seqdiscardthreshhold )
      defaultValue="1M"; cfgParm=seqDiscardThreshhold ;;
    setctimeonattrchange )
      defaultValue="yes"; cfgParm=setCtimeOnAttrChange ;;
    sharedmemlimit )
      defaultValue="0"; cfgParm=sharedMemLimit ;;
    socketrcvbuffersize )
      defaultValue="0"; cfgParm=socketRcvBufferSize ;;
    socketsndbuffersize )
      defaultValue="0"; cfgParm=socketSndBufferSize ;;
    statcachedirpct )
      defaultValue="10"; cfgParm=statCacheDirPct ;;
    statmaxattrage )
      defaultValue="0"; cfgParm=statMaxAttrAge ;;
    subnets )
      defaultValue="(undefined)"; cfgParm=subnets ;;
    syncinterval )
      defaultValue="70"; cfgParm=syncInterval ;;
    takeovertimeout )
      defaultValue="600"; cfgParm=takeovertimeout ;;
    tokenmemlimit )
      defaultValue="256M"; cfgParm=tokenMemLimit ;;
    totalpingtimeout )
      defaultValue="120"; cfgParm=totalPingTimeout ;;
    trace )
      defaultValue="all 0"; cfgParm=trace ;;
    tracebuffersizeforaix )
      defaultValue="(undefined)"; cfgParm=traceBufferSizeForAIX ;;
    tracedevbuffersize )
      defaultValue="(undefined)"; cfgParm=tracedevBufferSize ;;
    tracegendump )
      defaultValue="(undefined)"; cfgParm=traceGenDump ;;
    tracegensubdir )
      defaultValue="(undefined)"; cfgParm=traceGenSubDir ;;
    tracefilesize )
      defaultValue="(undefined)"; cfgParm=traceFileSize ;;
    tracelogquiet )
      defaultValue="(undefined)"; cfgParm=traceLogQuiet ;;
    tracerecycle )
      defaultValue="(undefined)"; cfgParm=traceRecycle ;;
    tscprimary )
      defaultValue="255.255.255.255"; cfgParm=tscPrimary ;;
    tscworkerpool )
      defaultValue="10"; cfgParm=tscWorkerPool ;;
    udaplrdma )
      defaultValue="disable"; cfgParm=udaplRdma ;;
    udaplports )
      defaultValue="(undefined)"; cfgParm=udaplPorts ;;
    udaplrdmaspernode )
      defaultValue="(undefined)"; cfgParm=udaplRdmasPerNode ;;
    udaplrdmasperconnection )
      defaultValue="(undefined)"; cfgParm=udaplRdmasPerConnection ;;
    udaplrdmaminbytes )
      defaultValue="16384"; cfgParm=udaplRdmasMinBytes ;;
    verbsrdma )
      defaultValue="disable"; cfgParm=verbsRdma ;;
    verbsports )
      defaultValue="(undefined)"; cfgParm=verbsPorts ;;
    verbsrdmaspernode )
      defaultValue="(undefined)"; cfgParm=verbsRdmasPerNode ;;
    verbsrdmasperconnection )
      defaultValue="(undefined)"; cfgParm=verbsRdmasPerConnection ;;
    verbsrdmaminbytes )
      defaultValue="16384"; cfgParm=verbsRdmasMinBytes ;;
    uiddomain )
      defaultValue="(undefined)"; cfgParm=uidDomain ;;
    uidexpiration )
      defaultValue="36000"; cfgParm=uidExpiration ;;
    unmountondiskfail )
      defaultValue="no"; cfgParm=unmountOnDiskFail ;;
    wait4rvsd )
      defaultValue="no"; cfgParm=wait4RVSD ;;
    waitforvsd )
      defaultValue="no"; cfgParm=wait4RVSD ;;
    watchdogtimeout )
      defaultValue="20"; cfgParm=watchdogtimeout ;;
    worker1threads )
      defaultValue="48"; cfgParm=worker1Threads ;;
    worker3threads )
      defaultValue="8"; cfgParm=worker3Threads ;;
    writealldescreplicas )
      defaultValue="no"; cfgParm=writeAllDescReplicas ;;
    writebehindthreshhold )
      defaultValue="512K"; cfgParm=writebehindThreshhold ;;
    * )
      defaultValue="(undefined)"; cfgParm="$cfgParm" ;;

  esac  # end of case $cfgParm_lc in

  # Invoke the function to retrieve and display the data.
  listCfgValue "$cfgParm" "$defaultValue" $mmfscfgFile $linePrefix

done  # end of for cfgParm in $parmList

cleanupAndExit 0

