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>
66 #include <potpourri.h>
67 #include <afs/afsutil.h>
74 #include <sys/types.h>
81 #ifdef HAVE_SYS_PARAM_H
82 #include <sys/param.h>
85 #ifdef HAVE_SYS_FS_TYPES_H
86 #include <sys/fs_types.h>
89 #ifdef HAVE_SYS_MOUNT_H
90 #include <sys/mount.h>
93 #ifdef HAVE_SYS_FCNTL_H
94 #include <sys/fcntl.h>
97 #ifdef HAVE_SYS_MNTTAB_H
98 #include <sys/mnttab.h>
101 #ifdef HAVE_SYS_MNTENT_H
102 #include <sys/mntent.h>
109 #ifdef HAVE_SYS_MOUNT_H
110 #include <sys/mount.h>
113 #ifdef HAVE_SYS_VFS_H
117 #ifdef HAVE_SYS_FSTYP_H
118 #include <sys/fstyp.h>
129 #include <netinet/in.h>
130 #include <afs/afs_args.h>
131 #include <afs/cellconfig.h>
132 #include <afs/auth.h>
134 #include <afs/afssyscalls.h>
135 #include <afs/afsutil.h>
141 #include <libdwarf.h>
142 void set_staticaddrs(void);
143 #endif /* AFS_SGI61_ENV */
144 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
146 #include <symconst.h>
151 #ifdef AFS_LINUX20_ENV
152 #include <sys/resource.h>
154 #ifdef AFS_DARWIN_ENV
155 #include <mach/mach.h>
156 /* Symbols from the DiskArbitration framework */
157 kern_return_t DiskArbStart(mach_port_t *);
158 kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int,
160 #define DISK_ARB_NETWORK_DISK_FLAG 8
161 #endif /* AFS_DARWIN_ENV */
164 #define MOUNT_AFS AFS_MOUNT_AFS
165 #endif /* MOUNT_AFS */
168 #include <sys/statvfs.h>
170 #if defined(AFS_SUN_ENV)
173 #if !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
174 #include <sys/statfs.h>
182 #define CACHEINFOFILE "cacheinfo"
183 #define AFSLOGFILE "AFSLog"
184 #define DCACHEFILE "CacheItems"
185 #define VOLINFOFILE "VolumeItems"
186 #define CELLINFOFILE "CellItems"
188 #define MAXIPADDRS 1024
190 char LclCellName[64];
192 #define MAX_CACHE_LOOPS 4
195 * Internet address (old style... should be updated). This was pulled out of the old 4.2
196 * version of <netinet/in.h>, since it's still useful.
201 u_char s_b1, s_b2, s_b3, s_b4;
208 #define s_host S_un.S_un_b.s_b2 /* host on imp */
209 #define s_net S_un.S_un_b.s_b1 /* network */
210 #define s_imp S_un.S_un_w.s_w2 /* imp */
211 #define s_impno S_un.S_un_b.s_b4 /* imp # */
212 #define s_lh S_un.S_un_b.s_b3 /* logical host */
215 #define mPrintIPAddr(ipaddr) printf("[%d.%d.%d.%d] ", \
216 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b1, \
217 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b2, \
218 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b3, \
219 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b4)
222 * Global configuration variables.
224 afs_int32 enable_rxbind = 0;
225 afs_int32 afs_shutdown = 0;
226 afs_int32 cacheBlocks; /*Num blocks in the cache */
227 afs_int32 cacheFiles = 1000; /*Optimal # of files in workstation cache */
228 afs_int32 cacheStatEntries = 300; /*Number of stat cache entries */
229 char cacheBaseDir[1024]; /*Where the workstation AFS cache lives */
230 char confDir[1024]; /*Where the workstation AFS configuration lives */
231 char fullpn_DCacheFile[1024]; /*Full pathname of DCACHEFILE */
232 char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE */
233 char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE */
234 char fullpn_AFSLogFile[1024]; /*Full pathname of AFSLOGFILE */
235 char fullpn_CacheInfo[1024]; /*Full pathname of CACHEINFO */
236 char fullpn_VFile[1024]; /*Full pathname of data cache files */
237 char *vFilePtr; /*Ptr to the number part of above pathname */
238 int sawCacheMountDir = 0; /* from cmd line */
239 int sawCacheBaseDir = 0;
240 int sawCacheBlocks = 0;
241 int sawDCacheSize = 0;
243 char cacheMountDir[1024]; /*Mount directory for AFS */
244 char rootVolume[64] = "root.afs"; /*AFS root volume name */
245 afs_int32 cacheSetTime = 1; /*Keep checking time to avoid drift? */
246 afs_int32 isHomeCell; /*Is current cell info for the home cell? */
248 int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC; /*Create & truncate on open */
250 int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open */
252 int ownerRWmode = 0600; /*Read/write OK by owner */
253 static int filesSet = 0; /*True if number of files explicitly set */
254 static int nFilesPerDir = 2048; /* # files per cache dir */
255 static int nDaemons = 2; /* Number of background daemons */
256 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
257 static int dCacheSize = 300; /* # of dcache entries */
258 static int vCacheSize = 50; /* # of volume cache entries */
259 static int rootVolSet = 0; /*True if root volume name explicitly set */
260 int addrNum; /*Cell server address index being printed */
261 static int cacheFlags = 0; /*Flags to cache manager */
262 static int nBiods = 5; /* AIX3.1 only */
263 static int preallocs = 400; /* Def # of allocated memory blocks */
264 static int enable_peer_stats = 0; /* enable rx stats */
265 static int enable_process_stats = 0; /* enable rx stats */
267 static int enable_afsdb = 0; /* enable AFSDB support */
269 static int enable_dynroot = 0; /* enable dynroot support */
270 static int enable_fakestat = 0; /* enable fakestat support */
271 static int enable_backuptree = 0; /* enable backup tree support */
272 static int enable_nomount = 0; /* do not mount */
274 static int inodes = 60; /* VERY conservative, but has to be */
276 int afsd_verbose = 0; /*Are we being chatty? */
277 int afsd_debug = 0; /*Are we printing debugging info? */
278 int afsd_CloseSynch = 0; /*Are closes synchronous or not? */
281 #define AFSD_INO_T ino64_t
283 #define AFSD_INO_T afs_uint32
285 struct afsd_file_list {
287 struct afsd_file_list *next;
289 struct afsd_file_list **cache_dir_filelist = NULL;
290 int *cache_dir_list = NULL; /* Array of cache subdirs */
291 int *dir_for_V = NULL; /* Array: dir of each cache file.
292 * -1: file does not exist
293 * -2: file exists in top-level
294 * >=0: file exists in Dxxx
296 AFSD_INO_T *inode_for_V; /* Array of inodes for desired
298 int missing_DCacheFile = 1; /*Is the DCACHEFILE missing? */
299 int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing? */
300 int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing? */
301 int afsd_rmtsys = 0; /* Default: don't support rmtsys */
302 struct afs_cacheParams cparams; /* params passed to cache manager */
304 static int HandleMTab();
306 /* ParseArgs is now obsolete, being handled by cmd */
308 /*------------------------------------------------------------------------------
312 * Open the file containing the description of the workstation's AFS cache
313 * and pull out its contents. The format of this file is as follows:
315 * cacheMountDir:cacheBaseDir:cacheBlocks
321 * 0 if everything went well,
325 * Nothing interesting.
329 *---------------------------------------------------------------------------*/
334 static char rn[] = "ParseCacheInfoFile"; /*This routine's name */
335 FILE *cachefd; /*Descriptor for cache info file */
336 int parseResult; /*Result of our fscanf() */
337 afs_int32 tCacheBlocks;
338 char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
341 printf("%s: Opening cache info file '%s'...\n", rn, fullpn_CacheInfo);
343 cachefd = fopen(fullpn_CacheInfo, "r");
345 printf("%s: Can't read cache info file '%s'\n", rn, fullpn_CacheInfo);
350 * Parse the contents of the cache info file. All chars up to the first
351 * colon are the AFS mount directory, all chars to the next colon are the
352 * full path name of the workstation cache directory and all remaining chars
353 * represent the number of blocks in the cache.
355 tCacheMountDir[0] = tCacheBaseDir[0] = '\0';
357 fscanf(cachefd, "%1024[^:]:%1024[^:]:%d", tCacheMountDir,
358 tCacheBaseDir, &tCacheBlocks);
361 * Regardless of how the parse went, we close the cache info file.
365 if (parseResult == EOF || parseResult < 3) {
366 printf("%s: Format error in cache info file!\n", rn);
367 if (parseResult == EOF)
368 printf("\tEOF encountered before any field parsed.\n");
370 printf("\t%d out of 3 fields successfully parsed.\n",
376 for (tmd = tCacheMountDir; *tmd == '\n' || *tmd == ' ' || *tmd == '\t';
378 for (tbd = tCacheBaseDir; *tbd == '\n' || *tbd == ' ' || *tbd == '\t';
380 /* now copy in the fields not explicitly overridden by cmd args */
381 if (!sawCacheMountDir)
382 strcpy(cacheMountDir, tmd);
383 if (!sawCacheBaseDir)
384 strcpy(cacheBaseDir, tbd);
386 cacheBlocks = tCacheBlocks;
389 printf("%s: Cache info file successfully parsed:\n", rn);
391 ("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
392 tmd, tbd, tCacheBlocks);
394 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
395 PartSizeOverflow(tbd, cacheBlocks);
401 * All failures to open the partition are ignored. Also if the cache dir
402 * isn't a mounted partition it's also ignored since we can't guarantee
403 * what will be stored afterwards. Too many if's. This is now purely
404 * advisory. ODS with over 2G partition also gives warning message.
406 PartSizeOverflow(path, cs)
410 int bsize = -1, totalblks, mint;
412 struct statvfs statbuf;
414 if (statvfs(path, &statbuf) != 0) {
417 ("statvfs failed on %s; skip checking for adequate partition space\n",
421 totalblks = statbuf.f_blocks;
422 bsize = statbuf.f_frsize;
424 struct statfs statbuf;
426 if (statfs(path, &statbuf) < 0) {
429 ("statfs failed on %s; skip checking for adequate partition space\n",
433 totalblks = statbuf.f_blocks;
434 bsize = statbuf.f_bsize;
437 return 0; /* sucess */
439 /* now free and totalblks are in fragment units, but we want them in 1K units */
441 totalblks *= (bsize / 1024);
443 totalblks /= (1024 / bsize);
446 mint = totalblks - ((totalblks * 5) / 100);
449 ("Cache size (%d) must be less than 95%% of partition size (which is %d). Lower cache size\n",
454 /*-----------------------------------------------------------------------------
458 * Given the final component of a filename expected to be a data cache file,
459 * return the integer corresponding to the file. Note: we reject names that
460 * are not a ``V'' followed by an integer. We also reject those names having
461 * the right format but lying outside the range [0..cacheFiles-1].
464 * fname : Char ptr to the filename to parse.
465 * max : integer for the highest number to accept
468 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
472 * Nothing interesting.
476 *---------------------------------------------------------------------------*/
479 doGetXFileNumber(fname, filechar, maxNum)
484 int computedVNumber; /*The computed file number we return */
485 int filenameLen; /*Number of chars in filename */
486 int currDigit; /*Current digit being processed */
489 * The filename must have at least two characters, the first of which must be a ``filechar''
490 * and the second of which cannot be a zero unless the file is exactly two chars long.
492 filenameLen = strlen(fname);
495 if (fname[0] != filechar)
497 if ((filenameLen > 2) && (fname[1] == '0'))
501 * Scan through the characters in the given filename, failing immediately if a non-digit
504 for (currDigit = 1; currDigit < filenameLen; currDigit++)
505 if (isdigit(fname[currDigit]) == 0)
509 * All relevant characters are digits. Pull out the decimal number they represent.
510 * Reject it if it's out of range, otherwise return it.
512 computedVNumber = atoi(++fname);
513 if (computedVNumber < cacheFiles)
514 return (computedVNumber);
520 GetVFileNumber(fname, maxFile)
524 return doGetXFileNumber(fname, 'V', maxFile);
528 GetDDirNumber(fname, maxDir)
532 return doGetXFileNumber(fname, 'D', maxDir);
536 /*-----------------------------------------------------------------------------
540 * Given a full pathname for a file we need to create for the workstation AFS
541 * cache, go ahead and create the file.
544 * fname : Full pathname of file to create.
545 * statp : A pointer to a stat buffer which, if NON-NULL, will be
549 * 0 iff the file was created,
553 * The given cache file has been found to be missing.
557 *---------------------------------------------------------------------------*/
560 CreateCacheSubDir(basename, dirNum)
564 static char rn[] = "CreateCacheSubDir"; /* Routine Name */
568 /* Build the new cache subdirectory */
569 sprintf(dir, "%s/D%d", basename, dirNum);
572 printf("%s: Creating cache subdir '%s'\n", rn, dir);
574 if ((ret = mkdir(dir, 0700)) != 0) {
575 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, dir,
581 /* Mark this directory as created */
582 cache_dir_list[dirNum] = 0;
584 /* And return success */
589 MoveCacheFile(basename, fromDir, toDir, cacheFile, maxDir)
591 int fromDir, toDir, cacheFile, maxDir;
593 static char rn[] = "MoveCacheFile";
594 char from[1024], to[1024];
597 if (cache_dir_list[toDir] < 0
598 && (ret = CreateCacheSubDir(basename, toDir))) {
599 printf("%s: Can't create directory '%s/D%d'\n", rn, basename, toDir);
603 /* Build the from,to dir */
605 /* old-style location */
606 snprintf(from, sizeof(from), "%s/V%d", basename, cacheFile);
608 snprintf(from, sizeof(from), "%s/D%d/V%d", basename, fromDir,
612 snprintf(to, sizeof(from), "%s/D%d/V%d", basename, toDir, cacheFile);
615 printf("%s: Moving cacheFile from '%s' to '%s'\n", rn, from, to);
617 if ((ret = rename(from, to)) != 0) {
618 printf("%s: Can't rename '%s' to '%s', error return is %d (%d)\n", rn,
619 from, to, ret, errno);
623 /* Reset directory pointer; fix file counts */
624 dir_for_V[cacheFile] = toDir;
625 cache_dir_list[toDir]++;
626 if (fromDir < maxDir && fromDir >= 0)
627 cache_dir_list[fromDir]--;
633 CreateCacheFile(fname, statp)
637 static char rn[] = "CreateCacheFile"; /*Routine name */
638 int cfd; /*File descriptor to AFS cache file */
639 int closeResult; /*Result of close() */
642 printf("%s: Creating cache file '%s'\n", rn, fname);
643 cfd = open(fname, createAndTrunc, ownerRWmode);
645 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
650 closeResult = fstat(cfd, statp);
653 ("%s: Can't stat newly-created AFS cache file '%s' (code %d)\n",
658 closeResult = close(cfd);
661 ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
670 CreateFileIfMissing(char *fullpn, int missing)
674 printf("CreateFileIfMissing: Creating '%s'\n", fullpn);
675 if (CreateCacheFile(fullpn, NULL))
676 printf("CreateFileIfMissing: Can't create '%s'\n", fullpn);
680 /*-----------------------------------------------------------------------------
684 * Sweep through the AFS cache directory, recording the inode number for
685 * each valid data cache file there. Also, delete any file that doesn't belong
686 * in the cache directory during this sweep, and remember which of the other
687 * residents of this directory were seen. After the sweep, we create any data
688 * cache files that were missing.
691 * vFilesFound : Set to the number of data cache files found.
694 * 0 if everything went well,
698 * This routine may be called several times. If the number of data cache files
699 * found is less than the global cacheFiles, then the caller will need to call it
700 * again to record the inodes of the missing zero-length data cache files created
701 * in the previous call.
704 * Fills up the global inode_for_V array, may create and/or delete files as
706 *---------------------------------------------------------------------------*/
710 doSweepAFSCache(vFilesFound, directory, dirNum, maxDir)
712 char *directory; /* /path/to/cache/directory */
713 int dirNum; /* current directory number */
714 int maxDir; /* maximum directory number */
716 static char rn[] = "doSweepAFSCache"; /* Routine Name */
717 char fullpn_FileToDelete[1024]; /*File to be deleted from cache */
718 char *fileToDelete; /*Ptr to last component of above */
719 DIR *cdirp; /*Ptr to cache directory structure */
721 struct dirent64 *currp; /*Current directory entry */
723 struct dirent *currp; /*Current directory entry */
725 int vFileNum; /*Data cache file's associated number */
726 int thisDir; /* A directory number */
730 printf("%s: Opening cache directory '%s'\n", rn, directory);
732 if (chmod(directory, 0700)) { /* force it to be 700 */
733 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
737 cdirp = opendir(directory);
738 if (cdirp == (DIR *) 0) {
739 printf("%s: Can't open AFS cache directory, '%s'.\n", rn, directory);
744 * Scan the directory entries, remembering data cache file inodes
745 * and the existance of other important residents. Recurse into
746 * the data subdirectories.
748 * Delete all files and directories that don't belong here.
750 sprintf(fullpn_FileToDelete, "%s/", directory);
751 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
754 for (currp = readdir64(cdirp); currp; currp = readdir64(cdirp))
756 for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
760 printf("%s: Current directory entry:\n", rn);
762 printf("\tinode=%lld, reclen=%d, name='%s'\n", currp->d_ino,
763 currp->d_reclen, currp->d_name);
765 printf("\tinode=%d, reclen=%d, name='%s'\n", currp->d_ino,
766 currp->d_reclen, currp->d_name);
771 * If dirNum < 0, we are a top-level cache directory and should
772 * only contain sub-directories and other sundry files. Therefore,
773 * V-files are valid only if dirNum >= 0, and Directories are only
774 * valid if dirNum < 0.
777 if (*(currp->d_name) == 'V'
778 && ((vFileNum = GetVFileNumber(currp->d_name, cacheFiles)) >=
781 * Found a valid data cache filename. Remember this
782 * file's inode, directory, and bump the number of files found
783 * total and in this directory.
785 inode_for_V[vFileNum] = currp->d_ino;
786 dir_for_V[vFileNum] = dirNum; /* remember this directory */
789 /* If we're in a real subdir, mark this file to be moved
790 * if we've already got too many files in this directory
793 cache_dir_list[dirNum]++; /* keep directory's file count */
794 if (cache_dir_list[dirNum] > nFilesPerDir) {
795 /* Too many files -- add to filelist */
796 struct afsd_file_list *tmp = (struct afsd_file_list *)
797 malloc(sizeof(*tmp));
800 ("%s: MALLOC FAILED allocating file_list entry\n",
803 tmp->fileNum = vFileNum;
804 tmp->next = cache_dir_filelist[dirNum];
805 cache_dir_filelist[dirNum] = tmp;
810 } else if (dirNum < 0 && (*(currp->d_name) == 'D')
811 && GetDDirNumber(currp->d_name, 1 << 30) >= 0) {
813 if ((vFileNum = GetDDirNumber(currp->d_name, maxDir)) >= 0) {
814 /* Found a valid cachefile sub-Directory. Remember this number
815 * and recurse into it. Note that subdirs cannot have subdirs.
818 } else if ((vFileNum = GetDDirNumber(currp->d_name, 1 << 30)) >=
820 /* This directory is going away, but figure out if there
821 * are any cachefiles in here that should be saved by
822 * moving them to other cache directories. This directory
823 * will be removed later.
828 /* Save the highest directory number we've seen */
829 if (vFileNum > highDir)
832 /* If this directory is staying, be sure to mark it as 'found' */
834 cache_dir_list[vFileNum] = 0;
836 /* Print the dirname for recursion */
837 sprintf(fileToDelete, "%s", currp->d_name);
839 /* Note: vFileNum is the directory number */
841 doSweepAFSCache(vFilesFound, fullpn_FileToDelete, vFileNum,
842 (retval == 1 ? 0 : -1));
844 printf("%s: Recursive sweep failed on directory %s\n", rn,
848 } else if (dirNum < 0 && strcmp(currp->d_name, DCACHEFILE) == 0) {
850 * Found the file holding the dcache entries.
852 missing_DCacheFile = 0;
853 } else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
855 * Found the file holding the volume info.
857 missing_VolInfoFile = 0;
858 } else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
860 * Found the file holding the cell info.
862 missing_CellInfoFile = 0;
863 } else if ((strcmp(currp->d_name, ".") == 0)
864 || (strcmp(currp->d_name, "..") == 0) ||
865 #ifdef AFS_DECOSF_ENV
866 /* these are magic AdvFS files */
867 (strcmp(currp->d_name, ".tags") == 0)
868 || (strcmp(currp->d_name, "quota.user") == 0)
869 || (strcmp(currp->d_name, "quota.group") == 0) ||
871 #ifdef AFS_LINUX22_ENV
872 /* this is the ext3 journal file */
873 (strcmp(currp->d_name, ".journal") == 0) ||
875 (strcmp(currp->d_name, "lost+found") == 0)) {
877 * Don't do anything - this file is legit, and is to be left alone.
881 * This file/directory doesn't belong in the cache. Nuke it.
883 sprintf(fileToDelete, "%s", currp->d_name);
885 printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
886 if (unlink(fullpn_FileToDelete)) {
887 if (errno == EISDIR && *fileToDelete == 'D') {
888 if (rmdir(fullpn_FileToDelete)) {
889 printf("%s: Can't rmdir '%s', errno is %d\n", rn,
890 fullpn_FileToDelete, errno);
893 printf("%s: Can't unlink '%s', errno is %d\n", rn,
894 fullpn_FileToDelete, errno);
902 * Create all the cache files that are missing.
904 CreateFileIfMissing(fullpn_DCacheFile, missing_DCacheFile);
905 CreateFileIfMissing(fullpn_VolInfoFile, missing_VolInfoFile);
906 CreateFileIfMissing(fullpn_CellInfoFile, missing_CellInfoFile);
908 /* ADJUST CACHE FILES */
910 /* First, let's walk through the list of files and figure out
911 * if there are any leftover files in extra directories or
912 * missing files. Move the former and create the latter in
913 * subdirs with extra space.
916 thisDir = 0; /* Keep track of which subdir has space */
918 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++) {
919 if (dir_for_V[vFileNum] == -1) {
920 /* This file does not exist. Create it in the first
921 * subdir that still has extra space.
923 while (thisDir < maxDir
924 && cache_dir_list[thisDir] >= nFilesPerDir)
926 if (thisDir >= maxDir)
927 printf("%s: can't find directory to create V%d\n", rn,
931 assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
932 sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
934 printf("%s: Creating '%s'\n", rn, fullpn_VFile);
935 if (cache_dir_list[thisDir] < 0
936 && CreateCacheSubDir(directory, thisDir))
937 printf("%s: Can't create directory for '%s'\n", rn,
939 if (CreateCacheFile(fullpn_VFile, &statb))
940 printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
942 inode_for_V[vFileNum] = statb.st_ino;
943 dir_for_V[vFileNum] = thisDir;
944 cache_dir_list[thisDir]++;
949 } else if (dir_for_V[vFileNum] >= maxDir
950 || dir_for_V[vFileNum] == -2) {
951 /* This file needs to move; move it to the first subdir
952 * that has extra space. (-2 means it's in the toplevel)
954 while (thisDir < maxDir
955 && cache_dir_list[thisDir] >= nFilesPerDir)
957 if (thisDir >= maxDir)
958 printf("%s: can't find directory to move V%d\n", rn,
962 (directory, dir_for_V[vFileNum], thisDir, vFileNum,
964 /* Cannot move. Ignore this file??? */
971 /* At this point, we've moved all of the valid cache files
972 * into the valid subdirs, and created all the extra
973 * cachefiles we need to create. Next, rebalance any subdirs
974 * with too many cache files into the directories with not
975 * enough cache files. Note that thisDir currently sits at
976 * the lowest subdir that _may_ have room.
979 for (dirNum = 0; dirNum < maxDir; dirNum++) {
980 struct afsd_file_list *thisFile;
982 for (thisFile = cache_dir_filelist[dirNum];
983 thisFile && cache_dir_list[dirNum] >= nFilesPerDir;
984 thisFile = thisFile->next) {
985 while (thisDir < maxDir
986 && cache_dir_list[thisDir] >= nFilesPerDir)
988 if (thisDir >= maxDir)
989 printf("%s: can't find directory to move V%d\n", rn,
993 (directory, dirNum, thisDir, thisFile->fileNum,
995 /* Cannot move. Ignore this file??? */
999 } /* for each file to move */
1000 } /* for each directory */
1002 /* Remove any directories >= maxDir -- they should be empty */
1003 for (; highDir >= maxDir; highDir--) {
1004 sprintf(fileToDelete, "D%d", highDir);
1005 if (unlink(fullpn_FileToDelete)) {
1006 if (errno == EISDIR && *fileToDelete == 'D') {
1007 if (rmdir(fullpn_FileToDelete)) {
1008 printf("%s: Can't rmdir '%s', errno is %d\n", rn,
1009 fullpn_FileToDelete, errno);
1012 printf("%s: Can't unlink '%s', errno is %d\n", rn,
1013 fullpn_FileToDelete, errno);
1020 * Close the directory, return success.
1023 printf("%s: Closing cache directory.\n", rn);
1029 CheckCacheBaseDir(char *dir)
1031 struct stat statbuf;
1034 return "cache base dir not specified";
1036 if (stat(dir, &statbuf) != 0) {
1037 return "unable to stat cache base directory";
1040 /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */
1042 #ifdef AFS_LINUX24_ENV
1045 struct statfs statfsbuf;
1047 res = statfs(dir, &statfsbuf);
1049 return "unable to statfs cache base directory";
1051 if (statfsbuf.f_type == 0x52654973) { /* REISERFS_SUPER_MAGIC */
1052 return "cannot use reiserfs as cache partition";
1053 } else if (statfsbuf.f_type == 0x58465342) { /* XFS_SUPER_MAGIC */
1054 return "cannot use xfs as cache partition";
1062 struct statfs statfsbuf;
1065 res = statfs(dir, &statfsbuf);
1067 return "unable to statfs cache base directory";
1070 if (sysfs(GETFSTYP, statfsbuf.f_fsid[1], name) != 0) {
1071 return "unable to determine filesystem type for cache base dir";
1074 if (strcmp(name, "hfs")) {
1075 return "can only use hfs filesystem for cache partition on hpux";
1084 struct stat statmnt, statci;
1086 if ((stat(dir, &statci) == 0)
1087 && ((vfstab = fopen(MNTTAB, "r")) != NULL)) {
1088 while (getmntent(vfstab, &mnt) == 0) {
1089 if (strcmp(dir, mnt.mnt_mountp) != 0) {
1093 if (cp = hasmntopt(&mnt, "dev="))
1095 (int)strtol(cp + strlen("dev="), (char **)NULL,
1098 if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
1099 rdev = statmnt.st_dev;
1101 if ((rdev == statci.st_dev)
1102 && (hasmntopt(&mnt, "logging") != NULL)) {
1106 "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n";
1120 SweepAFSCache(vFilesFound)
1123 static char rn[] = "SweepAFSCache"; /*Routine name */
1124 int maxDir = (cacheFiles + nFilesPerDir - 1) / nFilesPerDir;
1129 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1131 printf("%s: Memory Cache, no cache sweep done\n", rn);
1135 if (cache_dir_list == NULL) {
1136 cache_dir_list = (int *)malloc(maxDir * sizeof(*cache_dir_list));
1137 if (cache_dir_list == NULL) {
1138 printf("%s: Malloc Failed!\n", rn);
1141 for (i = 0; i < maxDir; i++)
1142 cache_dir_list[i] = -1; /* Does not exist */
1145 if (cache_dir_filelist == NULL) {
1146 cache_dir_filelist = (struct afsd_file_list **)
1147 malloc(maxDir * sizeof(*cache_dir_filelist));
1148 if (cache_dir_filelist == NULL) {
1149 printf("%s: Malloc Failed!\n", rn);
1152 memset(cache_dir_filelist, 0, maxDir * sizeof(*cache_dir_filelist));
1155 if (dir_for_V == NULL) {
1156 dir_for_V = (int *)malloc(cacheFiles * sizeof(*dir_for_V));
1157 if (dir_for_V == NULL) {
1158 printf("%s: Malloc Failed!\n", rn);
1161 for (i = 0; i < cacheFiles; i++)
1162 dir_for_V[i] = -1; /* Does not exist */
1165 /* Note, setting dirNum to -2 here will cause cachefiles found in
1166 * the toplevel directory to be marked in directory "-2". This
1167 * allows us to differentiate between 'file not seen' (-1) and
1168 * 'file seen in top-level' (-2). Then when we try to move the
1169 * file into a subdirectory, we know it's in the top-level instead
1170 * of some other cache subdir.
1172 return doSweepAFSCache(vFilesFound, cacheBaseDir, -2, maxDir);
1176 ConfigCell(aci, arock, adir)
1177 register struct afsconf_cell *aci;
1179 struct afsconf_dir *adir;
1181 register int isHomeCell;
1182 register int i, code;
1183 afs_int32 cellFlags = 0;
1184 afs_int32 hosts[MAXHOSTSPERCELL];
1186 /* figure out if this is the home cell */
1187 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
1189 cellFlags = 2; /* not home, suid is forbidden */
1191 /* build address list */
1192 for (i = 0; i < MAXHOSTSPERCELL; i++)
1193 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1195 if (aci->linkedCell)
1196 cellFlags |= 4; /* Flag that linkedCell arg exists,
1197 * for upwards compatibility */
1199 /* configure one cell */
1200 code = call_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
1201 aci->name, /* cell name */
1202 cellFlags, /* is this the home cell? */
1203 aci->linkedCell); /* Linked cell, if any */
1205 printf("Adding cell '%s': error %d\n", aci->name, code);
1210 ConfigCellAlias(aca, arock, adir)
1211 register struct afsconf_cellalias *aca;
1213 struct afsconf_dir *adir;
1215 /* push the alias into the kernel */
1216 call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
1220 #ifdef AFS_AFSDB_ENV
1222 AfsdbLookupHandler()
1224 afs_int32 kernelMsg[64];
1225 char acellName[128];
1227 struct afsconf_cell acellInfo;
1232 acellName[0] = '\0';
1235 /* On some platforms you only get 4 args to an AFS call */
1236 int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
1238 call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
1239 if (code) { /* Something is wrong? */
1244 if (*acellName == 1) /* Shutting down */
1247 code = afsconf_GetAfsdbInfo(acellName, 0, &acellInfo);
1252 kernelMsg[0] = acellInfo.numServers;
1253 if (acellInfo.timeout)
1254 kernelMsg[1] = acellInfo.timeout - time(0);
1257 for (i = 0; i < acellInfo.numServers; i++)
1258 kernelMsg[i + 2] = acellInfo.hostAddr[i].sin_addr.s_addr;
1259 strncpy(acellName, acellInfo.name, sizeof(acellName));
1260 acellName[sizeof(acellName) - 1] = '\0';
1269 #include <sys/ioctl.h>
1272 #ifdef AFS_SGI65_ENV
1273 #define SET_RTPRI(P) { \
1274 struct sched_param sp; \
1275 sp.sched_priority = P; \
1276 if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \
1277 perror("sched_setscheduler"); \
1280 #define SET_AFSD_RTPRI() SET_RTPRI(68)
1281 #define SET_RX_RTPRI() SET_RTPRI(199)
1283 #ifdef AFS_LINUX20_ENV
1284 #define SET_AFSD_RTPRI()
1285 #define SET_RX_RTPRI() do { if (setpriority(PRIO_PROCESS, 0, -10)<0) \
1286 perror("setting rx priority"); \
1289 #define SET_AFSD_RTPRI()
1290 #define SET_RX_RTPRI()
1295 register struct cmd_syndesc *as;
1298 static char rn[] = "afsd"; /*Name of this routine */
1299 register afs_int32 code; /*Result of fork() */
1301 int currVFile; /*Current AFS cache file number passed in */
1302 int mountFlags; /*Flags passed to mount() */
1303 int lookupResult; /*Result of GetLocalCellName() */
1304 int cacheIteration; /*How many times through cache verification */
1305 int vFilesFound; /*How many data cache files were found in sweep */
1306 struct afsconf_dir *cdir; /* config dir */
1308 char *fsTypeMsg = NULL;
1312 afs_int32 vfs1_type = -1;
1313 #ifdef AFS_SGI65_ENV
1314 struct sched_param sp;
1317 #ifdef AFS_SGI_VNODE_GLUE
1318 if (afs_init_kernel_config(-1) < 0) {
1319 printf("Can't determine NUMA configuration, not starting AFS.\n");
1324 /* call atoi on the appropriate parsed results */
1325 if (as->parms[0].items) {
1327 cacheBlocks = atoi(as->parms[0].items->data);
1330 if (as->parms[1].items) {
1332 cacheFiles = atoi(as->parms[1].items->data);
1333 filesSet = 1; /* set when spec'd on cmd line */
1335 if (as->parms[2].items) {
1337 strcpy(rootVolume, as->parms[2].items->data);
1340 if (as->parms[3].items) {
1342 cacheStatEntries = atoi(as->parms[3].items->data);
1344 if (as->parms[4].items) {
1346 cacheBaseDir[0] = '\0';
1347 sawCacheBaseDir = 1;
1348 cacheFlags |= AFSCALL_INIT_MEMCACHE;
1352 if (as->parms[5].items) {
1354 strcpy(cacheBaseDir, as->parms[5].items->data);
1355 sawCacheBaseDir = 1;
1357 if (as->parms[6].items) {
1359 strcpy(cacheMountDir, as->parms[6].items->data);
1360 sawCacheMountDir = 1;
1362 if (as->parms[7].items) {
1364 nDaemons = atoi(as->parms[7].items->data);
1366 if (as->parms[8].items) {
1368 cacheSetTime = FALSE;
1370 if (as->parms[9].items) {
1374 if (as->parms[10].items) {
1378 if (as->parms[11].items) {
1383 if (as->parms[12].items) {
1385 chunkSize = atoi(as->parms[12].items->data);
1386 if (chunkSize < 0 || chunkSize > 30) {
1387 printf("afsd:invalid chunk size (not in range 0-30), using default\n");
1391 if (as->parms[13].items) {
1393 dCacheSize = atoi(as->parms[13].items->data);
1396 if (as->parms[14].items) {
1398 vCacheSize = atoi(as->parms[14].items->data);
1400 if (as->parms[15].items) {
1402 #ifndef AFS_AIX32_ENV
1404 ("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
1406 nBiods = atoi(as->parms[15].items->data);
1410 if (as->parms[16].items) {
1412 preallocs = atoi(as->parms[16].items->data);
1415 if (as->parms[17].items) {
1417 inodes = atoi(as->parms[17].items->data);
1420 strcpy(confDir, AFSDIR_CLIENT_ETC_DIRPATH);
1421 if (as->parms[17].items) {
1423 strcpy(confDir, as->parms[17].items->data);
1425 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
1426 sprintf(fullpn_AFSLogFile, "%s/%s", confDir, AFSLOGFILE);
1427 if (as->parms[18].items) {
1429 strcpy(fullpn_AFSLogFile, as->parms[18].items->data);
1431 if (as->parms[19].items) {
1433 afsd_CloseSynch = 1;
1435 if (as->parms[20].items) {
1439 * Cold shutdown is the default
1441 printf("afsd: Shutting down all afs processes and afs state\n");
1442 code = call_syscall(AFSOP_SHUTDOWN, 1);
1444 printf("afsd: AFS still mounted; Not shutting down\n");
1449 if (as->parms[21].items) {
1450 /* -enable_peer_stats */
1451 enable_peer_stats = 1;
1453 if (as->parms[22].items) {
1454 /* -enable_process_stats */
1455 enable_process_stats = 1;
1457 if (as->parms[23].items) {
1458 /* -mem_alloc_sleep */
1459 cacheFlags |= AFSCALL_INIT_MEMCACHE_SLEEP;
1461 if (as->parms[24].items) {
1463 #ifdef AFS_AFSDB_ENV
1466 printf("afsd: No AFSDB support; ignoring -afsdb");
1469 if (as->parms[25].items) {
1470 /* -files_per_subdir */
1471 int res = atoi(as->parms[25].items->data);
1472 if (res < 10 || res > 2 ^ 30) {
1474 ("afsd:invalid number of files per subdir, \"%s\". Ignored\n",
1475 as->parms[25].items->data);
1480 if (as->parms[26].items) {
1484 if (as->parms[27].items) {
1486 enable_fakestat = 2;
1488 if (as->parms[28].items) {
1490 enable_fakestat = 1;
1492 if (as->parms[29].items) {
1496 if (as->parms[30].items) {
1498 enable_backuptree = 1;
1500 if (as->parms[31].items) {
1507 * Pull out all the configuration info for the workstation's AFS cache and
1508 * the cellular community we're willing to let our users see.
1510 cdir = afsconf_Open(confDir);
1512 printf("afsd: some file missing or bad in %s\n", confDir);
1517 afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
1519 printf("%s: Can't get my home cell name! [Error is %d]\n", rn,
1523 printf("%s: My home cell is '%s'\n", rn, LclCellName);
1526 /* parse cacheinfo file if this is a diskcache */
1527 if (ParseCacheInfoFile()) {
1531 if ((logfd = fopen(fullpn_AFSLogFile, "r+")) == 0) {
1533 printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile);
1534 if (CreateCacheFile(fullpn_AFSLogFile, NULL)) {
1536 ("%s: Can't create '%s' (You may want to use the -logfile option)\n",
1537 rn, fullpn_AFSLogFile);
1543 /* do some random computations in memcache case to get things to work
1544 * reasonably no matter which parameters you set.
1546 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1547 /* memory cache: size described either as blocks or dcache entries, but
1550 if (sawDCacheSize) {
1551 if (sawCacheBlocks) {
1553 ("%s: can't set cache blocks and dcache size simultaneously when diskless.\n",
1557 /* compute the cache size based on # of chunks times the chunk size */
1558 i = (chunkSize == 0 ? 13 : chunkSize);
1559 i = (1 << i); /* bytes per chunk */
1560 cacheBlocks = i * dCacheSize;
1561 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
1563 /* compute the dcache size from overall cache size and chunk size */
1564 i = (chunkSize == 0 ? 13 : chunkSize);
1565 /* dCacheSize = (cacheBlocks << 10) / (1<<i); */
1567 dCacheSize = (cacheBlocks >> (i - 10));
1568 } else if (i < 10) {
1569 dCacheSize = (cacheBlocks << (10 - i));
1571 dCacheSize = cacheBlocks;
1573 /* don't have to set sawDCacheSize here since it isn't overwritten
1574 * by ParseCacheInfoFile.
1577 /* kernel computes # of dcache entries as min of cacheFiles and dCacheSize,
1578 * so we now make them equal.
1580 cacheFiles = dCacheSize;
1583 * Compute the number of cache files based on cache size,
1584 * but only if -files isn't given on the command line.
1585 * Don't let # files be so small as to prevent full utilization
1586 * of the cache unless user has explicitly asked for it.
1587 * average V-file is ~10K, according to tentative empirical studies.
1590 cacheFiles = cacheBlocks / 10;
1591 if (cacheFiles < 100)
1593 /* Always allow more files than chunks. Presume average V-file
1594 * is ~67% of a chunk... (another guess, perhaps Honeyman will
1595 * have a grad student write a paper). i is KILOBYTES.
1597 i = 1 << (chunkSize ==
1598 0 ? 6 : (chunkSize < 10 ? 0 : chunkSize - 10));
1599 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
1600 /* never permit more files than blocks, while leaving space for
1601 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
1602 * CacheItems is 50 Bytes / file (== 1K/20)
1604 #define VOLINFOSZ 20
1605 #define CACHEITMSZ (cacheFiles / 20)
1608 min(cacheFiles, (cacheBlocks - VOLINFOSZ - CACHEITMSZ) / 4);
1611 min(cacheFiles, cacheBlocks - VOLINFOSZ - CACHEITMSZ);
1613 if (cacheFiles < 100)
1614 fprintf(stderr, "%s: WARNING: cache probably too small!\n",
1617 if (!sawDCacheSize) {
1618 if ((cacheFiles / 2) > dCacheSize)
1619 dCacheSize = cacheFiles / 2;
1620 if (dCacheSize > 2000)
1626 * Create and zero the inode table for the desired cache files.
1628 inode_for_V = (AFSD_INO_T *) malloc(cacheFiles * sizeof(AFSD_INO_T));
1629 if (inode_for_V == (AFSD_INO_T *) 0) {
1631 ("%s: malloc() failed for cache file inode table with %d entries.\n",
1635 memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
1637 printf("%s: %d inode_for_V entries at 0x%x, %d bytes\n", rn,
1638 cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
1641 * Set up all the pathnames we'll need for later.
1643 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
1644 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
1645 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
1646 sprintf(fullpn_VFile, "%s/", cacheBaseDir);
1647 vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
1649 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE) && (fsTypeMsg = CheckCacheBaseDir(cacheBaseDir))) {
1650 printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
1653 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1658 * Set up all the kernel processes needed for AFS.
1661 setpgrp(getpid(), 0);
1664 /* Initialize RX daemons and services */
1666 /* initialize the rx random number generator from user space */
1668 /* parse multihomed address files */
1669 afs_int32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
1673 parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
1674 AFSDIR_CLIENT_NETINFO_FILEPATH,
1675 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
1678 code = code | 0x80000000;
1679 call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
1681 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
1685 /* Set realtime priority for most threads to same as for biod's. */
1688 #ifdef AFS_SGI53_ENV
1689 #ifdef AFS_SGI61_ENV
1691 #else /* AFS_SGI61_ENV */
1692 code = get_nfsstaticaddr();
1694 call_syscall(AFSOP_NFSSTATICADDR, code);
1695 #endif /* AFS_SGI61_ENV */
1696 #endif /* AFS_SGI_53_ENV */
1698 /* Start listener, then callback listener. Lastly, start rx event daemon.
1699 * Change in ordering is so that Linux port has socket fd in listener
1701 * preallocs are passed for both listener and callback server. Only
1702 * the one which actually does the initialization uses them though.
1704 if (preallocs < cacheStatEntries + 50)
1705 preallocs = cacheStatEntries + 50;
1706 #ifdef RXK_LISTENER_ENV
1708 printf("%s: Forking rx listener daemon.\n", rn);
1712 SET_RX_RTPRI(); /* max advised for non-interrupts */
1713 call_syscall(AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
1714 enable_process_stats);
1719 printf("%s: Forking rx callback listener.\n", rn);
1723 call_syscall(AFSOP_START_RXCALLBACK, preallocs);
1726 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1728 printf("%s: Forking rxevent daemon.\n", rn);
1732 SET_RX_RTPRI(); /* max advised for non-interrupts */
1733 call_syscall(AFSOP_RXEVENT_DAEMON);
1738 #ifdef AFS_AFSDB_ENV
1741 printf("%s: Forking AFSDB lookup handler.\n", rn);
1744 AfsdbLookupHandler();
1750 code = call_syscall(AFSOP_BASIC_INIT, 1);
1752 printf("%s: Error %d in basic initialization.\n", rn, code);
1755 * Tell the kernel some basic information about the workstation's cache.
1759 ("%s: Calling AFSOP_CACHEINIT: %d stat cache entries, %d optimum cache files, %d blocks in the cache, flags = 0x%x, dcache entries %d\n",
1760 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
1762 memset(&cparams, '\0', sizeof(cparams));
1763 cparams.cacheScaches = cacheStatEntries;
1764 cparams.cacheFiles = cacheFiles;
1765 cparams.cacheBlocks = cacheBlocks;
1766 cparams.cacheDcaches = dCacheSize;
1767 cparams.cacheVolumes = vCacheSize;
1768 cparams.chunkSize = chunkSize;
1769 cparams.setTimeFlag = cacheSetTime;
1770 cparams.memCacheFlag = cacheFlags;
1772 cparams.inodes = inodes;
1774 call_syscall(AFSOP_CACHEINIT, &cparams);
1775 if (afsd_CloseSynch)
1776 call_syscall(AFSOP_CLOSEWAIT);
1779 * Sweep the workstation AFS cache directory, remembering the inodes of
1780 * valid files and deleting extraneous files. Keep sweeping until we
1781 * have the right number of data cache files or we've swept too many
1784 * This also creates files in the cache directory like VolumeItems and
1785 * CellItems, and thus must be ran before those are sent to the kernel.
1788 printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
1790 /* Memory-cache based system doesn't need any of this */
1791 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
1794 if (SweepAFSCache(&vFilesFound)) {
1795 printf("%s: Error on sweep %d of workstation AFS cache \
1796 directory.\n", rn, cacheIteration);
1801 ("%s: %d out of %d data cache files found in sweep %d.\n",
1802 rn, vFilesFound, cacheFiles, cacheIteration);
1803 } while ((vFilesFound < cacheFiles)
1804 && (cacheIteration < MAX_CACHE_LOOPS));
1805 } else if (afsd_verbose)
1806 printf("%s: Using memory cache, not swept\n", rn);
1809 * Pass the kernel the name of the workstation cache file holding the
1813 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
1815 /* once again, meaningless for a memory-based cache. */
1816 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
1817 call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
1820 * Pass the kernel the name of the workstation cache file holding the
1824 printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
1825 fullpn_CellInfoFile);
1826 call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
1828 if (enable_dynroot) {
1830 printf("%s: Enabling dynroot support in kernel.\n", rn);
1831 code = call_syscall(AFSOP_SET_DYNROOT, 1);
1833 printf("%s: Error enabling dynroot support.\n", rn);
1836 if (enable_fakestat) {
1838 printf("%s: Enabling fakestat support in kernel.\n", rn);
1839 code = call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
1841 printf("%s: Error enabling fakestat support.\n", rn);
1844 if (enable_backuptree) {
1846 printf("%s: Enabling backup tree support in kernel.\n", rn);
1847 code = call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
1849 printf("%s: Error enabling backup tree support.\n", rn);
1853 * Tell the kernel about each cell in the configuration.
1855 afsconf_CellApply(cdir, ConfigCell, NULL);
1856 afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
1859 * Set the primary cell name.
1861 call_syscall(AFSOP_SET_THISCELL, LclCellName);
1863 /* Initialize AFS daemon threads. */
1865 printf("%s: Forking AFS daemon.\n", rn);
1869 call_syscall(AFSOP_START_AFS);
1874 printf("%s: Forking Check Server Daemon.\n", rn);
1878 code = call_syscall(AFSOP_START_CS);
1880 printf("%s: No check server daemon in client.\n", rn);
1885 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
1886 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
1887 /* Add one because for sgi we always "steal" the first daemon for a
1888 * different task if we only have a 4K stack.
1892 for (i = 0; i < nDaemons; i++) {
1896 #ifdef AFS_AIX32_ENV
1897 call_syscall(AFSOP_START_BKG, 0);
1899 call_syscall(AFSOP_START_BKG);
1904 #ifdef AFS_AIX32_ENV
1906 nBiods = nDaemons * 2;
1909 for (i = 0; i < nBiods; i++) {
1911 if (code == 0) { /* Child */
1912 call_syscall(AFSOP_START_BKG, nBiods);
1919 * If the root volume has been explicitly set, tell the kernel.
1923 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
1925 call_syscall(AFSOP_ROOTVOLUME, rootVolume);
1929 * Pass the kernel the name of the workstation cache file holding the
1930 * volume information.
1933 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
1934 fullpn_VolInfoFile);
1935 /* once again, meaningless for a memory-based cache. */
1936 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
1937 call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
1940 * Pass the kernel the name of the afs logging file holding the volume
1944 printf("%s: Calling AFSOP_AFSLOG: volume info file is '%s'\n", rn,
1946 #if defined(AFS_SGI_ENV)
1947 /* permit explicit -logfile argument to enable logging on memcache systems */
1948 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE) || as->parms[18].items)
1950 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... nor this ... */
1952 call_syscall(AFSOP_AFSLOG, fullpn_AFSLogFile);
1955 * Give the kernel the names of the AFS files cached on the workstation's
1960 ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
1961 rn, cacheFiles, cacheBaseDir);
1962 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
1963 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
1964 #ifdef AFS_SGI62_ENV
1965 call_syscall(AFSOP_CACHEINODE,
1966 (afs_uint32) (inode_for_V[currVFile] >> 32),
1967 (afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
1969 call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
1976 * All the necessary info has been passed into the kernel to run an AFS
1977 * system. Give the kernel our go-ahead.
1980 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
1982 call_syscall(AFSOP_GO, cacheSetTime);
1985 * At this point, we have finished passing the kernel all the info
1986 * it needs to set up the AFS. Mount the AFS root.
1988 printf("%s: All AFS daemons started.\n", rn);
1991 printf("%s: Forking trunc-cache daemon.\n", rn);
1995 call_syscall(AFSOP_START_TRUNCDAEMON);
1999 if (!enable_nomount) {
2001 mountFlags = 0; /* Read/write file system, can do setuid() */
2002 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
2004 mountFlags |= MS_DATA;
2006 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... */
2010 #if defined(AFS_HPUX100_ENV)
2011 mountFlags |= MS_DATA;
2015 printf("%s: Mounting the AFS root on '%s', flags: %d.\n", rn,
2016 cacheMountDir, mountFlags);
2018 if ((mount("AFS", cacheMountDir, mountFlags, GT_AFS, (caddr_t) 0)) <
2022 if ((mount("AFS", cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
2025 if ((fsmount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
2030 #if defined(AFS_HPUX100_ENV)
2031 if ((mount("", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
2034 #if defined(AFS_HPUX90_ENV)
2039 strcpy(buffer, "afs");
2040 code = vfsmount(-1, cacheMountDir, mountFlags, (caddr_t) buffer);
2041 sscanf(buffer, "%d", &vfs1_type);
2044 ("Can't find 'afs' type in the registered filesystem table!\n");
2047 sscanf(buffer, "%d", &vfs1_type);
2049 printf("AFS vfs slot number is %d\n", vfs1_type);
2051 if ((vfsmount(vfs1_type, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
2054 (AFSOP_AFS_VFSMOUNT, MOUNT_AFS, cacheMountDir, mountFlags,
2055 (caddr_t) NULL) < 0) {
2059 if ((mount("AFS", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
2061 #if defined(AFS_SGI_ENV)
2062 mountFlags = MS_FSS;
2063 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) MOUNT_AFS))
2066 #ifdef AFS_LINUX20_ENV
2067 if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL)) < 0) {
2069 /* This is the standard mount used by the suns and rts */
2070 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
2071 #endif /* AFS_LINUX20_ENV */
2072 #endif /* AFS_SGI_ENV */
2073 #endif /* AFS_SUN5_ENV */
2074 #endif /* AFS_HPUX100_ENV */
2075 #endif /* AFS_HPUX_ENV */
2076 #endif /* AFS_AIX_ENV */
2077 #endif /* AFS_AUX_ENV */
2078 #endif /* AFS_FBSD_ENV */
2079 #endif /* AFS_DEC_ENV */
2080 printf("%s: Can't mount AFS on %s(%d)\n", rn, cacheMountDir,
2091 printf("%s: Forking 'rmtsys' daemon.\n", rn);
2100 * Exit successfully.
2105 #include "AFS_component_version_number.c"
2113 register struct cmd_syndesc *ts;
2115 ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
2116 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
2117 "1024 byte blocks in cache");
2118 cmd_AddParm(ts, "-files", CMD_SINGLE, CMD_OPTIONAL, "files in cache");
2119 cmd_AddParm(ts, "-rootvol", CMD_SINGLE, CMD_OPTIONAL,
2120 "name of AFS root volume");
2121 cmd_AddParm(ts, "-stat", CMD_SINGLE, CMD_OPTIONAL,
2122 "number of stat entries");
2123 cmd_AddParm(ts, "-memcache", CMD_FLAG, CMD_OPTIONAL, "run diskless");
2124 cmd_AddParm(ts, "-cachedir", CMD_SINGLE, CMD_OPTIONAL, "cache directory");
2125 cmd_AddParm(ts, "-mountdir", CMD_SINGLE, CMD_OPTIONAL, "mount location");
2126 cmd_AddParm(ts, "-daemons", CMD_SINGLE, CMD_OPTIONAL,
2127 "number of daemons to use");
2128 cmd_AddParm(ts, "-nosettime", CMD_FLAG, CMD_OPTIONAL,
2129 "don't set the time");
2130 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL,
2131 "display lots of information");
2132 cmd_AddParm(ts, "-rmtsys", CMD_FLAG, CMD_OPTIONAL,
2133 "start NFS rmtsysd program");
2134 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "display debug info");
2135 cmd_AddParm(ts, "-chunksize", CMD_SINGLE, CMD_OPTIONAL,
2136 "log(2) of chunk size");
2137 cmd_AddParm(ts, "-dcache", CMD_SINGLE, CMD_OPTIONAL,
2138 "number of dcache entries");
2139 cmd_AddParm(ts, "-volumes", CMD_SINGLE, CMD_OPTIONAL,
2140 "number of volume entries");
2141 cmd_AddParm(ts, "-biods", CMD_SINGLE, CMD_OPTIONAL,
2142 "number of bkg I/O daemons (aix vm)");
2144 cmd_AddParm(ts, "-prealloc", CMD_SINGLE, CMD_OPTIONAL,
2145 "number of 'small' preallocated blocks");
2147 cmd_AddParm(ts, "-pininodes", CMD_SINGLE, CMD_OPTIONAL,
2148 "number of inodes to hog");
2150 cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL,
2151 "configuration directory");
2152 cmd_AddParm(ts, "-logfile", CMD_SINGLE, CMD_OPTIONAL,
2153 "Place to keep the CM log");
2154 cmd_AddParm(ts, "-waitclose", CMD_FLAG, CMD_OPTIONAL,
2155 "make close calls synchronous");
2156 cmd_AddParm(ts, "-shutdown", CMD_FLAG, CMD_OPTIONAL,
2157 "Shutdown all afs state");
2158 cmd_AddParm(ts, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2159 "Collect rpc statistics by peer");
2160 cmd_AddParm(ts, "-enable_process_stats", CMD_FLAG,
2161 CMD_OPTIONAL | CMD_HIDE,
2162 "Collect rpc statistics for this process");
2163 cmd_AddParm(ts, "-mem_alloc_sleep", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
2164 "Allow sleeps when allocating memory cache");
2165 cmd_AddParm(ts, "-afsdb", CMD_FLAG, (CMD_OPTIONAL
2166 #ifndef AFS_AFSDB_ENV
2169 ), "Enable AFSDB support");
2170 cmd_AddParm(ts, "-files_per_subdir", CMD_SINGLE, CMD_OPTIONAL,
2171 "log(2) of the number of cache files per cache subdirectory");
2172 cmd_AddParm(ts, "-dynroot", CMD_FLAG, CMD_OPTIONAL,
2173 "Enable dynroot support");
2174 cmd_AddParm(ts, "-fakestat", CMD_FLAG, CMD_OPTIONAL,
2175 "Enable fakestat support for cross-cell mounts");
2176 cmd_AddParm(ts, "-fakestat-all", CMD_FLAG, CMD_OPTIONAL,
2177 "Enable fakestat support for all mounts");
2178 cmd_AddParm(ts, "-nomount", CMD_FLAG, CMD_OPTIONAL, "Do not mount AFS");
2179 cmd_AddParm(ts, "-backuptree", CMD_FLAG, CMD_OPTIONAL,
2180 "Prefer backup volumes for mointpoints in backup volumes");
2181 cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL, "Bind the Rx socket (one interface only)");
2182 return (cmd_Dispatch(argc, argv));
2187 #define MOUNTED_TABLE MNT_MNTTAB
2190 #define MOUNTED_TABLE MNTTAB
2192 #define MOUNTED_TABLE MOUNTED
2199 #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)
2203 struct mnttab tmntent;
2205 memset(&tmntent, '\0', sizeof(struct mnttab));
2206 if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) {
2207 printf("Can't open %s\n", MOUNTED_TABLE);
2211 tmntent.mnt_special = "AFS";
2212 tmntent.mnt_mountp = cacheMountDir;
2213 tmntent.mnt_fstype = "xx";
2214 tmntent.mnt_mntopts = "rw";
2215 sprintf(tbuf, "%ld", (long)time((time_t *) 0));
2216 tmntent.mnt_time = tbuf;
2217 putmntent(tfilep, &tmntent);
2220 #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
2221 struct mntent tmntent;
2223 tfilep = setmntent("/etc/mtab", "a+");
2224 tmntent.mnt_fsname = "AFS";
2225 tmntent.mnt_dir = cacheMountDir;
2226 tmntent.mnt_type = "afs";
2227 tmntent.mnt_opts = "rw";
2228 tmntent.mnt_freq = 1;
2229 tmntent.mnt_passno = 3;
2230 addmntent(tfilep, &tmntent);
2233 struct mntent tmntent;
2235 memset(&tmntent, '\0', sizeof(struct mntent));
2236 tfilep = setmntent(MOUNTED_TABLE, "a+");
2238 printf("Can't open %s for write; Not adding afs entry to it\n",
2242 tmntent.mnt_fsname = "AFS";
2243 tmntent.mnt_dir = cacheMountDir;
2244 tmntent.mnt_type = "xx";
2245 tmntent.mnt_opts = "rw";
2246 tmntent.mnt_freq = 1;
2247 tmntent.mnt_passno = 3;
2249 tmntent.mnt_type = "afs";
2250 tmntent.mnt_time = time(0);
2251 tmntent.mnt_cnode = 0;
2253 addmntent(tfilep, &tmntent);
2255 #endif /* AFS_SGI_ENV */
2256 #endif /* AFS_SUN5_ENV */
2257 #endif /* unreasonable systems */
2258 #ifdef AFS_DARWIN_ENV
2259 mach_port_t diskarb_port;
2260 kern_return_t status;
2262 status = DiskArbStart(&diskarb_port);
2263 if (status == KERN_SUCCESS) {
2265 DiskArbDiskAppearedWithMountpointPing_auto("AFS",
2266 DISK_ARB_NETWORK_DISK_FLAG,
2271 #endif /* AFS_DARWIN_ENV */
2275 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
2277 call_syscall(param1, param2, param3, param4, param5, param6, param7)
2278 long param1, param2, param3, param4, param5, param6, param7;
2281 #ifdef AFS_LINUX20_ENV
2283 struct afsprocdata syscall_data;
2284 int fd = open(PROC_SYSCALL_FNAME,O_RDWR);
2286 fd = open(PROC_SYSCALL_ARLA_FNAME,O_RDWR);
2292 param4 = (long)eparm;
2294 syscall_data.syscall = AFSCALL_CALL;
2295 syscall_data.param1 = param1;
2296 syscall_data.param2 = param2;
2297 syscall_data.param3 = param3;
2298 syscall_data.param4 = param4;
2300 error = ioctl(fd, VIOC_SYSCALL, &syscall_data);
2306 syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4,
2307 param5, param6, param7);
2310 printf("SScall(%d, %d, %d)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1,
2314 #else /* AFS_AIX32_ENV */
2315 #if defined(AFS_SGI_ENV)
2316 call_syscall(call, parm0, parm1, parm2, parm3, parm4)
2321 error = afs_syscall(call, parm0, parm1, parm2, parm3, parm4);
2323 printf("SScall(%d, %d)=%d ", call, parm0, error);
2328 call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6)
2331 return syscall(AFSCALL_CALL, call, parm0, parm1, parm2, parm3, parm4,
2334 #endif /* AFS_SGI_ENV */
2335 #endif /* AFS_AIX32_ENV */
2339 /* Special handling for AIX's afs mount operation since they require much more miscl. information before making the vmount(2) syscall */
2340 #include <sys/vfs.h>
2342 #define ROUNDUP(x) (((x) + 3) & ~3)
2346 struct vmount *vmountp;
2349 size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4;
2350 /* Malloc the vmount structure */
2351 if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) {
2352 printf("Can't allocate space for the vmount structure (AIX)\n");
2356 /* zero out the vmount structure */
2357 memset(vmountp, '\0', size);
2359 /* transfer info into the vmount structure */
2360 vmountp->vmt_revision = VMT_REVISION;
2361 vmountp->vmt_length = size;
2362 vmountp->vmt_fsid.fsid_dev = 0;
2363 vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS;
2364 vmountp->vmt_vfsnumber = 0;
2365 vmountp->vmt_time = 0; /* We'll put the time soon! */
2366 vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */
2367 vmountp->vmt_gfstype = AFS_MOUNT_AFS;
2368 vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw");
2370 /* Do the actual mount system call */
2371 error = vmount(vmountp, size);
2376 vmountdata(vmtp, obj, stub, host, hostsname, info, args)
2377 struct vmount *vmtp;
2378 char *obj, *stub, *host, *hostsname, *info, *args;
2380 register struct data {
2386 vdp = (struct data *)vmtp->vmt_data;
2387 vdp->vmt_off = sizeof(struct vmount);
2388 size = ROUNDUP(strlen(obj) + 1);
2389 vdp->vmt_size = size;
2390 strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj);
2394 vdp->vmt_off = vdprev->vmt_off + size;
2395 size = ROUNDUP(strlen(stub) + 1);
2396 vdp->vmt_size = size;
2397 strcpy(vmt2dataptr(vmtp, VMT_STUB), stub);
2401 vdp->vmt_off = vdprev->vmt_off + size;
2402 size = ROUNDUP(strlen(host) + 1);
2403 vdp->vmt_size = size;
2404 strcpy(vmt2dataptr(vmtp, VMT_HOST), host);
2408 vdp->vmt_off = vdprev->vmt_off + size;
2409 size = ROUNDUP(strlen(hostsname) + 1);
2410 vdp->vmt_size = size;
2411 strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname);
2416 vdp->vmt_off = vdprev->vmt_off + size;
2417 size = ROUNDUP(strlen(info) + 1);
2418 vdp->vmt_size = size;
2419 strcpy(vmt2dataptr(vmtp, VMT_INFO), info);
2423 vdp->vmt_off = vdprev->vmt_off + size;
2424 size = ROUNDUP(strlen(args) + 1);
2425 vdp->vmt_size = size;
2426 strcpy(vmt2dataptr(vmtp, VMT_ARGS), args);
2428 #endif /* AFS_AIX_ENV */
2430 #ifdef AFS_SGI53_ENV
2431 #ifdef AFS_SGI61_ENV
2432 /* The dwarf structures are searched to find entry points of static functions
2433 * and the addresses of static variables. The file name as well as the
2434 * sybmol name is reaquired.
2437 /* Contains list of names to find in given file. */
2439 char *name; /* Name of variable or function. */
2440 afs_hyper_t addr; /* Address of function, undefined if not found. */
2441 Dwarf_Half type; /* DW_AT_location for vars, DW_AT_lowpc for func's */
2442 char found; /* set if found. */
2446 char *file; /* Name of file containing vars or funcs */
2447 staticAddrList *addrList; /* List of vars and/or funcs. */
2448 int nAddrs; /* # of addrList's */
2449 int found; /* set if we've found this file already. */
2452 /* routines used to find addresses in /unix */
2453 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2454 void findMDebugStaticAddresses(staticNameList *, int, int);
2456 void findDwarfStaticAddresses(staticNameList *, int);
2457 void findElfAddresses(Dwarf_Debug, Dwarf_Die, staticNameList *);
2458 void getElfAddress(Dwarf_Debug, Dwarf_Die, staticAddrList *);
2460 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2461 #define AFS_N_FILELISTS 2
2462 #define AFS_SYMS_NEEDED 3
2463 #else /* AFS_SGI62_ENV */
2464 #define AFS_N_FILELISTS 1
2465 #endif /* AFS_SGI62_ENV */
2470 set_staticaddrs(void)
2472 staticNameList fileList[AFS_N_FILELISTS];
2474 fileList[0].addrList =
2475 (staticAddrList *) calloc(1, sizeof(staticAddrList));
2476 if (!fileList[0].addrList) {
2477 printf("set_staticaddrs: Can't calloc fileList[0].addrList\n");
2480 fileList[0].file = "nfs_server.c";
2481 fileList[0].found = 0;
2482 fileList[0].nAddrs = 1;
2483 fileList[0].addrList[0].name = "rfsdisptab_v2";
2484 fileList[0].addrList[0].type = DW_AT_location;
2485 fileList[0].addrList[0].found = 0;
2487 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2488 fileList[1].addrList =
2489 (staticAddrList *) calloc(2, sizeof(staticAddrList));
2490 if (!fileList[1].addrList) {
2491 printf("set_staticaddrs: Can't malloc fileList[1].addrList\n");
2494 fileList[1].file = "uipc_socket.c";
2495 fileList[1].found = 0;
2496 fileList[1].nAddrs = 2;
2497 fileList[1].addrList[0].name = "sblock";
2498 fileList[1].addrList[0].type = DW_AT_low_pc;
2499 fileList[1].addrList[0].found = 0;
2500 fileList[1].addrList[1].name = "sbunlock";
2501 fileList[1].addrList[1].type = DW_AT_low_pc;
2502 fileList[1].addrList[1].found = 0;
2504 if (64 != sysconf(_SC_KERN_POINTERS))
2505 findMDebugStaticAddresses(fileList, AFS_N_FILELISTS, AFS_SYMS_NEEDED);
2507 #endif /* AFS_SGI62_ENV */
2508 findDwarfStaticAddresses(fileList, AFS_N_FILELISTS);
2510 if (fileList[0].addrList[0].found) {
2511 call_syscall(AFSOP_NFSSTATICADDR2, fileList[0].addrList[0].addr.high,
2512 fileList[0].addrList[0].addr.low);
2515 printf("NFS V2 is not present in the kernel.\n");
2517 free(fileList[0].addrList);
2518 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2519 if (fileList[1].addrList[0].found && fileList[1].addrList[1].found) {
2520 call_syscall(AFSOP_SBLOCKSTATICADDR2,
2521 fileList[1].addrList[0].addr.high,
2522 fileList[1].addrList[0].addr.low,
2523 fileList[1].addrList[1].addr.high,
2524 fileList[1].addrList[1].addr.low);
2526 if (!fileList[1].addrList[0].found)
2527 printf("Can't find %s in kernel. Exiting.\n",
2528 fileList[1].addrList[0].name);
2529 if (!fileList[1].addrList[0].found)
2530 printf("Can't find %s in kernel. Exiting.\n",
2531 fileList[1].addrList[1].name);
2534 free(fileList[1].addrList);
2535 #endif /* AFS_SGI62_ENV */
2539 /* Find addresses for static variables and functions. */
2541 findDwarfStaticAddresses(staticNameList * nameList, int nLists)
2548 char *hname = (char *)0;
2549 Dwarf_Unsigned dwarf_access = O_RDONLY;
2550 Dwarf_Debug dwarf_debug;
2551 Dwarf_Error dwarf_error;
2552 Dwarf_Unsigned dwarf_cu_header_length;
2553 Dwarf_Unsigned dwarf_abbrev_offset;
2554 Dwarf_Half dwarf_address_size;
2555 Dwarf_Unsigned next_cu_header;
2556 Dwarf_Die dwarf_die;
2557 Dwarf_Die dwarf_next_die;
2558 Dwarf_Die dwarf_child_die;
2560 if (elf_version(EV_CURRENT) == EV_NONE) {
2561 printf("findDwarfStaticAddresses: Bad elf version.\n");
2565 if ((fd = open("/unix", O_RDONLY, 0)) < 0) {
2566 printf("findDwarfStaticAddresses: Failed to open /unix.\n");
2570 dwarf_init(fd, dwarf_access, NULL, NULL, &dwarf_debug, &dwarf_error);
2571 if (code != DW_DLV_OK) {
2572 /* Nope hope for the elves and dwarves, try intermediate code. */
2579 /* Run through the headers until we find ones for files we've
2580 * specified in nameList.
2583 dwarf_next_cu_header(dwarf_debug, &dwarf_cu_header_length, NULL,
2584 &dwarf_abbrev_offset, &dwarf_address_size,
2585 &next_cu_header, &dwarf_error);
2586 if (code == DW_DLV_NO_ENTRY) {
2588 } else if (code == DW_DLV_ERROR) {
2589 printf("findDwarfStaticAddresses: Error reading headers: %s\n",
2590 dwarf_errmsg(dwarf_error));
2594 code = dwarf_siblingof(dwarf_debug, NULL, &dwarf_die, &dwarf_error);
2595 if (code != DW_DLV_OK) {
2596 printf("findDwarfStaticAddresses: Can't get first die. %s\n",
2597 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2601 /* This is the header, test the name. */
2602 code = dwarf_diename(dwarf_die, &hname, &dwarf_error);
2603 if (code == DW_DLV_OK) {
2604 s = strrchr(hname, '/');
2605 for (i = 0; i < nLists; i++) {
2606 if (s && !strcmp(s + 1, nameList[i].file)) {
2607 findElfAddresses(dwarf_debug, dwarf_die, &nameList[i]);
2614 ("findDwarfStaticAddresses: Can't get name of current header. %s\n",
2615 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2618 dwarf_dealloc(dwarf_debug, hname, DW_DLA_STRING);
2620 if (found >= nLists) { /* we're done */
2625 /* Frees up all allocated space. */
2626 (void)dwarf_finish(dwarf_debug, &dwarf_error);
2631 findElfAddresses(Dwarf_Debug dwarf_debug, Dwarf_Die dwarf_die,
2632 staticNameList * nameList)
2635 Dwarf_Error dwarf_error;
2636 Dwarf_Die dwarf_next_die;
2637 Dwarf_Die dwarf_child_die;
2638 Dwarf_Attribute dwarf_return_attr;
2639 char *vname = (char *)0;
2643 /* Drop into this die to find names in addrList. */
2644 code = dwarf_child(dwarf_die, &dwarf_child_die, &dwarf_error);
2645 if (code != DW_DLV_OK) {
2646 printf("findElfAddresses: Can't get child die. %s\n",
2647 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2651 /* Try to find names in each sibling. */
2652 dwarf_next_die = (Dwarf_Die) 0;
2654 code = dwarf_diename(dwarf_child_die, &vname, &dwarf_error);
2655 /* It's possible that some siblings don't have names. */
2656 if (code == DW_DLV_OK) {
2657 for (i = 0; i < nameList->nAddrs; i++) {
2658 if (!nameList->addrList[i].found) {
2659 if (!strcmp(vname, nameList->addrList[i].name)) {
2660 getElfAddress(dwarf_debug, dwarf_child_die,
2661 &(nameList->addrList[i]));
2669 dwarf_dealloc(dwarf_debug, dwarf_next_die, DW_DLA_DIE);
2671 if (found >= nameList->nAddrs) { /* we're done. */
2675 dwarf_next_die = dwarf_child_die;
2677 dwarf_siblingof(dwarf_debug, dwarf_next_die, &dwarf_child_die,
2680 } while (code == DW_DLV_OK);
2683 /* Get address out of current die. */
2685 getElfAddress(Dwarf_Debug dwarf_debug, Dwarf_Die dwarf_child_die,
2686 staticAddrList * addrList)
2689 Dwarf_Error dwarf_error;
2690 Dwarf_Attribute dwarf_return_attr;
2691 Dwarf_Bool dwarf_return_bool;
2692 Dwarf_Locdesc *llbuf = NULL;
2693 Dwarf_Signed listlen;
2694 off64_t addr = (off64_t) 0;
2698 dwarf_hasattr(dwarf_child_die, addrList->type, &dwarf_return_bool,
2700 if ((code != DW_DLV_OK) || (!dwarf_return_bool)) {
2701 printf("getElfAddress: no address given for %s. %s\n", addrList->name,
2702 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2706 dwarf_attr(dwarf_child_die, addrList->type, &dwarf_return_attr,
2708 if (code != DW_DLV_OK) {
2709 printf("getElfAddress: Can't get attribute. %s\n",
2710 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2714 switch (addrList->type) {
2715 case DW_AT_location:
2717 dwarf_loclist(dwarf_return_attr, &llbuf, &listlen, &dwarf_error);
2718 if (code != DW_DLV_OK) {
2719 printf("getElfAddress: Can't get location for %s. %s\n",
2721 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2724 if ((listlen != 1) || (llbuf[0].ld_cents != 1)) {
2725 printf("getElfAddress: %s has more than one address.\n",
2729 addr = llbuf[0].ld_s[0].lr_number;
2734 dwarf_lowpc(dwarf_child_die, (Dwarf_Addr *) & addr, &dwarf_error);
2735 if (code != DW_DLV_OK) {
2736 printf("getElfAddress: Can't get lowpc for %s. %s\n",
2738 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
2744 printf("getElfAddress: Bad case %d in switch.\n", addrList->type);
2748 addrList->addr.high = (addr >> 32) & 0xffffffff;
2749 addrList->addr.low = addr & 0xffffffff;
2750 addrList->found = 1;
2753 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
2754 /* Find symbols in the .mdebug section for 32 bit kernels. */
2757 * On 32bit platforms, we're still using the ucode compilers to build
2758 * the kernel, so we need to get our static text/data from the .mdebug
2759 * section instead of the .dwarf sections.
2761 /* SearchNameList searches our bizarre structs for the given string.
2762 * If found, sets the found bit and the address and returns 1.
2763 * Not found returns 0.
2766 SearchNameList(char *name, afs_uint32 addr, staticNameList * nameList,
2770 for (i = 0; i < nLists; i++) {
2771 for (j = 0; j < nameList[i].nAddrs; j++) {
2772 if (nameList[i].addrList[j].found)
2774 if (!strcmp(name, nameList[i].addrList[j].name)) {
2775 nameList[i].addrList[j].addr.high = 0;
2776 nameList[i].addrList[j].addr.low = addr;
2777 nameList[i].addrList[j].found = 1;
2786 SearchMDebug(Elf_Scn * scnp, Elf32_Shdr * shdrp, staticNameList * nameList,
2787 int nLists, int needed)
2789 long *buf = (long *)(elf_getdata(scnp, NULL)->d_buf);
2790 u_long addr, mdoff = shdrp->sh_offset;
2792 SYMR *symbase, *symp, *symend;
2793 FDR *fdrbase, *fdrp;
2795 char *strbase, *str;
2800 addr = (__psunsigned_t) buf;
2801 hdrp = (HDRR *) addr;
2803 /* setup base addresses */
2804 addr = (u_long) buf + (u_long) (hdrp->cbFdOffset - mdoff);
2805 fdrbase = (FDR *) addr;
2806 addr = (u_long) buf + (u_long) (hdrp->cbSymOffset - mdoff);
2807 symbase = (SYMR *) addr;
2808 addr = (u_long) buf + (u_long) (hdrp->cbSsOffset - mdoff);
2809 strbase = (char *)addr;
2811 #define KEEPER(a,b) ((a == stStaticProc && b == scText) || \
2812 (a == stStatic && (b == scData || b == scBss || \
2813 b == scSBss || b == scSData)))
2815 for (fdrp = fdrbase; fdrp < &fdrbase[hdrp->ifdMax]; fdrp++) {
2816 str = strbase + fdrp->issBase + fdrp->rss;
2818 /* local symbols for each fd */
2819 for (symp = &symbase[fdrp->isymBase];
2820 symp < &symbase[fdrp->isymBase + fdrp->csym]; symp++) {
2821 if (KEEPER(symp->st, symp->sc)) {
2822 if (symp->value == 0)
2825 str = strbase + fdrp->issBase + symp->iss;
2826 /* Look for AFS symbols of interest */
2827 if (SearchNameList(str, symp->value, nameList, nLists)) {
2829 if (nFound >= needed)
2838 * returns section with the name of scn_name, & puts its header in shdr64 or
2839 * shdr32 based on elf's file type
2843 findMDebugSection(Elf * elf, char *scn_name)
2847 Elf_Scn *scn = NULL;
2851 if ((ehdr32 = elf32_getehdr(elf)) == NULL)
2854 if ((scn = elf_nextscn(elf, scn)) == NULL)
2856 if ((shdr32 = elf32_getshdr(scn)) == NULL)
2860 elf_strptr(elf, ehdr32->e_shstrndx, shdr32->sh_name)));
2867 findMDebugStaticAddresses(staticNameList * nameList, int nLists, int needed)
2871 Elf_Scn *mdebug_scn;
2872 Elf32_Shdr *mdebug_shdr;
2875 if ((fd = open("/unix", O_RDONLY)) == -1) {
2876 printf("findMDebugStaticAddresses: Failed to open /unix.\n");
2880 (void)elf_version(EV_CURRENT);
2881 if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
2883 ("findMDebugStaticAddresses: /unix doesn't seem to be an elf file\n");
2887 mdebug_scn = findMDebugSection(elf, ".mdebug");
2889 printf("findMDebugStaticAddresses: Can't find .mdebug section.\n");
2892 mdebug_shdr = elf32_getshdr(mdebug_scn);
2894 printf("findMDebugStaticAddresses: Can't find .mdebug header.\n");
2898 (void)SearchMDebug(mdebug_scn, mdebug_shdr, nameList, nLists, needed);
2904 #endif /* AFS_SGI62_ENV */
2906 #else /* AFS_SGI61_ENV */
2908 struct nlist nlunix[] = {
2915 int i, j, kmem, count;
2917 if ((kmem = open("/dev/kmem", O_RDONLY)) < 0) {
2918 printf("Warning: can't open /dev/kmem\n");
2921 if ((j = nlist("/unix", nlunix)) < 0) {
2922 printf("Warning: can't nlist /unix\n");
2925 i = nlunix[0].n_value;
2926 if (lseek(kmem, i, L_SET /*0 */ ) != i) {
2927 printf("Warning: can't lseek to %x\n", i);
2930 if ((j = read(kmem, &count, sizeof count)) != sizeof count) {
2931 printf("WARNING: kmem read at %x failed\n", i);
2936 #endif /* AFS_SGI61_ENV */
2937 #endif /* AFS_SGI53_ENV */