2 * (C) COPYRIGHT IBM CORPORATION 1987, 1998
3 * LICENSED MATERIALS - PROPERTY OF IBM
6 /*------------------------------------------------------------------------------
9 * Information Technology Center
13 * The Andrew File System startup process. It is responsible for
14 * reading and parsing the various configuration files, starting up
15 * the kernel processes required by AFS and feeding the configuration
16 * information to the kernel.
18 * Recognized flags are:
19 * -blocks The number of blocks available in the workstation cache.
20 * -files The target number of files in the workstation cache (Default:
22 * -rootvol The name of the root volume to use.
23 * -stat The number of stat cache entries.
24 * -hosts List of servers to check for volume location info FOR THE
26 * -memcache Use an in-memory cache rather than disk.
27 * -cachedir The base directory for the workstation cache.
28 * -mountdir The directory on which the AFS is to be mounted.
29 * -confdir The configuration directory .
30 * -nosettime Don't keep checking the time to avoid drift.
32 * -debug Print out additional debugging info.
33 * -kerndev [OBSOLETE] The kernel device for AFS.
34 * -dontfork [OBSOLETE] Don't fork off as a new process.
35 * -daemons The number of background daemons to start (Default: 2).
36 * -rmtsys Also fires up an afs remote sys call (e.g. pioctl, setpag)
38 * -chunksize [n] 2^n is the chunksize to be used. 0 is default.
39 * -dcache The number of data cache entries.
40 * -biods Number of bkg I/O daemons (AIX3.1 only)
41 * -prealloc Number of preallocated "small" memory blocks
42 * -pininodes Number of inodes which can be spared from inode[] for
43 * pointing at Vfiles. If this is set too high, you may have
44 * system problems, which can only be ameliorated by changing
45 * NINODE (or equivalent) and rebuilding the kernel.
46 * This option is now disabled.
47 * -logfile Place where to put the logfile (default in <cache>/etc/AFSLog.
48 * -waitclose make close calls always synchronous (slows em down, tho)
49 * -shutdown Shutdown afs daemons
50 *---------------------------------------------------------------------------*/
54 #include <afs/param.h>
59 #include <afs/afsutil.h>
68 #include <sys/types.h>
74 #include <sys/param.h>
75 #include <sys/fs_types.h>
77 #if defined(AFS_SUN_ENV)
81 #include <sys/mount.h>
85 #include <sys/fcntl.h>
86 #include <sys/mnttab.h>
87 #include <sys/mntent.h>
89 #if defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
94 #if defined(AFS_OSF_ENV) || defined(AFS_DEC_ENV)
95 #include <sys/mount.h>
100 #include <netinet/in.h>
101 #include <afs/afs_args.h>
102 #include <afs/cellconfig.h>
103 #include <afs/auth.h>
105 #include <afs/afssyscalls.h>
106 #include <afs/afsutil.h>
112 #include <libdwarf.h>
113 void set_staticaddrs(void);
114 #endif /* AFS_SGI61_ENV */
115 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
117 #include <symconst.h>
122 #ifdef AFS_LINUX20_ENV
123 #include <sys/resource.h>
127 #define MOUNT_AFS AFS_MOUNT_AFS
128 #endif /* MOUNT_AFS */
131 #include <sys/statvfs.h>
133 #if !defined(AFS_OSF_ENV)
134 #include <sys/statfs.h>
141 #define CACHEINFOFILE "cacheinfo"
142 #define AFSLOGFILE "AFSLog"
143 #define DCACHEFILE "CacheItems"
144 #define VOLINFOFILE "VolumeItems"
146 #define MAXIPADDRS 1024
148 char LclCellName[64];
150 #define MAX_CACHE_LOOPS 4
153 * Internet address (old style... should be updated). This was pulled out of the old 4.2
154 * version of <netinet/in.h>, since it's still useful.
158 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
159 struct { u_short s_w1,s_w2; } S_un_w;
162 #define s_host S_un.S_un_b.s_b2 /* host on imp */
163 #define s_net S_un.S_un_b.s_b1 /* network */
164 #define s_imp S_un.S_un_w.s_w2 /* imp */
165 #define s_impno S_un.S_un_b.s_b4 /* imp # */
166 #define s_lh S_un.S_un_b.s_b3 /* logical host */
169 #define mPrintIPAddr(ipaddr) printf("[%d.%d.%d.%d] ", \
170 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b1, \
171 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b2, \
172 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b3, \
173 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b4)
176 * Global configuration variables.
178 afs_int32 afs_shutdown = 0;
179 afs_int32 cacheBlocks; /*Num blocks in the cache*/
180 afs_int32 cacheFiles = 1000; /*Optimal # of files in workstation cache*/
181 afs_int32 cacheStatEntries = 300; /*Number of stat cache entries*/
182 char cacheBaseDir[1024]; /*Where the workstation AFS cache lives*/
183 char confDir[1024]; /*Where the workstation AFS configuration lives*/
184 char fullpn_DCacheFile[1024]; /*Full pathname of DCACHEFILE*/
185 char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE*/
186 char fullpn_AFSLogFile[1024]; /*Full pathname of AFSLOGFILE*/
187 char fullpn_CacheInfo[1024]; /*Full pathname of CACHEINFO*/
188 char fullpn_VFile[1024]; /*Full pathname of data cache files*/
189 char *vFileNumber; /*Ptr to the number part of above pathname*/
190 int sawCacheMountDir = 0; /* from cmd line */
191 int sawCacheBaseDir = 0;
192 int sawCacheBlocks = 0;
193 int sawDCacheSize = 0;
195 char cacheMountDir[1024]; /*Mount directory for AFS*/
196 char rootVolume[64] = "root.afs"; /*AFS root volume name*/
197 afs_int32 cacheSetTime = 1; /*Keep checking time to avoid drift?*/
198 afs_int32 isHomeCell; /*Is current cell info for the home cell?*/
199 afs_int32 lookingForHomeCell; /*Are we still looking for the home cell?*/
200 int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open*/
201 int ownerRWmode = 0600; /*Read/write OK by owner*/
202 static int filesSet = 0; /*True if number of files explicitly set*/
203 static int nDaemons = 2; /* Number of background daemons */
204 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
205 static int dCacheSize = 300; /* # of dcache entries */
206 static int vCacheSize = 50; /* # of volume cache entries */
207 static int rootVolSet = 0; /*True if root volume name explicitly set*/
208 int addrNum; /*Cell server address index being printed*/
209 static int cacheFlags = 0; /*Flags to cache manager*/
210 static int nBiods = 5; /* AIX3.1 only */
211 static int preallocs = 400; /* Def # of allocated memory blocks */
212 static int enable_peer_stats = 0; /* enable rx stats */
213 static int enable_process_stats = 0; /* enable rx stats */
215 static int inodes = 60; /* VERY conservative, but has to be */
217 int afsd_verbose = 0; /*Are we being chatty?*/
218 int afsd_debug = 0; /*Are we printing debugging info?*/
219 int afsd_CloseSynch = 0; /*Are closes synchronous or not? */
222 #define AFSD_INO_T ino64_t
224 #define AFSD_INO_T afs_uint32
226 AFSD_INO_T *inode_for_V; /* Array of inodes for desired
228 int missing_DCacheFile = 1; /*Is the DCACHEFILE missing?*/
229 int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing?*/
230 int afsd_rmtsys = 0; /* Default: don't support rmtsys */
231 struct afs_cacheParams cparams; /* params passed to cache manager */
233 static int HandleMTab();
235 /* ParseArgs is now obsolete, being handled by cmd */
237 /*------------------------------------------------------------------------------
241 * Open the file containing the description of the workstation's AFS cache
242 * and pull out its contents. The format of this file is as follows:
244 * cacheMountDir:cacheBaseDir:cacheBlocks
250 * 0 if everything went well,
254 * Nothing interesting.
258 *---------------------------------------------------------------------------*/
260 int ParseCacheInfoFile()
262 static char rn[]="ParseCacheInfoFile"; /*This routine's name*/
263 FILE *cachefd; /*Descriptor for cache info file*/
264 int parseResult; /*Result of our fscanf()*/
265 afs_int32 tCacheBlocks;
266 char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
269 printf("%s: Opening cache info file '%s'...\n",
270 rn, fullpn_CacheInfo);
272 cachefd = fopen(fullpn_CacheInfo, "r");
274 printf("%s: Can't read cache info file '%s'\n",
275 rn, fullpn_CacheInfo);
280 * Parse the contents of the cache info file. All chars up to the first
281 * colon are the AFS mount directory, all chars to the next colon are the
282 * full path name of the workstation cache directory and all remaining chars
283 * represent the number of blocks in the cache.
285 tCacheMountDir[0] = tCacheBaseDir[0] = '\0';
286 parseResult = fscanf(cachefd,
287 "%1024[^:]:%1024[^:]:%d",
288 tCacheMountDir, tCacheBaseDir, &tCacheBlocks);
291 * Regardless of how the parse went, we close the cache info file.
295 if (parseResult == EOF || parseResult < 3) {
296 printf("%s: Format error in cache info file!\n",
298 if (parseResult == EOF)
299 printf("\tEOF encountered before any field parsed.\n");
301 printf("\t%d out of 3 fields successfully parsed.\n",
304 printf("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
305 cacheMountDir, cacheBaseDir, cacheBlocks);
309 for (tmd = tCacheMountDir; *tmd == '\n' || *tmd == ' ' || *tmd == '\t'; tmd++) ;
310 for (tbd = tCacheBaseDir; *tbd == '\n' || *tbd == ' ' || *tbd == '\t'; tbd++) ;
311 /* now copy in the fields not explicitly overridden by cmd args */
312 if (!sawCacheMountDir)
313 strcpy(cacheMountDir, tmd);
314 if (!sawCacheBaseDir)
315 strcpy(cacheBaseDir, tbd);
317 cacheBlocks = tCacheBlocks;
320 printf("%s: Cache info file successfully parsed:\n",
322 printf("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
323 tmd, tbd, tCacheBlocks);
325 if (! (cacheFlags & AFSCALL_INIT_MEMCACHE))
326 PartSizeOverflow(tbd, cacheBlocks);
332 * All failures to open the partition are ignored. Also if the cache dir
333 * isn't a mounted partition it's also ignored since we can't guarantee
334 * what will be stored afterwards. Too many if's. This is now purely
335 * advisory. ODS with over 2G partition also gives warning message.
337 PartSizeOverflow(path, cs)
341 int bsize=-1, totalblks, mint;
343 struct statvfs statbuf;
345 if (statvfs(path, &statbuf) != 0) {
346 if (afsd_debug) printf("statvfs failed on %s; skip checking for adequate partition space\n", path);
349 totalblks = statbuf.f_blocks;
350 bsize = statbuf.f_frsize;
352 struct statfs statbuf;
354 if (statfs(path, &statbuf) < 0) {
355 if (afsd_debug) printf("statfs failed on %s; skip checking for adequate partition space\n", path);
358 totalblks = statbuf.f_blocks;
359 bsize = statbuf.f_bsize;
361 if (bsize == -1) return 0; /* sucess */
363 /* now free and totalblks are in fragment units, but we want them in 1K units */
365 totalblks *= (bsize / 1024);
367 totalblks /= (1024/bsize);
370 mint = totalblks - ((totalblks * 5) / 100);
372 printf("Cache size (%d) must be less than 95%% of partition size (which is %d). Lower cache size\n",
377 /*-----------------------------------------------------------------------------
381 * Given the final component of a filename expected to be a data cache file,
382 * return the integer corresponding to the file. Note: we reject names that
383 * are not a ``V'' followed by an integer. We also reject those names having
384 * the right format but lying outside the range [0..cacheFiles-1].
387 * fname : Char ptr to the filename to parse.
390 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
394 * Nothing interesting.
398 *---------------------------------------------------------------------------*/
400 int GetVFileNumber(fname)
403 int computedVNumber; /*The computed file number we return*/
404 int filenameLen; /*Number of chars in filename*/
405 int currDigit; /*Current digit being processed*/
408 * The filename must have at least two characters, the first of which must be a ``V''
409 * and the second of which cannot be a zero unless the file is exactly two chars long.
411 filenameLen = strlen(fname);
416 if ((filenameLen > 2) && (fname[1] == '0'))
420 * Scan through the characters in the given filename, failing immediately if a non-digit
423 for (currDigit = 1; currDigit < filenameLen; currDigit++)
424 if (isdigit(fname[currDigit]) == 0)
428 * All relevant characters are digits. Pull out the decimal number they represent.
429 * Reject it if it's out of range, otherwise return it.
431 computedVNumber = atoi(++fname);
432 if (computedVNumber < cacheFiles)
433 return(computedVNumber);
438 /*-----------------------------------------------------------------------------
442 * Given a full pathname for a file we need to create for the workstation AFS
443 * cache, go ahead and create the file.
446 * fname : Full pathname of file to create.
449 * 0 iff the file was created,
453 * The given cache file has been found to be missing.
457 *---------------------------------------------------------------------------*/
459 int CreateCacheFile(fname)
462 static char rn[] = "CreateCacheFile"; /*Routine name*/
463 int cfd; /*File descriptor to AFS cache file*/
464 int closeResult; /*Result of close()*/
467 printf("%s: Creating cache file '%s'\n",
469 cfd = open(fname, createAndTrunc, ownerRWmode);
471 printf("%s: Can't create '%s', error return is %d (%d)\n",
472 rn, fname, cfd, errno);
475 closeResult = close(cfd);
477 printf("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
485 /*-----------------------------------------------------------------------------
489 * Sweep through the AFS cache directory, recording the inode number for
490 * each valid data cache file there. Also, delete any file that doesn't beint32
491 * in the cache directory during this sweep, and remember which of the other
492 * residents of this directory were seen. After the sweep, we create any data
493 * cache files that were missing.
496 * vFilesFound : Set to the number of data cache files found.
499 * 0 if everything went well,
503 * This routine may be called several times. If the number of data cache files
504 * found is less than the global cacheFiles, then the caller will need to call it
505 * again to record the inodes of the missing zero-length data cache files created
506 * in the previous call.
509 * Fills up the global inode_for_V array, may create and/or delete files as
511 *---------------------------------------------------------------------------*/
513 int SweepAFSCache(vFilesFound)
516 static char rn[] = "SweepAFSCache"; /*Routine name*/
517 char fullpn_FileToDelete[1024]; /*File to be deleted from cache*/
518 char *fileToDelete; /*Ptr to last component of above*/
519 DIR *cdirp; /*Ptr to cache directory structure*/
521 struct dirent64 *currp; /*Current directory entry*/
523 struct dirent *currp; /*Current directory entry*/
525 int vFileNum; /*Data cache file's associated number*/
527 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
529 printf("%s: Memory Cache, no cache sweep done\n", rn);
535 printf("%s: Opening cache directory '%s'\n",
538 if (chmod(cacheBaseDir, 0700)) { /* force it to be 700 */
539 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n",
543 cdirp = opendir(cacheBaseDir);
544 if (cdirp == (DIR *)0) {
545 printf("%s: Can't open AFS cache directory, '%s'.\n",
551 * Scan the directory entries, remembering data cache file inodes and the existance
552 * of other important residents. Delete all files that don't belong here.
555 sprintf(fullpn_FileToDelete, "%s/", cacheBaseDir);
556 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
559 for (currp = readdir64(cdirp); currp; currp = readdir64(cdirp))
561 for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
565 printf("%s: Current directory entry:\n",
568 printf("\tinode=%lld, reclen=%d, name='%s'\n",
569 currp->d_ino, currp->d_reclen, currp->d_name);
571 printf("\tinode=%d, reclen=%d, name='%s'\n",
572 currp->d_ino, currp->d_reclen, currp->d_name);
577 * Guess current entry is for a data cache file.
579 vFileNum = GetVFileNumber(currp->d_name);
582 * Found a valid data cache filename. Remember this file's inode and bump
583 * the number of files found.
585 inode_for_V[vFileNum] = currp->d_ino;
588 else if (strcmp(currp->d_name, DCACHEFILE) == 0) {
590 * Found the file holding the dcache entries.
592 missing_DCacheFile = 0;
594 else if (strcmp(currp->d_name, VOLINFOFILE) == 0) {
596 * Found the file holding the volume info.
598 missing_VolInfoFile = 0;
600 else if ((strcmp(currp->d_name, ".") == 0) ||
601 (strcmp(currp->d_name, "..") == 0) ||
602 (strcmp(currp->d_name, "lost+found") == 0)) {
604 * Don't do anything - this file is legit, and is to be left alone.
609 * This file doesn't belong in the cache. Nuke it.
611 sprintf(fileToDelete, "%s", currp->d_name);
613 printf("%s: Deleting '%s'\n",
614 rn, fullpn_FileToDelete);
615 if (unlink(fullpn_FileToDelete)) {
616 printf("%s: Can't unlink '%s', errno is %d\n",
617 rn, fullpn_FileToDelete, errno);
623 * Create all the cache files that are missing.
625 if (missing_DCacheFile) {
627 printf("%s: Creating '%s'\n",
628 rn, fullpn_DCacheFile);
629 if (CreateCacheFile(fullpn_DCacheFile))
630 printf("%s: Can't create '%s'\n",
631 rn, fullpn_DCacheFile);
633 if (missing_VolInfoFile) {
635 printf("%s: Creating '%s'\n",
636 rn, fullpn_VolInfoFile);
637 if (CreateCacheFile(fullpn_VolInfoFile))
638 printf("%s: Can't create '%s'\n",
639 rn, fullpn_VolInfoFile);
642 if (*vFilesFound < cacheFiles) {
644 * We came up short on the number of data cache files found. Scan through the inode
645 * list and create all missing files.
647 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++)
648 if (inode_for_V[vFileNum] == (AFSD_INO_T)0) {
649 sprintf(vFileNumber, "%d", vFileNum);
651 printf("%s: Creating '%s'\n",
653 if (CreateCacheFile(fullpn_VFile))
654 printf("%s: Can't create '%s'\n",
660 * Close the directory, return success.
663 printf("%s: Closing cache directory.\n",
669 static ConfigCell(aci, arock, adir)
670 register struct afsconf_cell *aci;
672 struct afsconf_dir *adir; {
673 register int isHomeCell;
676 afs_int32 hosts[MAXHOSTSPERCELL];
678 /* figure out if this is the home cell */
679 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
681 lookingForHomeCell = 0;
682 cellFlags = 1; /* home cell, suid is ok */
685 cellFlags = 2; /* not home, suid is forbidden */
688 /* build address list */
689 for(i=0;i<MAXHOSTSPERCELL;i++)
690 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
692 if (aci->linkedCell) cellFlags |= 4; /* Flag that linkedCell arg exists,
693 for upwards compatibility */
695 /* configure one cell */
696 call_syscall(AFSOP_ADDCELL2,
697 hosts, /* server addresses */
698 aci->name, /* cell name */
699 cellFlags, /* is this the home cell? */
700 aci->linkedCell); /* Linked cell, if any */
705 #include <sys/ioctl.h>
709 #define SET_RTPRI(P) { \
710 struct sched_param sp; \
711 sp.sched_priority = P; \
712 if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \
713 perror("sched_setscheduler"); \
716 #define SET_AFSD_RTPRI() SET_RTPRI(68)
717 #define SET_RX_RTPRI() SET_RTPRI(199)
719 #ifdef AFS_LINUX20_ENV
720 #define SET_AFSD_RTPRI()
721 #define SET_RX_RTPRI() do { if (setpriority(PRIO_PROCESS, 0, -10)<0) \
722 perror("setting rx priority"); \
725 #define SET_AFSD_RTPRI()
726 #define SET_RX_RTPRI()
731 register struct cmd_syndesc *as;
734 static char rn[] = "afsd"; /*Name of this routine*/
735 register afs_int32 code; /*Result of fork()*/
737 int currVFile; /*Current AFS cache file number passed in*/
738 int mountFlags; /*Flags passed to mount()*/
739 int lookupResult; /*Result of GetLocalCellName()*/
740 int cacheIteration; /*How many times through cache verification*/
741 int vFilesFound; /*How many data cache files were found in sweep*/
742 struct afsconf_dir *cdir; /* config dir */
747 afs_int32 vfs1_type = -1;
749 struct sched_param sp;
752 #ifdef AFS_SGI_VNODE_GLUE
753 if (afs_init_kernel_config(-1) <0) {
754 printf("Can't determine NUMA configuration, not starting AFS.\n");
759 /* call atoi on the appropriate parsed results */
760 if (as->parms[0].items) {
762 cacheBlocks = atoi(as->parms[0].items->data);
765 if (as->parms[1].items) {
767 cacheFiles = atoi(as->parms[1].items->data);
768 filesSet = 1; /* set when spec'd on cmd line */
770 if (as->parms[2].items) {
772 strcpy(rootVolume, as->parms[2].items->data);
775 if (as->parms[3].items) {
777 cacheStatEntries = atoi(as->parms[3].items->data);
779 if (as->parms[4].items) {
781 cacheBaseDir[0] = '\0';
783 cacheFlags |= AFSCALL_INIT_MEMCACHE;
787 if (as->parms[5].items) {
789 strcpy(cacheBaseDir, as->parms[5].items->data);
792 if (as->parms[6].items) {
794 strcpy(cacheMountDir, as->parms[6].items->data);
795 sawCacheMountDir = 1;
797 if (as->parms[7].items) {
799 nDaemons = atoi(as->parms[7].items->data);
801 if (as->parms[8].items) {
803 cacheSetTime = FALSE;
805 if (as->parms[9].items) {
809 if (as->parms[10].items) {
813 if (as->parms[11].items) {
818 if (as->parms[12].items) {
820 chunkSize = atoi(as->parms[12].items->data);
821 if (chunkSize < 0 || chunkSize > 30) {
822 printf("afsd:invalid chunk size spec'd, using default\n");
826 if (as->parms[13].items) {
828 dCacheSize = atoi(as->parms[13].items->data);
831 if (as->parms[14].items) {
833 vCacheSize = atoi(as->parms[14].items->data);
835 if (as->parms[15].items) {
837 #ifndef AFS_AIX32_ENV
838 printf("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
840 nBiods = atoi(as->parms[15].items->data);
844 if (as->parms[16].items) {
846 preallocs = atoi(as->parms[16].items->data);
849 if (as->parms[17].items) {
851 inodes = atoi(as->parms[17].items->data);
854 strcpy(confDir, AFSDIR_CLIENT_ETC_DIRPATH);
855 if (as->parms[17].items) {
857 strcpy(confDir, as->parms[17].items->data);
859 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
860 sprintf(fullpn_AFSLogFile, "%s/%s", confDir, AFSLOGFILE);
861 if (as->parms[18].items) {
863 strcpy(fullpn_AFSLogFile, as->parms[18].items->data);
865 if (as->parms[19].items) {
869 if (as->parms[20].items) {
873 * Cold shutdown is the default
875 printf("afsd: Shutting down all afs processes and afs state\n");
876 call_syscall(AFSOP_SHUTDOWN, 1);
879 if (as->parms[21].items) {
880 /* -enable_peer_stats */
881 enable_peer_stats = 1;
883 if (as->parms[22].items) {
884 /* -enable_process_stats */
885 enable_process_stats = 1;
887 if (as->parms[23].items) {
888 /* -mem_alloc_sleep */
889 cacheFlags |= AFSCALL_INIT_MEMCACHE_SLEEP;
893 * Pull out all the configuration info for the workstation's AFS cache and
894 * the cellular community we're willing to let our users see.
896 cdir = afsconf_Open(confDir);
898 printf("afsd: some file missing or bad in %s\n", confDir);
902 lookupResult = afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
904 printf("%s: Can't get my home cell name! [Error is %d]\n",
909 printf("%s: My home cell is '%s'\n",
913 /* parse cacheinfo file if this is a diskcache */
914 if (ParseCacheInfoFile()) {
918 if ((logfd = fopen(fullpn_AFSLogFile,"r+")) == 0) {
919 if (afsd_verbose) printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile);
920 if (CreateCacheFile(fullpn_AFSLogFile)) {
921 printf("%s: Can't create '%s' (You may want to use the -logfile option)\n", rn, fullpn_AFSLogFile);
927 /* do some random computations in memcache case to get things to work
928 * reasonably no matter which parameters you set.
930 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
931 /* memory cache: size described either as blocks or dcache entries, but
935 if (sawCacheBlocks) {
936 printf("%s: can't set cache blocks and dcache size simultaneously when diskless.\n", rn);
939 /* compute the cache size based on # of chunks times the chunk size */
940 i = (chunkSize == 0? 13 : chunkSize);
941 i = (1<<i); /* bytes per chunk */
942 cacheBlocks = i * dCacheSize;
943 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
946 /* compute the dcache size from overall cache size and chunk size */
947 i = (chunkSize == 0? 13 : chunkSize);
948 /* dCacheSize = (cacheBlocks << 10) / (1<<i); */
950 dCacheSize = (cacheBlocks >> (i-10));
952 dCacheSize = (cacheBlocks << (10-i));
954 dCacheSize = cacheBlocks;
956 /* don't have to set sawDCacheSize here since it isn't overwritten
957 * by ParseCacheInfoFile.
960 /* kernel computes # of dcache entries as min of cacheFiles and dCacheSize,
961 * so we now make them equal.
963 cacheFiles = dCacheSize;
967 * Compute the number of cache files based on cache size,
968 * but only if -files isn't given on the command line.
969 * Don't let # files be so small as to prevent full utilization
970 * of the cache unless user has explicitly asked for it.
971 * average V-file is ~10K, according to tentative empirical studies.
974 cacheFiles = cacheBlocks / 10;
975 if (cacheFiles < 100) cacheFiles = 100;
976 /* Always allow more files than chunks. Presume average V-file
977 * is ~67% of a chunk... (another guess, perhaps Honeyman will
978 * have a grad student write a paper). i is KILOBYTES.
980 i = 1 << (chunkSize == 0? 6 : (chunkSize<10 ? 0 : chunkSize -10));
981 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
982 /* never permit more files than blocks, while leaving space for
983 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
984 * CacheItems is 50 Bytes / file (== 1K/20)
987 #define CACHEITMSZ (cacheFiles / 20)
989 cacheFiles= min(cacheFiles,(cacheBlocks -VOLINFOSZ -CACHEITMSZ)/4);
991 cacheFiles = min(cacheFiles, cacheBlocks - VOLINFOSZ - CACHEITMSZ);
993 if (cacheFiles < 100)
994 fprintf (stderr, "%s: WARNING: cache probably too small!\n", rn);
996 if (!sawDCacheSize) {
997 if ((cacheFiles / 2) > dCacheSize)
998 dCacheSize = cacheFiles / 2;
999 if (dCacheSize > 2000)
1005 * Create and zero the inode table for the desired cache files.
1007 inode_for_V = (AFSD_INO_T *) malloc(cacheFiles * sizeof(AFSD_INO_T));
1008 if (inode_for_V == (AFSD_INO_T *)0) {
1009 printf("%s: malloc() failed for cache file inode table with %d entries.\n",
1013 memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
1015 printf("%s: %d inode_for_V entries at 0x%x, %d bytes\n",
1016 rn, cacheFiles, inode_for_V,
1017 (cacheFiles * sizeof(AFSD_INO_T)));
1020 * Set up all the pathnames we'll need for later.
1022 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
1023 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
1024 sprintf(fullpn_VFile, "%s/V", cacheBaseDir);
1025 vFileNumber = fullpn_VFile + strlen(fullpn_VFile);
1027 fputs(AFS_GOVERNMENT_MESSAGE, stdout);
1031 * Set up all the kernel processes needed for AFS.
1034 setpgrp(getpid(), 0);
1037 /* Initialize RX daemons and services */
1039 /* initialize the rx random number generator from user space */
1041 /* parse multihomed address files */
1042 afs_int32 addrbuf[MAXIPADDRS],maskbuf[MAXIPADDRS],mtubuf[MAXIPADDRS];
1044 code=parseNetFiles(addrbuf,maskbuf,mtubuf,MAXIPADDRS,reason,
1045 AFSDIR_CLIENT_NETINFO_FILEPATH,
1046 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
1048 call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
1050 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",reason);
1053 /* Set realtime priority for most threads to same as for biod's. */
1056 #ifdef AFS_SGI53_ENV
1057 #ifdef AFS_SGI61_ENV
1059 #else /* AFS_SGI61_ENV */
1060 code = get_nfsstaticaddr();
1062 call_syscall(AFSOP_NFSSTATICADDR, code);
1063 #endif /* AFS_SGI61_ENV */
1064 #endif /* AFS_SGI_53_ENV */
1066 /* Start listener, then callback listener. Lastly, start rx event daemon.
1067 * Change in ordering is so that Linux port has socket fd in listener
1069 * preallocs are passed for both listener and callback server. Only
1070 * the one which actually does the initialization uses them though.
1072 if (preallocs < cacheStatEntries+50)
1073 preallocs = cacheStatEntries+50;
1074 #ifdef RXK_LISTENER_ENV
1076 printf("%s: Forking rx listener daemon.\n", rn);
1080 SET_RX_RTPRI(); /* max advised for non-interrupts */
1081 call_syscall(AFSOP_RXLISTENER_DAEMON,
1084 enable_process_stats);
1089 printf("%s: Forking rx callback listener.\n", rn);
1093 call_syscall(AFSOP_START_RXCALLBACK, preallocs);
1096 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV)
1098 printf("%s: Forking rxevent daemon.\n", rn);
1102 SET_RX_RTPRI(); /* max advised for non-interrupts */
1103 call_syscall(AFSOP_RXEVENT_DAEMON);
1108 /* Initialize AFS daemon threads. */
1110 printf("%s: Forking AFS daemon.\n", rn);
1114 call_syscall(AFSOP_START_AFS);
1119 printf("%s: Forking Check Server Daemon.\n", rn);
1123 code = call_syscall(AFSOP_START_CS);
1125 printf("%s: No check server daemon in client.\n", rn);
1130 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
1131 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
1132 /* Add one because for sgi we always "steal" the first daemon for a
1133 * different task if we only have a 4K stack.
1137 for (i=0;i<nDaemons;i++) {
1141 #ifdef AFS_AIX32_ENV
1142 call_syscall(AFSOP_START_BKG, 0);
1144 call_syscall(AFSOP_START_BKG);
1149 #ifdef AFS_AIX32_ENV
1151 nBiods = nDaemons * 2;
1154 for (i=0; i< nBiods;i++) {
1156 if (code == 0) { /* Child */
1157 call_syscall(AFSOP_START_BKG, nBiods);
1164 * Tell the kernel about each cell in the configuration.
1166 lookingForHomeCell = 1;
1168 afsconf_CellApply(cdir, ConfigCell, (char *) 0);
1171 * If we're still looking for the home cell after the whole cell configuration database
1172 * has been parsed, there's something wrong.
1174 if (lookingForHomeCell) {
1175 printf("%s: Can't find information for home cell '%s' in cell database!\n",
1180 * If the root volume has been explicitly set, tell the kernel.
1184 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n",
1186 call_syscall(AFSOP_ROOTVOLUME, rootVolume);
1190 * Tell the kernel some basic information about the workstation's cache.
1193 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",
1194 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
1196 memset(&cparams, '\0', sizeof(cparams));
1197 cparams.cacheScaches = cacheStatEntries;
1198 cparams.cacheFiles = cacheFiles;
1199 cparams.cacheBlocks = cacheBlocks;
1200 cparams.cacheDcaches = dCacheSize;
1201 cparams.cacheVolumes = vCacheSize;
1202 cparams.chunkSize = chunkSize;
1203 cparams.setTimeFlag = cacheSetTime;
1204 cparams.memCacheFlag = cacheFlags;
1206 cparams.inodes = inodes;
1208 call_syscall(AFSOP_CACHEINIT, &cparams);
1209 if (afsd_CloseSynch)
1210 call_syscall(AFSOP_CLOSEWAIT);
1213 * Sweep the workstation AFS cache directory, remembering the inodes of
1214 * valid files and deleting extraneous files. Keep sweeping until we
1215 * have the right number of data cache files or we've swept too many
1219 printf("%s: Sweeping workstation's AFS cache directory.\n",
1222 /* Memory-cache based system doesn't need any of this */
1223 if(!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
1226 if (SweepAFSCache(&vFilesFound)) {
1227 printf("%s: Error on sweep %d of workstation AFS cache \
1228 directory.\n", rn, cacheIteration);
1232 printf("%s: %d out of %d data cache files found in sweep %d.\n",
1233 rn, vFilesFound, cacheFiles, cacheIteration);
1234 } while ((vFilesFound < cacheFiles) &&
1235 (cacheIteration < MAX_CACHE_LOOPS));
1236 } else if(afsd_verbose)
1237 printf("%s: Using memory cache, not swept\n", rn);
1240 * Pass the kernel the name of the workstation cache file holding the
1244 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n",
1245 rn, fullpn_DCacheFile);
1246 /* once again, meaningless for a memory-based cache. */
1247 if(!(cacheFlags & AFSCALL_INIT_MEMCACHE))
1248 call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
1251 * Pass the kernel the name of the workstation cache file holding the
1252 * volume information.
1255 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n",
1256 rn, fullpn_VolInfoFile);
1257 call_syscall(AFSOP_VOLUMEINFO,fullpn_VolInfoFile);
1260 * Pass the kernel the name of the afs logging file holding the volume
1264 printf("%s: Calling AFSOP_AFSLOG: volume info file is '%s'\n",
1265 rn, fullpn_AFSLogFile);
1266 #if defined(AFS_SGI_ENV)
1267 /* permit explicit -logfile argument to enable logging on memcache systems */
1268 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE) || as->parms[18].items)
1270 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... nor this ... */
1272 call_syscall(AFSOP_AFSLOG,fullpn_AFSLogFile);
1275 * Give the kernel the names of the AFS files cached on the workstation's
1279 printf("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
1280 rn, cacheFiles, cacheBaseDir);
1281 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
1282 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
1283 #ifdef AFS_SGI62_ENV
1284 call_syscall(AFSOP_CACHEINODE,
1285 (afs_uint32)(inode_for_V[currVFile]>>32),
1286 (afs_uint32)(inode_for_V[currVFile] & 0xffffffff));
1288 call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
1294 * All the necessary info has been passed into the kernel to run an AFS
1295 * system. Give the kernel our go-ahead.
1298 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n",
1300 call_syscall(AFSOP_GO, cacheSetTime);
1303 * At this point, we have finished passing the kernel all the info
1304 * it needs to set up the AFS. Mount the AFS root.
1306 printf("%s: All AFS daemons started.\n", rn);
1309 printf("%s: Forking trunc-cache daemon.\n", rn);
1313 call_syscall(AFSOP_START_TRUNCDAEMON);
1317 mountFlags = 0; /* Read/write file system, can do setuid() */
1318 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
1320 mountFlags |= MS_DATA;
1322 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... */
1326 #if defined(AFS_HPUX100_ENV)
1327 mountFlags |= MS_DATA;
1331 printf("%s: Mounting the AFS root on '%s', flags: %d.\n",
1332 rn, cacheMountDir, mountFlags);
1334 if ((mount("AFS",cacheMountDir,mountFlags,GT_AFS,(caddr_t) 0)) < 0) {
1337 if ((fsmount(MOUNT_AFS,cacheMountDir,mountFlags,(caddr_t) 0)) < 0) {
1342 #if defined(AFS_HPUX100_ENV)
1343 if ((mount("",cacheMountDir,mountFlags,"afs", (char *)0, 0)) < 0) {
1346 #if defined(AFS_HPUX90_ENV)
1351 strcpy(buffer, "afs");
1352 code = vfsmount(-1,cacheMountDir,mountFlags,(caddr_t) buffer);
1353 sscanf(buffer, "%d", &vfs1_type);
1355 printf("Can't find 'afs' type in the registered filesystem table!\n");
1358 sscanf(buffer, "%d", &vfs1_type);
1360 printf("AFS vfs slot number is %d\n", vfs1_type);
1362 if ((vfsmount(vfs1_type,cacheMountDir,mountFlags,(caddr_t) 0)) < 0) {
1364 if (call_syscall(AFSOP_AFS_VFSMOUNT, MOUNT_AFS, cacheMountDir,
1365 mountFlags, (caddr_t)NULL) < 0) {
1369 if ((mount("",cacheMountDir,mountFlags,"afs", (char *)0, 0)) < 0) {
1371 #if defined(AFS_SGI_ENV)
1372 mountFlags = MS_FSS;
1374 if ((mount(MOUNT_AFS,cacheMountDir,mountFlags,(caddr_t) MOUNT_AFS)) < 0) {
1376 #ifdef AFS_LINUX20_ENV
1377 if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL))<0) {
1379 /* This is the standard mount used by the suns and rts */
1380 if ((mount(MOUNT_AFS,cacheMountDir,mountFlags,(caddr_t) 0)) < 0) {
1381 #endif /* AFS_LINUX20_ENV */
1382 #endif /* AFS_SGI_ENV */
1383 #endif /* AFS_SUN5_ENV */
1384 #endif /* AFS_HPUX100_ENV */
1385 #endif /* AFS_HPUX_ENV */
1386 #endif /* AFS_AIX_ENV */
1387 #endif /* AFS_AUX_ENV */
1388 #endif /* AFS_DEC_ENV */
1389 printf("%s: Can't mount AFS on %s(%d)\n",
1390 rn, cacheMountDir, errno);
1398 printf("%s: Forking 'rmtsys' daemon.\n", rn);
1407 * Exit successfully.
1412 #include "AFS_component_version_number.c"
1419 register struct cmd_syndesc *ts;
1421 ts = cmd_CreateSyntax((char *) 0, mainproc, (char *) 0, "start AFS");
1422 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "1024 byte blocks in cache");
1423 cmd_AddParm(ts, "-files", CMD_SINGLE, CMD_OPTIONAL, "files in cache");
1424 cmd_AddParm(ts, "-rootvol", CMD_SINGLE, CMD_OPTIONAL, "name of AFS root volume");
1425 cmd_AddParm(ts, "-stat", CMD_SINGLE, CMD_OPTIONAL, "number of stat entries");
1426 cmd_AddParm(ts, "-memcache", CMD_FLAG, CMD_OPTIONAL, "run diskless");
1427 cmd_AddParm(ts, "-cachedir", CMD_SINGLE, CMD_OPTIONAL, "cache directory");
1428 cmd_AddParm(ts, "-mountdir", CMD_SINGLE, CMD_OPTIONAL, "mount location");
1429 cmd_AddParm(ts, "-daemons", CMD_SINGLE, CMD_OPTIONAL, "number of daemons to use");
1430 cmd_AddParm(ts, "-nosettime", CMD_FLAG, CMD_OPTIONAL, "don't set the time");
1431 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "display lots of information");
1432 cmd_AddParm(ts, "-rmtsys", CMD_FLAG, CMD_OPTIONAL, "start NFS rmtsysd program");
1433 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "display debug info");
1434 cmd_AddParm(ts, "-chunksize", CMD_SINGLE, CMD_OPTIONAL, "log(2) of chunk size");
1435 cmd_AddParm(ts, "-dcache", CMD_SINGLE, CMD_OPTIONAL, "number of dcache entries");
1436 cmd_AddParm(ts, "-volumes", CMD_SINGLE, CMD_OPTIONAL, "number of volume entries");
1437 cmd_AddParm(ts, "-biods", CMD_SINGLE, CMD_OPTIONAL, "number of bkg I/O daemons (aix vm)");
1439 cmd_AddParm(ts, "-prealloc", CMD_SINGLE, CMD_OPTIONAL, "number of 'small' preallocated blocks");
1441 cmd_AddParm(ts, "-pininodes", CMD_SINGLE, CMD_OPTIONAL, "number of inodes to hog");
1443 cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL, "configuration directory");
1444 cmd_AddParm(ts, "-logfile", CMD_SINGLE, CMD_OPTIONAL, "Place to keep the CM log");
1445 cmd_AddParm(ts, "-waitclose", CMD_FLAG, CMD_OPTIONAL, "make close calls synchronous");
1446 cmd_AddParm(ts, "-shutdown", CMD_FLAG, CMD_OPTIONAL, "Shutdown all afs state");
1447 cmd_AddParm(ts, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL|CMD_HIDE, "Collect rpc statistics by peer");
1448 cmd_AddParm(ts, "-enable_process_stats", CMD_FLAG, CMD_OPTIONAL|CMD_HIDE, "Collect rpc statistics for this process");
1449 cmd_AddParm(ts, "-mem_alloc_sleep", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE), "Allow sleeps when allocating memory cache");
1450 return (cmd_Dispatch(argc, argv));
1455 #define MOUNTED_TABLE MNT_MNTTAB
1458 #define MOUNTED_TABLE MNTTAB
1460 #define MOUNTED_TABLE MOUNTED
1464 static int HandleMTab() {
1465 #if defined (AFS_SUN_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
1469 struct mnttab tmntent;
1471 memset(&tmntent, '\0', sizeof(struct mnttab));
1472 if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) {
1473 printf("Can't open %s\n", MOUNTED_TABLE);
1477 tmntent.mnt_special = "AFS";
1478 tmntent.mnt_mountp = cacheMountDir;
1479 tmntent.mnt_fstype = "xx";
1480 tmntent.mnt_mntopts = "rw";
1481 sprintf(tbuf, "%ld", (long)time((time_t *)0));
1482 tmntent.mnt_time = tbuf;
1483 putmntent(tfilep, &tmntent);
1486 #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
1487 struct mntent tmntent;
1489 tfilep = setmntent("/etc/mtab", "a+");
1490 tmntent.mnt_fsname = "AFS";
1491 tmntent.mnt_dir = cacheMountDir;
1492 tmntent.mnt_type = "afs";
1493 tmntent.mnt_opts = "rw";
1494 tmntent.mnt_freq = 1;
1495 tmntent.mnt_passno = 3;
1496 addmntent(tfilep, &tmntent);
1499 struct mntent tmntent;
1501 memset(&tmntent, '\0', sizeof(struct mntent));
1502 tfilep = setmntent(MOUNTED_TABLE, "a+");
1504 printf("Can't open %s for write; Not adding afs entry to it\n",
1508 tmntent.mnt_fsname = "AFS";
1509 tmntent.mnt_dir = cacheMountDir;
1510 tmntent.mnt_type = "xx";
1511 tmntent.mnt_opts = "rw";
1512 tmntent.mnt_freq = 1;
1513 tmntent.mnt_passno = 3;
1515 tmntent.mnt_time = time(0);
1516 tmntent.mnt_cnode = 0;
1518 addmntent(tfilep, &tmntent);
1520 #endif /* AFS_SGI_ENV */
1521 #endif /* AFS_SUN5_ENV */
1522 #endif /* unreasonable systems */
1526 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
1527 call_syscall(param1, param2, param3, param4, param5, param6, param7)
1528 long param1, param2, param3, param4, param5, param6, param7;
1532 error = syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4, param5, param6, param7);
1533 if (afsd_verbose) printf("SScall(%d, %d)=%d ", AFS_SYSCALL, AFSCALL_CALL, error);
1536 #else /* AFS_AIX32_ENV */
1537 #if defined(AFS_SGI_ENV)
1538 call_syscall(call, parm0, parm1, parm2, parm3, parm4)
1543 error = afs_syscall(call, parm0, parm1, parm2, parm3, parm4);
1544 if (afsd_verbose) printf("SScall(%d, %d)=%d ", call, parm0, error);
1549 call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6) {
1551 return syscall(AFSCALL_CALL, call, parm0, parm1, parm2, parm3, parm4, parm5, parm6);
1553 #endif /* AFS_SGI_ENV */
1554 #endif /* AFS_AIX32_ENV */
1558 /* Special handling for AIX's afs mount operation since they require much more miscl. information before making the vmount(2) syscall */
1559 #include <sys/vfs.h>
1561 #define ROUNDUP(x) (((x) + 3) & ~3)
1564 struct vmount *vmountp;
1567 size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir)+1) + 5*4;
1568 /* Malloc the vmount structure */
1569 if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) {
1570 printf("Can't allocate space for the vmount structure (AIX)\n");
1574 /* zero out the vmount structure */
1575 memset(vmountp, '\0', size);
1577 /* transfer info into the vmount structure */
1578 vmountp->vmt_revision = VMT_REVISION;
1579 vmountp->vmt_length = size;
1580 vmountp->vmt_fsid.fsid_dev = 0;
1581 vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS;
1582 vmountp->vmt_vfsnumber = 0;
1583 vmountp->vmt_time = 0;/* We'll put the time soon! */
1584 vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */
1585 vmountp->vmt_gfstype = AFS_MOUNT_AFS;
1586 vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw");
1588 /* Do the actual mount system call */
1589 error = vmount(vmountp, size);
1594 vmountdata(vmtp, obj, stub, host, hostsname, info, args)
1595 struct vmount *vmtp;
1596 char *obj, *stub, *host, *hostsname, *info, *args;
1598 register struct data {
1604 vdp = (struct data *)vmtp->vmt_data;
1605 vdp->vmt_off = sizeof(struct vmount);
1606 size = ROUNDUP(strlen(obj) + 1);
1607 vdp->vmt_size = size;
1608 strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj);
1612 vdp->vmt_off = vdprev->vmt_off + size;
1613 size = ROUNDUP(strlen(stub) + 1);
1614 vdp->vmt_size = size;
1615 strcpy(vmt2dataptr(vmtp, VMT_STUB), stub);
1619 vdp->vmt_off = vdprev->vmt_off + size;
1620 size = ROUNDUP(strlen(host) + 1);
1621 vdp->vmt_size = size;
1622 strcpy(vmt2dataptr(vmtp, VMT_HOST), host);
1626 vdp->vmt_off = vdprev->vmt_off + size;
1627 size = ROUNDUP(strlen(hostsname) + 1);
1628 vdp->vmt_size = size;
1629 strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname);
1634 vdp->vmt_off = vdprev->vmt_off + size;
1635 size = ROUNDUP(strlen(info) + 1);
1636 vdp->vmt_size = size;
1637 strcpy(vmt2dataptr(vmtp, VMT_INFO), info);
1641 vdp->vmt_off = vdprev->vmt_off + size;
1642 size = ROUNDUP(strlen(args) + 1);
1643 vdp->vmt_size = size;
1644 strcpy(vmt2dataptr(vmtp, VMT_ARGS), args);
1646 #endif /* AFS_AIX_ENV */
1648 #ifdef AFS_SGI53_ENV
1649 #ifdef AFS_SGI61_ENV
1650 /* The dwarf structures are searched to find entry points of static functions
1651 * and the addresses of static variables. The file name as well as the
1652 * sybmol name is reaquired.
1655 /* Contains list of names to find in given file. */
1657 char *name; /* Name of variable or function. */
1658 afs_hyper_t addr; /* Address of function, undefined if not found. */
1659 Dwarf_Half type; /* DW_AT_location for vars, DW_AT_lowpc for func's */
1660 char found; /* set if found. */
1664 char *file; /* Name of file containing vars or funcs */
1665 staticAddrList *addrList; /* List of vars and/or funcs. */
1666 int nAddrs; /* # of addrList's */
1667 int found; /* set if we've found this file already. */
1670 /* routines used to find addresses in /unix */
1671 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1672 void findMDebugStaticAddresses(staticNameList *, int, int);
1674 void findDwarfStaticAddresses(staticNameList *, int);
1675 void findElfAddresses(Dwarf_Debug, Dwarf_Die, staticNameList *);
1676 void getElfAddress(Dwarf_Debug, Dwarf_Die, staticAddrList *);
1678 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1679 #define AFS_N_FILELISTS 2
1680 #define AFS_SYMS_NEEDED 3
1681 #else /* AFS_SGI62_ENV */
1682 #define AFS_N_FILELISTS 1
1683 #endif /* AFS_SGI62_ENV */
1687 void set_staticaddrs(void)
1689 staticNameList fileList[AFS_N_FILELISTS];
1691 fileList[0].addrList = (staticAddrList*)calloc(1, sizeof(staticAddrList));
1692 if (!fileList[0].addrList) {
1693 printf("set_staticaddrs: Can't calloc fileList[0].addrList\n");
1696 fileList[0].file = "nfs_server.c";
1697 fileList[0].found = 0;
1698 fileList[0].nAddrs = 1;
1699 fileList[0].addrList[0].name = "rfsdisptab_v2";
1700 fileList[0].addrList[0].type = DW_AT_location;
1701 fileList[0].addrList[0].found = 0;
1703 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1704 fileList[1].addrList = (staticAddrList*)calloc(2, sizeof(staticAddrList));
1705 if (!fileList[1].addrList) {
1706 printf("set_staticaddrs: Can't malloc fileList[1].addrList\n");
1709 fileList[1].file = "uipc_socket.c";
1710 fileList[1].found = 0;
1711 fileList[1].nAddrs = 2;
1712 fileList[1].addrList[0].name = "sblock";
1713 fileList[1].addrList[0].type = DW_AT_low_pc;
1714 fileList[1].addrList[0].found = 0;
1715 fileList[1].addrList[1].name = "sbunlock";
1716 fileList[1].addrList[1].type = DW_AT_low_pc;
1717 fileList[1].addrList[1].found = 0;
1719 if (64 != sysconf(_SC_KERN_POINTERS))
1720 findMDebugStaticAddresses(fileList, AFS_N_FILELISTS, AFS_SYMS_NEEDED);
1722 #endif /* AFS_SGI62_ENV */
1723 findDwarfStaticAddresses(fileList, AFS_N_FILELISTS);
1725 if (fileList[0].addrList[0].found) {
1726 call_syscall(AFSOP_NFSSTATICADDR2, fileList[0].addrList[0].addr.high,
1727 fileList[0].addrList[0].addr.low);
1731 printf("NFS V2 is not present in the kernel.\n");
1733 free(fileList[0].addrList);
1734 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1735 if (fileList[1].addrList[0].found && fileList[1].addrList[1].found) {
1736 call_syscall(AFSOP_SBLOCKSTATICADDR2,
1737 fileList[1].addrList[0].addr.high,
1738 fileList[1].addrList[0].addr.low,
1739 fileList[1].addrList[1].addr.high,
1740 fileList[1].addrList[1].addr.low);
1743 if (!fileList[1].addrList[0].found)
1744 printf("Can't find %s in kernel. Exiting.\n",
1745 fileList[1].addrList[0].name);
1746 if (!fileList[1].addrList[0].found)
1747 printf("Can't find %s in kernel. Exiting.\n",
1748 fileList[1].addrList[1].name);
1751 free(fileList[1].addrList);
1752 #endif /* AFS_SGI62_ENV */
1756 /* Find addresses for static variables and functions. */
1758 findDwarfStaticAddresses(staticNameList * nameList, int nLists)
1765 char *hname = (char*)0;
1766 Dwarf_Unsigned dwarf_access = O_RDONLY;
1767 Dwarf_Debug dwarf_debug;
1768 Dwarf_Error dwarf_error;
1769 Dwarf_Unsigned dwarf_cu_header_length;
1770 Dwarf_Unsigned dwarf_abbrev_offset;
1771 Dwarf_Half dwarf_address_size;
1772 Dwarf_Unsigned next_cu_header;
1773 Dwarf_Die dwarf_die;
1774 Dwarf_Die dwarf_next_die;
1775 Dwarf_Die dwarf_child_die;
1777 if (elf_version(EV_CURRENT) == EV_NONE) {
1778 printf("findDwarfStaticAddresses: Bad elf version.\n");
1782 if ((fd=open("/unix", O_RDONLY,0))<0) {
1783 printf("findDwarfStaticAddresses: Failed to open /unix.\n");
1786 code = dwarf_init(fd, dwarf_access, NULL, NULL, &dwarf_debug,
1788 if (code != DW_DLV_OK) {
1789 /* Nope hope for the elves and dwarves, try intermediate code. */
1796 /* Run through the headers until we find ones for files we've
1797 * specified in nameList.
1799 code = dwarf_next_cu_header(dwarf_debug,
1800 &dwarf_cu_header_length, NULL,
1801 &dwarf_abbrev_offset,
1802 &dwarf_address_size,
1805 if (code == DW_DLV_NO_ENTRY) {
1808 else if (code == DW_DLV_ERROR) {
1809 printf("findDwarfStaticAddresses: Error reading headers: %s\n",
1810 dwarf_errmsg(dwarf_error));
1814 code = dwarf_siblingof(dwarf_debug, NULL, &dwarf_die, &dwarf_error);
1815 if (code != DW_DLV_OK) {
1816 printf("findDwarfStaticAddresses: Can't get first die. %s\n",
1817 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
1821 /* This is the header, test the name. */
1822 code = dwarf_diename(dwarf_die, &hname, &dwarf_error);
1823 if (code == DW_DLV_OK) {
1824 s = strrchr(hname, '/');
1825 for (i=0; i<nLists; i++) {
1826 if (s && !strcmp(s+1, nameList[i].file)) {
1827 findElfAddresses(dwarf_debug, dwarf_die, &nameList[i]);
1834 printf("findDwarfStaticAddresses: Can't get name of current header. %s\n",
1835 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
1838 dwarf_dealloc(dwarf_debug, hname, DW_DLA_STRING);
1840 if (found >= nLists) { /* we're done */
1845 /* Frees up all allocated space. */
1846 (void) dwarf_finish(dwarf_debug, &dwarf_error);
1851 findElfAddresses(Dwarf_Debug dwarf_debug, Dwarf_Die dwarf_die,
1852 staticNameList * nameList)
1855 Dwarf_Error dwarf_error;
1856 Dwarf_Die dwarf_next_die;
1857 Dwarf_Die dwarf_child_die;
1858 Dwarf_Attribute dwarf_return_attr;
1859 char *vname = (char*)0;
1863 /* Drop into this die to find names in addrList. */
1864 code = dwarf_child(dwarf_die, &dwarf_child_die, &dwarf_error);
1865 if (code != DW_DLV_OK) {
1866 printf("findElfAddresses: Can't get child die. %s\n",
1867 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
1871 /* Try to find names in each sibling. */
1872 dwarf_next_die = (Dwarf_Die)0;
1874 code = dwarf_diename(dwarf_child_die, &vname,
1876 /* It's possible that some siblings don't have names. */
1877 if (code == DW_DLV_OK) {
1878 for (i=0; i<nameList->nAddrs; i++) {
1879 if (!nameList->addrList[i].found) {
1880 if (!strcmp(vname, nameList->addrList[i].name)) {
1881 getElfAddress(dwarf_debug, dwarf_child_die,
1882 &(nameList->addrList[i]));
1890 dwarf_dealloc(dwarf_debug, dwarf_next_die, DW_DLA_DIE);
1892 if (found >= nameList->nAddrs) { /* we're done. */
1896 dwarf_next_die = dwarf_child_die;
1897 code = dwarf_siblingof(dwarf_debug, dwarf_next_die,
1901 } while(code == DW_DLV_OK);
1904 /* Get address out of current die. */
1906 getElfAddress(Dwarf_Debug dwarf_debug,
1907 Dwarf_Die dwarf_child_die, staticAddrList *addrList)
1910 Dwarf_Error dwarf_error;
1911 Dwarf_Attribute dwarf_return_attr;
1912 Dwarf_Bool dwarf_return_bool;
1913 Dwarf_Locdesc *llbuf = NULL;
1914 Dwarf_Signed listlen;
1915 off64_t addr = (off64_t)0;
1918 code = dwarf_hasattr(dwarf_child_die, addrList->type,
1919 &dwarf_return_bool, &dwarf_error);
1920 if ((code != DW_DLV_OK) || (!dwarf_return_bool)) {
1921 printf("getElfAddress: no address given for %s. %s\n",
1922 addrList->name, (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
1925 code = dwarf_attr(dwarf_child_die, addrList->type,
1926 &dwarf_return_attr, &dwarf_error);
1927 if (code != DW_DLV_OK) {
1928 printf("getElfAddress: Can't get attribute. %s\n",
1929 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
1933 switch (addrList->type) {
1934 case DW_AT_location:
1935 code = dwarf_loclist(dwarf_return_attr, &llbuf,
1936 &listlen, &dwarf_error);
1937 if (code != DW_DLV_OK) {
1938 printf("getElfAddress: Can't get location for %s. %s\n",
1940 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
1943 if ((listlen != 1) || (llbuf[0].ld_cents != 1)) {
1944 printf("getElfAddress: %s has more than one address.\n",
1948 addr = llbuf[0].ld_s[0].lr_number;
1952 code = dwarf_lowpc(dwarf_child_die, (Dwarf_Addr*)&addr, &dwarf_error);
1953 if ( code != DW_DLV_OK) {
1954 printf("getElfAddress: Can't get lowpc for %s. %s\n",
1956 (code == DW_DLV_ERROR) ? dwarf_errmsg(dwarf_error) : "");
1962 printf("getElfAddress: Bad case %d in switch.\n", addrList->type);
1966 addrList->addr.high = (addr>>32) & 0xffffffff;
1967 addrList->addr.low = addr & 0xffffffff;
1968 addrList->found = 1;
1971 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
1972 /* Find symbols in the .mdebug section for 32 bit kernels. */
1975 * On 32bit platforms, we're still using the ucode compilers to build
1976 * the kernel, so we need to get our static text/data from the .mdebug
1977 * section instead of the .dwarf sections.
1979 /* SearchNameList searches our bizarre structs for the given string.
1980 * If found, sets the found bit and the address and returns 1.
1981 * Not found returns 0.
1983 int SearchNameList(char *name, afs_uint32 addr, staticNameList *nameList,
1987 for (i=0; i<nLists; i++) {
1988 for (j=0; j<nameList[i].nAddrs; j++) {
1989 if (nameList[i].addrList[j].found)
1991 if (!strcmp(name, nameList[i].addrList[j].name)) {
1992 nameList[i].addrList[j].addr.high = 0;
1993 nameList[i].addrList[j].addr.low = addr;
1994 nameList[i].addrList[j].found = 1;
2003 SearchMDebug(Elf_Scn *scnp, Elf32_Shdr *shdrp, staticNameList * nameList,
2004 int nLists, int needed)
2006 long *buf = (long *)(elf_getdata(scnp, NULL)->d_buf);
2007 u_long addr, mdoff = shdrp->sh_offset;
2009 SYMR *symbase, *symp, *symend;
2010 FDR *fdrbase, *fdrp;
2012 char *strbase, *str;
2017 addr = (__psunsigned_t)buf;
2018 hdrp = (HDRR *)addr;
2020 /* setup base addresses */
2021 addr = (u_long)buf + (u_long)(hdrp->cbFdOffset - mdoff);
2022 fdrbase = (FDR *)addr;
2023 addr = (u_long)buf + (u_long)(hdrp->cbSymOffset - mdoff);
2024 symbase = (SYMR *)addr;
2025 addr = (u_long)buf + (u_long)(hdrp->cbSsOffset - mdoff);
2026 strbase = (char *)addr;
2028 #define KEEPER(a,b) ((a == stStaticProc && b == scText) || \
2029 (a == stStatic && (b == scData || b == scBss || \
2030 b == scSBss || b == scSData)))
2032 for (fdrp = fdrbase; fdrp < &fdrbase[hdrp->ifdMax]; fdrp++) {
2033 str = strbase + fdrp->issBase + fdrp->rss;
2035 /* local symbols for each fd */
2036 for (symp = &symbase[fdrp->isymBase];
2037 symp < &symbase[fdrp->isymBase+fdrp->csym];
2039 if (KEEPER(symp->st, symp->sc)) {
2040 if (symp->value == 0)
2043 str = strbase + fdrp->issBase + symp->iss;
2044 /* Look for AFS symbols of interest */
2045 if (SearchNameList(str, symp->value,
2046 nameList, nLists)) {
2048 if (nFound >= needed)
2057 * returns section with the name of scn_name, & puts its header in shdr64 or
2058 * shdr32 based on elf's file type
2062 findMDebugSection(Elf *elf, char *scn_name)
2066 Elf_Scn *scn = NULL;
2070 if ((ehdr32 = elf32_getehdr(elf)) == NULL)
2073 if ((scn = elf_nextscn(elf, scn)) == NULL)
2075 if ((shdr32 = elf32_getshdr(scn)) == NULL)
2077 } while (strcmp(scn_name, elf_strptr(elf, ehdr32->e_shstrndx,
2084 void findMDebugStaticAddresses(staticNameList * nameList, int nLists,
2089 Elf_Scn *mdebug_scn;
2090 Elf32_Shdr *mdebug_shdr;
2093 if ((fd = open("/unix", O_RDONLY)) == -1) {
2094 printf("findMDebugStaticAddresses: Failed to open /unix.\n");
2098 (void)elf_version(EV_CURRENT);
2099 if((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
2100 printf("findMDebugStaticAddresses: /unix doesn't seem to be an elf file\n");
2104 mdebug_scn = findMDebugSection(elf, ".mdebug");
2106 printf("findMDebugStaticAddresses: Can't find .mdebug section.\n");
2109 mdebug_shdr = elf32_getshdr(mdebug_scn);
2111 printf("findMDebugStaticAddresses: Can't find .mdebug header.\n");
2115 (void) SearchMDebug(mdebug_scn, mdebug_shdr, nameList, nLists, needed);
2121 #endif /* AFS_SGI62_ENV */
2123 #else /* AFS_SGI61_ENV */
2125 struct nlist nlunix[] = {
2126 { "rfsdisptab_v2" },
2130 get_nfsstaticaddr() {
2131 int i, j, kmem, count;
2133 if ((kmem = open("/dev/kmem", O_RDONLY)) < 0) {
2134 printf("Warning: can't open /dev/kmem\n");
2137 if ((j = nlist("/unix", nlunix)) < 0) {
2138 printf("Warning: can't nlist /unix\n");
2141 i = nlunix[0].n_value;
2142 if (lseek(kmem, i, L_SET/*0*/) != i) {
2143 printf("Warning: can't lseek to %x\n", i);
2146 if ((j = read(kmem, &count, sizeof count)) != sizeof count) {
2147 printf("WARNING: kmem read at %x failed\n", i);
2152 #endif /* AFS_SGI61_ENV */
2153 #endif /* AFS_SGI53_ENV */