source: gpfs_3.1_ker2.6.20/lpp/mmfs/bin/mmunlinkfileset

Last change on this file was 16, checked in by rock, 17 years ago
  • Property svn:executable set to *
File size: 7.7 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. 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# @(#)46 1.9.1.1 src/avs/fs/mmfs/ts/admin/mmunlinkfileset.sh, mmfs, avs_rgpfs24, rgpfs24s007a 10/18/06 12:03:01
17###############################################################################
18#
19# Usage:
20#   mmunlinkfileset Device {FilesetName | -J JunctionPath} [-f]
21#
22# where:
23#   Device            is the device name of the file system.
24#   FilesetName       is the fileset name.
25#   JunctionPath      is the fileset junction path name.
26#   -f                forcibly closes any open files and unlinks the fileset.
27#
28# Undocumented option:
29#   -a                unlink the fileset from all of its snapshots in the
30#                     top-level snapshot directories.
31#
32###############################################################################
33
34# Include global declarations and service routines.
35. /usr/lpp/mmfs/bin/mmglobfuncs
36. /usr/lpp/mmfs/bin/mmsdrfsdef
37. /usr/lpp/mmfs/bin/mmfsfuncs
38
39sourceFile="mmunlinkfileset.sh"
40[[ -n $DEBUG || -n $DEBUGmmunlinkfileset ]] && set -x
41$mmTRACE_ENTER "$*"
42
43# Local work files.  Names should be of the form:
44#   fn=${tmpDir}fn.${mmcmd}.$$
45
46LOCAL_FILES=" "
47
48
49# Local variables
50usageMsg=516
51
52
53# Local functions
54
55
56
57#######################
58# Mainline processing
59#######################
60
61
62#######################################
63# Process the command line arguments.
64#######################################
65[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
66  syntaxError "help" $usageMsg
67
68[[ $argc -lt 2 ]] &&  \
69  syntaxError "missingArgs" $usageMsg
70
71# The first argument is always the file system name.
72device=$arg1
73deviceName=${device##+(/)dev+(/)}  # name stripped of /dev/ prefix
74fqDeviceName="/dev/$deviceName"    # fully-qualified name (with /dev/ prefix)
75
76# The device name must be followed by a fileset name or -J and a junction path.
77if [[ $arg2 = "-J"* ]]
78then
79  junctionName=${arg2#-J}
80  if [[ -z $junctionName ]]
81  then
82    [[ $argc -lt 3  ]] && syntaxError "missingArgs" $usageMsg
83    junctionName=$arg3
84    shift 3
85  else
86    shift 2
87  fi
88else
89  filesetName=$arg2
90  [[ $arg3 = "-J"* ]] &&  \
91    syntaxError "invalidCombination" $usageMsg "-J" "FilesetName"
92  checkName filesetName 255 "$filesetName"
93  [[ $? -ne 0 ]] && cleanupAndExit
94  shift 2
95fi
96
97# Process the rest of the parameters.
98while getopts :af OPT
99do
100  case $OPT in
101    a) # Unlink from all snapshots.
102       [[ -n $aflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
103       aflag="-$OPT"
104       ;;
105    f) # Close all files.
106       [[ -n $fflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT"
107       fflag="-$OPT"
108       ;;
109    +[af]) # Invalid option.
110       syntaxError "invalidOption" $usageMsg $OPT
111       ;;
112    :) # Missing argument.
113       syntaxError "missingValue" $usageMsg $OPTARG
114       ;;
115    *) # Invalid option.
116       syntaxError "invalidOption" $usageMsg $OPTARG
117       ;;
118  esac
119done  # end of while getopts :af OPT do
120shift OPTIND-1
121
122[[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1
123
124
125#####################################################################
126# Set up trap exception handling and ensure that the local copy of
127# the mmsdrfs is up-to-date.  There is no need to lock the mmsdrfs.
128#####################################################################
129trap pretrap2 HUP INT QUIT KILL
130gpfsInitOutput=$(gpfsInit nolock)
131setGlobalVar $? $gpfsInitOutput
132
133
134###########################################################
135# Make sure the specified file system exists and is local.
136###########################################################
137findFSoutput=$(findFS "$device" $mmsdrfsFile)
138[[ -z $findFSoutput ]] && cleanupAndExit
139
140# Parse the output from the findFS function.
141set -f ; set -- $findFSoutput ; set +f
142fqDeviceName=$1
143deviceName=$2
144fsHomeCluster=$3
145
146# Exit if the command was invoked for a remote file system.
147if [[ $fsHomeCluster != $HOME_CLUSTER ]]
148then
149  # Command is not allowed for remote file systems.
150  printErrorMsg 106 $mmcmd $device $fsHomeCluster
151  cleanupAndExit
152fi
153
154
155#############################
156# Verify the junction name.
157#############################
158if [[ -n $junctionName ]]
159then
160  # The file system must be mounted.
161  mountPoint=$(findMountpoint $deviceName)
162  if [[ -z $mountPoint ]]
163  then
164    # File system is not mounted.
165    printErrorMsg 552 $mmcmd $device
166    cleanupAndExit
167  fi
168
169  # Find the device ID of the mounted GPFS file system.
170  gpfsDeviceID=$($perl -e '($dev) = stat "'$mountPoint'"; printf "%u", $dev;')
171
172  # Ensure the junction path name is fully qualified.
173  [[ $junctionName != /* ]] && junctionName="${PWD%/}/${junctionName}"
174  junctionName=${junctionName%%/}  # Strip any trailing slashes.
175
176  # Find the device ID and inode number of the junction.
177  # The result is a colon-separated device and inode numbers.
178  junctionDevAndIno=$($perl -e ' ($dev,$ino) = stat "'$junctionName'";
179                                 if ($dev ne "") { printf "%u:%u", $dev,$ino }')
180
181  # The junction must be within the mounted file system.
182  if [[ $gpfsDeviceID != ${junctionDevAndIno%:*} ]]
183  then
184    printErrorMsg 550 $mmcmd "$junctionName" "$device"
185    cleanupAndExit
186  fi
187
188  # Create the extended junction path name.
189  junctionName="-J /GPFS:${junctionDevAndIno#*:}${junctionName}"
190fi  # end of if [[ -n $junctionName ]]
191
192
193########################################################################
194# Invoke the tsunlinkfileset command on the local node.
195# Display any error messages and exit if any of the following are true:
196#   - the command completed successfully
197#   - a junction path name is specified
198#   - there is an unacceptable error
199#       (anything other than daemon down or quorum wait)
200#   - the fileset name contains path name expansion triggers
201#   - this is a single node cluster
202########################################################################
203set -f
204$tsunlinkfileset $fqDeviceName $filesetName $junctionName $aflag $fflag 2>$errMsg
205rc=$(remapRC $?)
206set +f
207
208if [[ $rc -ne $MM_DaemonDown && $rc -ne $MM_QuorumWait ||
209      -n $junctionName || $MMMODE = single ]]
210then
211  if [[ $rc -eq $MM_DaemonDown ]]
212  then
213    # GPFS is down on this node.
214    printErrorMsg 109 $mmcmd
215  elif [[ $rc -eq $MM_QuorumWait ]]
216  then
217    # GPFS is not ready for commands.
218    printErrorMsg 110 $mmcmd
219  elif [[ $rc -eq $MM_ConnectionReset ]]
220  then
221    # An internode connection was reset.
222    printErrorMsg 257 $mmcmd
223  else
224    # Either the command worked, or it is an unexpected error.
225    [[ -s $errMsg ]] && $cat $errMsg 1>&2
226#   [[ $rc -ne 0 ]] && printErrorMsg 113 "$mmcmd" "tsunlinkfileset" $rc
227  fi  # end of if [[ $rc -eq $MM_FsNotFound ]]
228  cleanupAndExit $rc
229fi  # end of if [[ ($rc -ne $MM_DaemonDown && ... ]]
230$rm -f $errMsg
231
232
233####################################################################
234# We come here if the local GPFS daemon is not ready for commands.
235# Find an active node and send the command there.
236####################################################################
237
238# Create a file with the reliable names of the nodes in the cluster.
239getNodeList $REL_HOSTNAME_Field $GLOBAL_ID $mmsdrfsFile > $nodefile
240preferredNode=$ourNodeName
241
242# Try the nodes one by one until you find a node that can execute the command.
243$mmcommon onactive $preferredNode $nodefile     \
244   $NO_FILE_COPY $NO_MOUNT_CHECK NULL $NO_LINK  \
245   tsunlinkfileset "$fqDeviceName $filesetName $aflag $fflag"
246rc=$?
247
248# if [[ $rc -ne 0 ]]
249# then
250#   # tsunlinkfileset failed.
251#   printErrorMsg 104 $mmcmd tsunlinkfileset
252#   cleanupAndExit $rc
253# fi
254
255cleanupAndExit $rc
256
Note: See TracBrowser for help on using the repository browser.