#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2019,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r721 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_file_system_attributes.sh 1.18 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2011,2016 # 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 # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_file_system_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_get_file_system_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect file system information. This function invokes # the C-SPOC utility, "cl_ls_cglvfs", if needed, and mines # its output for all relevant volume group data. If the # cl_ls_cglvfs data has already been collected, however, the # function will used the cached data instead. # # Inputs: See the "devDoc()" function at the bottom of this file. # # Outputs: The properties hash is populated. The only other outputs are # any error messages that might be needed. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function at the bottom of this file for # the standard return code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_get_file_system_attributes { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_file_system_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset fsnames=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then fsnames= typeset -n properties=$1 else typeset -n properties=$2 fi [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== for k in ${!properties[*]}; do unset properties[$k]; done typeset fsname="" value= LVM_DATA="" key= LINE= PAIR= typeset -i INDEX=1 rc=$RC_SUCCESS matches=0 try=0 tries=5 i=0 typeset -u attr= typeset -A queries typeset TEMPDATAFILE="$TMPDIR/clmgr.cl_ls_vglvfs.data.$$" typeset TEMPERRFILE="$TMPDIR/clmgr.cl_ls_vglvfs.err.$$" integer CLEANUP=0 cmd_rc=$RC_UNKNOWN #=================================================== : Check for any specified attribute=value pairs. : If any are found, use those to query the output. #=================================================== while (( $# > 0 )); do value="$1" if [[ $value == *=* ]]; then attr=${value%%=*} # "attr" makes this uppercase queries[$attr]="${value#*=}" fi shift done # : If this is for a snapshot report, we cannot use many of the standard : commands. Like cl_ls_vglvfs, which calls cl_lsvg, among others, which : queries the live cluster environment, and NOT the snapshot data. so : instead we glean what we can from the snapshot itself then return. # CL_SNAPSHOT is exported from the caller. # if [[ -n $CL_SNAPSHOT ]] then if [[ -z $SNAPSHOTPATH || ! -d $SNAPSHOTPATH ]]; then SNAPSHOTPATH=/usr/es/sbin/cluster/snapshots fi if [[ -s $SNAPSHOTPATH/$CL_SNAPSHOT.odm ]] then # # NOTE: this path is invoked from the KLIB_HACMP_view_report code, # which sets the snapshot being reported on. It also invokes # the KLIB_HACMP_get_cluster_attributes code, just like the # graphical cluster report command does, which takes # responsibility for converting the snapshot to temporary # ODMs, and sets ODMDIR to point to that location (so we # don't need to worry about doing any of that here). # : The only way to tell what file systems were being managed by the : cluster at the time a snapshot was take is to look inside of the : HACMPresource ODM that was restored from the snapshot. # typeset rgname="" FS_VG="" LV="" for rgname in $(clodmget -f group -n HACMPresource | sort -u) do FS_VG=$(clodmget -f value -n -q "group=$rgname AND name=VOLUME_GROUP" HACMPresource) for fsname in $(clodmget -f value -n -q "group=$rgname AND name=FILESYSTEM" HACMPresource) do properties[NAME$INDEX]=$fsname properties[RESOURCE_GROUP$INDEX]=$rgname properties[NODES$INDEX]=$(clodmget -f nodes -n -q "group=${properties[RESOURCE_GROUP$INDEX]}" HACMPgroup | tr ' ' ',') properties[NODES$INDEX]=${properties[NODES$INDEX]%,} properties[VOLUME_GROUP$INDEX]=$FS_VG (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) done done else cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 127 '\nERROR: the specified snapshot, "%1$s", could not be found.\n\n' "$CL_SNAPSHOT" 1>&2 rc=$RC_ERROR fi log_return_msg "$rc" "$0()" "$LINENO" return $? fi #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then rc=$RC_MISSING_DEPENDENCY #======================================= : Make sure we have something to query #======================================= elif [[ -n $fsnames ]]; then if [[ -z $LVM_DATA ]]; then if [[ ! -f $TEMPDATAFILE ]]; then typeset nodes=$(clnodename -c) [[ -n $LV_VG ]] && LV_VG=" -v $LV_VG" print "$0()[$LINENO]($SECONDS): cl_ls_vglvfs -cspoc \"-n ${nodes//:/,}\" -r$LV_VG" >>$CLMGR_TMPLOG # Always log commands cl_ls_vglvfs -cspoc "-n ${nodes//:/,}" -r$LV_VG >$TEMPDATAFILE 2>$TEMPERRFILE cmd_rc=$? print "$0()[$LINENO]($SECONDS): cl_ls_vglvfs RC: $cmd_rc" >>$CLMGR_TMPLOG [[ -s $TEMPERRFILE ]] && cat $TEMPERRFILE >>$CLMGR_TMPLOG CLEANUP=1 else cmd_rc=$RC_SUCCESS fi if (( cmd_rc == RC_SUCCESS )); then if (( CLEANUP )); then LVM_DATA=$(cat $TEMPDATAFILE) rm -f $TEMPDATAFILE elif [[ -n $LV_VG ]]; then LVM_DATA=$(grep -p "VG:$LV_VG:" $TEMPDATAFILE) else LVM_DATA=$(cat $TEMPDATAFILE) fi else dspmsg -s $CLMGR_SET $CLMGR_MSGS 469 "\nERROR: unable to collect the needed LVM information.\n\n" 1>&2 [[ -f $TEMPERRFILE ]] && cat $TEMPERRFILE 1>&2 rc=$RC_ERROR fi (( CLEANUP )) && rm -f $TEMPERRFILE fi if [[ -n $LVM_DATA ]]; then typeset -i ALL_FOUND=1 for fsname in ${fsnames//,/ }; do typeset -i FOUND=0 print -- "$LVM_DATA" |\ while read LINE; do if [[ $LINE == FS:$fsname:* ]]; then FOUND=1 break fi done if (( FOUND )); then FSS="$FSS $fsname" else unset FSS ALL_FOUND=0 break fi done if (( ! ALL_FOUND )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$fsname" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 145 'Available File Systems:\n\n' 1>&2 print -- "$LVM_DATA" |\ while read LINE; do [[ $LINE != FS:* ]] && continue LINE=${LINE#FS:} print -u2 "\t${LINE%%:*}" done print -u2 "" rc=$RC_NOT_FOUND break fi fi elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then if [[ -z $LVM_DATA ]]; then if [[ ! -f $TEMPDATAFILE ]]; then typeset nodes=$(clnodename -c) print "$0()[$LINENO]($SECONDS): cl_ls_vglvfs -cspoc \"-n ${nodes//:/,}\" -r" >>$CLMGR_TMPLOG # Always log commands cl_ls_vglvfs -cspoc "-n ${nodes//:/,}" -r >$TEMPDATAFILE 2>$TEMPERRFILE cmd_rc=$? print "$0()[$LINENO]($SECONDS): cl_ls_vglvfs RC: $cmd_rc" >>$CLMGR_TMPLOG # Always log results [[ -f $TEMPERRFILE && -s $TEMPERRFILE ]] && cat $TEMPERRFILE >>$CLMGR_TMPLOG CLEANUP=1 else cmd_rc=$RC_SUCCESS fi if (( cmd_rc == RC_SUCCESS )); then if (( CLEANUP )); then LVM_DATA=$(cat $TEMPDATAFILE) rm -f $TEMPDATAFILE elif [[ -n $LV_VG ]]; then LVM_DATA=$(grep -p "VG:$LV_VG:" $TEMPDATAFILE) else LVM_DATA=$(cat $TEMPDATAFILE) fi else dspmsg -s $CLMGR_SET $CLMGR_MSGS 469 "\nERROR: unable to collect the needed LVM information.\n\n" 1>&2 [[ -f $TEMPERRFILE ]] && cat $TEMPERRFILE 1>&2 rc=$RC_ERROR fi (( CLEANUP )) && rm -f $TEMPERRFILE fi print -- "$LVM_DATA" | grep "^FS:" |\ while IFS=: read rest fsname rest; do FSS="$FSS $fsname" done else dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT fi (( $rc != RC_SUCCESS )) && unset FSS #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for fsname in $FSS; do print -- "$LVM_DATA" | grep -p "FS:$fsname:" |\ while read -r LINE; do if [[ $LINE == LV:* && -z ${properties[LOGICAL_VOLUME$INDEX]} ]] then LV=${LINE#*:} LV=${LV%%:*} LINE=${LINE##*MOUNT_POINT=\"} LVMP=${LINE%%\"*} [[ $LVMP == $fsname ]] && properties[LOGICAL_VOLUME$INDEX]=$LV fi [[ $LINE != FS:$fsname:* ]] && continue LINE=${LINE#*:} # Remove the object type from LINE. LINE=${LINE#*:} # Remove the object name from LINE. LINE=${LINE// /\} # Preserve embedded spaces! properties[NAME$INDEX]=$fsname for PAIR in ${LINE//:/ }; do VAR=${PAIR%%=*} VAR=${VAR%_\?} VAL=${PAIR#*\"}; VAL=${VAL%\"} VAL=${VAL//\/ } if [[ $VAR == @(PP)* ]]; then VAL=${VAL% @(mega|kilo|giga)byte\(s\)} fi case $VAR in BLOCKSIZE) properties[BLOCK_SIZE$INDEX]=$VAL ;; EAFORMAT) properties[EXT_ATTR_FORMAT$INDEX]=$VAL ;; QUOTA) properties[ENABLE_QUOTA_MGMT$INDEX]=$VAL ;; ACCT) properties[DISK_ACCOUNTING$INDEX]=$VAL ;; INLINELOGSZ) properties[INLINE_LOG_SIZE$INDEX]=$VAL ;; LOGLV) properties[LV_FOR_LOG$INDEX]=$VAL ;; MOUNTOPTIONS) properties[OPTIONS$INDEX]=$VAL ;; FRAGSIZE) properties[FRAGMENT_SIZE$INDEX]=$VAL ;; NBPI) properties[BYTES_PER_INODE$INDEX]=$VAL ;; AGSIZE) properties[ALLOC_GROUP_SIZE$INDEX]=$VAL ;; RESOURCE_GROUP) [[ $VAL == \<* ]] && VAL="" properties[RESOURCE_GROUP$INDEX]=$VAL ;; *) properties[$VAR$INDEX]=$VAL ;; esac done rc=$RC_SUCCESS break done #============================================================== : Even if there is no value for a given attribute, we want to : display a placeholder for it, so the customer always sees a : consistent, complete set of attributes. #============================================================== for key in ${_COLON_ATTR_ORDER[file_system]}; do [[ $key == @(FILE|SIZE|FILES) ]] && continue if [[ -z ${properties[$key$INDEX]} ]]; then properties[$key$INDEX]="" fi done #============================================================== : Remove certain values from display, that are not applicable : to the current file system type. #============================================================== if [[ ${properties[TYPE$INDEX]} == @(S|C|L)* ]]; then for attr in INLINE_LOG INLINE_LOG_SIZE EXT_ATTR_FORMAT \ ENABLE_QUOTA_MGMT EFS MOUNTGUARD BLOCK_SIZE do unset properties[$attr$INDEX] done elif [[ ${properties[TYPE$INDEX]} == E* ]]; then for attr in DISK_ACCOUNTING FRAGMENT_SIZE BYTES_PER_INODE \ ALLOC_GROUP_SIZE do unset properties[$attr$INDEX] done fi (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) done #========================================================== : If any searches/filters were specified, handle them now #========================================================== if (( $rc == RC_SUCCESS && ${#queries[*]} > 0 )); then CL=$LINENO search_properties queries properties rc=$? fi (( $rc == RC_SUCCESS )) && CL=$LINENO prune_indexes properties log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_get_file_system_attributes()" #============================================================================ # # Name: devDoc # # Description: This is a never-to-be-called, wrapper function that all the # clmgr FPATH functions implement in order to hide embedded # syntax from trace logging. This information is implemented # in POD format, and can be viewed in a number of ways using # POD tools. Some viewing suggestions for this function's POD- # formatted information are: # # perldoc # pod2text -c # pod2text -c --code # pod2html # # However, the more important use for this information is that # it is parsed by clmgr to display the syntax for this file's # operation. The information in the "SYNOPSIS" section is used # for this purpose. This feature was originally implemented # using the man page information. However, in a code review it # was pointed out that this approach had to be changed because # customers do not have to install the man pages! Therefore, a # built-in dependency on man page information would break the # automatic help feature of clmgr. So the SYNPOSIS section must # be used instead. # # IMPORTANT: As a result of this, it is imperative that the # information in this SYNOPSIS be kept in sync # with the man page information, which is owned # by the IDD team. # # Inputs: None. # # Outputs: None. # # Returns: n/a (not intended to be invoked) # #============================================================================ function devDoc { : <<'=cut' >/dev/null 2>&1 =head1 NAME KLIB_HACMP_get_file_system_attributes =head1 SYNOPSIS clmgr query file_system [,,,...] clmgr -v query file_system NOTE: the alias for "file_system" is "fs". =head1 DESCRIPTION Retrieves the configuration data for one or more volume groups. =head1 ARGUMENTS 1. fsnames [REQUIRED] [string] The label of one or more volume groups (comma or space separated) that are to be queried. 2. properties [REQUIRED] [hash ref] An associative array within which data about the queried objects can be returned to the caller. =head1 RETURN 0: no errors were detected; the operation appears to have been successful 1: a general error has occurred 2: a specified resource does not exist, or could not be found 3: some required input was missing 4: some detected input was incorrect in some way 5: a required dependency does not exist 6: a specified search failed to match any data =cut } # End of "devDoc()" #============================================================================== # The following, comment block attempts to enforce coding standards when this # file is edited via emacs or vim. This block _must_ appear at the very end # of the file, or the editor will not find it, and it will be ignored. #============================================================================== # Local Variables: # indent-tabs-mode: nil # tab-width: 4 # End: #============================================================================== # vim: tabstop=4 shiftwidth=4 expandtab #==============================================================================