| 1 | #!/bin/ksh | 
|---|
| 2 | # IBM_PROLOG_BEGIN_TAG | 
|---|
| 3 | # This is an automatically generated prolog. | 
|---|
| 4 | # | 
|---|
| 5 | # | 
|---|
| 6 | # | 
|---|
| 7 | # Licensed Materials - Property of IBM | 
|---|
| 8 | # | 
|---|
| 9 | # (C) COPYRIGHT International Business Machines Corp. 2005,2006 | 
|---|
| 10 | # All Rights Reserved | 
|---|
| 11 | # | 
|---|
| 12 | # US Government Users Restricted Rights - Use, duplication or | 
|---|
| 13 | # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. | 
|---|
| 14 | # | 
|---|
| 15 | # IBM_PROLOG_END_TAG | 
|---|
| 16 | # @(#)84 1.10.1.4 src/avs/fs/mmfs/ts/admin/mmchpolicy.sh, mmfs, avs_rgpfs24, rgpfs24s005a 6/14/06 14:39:55 | 
|---|
| 17 | ############################################################################# | 
|---|
| 18 | # | 
|---|
| 19 | # Usage: | 
|---|
| 20 | #   mmchpolicy Device PolicyFilename [-t DescriptiveName] [-I {yes|test}] | 
|---|
| 21 | # | 
|---|
| 22 | # where | 
|---|
| 23 | # | 
|---|
| 24 | #   Device            is the device name of the file system. | 
|---|
| 25 | # | 
|---|
| 26 | #   PolicyFilename    is the name of the file containing the policy rules. | 
|---|
| 27 | #                     If DEFAULT is specified, the current policy file is | 
|---|
| 28 | #                     replaced with a single default rule that assigns all | 
|---|
| 29 | #                     newly created files to the system storage pool. | 
|---|
| 30 | # | 
|---|
| 31 | #   DescriptiveName   is a user-provided descriptive name for the new | 
|---|
| 32 | #                     policy rules.  Defaults to the name of the file. | 
|---|
| 33 | #                     The total length cannot exceed 255 characters. | 
|---|
| 34 | # | 
|---|
| 35 | #   -I                if yes, the rules will be installed immediately. | 
|---|
| 36 | #                     if test, the rules will not be installed. | 
|---|
| 37 | #                     The default -I yes. | 
|---|
| 38 | # | 
|---|
| 39 | ############################################################################# | 
|---|
| 40 |  | 
|---|
| 41 | # Include global declarations and service routines. | 
|---|
| 42 | . /usr/lpp/mmfs/bin/mmglobfuncs | 
|---|
| 43 | . /usr/lpp/mmfs/bin/mmsdrfsdef | 
|---|
| 44 | . /usr/lpp/mmfs/bin/mmfsfuncs | 
|---|
| 45 |  | 
|---|
| 46 | sourceFile="mmchpolicy.sh" | 
|---|
| 47 | [[ -n $DEBUG || -n $DEBUGmmchpolicy ]] && set -x | 
|---|
| 48 | $mmTRACE_ENTER "$*" | 
|---|
| 49 |  | 
|---|
| 50 | # Local work files.  Names should be of the form: | 
|---|
| 51 | #   fn=${tmpDir}fn.${mmcmd}.$$ | 
|---|
| 52 |  | 
|---|
| 53 | tspolicyFile=${tmpDir}tspolicyFile.${mmcmd}.$$ | 
|---|
| 54 |  | 
|---|
| 55 | LOCAL_FILES=" $tspolicyFile " | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | # Local variables | 
|---|
| 59 | usageMsg=361 | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 | ###################### | 
|---|
| 63 | # Mainline processing | 
|---|
| 64 | ###################### | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 | ################################# | 
|---|
| 68 | # Process the command arguments. | 
|---|
| 69 | ################################# | 
|---|
| 70 | [[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \ | 
|---|
| 71 | syntaxError "help" $usageMsg | 
|---|
| 72 |  | 
|---|
| 73 | [[ $argc -lt 2  ]] &&  \ | 
|---|
| 74 | syntaxError "missingArgs" $usageMsg | 
|---|
| 75 |  | 
|---|
| 76 | # Save the positional parameters. | 
|---|
| 77 | device=$arg1 | 
|---|
| 78 | inputPolicyFile=$arg2 | 
|---|
| 79 |  | 
|---|
| 80 | # Move past the required parameters. | 
|---|
| 81 | shift 2 | 
|---|
| 82 |  | 
|---|
| 83 | # Process the rest of the parameters. | 
|---|
| 84 | while getopts :I:t: OPT | 
|---|
| 85 | do | 
|---|
| 86 | case $OPT in | 
|---|
| 87 | I) [[ -n $Iflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT" | 
|---|
| 88 | Iflag="-$OPT"; Iarg=$OPTARG; | 
|---|
| 89 | [[ $Iarg != yes && $Iarg != test ]] &&  \ | 
|---|
| 90 | syntaxError "invalidOption" $usageMsg "-$OPT $OPTARG" | 
|---|
| 91 | ;; | 
|---|
| 92 |  | 
|---|
| 93 | t) # Comment string. | 
|---|
| 94 | [[ -n $tflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT" | 
|---|
| 95 | tflag="-$OPT"; targ="$OPTARG" | 
|---|
| 96 | policyName="$targ" | 
|---|
| 97 | checkName lengthCheckOnly 255 "$policyName" | 
|---|
| 98 | [[ $? -ne 0 ]] && cleanupAndExit | 
|---|
| 99 | ;; | 
|---|
| 100 |  | 
|---|
| 101 | +[It]) # Invalid option. | 
|---|
| 102 | syntaxError "invalidOption" $usageMsg $OPT | 
|---|
| 103 | ;; | 
|---|
| 104 |  | 
|---|
| 105 | :) # Missing argument. | 
|---|
| 106 | syntaxError "missingValue" $usageMsg $OPTARG | 
|---|
| 107 | ;; | 
|---|
| 108 |  | 
|---|
| 109 | *) # Invalid option. | 
|---|
| 110 | syntaxError "invalidOption" $usageMsg $OPTARG | 
|---|
| 111 | ;; | 
|---|
| 112 | esac | 
|---|
| 113 | done  # end of while getopts :t: OPT do | 
|---|
| 114 | shift OPTIND-1 | 
|---|
| 115 |  | 
|---|
| 116 | [[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1 | 
|---|
| 117 |  | 
|---|
| 118 | if [[ $inputPolicyFile = DEFAULT ]] | 
|---|
| 119 | then | 
|---|
| 120 | # If the user wants to remove the current policy, | 
|---|
| 121 | # replace it with a system default. | 
|---|
| 122 | print -- "/* Default system rule */" > $tspolicyFile | 
|---|
| 123 | checkForErrors "writing to $tspolicyFile" $? | 
|---|
| 124 | print -- "RULE 'DEFAULT' SET POOL 'system'" >> $tspolicyFile | 
|---|
| 125 | checkForErrors "writing to $tspolicyFile" $? | 
|---|
| 126 | policyName="DEFAULT" | 
|---|
| 127 | else | 
|---|
| 128 | # Check the input file parameter and create our own copy. | 
|---|
| 129 | checkUserFile $inputPolicyFile $tspolicyFile | 
|---|
| 130 | [[ $? -ne 0 ]] && cleanupAndExit | 
|---|
| 131 | fi | 
|---|
| 132 |  | 
|---|
| 133 | # Assign a descriptive policy name if not provided by the user. | 
|---|
| 134 | [[ -z $policyName ]] && policyName="${inputPolicyFile##*/}" | 
|---|
| 135 |  | 
|---|
| 136 |  | 
|---|
| 137 | ##################################################################### | 
|---|
| 138 | # Set up trap exception handling and ensure that the local copy of | 
|---|
| 139 | # the mmsdrfs is up-to-date.  There is no need to lock mmsdrfs file. | 
|---|
| 140 | ##################################################################### | 
|---|
| 141 | trap pretrap2 HUP INT QUIT KILL | 
|---|
| 142 | gpfsInitOutput=$(gpfsInit nolock) | 
|---|
| 143 | setGlobalVar $? $gpfsInitOutput | 
|---|
| 144 |  | 
|---|
| 145 |  | 
|---|
| 146 | ########################################################### | 
|---|
| 147 | # Make sure the specified file system exists and is local. | 
|---|
| 148 | ########################################################### | 
|---|
| 149 | findFSoutput=$(findFS "$device" $mmsdrfsFile) | 
|---|
| 150 | [[ -z $findFSoutput ]] && cleanupAndExit | 
|---|
| 151 |  | 
|---|
| 152 | # Parse the output from the findFS function. | 
|---|
| 153 | set -f ; set -- $findFSoutput ; set +f | 
|---|
| 154 | fqDeviceName=$1 | 
|---|
| 155 | deviceName=$2 | 
|---|
| 156 | fsHomeCluster=$3 | 
|---|
| 157 |  | 
|---|
| 158 | # Exit with a message if the command was invoked for a remote file system. | 
|---|
| 159 | if [[ $fsHomeCluster != $HOME_CLUSTER ]] | 
|---|
| 160 | then | 
|---|
| 161 | # Command is not allowed for remote file systems. | 
|---|
| 162 | printErrorMsg 106 $mmcmd $device $fsHomeCluster | 
|---|
| 163 | cleanupAndExit | 
|---|
| 164 | fi | 
|---|
| 165 |  | 
|---|
| 166 | # If removing the current policy and -I test is specified, | 
|---|
| 167 | # there is nothing else to do. | 
|---|
| 168 | [[ $inputPolicyFile = DEFAULT && $Iarg = test ]] &&  \ | 
|---|
| 169 | cleanupAndExit 0 | 
|---|
| 170 |  | 
|---|
| 171 |  | 
|---|
| 172 | ######################################################################## | 
|---|
| 173 | # Invoke the tschpolicy command on the local node. | 
|---|
| 174 | # Display any error messages and exit if any of the following are true: | 
|---|
| 175 | #   - the command completed successfully | 
|---|
| 176 | #   - there is an unacceptable error | 
|---|
| 177 | #       (anything other than daemon down or quorum wait) | 
|---|
| 178 | #   - the policy name string contains blanks or tabs | 
|---|
| 179 | #       (the existing infrastructure cannot deal with imbedded blanks) | 
|---|
| 180 | #   - this is a single node cluster | 
|---|
| 181 | ######################################################################## | 
|---|
| 182 | $tschpolicy $fqDeviceName $tspolicyFile -t "$policyName" $Iflag $Iarg 2>$errMsg | 
|---|
| 183 | rc=$(remapRC $?) | 
|---|
| 184 |  | 
|---|
| 185 | if [[ $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait || | 
|---|
| 186 | "$policyName" = *+([;$BLANKchar$TABchar])*       || | 
|---|
| 187 | $MMMODE = single ]] | 
|---|
| 188 | then | 
|---|
| 189 | if [[ $rc -eq $MM_DaemonDown ]] | 
|---|
| 190 | then | 
|---|
| 191 | # GPFS is down on this node. | 
|---|
| 192 | printErrorMsg 109 $mmcmd | 
|---|
| 193 | elif [[ $rc -eq $MM_QuorumWait ]] | 
|---|
| 194 | then | 
|---|
| 195 | # GPFS is not ready for commands. | 
|---|
| 196 | printErrorMsg 110 $mmcmd | 
|---|
| 197 | elif [[ $rc -eq $MM_ConnectionReset ]] | 
|---|
| 198 | then | 
|---|
| 199 | # An internode connection was reset. | 
|---|
| 200 | printErrorMsg 257 $mmcmd | 
|---|
| 201 | else | 
|---|
| 202 | # Either the command worked, or it is an unexpected error. | 
|---|
| 203 | [[ -s $errMsg ]] && $cat $errMsg 1>&2 | 
|---|
| 204 | #   [[ $rc -ne 0 ]] && printErrorMsg 113 "$mmcmd" "tschpolicy" $rc | 
|---|
| 205 | fi  # end of if [[ $rc -eq $MM_DaemonDown ]] | 
|---|
| 206 | cleanupAndExit $rc | 
|---|
| 207 | fi  # end of if [[ ($rc -ne $MM_DaemonDown && ... ]] | 
|---|
| 208 | $rm -f $errMsg | 
|---|
| 209 |  | 
|---|
| 210 |  | 
|---|
| 211 | ##################################################################### | 
|---|
| 212 | # We come here if the local GPFS daemon is not ready for commands. | 
|---|
| 213 | # Find an active node and send the command there. | 
|---|
| 214 | ##################################################################### | 
|---|
| 215 |  | 
|---|
| 216 | # Create a file with the reliable names of the nodes in the cluster. | 
|---|
| 217 | getNodeList $REL_HOSTNAME_Field $GLOBAL_ID $mmsdrfsFile > $nodefile | 
|---|
| 218 | preferredNode=$ourNodeName | 
|---|
| 219 |  | 
|---|
| 220 | # Try the nodes one by one until you find a node that can execute the command. | 
|---|
| 221 | $mmcommon onactive $preferredNode $nodefile     \ | 
|---|
| 222 | $tspolicyFile $NO_MOUNT_CHECK NULL $NO_LINK  \ | 
|---|
| 223 | tschpolicy "$fqDeviceName $tspolicyFile -t $policyName $Iflag $Iarg" | 
|---|
| 224 | rc=$? | 
|---|
| 225 |  | 
|---|
| 226 | # if [[ $rc -ne 0 ]] | 
|---|
| 227 | # then | 
|---|
| 228 | #   # tschpolicy failed. | 
|---|
| 229 | #   printErrorMsg 104 $mmcmd tschpolicy | 
|---|
| 230 | #   cleanupAndExit $rc | 
|---|
| 231 | # fi | 
|---|
| 232 |  | 
|---|
| 233 | cleanupAndExit $rc | 
|---|
| 234 |  | 
|---|