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

Last change on this file since 223 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 11.5 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# @(#)22 1.4.1.2 src/avs/fs/mmfs/ts/admin/mmumount.sh, mmfs, avs_rgpfs24, rgpfs24s006a 8/29/06 15:12:46
17##############################################################################
18#
19#  Unmount GPFS file systems on one or more nodes in the cluster.
20#
21#  Usage:
22#    mmumount {Device | MountPoint | all | all_local | all_remote} [-f]
23#             [-a | -N {Node[,Node...] | NodeFile | NodeClass}]
24#  or
25#    mmumount Device -f -C {all_remote | ClusterName} [-N Node[,Node...]]
26#
27#  where:
28#
29#    Device | MountPoint | all | all_local | all_remote
30#        Specifies the file systems to be unmounted.
31#        Only file systems that are owned by this cluster can be specified
32#        in conjuction with the -C option.
33#
34#    -a  Unmount the file systems on all nodes in the cluster.
35#
36#    -f  Force the unmount to take place even though the file system may
37#        still be in use.
38#
39#    -N {Node[,Node...] | NodeFile | NodeClass}
40#        Specifies the nodes on which the unmount is to take place.
41#
42#    -C { all_remote | ClusterName }
43#        Specifies the clusters on which the file system is to be unmounted.
44#        Only remote clusters should be specified with this form of the command.
45#        Use the first form of the command to unmount file systems on nodes in
46#        the local cluster.
47#
48#        -C all_remote denotes all clusters other than the one from which
49#        the command is ussued (this cluster).
50#
51#
52#  Usage notes:
53#
54#    If not explicitly-specified otherwise, the file systems are unmounted on
55#    the local node only.
56#
57#    The first form of the command should be used to unmount file systems on
58#    nodes that belong to the local cluster.
59#
60#    The second form of the command should be used when it is necessary to
61#    internally force unmount file systems that are owned by this cluster
62#    but are mounted on nodes that belong to some other cluster.
63#
64#    When a file system is internally force unmounted with the second form of
65#    the mmumount command, the affected nodes may still show the file system
66#    as mounted (although the data is not accessible).  It is the responsibility
67#    of the system administrator to clear the mount state by issuing the OS
68#    umount command.
69#
70#    When the -N parameter is specified in conjunction with -C ClusterName,
71#    the specified node names are assumed to refer to nodes that belong to
72#    the specified remote cluster (as shown by mmlsmount).  The mmunmount
73#    command cannot verify upfront the accuracy of this information.
74#
75##############################################################################
76
77# Include global declarations and service routines.
78. /usr/lpp/mmfs/bin/mmglobfuncs
79. /usr/lpp/mmfs/bin/mmsdrfsdef
80
81sourceFile="mmumount.sh"
82[[ -n $DEBUG || -n $DEBUGmmumount ]] && set -x
83$mmTRACE_ENTER "$*"
84
85
86# Local variables
87
88usageMsg=396
89rc=0
90
91
92#######################
93# Mainline processing
94#######################
95
96
97##################################
98# Process each of the arguments.
99##################################
100[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
101  syntaxError "help" $usageMsg
102
103[[ $argc -lt 1  ]] &&  \
104  syntaxError "missingArgs" $usageMsg
105
106# Figure out what was specified on the command line.
107if [[ $arg1 = /* && $arg1 != +(/)dev+(/)* ]]
108then
109  # If the first argument starts with a "/" but not "/dev/",
110  # it is assumed to be a fully-qualified mount point.
111  mountPoint=$arg1
112else
113  # Otherwise, the argument is assumed to be the device name
114  # of a file system (or the key word "all").
115  device=$arg1
116  deviceName=${device##+(/)dev+(/)}  # Name stripped of /dev/ prefix.
117fi  # end of if [[ $arg1 = "/"* && $arg1 != +(/)dev+(/)* ]]
118
119# Drop the name from the parameter list.
120shift 1
121
122# Process the rest of the options.
123while getopts :afC:N: OPT
124do
125  case $OPT in
126
127    a) [[ -n $aflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
128       aflag="-$OPT"
129       [[ -n $Nflag ]] &&  \
130         syntaxError "invalidCombination" $usageMsg "-a" "-N"
131       [[ -n $Cflag ]] &&  \
132         syntaxError "invalidCombination" $usageMsg "-a" "-C"
133       initRequired=yes
134       ;;
135
136    f) [[ -n $fflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
137       fflag="-$OPT"
138       ;;
139
140    C) [[ -n $Cflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
141       Cflag="-$OPT"
142       clusterName="$OPTARG"
143       [[ -n $aflag ]] &&  \
144         syntaxError "invalidCombination" $usageMsg "-a" "-C"
145       [[ -n $mountPoint ]] &&  \
146         syntaxError "help" $usageMsg
147       [[ $clusterName = *,* ]] &&  \
148         syntaxError "help" $usageMsg
149       initRequired=yes
150       ;;
151
152    N) [[ -n $Nflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
153       Nflag="-$OPT"
154       nodenames="$OPTARG"
155       [[ -n $aflag ]] &&  \
156         syntaxError "invalidCombination" $usageMsg "-a" "-N"
157       initRequired=yes
158       ;;
159
160    :) syntaxError "missingValue" $usageMsg $OPTARG
161       ;;
162
163    +[afCN])
164       syntaxError "invalidOption" $usageMsg "$OPT"
165       ;;
166
167    *) syntaxError "invalidOption" $usageMsg $OPTARG
168       ;;
169
170  esac
171done
172
173shift OPTIND-1
174[[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
175
176# Some additional restrictions for the -C version of the command.
177if [[ -n $Cflag ]]
178then
179  [[ $clusterName = *,* ]] && syntaxError "help" $usageMsg
180  [[ -n $mountPoint ]] && syntaxError "help" $usageMsg
181  [[ $device = all  ]] && device=all_local
182fi
183
184
185##################################################################
186# Set up trap exception handling.  If more than the local node
187# is affected, ensure the local copy of the mmsdrfs and the rest
188# of the GPFS system files are up-to-date.
189##################################################################
190trap pretrap2 HUP INT QUIT KILL
191if [[ -n $initRequired ]]
192then
193  gpfsInitOutput=$(gpfsInit nolock)
194  setGlobalVar $? $gpfsInitOutput
195fi
196
197
198#######################################################
199# Create a file containing all of the specified nodes.
200#######################################################
201if [[ -n $aflag ]]
202then
203  # Get a list of the nodes.
204  getNodeList $REL_HOSTNAME_Field $GLOBAL_ID $mmsdrfsFile > $nodefile
205
206elif [[ -n $Cflag ]]
207then
208  # Get a list of the nodes in this cluster.
209  getNodeList $REL_HOSTNAME_Field $GLOBAL_ID $mmsdrfsFile > $nodefile
210
211  # Decide what to pass to the tsunmount command.
212  # If the -N option is specified in conjuction with -C,
213  # the scope is limited to the specified nodes.
214  if [[ -n $Nflag ]]
215  then
216    affectedNodes="-n $nodenames"
217  else
218    affectedNodes="-C $clusterName"
219  fi
220
221elif [[ -n $Nflag ]]
222then
223  # Convert the passed data into a file containing admin node names.
224  createVerifiedNodefile "$nodenames" $REL_HOSTNAME_Field no $nodefile
225  [[ $? -ne 0 ]] && cleanupAndExit
226
227else
228  : # Nothing to do.  Only the local node is affected.
229fi  # end of if [[ -n $aflag ]]
230
231
232######################################
233# Verify the file system device name.
234######################################
235if [[ $device = all ]]
236then
237  # Ensure there are file systems to unmount.
238  $awk -F: '                                \
239    BEGIN { rc = '$MM_FsNotFound' }         \
240    $'$LINE_TYPE_Field' == "'$SG_HEADR'" {  \
241      { rc = 0 }                            \
242      { exit }                              \
243    }                                       \
244  END { exit rc }                           \
245  ' $mmsdrfsFile
246  rc=$?
247
248  if [[ $rc = $MM_FsNotFound ]]
249  then
250    # No file systems were found in the cluster.
251    printErrorMsg 200 $mmcmd
252    cleanupAndExit $rc
253  else
254    # Check for unexpected errors
255    checkForErrors awk $rc
256  fi
257
258  fsList=all
259
260elif [[ $device = all_local ]]
261then
262  # Create a list of the file systems to unmount.
263  fsList=$($awk -F: '                        \
264    $'$LINE_TYPE_Field' == "'$SG_HEADR'" &&  \
265    $'$FS_TYPE_Field'   == "'$localfs'"   {  \
266      { printf $'$DEV_NAME_Field' "," }      \
267    }                                        \
268  ' $mmsdrfsFile)
269  checkForErrors awk $rc
270
271  if [[ -z $fsList ]]
272  then
273    # No file systems were found in the cluster.
274    printErrorMsg 200 $mmcmd
275    cleanupAndExit $MM_FsNotFound
276  fi
277
278  fsList=${fsList%%,}
279
280elif [[ $device = all_remote ]]
281then
282  # Only locally owned file systems can be specified with the -C option.
283  if [[ -n $Cflag ]]
284  then
285    # Command is not allowed for remote file systems.
286    printErrorMsg 469 $mmcmd $Cflag
287    cleanupAndExit
288  fi
289
290  # Create a list of the file systems to unmount.
291  fsList=$($awk -F: '                        \
292    $'$LINE_TYPE_Field' == "'$SG_HEADR'" &&  \
293    $'$FS_TYPE_Field'   == "'$remotefs'"  {  \
294      { printf $'$DEV_NAME_Field' "," }      \
295    }                                        \
296  ' $mmsdrfsFile)
297  checkForErrors awk $rc
298
299  if [[ -z $fsList ]]
300  then
301    # No remote file systems were found in the cluster.
302    printErrorMsg 193 $mmcmd
303    cleanupAndExit $MM_FsNotFound
304  fi
305
306  fsList=${fsList%%,}
307
308elif [[ -n $device ]]
309then
310  # Ensure the specified file system exists.
311  findFSoutput=$(findFS "$device" $mmsdrfsFile device)
312  [[ -z $findFSoutput ]] && cleanupAndExit
313
314  # Parse the output from the findFS function.
315  set -f ; set -- $findFSoutput ; set +f
316  fqDeviceName=$1
317  deviceName=$2
318  fsHomeCluster=$3
319
320  # Only locally owned file systems can be specified with the -C option.
321  if [[ -n $Cflag && $fsHomeCluster != $HOME_CLUSTER ]]
322  then
323    # Command is not allowed for remote file systems.
324    printErrorMsg 472 $mmcmd $device $fsHomeCluster $Cflag
325    cleanupAndExit
326  fi
327
328  fsList=$deviceName
329
330else
331  # A mount point was specified.  Since it can be anything,
332  # there is no point in searching the mmsdrfs file.
333  : # Let the unmount function handle it.
334fi  # end of if [[ $device = all ]]
335
336# Ensure we have the proper credentials.
337[[ $getCredCalled = no ]] && getCred
338
339
340###################################################
341# Unmount the file systems on the specified nodes.
342###################################################
343
344# Unmounting file systems ...
345printInfoMsg 426 "$(date)" $mmcmd
346
347if [[ ! -s $nodefile ]]
348then
349  # The request is to unmount file systems on the local node only.
350  if [[ -n $device ]]
351  then
352    $mmremote unmountFileSystems $fsList "$fflag"
353    rc=$?
354  else
355    $mmremote unmountMountpoint $mountPoint "$fflag"
356    rc=$?
357  fi
358
359elif [[ -n $Cflag ]]
360then
361  # The request is to internally force unmount one or more file systems.
362  IFS=','
363  for deviceName in $fsList
364  do
365    IFS="$IFS_sv"
366    $mmcommon onactive $preferredNode $nodefile                     \
367                       $NO_FILE_COPY $NO_MOUNT_CHECK NULL $NO_LINK  \
368                       tsunmount "$deviceName $affectedNodes"
369    IFS=',' # Move to the next file system.
370  done  # end of for deviceName in $fsList
371  IFS="$IFS_sv"
372
373else
374  # The request is to unmount file systems on a number
375  # of nodes in the local cluster.
376  if [[ -n $device ]]
377  then
378    $mmcommon onall $nodefile $unreachedNodes  \
379      unmountFileSystems $fsList "$fflag"
380    rc=$?
381  else
382    $mmcommon onall $nodefile $unreachedNodes  \
383      unmountMountpoint $mountPoint "$fflag"
384    rc=$?
385  fi
386fi  # end of if [[ ! -s $nodefile ]]
387
388# If any nodes could not be reached, tell the user which ones.
389if [[ -s $unreachedNodes ]]
390then
391  # The following nodes could not be reached: . . .
392  printErrorMsg 270 $mmcmd
393  $cat $unreachedNodes 1>&2
394fi
395
396cleanupAndExit $rc
397
Note: See TracBrowser for help on using the repository browser.