source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmlinkfileset @ 223

Last change on this file since 223 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 6.2 KB
Line 
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
37sourceFile="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
44LOCAL_FILES=" "
45
46
47# Local variables
48usageMsg=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.
70device=$arg1
71deviceName=${device##+(/)dev+(/)}  # name stripped of /dev/ prefix
72fqDeviceName="/dev/$deviceName"    # fully-qualified name (with /dev/ prefix)
73
74# The second argument is always the fileset name.
75filesetName=$arg2
76
77# Move past the positional parameters.
78shift 2
79
80# Process the rest of the parameters.
81while getopts :J: OPT
82do
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
102done  # end of while getopts :J: OPT do
103shift 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######################################################################
115trap pretrap2 HUP INT QUIT KILL
116gpfsInitOutput=$(gpfsInit nolock)
117setGlobalVar $? $gpfsInitOutput
118
119
120###########################################################
121# Make sure the specified file system exists and is local.
122###########################################################
123findFSoutput=$(findFS "$device" $mmsdrfsFile)
124[[ -z $findFSoutput ]] && cleanupAndExit
125
126# Parse the output from the findFS function.
127set -f ; set -- $findFSoutput ; set +f
128fqDeviceName=$1
129deviceName=$2
130fsHomeCluster=$3
131
132# Exit if the command was invoked for a remote file system.
133if [[ $fsHomeCluster != $HOME_CLUSTER ]]
134then
135  # Command is not allowed for remote file systems.
136  printErrorMsg 106 $mmcmd $device $fsHomeCluster
137  cleanupAndExit
138fi
139
140# The file system must be mounted.
141mountPoint=$(findMountpoint $deviceName)
142if [[ -z $mountPoint ]]
143then
144  # File system is not mounted.
145  printErrorMsg 552 $mmcmd $device
146  cleanupAndExit
147fi
148
149# Find the device ID of the mounted GPFS file system.
150gpfsDeviceID=$($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}"
158junctionName=${junctionName%%/}  # Strip any trailing slashes.
159
160checkName lengthCheckOnly 1023 "$junctionName"
161[[ $? -ne 0 ]] && cleanupAndExit
162
163# Find the last component of the junction name and its parent directory.
164junctionBaseName=${junctionName##*/}
165junctionParentDir=${junctionName%/*}
166
167checkName junctionName 255 "$junctionBaseName"
168[[ $? -ne 0 ]] && cleanupAndExit
169
170if [[ $junctionBaseName = '.' || $junctionBaseName = '..' ]]
171then
172  # Name is not allowed.
173  printErrorMsg 551 $mmcmd "$junctionName"
174  cleanupAndExit
175fi
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.
179junctionDevAndIno=$($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.
183if [[ $gpfsDeviceID != ${junctionDevAndIno%:*} ]]
184then
185  printErrorMsg 550 $mmcmd "$junctionName" $device
186  cleanupAndExit
187fi
188
189# Create the extended junction path name.
190junctionName="/GPFS:${junctionDevAndIno#*:}${junctionName}"
191
192
193####################################
194# Invoke the tslinkfileset command.
195####################################
196$tslinkfileset $fqDeviceName "$filesetName" -J "$junctionName"
197rc=$(remapRC $?)
198
199if [[ $rc -eq $MM_DaemonDown ]]
200then
201  # GPFS is down on this node.
202  printErrorMsg 109 $mmcmd
203elif [[ $rc -eq $MM_QuorumWait ]]
204then
205  # GPFS is not ready for commands.
206  printErrorMsg 110 $mmcmd
207elif [[ $rc -eq $MM_ConnectionReset ]]
208then
209  # An internode connection was reset.
210  printErrorMsg 257 $mmcmd
211else
212  # Either the command worked, or it is an unexpected error.
213  : # [[ $rc -ne 0 ]] && printErrorMsg 113 "$mmcmd" "tslinkfileset" $rc
214fi  # 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
223cleanupAndExit $rc
224
Note: See TracBrowser for help on using the repository browser.