| [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 | # @(#)44 1.8 src/avs/fs/mmfs/ts/admin/mmlinkfileset.sh, mmfs, avs_rgpfs24, rgpfs240610b 1/23/06 01:56:54 | 
|---|
 | 17 | ############################################################################### | 
|---|
 | 18 | # | 
|---|
 | 19 | # Usage: | 
|---|
 | 20 | #   mmlinkfileset Device FilesetName [-J JunctionPath] | 
|---|
 | 21 | # | 
|---|
 | 22 | # where: | 
|---|
 | 23 | #   Device            is the device name of the file system. | 
|---|
 | 24 | # | 
|---|
 | 25 | #   FilesetName       is the fileset name. | 
|---|
 | 26 | # | 
|---|
 | 27 | #   JunctionPath      is the fileset junction path name. | 
|---|
 | 28 | #                     If not specified, it defaults to $PWD/FilesetName | 
|---|
 | 29 | # | 
|---|
 | 30 | ############################################################################### | 
|---|
 | 31 |  | 
|---|
 | 32 | # Include global declarations and service routines. | 
|---|
 | 33 | . /usr/lpp/mmfs/bin/mmglobfuncs | 
|---|
 | 34 | . /usr/lpp/mmfs/bin/mmsdrfsdef | 
|---|
 | 35 | . /usr/lpp/mmfs/bin/mmfsfuncs | 
|---|
 | 36 |  | 
|---|
 | 37 | sourceFile="mmlinkfileset.sh" | 
|---|
 | 38 | [[ -n $DEBUG || -n $DEBUGmmlinkfileset ]] && set -x | 
|---|
 | 39 | $mmTRACE_ENTER "$*" | 
|---|
 | 40 |  | 
|---|
 | 41 | # Local work files.  Names should be of the form: | 
|---|
 | 42 | #   fn=${tmpDir}fn.${mmcmd}.$$ | 
|---|
 | 43 |  | 
|---|
 | 44 | LOCAL_FILES=" " | 
|---|
 | 45 |  | 
|---|
 | 46 |  | 
|---|
 | 47 | # Local variables | 
|---|
 | 48 | usageMsg=515 | 
|---|
 | 49 |  | 
|---|
 | 50 |  | 
|---|
 | 51 | # Local functions | 
|---|
 | 52 |  | 
|---|
 | 53 |  | 
|---|
 | 54 |  | 
|---|
 | 55 | ####################### | 
|---|
 | 56 | # Mainline processing | 
|---|
 | 57 | ####################### | 
|---|
 | 58 |  | 
|---|
 | 59 |  | 
|---|
 | 60 | ####################################### | 
|---|
 | 61 | # Process the command line arguments. | 
|---|
 | 62 | ####################################### | 
|---|
 | 63 | [[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \ | 
|---|
 | 64 |   syntaxError "help" $usageMsg | 
|---|
 | 65 |  | 
|---|
 | 66 | [[ $argc -lt 2 ]] &&  \ | 
|---|
 | 67 |   syntaxError "missingArgs" $usageMsg | 
|---|
 | 68 |  | 
|---|
 | 69 | # The first argument is always the file system name. | 
|---|
 | 70 | device=$arg1 | 
|---|
 | 71 | deviceName=${device##+(/)dev+(/)}  # name stripped of /dev/ prefix | 
|---|
 | 72 | fqDeviceName="/dev/$deviceName"    # fully-qualified name (with /dev/ prefix) | 
|---|
 | 73 |  | 
|---|
 | 74 | # The second argument is always the fileset name. | 
|---|
 | 75 | filesetName=$arg2 | 
|---|
 | 76 |  | 
|---|
 | 77 | # Move past the positional parameters. | 
|---|
 | 78 | shift 2 | 
|---|
 | 79 |  | 
|---|
 | 80 | # Process the rest of the parameters. | 
|---|
 | 81 | while getopts :J: OPT | 
|---|
 | 82 | do | 
|---|
 | 83 |   case $OPT in | 
|---|
 | 84 |     J) # New junction name | 
|---|
 | 85 |        [[ -n $Jflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT" | 
|---|
 | 86 |        Jflag="-$OPT"; Jarg="$OPTARG" | 
|---|
 | 87 |        junctionName=$Jarg | 
|---|
 | 88 |        ;; | 
|---|
 | 89 |  | 
|---|
 | 90 |     +[J]) # Invalid option | 
|---|
 | 91 |        syntaxError "invalidOption" $usageMsg $OPT | 
|---|
 | 92 |        ;; | 
|---|
 | 93 |  | 
|---|
 | 94 |     :) # Missing argument | 
|---|
 | 95 |        syntaxError "missingValue" $usageMsg $OPTARG | 
|---|
 | 96 |        ;; | 
|---|
 | 97 |  | 
|---|
 | 98 |     *) # Invalid option | 
|---|
 | 99 |        syntaxError "invalidOption" $usageMsg $OPTARG | 
|---|
 | 100 |        ;; | 
|---|
 | 101 |   esac | 
|---|
 | 102 | done  # end of while getopts :J: OPT do | 
|---|
 | 103 | shift OPTIND-1 | 
|---|
 | 104 |  | 
|---|
 | 105 | [[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1 | 
|---|
 | 106 |  | 
|---|
 | 107 | # If not specified, default the junction name to the fileset name. | 
|---|
 | 108 | [[ -z $junctionName ]] && junctionName="$filesetName" | 
|---|
 | 109 |  | 
|---|
 | 110 |  | 
|---|
 | 111 | ###################################################################### | 
|---|
 | 112 | # Set up trap exception handling and ensure that the local copy of | 
|---|
 | 113 | # the mmsdrfs file is up-to-date.  There is no need to lock the file. | 
|---|
 | 114 | ###################################################################### | 
|---|
 | 115 | trap pretrap2 HUP INT QUIT KILL | 
|---|
 | 116 | gpfsInitOutput=$(gpfsInit nolock) | 
|---|
 | 117 | setGlobalVar $? $gpfsInitOutput | 
|---|
 | 118 |  | 
|---|
 | 119 |  | 
|---|
 | 120 | ########################################################### | 
|---|
 | 121 | # Make sure the specified file system exists and is local. | 
|---|
 | 122 | ########################################################### | 
|---|
 | 123 | findFSoutput=$(findFS "$device" $mmsdrfsFile) | 
|---|
 | 124 | [[ -z $findFSoutput ]] && cleanupAndExit | 
|---|
 | 125 |  | 
|---|
 | 126 | # Parse the output from the findFS function. | 
|---|
 | 127 | set -f ; set -- $findFSoutput ; set +f | 
|---|
 | 128 | fqDeviceName=$1 | 
|---|
 | 129 | deviceName=$2 | 
|---|
 | 130 | fsHomeCluster=$3 | 
|---|
 | 131 |  | 
|---|
 | 132 | # Exit if the command was invoked for a remote file system. | 
|---|
 | 133 | if [[ $fsHomeCluster != $HOME_CLUSTER ]] | 
|---|
 | 134 | then | 
|---|
 | 135 |   # Command is not allowed for remote file systems. | 
|---|
 | 136 |   printErrorMsg 106 $mmcmd $device $fsHomeCluster | 
|---|
 | 137 |   cleanupAndExit | 
|---|
 | 138 | fi | 
|---|
 | 139 |  | 
|---|
 | 140 | # The file system must be mounted. | 
|---|
 | 141 | mountPoint=$(findMountpoint $deviceName) | 
|---|
 | 142 | if [[ -z $mountPoint ]] | 
|---|
 | 143 | then | 
|---|
 | 144 |   # File system is not mounted. | 
|---|
 | 145 |   printErrorMsg 552 $mmcmd $device | 
|---|
 | 146 |   cleanupAndExit | 
|---|
 | 147 | fi | 
|---|
 | 148 |  | 
|---|
 | 149 | # Find the device ID of the mounted GPFS file system. | 
|---|
 | 150 | gpfsDeviceID=$($perl -e '($dev) = stat "'$mountPoint'"; printf "%u", $dev;') | 
|---|
 | 151 |  | 
|---|
 | 152 |  | 
|---|
 | 153 | ############################# | 
|---|
 | 154 | # Verify the junction name. | 
|---|
 | 155 | ############################# | 
|---|
 | 156 | # Ensure the junction path name is fully qualified. | 
|---|
 | 157 | [[ $junctionName != /* ]] && junctionName="${PWD%/}/${junctionName}" | 
|---|
 | 158 | junctionName=${junctionName%%/}  # Strip any trailing slashes. | 
|---|
 | 159 |  | 
|---|
 | 160 | checkName lengthCheckOnly 1023 "$junctionName" | 
|---|
 | 161 | [[ $? -ne 0 ]] && cleanupAndExit | 
|---|
 | 162 |  | 
|---|
 | 163 | # Find the last component of the junction name and its parent directory. | 
|---|
 | 164 | junctionBaseName=${junctionName##*/} | 
|---|
 | 165 | junctionParentDir=${junctionName%/*} | 
|---|
 | 166 |  | 
|---|
 | 167 | checkName junctionName 255 "$junctionBaseName" | 
|---|
 | 168 | [[ $? -ne 0 ]] && cleanupAndExit | 
|---|
 | 169 |  | 
|---|
 | 170 | if [[ $junctionBaseName = '.' || $junctionBaseName = '..' ]] | 
|---|
 | 171 | then | 
|---|
 | 172 |   # Name is not allowed. | 
|---|
 | 173 |   printErrorMsg 551 $mmcmd "$junctionName" | 
|---|
 | 174 |   cleanupAndExit | 
|---|
 | 175 | fi | 
|---|
 | 176 |  | 
|---|
 | 177 | # Find the device ID and inode number of the new junction's parent directory. | 
|---|
 | 178 | # The result is a colon-separated device and inode numbers. | 
|---|
 | 179 | junctionDevAndIno=$($perl -e ' ($dev,$ino) = stat "'$junctionParentDir'"; | 
|---|
 | 180 |                                if ($dev ne "") { printf "%u:%u", $dev,$ino }') | 
|---|
 | 181 |  | 
|---|
 | 182 | # The new junction must be created within the mounted file system. | 
|---|
 | 183 | if [[ $gpfsDeviceID != ${junctionDevAndIno%:*} ]] | 
|---|
 | 184 | then | 
|---|
 | 185 |   printErrorMsg 550 $mmcmd "$junctionName" $device | 
|---|
 | 186 |   cleanupAndExit | 
|---|
 | 187 | fi | 
|---|
 | 188 |  | 
|---|
 | 189 | # Create the extended junction path name. | 
|---|
 | 190 | junctionName="/GPFS:${junctionDevAndIno#*:}${junctionName}" | 
|---|
 | 191 |  | 
|---|
 | 192 |  | 
|---|
 | 193 | #################################### | 
|---|
 | 194 | # Invoke the tslinkfileset command. | 
|---|
 | 195 | #################################### | 
|---|
 | 196 | $tslinkfileset $fqDeviceName "$filesetName" -J "$junctionName" | 
|---|
 | 197 | rc=$(remapRC $?) | 
|---|
 | 198 |  | 
|---|
 | 199 | if [[ $rc -eq $MM_DaemonDown ]] | 
|---|
 | 200 | then | 
|---|
 | 201 |   # GPFS is down on this node. | 
|---|
 | 202 |   printErrorMsg 109 $mmcmd | 
|---|
 | 203 | elif [[ $rc -eq $MM_QuorumWait ]] | 
|---|
 | 204 | then | 
|---|
 | 205 |   # GPFS is not ready for commands. | 
|---|
 | 206 |   printErrorMsg 110 $mmcmd | 
|---|
 | 207 | elif [[ $rc -eq $MM_ConnectionReset ]] | 
|---|
 | 208 | then | 
|---|
 | 209 |   # An internode connection was reset. | 
|---|
 | 210 |   printErrorMsg 257 $mmcmd | 
|---|
 | 211 | else | 
|---|
 | 212 |   # Either the command worked, or it is an unexpected error. | 
|---|
 | 213 |   : # [[ $rc -ne 0 ]] && printErrorMsg 113 "$mmcmd" "tslinkfileset" $rc | 
|---|
 | 214 | fi  # end of if [[ $rc -eq $MM_FsNotFound ]] | 
|---|
 | 215 |  | 
|---|
 | 216 | # if [[ $rc -ne 0 ]] | 
|---|
 | 217 | # then | 
|---|
 | 218 | #   # tslinkfileset failed. | 
|---|
 | 219 | #   printErrorMsg 104 $mmcmd tslinkfileset | 
|---|
 | 220 | #   cleanupAndExit $rc | 
|---|
 | 221 | # fi | 
|---|
 | 222 |  | 
|---|
 | 223 | cleanupAndExit $rc | 
|---|
 | 224 |  | 
|---|