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

Last change on this file since 223 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 29.2 KB
RevLine 
[16]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. 2004,2007
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.55 src/avs/fs/mmfs/ts/admin/mmremotecluster.sh, mmfs, avs_rgpfs24, rgpfs24s012a 5/2/07 15:29:27
17################################################################################
18#
19# Usage:
20#   mmremotecluster add remoteClusterName [-k keyfile] [-n contactNodes]
21#
22#   mmremotecluster update remoteClusterName [-C newClusterName]
23#                          [-k keyfile] [-n contactNodes]
24#
25#   mmremotecluster delete {remoteClusterName | all}
26#
27#   mmremotecluster show   [remoteClusterName | all]
28#
29# where
30#
31#   remoteClusterName  is the fully-qualified name for a remote cluster that
32#                      owns file systems that nodes from this cluster intend
33#                      to mount.
34#
35#   -C newClusterName  is the new fully-qualified cluster name for an
36#                      already-defined cluster remoteClusterName.
37#
38#   -k keyfile         is the authentication key file generated by the mmauth
39#                      command on the remote cluster.
40#
41#   -n contactNodes    provides contact information for the remote cluster.
42#                      The contactNodes parameter has the following format:
43#
44#                        [tcpPort=NNNN,]node1[,node2 ...]
45#
46#                      where
47#
48#                        tcpPort=NNNN  is the TCP port number to be used by the
49#                                  GPFS daemon.  If not specified, GPFS will
50#                                  use the default TCP port number 1191.
51#
52#                        node1[,node2 ...]  is a list of nodes that belong to
53#                                  the remote cluster.  The nodes can be
54#                                  identified through their host names or
55#                                  IP addresses.  If contactNodes are not
56#                                  specified, the user must enable
57#                                  /var/mmfs/etc/remoteclusternodes.
58#
59################################################################################
60
61# Include global declarations and service routines.
62. /usr/lpp/mmfs/bin/mmglobfuncs
63. /usr/lpp/mmfs/bin/mmsdrfsdef
64. /usr/lpp/mmfs/bin/mmfsfuncs
65
66sourceFile="mmremotecluster.sh"
67[[ -n $DEBUG || -n $DEBUGmmremotecluster ]] && set -x
68$mmTRACE_ENTER "$*"
69
70# Local work files.  Names should be of the form:
71#   fn=${tmpDir}fn.${mmcmd}.$$
72mountCheckList=${tmpDir}mountCheckList.${mmcmd}.$$
73verifiedKey=${tmpDir}verifiedKey.${mmcmd}.$$
74tmpPublicKey=${tmpDir}tmpPublicKey.${mmcmd}.$$
75
76LOCAL_FILES=" $mountCheckList $verifiedKey $tmpPublicKey "
77
78# Local variables
79usageMsg=388
80contactNodesCount=0
81
82
83# Local functions
84
85##########################################################################
86#
87# Function:  Determine the SHA digest (fingerprint) that corresponds
88#            to the public key file for the specified cluster.
89#
90# Input:     $1 - cluster name
91#            $2 - sdrfs file to use
92#
93# Output:    The SHA digest string.
94#
95# Returns:   0 - no errors encountered
96#            1 - unexpected error
97#
98##########################################################################
99function getFingerprint  # <clusterName> <sdrfsFile>
100{
101  typeset sourceFile="mmremotecluster.sh"
102  [[ -n $DEBUG || -n $DEBUGgetFingerprint ]] && set -x
103  typeset clusterName=$1
104  typeset sdrfs=$2
105
106  typeset sdrfsLine clusterNameField lineTypeField keyLine keyFingerprint
107
108  [[ ! -f $sdrfs ]] && return 1
109  $rm -f $tmpPublicKey
110
111  # Go through the current mmsdrfs file and retrieve the requested information.
112  IFS=":"
113  exec 4<&-
114  exec 4< $sdrfs
115  while read -u4 sdrfsLine
116  do
117    # Parse the line.
118    set -f ; set -- $sdrfsLine ; set +f
119    clusterNameField=$1
120    lineTypeField=$2
121
122    # We are interested only in the REM_CLUSTER_KEY lines for the specified cluster.
123    if [[ $clusterNameField = $clusterName && $lineTypeField = $REM_CLUSTER_KEY ]]
124    then
125      # The public key information is everything past the first 4 fields.
126      shift 4
127      keyLine=$*
128      keyLine="${keyLine%%+(:)}"
129
130      # Examine the lines.  If the key was generated by the cs4b version
131      # of mmauth genkey, there will be stanza lines and the fingerprint
132      # will be included.  If the fingerprint is missing, or if this is
133      # a key generated by a cs3b version of mmauth genkey, extract the
134      # public key in a temp file.
135      if [[ $keyLine = "clusterName="*            ||
136            $keyLine = "clusterID="*              ||
137            $keyLine = "genkeyFormat="*           ||
138            $keyLine = "genkeyCompatibleFormat="* ||
139            $keyLine = "keyGenNumber="*           ||
140            $keyLine = "publicKey="               ||
141            $keyLine = "certificate="             ]]
142      then
143        :  # Skip the line.
144
145      elif [[ $keyLine = "keyDigest="* ]]
146      then
147        # Return the key fingerprint.
148        keyFingerprint="${keyLine#keyDigest=}"
149        break
150
151      else
152        # Add the line to the key file.
153        IFS=""     # Reset IFS to preserve blanks and tabs.
154        print -- "$keyLine" >> $tmpPublicKey
155        checkForErrors "writing to file $tmpPublicKey" $?
156      fi  # end of if [[ $keyLine = "clusterName="* ]]
157    fi  # end of if [[ $clusterNameField = $clusterName && ...
158
159    IFS=":" # Change the separator back to ":" for the next iteration.
160
161  done  # end while read -u4 sdrfsLine
162
163  IFS="$IFS_sv"  # Restore the default IFS settings.
164
165  # If the fingerprint was not imbedded in the key stanza,
166  # determine it with the help of the openssl command.
167  if [[ -z $keyFingerprint && -s $tmpPublicKey ]]
168  then
169    keyFingerprint=$($openssl dgst -sha -hex < $tmpPublicKey)
170    checkForErrors "openssl dgst -sha -hex $tmpPublicKey" $?
171  fi
172  [[ -z $keyFingerprint ]] && keyFingerprint="(undefined)"
173
174  # Return the result.
175  print -- "$keyFingerprint"
176  return 0
177
178}  #------------ end function getFingerprint -----------------
179
180
181################################################################
182#
183# Function:  Create a list with the names of the file
184#            systems in a given cluster.
185#
186# Input:     $1 - cluster name
187#            $2 - sdrfs file to use
188#
189# Output:    A line with the local and remote file system names
190#            for all file systems in the requested cluster.
191#            The names have the following format:
192#               localFSname (remoteFSname) ...
193#
194# Returns:   0 - success
195#            1 - error encountered
196#
197################################################################
198function getFileSystemList   # <clusterName> <sdrfs>
199{
200  typeset sourceFile="mmremotecluster.sh"
201  [[ -n $DEBUG || -n $DEBUGgetFileSystemList ]] && set -x
202  $mmTRACE_ENTER "$*"
203  typeset clusterName=$1
204  typeset sdrfs=$2
205
206  [[ ! -s $sdrfs ]] &&  \
207    checkForErrors "getFileSystemList: Missing or empty file $sdrfs" 1
208
209  $awk -F: '                                           \
210    $'$NODESETID_Field' == "'$clusterName'" &&         \
211    $'$LINE_TYPE_Field' == "'$SG_HEADR'"    {          \
212      if ( $'$FS_TYPE_Field' == "'$remotefs'" ) {      \
213        { fsList = fsList $'$DEV_NAME_Field' " ("      \
214                   $'$REMOTE_DEV_NAME_Field' ")  " }   \
215      }                                                \
216      else {                                           \
217        { fsList = fsList $'$DEV_NAME_Field' "  " }    \
218      }                                                \
219    }                                                  \
220    END { print fsList }                               \
221  ' $sdrfs
222  checkForErrors awk $?
223
224  $mmTRACE_EXIT "rc=$rc"
225  return $rc
226
227}  #------ end of function getFileSystemList -----------------
228
229
230
231#######################
232# Mainline processing
233#######################
234
235
236#######################################
237# Process the command line arguments.
238#######################################
239[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
240  syntaxError "help" $usageMsg
241
242action=$arg1
243[[ -z $action ]] &&  \
244  syntaxError "missingArgs" $usageMsg
245
246remoteClusterName=$arg2
247checkName clusterName 255 "$remoteClusterName"
248[[ $? -ne 0 ]] && cleanupAndExit
249
250# Allow "ls" to be used in place of "show".
251[[ $action = ls ]] && action=show
252
253# remoteClusterName must be specified for all actions.
254# The only exception is the "show" subcommand where "all"
255# will be assumed if remoteClusterName is omitted.
256if [[ -z $remoteClusterName ]]
257then
258  if [[ $action = show ]]
259  then
260    remoteClusterName=all
261  elif [[ $action = add || $action = update || $action = delete ]]
262  then
263    syntaxError "missingArgs" $usageMsg
264  else
265    syntaxError "keyword" $usageMsg "$action"
266  fi
267fi  # end of if [[ -z $remoteClusterName ]]
268
269# Determine the lookup order for resolving host names.
270[[ $osName != AIX ]] && resolveOrder=$(setHostResolveOrder)
271
272# Continue with the rest of the parameters.
273if [[ $action = show || $action = delete ]]
274then
275  # No other arguments are expected.
276  [[ -n $arg3 ]] && syntaxError "extraArg" $usageMsg $arg3
277
278elif [[ $action = add || $action = update ]]
279then
280  shift 2    # Move past the cluster name in the parameter list.
281
282  # Process the individual arguments and the values associated with them.
283  while getopts :C:k:n: OPT
284  do
285    case $OPT in
286
287      C) [[ -n $Cflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
288         Cflag="-$OPT"; Carg=$OPTARG;
289         [[ $action != update ]] &&  \
290           syntaxError "invalidOption" $usageMsg "-$OPT"
291         checkName clusterName 255 "$Carg"
292         [[ $? -ne 0 ]] && cleanupAndExit
293         ;;
294
295      k) [[ -n $kflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
296         kflag="-$OPT"; karg=$OPTARG;
297         [[ -z $karg ]] && karg=DELETE
298         ;;
299
300      n) [[ -n $nflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
301         nflag="-$OPT"; narg=$OPTARG;
302         [[ -z $narg ]] && narg=DELETE
303         ;;
304
305       +[Ckn) # Invalid option.
306          syntaxError "invalidOption" $usageMsg $OPT
307          ;;
308
309       :) # Missing argument.
310          syntaxError "missingValue" $usageMsg $OPTARG
311          ;;
312
313       *) # Invalid option.
314          syntaxError "invalidOption" $usageMsg $OPTARG
315          ;;
316    esac
317  done
318
319  shift OPTIND-1
320  [[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
321
322  # Initialize local variables.
323  contactNodes=$narg
324  newClusterName=$Carg
325  keyfile=$karg
326
327  # Check the list of contact nodes.
328  if [[ -n $contactNodes &&
329        $contactNodes != DELETE && ! -x $remoteclusternodes ]]
330  then
331    # Parse the list and verify that the names can be resolved.
332    IFS=","
333    for nodeName in $contactNodes
334    do
335      IFS="$IFS_sv"
336
337      # Skip over the tcpPort information.
338      [[ $nodeName = tcpPort=+([0-9]) ]] && continue
339
340      # Verify the name is resolvable.
341      hostResult=$($host $nodeName)
342      set -f ; set -- $hostResult ; set +f
343      ipa=${3%%,*}   # Exclude everything after the first comma.
344      if [[ -z $ipa ]]
345      then
346        # Invalid node name specified.
347        printErrorMsg 54 $mmcmd $nodeName
348        cleanupAndExit
349      fi
350      (( contactNodesCount += 1 ))
351      IFS=","
352    done  # end of for nodeName in $contactNodes
353    IFS="$IFS_sv"
354  fi  # end of if [[ -n $contactNodes ]]
355
356else
357  # Invalid action requested.
358  syntaxError "keyword" $usageMsg "$action"
359fi  # end of if [[ $action = show || $action = delete ]]
360
361
362#####################################################################
363# Set up trap exception handling and call the gpfsInit function.
364# It will ensure that the local copy of the mmsdrfs and the rest of
365# the GPFS system files are up-to-date and will obtain the sdr lock.
366#####################################################################
367if [[ $action = show ]]
368then
369  trap pretrap2 HUP INT QUIT KILL
370  gpfsInitOutput=$(gpfsInit nolock)
371  rc=$?
372else
373  trap pretrap HUP INT QUIT KILL
374  gpfsInitOutput=$(gpfsInit $lockId)
375  rc=$?
376fi
377setGlobalVar $rc $gpfsInitOutput
378
379
380#######################################################################
381# Perform any remaining parameter checking that requires knowledge of
382# the sdrfsFormatLevel level (set by gpfsInit above).  Ensure the user
383# is not trying to utilize function that has not been enabled yet.
384#######################################################################
385# Ensure the key file exists and has the correct format.
386if [[ -n $keyfile && $keyfile != DELETE ]]
387then
388  verifyPublicKeyFile $keyfile $sdrfsFormatLevel $verifiedKey  \
389                      $newClusterName $remoteClusterName
390  [[ $? -ne 0 ]] && cleanupAndExit
391
392  if [[ $sdrfsFormatLevel -eq 0 ]]
393  then
394    # Ensure that the provided key file was generated by a 2.3 version of mmauth.
395    $grep -q -e "^clusterName=" $verifiedKey >/dev/null 2>&1
396    rc=$?
397    if [[ $rc -eq 0 ]]
398    then
399      print -u2 "$mmcmd:  The specified public key file cannot be handled until you"
400      print -u2 "    run \"mmchconfig release=LATEST\" to activate the new function."
401      cleanupAndExit
402    fi
403  fi  # end of if [[ $sdrfsFormatLevel -eq 0 ]]
404fi  # end of if [[ -n $keyfile && $keyfile != DELETE ]]
405
406
407#############################################################################
408#
409# Go through the mmsdrfs file.
410#
411# If action is "add", ensure that we can safely add the new remote cluster.
412#
413# If action is "update", make the needed changes to the mmsdrfs file.
414#
415# If action is "delete", remove the appropriate lines from the mmsdrfs file.
416#
417# If action is "show", extract and display the relevant information.
418#
419#############################################################################
420$rm -f $newsdrfs $nodefile $mountCheckList
421IFS=":"
422exec 3<&-
423exec 3< $mmsdrfsFile
424while read -u3 sdrfsLine
425do
426  # Parse the line.
427  set -f ; set -A v -- - $sdrfsLine ; set +f
428
429  IFS="$IFS_sv"   # Restore the default IFS settings.
430  printLine=true  # Assume the line will be printed.
431
432  # Change some of the fields depending on the type of line.
433  case ${v[$LINE_TYPE_Field]} in
434
435    $VERSION_LINE )
436      # Increment the generation number.
437      newGenNumber=${v[$SDRFS_GENNUM_Field]}+1
438      v[$SDRFS_GENNUM_Field]=$newGenNumber
439
440      ourClusterName=${v[$CLUSTER_NAME_Field]}
441
442      if [[ $ourClusterName = $remoteClusterName && $action = add ||
443            $ourClusterName = $newClusterName && $action = update ]]
444      then
445        # The cluster name is the name of the local cluster.
446        printErrorMsg 202 $mmcmd $ourClusterName
447        cleanupAndExit
448      fi
449      ;;
450
451    $MEMBER_NODE )
452      # Add the reliable node name to nodefile.
453      print -- "${v[$REL_HOSTNAME_Field]}" >> $nodefile
454      checkForErrors "writing to file $nodefile" $?
455
456      # If this is the line for the node that is executing
457      # this command, set the preferredNode variable.
458      [[ ${v[$NODE_NUMBER_Field]} = $ourNodeNumber ]] &&  \
459        preferredNode=${v[$REL_HOSTNAME_Field]}
460      ;;
461
462    $REM_CLUSTER )
463      if [[ ${v[$NODESETID_Field]} = $remoteClusterName ||
464            $remoteClusterName = all && ($action = show || $action = delete) ]]
465      then
466        clusterFound=yes
467        # Processing depends on the specified action:
468        case $action in
469          add )
470            # The remote cluster is already defined.
471            printErrorMsg 316 $mmcmd $remoteClusterName
472            cleanupAndExit
473            ;;
474
475          update )
476            [[ -n $newClusterName ]] &&  \
477              v[$NODESETID_Field]=$newClusterName
478            [[ -n $contactNodes ]] &&  \
479              v[$CONTACT_NODES_Field]=$contactNodes
480            [[ $contactNodes = DELETE ]] &&  \
481              v[$CONTACT_NODES_Field]=""
482            ;;
483
484          delete )
485            printLine=false
486            ;;
487
488          show )
489            # Display the cluster name.
490            header=$(printInfoMsg 442)
491            printf "%-16s %s\n" "$header" "${v[$NODESETID_Field]}"
492
493            # Display the contact nodes.
494            header=$(printInfoMsg 446)
495            contactNodes=""
496            if [[ -x $remoteclusternodes ]]
497            then
498              contactNodes=$($remoteclusternodes ${v[$NODESETID_Field]})
499              [[ -n $contactNodes ]] &&  \
500                contactNodes="$contactNodes  (from $remoteclusternodes)"
501            fi
502            if  [[ -z $contactNodes ]]
503            then
504              contactNodes="${v[$CONTACT_NODES_Field]}"
505              [[ -z $contactNodes ]] &&  \
506                contactNodes="(none specified)"
507            fi
508            printf "%-16s %s\n" "$header" "$contactNodes"
509
510            # Display the SHA digest (public key fingerprint).
511            header=$(printInfoMsg 444)
512            keyFingerprint=$(getFingerprint ${v[$NODESETID_Field]} $mmsdrfsFile)
513            printf "%-16s %s\n" "$header" "$keyFingerprint"
514
515            # Display the file system names.
516            header=$(printInfoMsg 447)
517            fsList=$(getFileSystemList ${v[$NODESETID_Field]} $mmsdrfsFile)
518            checkForErrors getFileSystemList $?
519            [[ -z $fsList ]] && fsList="(none defined)"
520            printf "%-16s %s\n\n" "$header" "$fsList"
521            ;;
522
523          *) checkForErrors "unexpected action $action" 1
524            ;;
525
526        esac  # end of case $action in
527      fi  # end of if [[ ${v[$NODESETID_Field]} = $remoteClusterName ]]
528      ;;
529
530    $REM_CLUSTER_KEY )
531      if [[ ${v[$NODESETID_Field]} = $remoteClusterName ||
532            $remoteClusterName = all && ($action = show || $action = delete) ]]
533      then
534        # Processing depends on the specified action:
535        case $action in
536          add )
537            # The remote cluster is already defined.
538            printErrorMsg 316 $mmcmd $remoteClusterName
539            cleanupAndExit
540            ;;
541
542          update )
543            [[ -n $keyfile ]] &&  \
544              printLine=false
545
546            if [[ -n $newClusterName ]]
547            then
548              v[$NODESETID_Field]=$newClusterName
549              [[ ${v[$LINE_NUMBER_Field]} = 1 ]] &&  \
550                v[$KEY_Field]="clusterName=$newClusterName"
551            fi
552            ;;
553
554          delete )
555            printLine=false
556            ;;
557
558          show )
559            :  # There is nothing to do for now.
560            ;;
561
562          *) checkForErrors "unexpected action $action" 1
563            ;;
564        esac  # end of case $action in
565      fi  # end of if [[ ${v[$NODESETID_Field]} = $remoteClusterName ]]
566      ;;
567
568    $SG_HEADR )
569      if [[ ${v[$NODESETID_Field]} != $HOME_CLUSTER &&
570            ($remoteClusterName = ${v[$NODESETID_Field]} ||
571             $remoteClusterName = "all") ]]
572      then
573        remoteFSfound=yes
574        # Processing depends on the specified action:
575        case $action in
576          add )
577            corruptedSdrFileExit 145 "$sdrfsLine"
578            cleanupAndExit
579            ;;
580
581          update )
582            if [[ -n $newClusterName || -n $keyfile ]]
583            then
584              # Generate the fully-qualified name for the file system.
585              # Put it, together with the local device name, on the list
586              # of file systems that should not be mounted.
587              fsFullName="${v[$NODESETID_Field]}:${v[$REMOTE_DEV_NAME_Field]}"
588              print -- "$fsFullName ${v[$DEV_NAME_Field]}" >> $mountCheckList
589              checkForErrors "writing to file $mountCheckList" $?
590
591              [[ -n $newClusterName ]] &&  \
592                v[$NODESETID_Field]=$newClusterName
593            fi
594            ;;
595
596          delete )
597            # Generate the fully-qualified name for the file system.
598            # Put it, together with the local device name, on the list
599            # of file systems that should not be mounted.
600            fsFullName="${v[$NODESETID_Field]}:${v[$REMOTE_DEV_NAME_Field]}"
601            print -- "$fsFullName ${v[$DEV_NAME_Field]}" >> $mountCheckList
602            checkForErrors "writing to file $mountCheckList" $?
603
604            printLine=false
605            ;;
606
607          show )
608            :  # There is nothing to do for now.
609            ;;
610
611          *) checkForErrors "unexpected action $action" 1
612            ;;
613
614        esac  # end of case $action in
615      fi  # end of if [[ ${v[$NODESETID_Field]} = $remoteClusterName ]]
616      ;;
617
618    $SG_ETCFS )
619      if [[ ${v[$NODESETID_Field]} != $HOME_CLUSTER &&
620            ($remoteClusterName = ${v[$NODESETID_Field]} ||
621             $remoteClusterName = "all") ]]
622      then
623        # Processing depends on the specified action:
624        case $action in
625          add )
626            corruptedSdrFileExit 146 "$sdrfsLine"
627            cleanupAndExit
628            ;;
629
630          update )
631            [[ -n $newClusterName ]] &&  \
632              v[$NODESETID_Field]=$newClusterName
633            ;;
634
635          delete )
636            printLine=false
637            ;;
638
639          show )
640            :  # There is nothing to do for now.
641            ;;
642
643          *) checkForErrors "unexpected action $action" 1
644            ;;
645
646        esac  # end of case $action in
647      fi  # end of if [[ ${v[$NODESETID_Field]} = $remoteClusterName ]]
648      ;;
649
650    $SG_MOUNT )
651      if [[ ${v[$NODESETID_Field]} != $HOME_CLUSTER &&
652            ($remoteClusterName = ${v[$NODESETID_Field]} ||
653             $remoteClusterName = "all") ]]
654      then
655        # Processing depends on the specified action:
656        case $action in
657          add )
658            corruptedSdrFileExit 147 "$sdrfsLine"
659            cleanupAndExit
660            ;;
661
662          update )
663            [[ -n $newClusterName ]] &&  \
664              v[$NODESETID_Field]=$newClusterName
665            ;;
666
667          delete )
668            printLine=false
669            ;;
670
671          show )
672            :  # There is nothing to do for now.
673            ;;
674
675          *) checkForErrors "unexpected action $action" 1
676            ;;
677
678        esac  # end of case $action in
679      fi  # end of if [[ ${v[$NODESETID_Field]} = $remoteClusterName ]]
680      ;;
681
682    * ) : # Pass all other lines without a change.
683      ;;
684
685  esac  # end of Change some of the fields
686
687  # Build and write the line to the new mmsdrfs file.
688  if [[ $printLine = true ]]
689  then
690    print_newLine >> $newsdrfs
691    checkForErrors "writing to file $newsdrfs" $?
692  fi
693
694  IFS=":"  # Change the separator back to ":" for the next iteration.
695
696done  # end of while read -u3 mmsdrfsFile
697
698IFS="$IFS_sv"  # Restore the default IFS settings.
699
700
701if [[ -z $clusterFound && $action != add ]]
702then
703  if [[ $remoteClusterName = all && ($action = show || $action = delete) ]]
704  then
705    # There are no remote cluster definitions.
706    printErrorMsg 262 $mmcmd
707  else
708    # The remote cluster is not defined.
709    printErrorMsg 263 $mmcmd $remoteClusterName
710  fi
711  cleanupAndExit
712fi  # end of if [[ -z $clusterFound ]]
713
714
715#########################################
716# Additional action-specific processing.
717#########################################
718
719if [[ $action = add ]]
720then
721  # Generate the needed information for the mmsdrfs file.
722
723  if [[ $contactNodesCount -eq 0 && ! -x $remoteclusternodes ]]
724  then
725    # No contact nodes were provided for the cluster.
726    printErrorMsg 177 $mmcmd $remoteClusterName
727    cleanupAndExit
728  fi
729
730  # Add the information for the remote cluster to the mmsdrfs file.
731  newLine="$remoteClusterName:$REM_CLUSTER:::$contactNodes:"
732  print -- "$newLine" >> $newsdrfs
733  checkForErrors "writing to file $newsdrfs" $?
734
735  # Process the -k keyfile option.
736  if [[ -n $keyfile ]]
737  then
738    # Add the key to the mmsdrfs file.
739    appendFile $remoteClusterName $verifiedKey $REM_CLUSTER_KEY $newsdrfs
740    checkForErrors  \
741       "appendFile $remoteClusterName $verifiedKey $REM_CLUSTER_KEY $newsdrfs" $?
742    refreshAuthNeeded=yes
743  fi  # end of if [[ -n $keyfile ]]
744fi  # end of if [[ $action = add ]]
745
746
747if [[ $action = update ]]
748then
749  if [[ -z $newClusterName && -z $contactNodes && -z $keyfile ]]
750  then
751    # No changes were made.
752    printErrorMsg 323 $mmcmd
753    cleanupAndExit
754  fi
755
756  # Update the cluster name if changed.
757  [[ -n $newClusterName ]] && remoteClusterName=$newClusterName
758
759  # Process the -n contactNodes option.
760  if [[ -n $contactNodes ]]
761  then
762    if [[ $contactNodes != DELETE  &&
763          $contactNodesCount -eq 0 &&
764          ! -x $remoteclusternodes ]]
765    then
766      # No contact nodes were provided for the cluster.
767      printErrorMsg 177 $mmcmd $remoteClusterName
768      cleanupAndExit
769    fi
770    propagateOptions="rereadContactNodes${remoteClusterName},${propagateOptions}"
771  fi  # end of if [[ -n $contactNodes ]]
772
773  # Process the -k keyfile option.
774  if [[ -n $keyfile ]]
775  then
776    if [[ $keyfile != DELETE ]]
777    then
778      # Add the key to the mmsdrfs file.
779      appendFile $remoteClusterName $verifiedKey $REM_CLUSTER_KEY $newsdrfs
780      checkForErrors  \
781         "appendFile $remoteClusterName $verifiedKey $REM_CLUSTER_KEY $newsdrfs" $?
782    fi  # end of if [[ $keyfile != DELETE ]]
783    refreshAuthNeeded=yes
784  fi  # end of if [[ -n $keyfile ]]
785fi  # end of if [[ $action = update ]]
786
787
788# if [[ $action = delete ]]
789# then
790#   : # Add additional processing if needed.
791# fi
792
793
794if [[ $action = show ]]
795then
796  # There is nothing more to do.
797  cleanupAndExit 0
798fi
799
800
801############################################
802# Sort the new version of the mmsdrfs file.
803############################################
804LC_ALL=C $SORT_MMSDRFS $newsdrfs -o $newsdrfs
805checkForErrors "sorting $newsdrfs" $?
806
807
808############################################
809# Lock the gpfs object to prevent daemons
810# from starting during the commit phase.
811############################################
812[[ $getCredCalled = no ]] && getCred
813setRunningCommand "$mmcmd" $primaryServer
814checkForErrors setRunningCommand $?
815gpfsLocked=yes
816
817
818################################################################
819# Make sure that file systems that should not be mounted
820# are indeed not mounted.  Note that the scope of the mount
821# restriction is our own cluster only.  It is OK for the file
822# systems to be mounted elsewhere.
823################################################################
824if [[ -s $mountCheckList ]]
825then
826  exec 3<&-
827  exec 3< $mountCheckList
828  while read -u3 mountCheckLine
829  do
830    # Parse the line.
831    set -f ; set -- $mountCheckLine ; set +f
832    fsFullName=$1
833    localDevName=$2
834
835    # Keep going if this file system belongs to a cluster that
836    # already has been determined to be down or unreachable.
837    [[ $skipList = *" ${fsFullName%%:*} "* ]] && continue
838
839    $mmcommon onactive $preferredNode $nodefile $NO_FILE_COPY   \
840       $fsFullName $ourClusterName $NO_LINK $MOUNT_CHECK_ONLY ldev=$localDevName 2>$errMsg
841    rc=$?
842    if [[ $rc -eq $MM_FsMounted ]]
843    then
844      # The file system is still mounted (messages were issued by mmcommon).
845      cleanupAndExit
846    elif [[ $rc -eq $MM_FsNotFound || $rc -eq $MM_Remotefs ]]
847    then
848      # The file system was not found, so it cannot be mounted.
849      rc=0
850    elif [[ $rc -eq $MM_HostDown ||
851            $rc -eq $MM_TimedOut ||
852            $rc -eq $MM_UnknownCluster ||
853            $rc -eq $MM_SecurityCfg ||
854            $rc -eq $MM_AuthorizationFailed ]]
855    then
856      # We failed to connect to the remote cluster.
857      rc=0
858      if [[ $remoteClusterName = all ]]
859      then
860        # We are dealing with more than one remote cluster.
861        # Do not try to contact this cluster any more.
862        # Note:  The trailing blank is important!
863        skipList="${skipList} ${fsFullName%%:*} "
864      else
865        # There is only one remote cluster, and we could not connect to it.
866        # Exit the loop since none of its file systems can be mounted.
867        break
868      fi
869    elif [[ $rc -eq $MM_DaemonDown ]]
870    then
871      # GPFS is down on all nodes in the local cluster.
872      # There are no mounted file systems, so exit the loop.
873      rc=0
874      break
875    elif [[ $rc -eq $MM_ConnectionReset ]]
876    then
877      # An internode connection was reset.
878      printErrorMsg 257 $mmcmd
879      cleanupAndExit
880    elif [[ $rc -ne 0 ]]
881    then
882      if [[ -s $errMsg ]]
883      then
884        # Show the error messages from the daemon.
885        $cat $errMsg 1>&2
886      else
887        # The mount check failed and there were no messages from the daemon.
888        printErrorMsg 104 $mmcmd "mmcommon onactive $fsFullName MOUNT_CHECK"
889      fi
890      # The command was unable to determine whether the file system is mounted.
891      printErrorMsg 564 $mmcmd $localDevName
892      cleanupAndExit
893    fi  # end of if [[ $rc -eq $MM_FsMounted ]]
894    $rm -f $errMsg
895  done  # end of while read -u3 mountCheckLine
896  $rm -f $errMsg
897fi  # end of if [[ -s $mountCheckList ]]
898
899
900############################################################
901# Replace the mmsdrfs file in the sdr with the new version.
902############################################################
903trap "" HUP INT QUIT KILL
904gpfsObjectInfo=$(commitChanges  \
905   $nsId $nsId $gpfsObjectInfo $newGenNumber $newsdrfs $primaryServer)
906rc=$?
907if [[ $rc -ne 0 ]]
908then
909  # The commit step failed; we cannot replace the file in the sdr.
910  printErrorMsg 381 $mmcmd
911  cleanupAndExit
912fi
913
914
915##################
916# Unlock the sdr.
917##################
918freeLockOnServer $primaryServer $ourNodeNumber >/dev/null
919sdrLocked=no
920trap posttrap HUP INT QUIT KILL
921
922# Issue "command was successful" message.
923printErrorMsg 272 $mmcmd
924
925
926#####################################################
927# Asynchronously propagate the changes to all nodes.
928#####################################################
929propagateSdrfsFile async $nodefile $newsdrfs $newGenNumber $propagateOptions
930
931if [[ -n $refreshAuthNeeded ]]
932then
933  # Notify all currently-running nodes to refresh their key files.
934  $mmcommon onactive $preferredNode $nodefile    \
935    $NO_FILE_COPY $NO_MOUNT_CHECK NULL $NO_LINK  \
936    tsdsh $mmremote refreshAuth >$tmpfile 2>&1
937fi
938
939cleanupAndExit 0
940
Note: See TracBrowser for help on using the repository browser.