#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 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_logical_volume_attributes.sh 1.13 # # 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 # @(#) 6756102 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_logical_volume_attributes.sh, 726, 2147A_aha726, Mar 09 2021 08:28 AM #============================================================================ # # Name: KLIB_HACMP_get_logical_volume_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect logical volume information. This function invokes # the C-SPOC utility, "cl_ls_vglvfs", if needed, and mines # its output for all relevant volume group data. If the # cl_ls_vglvfs 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_logical_volume_attributes { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 6756102 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_logical_volume_attributes.sh, 726, 2147A_aha726, Mar 09 2021 08:28 AM : INPUTS: $* typeset lvnames=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then lvnames= 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 lvname="" value= key= rest= LVS="" LVM_DATA="" typeset -i INDEX=1 rc=$RC_UNKNOWN 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 [[ $attr == "FAST" ]] && continue # A legacy input. Ignored. queries[$attr]="${value#*=}" fi shift done #================================================================ : 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 $lvnames ]]; then #===================================================================== # As a performance optimization, attempt to find the volume group # for each LV specified. If the VG is the same, we can do a slightly # faster look-up. If there is more than one VG, however, no boost is # possible. #===================================================================== typeset LV_VG="" for lvname in ${lvnames//,/ }; do lslv $lvname 2>/dev/null | grep "VOLUME GROUP:" | read LINE if [[ -z $LINE ]]; then LV_VG="" break # No such LV else LINE=${LINE##*VOLUME GROUP:*([[:space:]])} LINE=${LINE%%+([[:space:]])*} if [[ -z $LV_VG && -n $LINE ]]; then LV_VG=$LINE elif [[ -n $LV_VG && -n $LINE && $LINE != $LV_VG ]]; then LV_VG="" break # More than one VG. cl_ls_vglvfs can't handle. fi fi done 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 # Always log results [[ -s $TEMPERRFILE ]] && cat $TEMPERRFILE >>$CLMGR_TMPLOG CLEANUP=1 elif [[ -s $TEMPERRFILE ]]; then cat $TEMPERRFILE >>$CLMGR_TMPLOG cmd_rc=$RC_ERROR 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 [[ -s $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 lvname in ${lvnames//,/ }; do typeset -i FOUND=0 print -- "$LVM_DATA" |\ while read LINE; do if [[ $LINE == LV:$lvname:* ]]; then FOUND=1 break fi done if (( FOUND )); then LVS="$LVS $lvname" else LVS="" 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' "$lvname" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 148 'Available Logical Volumes:\n\n' 1>&2 print -- "$LVM_DATA" |\ while read LINE; do [[ $LINE != LV:* ]] && continue LINE=${LINE#LV:} 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 [[ -s $TEMPERRFILE ]] && cat $TEMPERRFILE >>$CLMGR_TMPLOG CLEANUP=1 elif [[ -s $TEMPERRFILE ]]; then cat $TEMPERRFILE >>$CLMGR_TMPLOG cmd_rc=$RC_ERROR 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 [[ -s $TEMPERRFILE ]] && cat $TEMPERRFILE 1>&2 rc=$RC_ERROR fi (( CLEANUP )) && rm -f $TEMPERRFILE fi if [[ -n $LVM_DATA ]]; then print -- "$LVM_DATA" | grep "^LV:" |\ while IFS=: read rest lvname rest; do LVS="$LVS $lvname" done fi else dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT fi if [[ $LVS == *([[:space:]]) ]]; then rc=$RC_SUCCESS # It's not an error to have no LVs fi #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for lvname in $LVS; do print -- "$LVM_DATA" |\ while read -r LINE; do [[ $LINE != LV:$lvname:* ]] && 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]=$lvname for PAIR in ${LINE//:/ }; do VAR=${PAIR%%=*} VAR=${VAR%_\?} VAL=${PAIR#*\"}; VAL=${VAL%\"} VAL=${VAL//\/ } VAR=${VAR#\(} VAR=${VAR%\)} if [[ $VAR == @(PP)* ]]; then VAL=${VAL% @(mega|kilo|giga)byte\(s\)} fi if [[ $VAR == "LPS" ]];then lp_size=$VAL fi if [[ $VAR == "PP_SIZE" ]];then pp_size=$(echo $VAL | cut -d' ' -f1) fi case $VAR in LV_IDENTIFIER) properties[IDENTIFIER$INDEX]=$VAL ;; SEPARATE_PV*) properties[EACH_LP_COPY_ON_A_SEPARATE_PV$INDEX]=$VAL ;; COPY_1*) properties[FIRST_COPY_MIRROR_POOL$INDEX]=$VAL ;; COPY_2*) properties[SECOND_COPY_MIRROR_POOL$INDEX]=$VAL ;; COPY_3*) properties[THIRD_COPY_MIRROR_POOL$INDEX]=$VAL ;; ENCRYPTION*) properties[ENCRYPTION$INDEX]=$VAL ;; RESOURCE_GROUP) [[ $VAL == \<* ]] && VAL="" properties[RESOURCE_GROUP$INDEX]=$VAL ;; *) properties[$VAR$INDEX]=$VAL ;; esac done VAL=$((lp_size * pp_size)) properties[SIZE]=$VAL 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[logical_volume]}; do [[ $key == @(FILE|SIZE|FILES) ]] && continue if [[ -z ${properties[$key$INDEX]} ]]; then properties[$key$INDEX]="" fi done if [[ -z ${properties[ENCRYPTION$INDEX]} ]];then properties[ENCRYPTION$INDEX]="no" 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_logical_volume_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_logical_volume_attributes =head1 VERSION Version Number: 1.13 Last Extracted: 6/16/15 17:51:07 Last Changed: 6/1/15 14:01:45 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_logical_volume_attributes.sh, hacmp.assist, 61haes_r720, 1525A_hacmp720 =head1 SYNOPSIS clmgr query logical_volume [,,,...] clmgr -v query logical_volume NOTE: the alias for "logical_volume" is "lv". =head1 DESCRIPTION Retrieves the configuration data for one or more logical volumes. =head1 ARGUMENTS 1. lvnames [REQUIRED] [string] The label of one or more logical volumes (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 =head1 COPYRIGHT COPYRIGHT International Business Machines Corp. 2010,2015 All Rights Reserved =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 #==============================================================================