source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmlsquota @ 214

Last change on this file since 214 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 12.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,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# @(#)84 1.11.1.1 src/avs/fs/mmfs/ts/admin/mmlsquota.sh, mmfs, avs_rgpfs24, rgpfs24s002a 4/27/06 19:20:07
17########################################################################
18#
19# Usage:
20#   mmlsquota [-u User | -g Group | -j Fileset] [-v | -q] [-e]
21#                [-C ClusterName] [Device1 Device2 ...]
22#     or
23#   mmlsquota -d {-u | -g | -j} [-C ClusterName] [Device1 Device2 ...]
24#
25########################################################################
26
27# Include global declarations and service routines.
28. /usr/lpp/mmfs/bin/mmglobfuncs
29if [[ $ourUid -eq 0 ]]
30then
31  . /usr/lpp/mmfs/bin/mmsdrfsdef
32  . /usr/lpp/mmfs/bin/mmfsfuncs
33fi
34
35sourceFile="mmlsquota.sh"
36[[ -n $DEBUG || -n $DEBUGmmlsquota ]] && set -x
37$mmTRACE_ENTER "$*"
38
39# Local variables
40usageMsg=452
41integer rc=0
42integer nodeCount=0
43deviceList=""
44
45
46#################################
47# Process the command arguments.
48#################################
49[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
50  syntaxError "help" $usageMsg
51
52string1=""
53Cstring=""
54if [[ $arg1 = '-d' ]]
55then
56  # We come here to handle the -d form of the command.
57  while getopts :C:dgju OPT
58  do
59    case $OPT in
60
61      C) # Specify a cluster name.
62         if [[ $OPTARG = *:* ]]
63         then
64           print -u2 "Disregarding the C operand because it contains a colon."
65         else
66           Cstring="$Cstring $OPTARG"
67           COpt="-C"
68         fi
69         ;;
70
71      d) string1="-d "
72         dOpt="-d"
73         ;;
74
75      g) [[ -n $jOpt ]] && syntaxError "invalidCombination" $usageMsg "-j" "-g"
76         [[ -n $uOpt ]] && syntaxError "invalidCombination" $usageMsg "-u" "-g"
77         gOpt="-g"
78         string1="$string1 -g"
79         ;;
80
81      j) [[ -n $gOpt ]] && syntaxError "invalidCombination" $usageMsg "-g" "-j"
82         [[ -n $uOpt ]] && syntaxError "invalidCombination" $usageMsg "-u" "-j"
83         jOpt="-j"
84         string1="$string1 -j"
85         ;;
86
87      u) [[ -n $gOpt ]] && syntaxError "invalidCombination" $usageMsg "-g" "-u"
88         [[ -n $jOpt ]] && syntaxError "invalidCombination" $usageMsg "-j" "-u"
89         uOpt="-u"
90         string1="$string1 -u"
91         ;;
92
93      :) syntaxError "missingValue" $usageMsg $OPTARG
94         ;;
95
96      +[dgju]) syntaxError "invalidOption" $usageMsg "$OPT"
97         ;;
98
99      *) syntaxError "invalidOption" $usageMsg $OPTARG
100         ;;
101
102    esac
103  done  # end of while getopts :C:dgju OPT do
104
105  # In this form, one of -g, -j, and -u are mandatory.
106  [[ -z $gOpt && -z $jOpt && -z $uOpt ]] && syntaxError "missingArgs" $usageMsg
107
108else
109  # We come here to handle the non-"-d" form of the command.
110  while getopts :C:eg:j:qu:v OPT
111  do
112    case $OPT in
113
114      C) # Specify a cluster name.
115         if [[ $OPTARG = *:* ]]
116         then
117           print -u2 "Disregarding the C operand because it contains a colon."
118         else
119           Cstring="$Cstring $OPTARG"
120           COpt="-C"
121         fi
122         ;;
123
124      e) string1="$string1 -e"
125         eOpt="-e"
126         ;;
127
128      g) # Specify a group.
129         [[ -n $gOpt ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
130         string1="$string1 -g $OPTARG"
131         gOpt="-g"
132         [[ -n $jOpt ]] && syntaxError "invalidCombination" $usageMsg "-j" "-g"
133         [[ -n $uOpt ]] && syntaxError "invalidCombination" $usageMsg "-u" "-g"
134         ;;
135
136      j) # Specify a fileset.
137         [[ -n $jOpt ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
138         string1="$string1 -j $OPTARG"
139         jOpt="-j"
140         [[ -n $gOpt ]] && syntaxError "invalidCombination" $usageMsg "-g" "-j"
141         [[ -n $uOpt ]] && syntaxError "invalidCombination" $usageMsg "-u" "-j"
142         ;;
143
144      q) [[ -n $vOpt ]] && syntaxError "invalidCombination" $usageMsg "-v" "-q"
145         string1="$string1 -q"
146         qOpt="-q"
147         ;;
148
149      u) # Specify a user.
150         [[ -n $uOpt ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
151         string1="$string1 -u $OPTARG"
152         uOpt="-u"
153         [[ -n $gOpt ]] && syntaxError "invalidCombination" $usageMsg "-g" "-u"
154         [[ -n $jOpt ]] && syntaxError "invalidCombination" $usageMsg "-j" "-u"
155         ;;
156
157      v) [[ -n $qOpt ]] && syntaxError "invalidCombination" $usageMsg "-q" "-v"
158         vOpt="-v"
159         string1="$string1 -v"
160         ;;
161
162      :) syntaxError "missingValue" $usageMsg $OPTARG
163         ;;
164
165      +[egjquv]) syntaxError "invalidOption" $usageMsg "$OPT"
166         ;;
167
168      *) syntaxError "invalidOption" $usageMsg $OPTARG
169         ;;
170
171    esac
172  done  # end of while getopts :C:eg:j:qu:v OPT do
173fi  # end of if [[ $arg1 = '-d' ]]
174
175shift OPTIND-1
176
177# Whatever is left is the blank-separated list of devices.
178deviceList=$@
179
180
181##################################
182# Set up trap exception handling.
183##################################
184trap pretrap2 HUP INT QUIT KILL
185
186
187####################################################################
188# If invoked by a root user, call the gpfsInit function to ensure
189# that the local copy of the mmsdrfs file and the rest of the GPFS
190# system files are up-to-date.  There is no need to lock the sdr.
191# Non-root users are not allowed to invoke commands on other nodes.
192####################################################################
193if [[ $ourUid -eq 0 ]]
194then
195  gpfsInitOutput=$(gpfsInit nolock)
196  setGlobalVar $? $gpfsInitOutput
197fi
198
199
200###############################################
201# Process any -C operands that were specified.
202###############################################
203deviceList2=""
204for cname in $Cstring
205do
206  # Set the remote file system flag.
207  remoteFsSpecified=yes
208
209  # Generate a list of the devices GPFS knows for the specified cluster.
210  # The awk script looks for SG_HEADR lines for the specified cluster.
211  # For each such line, clusterName:fsName is added to deviceList2.
212  dlist=$($awk -F: '                                                  \
213    /^'$cname:$SG_HEADR:'/ {                                          \
214      { print $'$NODESETID_Field' ":" $'$REMOTE_DEV_NAME_Field' " "}  \
215    }                                                                 \
216  ' $mmsdrfsFile)
217  checkForErrors awk $?
218
219  if [[ -z $dlist ]]
220  then
221    print -u2 "No remote file systems for cluster $cname were found."
222  else
223    deviceList2="$deviceList2 $dlist"
224    [[ -n $remoteCluster && $cname != $remoteCluster ]] &&  \
225      multipleClustersInvolved=yes
226    remoteCluster=$cname
227  fi
228done  # end of for cname in $Cstring do
229
230
231###################################################################
232# Process any file systems that were specified one at a time.
233# Loop through the device list and replace any remote file systems
234# with the string "remoteClusterName:remoteFsName".
235###################################################################
236set -f
237for device in $deviceList
238do
239  set +f
240
241  # If the invocation is not for an explicitly-remote device, obtain the
242  # needed information about the filesystem from the mmsdrfs file.
243  if [[ $device != *:* ]]
244  then
245    findFSoutput=$(findFS "$device" $mmsdrfsFile)
246    [[ -z $findFSoutput ]] && continue
247
248    # Parse the output from the findFS function.
249    set -f ; set -- $findFSoutput ; set +f
250    fqDeviceName=$1
251    deviceName=$2
252    fsHomeCluster=$3
253    remoteDevice=$4
254
255    # If this is a remote file system, set fqDeviceName appropriately.
256    if [[ $fsHomeCluster != $HOME_CLUSTER ]]
257    then
258      fqDeviceName="$fsHomeCluster:/dev/$remoteDevice"
259      remoteFsSpecified=yes
260      [[ -n $remoteCluster && $fsHomeCluster != $remoteCluster ]] &&  \
261        multipleClustersInvolved=yes
262      remoteCluster=$fsHomeCluster
263    fi
264  else
265    fqDeviceName=$device
266    deviceName=${fqDeviceName##*:}
267    fsHomeCluster=${fqDeviceName%%:*}
268    remoteDevice=$deviceName
269    remoteFsSpecified=yes
270    [[ -n $remoteCluster && $fsHomeCluster != $remoteCluster ]] &&  \
271      multipleClustersInvolved=yes
272    remoteCluster=$fsHomeCluster
273  fi
274
275  # If more than one file system requested, suppress error
276  # messages that deal with individual file systems.
277  # Such errors will go into the "unexpected" category.
278  [[ -n $deviceList2 ]] && multipleDevicesInvolved=yes
279
280  # Append the fully-qualified name to the list of fs names.
281  deviceList2="$deviceList2 $fqDeviceName"
282done  # end of for device in $deviceList do
283set +f
284
285
286########################################################################
287# Invoke the command on the local node.
288# Display any error messages and exit if any of the following are true:
289#   - the command completed successfully
290#   - there is an unacceptable error
291#       (anything other than daemon down or quorum wait)
292#   - one of the file systems is remote
293#   - we are not running as UID 0
294#   - this is a single node cluster
295########################################################################
296${mmcmdDir}/${links}/mmlsquota $string1 $deviceList2 2>$errMsg
297rc=$(remapRC $?)
298if [[ ($rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait) ||
299      $remoteFsSpecified = yes                           ||
300      $ourUid -ne 0                                      ||
301      $MMMODE = single ]]
302then
303  if [[ $rc -eq $MM_FsNotFound && -z $multipleDevicesInvolved ]]
304  then
305    if [[ $fsHomeCluster != $HOME_CLUSTER ]]
306    then
307      # The remote cluster does not know anything about this file system.
308      printErrorMsg 108 $mmcmd $remoteDevice $fsHomeCluster
309    else
310      # Unexpected error.
311      printErrorMsg 171 $mmcmd "file system $deviceName not found" $rc
312    fi
313  elif [[ $rc -eq $MM_Remotefs            &&
314          $fsHomeCluster != $HOME_CLUSTER &&
315          -z $multipleDevicesInvolved     ]]
316  then
317    # The file system is not owned by the remote cluster.
318    [[ $device != *:* ]] &&  \
319      printErrorMsg 111 $mmcmd $device $remoteDevice $fsHomeCluster
320    printErrorMsg 112 $mmcmd $remoteDevice $fsHomeCluster
321  elif [[ ($rc -eq $MM_HostDown            ||
322           $rc -eq $MM_TimedOut            ||
323           $rc -eq $MM_SecurityCfg         ||
324           $rc -eq $MM_AuthorizationFailed ||
325           $rc -eq $MM_UnknownCluster)        &&
326           $fsHomeCluster != $HOME_CLUSTER    &&
327           -z $multipleClustersInvolved       ]]
328  then
329    # Failed to connect to the remote cluster.
330    [[ $rc -eq $MM_SecurityCfg ]] &&  \
331      printErrorMsg 150 $mmcmd
332    [[ $rc -eq $MM_AuthorizationFailed ]] &&  \
333      printErrorMsg 151 $mmcmd
334    printErrorMsg 105 $mmcmd $fsHomeCluster
335  elif [[ $rc -eq $MM_DaemonDown ]]
336  then
337    # GPFS is down on this node.
338    printErrorMsg 109 $mmcmd
339  elif [[ $rc -eq $MM_QuorumWait ]]
340  then
341    # GPFS is not ready for commands.
342    printErrorMsg 110 $mmcmd
343  elif [[ $rc -eq $MM_ConnectionReset ]]
344  then
345    # An internode connection was reset.
346    printErrorMsg 257 $mmcmd
347  else
348    # Either the command worked, or it is an unexpected error.
349    if [[ -s $errMsg ]]
350    then
351      # Show the error messages from the daemon.
352      $cat $errMsg 1>&2
353    elif [[ $rc -ne 0 ]]
354    then
355      # tslsquota failed; there was no message from the daemon.
356      printErrorMsg 104 "$mmcmd" "tslsquota $string1 $deviceList2"
357    else
358      :  # The command must have worked.
359    fi
360  fi  # end of if [[ $rc -eq $MM_FsNotFound && -z $multipleDevicesInvolved ]]
361  cleanupAndExit $rc
362fi  # end of if [[ ($rc -ne $MM_DaemonDown  && ...
363$rm -f $errMsg
364
365
366################################################################
367# We come here if the command was invoked but the local daemon
368# is not available; send the command to an active node.
369################################################################
370
371# Create a file with the reliable names of the nodes in the cluster.
372nodeCount=$(getNodeFile $REL_HOSTNAME_Field $GLOBAL_ID $mmsdrfsFile $nodefile)
373if [[ $nodeCount -eq 0 ]]
374then
375  # The cluster is empty; there is nobody to run the command.
376  printErrorMsg 171 $mmcmd "getNodeFile (nodeCount=0)" 1
377  cleanupAndExit
378fi
379
380# Try the nodes one by one until you find a node that can execute the command.
381preferredNode=0     # We have no idea where to go first; let mmcommon decide.
382$mmcommon linkCommand $preferredNode $nodefile mmlsquota $string1 $deviceList2
383rc=$?
384
385cleanupAndExit $rc
386
Note: See TracBrowser for help on using the repository browser.