source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmsnapdir @ 16

Last change on this file since 16 was 16, checked in by rock, 16 years ago
  • Property svn:executable set to *
File size: 6.9 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. 2003,2005
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# @(#)34 1.14 src/avs/fs/mmfs/ts/admin/mmsnapdir.sh, mmfs, avs_rgpfs24, rgpfs240610b 3/22/05 13:20:50
17#######################################################################
18#
19#  Usage:
20#    mmsnapdir Device {-r | [-a] [-s SnapDirName]}
21#      or
22#    mmsnapdir Device [-q]
23#
24#######################################################################
25
26# Include global declarations and service routines.
27. /usr/lpp/mmfs/bin/mmglobfuncs
28if [[ $ourUid -eq 0 ]]
29then
30  . /usr/lpp/mmfs/bin/mmsdrfsdef
31  . /usr/lpp/mmfs/bin/mmfsfuncs
32fi
33
34sourceFile="mmsnapdir.sh"
35[[ -n $DEBUG || -n $DEBUGmmsnapdir ]] && set -x
36$mmTRACE_ENTER "$*"
37
38usageMsg=566
39integer rc=0
40integer nodeCount=0
41
42
43#####################################################################
44# Process the command arguments.
45# The detailed syntax checking is left for the ts command.
46# Here we make sure that we have the minimum needed to continue.
47#####################################################################
48[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
49  syntaxError "help" $usageMsg
50
51[[ $argc -lt 1  ]] &&  \
52  syntaxError "missingArgs" $usageMsg
53
54device=$arg1     # Save stripe group device (always the first parameter).
55shift 1          # Drop the device name from the parameter list.
56argList=$@       # Save the remainder of the argument list.
57
58
59###################################
60# Set up trap exception handling.
61###################################
62trap pretrap2 HUP INT QUIT KILL
63
64
65####################################################################
66# If invoked by a root user, call the gpfsInit function to ensure
67# that the local copy of the mmsdrfs file and the rest of the GPFS
68# system files are up-to-date.  There is no need to lock the sdr.
69# Non-root users are not allowed to invoke commands on other nodes.
70####################################################################
71if [[ $ourUid -eq 0 ]]
72then
73  gpfsInitOutput=$(gpfsInit nolock)
74  setGlobalVar $? $gpfsInitOutput
75fi
76
77
78####################################
79# Make sure the file system exists.
80####################################
81# If the invocation is not for an explicitly-remote device, obtain the
82# needed information about the filesystem from the mmsdrfs file.
83if [[ $device != *:* ]]
84then
85  findFSoutput=$(findFS "$device" $mmsdrfsFile)
86  [[ -z $findFSoutput ]] && cleanupAndExit
87
88  # Parse the output from the findFS function.
89  set -f ; set -- $findFSoutput ; set +f
90  fqDeviceName=$1
91  deviceName=$2
92  fsHomeCluster=$3
93  remoteDevice=$4
94
95  # If this is a remote file system, set fqDeviceName appropriately.
96  [[ $fsHomeCluster != $HOME_CLUSTER ]] &&  \
97    fqDeviceName="$fsHomeCluster:/dev/$remoteDevice"
98else
99  fqDeviceName=$device
100  deviceName=${fqDeviceName##*:}
101  fsHomeCluster=${fqDeviceName%%:*}
102  remoteDevice=$deviceName
103fi
104
105# If this is a remote file system, only the query option is allowed.
106if [[ $fsHomeCluster != $HOME_CLUSTER && $arg2 != "-q" ]]
107then
108  # Command is not allowed for remote file systems.
109  printErrorMsg 106 $mmcmd $device $fsHomeCluster
110  cleanupAndExit 1
111fi
112
113
114########################################################################
115# Invoke the command on the local node.
116# Display any error messages and exit if any of the following are true:
117#   - the command completed successfully
118#   - there is an unacceptable error
119#       (anything other than daemon down or quorum wait)
120#   - the file system is remote
121#   - we are not running as UID 0
122#   - this is a single node cluster
123########################################################################
124${mmcmdDir}/${links}/mmsnapdir $fqDeviceName $argList 2>$errMsg
125rc=$(remapRC $?)
126if [[ ($rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait) ||
127      $fsHomeCluster != $HOME_CLUSTER                    ||
128      $ourUid -ne 0                                      ||
129      $MMMODE = single ]]
130then
131  if [[ $rc -eq $MM_FsNotFound ]]
132  then
133    if [[ $fsHomeCluster != $HOME_CLUSTER ]]
134    then
135      # The remote cluster does not know anything about this file system.
136      printErrorMsg 108 $mmcmd $remoteDevice $fsHomeCluster
137    else
138      # Unexpected error.
139      printErrorMsg 171 $mmcmd "file system $deviceName not found" $rc
140    fi
141  elif [[ $rc -eq $MM_Remotefs && $fsHomeCluster != $HOME_CLUSTER ]]
142  then
143    # The file system is not owned by the remote cluster.
144    [[ $device != *:* ]] &&  \
145      printErrorMsg 111 $mmcmd $device $remoteDevice $fsHomeCluster
146    printErrorMsg 112 $mmcmd $remoteDevice $fsHomeCluster
147  elif [[ ($rc -eq $MM_HostDown    ||
148           $rc -eq $MM_TimedOut    ||
149           $rc -eq $MM_SecurityCfg ||
150           $rc -eq $MM_AuthorizationFailed ||
151           $rc -eq $MM_UnknownCluster)    &&
152          $fsHomeCluster != $HOME_CLUSTER ]]
153  then
154    # Failed to connect to the remote cluster.
155    [[ $rc -eq $MM_SecurityCfg ]] &&  \
156      printErrorMsg 150 $mmcmd
157    [[ $rc -eq $MM_AuthorizationFailed ]] &&  \
158      printErrorMsg 151 $mmcmd
159    printErrorMsg 105 $mmcmd $fsHomeCluster
160  elif [[ $rc -eq $MM_DaemonDown ]]
161  then
162    # GPFS is down on this node.
163    printErrorMsg 109 $mmcmd
164  elif [[ $rc -eq $MM_QuorumWait ]]
165  then
166    # GPFS is not ready for commands.
167    printErrorMsg 110 $mmcmd
168  elif [[ $rc -eq $MM_ConnectionReset ]]
169  then
170    # An internode connection was reset.
171    printErrorMsg 257 $mmcmd
172  else
173    # Either the command worked, or it is an unexpected error.
174    if [[ -s $errMsg ]]
175    then
176      # Show the error messages from the daemon.
177      $cat $errMsg 1>&2
178    elif [[ $rc -ne 0 ]]
179    then
180      # tssnapdir failed.
181      printErrorMsg 104 "$mmcmd" "tssnapdir $fqDeviceName"
182    else
183      :  # The command must have worked.
184    fi
185  fi  # end of if [[ $rc -eq $MM_FsNotFound ]]
186  cleanupAndExit $rc
187fi  # end of if [[ ($rc -ne $MM_DaemonDown && ... ]]
188$rm -f $errMsg
189
190
191#########################################################################
192# We come here if the command was invoked for a local file system but
193# the local daemon is not available; send the command to an active node.
194#########################################################################
195
196# Create a file with the reliable names of the nodes in the cluster.
197nodeCount=$(getNodeFile $REL_HOSTNAME_Field $fsHomeCluster $mmsdrfsFile $nodefile)
198if [[ $nodeCount -eq 0 ]]
199then
200  # The cluster is empty; there is nobody to run the command.
201  printErrorMsg 171 $mmcmd "getNodeFile (nodeCount=0)" 1
202  cleanupAndExit
203fi
204
205# Try the nodes one by one until you find a node that can execute the command.
206preferredNode=0     # We have no idea where to go first; let mmcommon decide.
207$mmcommon linkCommand $preferredNode $nodefile mmsnapdir $fqDeviceName $argList
208rc=$?
209
210cleanupAndExit $rc
211
Note: See TracBrowser for help on using the repository browser.