| [16] | 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 | # @(#)41 1.9.1.1 src/avs/fs/mmfs/ts/admin/mmchfileset.sh, mmfs, avs_rgpfs24, rgpfs24s007a 10/18/06 12:02:51 | 
|---|
 | 17 | ################################################################################ | 
|---|
 | 18 | # | 
|---|
 | 19 | # Usage: | 
|---|
 | 20 | #   mmchfileset Device {FilesetName | -J JunctionPath} | 
|---|
 | 21 | #                      {[-j NewFileSetName] [-t Comment]} | 
|---|
 | 22 | # | 
|---|
 | 23 | # where: | 
|---|
 | 24 | #   Device          is the device name of the file system. | 
|---|
 | 25 | #   FilesetName     is the fileset name. | 
|---|
 | 26 | #   JunctionPath    is the fileset junction path name. | 
|---|
 | 27 | #   NewFilesetName  is the new fileset name to be given to an existing fileset. | 
|---|
 | 28 | #   Comment         is a user-provided description of the fileset. | 
|---|
 | 29 | #                     The total length cannot exceed 255 characters. | 
|---|
 | 30 | # | 
|---|
 | 31 | ################################################################################ | 
|---|
 | 32 |  | 
|---|
 | 33 | # Include global declarations and service routines. | 
|---|
 | 34 | . /usr/lpp/mmfs/bin/mmglobfuncs | 
|---|
 | 35 | . /usr/lpp/mmfs/bin/mmsdrfsdef | 
|---|
 | 36 | . /usr/lpp/mmfs/bin/mmfsfuncs | 
|---|
 | 37 |  | 
|---|
 | 38 | sourceFile="mmchfileset.sh" | 
|---|
 | 39 | [[ -n $DEBUG || -n $DEBUGmmchfileset ]] && set -x | 
|---|
 | 40 | $mmTRACE_ENTER "$*" | 
|---|
 | 41 |  | 
|---|
 | 42 | # Local work files.  Names should be of the form: | 
|---|
 | 43 | #   fn=${tmpDir}fn.${mmcmd}.$$ | 
|---|
 | 44 |  | 
|---|
 | 45 | LOCAL_FILES=" " | 
|---|
 | 46 |  | 
|---|
 | 47 |  | 
|---|
 | 48 | # Local variables | 
|---|
 | 49 | usageMsg=514 | 
|---|
 | 50 |  | 
|---|
 | 51 |  | 
|---|
 | 52 | # Local functions | 
|---|
 | 53 |  | 
|---|
 | 54 |  | 
|---|
 | 55 |  | 
|---|
 | 56 | ####################### | 
|---|
 | 57 | # Mainline processing | 
|---|
 | 58 | ####################### | 
|---|
 | 59 |  | 
|---|
 | 60 |  | 
|---|
 | 61 | ####################################### | 
|---|
 | 62 | # Process the command line arguments. | 
|---|
 | 63 | ####################################### | 
