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. 2000,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 | # @(#)18 1.39.1.1 src/avs/fs/mmfs/ts/admin/mmsdrfsdef.Linux.sh, mmfs, avs_rgpfs24, rgpfs24s007a 9/20/06 11:22:28 |
---|
17 | ######################################################################### |
---|
18 | # |
---|
19 | # This file contains declarations and functions that are |
---|
20 | # unique to the Linux operating system environment. |
---|
21 | # |
---|
22 | ######################################################################### |
---|
23 | |
---|
24 | |
---|
25 | ####################################################################### |
---|
26 | # |
---|
27 | # Function: Check whether prerequisite software is installed. |
---|
28 | # |
---|
29 | # Input: $1 - Environment type |
---|
30 | # |
---|
31 | # Output: None |
---|
32 | # |
---|
33 | # Returns: 0 - the prerequisite software for the specified |
---|
34 | # environment is installed |
---|
35 | # 1 - the prerequisite software for the specified |
---|
36 | # environment is not installed |
---|
37 | # |
---|
38 | ####################################################################### |
---|
39 | function checkPrereqs # <environmentType> |
---|
40 | { |
---|
41 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
42 | [[ -n $DEBUG || -n $DEBUGcheckPrereqs ]] && set -x |
---|
43 | # $mmTRACE_ENTER "$*" |
---|
44 | typeset environmentType=$1 |
---|
45 | |
---|
46 | if [[ $environmentType = lc2 ]] |
---|
47 | then |
---|
48 | : # There are no special prereqs for cluster type lc2. |
---|
49 | |
---|
50 | elif [[ $environmentType = single ]] |
---|
51 | then |
---|
52 | : # There are no special prereqs for cluster type single. |
---|
53 | |
---|
54 | else |
---|
55 | # We should never get called for a cluster type other than |
---|
56 | # the ones we handle above. Return with a failure code if we do. |
---|
57 | return 1 |
---|
58 | fi |
---|
59 | |
---|
60 | return 0 |
---|
61 | |
---|
62 | } #-------- end of function checkPrereqs ------------------------ |
---|
63 | |
---|
64 | |
---|
65 | #################################################################### |
---|
66 | # |
---|
67 | # Function: Create a version of the /etc/fstab file with |
---|
68 | # all of the mmfs file system stanzas removed |
---|
69 | # |
---|
70 | # Input: $1 - output file name |
---|
71 | # |
---|
72 | # Output: None |
---|
73 | # |
---|
74 | # Returns: 0 - processing completed successfully |
---|
75 | # 1 - unexpected error |
---|
76 | # |
---|
77 | #################################################################### |
---|
78 | function removeAllStanzas # <outputFile> |
---|
79 | { |
---|
80 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
81 | [[ -n $DEBUG || -n $DEBUGremoveAllStanzas ]] && set -x |
---|
82 | $mmTRACE_ENTER "$*" |
---|
83 | typeset outfile=$1 |
---|
84 | |
---|
85 | $rm -f $outfile |
---|
86 | |
---|
87 | #--------------------------------------------------------- |
---|
88 | # Linux file system stanzas consist of 6 fields. |
---|
89 | # The third field is fs_vfstype and for GPFS file |
---|
90 | # systems its value is 'gpfs'. |
---|
91 | #--------------------------------------------------------- |
---|
92 | $awk ' \ |
---|
93 | # If this is a gpfs file system stanza, skip it. \ |
---|
94 | $3 == "gpfs" { next } \ |
---|
95 | # All other lines are passed through as is. \ |
---|
96 | { print $0 >> "'$outfile'" } \ |
---|
97 | ' $etcFilesystems |
---|
98 | checkForErrors "removeAllStanzas:awk" $? |
---|
99 | |
---|
100 | return 0 |
---|
101 | |
---|
102 | } #------------- end of function removeAllStanzas ---------------- |
---|
103 | |
---|
104 | |
---|
105 | #################################################################### |
---|
106 | # |
---|
107 | # Function: Remove a file system from /etc/fstab. |
---|
108 | # |
---|
109 | # Input: $1 - fully qualified file system device name |
---|
110 | # |
---|
111 | # Output: /etc/fstab is rewritten. |
---|
112 | # |
---|
113 | # Returns: 0 - processing completed successfully |
---|
114 | # 1 - unexpected error |
---|
115 | # |
---|
116 | #################################################################### |
---|
117 | function removeStanza # <deviceName> |
---|
118 | { |
---|
119 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
120 | [[ -n $DEBUG || -n $DEBUGremoveStanza ]] && set -x |
---|
121 | $mmTRACE_ENTER "$*" |
---|
122 | typeset fqDeviceName=$1 |
---|
123 | |
---|
124 | typeset rc |
---|
125 | |
---|
126 | $rm -f $newstanza |
---|
127 | |
---|
128 | #--------------------------------------------------------- |
---|
129 | # Linux file system stanzas consist of 6 fields. |
---|
130 | # The first field is the fully qualified device name. |
---|
131 | #--------------------------------------------------------- |
---|
132 | $awk ' \ |
---|
133 | # If this is the stanza to be removed, skip the line. \ |
---|
134 | $1 == "'$fqDeviceName'" && $3 == "gpfs" { next } \ |
---|
135 | # All other lines are passed through as is. \ |
---|
136 | { print $0 >> "'$newstanza'" } \ |
---|
137 | ' $etcFilesystems |
---|
138 | checkForErrors "removeStanza:awk" $? |
---|
139 | |
---|
140 | # If newstanza is missing or empty, something must have gone very wrong. |
---|
141 | [[ ! -s $newstanza ]] && \ |
---|
142 | checkForErrors "removeStanza: missing or empty $newstanza file" 1 |
---|
143 | |
---|
144 | # Replace /etc/fstab with its new version. |
---|
145 | $cp $newstanza $etcFilesystems |
---|
146 | rc=$? |
---|
147 | $mmsync $etcFilesystems |
---|
148 | checkForErrors "cp $newstanza $etcFilesystems" $rc |
---|
149 | |
---|
150 | return 0 |
---|
151 | |
---|
152 | } #------------- end of function removeStanza ---------------- |
---|
153 | |
---|
154 | |
---|
155 | #################################################################### |
---|
156 | # |
---|
157 | # Function: Create a list of the gpfs file systems currently |
---|
158 | # defined in /etc/fstab. Make the list look like |
---|
159 | # the output of the AIX lsfs -c command, i.e., |
---|
160 | # |
---|
161 | # #MountPoint:Device:Vfs:Nodename:Type:Size:Options:AutoMount:Acct |
---|
162 | # /gpfs/gpfsA:/dev/gpfsA:mmfs:-:mmfs:0:rw:no:no |
---|
163 | # /gpfs/gpfsB:/dev/gpfsB:mmfs:-:mmfs:0:rw:no:no |
---|
164 | # |
---|
165 | # Input: $1 - output file name |
---|
166 | # |
---|
167 | # Output: None |
---|
168 | # |
---|
169 | # Returns: 0 - processing completed successfully |
---|
170 | # |
---|
171 | #################################################################### |
---|
172 | function getCurrentStanzaList # <outputFile> |
---|
173 | { |
---|
174 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
175 | [[ -n $DEBUG || -n $DEBUGgetCurrentStanzaList ]] && set -x |
---|
176 | $mmTRACE_ENTER "$*" |
---|
177 | typeset outfile=$1 |
---|
178 | |
---|
179 | $rm -f $outfile |
---|
180 | |
---|
181 | #--------------------------------------------------------------- |
---|
182 | # Linux file system stanzas consist of 6 fields. The first |
---|
183 | # three fields are fs_spec (device name), fs_file (mount point) |
---|
184 | # and fs_vfstype ('gpfs' for us). |
---|
185 | #--------------------------------------------------------------- |
---|
186 | print -- "#MountPoint:Device:Vfs:junk" >$outfile |
---|
187 | $awk ' \ |
---|
188 | # If this is a gpfs file system stanza, \ |
---|
189 | # write its device name and mount point to the file. \ |
---|
190 | $3 == "gpfs" { print $2":"$1":mmfs:" >> "'$outfile'" } \ |
---|
191 | # Skip all other lines \ |
---|
192 | { next } \ |
---|
193 | ' $etcFilesystems |
---|
194 | checkForErrors "getCurrentStanzaList:awk" $? |
---|
195 | |
---|
196 | return 0 |
---|
197 | |
---|
198 | } #------------- end of function getCurrentStanzaList ---------------- |
---|
199 | |
---|
200 | |
---|
201 | ############################################################################# |
---|
202 | # |
---|
203 | # Function: Create the device and mountpoint for a file system |
---|
204 | # |
---|
205 | # Input: $1 - fully qualified device name |
---|
206 | # $2 - mount point to be created |
---|
207 | # $3 - major number for the /dev entry |
---|
208 | # $4 - minor number for the /dev entry |
---|
209 | # $5 - mount type (automount or not) |
---|
210 | # $6 - automount directory |
---|
211 | # |
---|
212 | # Output: None |
---|
213 | # |
---|
214 | # Returns: Zero if successful, non-zero otherwise. |
---|
215 | # |
---|
216 | ############################################################################# |
---|
217 | function createMountPoint # <device> <mountpnt> <majorNumber> <minorNumber> |
---|
218 | # <mountType> <automountDir> |
---|
219 | { |
---|
220 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
221 | [[ -n $DEBUG || -n $DEBUGcreateMountPoint ]] && set -x |
---|
222 | $mmTRACE_ENTER "$*" |
---|
223 | typeset fqDeviceName=$1 |
---|
224 | typeset mountPoint=$2 |
---|
225 | typeset majorNumber=$3 |
---|
226 | typeset minorNumber=$4 |
---|
227 | typeset mountType=$5 |
---|
228 | typeset automountDir=$6 |
---|
229 | |
---|
230 | |
---|
231 | typeset stillMounted existingMajorNumber mkdirError deviceName |
---|
232 | typeset mountPointParentDir mountPointExists |
---|
233 | typeset devType='b' |
---|
234 | |
---|
235 | |
---|
236 | # Strip away the /dev/ prefix from the device name. |
---|
237 | deviceName=${fqDeviceName##+(/)dev+(/)} |
---|
238 | |
---|
239 | # Ensure the device name exists and has the correct major number. |
---|
240 | existingMajorNumber=$(LC_ALL=C $ls -l $fqDeviceName 2>/dev/null | \ |
---|
241 | $awk ' { print $5 } ' ) |
---|
242 | existingMajorNumber=${existingMajorNumber%,*} |
---|
243 | |
---|
244 | if [[ $existingMajorNumber -ne $majorNumber ]] |
---|
245 | then |
---|
246 | # If the major number is not the same as the caller wants it to be, |
---|
247 | # remove the currently existing /dev entry, if any, and recreate it |
---|
248 | # with the correct major and minor numbers. |
---|
249 | [[ -n $existingMajorNumber ]] && $rm -f $fqDeviceName |
---|
250 | createDevEntry $fqDeviceName $majorNumber $minorNumber |
---|
251 | checkForErrors "createDevEntry $fqDeviceName $majorNumber $minorNumber" $? |
---|
252 | fi |
---|
253 | |
---|
254 | # Note that if the file system still shows as mounted, which can |
---|
255 | # happen after a previous gpfs invocation ends abnormally, the |
---|
256 | # normal check for existence can not be used - it fails with ESTALE. |
---|
257 | # In this case though, we can safely assume that the mount point |
---|
258 | # still exists. |
---|
259 | stillMounted=$($mount -t gpfs | \ |
---|
260 | $awk '{ if ($1 == "'"$fqDeviceName"'") print $1 }') |
---|
261 | |
---|
262 | [[ -n $stillMounted ]] && return 0 |
---|
263 | |
---|
264 | |
---|
265 | # If the file system is not mounted, ensure the mount |
---|
266 | # point is present. |
---|
267 | if [[ $mountType = automount ]] |
---|
268 | then |
---|
269 | # The mount point must be a symlink. |
---|
270 | if [[ -L $mountPoint ]] |
---|
271 | then |
---|
272 | # This is indeed a symlink. Verify the target is correct. |
---|
273 | linkTarget=$(LC_ALL=C $ls -l $mountPoint 2>/dev/null) |
---|
274 | linkTarget=${linkTarget##*$BLANKchar} |
---|
275 | if [[ $linkTarget = ${automountDir}/${deviceName} ]] |
---|
276 | then |
---|
277 | # The link looks good. |
---|
278 | mountPointExists=yes |
---|
279 | else |
---|
280 | # The link needs to be rebuild. |
---|
281 | $rm -f $mountPoint |
---|
282 | fi |
---|
283 | else |
---|
284 | # This is not a symlink. If a directory exists, remove |
---|
285 | # it so that a link can be created in its place. If it |
---|
286 | # some other object, we do not know what to do. |
---|
287 | if [[ -e $mountPoint ]] |
---|
288 | then |
---|
289 | $rmdir $mountPoint |
---|
290 | if [[ $? -ne 0 ]] |
---|
291 | then |
---|
292 | print -u2 "$mmcmd: Unable to create symlink $mountPoint" |
---|
293 | return 1 |
---|
294 | fi |
---|
295 | fi # end of if [[ -e $mountPoint ]] |
---|
296 | fi # end of if [[ -L $mountPoint ]] |
---|
297 | |
---|
298 | else |
---|
299 | # The mount point must be a directory. |
---|
300 | if [[ -L $mountPoint ]] |
---|
301 | then |
---|
302 | # This is a symlink (presumably from a file system that |
---|
303 | # used to have the automount mount attribute specified). |
---|
304 | # Remove the link so that we can create a directory in its place. |
---|
305 | $rm -f $mountPoint |
---|
306 | elif [[ -e $mountPoint ]] |
---|
307 | then |
---|
308 | # Things look good. |
---|
309 | mountPointExists=yes |
---|
310 | else |
---|
311 | : # Nothing found; we need to create a mount point. |
---|
312 | fi # end of if [[ -L $mountPoint ]] |
---|
313 | fi # end of if [[ $mountType = automount ]] |
---|
314 | |
---|
315 | # If missing, recreate the mount point. |
---|
316 | if [[ -z $mountPointExists ]] |
---|
317 | then |
---|
318 | if [[ $mountType = automount ]] |
---|
319 | then |
---|
320 | mountPointParentDir=$(dirname $mountPoint) |
---|
321 | mkdirError=$(LC_ALL=C $mkdir -p $mountPointParentDir 2>&1) |
---|
322 | [[ -n $mkdirError ]] && \ |
---|
323 | print -- $mkdirError | $grep -v "File exists" 1>&2 |
---|
324 | $ln -s ${automountDir}/${deviceName} $mountPoint |
---|
325 | else |
---|
326 | mkdirError=$(LC_ALL=C $mkdir -m 0755 -p $mountPoint 2>&1) |
---|
327 | [[ -n $mkdirError ]] && \ |
---|
328 | print -- $mkdirError | $grep -v "File exists" 1>&2 |
---|
329 | fi |
---|
330 | fi # end of if [[ -z $mountPointExists ]] |
---|
331 | |
---|
332 | return 0 |
---|
333 | |
---|
334 | } #------------- end of function createMountPoint --------------- |
---|
335 | |
---|
336 | |
---|
337 | ############################################################### |
---|
338 | # |
---|
339 | # Function: Determine the major number needed for proper |
---|
340 | # fs operations and the major number currently |
---|
341 | # assigned to /dev entries. Assign the two values |
---|
342 | # to the appropriate global variables. |
---|
343 | # |
---|
344 | # Input: None |
---|
345 | # |
---|
346 | # Output: None |
---|
347 | # |
---|
348 | # Returns: Always zero. |
---|
349 | # |
---|
350 | ############################################################### |
---|
351 | function checkVfsNumber |
---|
352 | { |
---|
353 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
354 | [[ -n $DEBUG || -n $DEBUGcheckVfsNumber ]] && set -x |
---|
355 | $mmTRACE_ENTER "$*" |
---|
356 | |
---|
357 | typeset device deviceList majorNumber |
---|
358 | |
---|
359 | |
---|
360 | # Determine the major number that is presently required. |
---|
361 | # This is required for kernel version 2.4 and earlier. |
---|
362 | # If the current kernel is 2.5 or later, use the default |
---|
363 | # values since the major number is largely irrelevant. |
---|
364 | [[ -z $version24 ]] && return 0 |
---|
365 | |
---|
366 | # If the daemon is running, the major number should be the one that |
---|
367 | # was assigned by the kernel when the mmfs extension was loaded. |
---|
368 | # Otherwise, use the default number. |
---|
369 | neededMajorNumber=$($awk ' $2=="gpfs" {print $1} ' /proc/devices) |
---|
370 | [[ -z $neededMajorNumber ]] && \ |
---|
371 | neededMajorNumber=$defaultMajorNumber |
---|
372 | |
---|
373 | # Determine the major number that has been used last, i.e., |
---|
374 | # determine the major number of the existing /dev entries. |
---|
375 | |
---|
376 | # If file mmfsVfsNumber* exists, its suffix is the major number. |
---|
377 | majorNumber=$($ls ${mmfsVfsNumber}+([0-9]) 2>/dev/null) |
---|
378 | majorNumber=${majorNumber#$mmfsVfsNumber} |
---|
379 | if [[ -n $majorNumber ]] |
---|
380 | then |
---|
381 | currentMajorNumber=$majorNumber |
---|
382 | return 0 |
---|
383 | fi |
---|
384 | |
---|
385 | # If the file has been lost somehow, create a list |
---|
386 | # of the file systems in the cluster and see what |
---|
387 | # major number is being used for their /dev entries. |
---|
388 | |
---|
389 | # Create a list of the file systems in the cluster. |
---|
390 | deviceList=$($grep -e ":$SG_HEADR:" $mmsdrfsFile | \ |
---|
391 | $GETVALUE $DEV_NAME_Field) |
---|
392 | |
---|
393 | # Go down the list of file systems until you find a corresponding |
---|
394 | # /dev entry from which to get the major number. |
---|
395 | for device in $deviceList |
---|
396 | do |
---|
397 | majorNumber=$(LC_ALL=C $ls -l /dev/$device 2>/dev/null | \ |
---|
398 | $awk ' { print $5 } ' ) |
---|
399 | majorNumber=${majorNumber%,*} |
---|
400 | [[ -n $majorNumber ]] && break |
---|
401 | done |
---|
402 | |
---|
403 | # If there are no file systems in this nodeset, or if all |
---|
404 | # file systems are missing their /dev entries for some reason, |
---|
405 | # assume the default major device number. |
---|
406 | [[ -z $majorNumber ]] && majorNumber=$defaultMajorNumber |
---|
407 | |
---|
408 | $touch ${mmfsVfsNumber}${majorNumber} 2>/dev/null |
---|
409 | currentMajorNumber=$majorNumber |
---|
410 | return 0 |
---|
411 | |
---|
412 | } #------------- end of function checkVfsNumber ---------------- |
---|
413 | |
---|
414 | |
---|
415 | ###################################################################### |
---|
416 | # |
---|
417 | # Function: Make sure there is an entry for mmfs in /etc/auto_master |
---|
418 | # |
---|
419 | # Input: None |
---|
420 | # |
---|
421 | # Output: None |
---|
422 | # |
---|
423 | # Returns: 0 - mmfs entry in /etc/auto_master confirmed. |
---|
424 | # |
---|
425 | ###################################################################### |
---|
426 | function checkAutomountDefine |
---|
427 | { |
---|
428 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
429 | [[ -n $DEBUG || -n $DEBUGcheckAutomountDefine ]] && set -x |
---|
430 | $mmTRACE_ENTER "$*" |
---|
431 | |
---|
432 | # Applies only to the AIX environment. |
---|
433 | |
---|
434 | return 0 |
---|
435 | |
---|
436 | } #-------- end of function checkAutomountDefine ---------------- |
---|
437 | |
---|
438 | |
---|
439 | ###################################################################### |
---|
440 | # |
---|
441 | # Function: Remove the entry for mmfs from /etc/auto_master |
---|
442 | # |
---|
443 | # Input: None |
---|
444 | # |
---|
445 | # Output: None |
---|
446 | # |
---|
447 | # Returns: 0 - mmfs entry in /etc/auto_master removed. |
---|
448 | # |
---|
449 | ###################################################################### |
---|
450 | function clearAutomountDefine |
---|
451 | { |
---|
452 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
453 | [[ -n $DEBUG || -n $DEBUGclearAutomountDefine ]] && set -x |
---|
454 | $mmTRACE_ENTER "$*" |
---|
455 | |
---|
456 | # Applies only to the AIX environment. |
---|
457 | |
---|
458 | return 0 |
---|
459 | |
---|
460 | } #-------- end of function clearAutomountDefine ---------------- |
---|
461 | |
---|
462 | |
---|
463 | ######################################################################## |
---|
464 | # |
---|
465 | # Function: Obtain K5 (DCE) and/or K4 credentials. |
---|
466 | # Applies only to the SP environment. |
---|
467 | # |
---|
468 | # Input: None |
---|
469 | # |
---|
470 | # Output: None |
---|
471 | # |
---|
472 | # Returns: 0 - command completed successfully |
---|
473 | # |
---|
474 | ######################################################################## |
---|
475 | function getCred |
---|
476 | { |
---|
477 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
478 | [[ -n $DEBUG || -n $DEBUGgetCred ]] && set -x |
---|
479 | # $mmTRACE_ENTER "$*" |
---|
480 | |
---|
481 | return 0 |
---|
482 | |
---|
483 | } #---------------- end of function getCred --------------------------- |
---|
484 | |
---|
485 | |
---|
486 | ############################################################################# |
---|
487 | # |
---|
488 | # Function: Destroy K5 (DCE) and/or K4 credentials obtained by this command |
---|
489 | # Applies only to the SP environment. |
---|
490 | # |
---|
491 | # Input: None |
---|
492 | # |
---|
493 | # Output: None |
---|
494 | # |
---|
495 | # Returns: 0 - command completed successfully |
---|
496 | # |
---|
497 | ############################################################################# |
---|
498 | function freeCred |
---|
499 | { |
---|
500 | typeset sourceFile="mmsdrfsdef.Linux.sh" |
---|
501 | [[ -n $DEBUG || -n $DEBUGfreeCred ]] && set -x |
---|
502 | # $mmTRACE_ENTER "$*" |
---|
503 | |
---|
504 | getCredCalled=no |
---|
505 | return 0 |
---|
506 | |
---|
507 | } #---------------- end of function freeCred --------------- |
---|
508 | |
---|