source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmchdisk @ 250

Last change on this file since 250 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 11.7 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. 1999,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# @(#)78 1.40 src/avs/fs/mmfs/ts/admin/mmchdisk.sh, mmfs, avs_rgpfs24, rgpfs240610b 11/11/05 09:29:00
17#########################################################################
18#
19# Usage:
20#   mmchdisk Device {resume | start} -a
21#            [-N {all | mount | Node[,Node...] | NodeFile | NodeClass}]
22# or
23#   mmchdisk Device {suspend | resume | stop | start | change}
24#            -d "DiskDesc[;DiskDesc...]"
25#            [-N {all | mount | Node[,Node...] | NodeFile | NodeClass}]
26#
27#########################################################################
28
29# Include global declarations and service routines.
30. /usr/lpp/mmfs/bin/mmglobfuncs
31. /usr/lpp/mmfs/bin/mmsdrfsdef
32. /usr/lpp/mmfs/bin/mmfsfuncs
33
34sourceFile="mmchdisk.sh"
35[[ -n $DEBUG || -n $DEBUGmmchdisk ]] && set -x
36$mmTRACE_ENTER "$*"
37
38
39# Local variables
40
41usageMsg=287
42integer rc=0
43integer nodeCount=0
44# argList=""   # argList without quotes around disk list
45# argListQ=""  # argList with quotes around disk list
46
47
48#####################################################################
49# Process the command arguments.
50#####################################################################
51[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
52  syntaxError "help" $usageMsg
53
54[[ $argc -lt 2  ]] &&  \
55  syntaxError "missingArgs" $usageMsg
56
57device=$arg1     # file system name (always the first parameter)
58action=$arg2     # action to be taken for the disks (always the 2nd parameter)
59shift 2          # Drop the device name and disk state from the parameter list.
60
61# Parse the optional parameters.  Special care must be taken when creating
62# argList because the disk names in the -d option are separated by the ';'
63# character.  For invocations via mmcommon, the argument lists must be
64# enclosed in quotes.  For direct (local) invocations of tschdisk,
65# the argument lists must not have surrounding quotes.  Detailed checking
66# of supported keywords is left to tschdisk.
67while getopts :ad:N: OPT
68do
69  case $OPT in
70    a) # Change the state of all disks in the file system.
71       [[ -n $aflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
72       [[ -n $dflag ]] &&  \
73         syntaxError "invalidCombination"  $usageMsg "-a" "-d"
74       aflag=yes
75       argList="$action -$OPT"
76       argListQ="$action -$OPT"
77       ;;
78
79    d) # Change the state of the specified disks.
80       [[ -n $dflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
81       [[ -n $aflag ]] &&  \
82         syntaxError "invalidCombination"  $usageMsg "-a" "-d"
83       diskDescList=$OPTARG
84       dflag=yes
85       [[ "$diskDescList" = *+([,${BLANKchar}${TABchar}])* ]] &&  \
86         syntaxError "badSeparator_notSemicolon" $noUsageMsg
87       argList="$action -$OPT $OPTARG "
88       argListQ="$action -$OPT \"$OPTARG\" "
89       ;;
90
91    N) # Specify the nodes on which to restripe.
92       [[ -n $Nflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
93       nodeList="$OPTARG"
94       Nflag="-N $OPTARG"
95       ;;
96
97    :) # missing required value after an option
98       syntaxError "missingValue" $usageMsg $OPTARG
99       ;;
100
101    +[adN]) # plus flags are not allowed
102       syntaxError "invalidOption" $usageMsg $OPT
103       ;;
104
105    *) # invalid option specified
106       syntaxError "invalidOption" $usageMsg $OPTARG
107       ;;
108   esac
109done
110
111shift OPTIND-1
112[[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
113
114
115########################################################################
116# Set up trap exception handling and call the gpfsInit function.
117# It will ensure that the local copy of the mmsdrfs and the rest of the
118# GPFS system files are up-to-date.  We only lock the sdr if mmchdisk
119# was invoked with the change action.
120########################################################################
121if [[ $action = change ]]
122then
123  trap pretrap HUP INT QUIT KILL
124  gpfsInitOutput=$(gpfsInit $lockId)
125else
126  trap pretrap2 HUP INT QUIT KILL
127  gpfsInitOutput=$(gpfsInit nolock)
128fi
129setGlobalVar $? $gpfsInitOutput
130
131# Determine the lookup order for resolving host names.
132[[ $osName != AIX ]] && resolveOrder=$(setHostResolveOrder)
133
134
135###########################################################
136# Make sure the specified file system exists and is local.
137###########################################################
138findFSoutput=$(findFS "$device" $mmsdrfsFile)
139[[ -z $findFSoutput ]] && cleanupAndExit
140
141# Parse the output from the findFS function.
142set -f ; set -- $findFSoutput ; set +f
143fqDeviceName=$1
144deviceName=$2
145fsHomeCluster=$3
146
147# Exit with a message if the command was invoked for a remote file system.
148if [[ $fsHomeCluster != $HOME_CLUSTER ]]
149then
150  # Command is not allowed for remote file systems.
151  printErrorMsg 106 $mmcmd $device $fsHomeCluster
152  cleanupAndExit
153fi
154
155
156###################################################################
157# If a keyword or a list of nodes was specified via the -N option,
158# verify the input and add it to the argList and argListQ strings.
159###################################################################
160if [[ -n $Nflag ]]
161then
162  if [[ $nodeList = all || $nodeList = mount ]]
163  then
164    # Add the keyword ("all" or "mount") to the argList and argListQ strings.
165    argList="$argList -N $nodeList "
166    argListQ="$argListQ -N \"$nodeList\" "
167  else
168    # Verify the node list and convert it to a file of daemon node names.
169    createVerifiedNodefile "$nodeList" $DAEMON_NODENAME_Field no $nodefile
170    [[ $? -ne 0 ]] && cleanupAndExit
171
172    # Convert the output data from a file to a comma-separated list.
173    newNodeList=$(print -- $(cat $nodefile) | $sed 's/ /,/g')
174
175    # Add the verified node list to the argList and argListQ strings.
176    argList="$argList -N $newNodeList "
177    argListQ="$argListQ -N \"$newNodeList\" "
178  fi  # end of if [[ $nodeList = all || $nodeList = mount ]]
179fi  # end of if [[ -n $Nflag ]]
180
181
182#######################################################################
183# If the cluster to which this node belongs is the same as the cluster
184# in which the file system resides, invoke the command directly.
185#######################################################################
186if [[ $nsId = $fsHomeCluster ]]
187then
188  ${mmcmdDir}/${links}/mmchdisk $fqDeviceName $argList 2>$errMsg
189  rc=$(remapRC $?)
190
191  # If the command completed successfully, or if there is an
192  # unacceptable error, display any error messages and get out.
193  # If the action was "change", update the mmsdrfs file before exiting.
194  if [[ $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait ]]
195  then
196    [[ -s $errMsg ]] && $cat $errMsg 1>&2
197    if [[ $rc -eq $MM_ConnectionReset ]]
198    then
199      # An internode connection was reset.
200      printErrorMsg 257 $mmcmd
201    fi
202
203    # Update the mmsdrfs file and unlock the sdr if the action was "change".
204    if [[ $action = change ]]
205    then
206      # Reconcile the sdrfs file with the GPFS daemon's view of the filesystem.
207      $cp $mmsdrfsFile $newsdrfs
208      reconcileSdrfsWithDaemon $deviceName $newsdrfs
209      rc2=$?
210      if [[ $rc2 -ne 0 ]]
211      then
212        # reconcileSdrfsWithDaemon failed.
213        printErrorMsg 171 $mmcmd reconcileSdrfsWithDaemon $rc2
214        # Tell the user to run mmcommon recoverfs against the file system.
215        printErrorMsg 190 $mmcmd $deviceName $deviceName
216        cleanupAndExit $rc
217      fi
218
219      # Get the generation number from the version line of the new sdrfs file.
220      versionLine=$($head -1 $newsdrfs)
221      IFS=':'
222      set -f ; set -- $versionLine ; set +f
223      newGenNumber=$6
224      IFS="$IFS_sv"
225
226      # Commit the reconciled version of the sdrfs file to the server
227      # so the admin scripts and the daemon are in sync.
228      trap "" HUP INT QUIT KILL   # Disable interrupts until the commit is done.
229      gpfsObjectInfo=$(commitChanges $fsHomeCluster $nsId $gpfsObjectInfo  \
230                         $newGenNumber $newsdrfs $primaryServer)
231      if [[ $? -ne 0 ]]
232      then
233        # We were unable to replace the file in the sdr.
234        printErrorMsg 381 $mmcmd
235        # Tell the user to run mmcommon recoverfs against the filesystem.
236        printErrorMsg 190 $mmcmd $deviceName $deviceName
237      fi
238
239      # Unlock the sdr.
240      [[ $sdrLocked = yes ]] &&  \
241        freeLockOnServer $primaryServer $ourNodeNumber >/dev/null
242      sdrLocked=no
243      trap localPosttrap HUP INT QUIT KILL
244
245      # Propagate the new mmsdrfs file.  This process is asynchronous.
246      propagateSdrfsFile async $nodefile $newsdrfs $newGenNumber
247
248    fi  # end of if [[ $action = change ]]
249
250    cleanupAndExit $rc
251
252  fi  # end of if [[ $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait ]]
253
254fi  # end of if [[ $nsId = $fsHomeCluster ]]
255$rm -f $errMsg
256
257
258############################################################################
259# If the local daemon is not available, send the command to an active node.
260############################################################################
261
262# Create a file with the reliable names of the nodes
263# in the cluster to which the file system belongs.
264nodeCount=$(getNodeFile $REL_HOSTNAME_Field $fsHomeCluster $mmsdrfsFile $nodefile)
265if [[ $nodeCount -eq 0 ]]
266then
267  # The cluster is empty; there is nobody to run the command.
268  printErrorMsg 171 $mmcmd "getNodeFile (nodeCount=0)" 1
269  cleanupAndExit
270fi
271
272# Try the nodes one by one until you find a node that can execute the command.
273preferredNode=0     # We have no idea where to go first; let mmcommon decide.
274$mmcommon linkCommand $preferredNode $nodefile mmchdisk $fqDeviceName "$argListQ"
275rc=$?
276
277# Update the mmsdrfs file and unlock the sdr if the action was "change"
278# and the cluster state allowed the mmchdisk to be attempted.
279if [[ $action = change ]]
280then
281  if [[ $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait ]]
282  then
283    # Reconcile the sdrfs file with the GPFS daemon's view of the filesystem.
284    $cp $mmsdrfsFile $newsdrfs
285    reconcileSdrfsWithDaemon $deviceName $newsdrfs
286    rc2=$?
287    if [[ $rc2 -ne 0 ]]
288    then
289      # reconcileSdrfsWithDaemon failed.
290      printErrorMsg 171 $mmcmd reconcileSdrfsWithDaemon $rc2
291      # Tell the user to run mmcommon recoverfs against the file system.
292      printErrorMsg 190 $mmcmd $deviceName $deviceName
293      cleanupAndExit $rc
294    fi
295
296    # Get the generation number from the version line of the new sdrfs file.
297    versionLine=$($head -1 $newsdrfs)
298    IFS=':'
299    set -f ; set -- $versionLine ; set +f
300    newGenNumber=$6
301    IFS="$IFS_sv"
302
303    # Commit the reconciled version of the sdrfs file to the server
304    # so the admin scripts and the daemon are in sync.
305    trap "" HUP INT QUIT KILL   # Disable interrupts until the commit is done.
306    gpfsObjectInfo=$(commitChanges $fsHomeCluster $nsId $gpfsObjectInfo  \
307                       $newGenNumber $newsdrfs $primaryServer)
308    if [[ $? -ne 0 ]]
309    then
310      # We were unable to replace the file in the sdr.
311      printErrorMsg 381 $mmcmd
312      # Tell the user to run mmcommon recoverfs against the filesystem.
313      printErrorMsg 190 $mmcmd $deviceName $deviceName
314    fi
315
316    # Unlock the sdr.
317    [[ $sdrLocked = yes ]] &&  \
318      freeLockOnServer $primaryServer $ourNodeNumber >/dev/null
319    sdrLocked=no
320    trap localPosttrap HUP INT QUIT KILL
321
322    # Propagate the new mmsdrfs file.  This process is asynchronous.
323    propagateSdrfsFile async $nodefile $newsdrfs $newGenNumber
324
325  else
326    # The cluster state did not allow mmchdisk to run.  Just unlock the sdr.
327    [[ $sdrLocked = yes ]] &&  \
328      freeLockOnServer $primaryServer $ourNodeNumber >/dev/null
329    sdrLocked=no
330    trap localPosttrap HUP INT QUIT KILL
331
332  fi  # end of if [[ $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait ]]
333
334fi  # end of if [[ $action = change ]]
335
336cleanupAndExit $rc
337
Note: See TracBrowser for help on using the repository browser.