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

Last change on this file since 211 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 13.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. 1998,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# @(#)00 1.72 src/avs/fs/mmfs/ts/admin/mmlsfs.sh, mmfs, avs_rgpfs24, rgpfs24s003a 5/18/06 18:48:16
17###############################################################################
18#
19#  List the attributes of a file system.
20#
21#  Usage:
22#    mmlsfs Device [-a] [-A] [-B] [-d] [-D] [-E] [-f] [-F] [-i] [-I] [-j] [-k] [-K]
23#                  [-m] [-M] [-n] [-o] [-P] [-Q] [-r] [-R] [-s] [-S] [-T] [-u] [-V]
24#                  [-z]
25#
26#  If Device is "all", then the command displays information for
27#  all file systems in the cluster.
28#
29###############################################################################
30
31# Include global declarations and service routines.
32. /usr/lpp/mmfs/bin/mmglobfuncs
33if [[ $ourUid -eq 0 ]]
34then
35  . /usr/lpp/mmfs/bin/mmsdrfsdef
36  . /usr/lpp/mmfs/bin/mmfsfuncs
37fi
38
39sourceFile="mmlsfs.sh"
40[[ -n $DEBUG || -n $DEBUGmmlsfs ]] && set -x
41$mmTRACE_ENTER "$*"
42
43# Local work files.  Names should be of the form:
44#   fn=${tmpDir}fn.${mmcmd}.$$
45if [[ $ourUid -eq 0 ]]
46then
47  fsToDisplay=${tmpDir}fsToDisplay.${mmcmd}.$$   # file systems to list
48else
49  fsToDisplay=/tmp/fsToDisplay.${mmcmd}.$$       # use /tmp if not root
50fi
51
52LOCAL_FILES=" $fsToDisplay "
53
54
55# Local variables
56integer rc=0
57integer nodeCount=0
58usageMsg=334
59call_tslsfs=no
60underline="==================================================================="
61underline="${underline}======================================================="
62
63
64# Local routines
65
66###############################################################
67#
68# Function:  Return all GPFS file system devices.
69#
70# Input:     None
71#
72# Output:    For each file system, print:
73#              - the fully-qualified device name
74#              - the short local device name
75#              - the home cluster name
76#              - the remote device name if remote,
77#                  otherwise repeat the local device name
78#
79###############################################################
80function getAllFileSystems
81{
82  typeset sourceFile="mmlsfs.sh"
83  [[ -n $DEBUG || -n $DEBUGgetAllFileSystems ]] && set -x
84  $mmTRACE_ENTER "$*"
85
86  $awk -F: '                                    \
87    /':$SG_HEADR:'/ {                           \
88      if ($'$REMOTE_DEV_NAME_Field' == "") {    \
89        { print "/dev/"$'$DEV_NAME_Field' " "   \
90                $'$DEV_NAME_Field'        " "   \
91                $'$NODESETID_Field'       " "   \
92                $'$DEV_NAME_Field' }            \
93      } else {                                  \
94        { print "/dev/"$'$DEV_NAME_Field' " "   \
95                $'$DEV_NAME_Field'        " "   \
96                $'$NODESETID_Field'       " "   \
97                $'$REMOTE_DEV_NAME_Field' }     \
98      }                                         \
99    }                                           \
100  ' $mmsdrfsFile
101  checkForErrors awk $?
102  return 0
103
104}  #------ end of function getAllFileSystems ----------------
105
106
107
108#######################
109# Mainline processing
110#######################
111
112
113##################################
114# Process the command arguments.
115##################################
116[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
117  syntaxError "help" $usageMsg
118
119[[ $argc -lt 1  ]] &&  \
120  syntaxError "missingArgs" $usageMsg
121
122device=$arg1     # Save the stripe group device (always the first parameter).
123shift 1          # Drop the device name from the parameter list.
124
125
126# The option flags can be divided into two categories:
127# options handled by the daemon, and non-daemon options.
128# If no options are specified, the command displays all options.
129if [[ $argc -eq 1 ]]
130then
131  call_tslsfs=yes
132  nonDaemonFlags="-A -o -T"
133else
134  while getopts :aABdDEfFiIjkKmMnoPQrRsSTuVz OPT
135  do
136    case $OPT in
137      A) # display the automount option
138         nonDaemonFlags="$nonDaemonFlags -$OPT"
139         ;;
140      o) # display the additional mount options
141         nonDaemonFlags="$nonDaemonFlags -$OPT"
142         ;;
143      T) # display the additional mount options
144         nonDaemonFlags="$nonDaemonFlags -$OPT"
145         ;;
146      [aBdDEfFkKiIjmMnPQrRsSVuz])  # Some other valid option was specified.
147         call_tslsfs=yes
148         daemonFlags="$daemonFlags -$OPT"
149         ;;
150      +[aABdDEfFiIjkKmMnoPQrRsSTVuz])
151         syntaxError "invalidOption" $usageMsg $OPT
152         ;;
153      *) # invalid option specified
154         syntaxError "invalidOption" $usageMsg $OPTARG
155         ;;
156    esac
157  done
158  shift OPTIND-1
159  [[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
160fi
161
162
163###################################
164# Set up trap exception handling.
165###################################
166trap pretrap2 HUP INT QUIT KILL
167
168
169####################################################################
170# If invoked by a root user, call the gpfsInit function to ensure
171# that the local copy of the mmsdrfs file and the rest of the GPFS
172# system files are up-to-date.  There is no need to lock the sdr.
173# Non-root users are not allowed to invoke commands on other nodes.
174####################################################################
175if [[ $ourUid -eq 0 ]]
176then
177  gpfsInitOutput=$(gpfsInit nolock)
178  setGlobalVar $? $gpfsInitOutput
179fi
180
181
182#########################################################################
183# If device is the keyword all, create a list of all known file systems.
184# Otherwise, ensure the specified file system exists.
185#########################################################################
186if [[ $device = all ]]
187then
188  getAllFileSystems > $fsToDisplay
189  if [[ ! -s $fsToDisplay ]]
190  then
191    # No file systems were found.
192    printErrorMsg 200 $mmcmd
193    cleanupAndExit
194  fi
195  displayName=yes
196else
197  # If the invocation is not for an explicitly-remote device, obtain the
198  # needed information about the filesystem from the mmsdrfs file.
199  if [[ $device != *:* ]]
200  then
201    findFSoutput=$(findFS "$device" $mmsdrfsFile)
202    [[ -z $findFSoutput ]] && cleanupAndExit
203    print -- $findFSoutput > $fsToDisplay
204    displayName=no
205  else
206    IFS=":"            # Change the field separator to ':'.
207    set -f ; set -- $device ; set +f
208    IFS="$IFS_sv"      # Restore the default IFS settings.
209    fsHomeCluster=$1
210    remoteDevice=$2
211    deviceName=${remoteDevice##+(/)dev+(/)}  # name stripped of /dev/ prefix
212    fqDeviceName="/dev/$deviceName"    # fully-qualified name with /dev/ prefix
213    print -- "$fqDeviceName $deviceName $fsHomeCluster $remoteDevice" > $fsToDisplay
214  fi
215fi
216
217
218######################################################
219# Process the individual file systems one at a time.
220######################################################
221exec 3<&-
222exec 3< $fsToDisplay
223while read -u3 inLine
224do
225  rc=0
226  set -f ; set -- $inLine ; set +f
227  fqDeviceName=$1
228  deviceName=$2
229  fsHomeCluster=$3
230  remoteDevice=$4
231
232  # If this is a remote file system, set fqDeviceName appropriately.
233  [[ $fsHomeCluster != $HOME_CLUSTER ]] &&  \
234    fqDeviceName="$fsHomeCluster:/dev/$remoteDevice"
235
236  ###################################################
237  # If more than one file system, display its name.
238  ###################################################
239  if [[ $displayName = yes ]]
240  then
241    header=$(printInfoMsg 406 $fqDeviceName)
242    printf "\n%s\n%.${#header}s\n" "$header" "$underline"
243  fi
244
245  ##################################################################
246  # Call tslsfs to handle all options other than -A and -o.
247  ##################################################################
248  if [[ $call_tslsfs = yes ]]
249  then
250
251    # Invoke the command on the local node.
252    ${mmcmdDir}/${links}/mmlsfs $fqDeviceName $daemonFlags 2>$errMsg
253    rc=$(remapRC $?)
254
255    # If we get an unacceptable error, or if the file system is remote,
256    # display any error messages and move to the next file system.
257    if [[ ($rc -ne 0 && $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait) ||
258          $fsHomeCluster != $HOME_CLUSTER ||
259          $ourUid -ne 0  || $MMMODE = single ]]
260    then
261      if [[ $rc -eq $MM_FsNotFound ]]
262      then
263        if [[ $fsHomeCluster != $HOME_CLUSTER ]]
264        then
265          # The remote cluster does not know anything about this file system.
266          printErrorMsg 108 $mmcmd $remoteDevice $fsHomeCluster
267        else
268          # Unexpected error.
269          printErrorMsg 171 $mmcmd "file system $deviceName not found" $rc
270        fi
271      elif [[ $rc -eq $MM_Remotefs && $fsHomeCluster != $HOME_CLUSTER ]]
272      then
273        # The file system is not owned by the remote cluster.
274        [[ $device != *:* && $device != all ]] &&  \
275          printErrorMsg 111 $mmcmd $device $remoteDevice $fsHomeCluster
276        printErrorMsg 112 $mmcmd $remoteDevice $fsHomeCluster
277      elif [[ ($rc -eq $MM_HostDown    ||
278               $rc -eq $MM_TimedOut    ||
279               $rc -eq $MM_SecurityCfg ||
280               $rc -eq $MM_AuthorizationFailed ||
281               $rc -eq $MM_UnknownCluster)    &&
282              $fsHomeCluster != $HOME_CLUSTER ]]
283      then
284        # Failed to connect to the remote cluster.
285        [[ $rc -eq $MM_SecurityCfg ]] &&  \
286          printErrorMsg 150 $mmcmd
287        [[ $rc -eq $MM_AuthorizationFailed ]] &&  \
288          printErrorMsg 151 $mmcmd
289        printErrorMsg 105 $mmcmd $fsHomeCluster
290      elif [[ $rc -eq $MM_DaemonDown ]]
291      then
292        # GPFS is down on this node.
293        printErrorMsg 109 $mmcmd
294      elif [[ $rc -eq $MM_QuorumWait ]]
295      then
296        # GPFS is not ready for commands.
297        printErrorMsg 110 $mmcmd
298      elif [[ $rc -eq $MM_ConnectionReset ]]
299      then
300        # An internode connection was reset.
301        printErrorMsg 257 $mmcmd
302      else
303        # Either the command worked, or it is an unexpected error.
304        [[ -s $errMsg ]] && $cat $errMsg 1>&2
305      fi  # end of if [[ $rc -eq $MM_FsNotFound ]]
306      $rm -f $errMsg
307
308      # If we failed for some reason, move to the next file system.
309      [[ $rc -ne 0 ]] && continue
310
311    fi  # end of if [[ ($rc -ne 0 && $rc -ne $MM_DaemonDown && ... ]]
312    $rm -f $errMsg
313
314    #------------------------------------------------------------
315    # If we come here, either (1) the mmlsfs command succeeded
316    # or (2) the mmlsfs command failed for a local file system
317    # when the local daemon is down or is waiting for quorum.
318    #
319    # If (1), the command succeeded, skip the rest of this if
320    # statement and continue processing the non-daemon flags.
321    #
322    # If (2), the command failed, try running it on some other
323    # node.  Note that we will never get here with a non-zero
324    # return code if we do not have root priviledges, or if this
325    # is not a local file system, or if cluster type is single.
326    #------------------------------------------------------------
327
328    if [[ $rc -ne 0 ]]
329    then
330      # The command failed due to daemon down or lack of quorum.
331      # Find an active node and send the command there.
332
333      # Create a file with the reliable names that form the local cluster
334      # to which the file system belongs.
335      nodeCount=$(getNodeFile $REL_HOSTNAME_Field $fsHomeCluster $mmsdrfsFile $nodefile)
336      if [[ $nodeCount -eq 0 ]]
337      then
338        # The local cluster is empty; there is nobody to run the command.
339        printErrorMsg 171 $mmcmd "getNodeFile (nodeCount=0)" 1
340        continue
341      fi
342
343      # Try the nodes one by one until you find a node
344      # that can execute the command.
345      preferredNode=0     # No idea where to go first; let mmcommon decide.
346      $mmcommon linkCommand  \
347        $preferredNode $nodefile mmlsfs $fqDeviceName $daemonFlags
348      rc=$?
349      if [[ $rc -eq $MM_ConnectionReset ]]
350      then
351        # An internode connection was reset.
352        printErrorMsg 257 $mmcmd
353      fi
354
355      # If we failed for some reason, move to the next file system.
356      [[ $rc -ne 0 ]] && continue
357
358    fi  # end of if [[ $rc -ne 0 ]]
359  fi  # end of if [[ $call_tslsfs = yes ]]
360
361  # If no non-daemon options requested, we are done.
362  [[ -z $nonDaemonFlags ]] && continue
363
364  # If tslsfs was not invoked, print the header for the mmlsfs output.
365  [[ $call_tslsfs = no ]] && printInfoMsg 179
366
367  # Get the values for the requested non-daemon options from the mmsdrfs file.
368  for flag in $(print -- $nonDaemonFlags)
369  do
370    case $flag in
371
372      -A ) # Find the value of the automount option.
373         mountOpt=$($grep -e  \
374           "$fsHomeCluster:$SG_ETCFS:$deviceName:$MOUNT_Line:" $mmsdrfsFile |  \
375           $GETVALUE $ETCFS_TEXT_Field)
376         set -f ; set -- $mountOpt ; set +f
377         automountOption=$3
378         if [[ $automountOption = mmfs ]]
379         then
380           flagValue=yes
381         elif [[ $automountOption = false ]]
382         then
383           flagValue=no
384         else
385           # must be "automount"
386           flagValue=$automountOption
387         fi
388         printf " %s  %-14s " $flag $flagValue
389         printInfoMsg 331   # "Automatic mount option"
390         ;;
391
392      -o ) # Find the additional mount options, if any.
393         otherOptions=$($grep -e  \
394           "$fsHomeCluster:$SG_MOUNT:$deviceName:" $mmsdrfsFile |  \
395           $GETVALUE $OTHER_OPT_Field)
396         [[ $otherOptions = "" ]] && \
397           otherOptions="none"
398
399         printf " %s  %-14s " $flag $otherOptions
400         printInfoMsg 519   # "Additional mount options"
401         ;;
402
403      -T ) # Find the mount point pathname.
404         mountPoint=$($grep -e  \
405           "$fsHomeCluster:$SG_ETCFS:$deviceName:$MOUNT_POINT_Line:" $mmsdrfsFile |  \
406           $GETVALUE $ETCFS_TEXT_Field)
407         printf " %s  %-14s " $flag $mountPoint
408         printInfoMsg 559   # "Default mount point"
409         ;;
410
411      * )  # Unknown flag; this should never happen.
412        printErrorMsg 13 "$mmcmd" $flag
413        checkForErrors "bad nonDaemonFlags value" 1
414        ;;
415    esac
416  done   # end of for flag in $(print -- $nonDaemonFlags)
417
418done  # end of while read -u3 inLine
419
420cleanupAndExit $rc
421
Note: See TracBrowser for help on using the repository browser.