|---|
 | 64 | [[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \ | 
|---|
 | 65 |   syntaxError "help" $usageMsg | 
|---|
 | 66 |  | 
|---|
 | 67 | [[ $argc -lt 3 ]] &&  \ | 
|---|
 | 68 |   syntaxError "missingArgs" $usageMsg | 
|---|
 | 69 |  | 
|---|
 | 70 | # The first argument is always the file system name. | 
|---|
 | 71 | device=$arg1 | 
|---|
 | 72 | deviceName=${device##+(/)dev+(/)}  # name stripped of /dev/ prefix | 
|---|
 | 73 | fqDeviceName="/dev/$deviceName"    # fully-qualified name (with /dev/ prefix) | 
|---|
 | 74 |  | 
|---|
 | 75 | # The device name must be followed by a fileset name or -J and a junction path. | 
|---|
 | 76 | if [[ $arg2 = "-J"* ]] | 
|---|
 | 77 | then | 
|---|
 | 78 |   junctionName=${arg2#-J} | 
|---|
 | 79 |   if [[ -z $junctionName ]] | 
|---|
 | 80 |   then | 
|---|
 | 81 |     junctionName=$arg3 | 
|---|
 | 82 |     shift 3 | 
|---|
 | 83 |   else | 
|---|
 | 84 |     shift 2 | 
|---|
 | 85 |   fi | 
|---|
 | 86 | else | 
|---|
 | 87 |   filesetName=$arg2 | 
|---|
 | 88 |   checkName filesetName 255 "$filesetName" | 
|---|
 | 89 |   [[ $? -ne 0 ]] && cleanupAndExit | 
|---|
 | 90 |   [[ $arg3 = "-J"* ]] &&  \ | 
|---|
 | 91 |     syntaxError "invalidCombination" $usageMsg "-J" "FilesetName" | 
|---|
 | 92 |   shift 2 | 
|---|
 | 93 | fi | 
|---|
 | 94 |  | 
|---|
 | 95 | # Process the rest of the parameters. | 
|---|
 | 96 | while getopts :j:t: OPT | 
|---|
 | 97 | do | 
|---|
 | 98 |   case $OPT in | 
|---|
 | 99 |     j) # New fileset name | 
|---|
 | 100 |        [[ -n $jflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT" | 
|---|
 | 101 |        jflag="-$OPT"; jarg="$OPTARG" | 
|---|
 | 102 |        newFilesetName=$jarg | 
|---|
 | 103 |        checkName filesetName 255 "$newFilesetName" | 
|---|
 | 104 |        [[ $? -ne 0 ]] && cleanupAndExit | 
|---|
 | 105 |        ;; | 
|---|
 | 106 |  | 
|---|
 | 107 |     t) # New comment string | 
|---|
 | 108 |        [[ -n $tflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT" | 
|---|
 | 109 |        tflag="-$OPT"; targ="$OPTARG" | 
|---|
 | 110 |        userComments="$targ" | 
|---|
 | 111 |        checkName lengthCheckOnly 255 "$userComments" | 
|---|
 | 112 |        [[ $? -ne 0 ]] && cleanupAndExit | 
|---|
 | 113 |        ;; | 
|---|
 | 114 |  | 
|---|
 | 115 |     +[jt]) # Invalid option | 
|---|
 | 116 |        syntaxError "invalidOption" $usageMsg $OPT | 
|---|
 | 117 |        ;; | 
|---|
 | 118 |  | 
|---|
 | 119 |     :) # Missing argument | 
|---|
 | 120 |        syntaxError "missingValue" $usageMsg $OPTARG | 
|---|
 | 121 |        ;; | 
|---|
 | 122 |  | 
|---|
 | 123 |     *) # Invalid option | 
|---|
 | 124 |        syntaxError "invalidOption" $usageMsg $OPTARG | 
|---|
 | 125 |        ;; | 
|---|
 | 126 |  | 
|---|
 | 127 |   esac | 
|---|
 | 128 | done  # end of while getopts :j:t: OPT do | 
|---|
 | 129 | shift OPTIND-1 | 
|---|
 | 130 |  | 
|---|
 | 131 | [[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1 | 
|---|
 | 132 |  | 
|---|
 | 133 |  | 
|---|
 | 134 | ###################################################################### | 
|---|
 | 135 | # Set up trap exception handling and ensure that the local copy of | 
|---|
 | 136 | # the mmsdrfs file is up-to-date.  There is no need to lock the file. | 
|---|
 | 137 | ###################################################################### | 
|---|
 | 138 | trap pretrap2 HUP INT QUIT KILL | 
|---|
 | 139 | gpfsInitOutput=$(gpfsInit nolock) | 
|---|
 | 140 | setGlobalVar $? $gpfsInitOutput | 
|---|
 | 141 |  | 
|---|
 | 142 |  | 
|---|
 | 143 | ########################################################### | 
|---|
 | 144 | # Make sure the specified file system exists and is local. | 
|---|
 | 145 | ########################################################### | 
|---|
 | 146 | findFSoutput=$(findFS "$device" $mmsdrfsFile) | 
|---|
 | 147 | [[ -z $findFSoutput ]] && cleanupAndExit | 
|---|
 | 148 |  | 
|---|
 | 149 | # Parse the output from the findFS function. | 
|---|
 | 150 | set -f ; set -- $findFSoutput ; set +f | 
|---|
 | 151 | fqDeviceName=$1 | 
|---|
 | 152 | deviceName=$2 | 
|---|
 | 153 | fsHomeCluster=$3 | 
|---|
 | 154 |  | 
|---|
 | 155 | # Exit if the command was invoked for a remote file system. | 
|---|
 | 156 | if [[ $fsHomeCluster != $HOME_CLUSTER ]] | 
|---|
 | 157 | then | 
|---|
 | 158 |   # Command is not allowed for remote file systems. | 
|---|
 | 159 |   printErrorMsg 106 $mmcmd $device $fsHomeCluster | 
|---|
 | 160 |   cleanupAndExit | 
|---|
 | 161 | fi | 
|---|
 | 162 |  | 
|---|
 | 163 |  | 
|---|
 | 164 | ############################# | 
|---|
 | 165 | # Verify the junction name. | 
|---|
 | 166 | ############################# | 
|---|
 | 167 | if [[ -n $junctionName ]] | 
|---|
 | 168 | then | 
|---|
 | 169 |   # The file system must be mounted. | 
|---|
 | 170 |   mountPoint=$(findMountpoint $deviceName) | 
|---|
 | 171 |   if [[ -z $mountPoint ]] | 
|---|
 | 172 |   then | 
|---|
 | 173 |     # File system is not mounted. | 
|---|
 | 174 |     printErrorMsg 552 $mmcmd $device | 
|---|
 | 175 |     cleanupAndExit | 
|---|
 | 176 |   fi | 
|---|
 | 177 |  | 
|---|
 | 178 |   # Find the device ID of the mounted GPFS file system. | 
|---|
 | 179 |   gpfsDeviceID=$($perl -e '($dev) = stat "'$mountPoint'"; printf "%u", $dev;') | 
|---|
 | 180 |  | 
|---|
 | 181 |   # Ensure the junction path name is fully qualified. | 
|---|
 | 182 |   [[ $junctionName != /* ]] && junctionName="${PWD%/}/${junctionName}" | 
|---|
 | 183 |   junctionName=${junctionName%%/}  # Strip any trailing slashes. | 
|---|
 | 184 |  | 
|---|
 | 185 |   # Find the device ID and inode number of the junction. | 
|---|
 | 186 |   # The result is a colon-separated device and inode numbers. | 
|---|
 | 187 |   junctionDevAndIno=$($perl -e ' ($dev,$ino) = stat "'$junctionName'"; | 
|---|
 | 188 |                                  if ($dev ne "") { printf "%u:%u", $dev,$ino }') | 
|---|
 | 189 |  | 
|---|
 | 190 |   # The junction must be within the mounted file system. | 
|---|
 | 191 |   if [[ $gpfsDeviceID != ${junctionDevAndIno%:*} ]] | 
|---|
 | 192 |   then | 
|---|
 | 193 |     printErrorMsg 550 $mmcmd "$junctionName" $device | 
|---|
 | 194 |     cleanupAndExit | 
|---|
 | 195 |   fi | 
|---|
 | 196 |  | 
|---|
 | 197 |   # Create the extended junction path name. | 
|---|
 | 198 |   junctionName="-J /GPFS:${junctionDevAndIno#*:}${junctionName}" | 
|---|
 | 199 | fi  # end of if [[ -n $junctionName ]] | 
|---|
 | 200 |  | 
|---|
 | 201 |  | 
|---|
 | 202 | ########################################################################## | 
|---|
 | 203 | # Invoke the tschfileset command on the local node. | 
|---|
 | 204 | # Display any error messages and exit if any of the following are true: | 
|---|
 | 205 | #   - the command completed successfully | 
|---|
 | 206 | #   - a junction path name is specified | 
|---|
 | 207 | #   - there is an unacceptable error | 
|---|
 | 208 | #       (anything other than daemon down or quorum wait) | 
|---|
 | 209 | #   - the user comment string contains blanks or tabs | 
|---|
 | 210 | #       (the existing infrastructure cannot deal with imbedded blanks) | 
|---|
 | 211 | #   - the fileset name (old or new) contains path name expansion triggers | 
|---|
 | 212 | #   - this is a single node cluster | 
|---|
 | 213 | ########################################################################## | 
|---|
 | 214 | [[ -n $newFilesetName ]] && newFilesetName="-j $newFilesetName" | 
|---|
 | 215 |  | 
|---|
 | 216 | set -f | 
|---|
 | 217 | if [[ -n $userComments ]] | 
|---|
 | 218 | then | 
|---|
 | 219 |   $tschfileset $fqDeviceName  \ | 
|---|
 | 220 |     $filesetName $junctionName $newFilesetName -t "$userComments" 2>$errMsg | 
|---|
 | 221 |   rc=$(remapRC $?) | 
|---|
 | 222 | else | 
|---|
 | 223 |   $tschfileset $fqDeviceName  \ | 
|---|
 | 224 |     $filesetName $junctionName $newFilesetName 2>$errMsg | 
|---|
 | 225 |   rc=$(remapRC $?) | 
|---|
 | 226 | fi | 
|---|
 | 227 | set +f | 
|---|
 | 228 |  | 
|---|
 | 229 | if [[ $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait || | 
|---|
 | 230 |       "$userComments"   = *+([;$BLANKchar$TABchar])*   || | 
|---|
 | 231 |       -n $junctionName || $MMMODE = single ]] | 
|---|
 | 232 | then | 
|---|
 | 233 |   if [[ $rc -eq $MM_DaemonDown ]] | 
|---|
 | 234 |   then | 
|---|
 | 235 |     # GPFS is down on this node. | 
|---|
 | 236 |     printErrorMsg 109 $mmcmd | 
|---|
 | 237 |   elif [[ $rc -eq $MM_QuorumWait ]] | 
|---|
 | 238 |   then | 
|---|
 | 239 |     # GPFS is not ready for commands. | 
|---|
 | 240 |     printErrorMsg 110 $mmcmd | 
|---|
 | 241 |   elif [[ $rc -eq $MM_ConnectionReset ]] | 
|---|
 | 242 |   then | 
|---|
 | 243 |     # An internode connection was reset. | 
|---|
 | 244 |     printErrorMsg 257 $mmcmd | 
|---|
 | 245 |   else | 
|---|
 | 246 |     # Either the command worked, or it is an unexpected error. | 
|---|
 | 247 |     [[ -s $errMsg ]] && $cat $errMsg 1>&2 | 
|---|
 | 248 | #   [[ $rc -ne 0 ]] && printErrorMsg 113 "$mmcmd" "tschfileset" $rc | 
|---|
 | 249 |   fi  # end of if [[ $rc -eq $MM_FsNotFound ]] | 
|---|
 | 250 |   cleanupAndExit $rc | 
|---|
 | 251 | fi  # end of if [[ ($rc -ne $MM_DaemonDown && ... ]] | 
|---|
 | 252 | $rm -f $errMsg | 
|---|
 | 253 |  | 
|---|
 | 254 |  | 
|---|
 | 255 | ##################################################################### | 
|---|
 | 256 | # We come here if the local GPFS daemon is not ready for commands. | 
|---|
 | 257 | # Find an active node and send the command there. | 
|---|
 | 258 | ##################################################################### | 
|---|
 | 259 |  | 
|---|
 | 260 | # Create a file with the reliable names of the nodes in the cluster. | 
|---|
 | 261 | getNodeList $REL_HOSTNAME_Field $GLOBAL_ID $mmsdrfsFile > $nodefile | 
|---|
 | 262 | preferredNode=$ourNodeName | 
|---|
 | 263 |  | 
|---|
 | 264 | # Try the nodes one by one until you find a node that can execute the command. | 
|---|
 | 265 | if [[ -n $userComments ]] | 
|---|
 | 266 | then | 
|---|
 | 267 |   $mmcommon onactive $preferredNode $nodefile     \ | 
|---|
 | 268 |      $NO_FILE_COPY $NO_MOUNT_CHECK NULL $NO_LINK  \ | 
|---|
 | 269 |      tschfileset $fqDeviceName $filesetName $newFilesetName -t "$userComments" | 
|---|
 | 270 |   rc=$? | 
|---|
 | 271 | else | 
|---|
 | 272 |   $mmcommon onactive $preferredNode $nodefile     \ | 
|---|
 | 273 |      $NO_FILE_COPY $NO_MOUNT_CHECK NULL $NO_LINK  \ | 
|---|
 | 274 |      tschfileset $fqDeviceName $filesetName $newFilesetName | 
|---|
 | 275 |   rc=$? | 
|---|
 | 276 | fi | 
|---|
 | 277 |  | 
|---|
 | 278 | # if [[ $rc -ne 0 ]] | 
|---|
 | 279 | # then | 
|---|
 | 280 | #   # tschfileset failed. | 
|---|
 | 281 | #   printErrorMsg 104 $mmcmd tschfileset | 
|---|
 | 282 | #   cleanupAndExit $rc | 
|---|
 | 283 | # fi | 
|---|
 | 284 |  | 
|---|
 | 285 | cleanupAndExit $rc | 
|---|
 | 286 |  | 
|---|