2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Information Technology Center
15 * The Andrew File System startup process. It is responsible for
16 * reading and parsing the various configuration files, starting up
17 * the kernel processes required by AFS and feeding the configuration
18 * information to the kernel.
20 * Recognized flags are:
21 * -blocks The number of blocks available in the workstation cache.
22 * -files The target number of files in the workstation cache (Default:
24 * -rootvol The name of the root volume to use.
25 * -stat The number of stat cache entries.
26 * -hosts List of servers to check for volume location info FOR THE
28 * -memcache Use an in-memory cache rather than disk.
29 * -cachedir The base directory for the workstation cache.
30 * -mountdir The directory on which the AFS is to be mounted.
31 * -confdir The configuration directory .
32 * -nosettime Don't keep checking the time to avoid drift.
34 * -debug Print out additional debugging info.
35 * -kerndev [OBSOLETE] The kernel device for AFS.
36 * -dontfork [OBSOLETE] Don't fork off as a new process.
37 * -daemons The number of background daemons to start (Default: 2).
38 * -rmtsys Also fires up an afs remote sys call (e.g. pioctl, setpag)
40 * -chunksize [n] 2^n is the chunksize to be used. 0 is default.
41 * -dcache The number of data cache entries.
42 * -biods Number of bkg I/O daemons (AIX3.1 only)
43 * -prealloc Number of preallocated "small" memory blocks
44 * -pininodes Number of inodes which can be spared from inode[] for
45 * pointing at Vfiles. If this is set too high, you may have
46 * system problems, which can only be ameliorated by changing
47 * NINODE (or equivalent) and rebuilding the kernel.
48 * This option is now disabled.
49 * -logfile Place where to put the logfile (default in <cache>/etc/AFSLog.
50 * -waitclose make close calls always synchronous (slows em down, tho)
51 * -files_per_subdir [n] number of files per cache subdir. (def=2048)
52 * -shutdown Shutdown afs daemons
53 *---------------------------------------------------------------------------*/
55 #include <afsconfig.h>
56 #include <afs/param.h>
65 #include <potpourri.h>
66 #include <afs/afsutil.h>
73 #include <sys/types.h>
80 #ifdef HAVE_SYS_PARAM_H
81 #include <sys/param.h>
84 #ifdef HAVE_SYS_FS_TYPES_H
85 #include <sys/fs_types.h>
88 #ifdef HAVE_SYS_MOUNT_H
89 #include <sys/mount.h>
92 #ifdef HAVE_SYS_FCNTL_H
93 #include <sys/fcntl.h>
96 #ifdef HAVE_SYS_MNTTAB_H
97 #include <sys/mnttab.h>
100 #ifdef HAVE_SYS_MNTENT_H
101 #include <sys/mntent.h>
108 #ifdef HAVE_SYS_MOUNT_H
109 #include <sys/mount.h>
112 #ifdef HAVE_SYS_VFS_H
116 #ifdef HAVE_SYS_FSTYP_H
117 #include <sys/fstyp.h>
128 #include <netinet/in.h>
129 #include <afs/afs_args.h>
130 #include <afs/cellconfig.h>
131 #include <afs/auth.h>
133 #include <afs/afssyscalls.h>
134 #include <afs/afsutil.h>
140 #include <libdwarf.h>
141 void set_staticaddrs(void);
142 #endif /* AFS_SGI61_ENV */
143 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
145 #include <symconst.h>
150 #ifdef AFS_LINUX20_ENV
151 #include <sys/resource.h>
153 #ifdef AFS_DARWIN_ENV
154 #include <mach/mach.h>
155 /* Symbols from the DiskArbitration framework */
156 kern_return_t DiskArbStart(mach_port_t *);
157 kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int,
159 #define DISK_ARB_NETWORK_DISK_FLAG 8
160 #endif /* AFS_DARWIN_ENV */
163 #define MOUNT_AFS AFS_MOUNT_AFS
164 #endif /* MOUNT_AFS */
167 #include <sys/statvfs.h>
169 #if defined(AFS_SUN_ENV)
172 #if !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
173 #include <sys/statfs.h>
181 #define CACHEINFOFILE "cacheinfo"
182 #define AFSLOGFILE "AFSLog"
183 #define DCACHEFILE "CacheItems"
184 #define VOLINFOFILE "VolumeItems"
185 #define CELLINFOFILE "CellItems"
187 #define MAXIPADDRS 1024
189 char LclCellName[64];
191 #define MAX_CACHE_LOOPS 4
194 * Internet address (old style... should be updated). This was pulled out of the old 4.2
195 * version of <netinet/in.h>, since it's still useful.
199 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
200 struct { u_short s_w1,s_w2; } S_un_w;
203 #define s_host S_un.S_un_b.s_b2 /* host on imp */
204 #define s_net S_un.S_un_b.s_b1 /* network */
205 #define s_imp S_un.S_un_w.s_w2 /* imp */
206 #define s_impno S_un.S_un_b.s_b4 /* imp # */
207 #define s_lh S_un.S_un_b.s_b3 /* logical host */
210 #define mPrintIPAddr(ipaddr) printf("[%d.%d.%d.%d] ", \
211 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b1, \
212 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b2, \
213 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b3, \
214 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b4)
217 * Global configuration variables.
219 afs_int32 afs_shutdown = 0;
220 afs_int32 cacheBlocks; /*Num blocks in the cache*/
221 afs_int32 cacheFiles = 1000; /*Optimal # of files in workstation cache*/
222 afs_int32 cacheStatEntries = 300; /*Number of stat cache entries*/
223 char cacheBaseDir[1024]; /*Where the workstation AFS cache lives*/
224 char confDir[1024]; /*Where the workstation AFS configuration lives*/
225 char fullpn_DCacheFile[1024]; /*Full pathname of DCACHEFILE*/
226 char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE*/
227 char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE*/
228 char fullpn_AFSLogFile[1024]; /*Full pathname of AFSLOGFILE*/
229 char fullpn_CacheInfo[1024]; /*Full pathname of CACHEINFO*/
230 char fullpn_VFile[1024]; /*Full pathname of data cache files*/
231 char *vFilePtr; /*Ptr to the number part of above pathname*/
232 int sawCacheMountDir = 0; /* from cmd line */
233 int sawCacheBaseDir = 0;
234 int sawCacheBlocks = 0;
235 int sawDCacheSize = 0;
237 char cacheMountDir[1024]; /*Mount directory for AFS*/
238 char rootVolume[64] = "root.afs"; /*AFS root volume name*/
239 afs_int32 cacheSetTime = 1; /*Keep checking time to avoid drift?*/
240 afs_int32 isHomeCell; /*Is current cell info for the home cell?*/
242 int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC; /*Create & truncate on open*/
244 int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open*/
246 int ownerRWmode = 0600; /*Read/write OK by owner*/
247 static int filesSet = 0; /*True if number of files explicitly set*/
248 static int nFilesPerDir = 2048; /* # files per cache dir */
249 static int nDaemons = 2; /* Number of background daemons */
250 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
251 static int dCacheSize = 300; /* # of dcache entries */
252 static int vCacheSize = 50; /* # of volume cache entries */
253 static int rootVolSet = 0; /*True if root volume name explicitly set*/
254 int addrNum; /*Cell server address index being printed*/
255 static int cacheFlags = 0; /*Flags to cache manager*/
256 static int nBiods = 5; /* AIX3.1 only */
257 static int preallocs = 400; /* Def # of allocated memory blocks */
258 static int enable_peer_stats = 0; /* enable rx stats */
259 static int enable_process_stats = 0; /* enable rx stats */
261 static int enable_afsdb = 0; /* enable AFSDB support */
263 static int enable_dynroot = 0; /* enable dynroot support */
264 static int enable_fakestat = 0; /* enable fakestat support */
265 static int enable_nomount = 0; /* do not mount */
267 static int inodes = 60; /* VERY conservative, but has to be */
269 int afsd_verbose = 0; /*Are we being chatty?*/
270 int afsd_debug = 0; /*Are we printing debugging info?*/
271 int afsd_CloseSynch = 0; /*Are closes synchronous or not? */
274 #define AFSD_INO_T ino64_t
276 #define AFSD_INO_T afs_uint32
278 struct afsd_file_list {
280 struct afsd_file_list *next;
282 struct afsd_file_list **cache_dir_filelist = NULL;
283 int *cache_dir_list = NULL; /* Array of cache subdirs */
284 int *dir_for_V = NULL; /* Array: dir of each cache file.
285 * -1: file does not exist
286 * -2: file exists in top-level
287 * >=0: file exists in Dxxx
289 AFSD_INO_T *inode_for_V; /* Array of inodes for desired
291 int missing_DCacheFile = 1; /*Is the DCACHEFILE missing?*/
292 int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing?*/
293 int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing?*/
294 int afsd_rmtsys = 0; /* Default: don't support rmtsys */
295 struct afs_cacheParams cparams; /* params passed to cache manager */
297 static int HandleMTab();
299 /* ParseArgs is now obsolete, being handled by cmd */
301 /*------------------------------------------------------------------------------
305 * Open the file containing the description of the workstation's AFS cache
306 * and pull out its contents. The format of this file is as follows:
308 * cacheMountDir:cacheBaseDir:cacheBlocks
314 * 0 if everything went well,
318 * Nothing interesting.
322 *---------------------------------------------------------------------------*/
324 int ParseCacheInfoFile()
326 static char rn[]="ParseCacheInfoFile"; /*This routine's name*/
327 FILE *cachefd; /*Descriptor for cache info file*/
328 int parseResult; /*Result of our fscanf()*/
329 afs_int32 tCacheBlocks;
330 char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
333 printf("%s: Opening cache info file '%s'...\n",
334 rn, fullpn_CacheInfo);
336 cachefd = fopen(fullpn_CacheInfo, "r");
338 printf("%s: Can't read cache info file '%s'\n",
339 rn, fullpn_CacheInfo);
344 * Parse the contents of the cache info file. All chars up to the first
345 * colon are the AFS mount directory, all chars to the next colon are the
346 * full path name of the workstation cache directory and all remaining chars
347 * represent the number of blocks in the cache.
349 tCacheMountDir[0] = tCacheBaseDir[0] = '\0';
350 parseResult = fscanf(cachefd,
351 "%1024[^:]:%1024[^:]:%d",
352 tCacheMountDir, tCacheBaseDir, &tCacheBlocks);
355 * Regardless of how the parse went, we close the cache info file.
359 if (parseResult == EOF || parseResult < 3) {
360 printf("%s: Format error in cache info file!\n",
362 if (parseResult == EOF)
363 printf("\tEOF encountered before any field parsed.\n");
365 printf("\t%d out of 3 fields successfully parsed.\n",
371 for (tmd = tCacheMountDir; *tmd == '\n' || *tmd == ' ' || *tmd == '\t'; tmd++) ;
372 for (tbd = tCacheBaseDir; *tbd == '\n' || *tbd == ' ' || *tbd == '\t'; tbd++) ;
373 /* now copy in the fields not explicitly overridden by cmd args */
374 if (!sawCacheMountDir)
375 strcpy(cacheMountDir, tmd);
376 if (!sawCacheBaseDir)
377 strcpy(cacheBaseDir, tbd);
379 cacheBlocks = tCacheBlocks;
382 printf("%s: Cache info file successfully parsed:\n",
384 printf("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
385 tmd, tbd, tCacheBlocks);
387 if (! (cacheFlags & AFSCALL_INIT_MEMCACHE))
388 PartSizeOverflow(tbd, cacheBlocks);
394 * All failures to open the partition are ignored. Also if the cache dir
395 * isn't a mounted partition it's also ignored since we can't guarantee
396 * what will be stored afterwards. Too many if's. This is now purely
397 * advisory. ODS with over 2G partition also gives warning message.
399 PartSizeOverflow(path, cs)
403 int bsize=-1, totalblks, mint;
405 struct statvfs statbuf;
407 if (statvfs(path, &statbuf) != 0) {
408 if (afsd_debug) printf("statvfs failed on %s; skip checking for adequate partition space\n", path);
411 totalblks = statbuf.f_blocks;
412 bsize = statbuf.f_frsize;
414 struct statfs statbuf;
416 if (statfs(path, &statbuf) < 0) {
417 if (afsd_debug) printf("statfs failed on %s; skip checking for adequate partition space\n", path);
420 totalblks = statbuf.f_blocks;
421 bsize = statbuf.f_bsize;
423 if (bsize == -1) return 0; /* sucess */
425 /* now free and totalblks are in fragment units, but we want them in 1K units */
427 totalblks *= (bsize / 1024);
429 totalblks /= (1024/bsize);
432 mint = totalblks - ((totalblks * 5) / 100);
434 printf("Cache size (%d) must be less than 95%% of partition size (which is %d). Lower cache size\n",
439 /*-----------------------------------------------------------------------------
443 * Given the final component of a filename expected to be a data cache file,
444 * return the integer corresponding to the file. Note: we reject names that
445 * are not a ``V'' followed by an integer. We also reject those names having
446 * the right format but lying outside the range [0..cacheFiles-1].
449 * fname : Char ptr to the filename to parse.
450 * max : integer for the highest number to accept
453 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
457 * Nothing interesting.
461 *---------------------------------------------------------------------------*/
463 static int doGetXFileNumber(fname, filechar, maxNum)
468 int computedVNumber; /*The computed file number we return*/
469 int filenameLen; /*Number of chars in filename*/
470 int currDigit; /*Current digit being processed*/
473 * The filename must have at least two characters, the first of which must be a ``filechar''
474 * and the second of which cannot be a zero unless the file is exactly two chars long.
476 filenameLen = strlen(fname);
479 if (fname[0] != filechar)
481 if ((filenameLen > 2) && (fname[1] == '0'))
485 * Scan through the characters in the given filename, failing immediately if a non-digit
488 for (currDigit = 1; currDigit < filenameLen; currDigit++)
489 if (isdigit(fname[currDigit]) == 0)
493 * All relevant characters are digits. Pull out the decimal number they represent.
494 * Reject it if it's out of range, otherwise return it.
496 computedVNumber = atoi(++fname);
497 if (computedVNumber < cacheFiles)
498 return(computedVNumber);
503 int GetVFileNumber(fname, maxFile)
507 return doGetXFileNumber(fname, 'V', maxFile);
510 int GetDDirNumber(fname, maxDir)
514 return doGetXFileNumber(fname, 'D', maxDir);
518 /*-----------------------------------------------------------------------------
522 * Given a full pathname for a file we need to create for the workstation AFS
523 * cache, go ahead and create the file.
526 * fname : Full pathname of file to create.
527 * statp : A pointer to a stat buffer which, if NON-NULL, will be
531 * 0 iff the file was created,
535 * The given cache file has been found to be missing.
539 *---------------------------------------------------------------------------*/
541 static int CreateCacheSubDir (basename, dirNum)
545 static char rn[] = "CreateCacheSubDir"; /* Routine Name */
549 /* Build the new cache subdirectory */
550 sprintf (dir, "%s/D%d", basename, dirNum);
553 printf("%s: Creating cache subdir '%s'\n",
556 if ((ret = mkdir(dir, 0700)) != 0) {
557 printf("%s: Can't create '%s', error return is %d (%d)\n",
558 rn, dir, ret, errno);
563 /* Mark this directory as created */
564 cache_dir_list[dirNum] = 0;
566 /* And return success */
570 static int MoveCacheFile (basename, fromDir, toDir, cacheFile, maxDir)
572 int fromDir, toDir, cacheFile, maxDir;
574 static char rn[] = "MoveCacheFile";
575 char from[1024], to[1024];
578 if (cache_dir_list[toDir] < 0 &&
579 (ret = CreateCacheSubDir(basename, toDir))) {
580 printf("%s: Can't create directory '%s/D%d'\n", rn, basename, toDir);
584 /* Build the from,to dir */
586 /* old-style location */
587 snprintf (from, sizeof(from), "%s/V%d", basename, cacheFile);
589 snprintf (from, sizeof(from), "%s/D%d/V%d", basename, fromDir, cacheFile);
592 snprintf (to, sizeof(from), "%s/D%d/V%d", basename, toDir, cacheFile);
595 printf("%s: Moving cacheFile from '%s' to '%s'\n",
598 if ((ret = rename (from, to)) != 0) {
599 printf("%s: Can't rename '%s' to '%s', error return is %d (%d)\n",
600 rn, from, to, ret, errno);
604 /* Reset directory pointer; fix file counts */
605 dir_for_V[cacheFile] = toDir;
606 cache_dir_list[toDir]++;
607 if (fromDir < maxDir && fromDir >= 0)
608 cache_dir_list[fromDir]--;
613 int CreateCacheFile(fname, statp)
617 static char rn[] = "CreateCacheFile"; /*Routine name*/
618 int cfd; /*File descriptor to AFS cache file*/
619 int closeResult; /*Result of close()*/
622 printf("%s: Creating cache file '%s'\n",
624 cfd = open(fname, createAndTrunc, ownerRWmode);
626 printf("%s: Can't create '%s', error return is %d (%d)\n",
627 rn, fname, cfd, errno);
631 closeResult = fstat (cfd, statp);
633 printf("%s: Can't stat newly-created AFS cache file '%s' (code %d)\n",
638 closeResult = close(cfd);
640 printf("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
648 static void CreateFileIfMissing(char *fullpn, int missing)
652 printf("CreateFileIfMissing: Creating '%s'\n", fullpn);
653 if (CreateCacheFile(fullpn, NULL))
654 printf("CreateFileIfMissing: Can't create '%s'\n", fullpn);
658 /*-----------------------------------------------------------------------------
662 * Sweep through the AFS cache directory, recording the inode number for
663 * each valid data cache file there. Also, delete any file that doesn't belong
664 * in the cache directory during this sweep, and remember which of the other
665 * residents of this directory were seen. After the sweep, we create any data
666 * cache files that were missing.
669 * vFilesFound : Set to the number of data cache files found.
672 * 0 if everything went well,
676 * This routine may be called several times. If the number of data cache files
677 * found is less than the global cacheFiles, then the caller will need to call it
678 * again to record the inodes of the missing zero-length data cache files created
679 * in the previous call.
682 * Fills up the global inode_for_V array, may create and/or delete files as
684 *---------------------------------------------------------------------------*/
687 static int doSweepAFSCache(vFilesFound,directory,dirNum,maxDir)
689 char *directory; /* /path/to/cache/directory */
690 int dirNum; /* current directory number */
691 int maxDir; /* maximum directory number */
693 static char rn[] = "doSweepAFSCache"; /* Routine Name */
694 char fullpn_FileToDelete[1024]; /*File to be deleted from cache*/
695 char *fileToDelete; /*Ptr to last component of above*/
696 DIR *cdirp; /*Ptr to cache directory structure*/
698 struct dirent64 *currp; /*Current directory entry*/
700 struct dirent *currp; /*Current directory entry*/
702 int vFileNum; /*Data cache file's associated number*/
703 int thisDir; /* A directory number */
707 printf("%s: Opening cache directory '%s'\n", rn, directory);
709 if (chmod(directory, 0700)) { /* force it to be 700 */
710 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn, directory);
713 cdirp = opendir(directory);
714 if (cdirp == (DIR *)0) {
715 printf("%s: Can't open AFS cache directory, '%s'.\n", rn, directory);
720 * Scan the directory entries, remembering data cache file inodes
721 * and the existance of other important residents. Recurse into
722 * the data subdirectories.
724 * Delete all files and directories that don't belong here.
726 sprintf(fullpn_FileToDelete, "%s/", directory);
727 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
730 for (currp = readdir64(cdirp); currp; currp = readdir64(cdirp))
732 for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
736 printf("%s: Current directory entry:\n",
739 printf("\tinode=%lld, reclen=%d, name='%s'\n",
740 currp->d_ino, currp->d_reclen, currp->d_name);
742 printf("\tinode=%d, reclen=%d, name='%s'\n",
743 currp->d_ino, currp->d_reclen, currp->d_name);
748 * If dirNum < 0, we are a top-level cache directory and should
749 * only contain sub-directories and other sundry files. Therefore,
750 * V-files are valid only if dirNum >= 0, and Directories are only
751 * valid if dirNum < 0.
754 if (*(currp->d_name) == 'V' &&
755 ((vFileNum = GetVFileNumber(currp->d_name, cacheFiles)) >= 0)) {
757 * Found a valid data cache filename. Remember this
758 * file's inode, directory, and bump the number of files found
759 * total and in this directory.
761 inode_for_V[vFileNum] = currp->d_ino;
762 dir_for_V[vFileNum] = dirNum; /* remember this directory */
765 /* If we're in a real subdir, mark this file to be moved
766 * if we've already got too many files in this directory
769 cache_dir_list[dirNum]++; /* keep directory's file count */
770 if (cache_dir_list[dirNum] > nFilesPerDir) {
771 /* Too many files -- add to filelist */
772 struct afsd_file_list *tmp = (struct afsd_file_list *)
773 malloc(sizeof(*tmp));
775 printf ("%s: MALLOC FAILED allocating file_list entry\n",
778 tmp->fileNum = vFileNum;
779 tmp->next = cache_dir_filelist[dirNum];
780 cache_dir_filelist[dirNum] = tmp;
786 else if (dirNum < 0 && (*(currp->d_name) == 'D') &&
787 GetDDirNumber(currp->d_name, 1<<30) >= 0) {
789 if ((vFileNum = GetDDirNumber(currp->d_name, maxDir)) >= 0) {
790 /* Found a valid cachefile sub-Directory. Remember this number
791 * and recurse into it. Note that subdirs cannot have subdirs.
794 } else if ((vFileNum = GetDDirNumber(currp->d_name, 1<<30)) >= 0) {
795 /* This directory is going away, but figure out if there
796 * are any cachefiles in here that should be saved by
797 * moving them to other cache directories. This directory
798 * will be removed later.
803 /* Save the highest directory number we've seen */
804 if (vFileNum > highDir)
807 /* If this directory is staying, be sure to mark it as 'found' */
808 if (retval == 1) cache_dir_list[vFileNum] = 0;
810 /* Print the dirname for recursion */
811 sprintf(fileToDelete, "%s", currp->d_name);
813 /* Note: vFileNum is the directory number */
814 retval = doSweepAFSCache(vFilesFound, fullpn_FileToDelete,
815 vFileNum, (retval == 1 ? 0 : -1));
817 printf ("%s: Recursive sweep failed on directory %s\n",
822 else if (dirNum < 0 && strcmp(currp->d_name, DCACHEFILE) == 0) {
824 * Found the file holding the dcache entries.
826 missing_DCacheFile = 0;
828 else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
830 * Found the file holding the volume info.
832 missing_VolInfoFile = 0;
834 else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
836 * Found the file holding the cell info.
838 missing_CellInfoFile = 0;
840 else if ((strcmp(currp->d_name, ".") == 0) ||
841 (strcmp(currp->d_name, "..") == 0) ||
842 #ifdef AFS_DECOSF_ENV
843 /* these are magic AdvFS files */
844 (strcmp(currp->d_name, ".tags") == 0) ||
845 (strcmp(currp->d_name, "quota.user") == 0) ||
846 (strcmp(currp->d_name, "quota.group") == 0) ||
848 #ifdef AFS_LINUX22_ENV
849 /* this is the ext3 journal file */
850 (strcmp(currp->d_name, ".journal") == 0) ||
852 (strcmp(currp->d_name, "lost+found") == 0)) {
854 * Don't do anything - this file is legit, and is to be left alone.
859 * This file/directory doesn't belong in the cache. Nuke it.
861 sprintf(fileToDelete, "%s", currp->d_name);
863 printf("%s: Deleting '%s'\n",
864 rn, fullpn_FileToDelete);
865 if (unlink(fullpn_FileToDelete)) {
866 if (errno == EISDIR && *fileToDelete == 'D') {
867 if (rmdir(fullpn_FileToDelete)) {
868 printf("%s: Can't rmdir '%s', errno is %d\n",
869 rn, fullpn_FileToDelete, errno);
872 printf("%s: Can't unlink '%s', errno is %d\n",
873 rn, fullpn_FileToDelete, errno);
881 * Create all the cache files that are missing.
883 CreateFileIfMissing(fullpn_DCacheFile, missing_DCacheFile);
884 CreateFileIfMissing(fullpn_VolInfoFile, missing_VolInfoFile);
885 CreateFileIfMissing(fullpn_CellInfoFile, missing_CellInfoFile);
887 /* ADJUST CACHE FILES */
889 /* First, let's walk through the list of files and figure out
890 * if there are any leftover files in extra directories or
891 * missing files. Move the former and create the latter in
892 * subdirs with extra space.
895 thisDir = 0; /* Keep track of which subdir has space */
897 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++) {
898 if (dir_for_V[vFileNum] == -1) {
899 /* This file does not exist. Create it in the first
900 * subdir that still has extra space.
902 while (thisDir < maxDir &&
903 cache_dir_list[thisDir] >= nFilesPerDir)
905 if (thisDir >= maxDir)
906 printf("%s: can't find directory to create V%d\n", rn, vFileNum);
909 assert (inode_for_V[vFileNum] == (AFSD_INO_T)0);
910 sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
912 printf("%s: Creating '%s'\n", rn, fullpn_VFile);
913 if (cache_dir_list[thisDir] < 0 &&
914 CreateCacheSubDir(directory, thisDir))
915 printf("%s: Can't create directory for '%s'\n",
917 if (CreateCacheFile(fullpn_VFile, &statb))
918 printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
920 inode_for_V[vFileNum] = statb.st_ino;
921 dir_for_V[vFileNum] = thisDir;
922 cache_dir_list[thisDir]++;
927 } else if (dir_for_V[vFileNum] >= maxDir ||
928 dir_for_V[vFileNum] == -2) {
929 /* This file needs to move; move it to the first subdir
930 * that has extra space. (-2 means it's in the toplevel)
932 while (thisDir < maxDir && cache_dir_list[thisDir] >= nFilesPerDir)
934 if (thisDir >= maxDir)
935 printf("%s: can't find directory to move V%d\n", rn, vFileNum);
937 if (MoveCacheFile (directory, dir_for_V[vFileNum], thisDir,
939 /* Cannot move. Ignore this file??? */
946 /* At this point, we've moved all of the valid cache files
947 * into the valid subdirs, and created all the extra
948 * cachefiles we need to create. Next, rebalance any subdirs
949 * with too many cache files into the directories with not
950 * enough cache files. Note that thisDir currently sits at
951 * the lowest subdir that _may_ have room.
954 for (dirNum = 0; dirNum < maxDir; dirNum++) {
955 struct afsd_file_list *thisFile;
957 for (thisFile = cache_dir_filelist[dirNum];
958 thisFile && cache_dir_list[dirNum] >= nFilesPerDir;
959 thisFile = thisFile->next) {
960 while (thisDir < maxDir && cache_dir_list[thisDir] >= nFilesPerDir)
962 if (thisDir >= maxDir)
963 printf("%s: can't find directory to move V%d\n", rn, vFileNum);
965 if (MoveCacheFile (directory, dirNum, thisDir,
966 thisFile->fileNum, maxDir)) {
967 /* Cannot move. Ignore this file??? */
971 } /* for each file to move */
972 } /* for each directory */
974 /* Remove any directories >= maxDir -- they should be empty */
975 for (; highDir >= maxDir; highDir--) {
976 sprintf(fileToDelete, "D%d", highDir);
977 if (unlink(fullpn_FileToDelete)) {
978 if (errno == EISDIR && *fileToDelete == 'D') {
979 if (rmdir(fullpn_FileToDelete)) {
980 printf("%s: Can't rmdir '%s', errno is %d\n",
981 rn, fullpn_FileToDelete, errno);
984 printf("%s: Can't unlink '%s', errno is %d\n",
985 rn, fullpn_FileToDelete, errno);
991 * Close the directory, return success.
994 printf("%s: Closing cache directory.\n",
1000 char *CheckCacheBaseDir(char *dir)
1002 struct stat statbuf;
1004 if ( !dir ) { return "cache base dir not specified"; }
1005 if ( stat(dir, &statbuf) != 0 ) {
1006 return "unable to stat cache base directory";
1009 /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */
1011 #ifdef AFS_LINUX24_ENV
1014 struct statfs statfsbuf;
1016 res = statfs(dir, &statfsbuf);
1018 return "unable to statfs cache base directory";
1020 if ( statfsbuf.f_type == 0x52654973 ) /* REISERFS_SUPER_MAGIC */
1022 return "cannot use reiserfs as cache partition";
1030 struct statfs statfsbuf;
1033 res = statfs(dir, &statfsbuf);
1036 return "unable to statfs cache base directory";
1039 if (sysfs(GETFSTYP, statfsbuf.f_fsid, name) != 0 )
1041 return "unable to determine filesystem type for cache base dir";
1044 if ( strcmp(name, "hfs") )
1046 return "can only use hfs filesystem for cache partition on hpux";
1055 struct stat statmnt, statci;
1057 if ((stat(dir, &statci) == 0) &&
1058 ((vfstab = fopen(MNTTAB, "r")) != NULL))
1060 while (getmntent(vfstab, &mnt) == 0) {
1061 if (strcmp(dir, mnt.mnt_mountp) != 0)
1066 if (cp = hasmntopt(&mnt, "dev="))
1067 rdev=(int)strtol(cp+strlen("dev="), (char **)NULL, 16);
1069 if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
1070 rdev=statmnt.st_dev;
1072 if ((rdev == statci.st_dev) &&
1073 (hasmntopt (&mnt, "logging") != NULL)) {
1076 return "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n";
1089 int SweepAFSCache(vFilesFound)
1092 static char rn[] = "SweepAFSCache"; /*Routine name*/
1093 int maxDir = (cacheFiles + nFilesPerDir - 1 ) / nFilesPerDir;
1098 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1100 printf("%s: Memory Cache, no cache sweep done\n", rn);
1104 if (cache_dir_list == NULL) {
1105 cache_dir_list = (int *) malloc (maxDir * sizeof(*cache_dir_list));
1106 if (cache_dir_list == NULL) {
1107 printf("%s: Malloc Failed!\n", rn);
1110 for (i=0; i < maxDir; i++)
1111 cache_dir_list[i] = -1; /* Does not exist */
1114 if (cache_dir_filelist == NULL) {
1115 cache_dir_filelist = (struct afsd_file_list **)
1116 malloc (maxDir * sizeof(*cache_dir_filelist));
1117 if (cache_dir_filelist == NULL) {
1118 printf("%s: Malloc Failed!\n", rn);
1121 memset (cache_dir_filelist, 0, maxDir * sizeof(*cache_dir_filelist));
1124 if (dir_for_V == NULL) {
1125 dir_for_V = (int *) malloc (cacheFiles * sizeof(*dir_for_V));
1126 if (dir_for_V == NULL) {
1127 printf("%s: Malloc Failed!\n", rn);
1130 for (i=0; i < cacheFiles; i++)
1131 dir_for_V[i] = -1; /* Does not exist */
1134 /* Note, setting dirNum to -2 here will cause cachefiles found in
1135 * the toplevel directory to be marked in directory "-2". This
1136 * allows us to differentiate between 'file not seen' (-1) and
1137 * 'file seen in top-level' (-2). Then when we try to move the
1138 * file into a subdirectory, we know it's in the top-level instead
1139 * of some other cache subdir.
1141 return doSweepAFSCache (vFilesFound, cacheBaseDir, -2, maxDir);
1144 static ConfigCell(aci, arock, adir)
1145 register struct afsconf_cell *aci;
1147 struct afsconf_dir *adir; {
1148 register int isHomeCell;
1149 register int i, code;
1150 afs_int32 cellFlags = 0;
1151 afs_int32 hosts[MAXHOSTSPERCELL];
1153 /* figure out if this is the home cell */
1154 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
1156 cellFlags = 2; /* not home, suid is forbidden */
1158 /* build address list */
1159 for(i=0;i<MAXHOSTSPERCELL;i++)
1160 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1162 if (aci->linkedCell) cellFlags |= 4; /* Flag that linkedCell arg exists,
1163 for upwards compatibility */
1165 /* configure one cell */
1166 code = call_syscall(AFSOP_ADDCELL2,
1167 hosts, /* server addresses */
1168 aci->name, /* cell name */
1169 cellFlags, /* is this the home cell? */
1170 aci->linkedCell); /* Linked cell, if any */
1172 printf("Adding cell '%s': error %d\n", aci->name, code);
1176 static ConfigCellAlias(aca, arock, adir)
1177 register struct afsconf_cellalias *aca;
1179 struct afsconf_dir *adir;
1181 /* push the alias into the kernel */
1182 call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
1186 #ifdef AFS_AFSDB_ENV
1187 static AfsdbLookupHandler()
1189 afs_int32 kernelMsg[64];
1190 char acellName[128];
1192 struct afsconf_cell acellInfo;
1197 acellName[0] = '\0';
1200 /* On some platforms you only get 4 args to an AFS call */
1201 int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
1202 code = call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
1203 if (code) { /* Something is wrong? */
1208 if (*acellName == 1) /* Shutting down */
1211 code = afsconf_GetAfsdbInfo(acellName, 0, &acellInfo);
1216 kernelMsg[0] = acellInfo.numServers;
1217 if (acellInfo.timeout)
1218 kernelMsg[1] = acellInfo.timeout - time(0);
1221 for (i=0; i<acellInfo.numServers; i++)
1222 kernelMsg[i+2] = acellInfo.hostAddr[i].sin_addr.s_addr;
1223 strncpy(acellName, acellInfo.name, sizeof(acellName));
1224 acellName[sizeof(acellName) - 1] = '\0';
1233 #include <sys/ioctl.h>
1236 #ifdef AFS_SGI65_ENV
1237 #define SET_RTPRI(P) { \
1238 struct sched_param sp; \
1239 sp.sched_priority = P; \
1240 if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \
1241 perror("sched_setscheduler"); \
1244 #define SET_AFSD_RTPRI() SET_RTPRI(68)
1245 #define SET_RX_RTPRI() SET_RTPRI(199)
1247 #ifdef AFS_LINUX20_ENV
1248 #define SET_AFSD_RTPRI()
1249 #define SET_RX_RTPRI() do { if (setpriority(PRIO_PROCESS, 0, -10)<0) \
1250 perror("setting rx priority"); \
1253 #define SET_AFSD_RTPRI()
1254 #define SET_RX_RTPRI()
1259 register struct cmd_syndesc *as;
1262 static char rn[] = "afsd"; /*Name of this routine*/
1263 register afs_int32 code; /*Result of fork()*/
1265 int currVFile; /*Current AFS cache file number passed in*/
1266 int mountFlags; /*Flags passed to mount()*/
1267 int lookupResult; /*Result of GetLocalCellName()*/
1268 int cacheIteration; /*How many times through cache verification*/
1269 int vFilesFound; /*How many data cache files were found in sweep*/
1270 struct afsconf_dir *cdir; /* config dir */
1272 char *fsTypeMsg = NULL;
1276 afs_int32 vfs1_type = -1;
1277 #ifdef AFS_SGI65_ENV
1278 struct sched_param sp;
1281 #ifdef AFS_SGI_VNODE_GLUE
1282 if (afs_init_kernel_config(-1) <0) {
1283 printf("Can't determine NUMA configuration, not starting AFS.\n");
1288 /* call atoi on the appropriate parsed results */
1289 if (as->parms[0].items) {
1291 cacheBlocks = atoi(as->parms[0].items->data);
1294 if (as->parms[1].items) {
1296 cacheFiles = atoi(as->parms[1].items->data);
1297 filesSet = 1; /* set when spec'd on cmd line */
1299 if (as->parms[2].items) {
1301 strcpy(rootVolume, as->parms[2].items->data);
1304 if (as->parms[3].items) {
1306 cacheStatEntries = atoi(as->parms[3].items->data);
1308 if (as->parms[4].items) {
1310 cacheBaseDir[0] = '\0';
1311 sawCacheBaseDir = 1;
1312 cacheFlags |= AFSCALL_INIT_MEMCACHE;
1316 if (as->parms[5].items) {
1318 strcpy(cacheBaseDir, as->parms[5].items->data);
1319 sawCacheBaseDir = 1;
1321 if (as->parms[6].items) {
1323 strcpy(cacheMountDir, as->parms[6].items->data);
1324 sawCacheMountDir = 1;
1326 if (as->parms[7].items) {
1328 nDaemons = atoi(as->parms[7].items->data);
1330 if (as->parms[8].items) {
1332 cacheSetTime = FALSE;
1334 if (as->parms[9].items) {
1338 if (as->parms[10].items) {
1342 if (as->parms[11].items) {
1347 if (as->parms[12].items) {
1349 chunkSize = atoi(as->parms[12].items->data);
1350 if (chunkSize < 0 || chunkSize > 30) {
1351 printf("afsd:invalid chunk size spec'd, using default\n");
1355 if (as->parms[13].items) {
1357 dCacheSize = atoi(as->parms[13].items->data);
1360 if (as->parms[14].items) {
1362 vCacheSize = atoi(as->parms[14].items->data);
1364 if (as->parms[15].items) {
1366 #ifndef AFS_AIX32_ENV
1367 printf("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
1369 nBiods = atoi(as->parms[15].items->data);
1373 if (as->parms[16].items) {
1375 preallocs = atoi(as->parms[16].items->data);
1378 if (as->parms[17].items) {
1380 inodes = atoi(as->parms[17].items->data);
1383 strcpy(confDir, AFSDIR_CLIENT_ETC_DIRPATH);
1384 if (as->parms[17].items) {
1386 strcpy(confDir, as->parms[17].items->data);
1388 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
1389 sprintf(fullpn_AFSLogFile, "%s/%s", confDir, AFSLOGFILE);
1390 if (as->parms[18].items) {
1392 strcpy(fullpn_AFSLogFile, as->parms[18].items->data);
1394 if (as->parms[19].items) {
1396 afsd_CloseSynch = 1;
1398 if (as->parms[20].items) {
1402 * Cold shutdown is the default
1404 printf("afsd: Shutting down all afs processes and afs state\n");
1405 code = call_syscall(AFSOP_SHUTDOWN, 1);
1407 printf("afsd: AFS still mounted; Not shutting down\n");
1412 if (as->parms[21].items) {
1413 /* -enable_peer_stats */
1414 enable_peer_stats = 1;
1416 if (as->parms[22].items) {
1417 /* -enable_process_stats */
1418 enable_process_stats = 1;
1420 if (as->parms[23].items) {
1421 /* -mem_alloc_sleep */
1422 cacheFlags |= AFSCALL_INIT_MEMCACHE_SLEEP;
1424 if (as->parms[24].items) {
1426 #ifdef AFS_AFSDB_ENV
1429 printf("afsd: No AFSDB support; ignoring -afsdb");
1432 if (as->parms[25].items) {
1433 /* -files_per_subdir */
1434 int res = atoi(as->parms[25].items->data);
1435 if ( res < 10 || res > 2^30) {
1436 printf("afsd:invalid number of files per subdir, \"%s\". Ignored\n", as->parms[25].items->data);
1441 if (as->parms[26].items) {
1445 if (as->parms[27].items) {
1447 enable_fakestat = 2;
1449 if (as->parms[28].items) {
1451 enable_fakestat = 1;
1453 if (as->parms[29].items) {
1459 * Pull out all the configuration info for the workstation's AFS cache and
1460 * the cellular community we're willing to let our users see.
1462 cdir = afsconf_Open(confDir);
1464 printf("afsd: some file missing or bad in %s\n", confDir);
1468 lookupResult = afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
1470 printf("%s: Can't get my home cell name! [Error is %d]\n",
1475 printf("%s: My home cell is '%s'\n",
1479 /* parse cacheinfo file if this is a diskcache */
1480 if (ParseCacheInfoFile()) {
1484 if ((logfd = fopen(fullpn_AFSLogFile,"r+")) == 0) {
1485 if (afsd_verbose) printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile);
1486 if (CreateCacheFile(fullpn_AFSLogFile, NULL)) {
1487 printf("%s: Can't create '%s' (You may want to use the -logfile option)\n", rn, fullpn_AFSLogFile);
1493 /* do some random computations in memcache case to get things to work
1494 * reasonably no matter which parameters you set.
1496 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1497 /* memory cache: size described either as blocks or dcache entries, but
1500 if (sawDCacheSize) {
1501 if (sawCacheBlocks) {
1502 printf("%s: can't set cache blocks and dcache size simultaneously when diskless.\n", rn);
1505 /* compute the cache size based on # of chunks times the chunk size */
1506 i = (chunkSize == 0? 13 : chunkSize);
1507 i = (1<<i); /* bytes per chunk */
1508 cacheBlocks = i * dCacheSize;
1509 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
1512 /* compute the dcache size from overall cache size and chunk size */
1513 i = (chunkSize == 0? 13 : chunkSize);
1514 /* dCacheSize = (cacheBlocks << 10) / (1<<i); */
1516 dCacheSize = (cacheBlocks >> (i-10));
1517 } else if (i < 10) {
1518 dCacheSize = (cacheBlocks << (10-i));
1520 dCacheSize = cacheBlocks;
1522 /* don't have to set sawDCacheSize here since it isn't overwritten
1523 * by ParseCacheInfoFile.
1526 /* kernel computes # of dcache entries as min of cacheFiles and dCacheSize,
1527 * so we now make them equal.
1529 cacheFiles = dCacheSize;
1533 * Compute the number of cache files based on cache size,
1534 * but only if -files isn't given on the command line.
1535 * Don't let # files be so small as to prevent full utilization
1536 * of the cache unless user has explicitly asked for it.
1537 * average V-file is ~10K, according to tentative empirical studies.
1540 cacheFiles = cacheBlocks / 10;
1541 if (cacheFiles < 100) cacheFiles = 100;
1542 /* Always allow more files than chunks. Presume average V-file
1543 * is ~67% of a chunk... (another guess, perhaps Honeyman will
1544 * have a grad student write a paper). i is KILOBYTES.
1546 i = 1 << (chunkSize == 0? 6 : (chunkSize<10 ? 0 : chunkSize -10));
1547 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
1548 /* never permit more files than blocks, while leaving space for
1549 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
1550 * CacheItems is 50 Bytes / file (== 1K/20)
1552 #define VOLINFOSZ 20
1553 #define CACHEITMSZ (cacheFiles / 20)
1555 cacheFiles= min(cacheFiles,(cacheBlocks -VOLINFOSZ -CACHEITMSZ)/4);
1557 cacheFiles = min(cacheFiles, cacheBlocks - VOLINFOSZ - CACHEITMSZ);
1559 if (cacheFiles < 100)
1560 fprintf (stderr, "%s: WARNING: cache probably too small!\n", rn);
1562 if (!sawDCacheSize) {
1563 if ((cacheFiles / 2) > dCacheSize)
1564 dCacheSize = cacheFiles / 2;
1565 if (dCacheSize > 2000)
1571 * Create and zero the inode table for the desired cache files.
1573 inode_for_V = (AFSD_INO_T *) malloc(cacheFiles * sizeof(AFSD_INO_T));
1574 if (inode_for_V == (AFSD_INO_T *)0) {
1575 printf("%s: malloc() failed for cache file inode table with %d entries.\n",
1579 memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
1581 printf("%s: %d inode_for_V entries at 0x%x, %d bytes\n",
1582 rn, cacheFiles, inode_for_V,
1583 (cacheFiles * sizeof(AFSD_INO_T)));
1586 * Set up all the pathnames we'll need for later.
1588 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
1589 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
1590 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
1591 sprintf(fullpn_VFile, "%s/", cacheBaseDir);
1592 vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
1594 if ((fsTypeMsg = CheckCacheBaseDir(cacheBaseDir))) {
1595 printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
1599 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1604 * Set up all the kernel processes needed for AFS.
1607 setpgrp(getpid(), 0);
1610 /* Initialize RX daemons and services */
1612 /* initialize the rx random number generator from user space */
1614 /* parse multihomed address files */
1615 afs_int32 addrbuf[MAXIPADDRS],maskbuf[MAXIPADDRS],mtubuf[MAXIPADDRS];
1617 code=parseNetFiles(addrbuf,maskbuf,mtubuf,MAXIPADDRS,reason,
1618 AFSDIR_CLIENT_NETINFO_FILEPATH,
1619 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
1621 call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
1623 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",reason);
1626 /* Set realtime priority for most threads to same as for biod's. */
1629 #ifdef AFS_SGI53_ENV
1630 #ifdef AFS_SGI61_ENV
1632 #else /* AFS_SGI61_ENV */
1633 code = get_nfsstaticaddr();
1635 call_syscall(AFSOP_NFSSTATICADDR, code);
1636 #endif /* AFS_SGI61_ENV */
1637 #endif /* AFS_SGI_53_ENV */
1639 /* Start listener, then callback listener. Lastly, start rx event daemon.
1640 * Change in ordering is so that Linux port has socket fd in listener
1642 * preallocs are passed for both listener and callback server. Only
1643 * the one which actually does the initialization uses them though.
1645 if (preallocs < cacheStatEntries+50)
1646 preallocs = cacheStatEntries+50;
1647 #ifdef RXK_LISTENER_ENV
1649 printf("%s: Forking rx listener daemon.\n", rn);
1653 SET_RX_RTPRI(); /* max advised for non-interrupts */
1654 call_syscall(AFSOP_RXLISTENER_DAEMON,
1657 enable_process_stats);
1662 printf("%s: Forking rx callback listener.\n", rn);
1666 call_syscall(AFSOP_START_RXCALLBACK, preallocs);
1669 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1671 printf("%s: Forking rxevent daemon.\n", rn);
1675 SET_RX_RTPRI(); /* max advised for non-interrupts */
1676 call_syscall(AFSOP_RXEVENT_DAEMON);
1681 #ifdef AFS_AFSDB_ENV
1684 printf("%s: Forking AFSDB lookup handler.\n", rn);
1687 AfsdbLookupHandler();
1693 code = call_syscall(AFSOP_BASIC_INIT, 1);
1695 printf("%s: Error %d in basic initialization.\n", rn, code);
1698 * Tell the kernel some basic information about the workstation's cache.
1701 printf("%s: Calling AFSOP_CACHEINIT: %d stat cache entries, %d optimum cache files, %d blocks in the cache, flags = 0x%x, dcache entries %d\n",
1702 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
1704 memset(&cparams, '\0', sizeof(cparams));
1705 cparams.cacheScaches = cacheStatEntries;
1706 cparams.cacheFiles = cacheFiles;
1707 cparams.cacheBlocks = cacheBlocks;
1708 cparams.cacheDcaches = dCacheSize;
1709 cparams.cacheVolumes = vCacheSize;
1710 cparams.chunkSize = chunkSize;
1711 cparams.setTimeFlag = cacheSetTime;
1712 cparams.memCacheFlag = cacheFlags;
1714 cparams.inodes = inodes;
1716 call_syscall(AFSOP_CACHEINIT, &cparams);
1717 if (afsd_CloseSynch)
1718 call_syscall(AFSOP_CLOSEWAIT);
1721 * Sweep the workstation AFS cache directory, remembering the inodes of
1722 * valid files and deleting extraneous files. Keep sweeping until we
1723 * have the right number of data cache files or we've swept too many
1726 * This also creates files in the cache directory like VolumeItems and
1727 * CellItems, and thus must be ran before those are sent to the kernel.
1730 printf("%s: Sweeping workstation's AFS cache directory.\n",
1733 /* Memory-cache based system doesn't need any of this */
1734 if(!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
1737 if (SweepAFSCache(&vFilesFound)) {
1738 printf("%s: Error on sweep %d of workstation AFS cache \
1739 directory.\n", rn, cacheIteration);
1743 printf("%s: %d out of %d data cache files found in sweep %d.\n",
1744 rn, vFilesFound, cacheFiles, cacheIteration);
1745 } while ((vFilesFound < cacheFiles) &&
1746 (cacheIteration < MAX_CACHE_LOOPS));
1747 } else if(afsd_verbose)
1748 printf("%s: Using memory cache, not swept\n", rn);
1751 * Pass the kernel the name of the workstation cache file holding the
1755 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n",
1756 rn, fullpn_DCacheFile);
1757 /* once again, meaningless for a memory-based cache. */
1758 if(!(cacheFlags & AFSCALL_INIT_MEMCACHE))
1759 call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
1762 * Pass the kernel the name of the workstation cache file holding the
1766 printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n",
1767 rn, fullpn_CellInfoFile);
1768 call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
1770 if (enable_dynroot) {
1772 printf("%s: Enabling dynroot support in kernel.\n", rn);
1773 code = call_syscall(AFSOP_SET_DYNROOT, 1);
1775 printf("%s: Error enabling dynroot support.\n", rn);
1778 if (enable_fakestat) {
1780 printf("%s: Enabling fakestat support in kernel.\n", rn);
1781 code = call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
1783 printf("%s: Error enabling fakestat support.\n", rn);
1787 * Tell the kernel about each cell in the configuration.
1789 afsconf_CellApply(cdir, ConfigCell, NULL);
1790 afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
1793 * Set the primary cell name.
1795 call_syscall(AFSOP_SET_THISCELL, LclCellName);
1797 /* Initialize AFS daemon threads. */
1799 printf("%s: Forking AFS daemon.\n", rn);
1803 call_syscall(AFSOP_START_AFS);
1808 printf("%s: Forking Check Server Daemon.\n", rn);
1812 code = call_syscall(AFSOP_START_CS);
1814 printf("%s: No check server daemon in client.\n", rn);
1819 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
1820 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
1821 /* Add one because for sgi we always "steal" the first daemon for a
1822 * different task if we only have a 4K stack.
1826 for (i=0;i<nDaemons;i++) {
1830 #ifdef AFS_AIX32_ENV
1831 call_syscall(AFSOP_START_BKG, 0);
1833 call_syscall(AFSOP_START_BKG);
1838 #ifdef AFS_AIX32_ENV
1840 nBiods = nDaemons * 2;
1843 for (i=0; i< nBiods;i++) {
1845 if (code == 0) { /* Child */
1846 call_syscall(AFSOP_START_BKG, nBiods);
1853 * If the root volume has been explicitly set, tell the kernel.
1857 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n",
1859 call_syscall(AFSOP_ROOTVOLUME, rootVolume);
1863 * Pass the kernel the name of the workstation cache file holding the
1864 * volume information.
1867 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n",
1868 rn, fullpn_VolInfoFile);
1869 call_syscall(AFSOP_VOLUMEINFO,fullpn_VolInfoFile);
1872 * Pass the kernel the name of the afs logging file holding the volume
1876 printf("%s: Calling AFSOP_AFSLOG: volume info file is '%s'\n",
1877 rn, fullpn_AFSLogFile);
1878 #if defined(AFS_SGI_ENV)
1879 /* permit explicit -logfile argument to enable logging on memcache systems */
1880 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE) || as->parms[18].items)
1882 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... nor this ... */
1884 call_syscall(AFSOP_AFSLOG,fullpn_AFSLogFile);
1887 * Give the kernel the names of the AFS files cached on the workstation's
1891 printf("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
1892 rn, cacheFiles, cacheBaseDir);
1893 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
1894 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
1895 #ifdef AFS_SGI62_ENV
1896 call_syscall(AFSOP_CACHEINODE,
1897 (afs_uint32)(inode_for_V[currVFile]>>32),
1898 (afs_uint32)(inode_for_V[currVFile] & 0xffffffff));
1900 call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
1906 * All the necessary info has been passed into the kernel to run an AFS
1907 * system. Give the kernel our go-ahead.
1910 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n",
1912 call_syscall(AFSOP_GO, cacheSetTime);
1915 * At this point, we have finished passing the kernel all the info
1916 * it needs to set up the AFS. Mount the AFS root.
1918 printf("%s: All AFS daemons started.\n", rn);
1921 printf("%s: Forking trunc-cache daemon.\n", rn);
1925 call_syscall(AFSOP_START_TRUNCDAEMON);
1929 if (!enable_nomount) {
1931 mountFlags = 0; /* Read/write file system, can do setuid() */
1932 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
1934 mountFlags |= MS_DATA;
1936 mountFlags |= M_NEWTYPE; /* This searches by name in vfs_conf.c so don't need to recompile vfs.c because MOUNT_MAXTYPE has changed; it seems that Sun fixed this at last... */
1940 #if defined(AFS_HPUX100_ENV)
1941 mountFlags |= MS_DATA;
1945 printf("%s: Mounting the AFS root on '%s', flags: %d.\n",
1946 rn, cacheMountDir, mountFlags);
1948 if ((mount("AFS",cacheMountDir,mountFlags,GT_AFS,(caddr_t) 0)) < 0) {
1951 if ((mount("AFS",cacheMountDir,mountFlags,(caddr_t) 0)) < 0) {
1954 if ((fsmount(MOUNT_AFS,cacheMountDir,mountFlags,(caddr_t) 0)) < 0) {
1959 #if defined(AFS_HPUX100_ENV)
1960 if ((mount("",cacheMountDir,mountFlags,"afs", NULL, 0)) < 0) {
1963 #if defined(AFS_HPUX90_ENV)
1968 strcpy(buffer, "afs");
1969 code = vfsmount(-1,cacheMountDir,mountFlags,(caddr_t) buffer);
1970 sscanf(buffer, "%d", &vfs1_type);
1972 printf("Can't find 'afs' type in the registered filesystem table!\n");
1975 sscanf(buffer, "%d", &vfs1_type);
1977 printf("AFS vfs slot number is %d\n", vfs1_type);
1979 if ((vfsmount(vfs1_type,cacheMountDir,mountFlags,(caddr_t) 0)) < 0) {
1981 if (call_syscall(AFSOP_AFS_VFSMOUNT, MOUNT_AFS, cacheMountDir,
1982 mountFlags, (caddr_t)NULL) < 0) {
1986 if ((mount("AFS",cacheMountDir,mountFlags,"afs", NULL, 0)) < 0) {
1988 #if defined(AFS_SGI_ENV)
1989 mountFlags = MS_FSS;
1990 if ((mount(MOUNT_AFS,cacheMountDir,mountFlags,(caddr_t) MOUNT_AFS)) < 0) {
1992 #ifdef AFS_LINUX20_ENV
1993 if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL))<0) {
1995 /* This is the standard mount used by the suns and rts */
1996 if ((mount(MOUNT_AFS,cacheMountDir,mountFlags,(caddr_t) 0)) < 0) {
1997 #endif /* AFS_LINUX20_ENV */
1998 #endif /* AFS_SGI_ENV */
1999 #endif /* AFS_SUN5_ENV */
2000 #endif /* AFS_HPUX100_ENV */
2001 #endif /* AFS_HPUX_ENV */
2002 #endif /* AFS_AIX_ENV */
2003 #endif /* AFS_AUX_ENV */
2004 #endif /* AFS_FBSD_ENV */
2005 #endif /* AFS_DEC_ENV */
2006 printf("%s: Can't mount AFS on %s(%d)\n",
2007 rn, cacheMountDir, errno);
2017 printf("%s: Forking 'rmtsys' daemon.\n", rn);
2026 * Exit successfully.
2031 #include "AFS_component_version_number.c"
2038 register struct cmd_syndesc *ts;
2040 ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
2041 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "1024 byte blocks in cache");
2042 cmd_AddParm(ts, "-files", CMD_SINGLE, CMD_OPTIONAL, "files in cache");
2043 cmd_AddParm(ts, "-rootvol", CMD_SINGLE, CMD_OPTIONAL, "name of AFS root volume");
2044 cmd_AddParm(ts, "-stat", CMD_SINGLE, CMD_OPTIONAL, "number of stat entries");
2045 cmd_AddParm(ts, "-memcache", CMD_FLAG, CMD_OPTIONAL, "run diskless");
2046 cmd_AddParm(ts, "-cachedir", CMD_SINGLE, CMD_OPTIONAL, "cache directory");
2047 cmd_AddParm(ts, "-mountdir", CMD_SINGLE, CMD_OPTIONAL, "mount location");
2048 cmd_AddParm(ts, "-daemons", CMD_SINGLE, CMD_OPTIONAL, "number of daemons to use");
2049 cmd_AddParm(ts, "-nosettime", CMD_FLAG, CMD_OPTIONAL, "don't set the time");
2050 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "display lots of information");
2051 cmd_AddParm(ts, "-rmtsys", CMD_FLAG, CMD_OPTIONAL, "start NFS rmtsysd program");
2052 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "display debug info");
2053 cmd_AddParm(ts, "-chunksize", CMD_SINGLE, CMD_OPTIONAL, "log(2) of chunk size");
2054 cmd_AddParm(ts, "-dcache", CMD_SINGLE, CMD_OPTIONAL, "number of dcache entries");
2055 cmd_AddParm(ts, "-volumes", CMD_SINGLE, CMD_OPTIONAL, "number of volume entries");
2056 cmd_AddParm(ts, "-biods", CMD_SINGLE, CMD_OPTIONAL, "number of bkg I/O daemons (aix vm)");
2058 cmd_AddParm(ts, "-prealloc", CMD_SINGLE, CMD_OPTIONAL, "number of 'small' preallocated blocks");
2060 cmd_AddParm(ts, "-pininodes", CMD_SINGLE, CMD_OPTIONAL, "number of inodes to hog");
2062 cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL, "configuration directory");
2063 cmd_AddParm(ts, "-logfile", CMD_SINGLE, CMD_OPTIONAL, "Place to keep the CM log");
2064 cmd_AddParm(ts, "-waitclose", CMD_FLAG, CMD_OPTIONAL, "make close calls synchronous");
2065 cmd_AddParm(ts, "-shutdown", CMD_FLAG, CMD_OPTIONAL, "Shutdown all afs state");
2066 cmd_AddParm(ts, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL|CMD_HIDE, "Collect rpc statistics by peer");
2067 cmd_AddParm(ts, "-enable_process_stats", CMD_FLAG, CMD_OPTIONAL|CMD_HIDE, "Collect rpc statistics for this process");
2068 cmd_AddParm(ts, "-mem_alloc_sleep", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE), "Allow sleeps when allocating memory cache");
2069 cmd_AddParm(ts, "-afsdb", CMD_FLAG, (CMD_OPTIONAL
2070 #ifndef AFS_AFSDB_ENV
2073 ), "Enable AFSDB support");
2074 cmd_AddParm(ts, "-files_per_subdir", CMD_SINGLE, CMD_OPTIONAL, "log(2) of the number of cache files per cache subdirectory");
2075 cmd_AddParm(ts, "-dynroot", CMD_FLAG, CMD_OPTIONAL, "Enable dynroot support");
2076 cmd_AddParm(ts, "-fakestat", CMD_FLAG, CMD_OPTIONAL, "Enable fakestat support for cross-cell mounts");
2077 cmd_AddParm(ts, "-fakestat-all", CMD_FLAG, CMD_OPTIONAL, "Enable fakestat support for all mounts");
2078 cmd_AddParm(ts, "-nomount", CMD_FLAG, CMD_OPTIONAL, "Do not mount AFS");
2079 return (cmd_Dispatch(argc, argv));
2084 #define MOUNTED_TABLE MNT_MNTTAB
2087 #define MOUNTED_TABLE MNTTAB
2089 #define MOUNTED_TABLE MOUNTED
2093 static int HandleMTab() {
2094 #if (defined (AFS_SUN_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)) && !defined(AFS_SUN58_ENV)
2098 struct mnttab tmntent;
2100 memset(&tmntent, '\0', sizeof(struct mnttab));
2101 if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) {
2102 printf("Can't open %s\n", MOUNTED_TABLE);
2106 tmntent.mnt_special = "AFS";
2107 tmntent.mnt_mountp = cacheMountDir;
2108 tmntent.mnt_fstype = "xx";
2109 tmntent.mnt_mntopts = "rw";
2110 sprintf(tbuf, "%ld", (long)time((time_t *)0));
2111 tmntent.mnt_time = tbuf;
2112 putmntent(tfilep, &tmntent);
2115 #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
2116 struct mntent tmntent;
2118 tfilep = setmntent("/etc/mtab", "a+");
2119 tmntent.mnt_fsname = "AFS";
2120 tmntent.mnt_dir = cacheMountDir;
2121 tmntent.mnt_type = "afs";
2122 tmntent.mnt_opts = "rw";
2123 tmntent.mnt_freq = 1;
2124 tmntent.mnt_passno = 3;
2125 addmntent(tfilep, &tmntent);
2128 struct mntent tmntent;
2130 memset(&tmntent, '\0', sizeof(struct mntent));
2131 tfilep = setmntent(MOUNTED_TABLE, "a+");
2133 printf("Can't open %s for write; Not adding afs entry to it\n",
2137 tmntent.mnt_fsname = "AFS";
2138 tmntent.mnt_dir = cacheMountDir;
2139 tmntent.mnt_type = "xx";
2140 tmntent.mnt_opts = "rw";
2141 tmntent.mnt_freq = 1;
2142 tmntent.mnt_passno = 3;
2144 tmntent.mnt_time = time(0);
2145 tmntent.mnt_cnode = 0;
2147 addmntent(tfilep, &tmntent);
2149 #endif /* AFS_SGI_ENV */
2150 #endif /* AFS_SUN5_ENV */
2151 #endif /* unreasonable systems */
2152 #ifdef AFS_DARWIN_ENV
2153 mach_port_t diskarb_port;
2154 kern_return_t status;
2156 status = DiskArbStart(&diskarb_port);
2157 if (status == KERN_SUCCESS) {
2158 status = DiskArbDiskAppearedWithMountpointPing_auto("AFS",
2159 DISK_ARB_NETWORK_DISK_FLAG, cacheMountDir);
2163 #endif /* AFS_DARWIN_ENV */
2167 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
2168 call_syscall(param1, param2, param3, param4, param5, param6, param7)
2169 long param1, param2, param3, param4, param5, param6, param7;
2172 #ifdef AFS_LINUX20_ENV
2183 error = syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4, param5, param6, param7);
2184 if (afsd_verbose) printf("SScall(%d, %d, %d)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1, error);
2187 #else /* AFS_AIX32_ENV */
2188 #if defined(AFS_SGI_ENV)
2189 call_syscall(call, parm0, parm1, parm2, parm3, parm4)
2194 error = afs_syscall(call, parm0, parm1, parm2, parm3, parm4);
2195 if (afsd_verbose) printf("SScall(%d, %d)=%d ", call, parm0, error);
2200 call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6) {
2202 return syscall(AFSCALL_CALL, call, parm0, parm1, parm2, parm3, parm4, parm5, parm6);
2204 #endif /* AFS_SGI_ENV */
2205 #endif /* AFS_AIX32_ENV */
2209 /* Special handling for AIX's afs mount operation since they require much more miscl. information before making the vmount(2) syscall */
2210 #include <sys/vfs.h>
2212 #define ROUNDUP(x) (((x) + 3) & ~3)
2215 struct vmount *vmountp;
2218 size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir)+1) + 5*4;
2219 /* Malloc the vmount structure */
2220 if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) {
2221 printf("Can't allocate space for the vmount structure (AIX)\n");
2225 /* zero out the vmount structure */
2226 memset(vmountp, '\0', size);
2228 /* transfer info into the vmount structure */
2229 vmountp->vmt_revision = VMT_REVISION;
2230 vmountp->vmt_length = size;
2231 vmountp->vmt_fsid.fsid_dev = 0;
2232 vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS;
2233 vmountp->vmt_vfsnumber = 0;
2234 vmountp->vmt_time = 0;/* We'll put the time soon! */
2235 vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */
2236 vmountp->vmt_gfstype = AFS_MOUNT_AFS;
2237 vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw");
2239 /* Do the actual mount system call */
2240 error = vmount(vmountp, size);
2245 vmountdata(vmtp, obj, stub, host, hostsname, info, args)
2246 struct vmount *vmtp;
2247 char *obj, *stub, *host, *hostsname, *info, *args;
2249 register struct data {
2255 vdp = (struct data *)vmtp->vmt_data;
2256 vdp->vmt_off = sizeof(struct vmount);
2257 size = ROUNDUP(strlen(obj) + 1);
2258 vdp->vmt_size = size;
2259 strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj);
2263 vdp->vmt_off = vdprev->vmt_off + size;
2264 size = ROUNDUP(strlen(stub) + 1);
2265 vdp->vmt_size = size;
2266 strcpy(vmt2dataptr(vmtp, VMT_STUB), stub);
2270 vdp->vmt_off = vdprev->vmt_off + size;
2271 size = ROUNDUP(strlen(host) + 1);
2272 vdp->vmt_size = size;
2273 strcpy(vmt2dataptr(vmtp, VMT_HOST), host);
2277 vdp->vmt_off = vdprev->vmt_off + size;
2278 size = ROUNDUP(strlen(hostsname) + 1);
2279 vdp->vmt_size = size;
2280 strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname);
2285 vdp->vmt_off = vdprev->vmt_off + size;
2286 size = ROUNDUP(strlen(info) + 1);
2287 vdp->vmt_size = size;
2288 strcpy(vmt2dataptr(vmtp, VMT_INFO), info);
2292 vdp->vmt_off = vdprev->vmt_off + size;
2293 size = ROUNDUP(strlen(args) + 1);
2294 vdp->vmt_size = size;
2295 strcpy(vmt2dataptr(vmtp, VMT_ARGS), args);
2297 #endif /* AFS_AIX_ENV */
2299 #ifdef AFS_SGI53_ENV
2300 #ifdef AFS_SGI61_ENV
2301 /* The dwarf structures are searched to find entry points of static functions
2302 * and the addresses of static variables. The file name as well as the
2303 * sybmol name is reaquired.
2306 /* Contains list of names to find in given file. */
2308 char *name; /* Name of variable or function. */
2309 afs_hyper_t addr; /* Address of function, undefined if not found. */
2310 Dwarf_Half type; /* DW_AT_location for vars, DW_AT_lowpc for func's */
2311 char found; /* set if found. */
2315 char *file; /* Name of file containing vars or funcs */
2316 staticAddrList *addrList; /* List of vars and/or funcs. */
2317 int nAddrs; /* # of addrList's */
2318 int found; /* set if we've found this file already. */
2321 /* routines used to find addresses in /unix */
2322 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2323 void findMDebugStaticAddresses(staticNameList *, int, int);
2325 void findDwarfStaticAddresses(staticNameList *, int);
2326 void findElfAddresses(Dwarf_Debug, Dwarf_Die, staticNameList *);
2327 void getElfAddress(Dwarf_Debug, Dwarf_Die, staticAddrList *);
2329 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2330 #define AFS_N_FILELISTS 2
2331 #define AFS_SYMS_NEEDED 3
2332 #else /* AFS_SGI62_ENV */
2333 #define AFS_N_FILELISTS 1
2334 #endif /* AFS_SGI62_ENV */
2338 void set_staticaddrs(void)
2340 staticNameList fileList[AFS_N_FILELISTS];
2342 fileList[0].addrList = (staticAddrList*)calloc(1, sizeof(staticAddrList));
2343 if (!fileList[0].addrList) {
2344 printf("set_staticaddrs: Can't calloc fileList[0].addrList\n");
2347 fileList[0].file = "nfs_server.c";
2348 fileList[0].found = 0;
2349 fileList[0].nAddrs = 1;
2350 fileList[0].addrList[0].name = "rfsdisptab_v2";
2351 fileList[0].addrList[0].type = DW_AT_location;
2352 fileList[0].addrList[0].found = 0;
2354 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2355 fileList[1].addrList = (staticAddrList*)calloc(2, sizeof(staticAddrList));
2356 if (!fileList[1].addrList) {
2357 printf("set_staticaddrs: Can't malloc fileList[1].addrList\n");
2360 fileList[1].file = "uipc_socket.c";
2361 fileList[1].found = 0;
2362 fileList[1].nAddrs = 2;
2363 fileList[1].addrList[0].name = "sblock";
2364 fileList[1].addrList[0].type = DW_AT_low_pc;
2365 fileList[1].addrList[0].found = 0;
2366 fileList[1].addrList[1].name = "sbunlock";
2367 fileList[1].addrList[1].type = DW_AT_low_pc;
2368 fileList[1].addrList[1].found = 0;
2370 if (64 != sysconf(_SC_KERN_POINTERS))
2371 findMDebugStaticAddresses(fileList, AFS_N_FILELISTS, AFS_SYMS_NEEDED);
2373 #endif /* AFS_SGI62_ENV */
2374 findDwarfStaticAddresses(fileList, AFS_N_FILELISTS);
2376 if (fileList[0].addrList[0].found) {
2377 call_syscall(AFSOP_NFSSTATICADDR2, fileList[0].addrList[0].addr.high,
2378 fileList[0].addrList[0].addr.low);
2382 printf("NFS V2 is not present in the kernel.\n");
2384 free(fileList[0].addrList);
2385 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2386 if (fileList[1].addrList[0].found && fileList[1].addrList[1].found) {
2387 call_syscall(AFSOP_SBLOCKSTATICADDR2,
2388 fileList[1].addrList[0].addr.high,
2389 fileList[1].addrList[0].addr.low,
2390 fileList[1].addrList[1].addr.high,
2391 fileList[1].addrList[1].addr.low);
2394 if (!fileList[1].addrList[0].found)
2395 printf("Can't find %s in kernel. Exiting.\n",
2396 fileList[1].addrList[0].name);
2397 if (!fileList[1].addrList[0].found)
2398 printf("Can't find %s in kernel. Exiting.\n",
2399 fileList[1].addrList[1].name);
2402 free(fileList[1].addrList);
2403 #endif /* AFS_SGI62_ENV */
2407 /* Find addresses for static variables and functions. */
2409 findDwarfStaticAddresses(staticNameList * nameList, int nLists)
2416 char *hname = (char*)0;
2417 Dwarf_Unsigned dwarf_access = O_RDONLY;
2418 Dwarf_Debug dwarf_debug;
2419 Dwarf_Error dwarf_error;
2420 Dwarf_Unsigned dwarf_cu_header_length;
2421 Dwarf_Unsigned dwarf_abbrev_offset;
2422 Dwarf_Half dwarf_address_size;
2423 Dwarf_Unsigned next_cu_header;
2424 Dwarf_Die dwarf_die;
2425 Dwarf_Die dwarf_next_die;
2426 Dwarf_Die dwarf_child_die;
2428 if (elf_version(EV_CURRENT) == EV_NONE) {
2429 printf("findDwarfStaticAddresses: Bad elf version.\n");
2433 if ((fd=open("/unix", O_RDONLY,0))<0) {
2434 printf("findDwarfStaticAddresses: Failed to open /unix.\n");
2437 code = dwarf_init(fd, dwarf_access, NULL, NULL, &dwarf_debug,
2439 if (code != DW_DLV_OK) {
2440 /* Nope hope for the elves and dwarves, try intermediate code. */
2447 /* Run through the headers until we find ones for files we've
2448 * specified in nameList.
2450 code = dwarf_next_cu_header(dwarf_debug,
2451 &dwarf_cu_header_length, NULL,
2452 &dwarf_abbrev_offset,
2453 &dwarf_address_size,
2456 if (code == DW_DLV_NO_ENTRY) {
2459 else if (code == DW_DLV_ERROR) {
2460 printf("findDwarfStaticAddresses: Error reading headers: %s\n",
2461 dwarf_errmsg(dwarf_error));
2465 code = dwarf_siblingof(dwarf_debug, NULL, &dwarf_die, &dwarf_error);
2466 if (code != DW_DLV_OK) {
2467 printf("findDwarfStaticAddresses: Can't get first die. %s\n",
2468 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2472 /* This is the header, test the name. */
2473 code = dwarf_diename(dwarf_die, &hname, &dwarf_error);
2474 if (code == DW_DLV_OK) {
2475 s = strrchr(hname, '/');
2476 for (i=0; i<nLists; i++) {
2477 if (s && !strcmp(s+1, nameList[i].file)) {
2478 findElfAddresses(dwarf_debug, dwarf_die, &nameList[i]);
2485 printf("findDwarfStaticAddresses: Can't get name of current header. %s\n",
2486 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2489 dwarf_dealloc(dwarf_debug, hname, DW_DLA_STRING);
2491 if (found >= nLists) { /* we're done */
2496 /* Frees up all allocated space. */
2497 (void) dwarf_finish(dwarf_debug, &dwarf_error);
2502 findElfAddresses(Dwarf_Debug dwarf_debug, Dwarf_Die dwarf_die,
2503 staticNameList * nameList)
2506 Dwarf_Error dwarf_error;
2507 Dwarf_Die dwarf_next_die;
2508 Dwarf_Die dwarf_child_die;
2509 Dwarf_Attribute dwarf_return_attr;
2510 char *vname = (char*)0;
2514 /* Drop into this die to find names in addrList. */
2515 code = dwarf_child(dwarf_die, &dwarf_child_die, &dwarf_error);
2516 if (code != DW_DLV_OK) {
2517 printf("findElfAddresses: Can't get child die. %s\n",
2518 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2522 /* Try to find names in each sibling. */
2523 dwarf_next_die = (Dwarf_Die)0;
2525 code = dwarf_diename(dwarf_child_die, &vname,
2527 /* It's possible that some siblings don't have names. */
2528 if (code == DW_DLV_OK) {
2529 for (i=0; i<nameList->nAddrs; i++) {
2530 if (!nameList->addrList[i].found) {
2531 if (!strcmp(vname, nameList->addrList[i].name)) {
2532 getElfAddress(dwarf_debug, dwarf_child_die,
2533 &(nameList->addrList[i]));
2541 dwarf_dealloc(dwarf_debug, dwarf_next_die, DW_DLA_DIE);
2543 if (found >= nameList->nAddrs) { /* we're done. */
2547 dwarf_next_die = dwarf_child_die;
2548 code = dwarf_siblingof(dwarf_debug, dwarf_next_die,
2552 } while(code == DW_DLV_OK);
2555 /* Get address out of current die. */
2557 getElfAddress(Dwarf_Debug dwarf_debug,
2558 Dwarf_Die dwarf_child_die, staticAddrList *addrList)
2561 Dwarf_Error dwarf_error;
2562 Dwarf_Attribute dwarf_return_attr;
2563 Dwarf_Bool dwarf_return_bool;
2564 Dwarf_Locdesc *llbuf = NULL;
2565 Dwarf_Signed listlen;
2566 off64_t addr = (off64_t)0;
2569 code = dwarf_hasattr(dwarf_child_die, addrList->type,
2570 &dwarf_return_bool, &dwarf_error);
2571 if ((code != DW_DLV_OK) || (!dwarf_return_bool)) {
2572 printf("getElfAddress: no address given for %s. %s\n",
2573 addrList->name, (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2576 code = dwarf_attr(dwarf_child_die, addrList->type,
2577 &dwarf_return_attr, &dwarf_error);
2578 if (code != DW_DLV_OK) {
2579 printf("getElfAddress: Can't get attribute. %s\n",
2580 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2584 switch (addrList->type) {
2585 case DW_AT_location:
2586 code = dwarf_loclist(dwarf_return_attr, &llbuf,
2587 &listlen, &dwarf_error);
2588 if (code != DW_DLV_OK) {
2589 printf("getElfAddress: Can't get location for %s. %s\n",
2591 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2594 if ((listlen != 1) || (llbuf[0].ld_cents != 1)) {
2595 printf("getElfAddress: %s has more than one address.\n",
2599 addr = llbuf[0].ld_s[0].lr_number;
2603 code = dwarf_lowpc(dwarf_child_die, (Dwarf_Addr*)&addr, &dwarf_error);
2604 if ( code != DW_DLV_OK) {
2605 printf("getElfAddress: Can't get lowpc for %s. %s\n",
2607 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2613 printf("getElfAddress: Bad case %d in switch.\n", addrList->type);
2617 addrList->addr.high = (addr>>32) & 0xffffffff;
2618 addrList->addr.low = addr & 0xffffffff;
2619 addrList->found = 1;
2622 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2623 /* Find symbols in the .mdebug section for 32 bit kernels. */
2626 * On 32bit platforms, we're still using the ucode compilers to build
2627 * the kernel, so we need to get our static text/data from the .mdebug
2628 * section instead of the .dwarf sections.
2630 /* SearchNameList searches our bizarre structs for the given string.
2631 * If found, sets the found bit and the address and returns 1.
2632 * Not found returns 0.
2634 int SearchNameList(char *name, afs_uint32 addr, staticNameList *nameList,
2638 for (i=0; i<nLists; i++) {
2639 for (j=0; j<nameList[i].nAddrs; j++) {
2640 if (nameList[i].addrList[j].found)
2642 if (!strcmp(name, nameList[i].addrList[j].name)) {
2643 nameList[i].addrList[j].addr.high = 0;
2644 nameList[i].addrList[j].addr.low = addr;
2645 nameList[i].addrList[j].found = 1;
2654 SearchMDebug(Elf_Scn *scnp, Elf32_Shdr *shdrp, staticNameList * nameList,
2655 int nLists, int needed)
2657 long *buf = (long *)(elf_getdata(scnp, NULL)->d_buf);
2658 u_long addr, mdoff = shdrp->sh_offset;
2660 SYMR *symbase, *symp, *symend;
2661 FDR *fdrbase, *fdrp;
2663 char *strbase, *str;
2668 addr = (__psunsigned_t)buf;
2669 hdrp = (HDRR *)addr;
2671 /* setup base addresses */
2672 addr = (u_long)buf + (u_long)(hdrp->cbFdOffset - mdoff);
2673 fdrbase = (FDR *)addr;
2674 addr = (u_long)buf + (u_long)(hdrp->cbSymOffset - mdoff);
2675 symbase = (SYMR *)addr;
2676 addr = (u_long)buf + (u_long)(hdrp->cbSsOffset - mdoff);
2677 strbase = (char *)addr;
2679 #define KEEPER(a,b) ((a == stStaticProc && b == scText) || \
2680 (a == stStatic && (b == scData || b == scBss || \
2681 b == scSBss || b == scSData)))
2683 for (fdrp = fdrbase; fdrp < &fdrbase[hdrp->ifdMax]; fdrp++) {
2684 str = strbase + fdrp->issBase + fdrp->rss;
2686 /* local symbols for each fd */
2687 for (symp = &symbase[fdrp->isymBase];
2688 symp < &symbase[fdrp->isymBase+fdrp->csym];
2690 if (KEEPER(symp->st, symp->sc)) {
2691 if (symp->value == 0)
2694 str = strbase + fdrp->issBase + symp->iss;
2695 /* Look for AFS symbols of interest */
2696 if (SearchNameList(str, symp->value,
2697 nameList, nLists)) {
2699 if (nFound >= needed)
2708 * returns section with the name of scn_name, & puts its header in shdr64 or
2709 * shdr32 based on elf's file type
2713 findMDebugSection(Elf *elf, char *scn_name)
2717 Elf_Scn *scn = NULL;
2721 if ((ehdr32 = elf32_getehdr(elf)) == NULL)
2724 if ((scn = elf_nextscn(elf, scn)) == NULL)
2726 if ((shdr32 = elf32_getshdr(scn)) == NULL)
2728 } while (strcmp(scn_name, elf_strptr(elf, ehdr32->e_shstrndx,
2735 void findMDebugStaticAddresses(staticNameList * nameList, int nLists,
2740 Elf_Scn *mdebug_scn;
2741 Elf32_Shdr *mdebug_shdr;
2744 if ((fd = open("/unix", O_RDONLY)) == -1) {
2745 printf("findMDebugStaticAddresses: Failed to open /unix.\n");
2749 (void)elf_version(EV_CURRENT);
2750 if((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
2751 printf("findMDebugStaticAddresses: /unix doesn't seem to be an elf file\n");
2755 mdebug_scn = findMDebugSection(elf, ".mdebug");
2757 printf("findMDebugStaticAddresses: Can't find .mdebug section.\n");
2760 mdebug_shdr = elf32_getshdr(mdebug_scn);
2762 printf("findMDebugStaticAddresses: Can't find .mdebug header.\n");
2766 (void) SearchMDebug(mdebug_scn, mdebug_shdr, nameList, nLists, needed);
2772 #endif /* AFS_SGI62_ENV */
2774 #else /* AFS_SGI61_ENV */
2776 struct nlist nlunix[] = {
2777 { "rfsdisptab_v2" },
2781 get_nfsstaticaddr() {
2782 int i, j, kmem, count;
2784 if ((kmem = open("/dev/kmem", O_RDONLY)) < 0) {
2785 printf("Warning: can't open /dev/kmem\n");
2788 if ((j = nlist("/unix", nlunix)) < 0) {
2789 printf("Warning: can't nlist /unix\n");
2792 i = nlunix[0].n_value;
2793 if (lseek(kmem, i, L_SET/*0*/) != i) {
2794 printf("Warning: can't lseek to %x\n", i);
2797 if ((j = read(kmem, &count, sizeof count)) != sizeof count) {
2798 printf("WARNING: kmem read at %x failed\n", i);
2803 #endif /* AFS_SGI61_ENV */
2804 #endif /* AFS_SGI53_ENV */