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

Last change on this file since 211 was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 11.3 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. 2005,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# @(#)45 1.9.1.2 src/avs/fs/mmfs/ts/admin/mmlsfileset.sh, mmfs, avs_rgpfs24, rgpfs24s005a 6/14/06 14:40:28
17################################################################################
18#
19# Usage:
20#   mmlsfileset Device [[FilesetNameList] [-J JunctionPathList]] | -F FileName]
21#                       [-L] [-d] [-i]
22#
23# where:
24#   Device            is the device name of the file system.
25#
26#   FilesetNameList   is a comma-separated list of fileset names.
27#
28#   JunctionPathList  is a comma-separated list of junction path names.
29#
30#   FileName          is the name of a file containing either fileset
31#                     names or junction path names.  Each line must contain
32#                     a single entry.  All junction path names must be fully
33#                     qualified path names.
34#
35#   -L                display extended information (fileset id, parent, etc.)
36#
37#   -d                display the number of blocks in use.
38#
39#   -i                display the number of i-nodes in use.
40#
41# Undocumented option:
42#   -s                display a list of snapshots for this fileset.
43#
44################################################################################
45
46# Include global declarations and service routines.
47. /usr/lpp/mmfs/bin/mmglobfuncs
48. /usr/lpp/mmfs/bin/mmsdrfsdef
49. /usr/lpp/mmfs/bin/mmfsfuncs
50
51sourceFile="mmlsfileset.sh"
52[[ -n $DEBUG || -n $DEBUGmmlsfileset ]] && set -x
53$mmTRACE_ENTER "$*"
54
55# Local work files.  Names should be of the form:
56#   fn=${tmpDir}fn.${mmcmd}.$$
57filesetFile=${tmpDir}filesetFile.${mmcmd}.$$
58
59LOCAL_FILES=" $filesetFile "
60
61
62# Local variables
63usageMsg=518
64
65
66# Local functions
67
68
69
70#######################
71# Mainline processing
72#######################
73
74
75#######################################
76# Process the command line arguments.
77#######################################
78[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
79  syntaxError "help" $usageMsg
80
81[[ $argc -lt 1 ]] &&  \
82  syntaxError "missingArgs" $usageMsg
83
84# The first argument is always the file system name.
85device=$arg1
86deviceName=${device##+(/)dev+(/)}  # name stripped of /dev/ prefix
87fqDeviceName="/dev/$deviceName"    # fully-qualified name (with /dev/ prefix)
88
89# The device name may be followed by a fileset name list
90# and a -J junction name list, or -F and a file name.
91if [[ -n $arg2 && $arg2 != "-"* ]]
92then
93  # A fileset list was specified which may or
94  # may not be followed by a junction list.
95  filesetNameList=$arg2
96  if [[ $arg3 = "-J"* ]]
97  then
98    # The fileset list is followed by a junction list.
99    junctionPathList=${arg3#-J}
100    if [[ -z $junctionPathList ]]
101    then
102      [[ $argc -lt 4  ]] && syntaxError "missingArgs" $usageMsg
103      junctionPathList=$arg4
104      shift 4
105    else
106      shift 3
107    fi
108  else
109    # The fileset list is not followed by a junction list.
110    shift 2
111  fi
112
113elif [[ $arg2 = "-J"* ]]
114then
115  # Only a junction list is specified.
116  junctionPathList=${arg2#-J}
117  if [[ -z $junctionPathList ]]
118  then
119    [[ $argc -lt 3  ]] && syntaxError "missingArgs" $usageMsg
120    junctionPathList=$arg3
121    shift 3
122  else
123    shift 2
124  fi
125
126elif [[ $arg2 = "-F"* ]]
127then
128  # A file name is specified; fileset and/or junction lists are not allowed.
129  userFilesetFile=${arg2#-F}
130  if [[ -z $userFilesetFile ]]
131  then
132    [[ $argc -lt 3  ]] && syntaxError "missingArgs" $usageMsg
133    userFilesetFile=$arg3
134    shift 3
135  else
136    shift 2
137  fi
138
139else
140  # No file name and no fileset and/or junction lists are specified.
141  shift 1
142fi
143
144
145# Process the rest of the parameters.
146while getopts :diLs OPT
147do
148  case $OPT in
149    d) # Display number of blocks in use.
150       [[ -n $dflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
151       dflag="-$OPT"
152       ;;
153
154    i) # Display number of inodes in use.
155       [[ -n $iflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
156       iflag="-$OPT"
157       ;;
158
159    L) # Display extended information.
160       [[ -n $Lflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
161       Lflag="-$OPT"
162       ;;
163
164    s) # Display the snapshots of the fileset.
165       [[ -n $sflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
166       sflag="-$OPT"
167       ;;
168
169    +[diLs]) # Invalid option
170       syntaxError "invalidOption" $usageMsg $OPT
171       ;;
172
173    :) # Missing argument
174       syntaxError "missingValue" $usageMsg $OPTARG
175       ;;
176
177    *) # Invalid option
178       syntaxError "invalidOption" $usageMsg $OPTARG
179       ;;
180
181  esac
182done  # end of while getopts :diLs OPT do
183shift OPTIND-1
184
185[[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
186
187
188# If a fileset list was specified, parse it and
189# put the names in a file.
190$rm -f $filesetFile
191if [[ -n $filesetNameList ]]
192then
193  IFS=','
194  set -f
195  for filesetName in $filesetNameList
196  do
197    print -- "$filesetName" >> $filesetFile
198    checkForErrors "writing to $filesetFile" $?
199  done
200  set +f
201  IFS="$IFS_sv"
202fi  # end of if [[ -n $filesetNameList ]]
203
204# If a junction list was specified, parse it and
205# put the fully-qualified path names in a file.
206if [[ -n $junctionPathList ]]
207then
208  IFS=','
209  set -f
210  for junctionName in $junctionPathList
211  do
212    [[ $junctionName != /* ]] && junctionName="${PWD%/}/${junctionName}"
213    print -- "$junctionName" >> $filesetFile
214    checkForErrors "writing to $filesetFile" $?
215  done
216  set +f
217  IFS="$IFS_sv"
218  junctionsSpecified=yes
219fi  # end of if [[ -n $junctionPathList ]]
220
221# If a file was specified, ensure the file exists and create our own copy.
222if [[ -n $userFilesetFile ]]
223then
224  checkUserFile $userFilesetFile $filesetFile
225  [[ $? -ne 0 ]] && cleanupAndExit
226
227  # See if this file contains junction path names.
228  $grep -q "^/" $filesetFile > /dev/null 2>&1
229  [[ $? -eq 0 ]] && junctionsSpecified=yes
230fi  # end of if [[ -n $userFilesetFile ]]
231
232
233#####################################################################
234# Set up trap exception handling and ensure that the local copy of
235# the mmsdrfs is up-to-date.  There is no need to lock the mmsdrfs.
236#####################################################################
237trap pretrap2 HUP INT QUIT KILL
238gpfsInitOutput=$(gpfsInit nolock)
239setGlobalVar $? $gpfsInitOutput
240
241
242###########################################################
243# Make sure the specified file system exists and is local.
244###########################################################
245findFSoutput=$(findFS "$device" $mmsdrfsFile)
246[[ -z $findFSoutput ]] && cleanupAndExit
247
248# Parse the output from the findFS function.
249set -f ; set -- $findFSoutput ; set +f
250fqDeviceName=$1
251deviceName=$2
252fsHomeCluster=$3
253
254# Exit if the command was invoked for a remote file system.
255if [[ $fsHomeCluster != $HOME_CLUSTER ]]
256then
257  # The command is not allowed for remote file systems.
258  printErrorMsg 106 $mmcmd $device $fsHomeCluster
259  cleanupAndExit
260fi
261
262
263#############################
264# Verify the junction names.
265#############################
266if [[ -n $junctionsSpecified ]]
267then
268  # The file system must be mounted.
269  mountPoint=$(findMountpoint $deviceName)
270  if [[ -z $mountPoint ]]
271  then
272    # The file system is not mounted.
273    printErrorMsg 552 $mmcmd $device
274    cleanupAndExit
275  fi
276
277  # Find the device ID of the mounted GPFS file system.
278  gpfsDeviceID=$($perl -e '($dev) = stat "'$mountPoint'"; printf "%u", $dev;')
279
280  # Scan the entries in the file.  If a junction path name is found,
281  # ensure the junction is within the mounted file system.
282  exec 3< $filesetFile
283  while read -u3 name
284  do
285    # Skip empty lines.
286    [[ $name = *([$BLANKchar$TABchar]) ]] && continue
287
288    if [[ $name = /* ]]
289    then
290      # This is a junction path name.
291
292      # Find the device ID and inode number of the junction.
293      # The result is a colon-separated device and inode numbers.
294      junctionDevAndIno=$($perl -e ' ($dev,$ino) = stat "'$name'";
295                                     if ($dev ne "") { printf "%u:%u", $dev,$ino }')
296
297      # The junction must be within the mounted file system.
298      if [[ $gpfsDeviceID != ${junctionDevAndIno%:*} ]]
299      then
300        printErrorMsg 550 $mmcmd $name $device
301        fatalError=yes
302      else
303        # Things look OK.  Create the extended junction path name.
304        name="/GPFS:${junctionDevAndIno#*:}${name}"
305      fi
306    fi  # end of if [[ $name = /* ]]
307
308    # Put the verified name in a temp file.
309    print -- "$name" >> $tmpfile
310    checkForErrors "writing to $tmpfile" $?
311
312  done  # end while read -u3 name
313
314  # Give up if there are errors.
315  [[ -n $fatalError ]] && cleanupAndExit
316
317  $mv $tmpfile $filesetFile
318  checkForErrors "mv $tmpfile $filesetFile" $?
319fi  # end of if [[ -n $junctionsSpecified ]]
320
321
322########################################################################
323# Invoke the tslsfileset command on the local node.
324# Display any error messages and exit if any of the following are true:
325#   - the command completed successfully
326#   - a junction path name is specified
327#   - there is an unacceptable error
328#       (anything other than daemon down or quorum wait)
329#   - this is a single node cluster
330########################################################################
331if [[ -s $filesetFile ]]
332then
333  $tslsfileset $fqDeviceName -F $filesetFile $Lflag $dflag $iflag $sflag 2>$errMsg
334  rc=$(remapRC $?)
335else
336  $tslsfileset $fqDeviceName $Lflag $dflag $iflag $sflag 2>$errMsg
337  rc=$(remapRC $?)
338fi
339
340if [[ $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait ||
341      -n $junctionsSpecified || $MMMODE = single ]]
342then
343  if [[ $rc -eq $MM_DaemonDown ]]
344  then
345    # GPFS is down on this node.
346    printErrorMsg 109 $mmcmd
347  elif [[ $rc -eq $MM_QuorumWait ]]
348  then
349    # GPFS is not ready for commands.
350    printErrorMsg 110 $mmcmd
351  elif [[ $rc -eq $MM_ConnectionReset ]]
352  then
353    # An internode connection was reset.
354    printErrorMsg 257 $mmcmd
355  else
356    # Either the command worked, or it is an unexpected error.
357    [[ -s $errMsg ]] && $cat $errMsg 1>&2
358#   [[ $rc -ne 0 ]] && printErrorMsg 113 "$mmcmd" "tslsfileset" $rc
359  fi  # end of if [[ $rc -eq $MM_FsNotFound ]]
360  cleanupAndExit $rc
361fi  # end of if [[ ($rc -ne $MM_DaemonDown && ... ]]
362$rm -f $errMsg
363
364
365####################################################################
366# We come here if the local GPFS daemon is not ready for commands.
367# Find an active node and send the command there.
368####################################################################
369
370# Create a file with the reliable names of the nodes in the cluster.
371getNodeList $REL_HOSTNAME_Field $GLOBAL_ID $mmsdrfsFile > $nodefile
372preferredNode=$ourNodeName
373
374# Try the nodes one by one until you find a node that can execute the command.
375
376##################################
377# Invoke the tslsfileset command.
378##################################
379if [[ -s $filesetFile ]]
380then
381  $mmcommon onactive $preferredNode $nodefile    \
382     $filesetFile $NO_MOUNT_CHECK NULL $NO_LINK  \
383     tslsfileset "$fqDeviceName -F $filesetFile $Lflag $dflag $iflag $sflag"
384  rc=$?
385else
386  $mmcommon onactive $preferredNode $nodefile     \
387     $NO_FILE_COPY $NO_MOUNT_CHECK NULL $NO_LINK  \
388     tslsfileset "$fqDeviceName $Lflag $dflag $iflag $sflag"
389  rc=$?
390fi  # end of if [[ -s $filesetFile ]]
391
392# if [[ $rc -ne 0 ]]
393# then
394#   # tslsfileset failed.
395#   printErrorMsg 104 $mmcmd tslsfileset
396#   cleanupAndExit $rc
397# fi
398
399cleanupAndExit $rc
400
Note: See TracBrowser for help on using the repository browser.