source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmsetrcmd @ 65

Last change on this file since 65 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 13.6 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. 2001,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# @(#)97 1.23 src/avs/fs/mmfs/ts/admin/mmsetrcmd.sh, mmfs, avs_rgpfs24, rgpfs240610b 12/5/05 15:41:55
17##############################################################################
18#
19#  Usage:
20#    mmsetrcmd {[-r RemoteShellCommand] [-R RemoteFileCopyCommand]} [-f]
21#  or
22#    mmsetrcmd -C ClusterName
23#
24#  where:
25#
26#    -r remoteShellCommand     specifies the fully qualified pathname for
27#                              the remote shell program to be used by GPFS.
28#                              The default is /usr/bin/rsh.
29#
30#    -R remoteFileCopyCommand  specifies the fully qualified pathname for
31#                              the remote file copy program to be used
32#                              by GPFS.  The default is /usr/bin/rcp.
33#
34#    -f                  Force option.  Make the change only on the node on
35#                        which the command is executed.  Do not fail if the
36#                        local copy of /var/mmsdrfs cannot be refreshed.
37#                        This option is intended to be used on nodes that
38#                        were not available when the mmchcluster command
39#                        was executed.  The option is not documented.
40#
41#    -C ClusterName      specifies a new name for the cluster.  If the name
42#                        contains dots it is assumed to be a fully qualified
43#                        domain name.  Otherwise, the domain will default
44#                        to the domain of the primary configuration server.
45#
46##############################################################################
47
48# Include global declarations and service routines
49. /usr/lpp/mmfs/bin/mmglobfuncs
50. /usr/lpp/mmfs/bin/mmsdrfsdef
51
52sourceFile="mmsetrcmd.sh"
53[[ -n $DEBUG || -n $DEBUGmmsetrcmd ]] && set -x
54$mmTRACE_ENTER "$*"
55
56
57# Local work files.  Names should be of the form:
58#   fn=${tmpDir}fn.${mmcmd}.$$
59
60LOCAL_FILES=" "
61
62
63# Local declarations
64
65usageMsg=425
66fflag=""
67rflag=""
68Rflag=""
69rarg=""
70Rarg=""
71rc=0
72
73
74# Local routines
75
76#####################################################################
77#
78# This function simulates the real gpfsInit and extracts the global
79# variable information from the local mmsdrfs file.  It is intended
80# for use when the real gpfsInit fails for some reason.
81#
82# Note: Locking makes no sense in this context.
83#
84#####################################################################
85function gpfsInit_Local
86{
87  typeset sourceFile="mmsetrcmd.sh"
88  [[ -n $DEBUG || -n $DEBUGgpfsInit_Local ]] && set -x
89  $mmTRACE_ENTER "$*"
90
91  typeset localGenNumber localGenTimestamp versionLine mmmode
92  typeset primaryServer backupServer gpfsObjectInfo
93  typeset sdrfsFormatLevel rshPath rcpPath environmentType
94
95
96  versionLine=$($head -1 $mmsdrfsFile)
97  IFS=':'
98  set -f ; set -A v -- - $versionLine ; set +f
99  IFS="$IFS_sv"
100
101  # Perform a quick sanity check.
102  [[ ${v[$LINE_TYPE_Field]} != $VERSION_LINE ]] && \
103    corruptedSdrFileExit 144 "$versionLine"
104
105  # Retrieve cluster environment information.
106  mmmode=${v[$CLUSTER_TYPE_Field]}
107  if [[ $mmmode != lc && $mmmode != single ]]
108  then
109    # Unknown GPFS execution environment
110    printErrorMsg 338 $mmcmd $mmmode
111    cleanupAndExit
112  fi
113
114  sdrfsFormatLevel=${v[$SDRFS_FORMAT_Field]}
115  localGenNumber=${v[$SDRFS_GENNUM_Field]}
116  gpfsObjectInfo="${sdrfsFormatLevel}:${localGenNumber}:"
117  primaryServer=${v[$PRIMARY_SERVER_Field]}
118  [[ -z $primaryServer ]] && primaryServer="_NOPRIMARY_"
119  backupServer=${v[$BACKUP_SERVER_Field]}
120  [[ -z $backupServer ]] && backupServer="_NOSECONDARY_"
121  localGenTimestamp=${v[$GENNUM_TSTAMP_Field]}
122  [[ -z $localGenTimestamp ]] && localGenTimestamp=0
123  rshPath=${v[$RSH_PATH_Field]}
124  [[ -z $rshPath ]] && rshPath="_DEFAULT_"
125  rcpPath=${v[$RCP_PATH_Field]}
126  [[ -z $rcpPath ]] && rcpPath="_DEFAULT_"
127  environmentType=${v[$CLUSTER_SUBTYPE_Field]}
128  [[ -z $environmentType ]] && environmentType=$mmmode
129  [[ $mmmode != $environmentType && $environmentType != lc2 ]] && \
130    environmentType="rpd"
131
132  # Make the mode value globally available
133  export MMMODE=$mmmode
134  export environmentType=$environmentType
135
136  # Export remote commands if necessary.
137  if [[ -n $rshPath && $rshPath != "_DEFAULT_" ]]
138  then
139    rsh="$rshPath"
140    export GPFS_rshPath="$rshPath"
141  fi
142  if [[ -n $rcpPath && $rcpPath != "_DEFAULT_" ]]
143  then
144    rcp="$rcpPath"
145    export GPFS_rcpPath="$rcpPath"
146  fi
147
148  # Locking does not work if we need this function.
149  sdrLocked=no
150
151  # Determine the local node data.  If file mmfsNodeData is
152  # missing, there is a need for manual intervention.
153  [[ ! -f $mmfsNodeData ]] && \
154    checkForErrors "gpfsInit_Local: Missing file $mmfsNodeData" 1
155  getLocalNodeData
156
157  print -- "$MMMODE $sdrLocked $HOME_CLUSTER $ourNodeNumber" \
158           "$gpfsObjectInfo $primaryServer $backupServer"    \
159           "$ourNodeName $rshPath $rcpPath $localGenNumber"  \
160           "$localGenTimestamp $environmentType"             \
161           "$ourShortName $sdrfsFormatLevel"
162  return 0
163
164}  #------------ end of function gpfsInit_Local ------------------------
165
166
167
168########################
169# Mainline processing
170########################
171
172
173#################################
174# Process the command arguments.
175#################################
176[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] && \
177  syntaxError "help" $usageMsg
178
179[[ $argc -lt 2  ]] && \
180  syntaxError "missingArgs" $usageMsg
181
182while getopts :C:fr:R: OPT
183do
184  case $OPT in
185
186    C) # cluster name
187       [[ -n $Cflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
188       Cflag="-$OPT"
189       Carg=$OPTARG
190       ;;
191
192    f) # force flag
193       [[ -n $fflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
194       fflag="-$OPT"
195       ;;
196
197    r) # remote shell command
198       [[ -n $rflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
199       rflag="-$OPT"
200       rarg=$OPTARG
201       [[ $rarg = ${rarg#/} ]] && \
202         syntaxError "absolutePath_2" $noUsageMsg "-$OPT" "$rarg"
203       [[ ! -x $rarg ]] && \
204         syntaxError "cannotOpenFile" $noUsageMsg "$OPTARG"
205       newRshPath=$rarg
206       ;;
207
208    R) # remote file copy command
209       [[ -n $Rflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
210       Rflag="-$OPT"
211       Rarg=$OPTARG
212       [[ $Rarg = ${Rarg#/} ]] && \
213         syntaxError "absolutePath_2" $noUsageMsg "-$OPT" "$Rarg"
214       [[ ! -x $Rarg ]] && \
215         syntaxError "cannotOpenFile" $noUsageMsg "$OPTARG"
216       newRcpPath=$Rarg
217       ;;
218
219    +[CfrR]) # Invalid option
220       syntaxError "invalidOption" $usageMsg $OPT
221       ;;
222
223    :) # Missing argument
224       syntaxError "missingValue" $usageMsg $OPTARG
225       ;;
226
227    *) # Invalid option
228       syntaxError "invalidOption" $usageMsg $OPTARG
229       ;;
230
231  esac
232
233done
234
235# Complete the parameter checking.
236shift OPTIND-1
237[[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
238
239
240#######################################################################
241# Set up trap exception handling and call the gpfsInit function.
242# It will ensure that the local copy of the mmsdrfs and the rest of
243# the GPFS system files are up-to-date and will obtain the sdr lock.
244# If this process fails, and the -f flag is specified, ignore the
245# error and proceed anyway.
246#######################################################################
247trap pretrap HUP INT QUIT KILL
248gpfsInitOutput=$(gpfsInit $lockId)
249rc=$?
250if [[ -z $fflag ]]
251then
252  setGlobalVar $rc $gpfsInitOutput
253elif [[ $rc -eq 0 ]]
254then
255  setGlobalVar $rc $gpfsInitOutput
256else
257  if [[ -f $mmsdrfsFile ]]
258  then
259    # gpfsInit failed but -f is specified.
260    # Parse the local mmsdrfs file to set up the global variables.
261    gpfsInitOutput=$(gpfsInit_Local nolock)
262    setGlobalVar $? $gpfsInitOutput
263  else
264    checkForErrors "Missing local file $mmsdrfsFile" $?
265  fi
266fi
267nodesetId=$nsId
268
269
270############################################################################
271# Make a new copy of the current mmsdrfs file with the appropriate changes.
272############################################################################
273$rm -f $newsdrfs $nodefile $tmpCfg
274IFS=":"         # Change the field separator to ':'.
275exec 3<&-
276exec 3< $mmsdrfsFile
277while read -u3 sdrfsLine
278do
279  # Parse the line.
280  set -f ; set -A v -- - $sdrfsLine ; set +f
281  IFS="$IFS_sv"
282  printLine=true
283
284  # Change some of the fields depending on the type of line.
285  case ${v[$LINE_TYPE_Field]} in
286
287    $VERSION_LINE )
288      # Increment the generation number if this is going
289      # to be a global change (-f flag is not specified).
290      if [[ -z $fflag ]]
291      then
292        newGenNumber=${v[$SDRFS_GENNUM_Field]}+1
293        v[$SDRFS_GENNUM_Field]=$newGenNumber
294      fi
295
296      # Change the remote commands as needed.
297      [[ -n $newRshPath ]] &&  \
298        v[$RSH_PATH_Field]=$newRshPath
299      [[ -n $newRcpPath ]] &&  \
300        v[$RCP_PATH_Field]=$newRcpPath
301
302      # Change the cluster name if asked.
303      if [[ -n $Cflag ]]
304      then
305        if [[ $Carg = "." ]]
306        then
307          clusterName=$primaryServer
308        elif [[ $Carg = *.* ]]
309        then
310          clusterName=$Carg
311        else
312          primaryServer=${v[$PRIMARY_SERVER_Field]}
313          clusterName=${Carg}.${primaryServer#*.}
314        fi
315        v[$CLUSTER_NAME_Field]=$clusterName
316        clusterId=${v[$CLUSTERID_Field]}
317      fi  # end if [[ -n $Cflag ]]
318      ;;
319
320    $MEMBER_NODE )
321      # Add the node's reliable name to the list of reliable names.
322      print -- "${v[$REL_HOSTNAME_Field]}" >> $nodefile
323      checkForErrors "writing to file $nodefile" $?
324      ;;
325
326    $MMFSCFG )
327      # If changing the cluster name, extract the mmfs.cfg data.
328      if [[ -n $Cflag ]]
329      then
330        # Remove the line from the mmsdrfs file for now.  The mmfs.cfg
331        # information will be added back before committing the changes.
332        printLine=false
333
334        # Extract the mmfs.cfg information.
335        # It is everything past the first 4 fields.
336        cfgLine="${v[5]}:${v[6]}:${v[7]}:${v[8]}:${v[9]}:${v[10]}:${v[11]}"
337        cfgLine="$cfgLine:${v[12]}:${v[13]}:${v[14]}:${v[15]}:${v[16]}"
338        cfgLine="$cfgLine:${v[17]}:${v[18]}:${v[19]}:${v[20]}:${v[21]}:${v[22]}"
339
340        # To preserve tabs, temporarily set IFS to new line only.
341        IFS="
342"
343        # Strip trailing colons and write the line to the file.
344        print -- "${cfgLine%%+(:)}" >> $tmpCfg
345        checkForErrors "writing to file $tmpCfg" $?
346        IFS="$IFS_sv"  # restore the default IFS settings
347      fi
348      ;;
349
350    * )
351      # If changing the cluster name, make sure we do not
352      # already have some remote cluster with the same name.
353      if [[ -n $Cflag && ${v[$NODESETID_Field]} = $clusterName ]]
354      then
355        print -u2 "$mmcmd: The name $clusterName is already in use."
356        # Command failed.
357        printErrorMsg 389 $mmcmd
358        cleanupAndExit
359      fi
360      ;;
361
362  esac  # end Change some of the fields
363
364  # Write the line to the new mmsdrfs file.
365  if [[ $printLine = true ]]
366  then
367    print_newLine >> $newsdrfs
368    checkForErrors "writing to file $newsdrfs" $?
369  fi
370
371  IFS=":"  # Change the separator back to ":" for the next iteration.
372
373done  # end while read -u3 sdrfsLine
374
375IFS="$IFS_sv"  # restore the default IFS settings
376
377
378###################################################################
379# If changing the cluster name, there are a few more things to do.
380###################################################################
381if [[ -n $Cflag ]]
382then
383  # Verify GPFS is stopped on all nodes.
384  printInfoMsg 339
385  verifyDaemonInactive $nodefile $mmcmd
386  [[ $? -ne 0 ]] && cleanupAndExit
387
388  # Change the clusterName parameter in the mmfs.cfg file.
389  $mmfixcfg "clusterName" "$clusterName" <$tmpCfg >$newcfg
390  checkForErrors "mmfixcfg clusterName $clusterName" $?
391
392  # Ensure the clusterId parameter is in the mmfs.cfg file.
393  $mv $newcfg $tmpCfg
394  checkForErrors "mv $newcfg $tmpCfg" $?
395  $mmfixcfg "clusterId" "${clusterId#gpfs}" <$tmpCfg >$newcfg
396  checkForErrors "mmfixcfg clusterName $clusterName" $?
397
398  # Put the new version of mmfs.cfg back into the mmsdrfs file.
399  appendCfgFile $nodesetId $newcfg $newsdrfs
400  checkForErrors "appendCfgFile" $?
401
402  # Sort the new version of the mmsdrfs file.
403  LC_ALL=C $SORT_MMSDRFS $newsdrfs -o $newsdrfs
404  checkForErrors sort $?
405fi  # end if [[ -n $Cflag ]]
406
407##############################################################
408# If this is a local change only, copy the file and return.
409##############################################################
410if [[ -n $fflag ]]
411then
412  $mv $newsdrfs $mmsdrfsFile
413  checkForErrors "mv $newsdrfs $mmsdrfsFile" $?
414  cleanupAndExit 0
415fi
416
417
418#########################################################################
419# Put the new mmsdrfs file into the sdr.
420#########################################################################
421trap "" HUP INT QUIT KILL
422gpfsObjectInfo=$(commitChanges \
423   $HOME_CLUSTER $nsId $gpfsObjectInfo $newGenNumber $newsdrfs $primaryServer)
424rc=$?
425if [[ $rc -ne 0 ]]
426then
427  # Cannot replace file in the sdr
428  printErrorMsg 381 $mmcmd
429  cleanupAndExit
430fi
431
432
433########################################################################
434# Unlock the sdr.
435########################################################################
436[[ $sdrLocked = yes ]] && \
437  freeLockOnServer $primaryServer $ourNodeNumber > /dev/null
438sdrLocked=no
439trap posttrap HUP INT QUIT KILL
440
441
442#########################################################################
443# Asynchronously propagate the changes to all nodes.
444#########################################################################
445propagateSdrfsFile async $nodefile $newsdrfs $newGenNumber
446
447cleanupAndExit 0
448
Note: See TracBrowser for help on using the repository browser.