source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmchnsd @ 211

Last change on this file since 211 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 15.1 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# @(#)10 1.39.1.2 src/avs/fs/mmfs/ts/admin/mmchnsd.sh, mmfs, avs_rgpfs24, rgpfs24s005a 6/14/06 14:39:52
17###############################################################################
18#
19#  Usage:
20#    mmchnsd {"DiskDesc[;DiskDesc...]" | -F DescFile}
21#
22#  where
23#    DiskDesc       is a descriptor for the disk to be changed
24#    -F DescFile    specifies a file containing the disk descriptors for
25#                   the network shared disks to be changed
26#
27#  Notes:
28#         You cannot change the name of a disk.
29#
30#         Changing the failure group and disk usage is a no-op for mmchnsd.
31#         Instead, use the mmchdisk command for this purpose.
32#
33#         You must explicitly specify the desired new values
34#         for both primary and backup server even if changing
35#         only one of them.
36#
37#         The following operations are allowed:
38#
39#         - Changing the primary and/or backup server for a disk.
40#
41#         - Defining a backup server for a disk that up to this
42#           moment did not have one.
43#
44#         - Deleting the backup server for a disk.
45#
46#         - Removing the primary and backup servers for a disk,
47#           thereby converting it to a directly-attached disk.
48#
49#         - Assigning a primary and an optional backup server to
50#           a directly-attached disk.
51#
52###############################################################################
53
54# Include global declarations and service routines.
55. /usr/lpp/mmfs/bin/mmglobfuncs
56. /usr/lpp/mmfs/bin/mmsdrfsdef
57. /usr/lpp/mmfs/bin/mmfsfuncs
58
59sourceFile="mmchnsd.sh"
60[[ -n $DEBUG || -n $DEBUGmmchnsd ]] && set -x
61$mmTRACE_ENTER "$*"
62
63# Local work files.  Names should be of the form:
64#   fn=${tmpDir}fn.${mmcmd}.$$
65
66descfile=${tmpDir}descfile.${mmcmd}.$$
67existingDisks=${tmpDir}existingDisks.${mmcmd}.$$
68affectedFileSystems=${tmpDir}affectedFileSystems.${mmcmd}.$$
69
70LOCAL_FILES=" $descfile $existingDisks $affectedFileSystems "
71
72
73# Local variables
74usageMsg=438
75noUsageMsg=0
76hadSuccess=false
77
78
79
80######################
81# Mainline processing
82######################
83
84
85######################################
86# Process the command line arguments.
87######################################
88[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
89  syntaxError "help" $usageMsg
90
91[[ $argc -lt 1  ]] &&  \
92  syntaxError "missingArgs" $usageMsg
93
94if [[ $arg1 != "-F" ]]
95then
96  # If the first argument is not -F, it must be a disk descriptor list.
97  desclist=$arg1
98  # Ensure that semi-colon is used as a disk name separator.
99  [[ "$desclist" = *+([,${BLANKchar}${TABchar}])* ]] &&  \
100    syntaxError "badSeparator_notSemicolon" $noUsageMsg
101else
102  # -F specified.  The second argument must be a file name.
103  if [[ -z $arg2 ]]
104  then
105    syntaxError "missingFile" $usageMsg
106  else
107    # Verify the existence of the file and create our own copy.
108    checkUserFile $arg2 $descfile
109    [[ $? -ne 0 ]] && cleanupAndExit
110    shift
111  fi  # end of if [[ -z $arg2 ]]
112fi  # end of if [[ $arg1 != "-F" ]]
113
114# Move past the required parameters.
115shift 1
116[[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
117
118
119#####################################################################
120# Set up trap exception handling and call the gpfsInit function.
121# It will ensure that the local copy of the mmsdrfs and the rest of
122# the GPFS system files are up-to-date and will obtain the sdr lock.
123#####################################################################
124trap pretrap HUP INT QUIT KILL
125gpfsInitOutput=$(gpfsInit $lockId)
126setGlobalVar $? $gpfsInitOutput
127
128# Determine the lookup order for resolving host names.
129[[ $osName != AIX ]] && resolveOrder=$(setHostResolveOrder)
130
131
132###########################################################
133# If a descriptor list is specified on the command line,
134# create a file with one disk descriptor per line.
135# Note: If the input is in a file, descfile was created
136#       by the checkUserFile function.
137###########################################################
138if [[ -n $desclist ]]
139then
140  # Move the descriptors into a temporary file.
141  $rm -f $descfile
142  IFS=";"
143  for diskDesc in $desclist
144  do
145    [[ -z $diskDesc ]] && continue
146    print -- "$diskDesc" >> $descfile
147    checkForErrors "writing to file $descfile" $?
148  done  # end for diskDesc in $desclist
149  IFS="$IFS_sv"
150fi  # end of if [[ -n $desclist ]]
151
152
153#########################################################################
154# Create a new version of the mmsdrfs file with a new generation number.
155# Generate a file containing the names of the nodes in the cluster.
156# Generate files containing the nodes in the different nodesets.
157#########################################################################
158$rm -f $nodefile $newsdrfs $existingDisks
159IFS=":"
160exec 3<&-
161exec 3< $mmsdrfsFile
162while read -u3 sdrfsLine
163do
164  # Parse the line.
165  set -f ; set -A v -- - $sdrfsLine ; set +f
166
167  IFS="$IFS_sv"    # Restore the default IFS settings.
168
169  printLine=true   # Assume the line will be printed.
170
171  # Change some of the fields depending on the type of line.
172  case ${v[$LINE_TYPE_Field]} in
173
174    $VERSION_LINE )  # this is the global header line
175      # Increment the generation number
176      newGenNumber=${v[$SDRFS_GENNUM_Field]}+1
177      v[$SDRFS_GENNUM_Field]=$newGenNumber
178      ;;
179
180    $MEMBER_NODE )  # this line describes a node
181       # Add the node to the file with all nodes in the cluster.
182       print -- "${v[$REL_HOSTNAME_Field]}" >> $nodefile
183       checkForErrors "writing to file $nodefile" $?
184       ;;
185
186    $SG_DISKS )  # this line describes a disk that belongs to some file system
187       # Generate a file with SG_DISKS lines for all disks in the cluster.
188       print -- $sdrfsLine >> $existingDisks
189       checkForErrors "writing to file $existingDisks" $?
190       printLine=false
191       ;;
192
193    * )  # Pass all other lines without a change.
194      ;;
195
196  esac  # end Change some of the fields
197
198  # Build and write the line to the new mmsdrfs file.
199  if [[ $printLine = true ]]
200  then
201    print_newLine >> $newsdrfs
202    checkForErrors "writing to file $newsdrfs" $?
203  fi
204
205  IFS=":"  # Change the separator back to ":" for the next iteration.
206
207done  # end while read -u3 sdrfsLine
208
209IFS="$IFS_sv"  # Restore the default IFS settings.
210
211
212# Give up if there are no NSDs in the cluster.
213if [[ ! -s $existingDisks ]]
214then
215  # Issue message that the requested disks are not known to GPFS.
216  printErrorMsg 481 $mmcmd
217  cleanupAndExit
218fi
219
220
221########################################################
222# Process the descriptors with the new disk attributes.
223########################################################
224foundErrors=false
225$rm -f $affectedFileSystems
226exec 3<&-
227exec 3< $descfile
228while read -u3 mmDiskDesc
229do
230  # Skip empty and comment lines.
231  [[ $mmDiskDesc = *([$BLANKchar$TABchar])   ]] && continue
232  [[ $mmDiskDesc = *([$BLANKchar$TABchar])#* ]] && continue
233
234  # Parse mmDiskDesc to get the name of the disk.
235  IFS=':'
236  set -f ; set -- $mmDiskDesc ; set +f
237  diskName=$1
238  IFS="$IFS_sv"
239
240  if [[ -z $diskName ]]
241  then
242    # The disk name must be specified in the disk descriptor.
243    printErrorMsg 23 $mmcmd
244
245    # Show the bad descriptor.
246    printErrorMsg 386 $mmcmd "$mmDiskDesc"
247
248    # The command will fail, but before giving up, we will check the
249    # remainder of the descriptors to flush out as many errors as possible.
250    foundErrors=true
251    [[ $sdrLocked = yes ]] &&  \
252      freeLockOnServer $primaryServer $ourNodeNumber >/dev/null
253    sdrLocked=no
254
255    # Move to the next descriptor.
256    continue
257  fi
258
259  # Locate and extract the SG_DISK line for this disk.
260  $rm -f $tmpfile
261  currentDiskLine=$($awk -F: '                                      \
262    # If the line is for our disk, assigned it to currentDiskLine.  \
263    # Do not put the line in the temp file.                         \
264    $'$DISK_NAME_Field' == "'$diskName'" {                          \
265      { print $0 }                                                  \
266      { next }                                                      \
267    }                                                               \
268    # If the line is for some other disk, add it to tmpfile.        \
269    { print $0 >> "'$tmpfile'" }                                    \
270  ' $existingDisks)
271  checkForErrors awk $?
272
273  # Prepare the existingDisks file for the next iteration.
274  # It will contain all of its original lines except the line
275  # that describes the disk that is currently being processed.
276  $touch $tmpfile    # Ensure file exists even if empty.
277  $mv $tmpfile $existingDisks
278  checkForErrors "mv $tmpfile $existingDisks" $?
279
280  # If not found, issue an appropriate error message.
281  if [[ -z $currentDiskLine ]]
282  then
283    # Check whether the disk was processed earlier.
284    alreadyProcessed=$(getDiskInfo $DISK_NAME_Field $diskName $newsdrfs)
285    if [[ -n $alreadyProcessed ]]
286    then
287      # This disk was already processed; it must be a duplicate entry.
288      printErrorMsg 88 $mmcmd $diskName
289    else
290      # Print error stating disk descriptor should refer to an existing NSD.
291      printErrorMsg 415 $mmcmd "$mmDiskDesc"
292    fi
293
294    # The command will fail, but before giving up, we will check the
295    # remainder of the descriptors to flush out as many errors as possible.
296    foundErrors=true
297    [[ $sdrLocked = yes ]] &&  \
298      freeLockOnServer $primaryServer $ourNodeNumber >/dev/null
299    sdrLocked=no
300
301    # Move to the next descriptor.
302    continue
303
304  fi  # end of if [[ -z $currentDiskLine ]]
305
306  # Find out the file system and nodeset to which this disk belongs.
307  # Parse the line.
308  IFS=":"
309  set -f ; set -A v -- - $currentDiskLine  ; set +f
310  IFS="$IFS_sv"
311  print -- "${v[$DEV_NAME_Field]}" >> $affectedFileSystems
312  checkForErrors "writing to file $affectedFileSystems" $?
313
314  # Check the correctness of the disk descriptor.  If everything is OK,
315  # validateAndConvertNsdDescriptor will create an SG_DISKS line with
316  # the new parameters for the disk.
317  validateDescriptorOutput=$(validateAndConvertNsdDescriptor "$mmDiskDesc"  \
318                    $currentDiskLine $CHANGE_NSD ${v[$NODESETID_Field]} NULL)
319  rc=$?
320  if [[ $rc -ne 0 ]]
321  then
322    # If an error was found, the validate routine issued a message.
323    # We will now print the entire descriptor to help the guy some more.
324    printErrorMsg 386 $mmcmd "$mmDiskDesc"
325
326    # The command will fail, but before giving up, we will check the remainder
327    # of the descriptors to flush out as many errors as possible.
328    foundErrors=true
329    [[ $sdrLocked = yes ]] &&  \
330      freeLockOnServer $primaryServer $ourNodeNumber >/dev/null
331    sdrLocked=no
332
333  else
334    # If the descriptor seems to be OK, parse the output
335    # from the validateAndConvertNsdDescriptor routine.
336    set -f ; set -- $validateDescriptorOutput ; set +f
337    updatedDiskLine="$1"
338
339#esjrm  Add tspreparedisk connectivity verification ???
340#esjrm  Do it based on the pvid (see backup server checking in mmcrnsd)
341#esjrm  Make it conditional on some input flag ( -v yes|no ??)
342#esjrm  Is this the right place ?
343
344    # Add the SG_DISKS line for the disk to the mmsdrfs file.
345    print -- $updatedDiskLine >> $newsdrfs
346    checkForErrors "writing to file $newsdrfs" $?
347  fi  # end of if [[ $rc -ne 0 ]]
348done  # end of while read -u3 mmDiskDesc
349
350
351# Give up if there were errors with one or more of the descriptors.
352if [[ $foundErrors = true ]]
353then
354  # Command failed.
355  printErrorMsg 389 $mmcmd
356  cleanupAndExit
357fi
358
359
360################################################
361# Lock the gpfs object to prevent daemons
362# from starting while things are being changed.
363################################################
364[[ $getCredCalled = no ]] && getCred
365setRunningCommand "$mmcmd" $primaryServer
366checkForErrors setRunningCommand $?
367gpfsLocked=yes
368
369
370##################################################
371# Verify all affected file systems are unmounted.
372##################################################
373$sort -u -o $affectedFileSystems $affectedFileSystems
374checkForErrors "sort -u $affectedFileSystems" $?
375
376exec 3<&-
377exec 3< $affectedFileSystems
378while read -u3 fsLine
379do
380  set -f ; set -- $fsLine ; set +f
381  fsToCheck=$1
382
383  [[ $fsToCheck = $NO_DEVICE ]] && continue
384
385  # Make sure the file system is not mounted on any of the nodes.
386  $mmcommon onactive $preferredNode $nodefile  \
387     $NO_FILE_COPY $fsToCheck $CHECK_ALL $NO_LINK $MOUNT_CHECK_ONLY 2>$errMsg
388  rc=$?
389  if [[ $rc -eq $MM_FsMounted ]]
390  then
391    # File system is still mounted; messages issued by mmcommon.
392    cleanupAndExit
393  elif [[ $rc -eq $MM_DaemonDown ]]
394  then
395    # GPFS is down on all nodes that we care about; that's just fine.
396    rc=0
397  elif [[ $rc -eq $MM_ConnectionReset ]]
398  then
399    # An internode connection was reset.
400    printErrorMsg 257 $mmcmd
401    # The command failed.
402    printErrorMsg 389 $mmcmd
403    cleanupAndExit $rc
404  elif [[ $rc -ne 0 ]]
405  then
406    # An unexpected error occurred during the mount check.
407    if [[ -s $errMsg ]]
408    then
409      # Show the error messages from the daemon.
410      $cat $errMsg 1>&2
411    else
412      # The mount check failed and there were no messages from the daemon.
413      printErrorMsg 171 $mmcmd "mount check for $fsToCheck" $rc
414    fi
415    # The command was unable to determine whether the file system is mounted.
416    printErrorMsg 564 $mmcmd $fsToCheck
417    cleanupAndExit $rc
418  fi  # end if [[ $rc -eq $MM_FsMounted ]]
419  $rm -f $errMsg
420
421done   # end of while read -u3 fsLine
422
423
424####################################################
425# Put the unchanged disks back in the mmsdrfs file.
426####################################################
427$cat $existingDisks >> $newsdrfs
428checkForErrors "cat $existingDisks >> $newsdrfs" $?
429
430
431############################################
432# Sort the new version of the mmsdrfs file.
433############################################
434LC_ALL=C $SORT_MMSDRFS $newsdrfs -o $newsdrfs
435
436
437####################################################
438# Replace the mmsdrfs file.  This makes the changes
439# to the disks visible to the rest of the world.
440####################################################
441trap "" HUP INT QUIT KILL
442gpfsObjectInfo=$(commitChanges  \
443   $FREE_DISK $nsId $gpfsObjectInfo $newGenNumber $newsdrfs $primaryServer)
444rc=$?
445if [[ $rc -ne 0 ]]
446then
447  # We were unable to replace the file in the sdr.
448  printErrorMsg 381 $mmcmd
449  cleanupAndExit
450fi
451
452
453##################
454# Unlock the sdr.
455##################
456[[ $sdrLocked = yes ]] &&  \
457  freeLockOnServer $primaryServer $ourNodeNumber >/dev/null
458sdrLocked=no
459trap posttrap HUP INT QUIT KILL
460
461
462#################################################################
463# Propagate the new mmsdrfs file.  This process is asynchronous.
464#################################################################
465propagateSdrfsFile async $nodefile $newsdrfs $newGenNumber rereadnsd
466
467###################################################
468# If installed, invoke the syncfsconfig user exit.
469###################################################
470if [[ -x $syncfsconfig ]]
471then
472   print -- "$mmcmd:  Starting $syncfsconfig ..."
473   $syncfsconfig
474   print -- "$mmcmd$syncfsconfig finished."
475fi
476
477cleanupAndExit 0
478
Note: See TracBrowser for help on using the repository browser.