#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2018,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_modify_physical_volume.sh 1.4.1.5 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2011 # 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_modify_physical_volume.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_modify_physical_volume # # Description: This is the main, FPATH function that is invoked by clmgr # to modify physical volume names in the cluster configuration. # The C-SPOC utility "cl_rendisk" is what is used. # # Inputs: See the "devDoc()" function, below. # # 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, below, for the standard return # code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_modify_physical_volume { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_physical_volume.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset -n properties=$1 typeset disk=${2//\"/} shift; shift typeset new_name=${1//\"/} typeset -l scsipr_action=${2//\"/} typeset refnode=${3//\"/} typeset -l all_nodes=${4//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset -i rc=$RC_UNKNOWN i=0 typeset data= #================================================================ : Assuming an object was specified, see if it is a known object #================================================================ if [[ $disk != *([[:space:]]) ]]; then CL=$LINENO KLIB_HACMP_is_known_physical_volume "$disk" "$refnode" data if (( $? != RC_SUCCESS )); then rc=$RC_NOT_FOUND dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$disk" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 153 "Available Physical Volumes:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_physical_volume available "" "" for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi #================= : Validate input #================= 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 [[ -n $all_nodes ]]; then case $all_nodes in @(t|y)*) all_nodes=true ;; @(f|n)*) all_nodes=false ;; ?) dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 '\nERROR: invalid value specified for "%1$s": "%2$s".\n' ALL_NODES "$all_nodes" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n\n' "false, true" 1>&2 rc=$RC_INCORRECT_INPUT ;; esac fi if [[ "$new_name$scsipr_action" == *([[:space:]]) ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 401 '\nERROR: no valid modifications were specified for "%1$s".\n\n' "$disk" 1>&2 rc=$RC_MISSING_INPUT fi #=================================================================== : Modify the physical volume if no input errors have been detected #=================================================================== if (( $rc == RC_UNKNOWN )); then typeset nodes= n= name= p= pvid= uuid= rest= print -- "$data" |\ while IFS=: read nodes n p uuid rest; do name=$n pvid=$p for node in ${nodes//,/ }; do if [[ " $disk_nodes " != *\ $node\ * ]]; then [[ -n $disk_nodes ]] && disk_nodes="$disk_nodes " disk_nodes="$disk_nodes$node" fi done done # # Find all the nodes that this disk is visible on within the cluster # print "$0()[$LINENO]($SECONDS): LC_ALL=C cllspvids" >>$CLMGR_TMPLOG data=$(LC_ALL=C cllspvids) print "$0()[$LINENO]($SECONDS): cllspvids RC: $?" >>$CLMGR_TMPLOG print -- "$data" | grep -w "$pvid" |\ while read line; do if [[ $line == *"on all cluster nodes"* ]]; then for node in $(clnodename); do if [[ " $disk_nodes " != *\ $node\ * ]]; then disk_nodes="${disk_nodes:+$disk_nodes }$node" fi done elif [[ $line == *" on node "* ]]; then line=${line#* on node } line=${line%% *} if [[ " $disk_nodes " != *\ $line\ * ]]; then disk_nodes="${disk_nodes:+$disk_nodes }$line" fi elif [[ $line == *" on nodes "* ]]; then line=${line#* on nodes } line=${line%% *} for node in ${line//,/ }; do if [[ " $disk_nodes " != *\ $node\ * ]]; then disk_nodes="${disk_nodes:+$disk_nodes }$node" fi done fi done if [[ -n $scsipr_action ]]; then if [[ $scsipr_action == "clear" ]]; then # #Check if given disk is resrved or not , if not then throw an error else go ahead and clear the reservation # typeset reservstate="" reservstate=$(LC_ALL=C devrsrv -c query -l $name|grep 'Device Reservation State'|awk 'NR==2'|cut -f2 -d:|sed -e 's/^[[:space:]]*//') if [[ -z $reservstate ]];then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 397 "\nERROR: Unable to read the reservation state of disk \"%1\$s\".\n\n" "$name" 1>&2 rc=RC_ERROR else if [[ $reservstate == "NO RESERVE" ]];then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 398 "\nERROR: Disk \"%1\$s\" is not reserved , this operation must be run to clear the reservation of disk if it is reserved.\n\n" "$name" 1>&2 rc=RC_ERROR else # : Clearing the registrations from the physical volume # print "$0()[$LINENO]($SECONDS): clpr_clear $name" >>$CLMGR_TMPLOG clpr_clear $name 2>>$CLMGR_TMPLOG rc=$? print "$0()[$LINENO]($SECONDS): clpr_clear RC: $rc" >>$CLMGR_TMPLOG if (( $rc == 14 ));then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 396 "\nERROR: Unable to open the disk \"%1\$s\" ,please check if disk is already being opened by some other process.\n\n" "$name" 1>&2 rc=RC_ERROR elif (( $rc == 12 ));then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 395 "\nERROR: Given disk \"%1\$s\" is a remote disk so can not perform this operation.\n\n" "$name" 1>&2 rc=RC_ERROR elif (( $rc != RC_SUCCESS )); then /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 109 "\nERROR: the operation appears to have failed.\n\n" 1>&2 rc=RC_ERROR fi fi fi else dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 '\nERROR: invalid value specified for "%1$s": "%2$s".\n' SCSIPR_ACTION "$scsipr_action" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n' "clear" 1>&2 rc=$RC_INCORRECT_INPUT fi fi if [[ -n $new_name ]]; then typeset yOpt= [[ $all_nodes == "true" ]] && yOpt=" -Y $pvid" print "$0()[$LINENO]($SECONDS): cl_rendisk -cspoc \"-n ${disk_nodes// /,}\" -N \"$new_name\"$yOpt $disk $pvid" >>$CLMGR_TMPLOG cl_rendisk -cspoc "-n ${disk_nodes// /,}" \ -N $new_name$yOpt \ $disk rc=$? print "$0()[$LINENO]($SECONDS): cl_rendisk RC: $rc" >>$CLMGR_TMPLOG if (( $rc != RC_SUCCESS )); then rc=$RC_ERROR elif [[ -n $new_name ]]; then physical_volume=$new_name fi fi #=========================================================== : If output from this operation was requested, retrieve it #=========================================================== if (( $rc == RC_SUCCESS )); then if (( CLMGR_VERBOSE )) || [[ -n $CLMGR_ATTRS ]]; then CL=$LINENO KLIB_HACMP_get_physical_volume_attributes "$disk" properties fi fi fi #======================================================================= : If a user input error was detected, provide some helpful suggestions #======================================================================= if (( $rc == RC_MISSING_INPUT || $rc == RC_INCORRECT_INPUT )) && \ [[ $CLMGR_GUI == *([[:space:]]) ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 104 'For more information about available options and syntax, try\n"$HAUTILS/clmgr %1$s". As an\nalternative, if the PowerHA SystemMirror man pages have been installed, invoke\n"$HAUTILS/clmgr -hv" (or "/usr/bin/man clmgr"),\nsearching for "%2$s" in the displayed text.\n\n' \ "modify physical_volume -h" "PHYSICAL VOLUME:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_modify_physical_volume()" #============================================================================ # # 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_modify_physical_volume =head1 SYNOPSIS clmgr modify physical_volume \ NAME= \ [ NODE= ] clmgr modify physical_volume \ SCSIPR_ACTION= \ [ NODE= ] NOTE: a reference "NODE" may be required if the specified disk is provided via a device name, such as "hdisk#". If the disk is specified via its PVID, then no reference node is needed. NOTE: the alias for "physical_volume" is "pv". =head1 DESCRIPTION Attempts to modify the specified SystemMirror physical volume to conform to the provided specifications. =head1 ARGUMENTS 1. properties [REQUIRED] [hash ref] An associative array within which data about the modified object can be returned to the caller. 2. disk [REQUIRED] [string] The label of the physical volume that is to be modified. 3. new_name [OPTIONAL] [string] A new label to attempt to apply to the specified physical volume. 4. SCSIPR_ACTION [OPTIONAL] [string] To clear the disk of scsi persistent reserve registrations. 5. refnode [OPTIONAL] [string] The reference node for this physical volume. 6. all_nodes [OPTIONAL] [boolean] A flag indicating whether or not to update all nodes in the cluster with the new disk name, as appropriate. =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 #==============================================================================