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. 1997,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 | # @(#)23 1.82 src/avs/fs/mmfs/ts/admin/mmdelfs.sh, mmfs, avs_rgpfs24, rgpfs240610b 10/25/05 14:41:42 |
---|
17 | ###################################################################### |
---|
18 | # |
---|
19 | # Usage: mmdelfs Device [-p] |
---|
20 | # |
---|
21 | # Device - the device name of the filesystem to be deleted. |
---|
22 | # |
---|
23 | # -p - indicates that the disks are permanently damaged and |
---|
24 | # that the fs information should be removed from the sdr |
---|
25 | # even if tsdelfs fails. |
---|
26 | # |
---|
27 | ###################################################################### |
---|
28 | |
---|
29 | # Include global declarations and service routines. |
---|
30 | . /usr/lpp/mmfs/bin/mmglobfuncs |
---|
31 | . /usr/lpp/mmfs/bin/mmsdrfsdef |
---|
32 | . /usr/lpp/mmfs/bin/mmfsfuncs |
---|
33 | |
---|
34 | sourceFile="mmdelfs.sh" |
---|
35 | [[ -n $DEBUG || -n $DEBUGmmdelfs ]] && set -x |
---|
36 | $mmTRACE_ENTER "$*" |
---|
37 | |
---|
38 | # Local work files. Names should be of the form: |
---|
39 | # fn=${tmpDir}fn.${mmcmd}.$$ |
---|
40 | |
---|
41 | LOCAL_FILES=" " |
---|
42 | |
---|
43 | |
---|
44 | # Local variables |
---|
45 | integer n=1 |
---|
46 | usageMsg=292 |
---|
47 | pflag="" |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | ####################### |
---|
52 | # Mainline processing |
---|
53 | ####################### |
---|
54 | |
---|
55 | |
---|
56 | ####################################### |
---|
57 | # Process the command line arguments. |
---|
58 | ####################################### |
---|
59 | [[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] && \ |
---|
60 | syntaxError "help" $usageMsg |
---|
61 | |
---|
62 | [[ $argc -lt 1 ]] && \ |
---|
63 | syntaxError "missingArgs" $usageMsg |
---|
64 | |
---|
65 | device=$arg1 # The first argument is always the file system name. |
---|
66 | shift 1 # Move past the required positional parameters. |
---|
67 | |
---|
68 | # Check validity of the flags. |
---|
69 | while getopts :np OPT |
---|
70 | do |
---|
71 | case $OPT in |
---|
72 | p) [[ -n $pflag ]] && syntaxError "multiple" $noUsageMsg "-$OPT" |
---|
73 | pflag=yes |
---|
74 | ;; |
---|
75 | :) syntaxError "missingValue" $usageMsg $OPTARG |
---|
76 | ;; |
---|
77 | +[p]) syntaxError "invalidOption" $usageMsg $OPT |
---|
78 | ;; |
---|
79 | *) syntaxError "invalidOption" $usageMsg $OPTARG |
---|
80 | ;; |
---|
81 | esac |
---|
82 | done |
---|
83 | |
---|
84 | shift OPTIND-1 |
---|
85 | [[ $# != 0 ]] && syntaxError "extraArg" $usageMsg $1 |
---|
86 | |
---|
87 | |
---|
88 | ####################################################################### |
---|
89 | # Set up trap exception handling and call the gpfsInit function. |
---|
90 | # It will ensure that the local copy of the mmsdrfs and the rest of |
---|
91 | # the GPFS system files are up-to-date and will obtain the sdr lock. |
---|
92 | ####################################################################### |
---|
93 | trap pretrap HUP INT QUIT KILL |
---|
94 | gpfsInitOutput=$(gpfsInit $lockId) |
---|
95 | setGlobalVar $? $gpfsInitOutput |
---|
96 | |
---|
97 | |
---|
98 | ########################################################### |
---|
99 | # Make sure the specified file system exists and is local. |
---|
100 | ########################################################### |
---|
101 | findFSoutput=$(findFS "$device" $mmsdrfsFile) |
---|
102 | [[ -z $findFSoutput ]] && cleanupAndExit |
---|
103 | |
---|
104 | # Parse the output from the findFS function. |
---|
105 | set -f ; set -- $findFSoutput ; set +f |
---|
106 | fqDeviceName=$1 |
---|
107 | deviceName=$2 |
---|
108 | fsHomeCluster=$3 |
---|
109 | |
---|
110 | # Exit with a message if the command was invoked for a remote file system. |
---|
111 | if [[ $fsHomeCluster != $HOME_CLUSTER ]] |
---|
112 | then |
---|
113 | # Command is not allowed for remote file systems. |
---|
114 | printErrorMsg 106 $mmcmd $device $fsHomeCluster |
---|
115 | cleanupAndExit 1 |
---|
116 | fi |
---|
117 | |
---|
118 | |
---|
119 | ######################################################################## |
---|
120 | # Create the new version of the mmsdrfs file. |
---|
121 | # |
---|
122 | # It will have a new generation number and all references |
---|
123 | # to the file system that is being deleted will be removed. |
---|
124 | # |
---|
125 | # Simultaneously, we will create a file with the names of the nodes |
---|
126 | # that belong to the cluster. This file will be used later for |
---|
127 | # propagating the changes to the individual nodes. |
---|
128 | ######################################################################## |
---|
129 | $rm -f $newsdrfs $nodefile |
---|
130 | IFS=":" |
---|
131 | exec 3<&- |
---|
132 | exec 3< $mmsdrfsFile |
---|
133 | while read -u3 sdrfsLine |
---|
134 | do |
---|
135 | # Parse the line. |
---|
136 | set -f ; set -A v -- - $sdrfsLine ; set +f |
---|
137 | |
---|
138 | IFS="$IFS_sv" # Restore the default IFS settings. |
---|
139 | printLine=true # Assume the line will be printed. |
---|
140 | |
---|
141 | # Change some of the fields depending on the type of line. |
---|
142 | case ${v[$LINE_TYPE_Field]} in |
---|
143 | |
---|
144 | $VERSION_LINE ) |
---|
145 | # Increment the generation number. |
---|
146 | newGenNumber=${v[$SDRFS_GENNUM_Field]}+1 |
---|
147 | v[$SDRFS_GENNUM_Field]=$newGenNumber |
---|
148 | ;; |
---|
149 | |
---|
150 | $MEMBER_NODE ) |
---|
151 | # Add the reliable node name to nodefile. |
---|
152 | print -- "${v[$REL_HOSTNAME_Field]}" >> $nodefile |
---|
153 | checkForErrors "writing to file $nodefile" $? |
---|
154 | |
---|
155 | # If this is the line for the node that is executing |
---|
156 | # this command, set the preferredNode variable. |
---|
157 | [[ ${v[$NODE_NUMBER_Field]} = $ourNodeNumber ]] && \ |
---|
158 | preferredNode=${v[$REL_HOSTNAME_Field]} |
---|
159 | ;; |
---|
160 | |
---|
161 | $SG_HEADR | $SG_ETCFS | $SG_MOUNT | $AUTHORIZED_FS ) |
---|
162 | # If any of the above lines belongs to the file system |
---|
163 | # being deleted, remove the line from the mmsdrfs file. |
---|
164 | [[ ${v[$DEV_NAME_Field]} = $deviceName ]] && \ |
---|
165 | printLine=false |
---|
166 | ;; |
---|
167 | |
---|
168 | $SG_DISKS ) |
---|
169 | # If this disk belongs the file system being deleted, change |
---|
170 | # the SG_DISK line to indicate that the disk is now available. |
---|
171 | if [[ ${v[$DEV_NAME_Field]} = $deviceName ]] |
---|
172 | then |
---|
173 | # Reset relevant fields. |
---|
174 | v[$NODESETID_Field]=$FREE_DISK |
---|
175 | v[$DEV_NAME_Field]=$NO_DEVICE |
---|
176 | v[$LINE_NUMBER_Field]=0 |
---|
177 | v[$EXCLUDE_Field]=$includedDisk |
---|
178 | v[$DISK_STATUS_Field]="" |
---|
179 | fi # end if [[ ${v[$DEV_NAME_Field]} = $deviceName ]] |
---|
180 | ;; |
---|
181 | |
---|
182 | * ) # Pass all other lines without a change. |
---|
183 | ;; |
---|
184 | esac # end Change some of the fields |
---|
185 | |
---|
186 | # Build and write the line to the new mmsdrfs file. |
---|
187 | if [[ $printLine = true ]] |
---|
188 | then |
---|
189 | print_newLine >> $newsdrfs |
---|
190 | checkForErrors "writing to file $newsdrfs" $? |
---|
191 | fi |
---|
192 | |
---|
193 | IFS=":" # Change the separator back to ":" for the next iteration. |
---|
194 | |
---|
195 | done # end while read -u3 sdrfsLine |
---|
196 | |
---|
197 | IFS="$IFS_sv" # Restore the default IFS settings. |
---|
198 | |
---|
199 | # Sort the new version of the mmsdrfs file. |
---|
200 | LC_ALL=C $SORT_MMSDRFS $newsdrfs -o $newsdrfs |
---|
201 | |
---|
202 | |
---|
203 | ############################################# |
---|
204 | # Lock the gpfs object to prevent mounts |
---|
205 | # from taking place during the commit phase. |
---|
206 | ############################################# |
---|
207 | [[ $getCredCalled = no ]] && getCred |
---|
208 | setRunningCommand "$mmcmd" $primaryServer |
---|
209 | checkForErrors setRunningCommand $? |
---|
210 | gpfsLocked=yes |
---|
211 | |
---|
212 | |
---|
213 | ############################################## |
---|
214 | # Call tsdelfs to mark the disks as free. |
---|
215 | # The function will be performed only if the |
---|
216 | # file system is not mounted anywhere. |
---|
217 | ############################################## |
---|
218 | $mmcommon onactive $preferredNode $nodefile $NO_FILE_COPY $fqDeviceName \ |
---|
219 | $CHECK_ALL $NO_LINK tsdelfs "$fqDeviceName" |
---|
220 | rc=$? |
---|
221 | |
---|
222 | # If the file system is still mounted, give up (msg already issued). |
---|
223 | [[ $rc -eq $MM_FsMounted ]] && \ |
---|
224 | cleanupAndExit |
---|
225 | |
---|
226 | if [[ $rc -ne 0 ]] |
---|
227 | then |
---|
228 | # tsdelfs failed. If -p is not specified, the mmdelfs command fails too. |
---|
229 | # Otherwise, the tsdelfs error is ignored and the fs is removed from the sdr. |
---|
230 | if [[ -z $pflag ]] |
---|
231 | then |
---|
232 | printErrorMsg 104 $mmcmd tsdelfs |
---|
233 | cleanupAndExit |
---|
234 | else |
---|
235 | # Issue a warning. |
---|
236 | printErrorMsg 267 $mmcmd |
---|
237 | fi |
---|
238 | fi # end of if [[ $rc -ne 0 ]] |
---|
239 | |
---|
240 | |
---|
241 | ################################################################# |
---|
242 | # Put the mmsdrfs file back. This deletes the file system for |
---|
243 | # newly-started daemons - they will not see the file system. |
---|
244 | ################################################################# |
---|
245 | trap "" HUP INT QUIT KILL # Disable until mmsdrfs update is done. |
---|
246 | gpfsObjectInfo=$(commitChanges \ |
---|
247 | $fsHomeCluster $nsId $gpfsObjectInfo $newGenNumber $newsdrfs $primaryServer) |
---|
248 | rc=$? |
---|
249 | if [[ $rc -ne 0 ]] |
---|
250 | then |
---|
251 | # Cannot replace file in the sdr. |
---|
252 | printErrorMsg 381 $mmcmd |
---|
253 | cleanupAndExit |
---|
254 | fi |
---|
255 | |
---|
256 | |
---|
257 | ################################################################### |
---|
258 | # The file system was successfully deleted. Unlock the sdr. |
---|
259 | ################################################################### |
---|
260 | [[ $sdrLocked = yes ]] && \ |
---|
261 | freeLockOnServer $primaryServer $ourNodeNumber >/dev/null |
---|
262 | sdrLocked=no |
---|
263 | trap posttrap HUP INT QUIT KILL |
---|
264 | |
---|
265 | |
---|
266 | ###################################################################### |
---|
267 | # Propagate the changes to all affected nodes. This will include |
---|
268 | # removing of the stanza for the file system from /etc/filesystems, |
---|
269 | # and removing the device name and mount point. |
---|
270 | ###################################################################### |
---|
271 | propagateSdrfsFile async $nodefile $newsdrfs $newGenNumber |
---|
272 | |
---|
273 | |
---|
274 | ################################################### |
---|
275 | # If installed, invoke the syncfsconfig user exit. |
---|
276 | ################################################### |
---|
277 | if [[ -x $syncfsconfig ]] |
---|
278 | then |
---|
279 | print -- "$mmcmd: Starting $syncfsconfig ..." |
---|
280 | $syncfsconfig |
---|
281 | print -- "$mmcmd: $syncfsconfig finished." |
---|
282 | fi |
---|
283 | |
---|
284 | cleanupAndExit 0 |
---|
285 | |
---|