#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2019,2020,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r720 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_volume_group_attributes.sh 1.23 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2010,2015 # 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 # @(#) e978906 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_volume_group_attributes.sh, 726, 2147A_aha726, Mar 16 2021 11:29 PM #============================================================================ # # Name: KLIB_HACMP_get_volume_group_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect volume group 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_volume_group_attributes { . $HALIBROOT/log_entry "$0()" "$CL" : INPUTS: $* typeset vgnames=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then vgnames= typeset -n properties=$1 shift else typeset -n properties=$2 shift; shift fi typeset -l FAST=${1//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== for k in ${!properties[*]}; do unset properties[$k]; done typeset vgname="" value="" VGS="" rg="" nodelist="" rest="" LINE="" LVM_DATA="" typeset -i INDEX=1 i=0 matches=0 VRltg=0 MaxPPsVG=0 MaxLVs=0 rc=$RC_SUCCESS typeset -u attr="" typeset -l lc_val="" 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 [[ $attr == "FAST" ]] && continue 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). # typeset vgname="" for vgname in $(clodmget -q "name=VOLUME_GROUP" -n -f value HACMPresource) do properties[NAME$INDEX]=$vgname properties[RESOURCE_GROUP$INDEX]=$(clodmget -f group -n -q "value=$vgname AND name=VOLUME_GROUP" HACMPresource) if [[ -n ${properties[RESOURCE_GROUP$INDEX]} ]] then properties[NODES$INDEX]=$(clodmget -f nodes -n -q "group=${properties[RESOURCE_GROUP$INDEX]}" HACMPgroup | tr ' ' ',') properties[NODES$INDEX]=${properties[NODES$INDEX]%,} fi typeset preferred_read=$(clodmget -f value -n -q "volume_group=$vgname AND name=LVM_PREFERRED_READ" HACMPvolumegroup) if [[ $preferred_read == *([[:space:]]) ]] then preferred_read="roundrobin" fi properties[LVM_PREFERRED_READ$INDEX]=$preferred_read (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) done # End of populating the properties array 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 $vgnames ]]; then # lvm data is collected in a file and ultimately stored in LVM_DATA if [[ -z $LVM_DATA ]]; then typeset vOpt="" [[ $vgnames != *@(,| )* ]] && vOpt=" -v $vgnames" if [[ ! -f $TEMPDATAFILE ]]; then typeset nodes=$(clnodename -c) print -- "$0()[$LINENO]($SECONDS): cl_ls_vglvfs -cspoc \"-n ${nodes//:/,}\" -r$vOpt" >>$CLMGR_TMPLOG # Always log commands cl_ls_vglvfs -cspoc "-n ${nodes//:/,}" -r$vOpt >$TEMPDATAFILE 2>$TEMPERRFILE cmd_rc=$? print -- "$0()[$LINENO]($SECONDS): cl_ls_vglvfs RC: $cmd_rc" >>$CLMGR_TMPLOG # Always log results [[ -s $TEMPERRFILE ]] && cat $TEMPERRFILE >>$CLMGR_TMPLOG CLEANUP=1 else cmd_rc=$RC_SUCCESS fi if (( cmd_rc == RC_SUCCESS )); then # now bring it into a local variable LVM_DATA=$(cat $TEMPDATAFILE) if [[ -z $LVM_DATA ]] then # dont have data for this one - list the ones we know about dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 "\nERROR: \"%1\$s\" does not appear to exist!\n\n" "$vgnames" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 160 "Available Volume Groups:\n\n" 1>&2 typeset -A available CL=$LINENO KLIB_HACMP_list_volume_groups available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done rc=$RC_NOT_FOUND fi (( CLEANUP )) && rm -f $TEMPDATAFILE 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 # we got data - carve out node and rg info for each vg typeset -i ALL_FOUND=1 for vgname in ${vgnames//,/ }; do typeset -i FOUND=0 print -- "$LVM_DATA" |\ while read LINE; do if [[ $LINE == VG:$vgname:* ]]; then print -- "$LINE" | IFS=: read rest rest nodelist rg rest nodelist=${nodelist#*\"} nodelist=${nodelist%\"} rg=${rg#*\"} rg=${rg%\"} [[ $rg != *\<* ]] && vgrgs[$vgname]=$rg vgnodes[$vgname]=$nodelist FOUND=1 break fi done if (( FOUND )); then VGS="$VGS $vgname" else unset VGS ALL_FOUND=0 break fi done if (( ! ALL_FOUND )); then # loop above should have found all specified vgs - list the # ones we know about dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$vgname" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 160 'Available Volume Groups:\n\n' 1>&2 print -- "$LVM_DATA" |\ while read LINE; do [[ $LINE != VG:* ]] && continue LINE=${LINE#VG:} print -u2 "\t${LINE%%:*}" done print -u2 "" rc=$RC_NOT_FOUND break fi fi elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then # no names were specified, but we want to respond to "generic" queries, # and in verbose mode if [[ -z $LVM_DATA ]]; then # harvest the data to a file 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 [[ -s $TEMPERRFILE ]] && cat $TEMPERRFILE >>$CLMGR_TMPLOG CLEANUP=1 else cmd_rc=$RC_SUCCESS fi if (( cmd_rc == RC_SUCCESS )); then LVM_DATA=$(cat $TEMPDATAFILE) (( CLEANUP )) && rm -f $TEMPDATAFILE 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 # lvm data was captured in a file and read to a local variable - carve # out node and rg for all vgs print -- "$LVM_DATA" | grep "^VG:" |\ while IFS=: read rest vgname nodelist rg rest; do VGS="$VGS $vgname" nodelist=${nodelist#*\"} nodelist=${nodelist%\"} rg=${rg#*\"} rg=${rg%\"} [[ $rg != *\<* ]] && vgrgs[$vgname]=$rg vgnodes[$vgname]=$nodelist done else # no name given and we are not in verbose or generic query mode 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 VGS if [[ $VGS == *([[:space:]]) ]]; then log_return_msg "$rc" "$0()" "$LINENO" return $? fi #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for vgname in $VGS; do print -- "$LVM_DATA" |\ while read -r LINE; do [[ $LINE != VG:$vgname:* ]] && 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]=$vgname : Find out if the volume group is SCSI persistent reserve type 7H capbale clpr_verifycap_vg $vgname 2>>$CLMGR_TMPLOG typeset -i rc_cap=$? if (( $rc_cap == 0 ));then properties[SCSIPR_CAPABLE$INDEX]="Yes" elif (( $rc_cap == 1 ));then properties[SCSIPR_CAPABLE$INDEX]="No" else properties[SCSIPR_CAPABLE$INDEX]="Unknown" fi # each line of data has pairs of variable names and their # associated values delimited with colon - parse and # populate the "properties" array with the data for each for PAIR in ${LINE//:/ }; do VAR=${PAIR%%=*} VAR=${VAR%_\?} VAL=${PAIR#*\"}; VAL=${VAL%\"} VAL=${VAL//\/ } if [[ $VAR == @(AUTO_@(ON|SYNC)) ]]; then [[ $VAL == "no" ]] && VAL="false" [[ $VAL == "yes" ]] && VAL="true" elif [[ $VAR == @(LTG|PP)* ]]; then VAL=${VAL% @(mega|kilo|giga)byte\(s\)} fi # some output variables do not match the incoming data # names or values precisely - do any needed mapping here case $VAR in PHYSICAL_VOLUME) properties[PHYSICAL_VOLUMES$INDEX]=$VAL ;; VG_IDENTIFIER) properties[IDENTIFIER$INDEX]=$VAL ;; PP_SIZE) properties[PPART_SIZE$INDEX]=$VAL ;; HOT_SPARE) lc_val=$VAL case $lc_val in n*) properties[MIGRATE_FAILED_DISKS$INDEX]="false" ;; r*) properties[MIGRATE_FAILED_DISKS$INDEX]="remove" ;; y*) properties[MIGRATE_FAILED_DISKS$INDEX]="one" ;; Y*) properties[MIGRATE_FAILED_DISKS$INDEX]="pool" ;; esac ;; AUTO_ON) properties[AUTO_ACTIVATE$INDEX]=$VAL ;; VG_MODE) lc_val=$VAL if [[ $lc_val == non* ]]; then properties[CONCURRENT_ACCESS$INDEX]="false" else properties[CONCURRENT_ACCESS$INDEX]="true" fi ;; MAX_LVS) properties[MAX_LOGICAL_VOLUMES$INDEX]=$VAL ;; LTG_SIZE*) properties[LOGICAL_TRACK_GROUP_SIZE$INDEX]=$VAL ;; AUTO_SYNC) properties[SYNCHRONIZE$INDEX]=$VAL ;; MAX_PPS_PER_VG) properties[MAX_PHYSICAL_PARTITIONS$INDEX]=$VAL ;; QUORUM) properties[QUORUM$INDEX]="false" lc_val=$VAL if [[ $lc_val == *enabled* ]]; then properties[QUORUM$INDEX]="true" fi ;; RESOURCE_GROUP) properties[$VAR$INDEX]="" [[ $VAL != \<* ]] && properties[$VAR$INDEX]=$VAL ;; MIRROR_POOL_STRICT) properties[STRICT_MIRROR_POOLS$INDEX]="no" case $VAL in on) properties[STRICT_MIRROR_POOLS$INDEX]="yes" ;; off) properties[STRICT_MIRROR_POOLS$INDEX]="no" ;; super) properties[STRICT_MIRROR_POOLS$INDEX]="super" ;; *) print -- "$0()[$LINENO]($SECONDS): ignoring unknown STRICT_MIRROR_POOLS value $VAL" >>$CLMGR_TMPLOG esac ;; ON_LOSS_OF_ACCESS) properties[FAILUREACTION$INDEX]=$VAL ;; TYPE) # : Verify given VG is GLVM Capable or not ? then mark it as GMVG : All GLVM VGs are scalable in type. # if [[ $VAL == "SCALABLE" ]]; then if [[ -n $(clodmget -q "name=GMVG_REP_RESOURCE and value=$vgname" -f group HACMPresource 2>/dev/null) ]];then properties[TYPE$INDEX]="gmvg" else properties[TYPE$INDEX]=$VAL fi else properties[TYPE$INDEX]=$VAL fi ;; ENCRYPTION) properties[$VAR$INDEX]=$VAL ;; *) properties[$VAR$INDEX]=$VAL ;; esac done done # : Retrieve the LVM_PREFERRED_READ : If no value is specified for preferred read setting to default value. # preferred_read=$(clodmget -n -f value -q "name=LVM_PREFERRED_READ and volume_group=$vgname" HACMPvolumegroup 2>/dev/null) if [[ ${preferred_read} == *([[:space:]]) ]]; then preferred_read="roundrobin" fi properties[LVM_PREFERRED_READ$INDEX]=$preferred_read : Update encryption with no by default if [[ -z ${properties[ENCRYPTION$INDEX]} ]];then properties[ENCRYPTION$INDEX]="no" fi (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) done # End of populating the properties array #========================================================== : 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_volume_group_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_volume_group_attributes =head1 SYNOPSIS clmgr query volume_group [,,...] clmgr -v query volume_group NOTE: the alias for "volume_group" is "vg". =head1 DESCRIPTION Retrieves the configuration data for one or more volume groups. =head1 ARGUMENTS 1. vgnames [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. 3. FAST [OPTIONAL] [boolean] Skips some of the data retrieval, returning just basic VG info. Slightly faster. =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 #==============================================================================