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 (default).
33 * -settime Keep checking the time to avoid drift.
34 * -rxmaxmtu Set the max mtu to help with VPN issues.
36 * -disable-dynamic-vcaches Disable the use of -stat value as the starting size of
37 * the size of the vcache/stat cache pool,
38 * but increase that pool dynamically as needed.
39 * -debug Print out additional debugging info.
40 * -kerndev [OBSOLETE] The kernel device for AFS.
41 * -dontfork [OBSOLETE] Don't fork off as a new process.
42 * -daemons The number of background daemons to start (Default: 2).
43 * -rmtsys Also fires up an afs remote sys call (e.g. pioctl, setpag)
45 * -chunksize [n] 2^n is the chunksize to be used. 0 is default.
46 * -dcache The number of data cache entries.
47 * -biods Number of bkg I/O daemons (AIX3.1 only)
48 * -prealloc Number of preallocated "small" memory blocks
49 * -logfile [OBSOLETE] Place where to put the logfile (default in
51 * -waitclose make close calls always synchronous (slows em down, tho)
52 * -files_per_subdir [n] number of files per cache subdir. (def=2048)
53 * -shutdown Shutdown afs daemons
54 *---------------------------------------------------------------------------*/
56 #include <afsconfig.h>
57 #include <afs/param.h>
64 #include <afs/opr_assert.h>
70 #include <afs/afsutil.h>
75 /* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
77 #if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
85 #ifdef HAVE_SYS_FS_TYPES_H
86 #include <sys/fs_types.h>
89 #if defined(HAVE_SYS_MOUNT_H) && !defined(AFS_ARM_DARWIN_ENV)
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_VFS_H
113 #ifdef HAVE_SYS_FSTYP_H
114 #include <sys/fstyp.h>
119 #include <afs/afs_args.h>
120 #include <afs/cellconfig.h>
121 #include <afs/afssyscalls.h>
122 #include <afs/afsutil.h>
123 #include <afs/sys_prototypes.h>
125 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
127 #include <symconst.h>
133 #ifdef AFS_DARWIN_ENV
134 #ifdef AFS_DARWIN80_ENV
135 #include <sys/xattr.h>
137 #include <CoreFoundation/CoreFoundation.h>
139 #include <SystemConfiguration/SystemConfiguration.h>
140 #include <SystemConfiguration/SCDynamicStore.h>
142 #ifndef AFS_ARM_DARWIN_ENV
143 #include <IOKit/pwr_mgt/IOPMLib.h>
144 #include <IOKit/IOMessage.h>
146 static io_connect_t root_port;
147 static IONotificationPortRef notify;
148 static io_object_t iterator;
151 static CFRunLoopSourceRef source;
153 static int event_pid;
155 #endif /* AFS_DARWIN_ENV */
157 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
158 #include <sys/statvfs.h>
160 #if defined(AFS_SUN_ENV)
163 #ifdef HAVE_SYS_STATFS_H
164 #include <sys/statfs.h>
173 #define CACHEINFOFILE "cacheinfo"
174 #define DCACHEFILE "CacheItems"
175 #define VOLINFOFILE "VolumeItems"
176 #define CELLINFOFILE "CellItems"
178 #define MAXIPADDRS 1024
180 char LclCellName[64];
182 #define MAX_CACHE_LOOPS 4
186 * Internet address (old style... should be updated). This was pulled out of the old 4.2
187 * version of <netinet/in.h>, since it's still useful.
192 u_char s_b1, s_b2, s_b3, s_b4;
201 #define mPrintIPAddr(ipaddr) printf("[%d.%d.%d.%d] ", \
202 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b1, \
203 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b2, \
204 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b3, \
205 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b4)
208 * Global configuration variables.
210 static int enable_rxbind = 0;
211 static int afs_shutdown = 0;
212 static int cacheBlocks; /*Num blocks in the cache */
213 static int cacheFiles; /*Optimal # of files in workstation cache */
214 static int rwpct = 0;
215 static int ropct = 0;
216 static int cacheStatEntries; /*Number of stat cache entries */
217 static char *cacheBaseDir; /*Where the workstation AFS cache lives */
218 static char *confDir; /*Where the workstation AFS configuration lives */
219 static char fullpn_DCacheFile[1024]; /*Full pathname of DCACHEFILE */
220 static char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE */
221 static char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE */
222 static char fullpn_CacheInfo[1024]; /*Full pathname of CACHEINFO */
223 static char fullpn_VFile[1024]; /*Full pathname of data cache files */
224 static char *vFilePtr; /*Ptr to the number part of above pathname */
225 static int sawCacheMountDir = 0; /* from cmd line */
226 static int sawCacheBaseDir = 0;
227 static int sawCacheBlocks = 0;
228 static int sawDCacheSize = 0;
230 static int sawBiod = 0;
232 static int sawCacheStatEntries = 0;
233 char *afsd_cacheMountDir;
234 static char *rootVolume = NULL;
236 static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC; /*Create & truncate on open */
238 static int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open */
240 static int ownerRWmode = 0600; /*Read/write OK by owner */
241 static int filesSet = 0; /*True if number of files explicitly set */
242 static int nFilesPerDir = 2048; /* # files per cache dir */
243 #if defined(AFS_CACHE_BYPASS)
244 #define AFSD_NDAEMONS 4
246 #define AFSD_NDAEMONS 2
248 static int nDaemons = AFSD_NDAEMONS; /* Number of background daemons */
249 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
250 static int dCacheSize; /* # of dcache entries */
251 static int vCacheSize = 200; /* # of volume cache entries */
252 static int rootVolSet = 0; /*True if root volume name explicitly set */
253 int addrNum; /*Cell server address index being printed */
254 static int cacheFlags = 0; /*Flags to cache manager */
256 static int nBiods = 5; /* AIX3.1 only */
258 static int preallocs = 400; /* Def # of allocated memory blocks */
259 static int enable_peer_stats = 0; /* enable rx stats */
260 static int enable_process_stats = 0; /* enable rx stats */
261 static int enable_afsdb = 0; /* enable AFSDB support */
262 static int enable_dynroot = 0; /* enable dynroot support */
263 static int enable_fakestat = 0; /* enable fakestat support */
264 static int enable_backuptree = 0; /* enable backup tree support */
265 static int enable_nomount = 0; /* do not mount */
266 static int enable_splitcache = 0;
267 static int afsd_dynamic_vcaches = 0; /* Enable dynamic-vcache support */
268 int afsd_verbose = 0; /*Are we being chatty? */
269 int afsd_debug = 0; /*Are we printing debugging info? */
270 static int afsd_CloseSynch = 0; /*Are closes synchronous or not? */
271 static int rxmaxmtu = 0; /* Are we forcing a limit on the mtu? */
272 static int rxmaxfrags = 0; /* Are we forcing a limit on frags? */
275 #define AFSD_INO_T ino64_t
277 #define AFSD_INO_T afs_uint32
279 struct afsd_file_list {
281 struct afsd_file_list *next;
283 struct afsd_file_list **cache_dir_filelist = NULL;
284 int *cache_dir_list = NULL; /* Array of cache subdirs */
285 int *dir_for_V = NULL; /* Array: dir of each cache file.
286 * -1: file does not exist
287 * -2: file exists in top-level
288 * >=0: file exists in Dxxx
290 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
291 AFSD_INO_T *inode_for_V; /* Array of inodes for desired
294 int missing_DCacheFile = 1; /*Is the DCACHEFILE missing? */
295 int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing? */
296 int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing? */
297 int afsd_rmtsys = 0; /* Default: don't support rmtsys */
298 struct afs_cacheParams cparams; /* params passed to cache manager */
300 int PartSizeOverflow(char *path, int cs);
302 static int afsd_syscall(int code, ...);
304 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
305 static void fork_rx_syscall_wait(const char *rn, int syscall, ...);
307 static void fork_rx_syscall(const char *rn, int syscall, ...);
308 static void fork_syscall(const char *rn, int syscall, ...);
352 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
354 afsd_sleep_callback(void * refCon, io_service_t service,
355 natural_t messageType, void * messageArgument )
357 switch (messageType) {
358 case kIOMessageCanSystemSleep:
359 /* Idle sleep is about to kick in; can
360 prevent sleep by calling IOCancelPowerChange, otherwise
361 if we don't ack in 30s the system sleeps anyway */
364 IOAllowPowerChange(root_port, (long)messageArgument);
367 case kIOMessageSystemWillSleep:
368 /* The system WILL go to sleep. Ack or suffer delay */
370 IOAllowPowerChange(root_port, (long)messageArgument);
373 case kIOMessageSystemWillRestart:
374 /* The system WILL restart. Ack or suffer delay */
376 IOAllowPowerChange(root_port, (long)messageArgument);
379 case kIOMessageSystemWillPowerOn:
380 case kIOMessageSystemHasPoweredOn:
381 /* coming back from sleep */
383 IOAllowPowerChange(root_port, (long)messageArgument);
387 IOAllowPowerChange(root_port, (long)messageArgument);
393 afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
395 /* parse multihomed address files */
396 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
401 code = afsconf_ParseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS,
402 reason, AFSDIR_CLIENT_NETINFO_FILEPATH,
403 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
406 /* Note we're refreshing */
407 code = code | 0x40000000;
408 afsd_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
410 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
413 /* Since it's likely this means our DNS server changed, reinit now */
418 /* This function is called when the system's ip addresses may have changed. */
420 afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
422 CFRunLoopTimerRef timer;
424 timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
425 0.0, 0, 0, afsd_update_addresses, NULL);
426 CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
427 kCFRunLoopDefaultMode);
432 afsd_event_cleanup(int signo) {
434 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
436 IODeregisterForSystemPower(&iterator);
437 IOServiceClose(root_port);
438 IONotificationPortDestroy(notify);
442 /* Adapted from "Living in a Dynamic TCP/IP Environment" technote. */
444 afsd_install_events(void)
446 SCDynamicStoreContext ctx = {0};
447 SCDynamicStoreRef store;
449 root_port = IORegisterForSystemPower(0,¬ify,afsd_sleep_callback,&iterator);
452 CFRunLoopAddSource(CFRunLoopGetCurrent(),
453 IONotificationPortGetRunLoopSource(notify),
454 kCFRunLoopDefaultMode);
458 store = SCDynamicStoreCreate (NULL,
459 CFSTR ("AddIPAddressListChangeCallbackSCF"),
460 afsd_ipaddr_callback, &ctx);
465 /* Request IPV4 address change notification */
466 keys[0] = (SCDynamicStoreKeyCreateNetworkServiceEntity
467 (NULL, kSCDynamicStoreDomainState,
468 kSCCompAnyRegex, kSCEntNetIPv4));
471 /* This should tell us when the hostname(s) change. do we care? */
472 keys[N] = SCDynamicStoreKeyCreateHostNames (NULL);
475 if (keys[0] != NULL) {
476 CFArrayRef pattern_array;
478 pattern_array = CFArrayCreate (NULL, keys, 1,
479 &kCFTypeArrayCallBacks);
481 if (pattern_array != NULL)
483 SCDynamicStoreSetNotificationKeys (store, NULL, pattern_array);
484 source = SCDynamicStoreCreateRunLoopSource (NULL, store, 0);
486 CFRelease (pattern_array);
496 if (source != NULL) {
497 CFRunLoopAddSource (CFRunLoopGetCurrent(),
498 source, kCFRunLoopDefaultMode);
501 signal(SIGTERM, afsd_event_cleanup);
507 /* ParseArgs is now obsolete, being handled by cmd */
509 /*------------------------------------------------------------------------------
513 * Open the file containing the description of the workstation's AFS cache
514 * and pull out its contents. The format of this file is as follows:
516 * cacheMountDir:cacheBaseDir:cacheBlocks
522 * 0 if everything went well,
526 * Nothing interesting.
530 *---------------------------------------------------------------------------*/
533 ParseCacheInfoFile(void)
535 static char rn[] = "ParseCacheInfoFile"; /*This routine's name */
536 FILE *cachefd; /*Descriptor for cache info file */
537 int parseResult; /*Result of our fscanf() */
539 char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
542 printf("%s: Opening cache info file '%s'...\n", rn, fullpn_CacheInfo);
544 cachefd = fopen(fullpn_CacheInfo, "r");
546 printf("%s: Can't read cache info file '%s'\n", rn, fullpn_CacheInfo);
551 * Parse the contents of the cache info file. All chars up to the first
552 * colon are the AFS mount directory, all chars to the next colon are the
553 * full path name of the workstation cache directory and all remaining chars
554 * represent the number of blocks in the cache.
556 tCacheMountDir[0] = tCacheBaseDir[0] = '\0';
558 fscanf(cachefd, "%1024[^:]:%1024[^:]:%d", tCacheMountDir,
559 tCacheBaseDir, &tCacheBlocks);
562 * Regardless of how the parse went, we close the cache info file.
566 if (parseResult == EOF || parseResult < 3) {
567 printf("%s: Format error in cache info file!\n", rn);
568 if (parseResult == EOF)
569 printf("\tEOF encountered before any field parsed.\n");
571 printf("\t%d out of 3 fields successfully parsed.\n",
577 for (tmd = tCacheMountDir; *tmd == '\n' || *tmd == ' ' || *tmd == '\t';
579 for (tbd = tCacheBaseDir; *tbd == '\n' || *tbd == ' ' || *tbd == '\t';
581 /* now copy in the fields not explicitly overridden by cmd args */
582 if (!sawCacheMountDir)
583 afsd_cacheMountDir = strdup(tmd);
584 if (!sawCacheBaseDir)
585 cacheBaseDir = strdup(tbd);
587 cacheBlocks = tCacheBlocks;
590 printf("%s: Cache info file successfully parsed:\n", rn);
592 ("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
593 tmd, tbd, tCacheBlocks);
595 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
596 return (PartSizeOverflow(tbd, cacheBlocks));
603 * All failures to open the partition are ignored. Also if the cache dir
604 * isn't a mounted partition it's also ignored since we can't guarantee
605 * what will be stored afterwards. Too many if's. This is now purely
606 * advisory. ODS with over 2G partition also gives warning message.
609 * 0 if everything went well,
613 PartSizeOverflow(char *path, int cs)
616 afs_int64 totalblks, mint;
617 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
618 struct statvfs statbuf;
620 if (statvfs(path, &statbuf) != 0) {
623 ("statvfs failed on %s; skip checking for adequate partition space\n",
627 totalblks = statbuf.f_blocks;
628 bsize = statbuf.f_frsize;
630 if (strcmp(statbuf.f_basetype, "jfs")) {
631 fprintf(stderr, "Cache filesystem '%s' must be jfs (now %s)\n",
632 path, statbuf.f_basetype);
635 #endif /* AFS_AIX51_ENV */
637 #else /* AFS_HAVE_STATVFS */
638 struct statfs statbuf;
640 if (statfs(path, &statbuf) < 0) {
643 ("statfs failed on %s; skip checking for adequate partition space\n",
647 totalblks = statbuf.f_blocks;
648 bsize = statbuf.f_bsize;
651 return 0; /* success */
653 /* now free and totalblks are in fragment units, but we want them in 1K units */
655 totalblks *= (bsize / 1024);
657 totalblks /= (1024 / bsize);
660 mint = totalblks / 100 * 95;
663 ("Cache size (%d) must be less than 95%% of partition size (which is %lld). Lower cache size\n",
671 /*-----------------------------------------------------------------------------
675 * Given the final component of a filename expected to be a data cache file,
676 * return the integer corresponding to the file. Note: we reject names that
677 * are not a ``V'' followed by an integer. We also reject those names having
678 * the right format but lying outside the range [0..cacheFiles-1].
681 * fname : Char ptr to the filename to parse.
682 * max : integer for the highest number to accept
685 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
689 * Nothing interesting.
693 *---------------------------------------------------------------------------*/
696 doGetXFileNumber(char *fname, char filechar, int maxNum)
698 int computedVNumber; /*The computed file number we return */
699 int filenameLen; /*Number of chars in filename */
700 int currDigit; /*Current digit being processed */
703 * The filename must have at least two characters, the first of which must be a ``filechar''
704 * and the second of which cannot be a zero unless the file is exactly two chars long.
706 filenameLen = strlen(fname);
709 if (fname[0] != filechar)
711 if ((filenameLen > 2) && (fname[1] == '0'))
715 * Scan through the characters in the given filename, failing immediately if a non-digit
718 for (currDigit = 1; currDigit < filenameLen; currDigit++)
719 if (isdigit(fname[currDigit]) == 0)
723 * All relevant characters are digits. Pull out the decimal number they represent.
724 * Reject it if it's out of range, otherwise return it.
726 computedVNumber = atoi(++fname);
727 if (computedVNumber < cacheFiles)
728 return (computedVNumber);
734 GetVFileNumber(char *fname, int maxFile)
736 return doGetXFileNumber(fname, 'V', maxFile);
740 GetDDirNumber(char *fname, int maxDir)
742 return doGetXFileNumber(fname, 'D', maxDir);
746 /*-----------------------------------------------------------------------------
750 * Given a full pathname for a file we need to create for the workstation AFS
751 * cache, go ahead and create the file.
754 * fname : Full pathname of file to create.
755 * statp : A pointer to a stat buffer which, if NON-NULL, will be
759 * 0 iff the file was created,
763 * The given cache file has been found to be missing.
767 *---------------------------------------------------------------------------*/
770 CreateCacheSubDir(char *basename, int dirNum)
772 static char rn[] = "CreateCacheSubDir"; /* Routine Name */
776 /* Build the new cache subdirectory */
777 sprintf(dir, "%s/D%d", basename, dirNum);
780 printf("%s: Creating cache subdir '%s'\n", rn, dir);
782 if ((ret = mkdir(dir, 0700)) != 0) {
783 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, dir,
789 /* Mark this directory as created */
790 cache_dir_list[dirNum] = 0;
792 /* And return success */
797 SetNoBackupAttr(char *fullpn)
799 #ifdef AFS_DARWIN80_ENV
802 ret = setxattr(fullpn, "com.apple.metadata:com_apple_backup_excludeItem",
803 "com.apple.backupd", strlen("com.apple.backupd"), 0,
808 fprintf(stderr, "afsd: Warning: failed to set attribute to preclude cache backup: %s\n", strerror(errno));
815 MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
818 static char rn[] = "MoveCacheFile";
819 char from[1024], to[1024];
822 if (cache_dir_list[toDir] < 0
823 && (ret = CreateCacheSubDir(basename, toDir))) {
824 printf("%s: Can't create directory '%s/D%d'\n", rn, basename, toDir);
828 /* Build the from,to dir */
830 /* old-style location */
831 snprintf(from, sizeof(from), "%s/V%d", basename, cacheFile);
833 snprintf(from, sizeof(from), "%s/D%d/V%d", basename, fromDir,
837 snprintf(to, sizeof(from), "%s/D%d/V%d", basename, toDir, cacheFile);
840 printf("%s: Moving cacheFile from '%s' to '%s'\n", rn, from, to);
842 if ((ret = rename(from, to)) != 0) {
843 printf("%s: Can't rename '%s' to '%s', error return is %d (%d)\n", rn,
844 from, to, ret, errno);
849 /* Reset directory pointer; fix file counts */
850 dir_for_V[cacheFile] = toDir;
851 cache_dir_list[toDir]++;
852 if (fromDir < maxDir && fromDir >= 0)
853 cache_dir_list[fromDir]--;
859 CreateCacheFile(char *fname, struct stat *statp)
861 static char rn[] = "CreateCacheFile"; /*Routine name */
862 int cfd; /*File descriptor to AFS cache file */
863 int closeResult; /*Result of close() */
866 printf("%s: Creating cache file '%s'\n", rn, fname);
867 cfd = open(fname, createAndTrunc, ownerRWmode);
869 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
874 closeResult = fstat(cfd, statp);
877 ("%s: Can't stat newly-created AFS cache file '%s' (code %d)\n",
882 closeResult = close(cfd);
885 ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
894 CreateFileIfMissing(char *fullpn, int missing)
897 if (CreateCacheFile(fullpn, NULL))
898 printf("CreateFileIfMissing: Can't create '%s'\n", fullpn);
903 UnlinkUnwantedFile(char *rn, char *fullpn_FileToDelete, char *fileToDelete)
905 if (unlink(fullpn_FileToDelete)) {
906 if ((errno == EISDIR || errno == EPERM) && *fileToDelete == 'D') {
907 if (rmdir(fullpn_FileToDelete)) {
908 printf("%s: Can't rmdir '%s', errno is %d\n", rn,
909 fullpn_FileToDelete, errno);
912 printf("%s: Can't unlink '%s', errno is %d\n", rn,
913 fullpn_FileToDelete, errno);
917 /*-----------------------------------------------------------------------------
921 * Sweep through the AFS cache directory, recording the inode number for
922 * each valid data cache file there. Also, delete any file that doesn't belong
923 * in the cache directory during this sweep, and remember which of the other
924 * residents of this directory were seen. After the sweep, we create any data
925 * cache files that were missing.
928 * vFilesFound : Set to the number of data cache files found.
931 * 0 if everything went well,
935 * This routine may be called several times. If the number of data cache files
936 * found is less than the global cacheFiles, then the caller will need to call it
937 * again to record the inodes of the missing zero-length data cache files created
938 * in the previous call.
941 * Fills up the global inode_for_V array, may create and/or delete files as
943 *---------------------------------------------------------------------------*/
947 doSweepAFSCache(int *vFilesFound,
948 char *directory, /* /path/to/cache/directory */
949 int dirNum, /* current directory number */
950 int maxDir) /* maximum directory number */
952 static char rn[] = "doSweepAFSCache"; /* Routine Name */
953 char fullpn_FileToDelete[1024]; /*File to be deleted from cache */
954 char *fileToDelete; /*Ptr to last component of above */
955 DIR *cdirp; /*Ptr to cache directory structure */
957 struct dirent64 *currp; /*Current directory entry */
959 struct dirent *currp; /*Current directory entry */
961 int vFileNum; /*Data cache file's associated number */
962 int thisDir; /* A directory number */
966 printf("%s: Opening cache directory '%s'\n", rn, directory);
968 if (chmod(directory, 0700)) { /* force it to be 700 */
969 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
973 cdirp = opendir(directory);
974 if (cdirp == (DIR *) 0) {
975 printf("%s: Can't open AFS cache directory, '%s'.\n", rn, directory);
980 * Scan the directory entries, remembering data cache file inodes
981 * and the existance of other important residents. Recurse into
982 * the data subdirectories.
984 * Delete all files and directories that don't belong here.
986 sprintf(fullpn_FileToDelete, "%s/", directory);
987 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
990 for (currp = readdir64(cdirp); currp; currp = readdir64(cdirp))
992 for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
996 printf("%s: Current directory entry:\n", rn);
997 #if defined(AFS_SGI62_ENV) || defined(AFS_DARWIN90_ENV)
998 printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
999 currp->d_reclen, currp->d_name);
1000 #elif defined(AFS_DFBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
1001 printf("\tinode=%ld, name='%s'\n", (long)currp->d_ino, currp->d_name);
1003 printf("\tinode=%ld, reclen=%d, name='%s'\n", (long)currp->d_ino,
1004 currp->d_reclen, currp->d_name);
1009 * If dirNum < 0, we are a top-level cache directory and should
1010 * only contain sub-directories and other sundry files. Therefore,
1011 * V-files are valid only if dirNum >= 0, and Directories are only
1012 * valid if dirNum < 0.
1015 if (*(currp->d_name) == 'V'
1016 && ((vFileNum = GetVFileNumber(currp->d_name, cacheFiles)) >=
1019 * Found a valid data cache filename. Remember this
1020 * file's inode, directory, and bump the number of files found
1021 * total and in this directory.
1023 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1024 inode_for_V[vFileNum] = currp->d_ino;
1026 dir_for_V[vFileNum] = dirNum; /* remember this directory */
1029 /* If we're in a real subdir, mark this file to be moved
1030 * if we've already got too many files in this directory
1032 assert(dirNum >= 0);
1033 cache_dir_list[dirNum]++; /* keep directory's file count */
1034 if (cache_dir_list[dirNum] > nFilesPerDir) {
1035 /* Too many files -- add to filelist */
1036 struct afsd_file_list *tmp = malloc(sizeof(*tmp));
1039 ("%s: MALLOC FAILED allocating file_list entry\n",
1042 tmp->fileNum = vFileNum;
1043 tmp->next = cache_dir_filelist[dirNum];
1044 cache_dir_filelist[dirNum] = tmp;
1049 } else if (dirNum < 0 && (*(currp->d_name) == 'D')
1050 && GetDDirNumber(currp->d_name, 1 << 30) >= 0) {
1052 if ((vFileNum = GetDDirNumber(currp->d_name, maxDir)) >= 0) {
1053 /* Found a valid cachefile sub-Directory. Remember this number
1054 * and recurse into it. Note that subdirs cannot have subdirs.
1057 } else if ((vFileNum = GetDDirNumber(currp->d_name, 1 << 30)) >=
1059 /* This directory is going away, but figure out if there
1060 * are any cachefiles in here that should be saved by
1061 * moving them to other cache directories. This directory
1062 * will be removed later.
1067 /* Save the highest directory number we've seen */
1068 if (vFileNum > highDir)
1071 /* If this directory is staying, be sure to mark it as 'found' */
1073 cache_dir_list[vFileNum] = 0;
1075 /* Print the dirname for recursion */
1076 sprintf(fileToDelete, "%s", currp->d_name);
1078 /* Note: vFileNum is the directory number */
1080 doSweepAFSCache(vFilesFound, fullpn_FileToDelete, vFileNum,
1081 (retval == 1 ? 0 : -1));
1083 printf("%s: Recursive sweep failed on directory %s\n", rn,
1087 } else if (dirNum < 0 && strcmp(currp->d_name, DCACHEFILE) == 0) {
1089 * Found the file holding the dcache entries.
1091 missing_DCacheFile = 0;
1092 SetNoBackupAttr(fullpn_DCacheFile);
1093 } else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
1095 * Found the file holding the volume info.
1097 missing_VolInfoFile = 0;
1098 SetNoBackupAttr(fullpn_VolInfoFile);
1099 } else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
1101 * Found the file holding the cell info.
1103 missing_CellInfoFile = 0;
1104 SetNoBackupAttr(fullpn_CellInfoFile);
1105 } else if ((strcmp(currp->d_name, ".") == 0)
1106 || (strcmp(currp->d_name, "..") == 0) ||
1107 #ifdef AFS_DECOSF_ENV
1108 /* these are magic AdvFS files */
1109 (strcmp(currp->d_name, ".tags") == 0)
1110 || (strcmp(currp->d_name, "quota.user") == 0)
1111 || (strcmp(currp->d_name, "quota.group") == 0) ||
1113 #ifdef AFS_LINUX22_ENV
1114 /* this is the ext3 journal file */
1115 (strcmp(currp->d_name, ".journal") == 0) ||
1117 (strcmp(currp->d_name, "lost+found") == 0)) {
1119 * Don't do anything - this file is legit, and is to be left alone.
1123 * This file/directory doesn't belong in the cache. Nuke it.
1125 sprintf(fileToDelete, "%s", currp->d_name);
1127 printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
1128 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1135 * Create all the cache files that are missing.
1137 CreateFileIfMissing(fullpn_DCacheFile, missing_DCacheFile);
1138 CreateFileIfMissing(fullpn_VolInfoFile, missing_VolInfoFile);
1139 CreateFileIfMissing(fullpn_CellInfoFile, missing_CellInfoFile);
1141 /* ADJUST CACHE FILES */
1143 /* First, let's walk through the list of files and figure out
1144 * if there are any leftover files in extra directories or
1145 * missing files. Move the former and create the latter in
1146 * subdirs with extra space.
1149 thisDir = 0; /* Keep track of which subdir has space */
1151 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++) {
1152 if (dir_for_V[vFileNum] == -1) {
1153 /* This file does not exist. Create it in the first
1154 * subdir that still has extra space.
1156 while (thisDir < maxDir
1157 && cache_dir_list[thisDir] >= nFilesPerDir)
1159 if (thisDir >= maxDir)
1160 printf("%s: can't find directory to create V%d\n", rn,
1164 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1165 assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
1167 sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
1169 printf("%s: Creating '%s'\n", rn, fullpn_VFile);
1170 if (cache_dir_list[thisDir] < 0
1171 && CreateCacheSubDir(directory, thisDir))
1172 printf("%s: Can't create directory for '%s'\n", rn,
1174 if (CreateCacheFile(fullpn_VFile, &statb))
1175 printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
1177 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1178 inode_for_V[vFileNum] = statb.st_ino;
1180 dir_for_V[vFileNum] = thisDir;
1181 cache_dir_list[thisDir]++;
1184 SetNoBackupAttr(fullpn_VFile);
1187 } else if (dir_for_V[vFileNum] >= maxDir
1188 || dir_for_V[vFileNum] == -2) {
1189 /* This file needs to move; move it to the first subdir
1190 * that has extra space. (-2 means it's in the toplevel)
1192 while (thisDir < maxDir
1193 && cache_dir_list[thisDir] >= nFilesPerDir)
1195 if (thisDir >= maxDir)
1196 printf("%s: can't find directory to move V%d\n", rn,
1200 (directory, dir_for_V[vFileNum], thisDir, vFileNum,
1202 /* Cannot move. Ignore this file??? */
1209 /* At this point, we've moved all of the valid cache files
1210 * into the valid subdirs, and created all the extra
1211 * cachefiles we need to create. Next, rebalance any subdirs
1212 * with too many cache files into the directories with not
1213 * enough cache files. Note that thisDir currently sits at
1214 * the lowest subdir that _may_ have room.
1217 for (dirNum = 0; dirNum < maxDir; dirNum++) {
1218 struct afsd_file_list *thisFile;
1220 for (thisFile = cache_dir_filelist[dirNum];
1221 thisFile && cache_dir_list[dirNum] >= nFilesPerDir;
1222 thisFile = thisFile->next) {
1223 while (thisDir < maxDir
1224 && cache_dir_list[thisDir] >= nFilesPerDir)
1226 if (thisDir >= maxDir)
1227 printf("%s: can't find directory to move V%d\n", rn,
1231 (directory, dirNum, thisDir, thisFile->fileNum,
1233 /* Cannot move. Ignore this file??? */
1237 } /* for each file to move */
1238 } /* for each directory */
1240 /* Remove any directories >= maxDir -- they should be empty */
1241 for (; highDir >= maxDir; highDir--) {
1242 sprintf(fileToDelete, "D%d", highDir);
1243 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1249 * Close the directory, return success.
1252 printf("%s: Closing cache directory.\n", rn);
1258 CheckCacheBaseDir(char *dir)
1260 struct stat statbuf;
1263 return "cache base dir not specified";
1265 if (stat(dir, &statbuf) != 0) {
1266 return "unable to stat cache base directory";
1269 /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */
1271 #ifdef AFS_LINUX24_ENV
1274 struct statfs statfsbuf;
1276 res = statfs(dir, &statfsbuf);
1278 return "unable to statfs cache base directory";
1280 #if !defined(AFS_LINUX26_ENV)
1281 if (statfsbuf.f_type == 0x52654973) { /* REISERFS_SUPER_MAGIC */
1282 return "cannot use reiserfs as cache partition";
1283 } else if (statfsbuf.f_type == 0x58465342) { /* XFS_SUPER_MAGIC */
1284 return "cannot use xfs as cache partition";
1285 } else if (statfsbuf.f_type == 0x01021994) { /* TMPFS_SUPER_MAGIC */
1286 return "cannot use tmpfs as cache partition";
1287 } else if (statfsbuf.f_type != 0xEF53) {
1288 return "must use ext2 or ext3 for cache partition";
1297 struct statfs statfsbuf;
1300 res = statfs(dir, &statfsbuf);
1302 return "unable to statfs cache base directory";
1305 if (sysfs(GETFSTYP, statfsbuf.f_fsid[1], name) != 0) {
1306 return "unable to determine filesystem type for cache base dir";
1309 if (strcmp(name, "hfs")) {
1310 return "can only use hfs filesystem for cache partition on hpux";
1319 struct stat statmnt, statci;
1321 if ((stat(dir, &statci) == 0)
1322 && ((vfstab = fopen(MNTTAB, "r")) != NULL)) {
1323 while (getmntent(vfstab, &mnt) == 0) {
1324 if (strcmp(dir, mnt.mnt_mountp) != 0) {
1328 if (cp = hasmntopt(&mnt, "dev="))
1330 (int)strtol(cp + strlen("dev="), (char **)NULL,
1333 if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
1334 rdev = statmnt.st_dev;
1336 if ((rdev == statci.st_dev)
1337 && (hasmntopt(&mnt, "logging") != NULL)) {
1341 "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n";
1355 SweepAFSCache(int *vFilesFound)
1357 static char rn[] = "SweepAFSCache"; /*Routine name */
1358 int maxDir = (cacheFiles + nFilesPerDir - 1) / nFilesPerDir;
1363 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1365 printf("%s: Memory Cache, no cache sweep done\n", rn);
1369 if (cache_dir_list == NULL) {
1370 cache_dir_list = malloc(maxDir * sizeof(*cache_dir_list));
1371 if (cache_dir_list == NULL) {
1372 printf("%s: Malloc Failed!\n", rn);
1375 for (i = 0; i < maxDir; i++)
1376 cache_dir_list[i] = -1; /* Does not exist */
1379 if (cache_dir_filelist == NULL) {
1380 cache_dir_filelist = calloc(maxDir, sizeof(*cache_dir_filelist));
1381 if (cache_dir_filelist == NULL) {
1382 printf("%s: Malloc Failed!\n", rn);
1387 if (dir_for_V == NULL) {
1388 dir_for_V = malloc(cacheFiles * sizeof(*dir_for_V));
1389 if (dir_for_V == NULL) {
1390 printf("%s: Malloc Failed!\n", rn);
1393 for (i = 0; i < cacheFiles; i++)
1394 dir_for_V[i] = -1; /* Does not exist */
1397 /* Note, setting dirNum to -2 here will cause cachefiles found in
1398 * the toplevel directory to be marked in directory "-2". This
1399 * allows us to differentiate between 'file not seen' (-1) and
1400 * 'file seen in top-level' (-2). Then when we try to move the
1401 * file into a subdirectory, we know it's in the top-level instead
1402 * of some other cache subdir.
1404 return doSweepAFSCache(vFilesFound, cacheBaseDir, -2, maxDir);
1408 ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
1413 afs_int32 hosts[MAXHOSTSPERCELL];
1415 /* figure out if this is the home cell */
1416 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
1418 cellFlags = 2; /* not home, suid is forbidden */
1419 if (enable_dynroot == 2)
1420 cellFlags |= 8; /* don't display foreign cells until looked up */
1422 /* build address list */
1423 for (i = 0; i < MAXHOSTSPERCELL; i++)
1424 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1426 if (aci->linkedCell)
1427 cellFlags |= 4; /* Flag that linkedCell arg exists,
1428 * for upwards compatibility */
1430 /* configure one cell */
1431 code = afsd_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
1432 aci->name, /* cell name */
1433 cellFlags, /* is this the home cell? */
1434 aci->linkedCell); /* Linked cell, if any */
1436 printf("Adding cell '%s': error %d\n", aci->name, code);
1441 ConfigCellAlias(struct afsconf_cellalias *aca,
1442 void *arock, struct afsconf_dir *adir)
1444 /* push the alias into the kernel */
1445 afsd_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
1450 AfsdbLookupHandler(void)
1452 afs_int32 kernelMsg[64];
1453 char acellName[128];
1455 struct afsconf_cell acellInfo;
1460 acellName[0] = '\0';
1462 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
1463 /* Fork the event handler also. */
1466 afsd_install_events();
1468 } else if (code != -1) {
1473 /* On some platforms you only get 4 args to an AFS call */
1474 int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
1476 afsd_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
1477 if (code) { /* Something is wrong? */
1482 if (*acellName == 1) /* Shutting down */
1485 code = afsconf_GetAfsdbInfo(acellName, 0, &acellInfo);
1490 kernelMsg[0] = acellInfo.numServers;
1491 if (acellInfo.timeout)
1492 kernelMsg[1] = acellInfo.timeout - time(0);
1495 for (i = 0; i < acellInfo.numServers; i++)
1496 kernelMsg[i + 2] = acellInfo.hostAddr[i].sin_addr.s_addr;
1497 strncpy(acellName, acellInfo.name, sizeof(acellName));
1498 acellName[sizeof(acellName) - 1] = '\0';
1501 #ifdef AFS_DARWIN_ENV
1502 kill(event_pid, SIGTERM);
1511 struct afs_uspc_param *uspc;
1515 uspc = calloc(1, sizeof(struct afs_uspc_param));
1516 memset(srcName, 0, sizeof(srcName));
1517 memset(dstName, 0, sizeof(dstName));
1519 /* brscount starts at 0 */
1525 char srcpath[BUFSIZ];
1526 char dstpath[BUFSIZ];
1528 /* pushing in a buffer this large */
1531 code = afsd_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
1532 if (code) { /* Something is wrong? */
1533 if (code == -2) /* shutting down */
1541 switch (uspc->reqtype) {
1543 snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1544 uspc->req.umv.sCell, uspc->req.umv.sVolume,
1545 uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
1546 snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1547 uspc->req.umv.dCell, uspc->req.umv.dVolume,
1548 uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
1549 if ((child = fork()) == 0) {
1550 /* first child does cp; second, rm. mv would re-enter. */
1552 switch (uspc->req.umv.idtype) {
1554 if (setuid(uspc->req.umv.id) != 0) {
1560 break; /* notreached */
1562 execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
1563 dstpath, (char *) NULL);
1565 if (child == (pid_t) -1) {
1570 if (waitpid(child, &status, 0) == -1)
1572 else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
1573 if ((child = fork()) == 0) {
1574 switch (uspc->req.umv.idtype) {
1576 if (setuid(uspc->req.umv.id) != 0) {
1582 break; /* notreached */
1584 execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
1585 srcpath, (char *) NULL);
1587 if (child == (pid_t) -1) {
1591 if (waitpid(child, &status, 0) == -1)
1593 else if (WIFEXITED(status) != 0) {
1594 /* rm exit status */
1595 uspc->retval = WEXITSTATUS(status);
1597 /* rm signal status */
1598 uspc->retval = -(WTERMSIG(status));
1601 /* error from cp: exit or signal status */
1602 uspc->retval = (WIFEXITED(status) != 0) ?
1603 WEXITSTATUS(status) : -(WTERMSIG(status));
1605 memset(srcName, 0, sizeof(srcName));
1606 memset(dstName, 0, sizeof(dstName));
1610 /* unknown req type */
1619 afsdb_thread(void *rock)
1621 /* Since the AFSDB lookup handler runs as a user process,
1622 * need to drop the controlling TTY, etc.
1624 if (afsd_daemon(0, 0) == -1) {
1625 printf("Error starting AFSDB lookup handler: %s\n",
1629 AfsdbLookupHandler();
1634 daemon_thread(void *rock)
1637 /* Since the background daemon runs as a user process,
1638 * need to drop the controlling TTY, etc.
1640 if (afsd_daemon(0, 0) == -1) {
1641 printf("Error starting background daemon: %s\n",
1647 afsd_syscall(AFSOP_START_BKG, 0);
1654 rmtsysd_thread(void *rock)
1659 #endif /* !UKERNEL */
1662 mainproc(struct cmd_syndesc *as, void *arock)
1664 afs_int32 code; /*Result of fork() */
1668 #ifdef AFS_SGI65_ENV
1669 struct sched_param sp;
1672 #ifdef AFS_SGI_VNODE_GLUE
1673 if (afs_init_kernel_config(-1) < 0) {
1674 printf("Can't determine NUMA configuration, not starting AFS.\n");
1679 cmd_OpenConfigFile(AFSDIR_CLIENT_CONFIG_FILE_FILEPATH);
1680 cmd_SetCommandName("afsd");
1682 /* call atoi on the appropriate parsed results */
1683 if (cmd_OptionAsInt(as, OPT_blocks, &cacheBlocks) == 0)
1686 if (cmd_OptionAsInt(as, OPT_files, &cacheFiles) == 0)
1689 if (cmd_OptionAsString(as, OPT_rootvol, &rootVolume) == 0)
1692 if (cmd_OptionAsInt(as, OPT_stat, &cacheStatEntries) == 0)
1693 sawCacheStatEntries = 1;
1695 if (cmd_OptionPresent(as, OPT_memcache)) {
1696 cacheBaseDir = NULL;
1697 sawCacheBaseDir = 1;
1698 cacheFlags |= AFSCALL_INIT_MEMCACHE;
1701 if (cmd_OptionAsString(as, OPT_cachedir, &cacheBaseDir) == 0)
1702 sawCacheBaseDir = 1;
1704 if (cmd_OptionAsString(as, OPT_mountdir, &afsd_cacheMountDir) == 0)
1705 sawCacheMountDir = 1;
1707 cmd_OptionAsInt(as, OPT_daemons, &nDaemons);
1709 afsd_verbose = cmd_OptionPresent(as, OPT_verbose);
1711 if (cmd_OptionPresent(as, OPT_rmtsys)) {
1714 printf("-rmtsys not supported for UKERNEL\n");
1719 if (cmd_OptionPresent(as, OPT_debug)) {
1724 if (cmd_OptionAsInt(as, OPT_chunksize, &chunkSize) == 0) {
1725 if (chunkSize < 0 || chunkSize > 30) {
1727 ("afsd:invalid chunk size (not in range 0-30), using default\n");
1732 if (cmd_OptionAsInt(as, OPT_dcache, &dCacheSize) == 0)
1735 cmd_OptionAsInt(as, OPT_volumes, &vCacheSize);
1737 if (cmd_OptionPresent(as, OPT_biods)) {
1739 #ifndef AFS_AIX32_ENV
1741 ("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
1743 cmd_OptionAsInt(as, OPT_biods, &nBiods);
1746 cmd_OptionAsInt(as, OPT_prealloc, &preallocs);
1748 if (cmd_OptionAsString(as, OPT_confdir, &confDir) == CMD_MISSING) {
1749 confDir = strdup(AFSDIR_CLIENT_ETC_DIRPATH);
1751 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
1753 if (cmd_OptionPresent(as, OPT_logfile)) {
1754 printf("afsd: Ignoring obsolete -logfile flag\n");
1757 afsd_CloseSynch = cmd_OptionPresent(as, OPT_waitclose);
1759 if (cmd_OptionPresent(as, OPT_shutdown)) {
1763 * Cold shutdown is the default
1765 printf("afsd: Shutting down all afs processes and afs state\n");
1766 code = afsd_syscall(AFSOP_SHUTDOWN, 1);
1768 printf("afsd: AFS still mounted; Not shutting down\n");
1774 enable_peer_stats = cmd_OptionPresent(as, OPT_peerstats);
1775 enable_process_stats = cmd_OptionPresent(as, OPT_processstats);
1777 if (cmd_OptionPresent(as, OPT_memallocsleep)) {
1778 printf("afsd: -mem_alloc_sleep is deprecated -- ignored\n");
1781 enable_afsdb = cmd_OptionPresent(as, OPT_afsdb);
1782 if (cmd_OptionPresent(as, OPT_filesdir)) {
1783 /* -files_per_subdir */
1785 cmd_OptionAsInt(as, OPT_filesdir, &res);
1786 if (res < 10 || res > (1 << 30)) {
1788 ("afsd:invalid number of files per subdir, \"%s\". Ignored\n",
1789 as->parms[25].items->data);
1794 enable_dynroot = cmd_OptionPresent(as, OPT_dynroot);
1796 if (cmd_OptionPresent(as, OPT_fakestat)) {
1797 enable_fakestat = 2;
1799 if (cmd_OptionPresent(as, OPT_fakestatall)) {
1800 enable_fakestat = 1;
1802 if (cmd_OptionPresent(as, OPT_settime)) {
1804 printf("afsd: -settime ignored\n");
1805 printf("afsd: the OpenAFS client no longer sets the system time; "
1806 "please use NTP or\n");
1807 printf("afsd: another such system to synchronize client time\n");
1810 enable_nomount = cmd_OptionPresent(as, OPT_nomount);
1811 enable_backuptree = cmd_OptionPresent(as, OPT_backuptree);
1812 enable_rxbind = cmd_OptionPresent(as, OPT_rxbind);
1814 /* set rx_extraPackets */
1815 if (cmd_OptionPresent(as, OPT_rxpck)) {
1818 cmd_OptionAsInt(as, OPT_rxpck, &rxpck);
1819 printf("afsd: set rxpck = %d\n", rxpck);
1820 code = afsd_syscall(AFSOP_SET_RXPCK, rxpck);
1822 printf("afsd: failed to set rxpck\n");
1826 if (cmd_OptionPresent(as, OPT_splitcache)) {
1830 cmd_OptionAsString(as, OPT_splitcache, &var);
1832 if (var == NULL || ((c = strchr(var, '/')) == NULL))
1834 ("ignoring splitcache (specify as RW/RO percentages: 60/40)\n");
1836 ropct = atoi(c + 1);
1839 if ((rwpct != 0) && (ropct != 0) && (ropct + rwpct == 100)) {
1841 enable_splitcache = 1;
1846 if (cmd_OptionPresent(as, OPT_nodynvcache)) {
1847 #ifdef AFS_MAXVCOUNT_ENV
1848 afsd_dynamic_vcaches = 0;
1850 printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
1854 #ifdef AFS_MAXVCOUNT_ENV
1856 /* -dynamic-vcaches */
1857 afsd_dynamic_vcaches = 1;
1861 printf("afsd: %s dynamically allocated vcaches\n", ( afsd_dynamic_vcaches ? "enabling" : "disabling" ));
1864 cmd_OptionAsInt(as, OPT_rxmaxmtu, &rxmaxmtu);
1866 if (cmd_OptionPresent(as, OPT_dynrootsparse)) {
1870 cmd_OptionAsInt(as, OPT_rxmaxfrags, &rxmaxfrags);
1872 /* parse cacheinfo file if this is a diskcache */
1873 if (ParseCacheInfoFile()) {
1883 static char rn[] = "afsd"; /*Name of this routine */
1884 struct afsconf_dir *cdir; /* config dir */
1885 int lookupResult; /*Result of GetLocalCellName() */
1887 int code; /*Result of fork() */
1888 char *fsTypeMsg = NULL;
1889 int cacheIteration; /*How many times through cache verification */
1890 int vFilesFound; /*How many data cache files were found in sweep */
1891 int currVFile; /*Current AFS cache file number passed in */
1894 * Pull out all the configuration info for the workstation's AFS cache and
1895 * the cellular community we're willing to let our users see.
1897 cdir = afsconf_Open(confDir);
1899 printf("afsd: some file missing or bad in %s\n", confDir);
1904 afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
1906 printf("%s: Can't get my home cell name! [Error is %d]\n", rn,
1910 printf("%s: My home cell is '%s'\n", rn, LclCellName);
1913 if (!enable_nomount) {
1914 if (afsd_check_mount(rn, afsd_cacheMountDir)) {
1919 /* do some random computations in memcache case to get things to work
1920 * reasonably no matter which parameters you set.
1922 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1923 /* memory cache: size described either as blocks or dcache entries, but
1927 fprintf(stderr, "%s: -files ignored with -memcache\n", rn);
1929 if (sawDCacheSize) {
1930 if (chunkSize == 0) {
1931 chunkSize = 13; /* 8k default chunksize for memcache */
1933 if (sawCacheBlocks) {
1935 ("%s: can't set cache blocks and dcache size simultaneously when diskless.\n",
1939 /* compute the cache size based on # of chunks times the chunk size */
1940 i = (1 << chunkSize); /* bytes per chunk */
1941 cacheBlocks = i * dCacheSize;
1942 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
1944 if (chunkSize == 0) {
1945 /* Try to autotune the memcache chunksize based on size
1946 * of memcache. This is done on the assumption that approx
1947 * 1024 chunks is suitable, it's a balance between enough
1948 * chunks to be useful and ramping up nicely when using larger
1949 * memcache to improve bulk read/write performance
1952 i <= 21 && (1 << i) / 1024 < (cacheBlocks / 1024); i++);
1955 /* compute the dcache size from overall cache size and chunk size */
1956 if (chunkSize > 10) {
1957 dCacheSize = (cacheBlocks >> (chunkSize - 10));
1958 } else if (chunkSize < 10) {
1959 dCacheSize = (cacheBlocks << (10 - chunkSize));
1961 dCacheSize = cacheBlocks;
1963 /* don't have to set sawDCacheSize here since it isn't overwritten
1964 * by ParseCacheInfoFile.
1968 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
1970 /* kernel computes # of dcache entries as min of cacheFiles and
1971 * dCacheSize, so we now make them equal.
1973 cacheFiles = dCacheSize;
1976 * Compute the number of cache files based on cache size,
1977 * but only if -files isn't given on the command line.
1978 * Don't let # files be so small as to prevent full utilization
1979 * of the cache unless user has explicitly asked for it.
1981 if (chunkSize == 0) {
1982 /* Set chunksize to 256kB - 1MB depending on cache size */
1983 if (cacheBlocks < 500000) {
1985 } else if (cacheBlocks < 1000000) {
1993 cacheFiles = cacheBlocks / 32; /* Assume 32k avg filesize */
1995 cacheFiles = max(cacheFiles, 1000);
1997 /* Always allow more files than chunks. Presume average V-file
1998 * is ~67% of a chunk... (another guess, perhaps Honeyman will
1999 * have a grad student write a paper). i is KILOBYTES.
2001 i = 1 << (chunkSize < 10 ? 0 : chunkSize - 10);
2002 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
2004 /* never permit more files than blocks, while leaving space for
2005 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
2006 * CacheItems is 50 Bytes / file (== 1K/20)
2008 #define CACHEITMSZ (cacheFiles / 20)
2009 #define VOLINFOSZ 50 /* 40kB has been seen, be conservative */
2010 #define CELLINFOSZ 4 /* Assuming disk block size is 4k ... */
2011 #define INFOSZ (VOLINFOSZ+CELLINFOSZ+CACHEITMSZ)
2013 /* Sanity check: If the obtained number of disk cache files
2014 * is larger than the number of available (4k) disk blocks, we're
2015 * doing something wrong. Fail hard so we can fix the bug instead
2016 * of silently hiding it like before */
2018 if (cacheFiles > (cacheBlocks - INFOSZ) / 4) {
2020 "%s: ASSERT: cacheFiles %d diskblocks %d\n",
2021 rn, cacheFiles, (cacheBlocks - INFOSZ) / 4);
2024 if (cacheFiles < 100)
2025 fprintf(stderr, "%s: WARNING: cache probably too small!\n",
2029 printf("%s: cacheFiles autotuned to %d\n", rn, cacheFiles);
2032 /* This actually needs to
2034 2) not second-guess when a chunksize comes from the command line
2035 3) be less, um, small. 2^2??
2037 /* Sanity check chunkSize */
2038 i = max(cacheBlocks / 1000, cacheBlocks / cacheFiles);
2039 chunkSize = min(chunkSize, i);
2040 chunkSize = max(chunkSize, 2);
2042 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
2045 if (!sawDCacheSize) {
2046 dCacheSize = cacheFiles / 2;
2047 if (dCacheSize > 10000) {
2050 if (dCacheSize < 2000) {
2054 printf("%s: dCacheSize autotuned to %d\n", rn, dCacheSize);
2057 if (!sawCacheStatEntries) {
2058 if (chunkSize <= 13) {
2059 cacheStatEntries = dCacheSize / 4;
2060 } else if (chunkSize >= 16) {
2061 cacheStatEntries = dCacheSize * 1.5;
2063 cacheStatEntries = dCacheSize;
2066 printf("%s: cacheStatEntries autotuned to %d\n", rn,
2070 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
2072 * Create and zero the inode table for the desired cache files.
2074 inode_for_V = calloc(cacheFiles, sizeof(AFSD_INO_T));
2075 if (inode_for_V == (AFSD_INO_T *) 0) {
2077 ("%s: malloc() failed for cache file inode table with %d entries.\n",
2082 printf("%s: %d inode_for_V entries at 0x%x, %lu bytes\n", rn,
2083 cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
2086 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2088 * Set up all the pathnames we'll need for later.
2090 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
2091 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
2092 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
2093 sprintf(fullpn_VFile, "%s/", cacheBaseDir);
2094 vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
2096 fsTypeMsg = CheckCacheBaseDir(cacheBaseDir);
2099 printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2101 printf("%s: ERROR: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2108 * Set up all the kernel processes needed for AFS.
2111 setpgrp(getpid(), 0);
2115 * Set the primary cell name.
2117 afsd_syscall(AFSOP_SET_THISCELL, LclCellName);
2119 /* Initialize RX daemons and services */
2121 /* initialize the rx random number generator from user space */
2123 /* parse multihomed address files */
2124 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
2127 code = afsconf_ParseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
2128 AFSDIR_CLIENT_NETINFO_FILEPATH,
2129 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
2132 code = code | 0x80000000;
2133 afsd_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
2135 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
2139 /* Set realtime priority for most threads to same as for biod's. */
2140 afsd_set_afsd_rtpri();
2142 /* Start listener, then callback listener. Lastly, start rx event daemon.
2143 * Change in ordering is so that Linux port has socket fd in listener
2145 * preallocs are passed for both listener and callback server. Only
2146 * the one which actually does the initialization uses them though.
2148 if (preallocs < cacheStatEntries + 50)
2149 preallocs = cacheStatEntries + 50;
2150 #ifdef RXK_LISTENER_ENV
2152 printf("%s: Forking rx listener daemon.\n", rn);
2153 # ifdef AFS_SUN510_ENV
2154 fork_rx_syscall_wait(rn, AFSOP_RXLISTENER_DAEMON, preallocs,
2155 enable_peer_stats, enable_process_stats);
2156 # else /* !AFS_SUN510_ENV */
2157 fork_rx_syscall(rn, AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
2158 enable_process_stats);
2159 # endif /* !AFS_SUN510_ENV */
2162 printf("%s: Forking rx callback listener.\n", rn);
2163 #ifndef RXK_LISTENER_ENV
2164 fork_rx_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, enable_peer_stats,
2165 enable_process_stats);
2167 fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, 0, 0);
2169 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
2171 printf("%s: Forking rxevent daemon.\n", rn);
2172 fork_rx_syscall(rn, AFSOP_RXEVENT_DAEMON);
2177 printf("%s: Forking AFSDB lookup handler.\n", rn);
2178 afsd_fork(0, afsdb_thread, NULL);
2180 code = afsd_syscall(AFSOP_BASIC_INIT, 1);
2182 printf("%s: Error %d in basic initialization.\n", rn, code);
2187 * Tell the kernel some basic information about the workstation's cache.
2191 ("%s: Calling AFSOP_CACHEINIT: %d stat cache entries, %d optimum cache files, %d blocks in the cache, flags = 0x%x, dcache entries %d\n",
2192 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
2194 memset(&cparams, '\0', sizeof(cparams));
2195 cparams.cacheScaches = cacheStatEntries;
2196 cparams.cacheFiles = cacheFiles;
2197 cparams.cacheBlocks = cacheBlocks;
2198 cparams.cacheDcaches = dCacheSize;
2199 cparams.cacheVolumes = vCacheSize;
2200 cparams.chunkSize = chunkSize;
2201 cparams.setTimeFlag = 0;
2202 cparams.memCacheFlag = cacheFlags;
2203 cparams.dynamic_vcaches = afsd_dynamic_vcaches;
2204 afsd_syscall(AFSOP_CACHEINIT, &cparams);
2206 /* do it before we init the cache inodes */
2207 if (enable_splitcache) {
2208 afsd_syscall(AFSOP_BUCKETPCT, 1, rwpct);
2209 afsd_syscall(AFSOP_BUCKETPCT, 2, ropct);
2212 if (afsd_CloseSynch)
2213 afsd_syscall(AFSOP_CLOSEWAIT);
2216 * Sweep the workstation AFS cache directory, remembering the inodes of
2217 * valid files and deleting extraneous files. Keep sweeping until we
2218 * have the right number of data cache files or we've swept too many
2221 * This also creates files in the cache directory like VolumeItems and
2222 * CellItems, and thus must be ran before those are sent to the kernel.
2225 printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
2227 /* Memory-cache based system doesn't need any of this */
2228 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2231 if (SweepAFSCache(&vFilesFound)) {
2232 printf("%s: Error on sweep %d of workstation AFS cache \
2233 directory.\n", rn, cacheIteration);
2238 ("%s: %d out of %d data cache files found in sweep %d.\n",
2239 rn, vFilesFound, cacheFiles, cacheIteration);
2240 } while ((vFilesFound < cacheFiles)
2241 && (cacheIteration < MAX_CACHE_LOOPS));
2242 } else if (afsd_verbose)
2243 printf("%s: Using memory cache, not swept\n", rn);
2246 * Pass the kernel the name of the workstation cache file holding the
2250 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
2252 /* once again, meaningless for a memory-based cache. */
2253 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2254 afsd_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
2257 * Pass the kernel the name of the workstation cache file holding the
2260 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2262 printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
2263 fullpn_CellInfoFile);
2264 afsd_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
2269 printf("%s: Setting rxmaxfrags in kernel = %d\n", rn, rxmaxfrags);
2270 code = afsd_syscall(AFSOP_SET_RXMAXFRAGS, rxmaxfrags);
2272 printf("%s: Error seting rxmaxfrags\n", rn);
2277 printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
2278 code = afsd_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
2280 printf("%s: Error seting rxmaxmtu\n", rn);
2283 if (enable_dynroot) {
2285 printf("%s: Enabling dynroot support in kernel%s.\n", rn,
2286 (enable_dynroot==2)?", not showing cells.":"");
2287 code = afsd_syscall(AFSOP_SET_DYNROOT, 1);
2289 printf("%s: Error enabling dynroot support.\n", rn);
2292 if (enable_fakestat) {
2294 printf("%s: Enabling fakestat support in kernel%s.\n", rn,
2295 (enable_fakestat==1)?" for all mountpoints."
2296 :" for crosscell mountpoints");
2297 code = afsd_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
2299 printf("%s: Error enabling fakestat support.\n", rn);
2302 if (enable_backuptree) {
2304 printf("%s: Enabling backup tree support in kernel.\n", rn);
2305 code = afsd_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
2307 printf("%s: Error enabling backup tree support.\n", rn);
2311 * Tell the kernel about each cell in the configuration.
2313 afsconf_CellApply(cdir, ConfigCell, NULL);
2314 afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
2316 /* Initialize AFS daemon threads. */
2318 printf("%s: Forking AFS daemon.\n", rn);
2319 fork_syscall(rn, AFSOP_START_AFS);
2322 printf("%s: Forking Check Server Daemon.\n", rn);
2323 fork_syscall(rn, AFSOP_START_CS);
2326 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
2327 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
2328 /* Add one because for sgi we always "steal" the first daemon for a
2329 * different task if we only have a 4K stack.
2333 for (i = 0; i < nDaemons; i++) {
2334 afsd_fork(0, daemon_thread, NULL);
2336 #ifdef AFS_AIX32_ENV
2338 nBiods = nDaemons * 2;
2341 for (i = 0; i < nBiods; i++) {
2342 fork_syscall(rn, AFSOP_START_BKG, nBiods);
2347 * If the root volume has been explicitly set, tell the kernel.
2351 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
2353 afsd_syscall(AFSOP_ROOTVOLUME, rootVolume);
2357 * Pass the kernel the name of the workstation cache file holding the
2358 * volume information.
2361 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
2362 fullpn_VolInfoFile);
2363 /* once again, meaningless for a memory-based cache. */
2364 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2365 afsd_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
2368 * Give the kernel the names of the AFS files cached on the workstation's
2371 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2372 int nocachefile = 0;
2375 ("%s: Calling AFSOP_CACHEFILE for each of the %d files in '%s'\n",
2376 rn, cacheFiles, cacheBaseDir);
2377 /* ... and again ... */
2378 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
2380 sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
2381 code = afsd_syscall(AFSOP_CACHEFILE, fullpn_VFile);
2383 if (currVFile == 0) {
2386 ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
2387 rn, cacheFiles, cacheBaseDir);
2391 ("%s: Error calling AFSOP_CACHEFILE for '%s'\n",
2398 /* fall through to setup-by-inode */
2400 #if defined(AFS_SGI62_ENV) || !(defined(AFS_LINUX26_ENV) || defined(AFS_CACHE_VNODE_PATH))
2401 afsd_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
2404 ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
2412 * All the necessary info has been passed into the kernel to run an AFS
2413 * system. Give the kernel our go-ahead.
2416 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
2418 afsd_syscall(AFSOP_GO, 0);
2421 * At this point, we have finished passing the kernel all the info
2422 * it needs to set up the AFS. Mount the AFS root.
2424 printf("%s: All AFS daemons started.\n", rn);
2427 printf("%s: Forking trunc-cache daemon.\n", rn);
2428 fork_syscall(rn, AFSOP_START_TRUNCDAEMON);
2430 if (!enable_nomount) {
2431 afsd_mount_afs(rn, afsd_cacheMountDir);
2437 printf("%s: Forking 'rmtsys' daemon.\n", rn);
2438 afsd_fork(0, rmtsysd_thread, NULL);
2440 #endif /* !UKERNEL */
2442 * Exit successfully.
2447 #include "AFS_component_version_number.c"
2452 struct cmd_syndesc *ts;
2454 ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
2457 cmd_AddParmAtOffset(ts, OPT_blocks, "-blocks", CMD_SINGLE,
2458 CMD_OPTIONAL, "1024 byte blocks in cache");
2459 cmd_AddParmAtOffset(ts, OPT_files, "-files", CMD_SINGLE,
2460 CMD_OPTIONAL, "files in cache");
2461 cmd_AddParmAtOffset(ts, OPT_rootvol, "-rootvol", CMD_SINGLE,
2462 CMD_OPTIONAL, "name of AFS root volume");
2463 cmd_AddParmAtOffset(ts, OPT_stat, "-stat", CMD_SINGLE,
2464 CMD_OPTIONAL, "number of stat entries");
2465 cmd_AddParmAtOffset(ts, OPT_memcache, "-memcache", CMD_FLAG,
2466 CMD_OPTIONAL, "run diskless");
2467 cmd_AddParmAtOffset(ts, OPT_cachedir, "-cachedir", CMD_SINGLE,
2468 CMD_OPTIONAL, "cache directory");
2469 cmd_AddParmAtOffset(ts, OPT_mountdir, "-mountdir", CMD_SINGLE,
2470 CMD_OPTIONAL, "mount location");
2471 cmd_AddParmAtOffset(ts, OPT_daemons, "-daemons", CMD_SINGLE,
2472 CMD_OPTIONAL, "number of daemons to use");
2473 cmd_AddParmAtOffset(ts, OPT_nosettime, "-nosettime", CMD_FLAG,
2474 CMD_OPTIONAL, "don't set the time");
2475 cmd_AddParmAtOffset(ts, OPT_verbose, "-verbose", CMD_FLAG,
2476 CMD_OPTIONAL, "display lots of information");
2477 cmd_AddParmAtOffset(ts, OPT_rmtsys, "-rmtsys", CMD_FLAG,
2478 CMD_OPTIONAL, "start NFS rmtsysd program");
2479 cmd_AddParmAtOffset(ts, OPT_debug, "-debug", CMD_FLAG,
2480 CMD_OPTIONAL, "display debug info");
2481 cmd_AddParmAtOffset(ts, OPT_chunksize, "-chunksize", CMD_SINGLE,
2482 CMD_OPTIONAL, "log(2) of chunk size");
2483 cmd_AddParmAtOffset(ts, OPT_dcache, "-dcache", CMD_SINGLE,
2484 CMD_OPTIONAL, "number of dcache entries");
2485 cmd_AddParmAtOffset(ts, OPT_volumes, "-volumes", CMD_SINGLE,
2486 CMD_OPTIONAL, "number of volume entries");
2487 cmd_AddParmAtOffset(ts, OPT_biods, "-biods", CMD_SINGLE,
2488 CMD_OPTIONAL, "number of bkg I/O daemons (aix vm)");
2489 cmd_AddParmAtOffset(ts, OPT_prealloc, "-prealloc", CMD_SINGLE,
2490 CMD_OPTIONAL, "number of 'small' preallocated blocks");
2491 cmd_AddParmAtOffset(ts, OPT_confdir, "-confdir", CMD_SINGLE,
2492 CMD_OPTIONAL, "configuration directory");
2493 cmd_AddParmAtOffset(ts, OPT_logfile, "-logfile", CMD_SINGLE,
2494 CMD_OPTIONAL, "Place to keep the CM log");
2495 cmd_AddParmAtOffset(ts, OPT_waitclose, "-waitclose", CMD_FLAG,
2496 CMD_OPTIONAL, "make close calls synchronous");
2497 cmd_AddParmAtOffset(ts, OPT_shutdown, "-shutdown", CMD_FLAG,
2498 CMD_OPTIONAL, "Shutdown all afs state");
2499 cmd_AddParmAtOffset(ts, OPT_peerstats, "-enable_peer_stats", CMD_FLAG,
2500 CMD_OPTIONAL | CMD_HIDE,
2501 "Collect rpc statistics by peer");
2502 cmd_AddParmAtOffset(ts, OPT_processstats, "-enable_process_stats",
2503 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2504 "Collect rpc statistics for this process");
2505 cmd_AddParmAtOffset(ts, OPT_memallocsleep, "-mem_alloc_sleep",
2506 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2507 "Allow sleeps when allocating memory cache");
2508 cmd_AddParmAtOffset(ts, OPT_afsdb, "-afsdb", CMD_FLAG,
2509 CMD_OPTIONAL, "Enable AFSDB support");
2510 cmd_AddParmAtOffset(ts, OPT_filesdir, "-files_per_subdir", CMD_SINGLE,
2512 "log(2) of the number of cache files per "
2513 "cache subdirectory");
2514 cmd_AddParmAtOffset(ts, OPT_dynroot, "-dynroot", CMD_FLAG,
2515 CMD_OPTIONAL, "Enable dynroot support");
2516 cmd_AddParmAtOffset(ts, OPT_fakestat, "-fakestat", CMD_FLAG,
2518 "Enable fakestat support for cross-cell mounts");
2519 cmd_AddParmAtOffset(ts, OPT_fakestatall, "-fakestat-all", CMD_FLAG,
2521 "Enable fakestat support for all mounts");
2522 cmd_AddParmAtOffset(ts, OPT_nomount, "-nomount", CMD_FLAG,
2523 CMD_OPTIONAL, "Do not mount AFS");
2524 cmd_AddParmAtOffset(ts, OPT_backuptree, "-backuptree", CMD_FLAG,
2526 "Prefer backup volumes for mointpoints in backup "
2528 cmd_AddParmAtOffset(ts, OPT_rxbind, "-rxbind", CMD_FLAG,
2530 "Bind the Rx socket (one interface only)");
2531 cmd_AddParmAtOffset(ts, OPT_settime, "-settime", CMD_FLAG,
2532 CMD_OPTIONAL, "set the time");
2533 cmd_AddParmAtOffset(ts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
2534 "set rx_extraPackets to this value");
2535 cmd_AddParmAtOffset(ts, OPT_splitcache, "-splitcache", CMD_SINGLE,
2537 "Percentage RW versus RO in cache (specify as 60/40)");
2538 cmd_AddParmAtOffset(ts, OPT_nodynvcache, "-disable-dynamic-vcaches",
2539 CMD_FLAG, CMD_OPTIONAL,
2540 "disable stat/vcache cache growing as needed");
2541 cmd_AddParmAtOffset(ts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
2542 CMD_OPTIONAL, "set rx max MTU to use");
2543 cmd_AddParmAtOffset(ts, OPT_dynrootsparse, "-dynroot-sparse", CMD_FLAG,
2545 "Enable dynroot support with minimal cell list");
2546 cmd_AddParmAtOffset(ts, OPT_rxmaxfrags, "-rxmaxfrags", CMD_SINGLE,
2548 "Set the maximum number of UDP fragments Rx should "
2549 "send/receive per Rx packet");
2553 afsd_parse(int argc, char **argv)
2555 return cmd_Dispatch(argc, argv);
2559 * entry point for calling a syscall from another proc/thread.
2561 * @param[in] rock a struct afsd_syscall_args* specifying what syscall to call
2564 * @retval NULL always
2567 call_syscall_thread(void *rock)
2569 struct afsd_syscall_args *args = rock;
2573 afsd_set_rx_rtpri();
2576 code = afsd_call_syscall(args);
2577 if (code && args->syscall == AFSOP_START_CS) {
2578 printf("%s: No check server daemon in client.\n", args->rn);
2587 afsd_syscall_populate(struct afsd_syscall_args *args, int syscall, va_list ap)
2589 afsd_syscall_param_t *params;
2591 memset(args, 0, sizeof(struct afsd_syscall_args));
2593 args->syscall = syscall;
2594 params = args->params;
2597 case AFSOP_RXEVENT_DAEMON:
2598 case AFSOP_CLOSEWAIT:
2599 case AFSOP_START_AFS:
2600 case AFSOP_START_CS:
2601 case AFSOP_START_TRUNCDAEMON:
2603 case AFSOP_START_BKG:
2604 case AFSOP_SHUTDOWN:
2605 case AFSOP_SET_RXPCK:
2606 case AFSOP_BASIC_INIT:
2607 case AFSOP_SET_RXMAXFRAGS:
2608 case AFSOP_SET_RXMAXMTU:
2609 case AFSOP_SET_DYNROOT:
2610 case AFSOP_SET_FAKESTAT:
2611 case AFSOP_SET_BACKUPTREE:
2612 case AFSOP_BUCKETPCT:
2614 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
2616 case AFSOP_SET_THISCELL:
2617 case AFSOP_ROOTVOLUME:
2618 case AFSOP_VOLUMEINFO:
2619 case AFSOP_CACHEFILE:
2620 case AFSOP_CACHEINFO:
2621 case AFSOP_CACHEINIT:
2622 case AFSOP_CELLINFO:
2623 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2625 case AFSOP_ADDCELLALIAS:
2626 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2627 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2629 case AFSOP_AFSDB_HANDLER:
2630 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2631 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2632 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
2634 case AFSOP_BKG_HANDLER:
2635 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2636 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2637 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2639 case AFSOP_RXLISTENER_DAEMON:
2640 case AFSOP_START_RXCALLBACK:
2641 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
2642 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
2643 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
2645 case AFSOP_ADVISEADDR:
2646 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
2647 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2648 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2649 params[3] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2651 case AFSOP_ADDCELL2:
2652 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2653 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2654 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, afs_int32)));
2655 params[3] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
2657 case AFSOP_CACHEINODE:
2658 #if defined AFS_SGI62_ENV
2660 afs_int64 tmp = va_arg(ap, afs_int64);
2661 params[0] = CAST_SYSCALL_PARAM((afs_uint32)(tmp >> 32));
2662 params[1] = CAST_SYSCALL_PARAM((afs_uint32)(tmp & 0xffffffff));
2665 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, afs_uint32)));
2669 printf("Unknown syscall enountered: %d\n", syscall);
2675 * common code for calling a syscall in another proc/thread.
2677 * @param[in] rx 1 if this is a thread for RX stuff, 0 otherwise
2678 * @param[in] wait 1 if we should wait for the new proc/thread to finish, 0 to
2679 * let it run in the background
2680 * @param[in] rn the name of the running program
2681 * @param[in] syscall syscall to run
2684 fork_syscall_impl(int rx, int wait, const char *rn, int syscall, va_list ap)
2686 struct afsd_syscall_args *args;
2688 args = malloc(sizeof(*args));
2689 afsd_syscall_populate(args, syscall, ap);
2693 afsd_fork(wait, call_syscall_thread, args);
2697 * call a syscall in another process or thread.
2700 fork_syscall(const char *rn, int syscall, ...)
2704 va_start(ap, syscall);
2705 fork_syscall_impl(0, 0, rn, syscall, ap);
2710 * call a syscall in another process or thread, and give it RX priority.
2713 fork_rx_syscall(const char *rn, int syscall, ...)
2717 va_start(ap, syscall);
2718 fork_syscall_impl(1, 0, rn, syscall, ap);
2722 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
2724 * call a syscall in another process or thread, give it RX priority, and wait
2725 * for it to finish before returning.
2728 fork_rx_syscall_wait(const char *rn, int syscall, ...)
2732 va_start(ap, syscall);
2733 fork_syscall_impl(1, 1, rn, syscall, ap);
2736 #endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */
2739 afsd_syscall(int syscall, ...)
2742 struct afsd_syscall_args args;
2744 va_start(ap, syscall);
2745 afsd_syscall_populate(&args, syscall, ap);
2748 return afsd_call_syscall(&args);