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>
60 #ifdef IGNORE_SOME_GCC_WARNINGS
61 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
68 #include <afs/opr_assert.h>
74 #include <afs/afsutil.h>
81 #include <sys/types.h>
88 /* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
90 #if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
99 #ifdef HAVE_SYS_PARAM_H
100 #include <sys/param.h>
103 #ifdef HAVE_SYS_FS_TYPES_H
104 #include <sys/fs_types.h>
107 #if defined(HAVE_SYS_MOUNT_H) && !defined(AFS_ARM_DARWIN_ENV)
108 #include <sys/mount.h>
111 #ifdef HAVE_SYS_FCNTL_H
112 #include <sys/fcntl.h>
115 #ifdef HAVE_SYS_MNTTAB_H
116 #include <sys/mnttab.h>
119 #ifdef HAVE_SYS_MNTENT_H
120 #include <sys/mntent.h>
127 #ifdef HAVE_SYS_VFS_H
131 #ifdef HAVE_SYS_FSTYP_H
132 #include <sys/fstyp.h>
143 #include <netinet/in.h>
144 #include <afs/afs_args.h>
145 #include <afs/cellconfig.h>
147 #include <afs/afssyscalls.h>
148 #include <afs/afsutil.h>
149 #include <afs/sys_prototypes.h>
155 #include <libdwarf.h>
156 void set_staticaddrs(void);
157 #endif /* AFS_SGI61_ENV */
158 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
160 #include <symconst.h>
166 #ifdef AFS_DARWIN_ENV
167 #ifdef AFS_DARWIN80_ENV
168 #include <sys/ioctl.h>
169 #include <sys/xattr.h>
171 #include <CoreFoundation/CoreFoundation.h>
173 #include <SystemConfiguration/SystemConfiguration.h>
174 #include <SystemConfiguration/SCDynamicStore.h>
176 #ifndef AFS_ARM_DARWIN_ENV
177 #include <IOKit/pwr_mgt/IOPMLib.h>
178 #include <IOKit/IOMessage.h>
180 static io_connect_t root_port;
181 static IONotificationPortRef notify;
182 static io_object_t iterator;
185 static CFRunLoopSourceRef source;
187 static int event_pid;
189 #endif /* AFS_DARWIN_ENV */
191 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
192 #include <sys/statvfs.h>
194 #if defined(AFS_SUN_ENV)
197 #ifdef HAVE_SYS_STATFS_H
198 #include <sys/statfs.h>
207 #define CACHEINFOFILE "cacheinfo"
208 #define DCACHEFILE "CacheItems"
209 #define VOLINFOFILE "VolumeItems"
210 #define CELLINFOFILE "CellItems"
212 #define MAXIPADDRS 1024
214 char LclCellName[64];
216 #define MAX_CACHE_LOOPS 4
220 * Internet address (old style... should be updated). This was pulled out of the old 4.2
221 * version of <netinet/in.h>, since it's still useful.
226 u_char s_b1, s_b2, s_b3, s_b4;
235 #define mPrintIPAddr(ipaddr) printf("[%d.%d.%d.%d] ", \
236 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b1, \
237 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b2, \
238 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b3, \
239 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b4)
242 * Global configuration variables.
244 static afs_int32 enable_rxbind = 0;
245 static afs_int32 afs_shutdown = 0;
246 static afs_int32 cacheBlocks; /*Num blocks in the cache */
247 static afs_int32 cacheFiles; /*Optimal # of files in workstation cache */
248 static afs_int32 rwpct = 0;
249 static afs_int32 ropct = 0;
250 static afs_int32 cacheStatEntries; /*Number of stat cache entries */
251 static char *cacheBaseDir; /*Where the workstation AFS cache lives */
252 static char *confDir; /*Where the workstation AFS configuration lives */
253 static char fullpn_DCacheFile[1024]; /*Full pathname of DCACHEFILE */
254 static char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE */
255 static char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE */
256 static char fullpn_CacheInfo[1024]; /*Full pathname of CACHEINFO */
257 static char fullpn_VFile[1024]; /*Full pathname of data cache files */
258 static char *vFilePtr; /*Ptr to the number part of above pathname */
259 static int sawCacheMountDir = 0; /* from cmd line */
260 static int sawCacheBaseDir = 0;
261 static int sawCacheBlocks = 0;
262 static int sawDCacheSize = 0;
264 static int sawBiod = 0;
266 static int sawCacheStatEntries = 0;
267 char *afsd_cacheMountDir;
268 static char *rootVolume = NULL;
270 static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC; /*Create & truncate on open */
272 static int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open */
274 static int ownerRWmode = 0600; /*Read/write OK by owner */
275 static int filesSet = 0; /*True if number of files explicitly set */
276 static int nFilesPerDir = 2048; /* # files per cache dir */
277 #if defined(AFS_CACHE_BYPASS)
278 #define AFSD_NDAEMONS 4
280 #define AFSD_NDAEMONS 2
282 static int nDaemons = AFSD_NDAEMONS; /* Number of background daemons */
283 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
284 static int dCacheSize; /* # of dcache entries */
285 static int vCacheSize = 200; /* # of volume cache entries */
286 static int rootVolSet = 0; /*True if root volume name explicitly set */
287 int addrNum; /*Cell server address index being printed */
288 static int cacheFlags = 0; /*Flags to cache manager */
290 static int nBiods = 5; /* AIX3.1 only */
292 static int preallocs = 400; /* Def # of allocated memory blocks */
293 static int enable_peer_stats = 0; /* enable rx stats */
294 static int enable_process_stats = 0; /* enable rx stats */
295 static int enable_afsdb = 0; /* enable AFSDB support */
296 static int enable_dynroot = 0; /* enable dynroot support */
297 static int enable_fakestat = 0; /* enable fakestat support */
298 static int enable_backuptree = 0; /* enable backup tree support */
299 static int enable_nomount = 0; /* do not mount */
300 static int enable_splitcache = 0;
301 static int afsd_dynamic_vcaches = 0; /* Enable dynamic-vcache support */
302 int afsd_verbose = 0; /*Are we being chatty? */
303 int afsd_debug = 0; /*Are we printing debugging info? */
304 static int afsd_CloseSynch = 0; /*Are closes synchronous or not? */
305 static int rxmaxmtu = 0; /* Are we forcing a limit on the mtu? */
306 static int rxmaxfrags = 0; /* Are we forcing a limit on frags? */
309 #define AFSD_INO_T ino64_t
311 #define AFSD_INO_T afs_uint32
313 struct afsd_file_list {
315 struct afsd_file_list *next;
317 struct afsd_file_list **cache_dir_filelist = NULL;
318 int *cache_dir_list = NULL; /* Array of cache subdirs */
319 int *dir_for_V = NULL; /* Array: dir of each cache file.
320 * -1: file does not exist
321 * -2: file exists in top-level
322 * >=0: file exists in Dxxx
324 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
325 AFSD_INO_T *inode_for_V; /* Array of inodes for desired
328 int missing_DCacheFile = 1; /*Is the DCACHEFILE missing? */
329 int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing? */
330 int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing? */
331 int afsd_rmtsys = 0; /* Default: don't support rmtsys */
332 struct afs_cacheParams cparams; /* params passed to cache manager */
334 int PartSizeOverflow(char *path, int cs);
336 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
337 static void fork_rx_syscall_wait();
339 static void fork_rx_syscall();
340 static void fork_syscall();
384 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
386 afsd_sleep_callback(void * refCon, io_service_t service,
387 natural_t messageType, void * messageArgument )
389 switch (messageType) {
390 case kIOMessageCanSystemSleep:
391 /* Idle sleep is about to kick in; can
392 prevent sleep by calling IOCancelPowerChange, otherwise
393 if we don't ack in 30s the system sleeps anyway */
396 IOAllowPowerChange(root_port, (long)messageArgument);
399 case kIOMessageSystemWillSleep:
400 /* The system WILL go to sleep. Ack or suffer delay */
402 IOAllowPowerChange(root_port, (long)messageArgument);
405 case kIOMessageSystemWillRestart:
406 /* The system WILL restart. Ack or suffer delay */
408 IOAllowPowerChange(root_port, (long)messageArgument);
411 case kIOMessageSystemWillPowerOn:
412 case kIOMessageSystemHasPoweredOn:
413 /* coming back from sleep */
415 IOAllowPowerChange(root_port, (long)messageArgument);
419 IOAllowPowerChange(root_port, (long)messageArgument);
425 afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
427 /* parse multihomed address files */
428 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
434 parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
435 AFSDIR_CLIENT_NETINFO_FILEPATH,
436 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
439 /* Note we're refreshing */
440 code = code | 0x40000000;
441 afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
443 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
446 /* Since it's likely this means our DNS server changed, reinit now */
451 /* This function is called when the system's ip addresses may have changed. */
453 afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
455 CFRunLoopTimerRef timer;
457 timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
458 0.0, 0, 0, afsd_update_addresses, NULL);
459 CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
460 kCFRunLoopDefaultMode);
465 afsd_event_cleanup(int signo) {
467 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
469 IODeregisterForSystemPower(&iterator);
470 IOServiceClose(root_port);
471 IONotificationPortDestroy(notify);
475 /* Adapted from "Living in a Dynamic TCP/IP Environment" technote. */
477 afsd_install_events(void)
479 SCDynamicStoreContext ctx = {0};
480 SCDynamicStoreRef store;
482 root_port = IORegisterForSystemPower(0,¬ify,afsd_sleep_callback,&iterator);
485 CFRunLoopAddSource(CFRunLoopGetCurrent(),
486 IONotificationPortGetRunLoopSource(notify),
487 kCFRunLoopDefaultMode);
491 store = SCDynamicStoreCreate (NULL,
492 CFSTR ("AddIPAddressListChangeCallbackSCF"),
493 afsd_ipaddr_callback, &ctx);
498 /* Request IPV4 address change notification */
499 keys[0] = (SCDynamicStoreKeyCreateNetworkServiceEntity
500 (NULL, kSCDynamicStoreDomainState,
501 kSCCompAnyRegex, kSCEntNetIPv4));
504 /* This should tell us when the hostname(s) change. do we care? */
505 keys[N] = SCDynamicStoreKeyCreateHostNames (NULL);
508 if (keys[0] != NULL) {
509 CFArrayRef pattern_array;
511 pattern_array = CFArrayCreate (NULL, keys, 1,
512 &kCFTypeArrayCallBacks);
514 if (pattern_array != NULL)
516 SCDynamicStoreSetNotificationKeys (store, NULL, pattern_array);
517 source = SCDynamicStoreCreateRunLoopSource (NULL, store, 0);
519 CFRelease (pattern_array);
529 if (source != NULL) {
530 CFRunLoopAddSource (CFRunLoopGetCurrent(),
531 source, kCFRunLoopDefaultMode);
534 signal(SIGTERM, afsd_event_cleanup);
540 /* ParseArgs is now obsolete, being handled by cmd */
542 /*------------------------------------------------------------------------------
546 * Open the file containing the description of the workstation's AFS cache
547 * and pull out its contents. The format of this file is as follows:
549 * cacheMountDir:cacheBaseDir:cacheBlocks
555 * 0 if everything went well,
559 * Nothing interesting.
563 *---------------------------------------------------------------------------*/
566 ParseCacheInfoFile(void)
568 static char rn[] = "ParseCacheInfoFile"; /*This routine's name */
569 FILE *cachefd; /*Descriptor for cache info file */
570 int parseResult; /*Result of our fscanf() */
571 afs_int32 tCacheBlocks;
572 char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
575 printf("%s: Opening cache info file '%s'...\n", rn, fullpn_CacheInfo);
577 cachefd = fopen(fullpn_CacheInfo, "r");
579 printf("%s: Can't read cache info file '%s'\n", rn, fullpn_CacheInfo);
584 * Parse the contents of the cache info file. All chars up to the first
585 * colon are the AFS mount directory, all chars to the next colon are the
586 * full path name of the workstation cache directory and all remaining chars
587 * represent the number of blocks in the cache.
589 tCacheMountDir[0] = tCacheBaseDir[0] = '\0';
591 fscanf(cachefd, "%1024[^:]:%1024[^:]:%d", tCacheMountDir,
592 tCacheBaseDir, &tCacheBlocks);
595 * Regardless of how the parse went, we close the cache info file.
599 if (parseResult == EOF || parseResult < 3) {
600 printf("%s: Format error in cache info file!\n", rn);
601 if (parseResult == EOF)
602 printf("\tEOF encountered before any field parsed.\n");
604 printf("\t%d out of 3 fields successfully parsed.\n",
610 for (tmd = tCacheMountDir; *tmd == '\n' || *tmd == ' ' || *tmd == '\t';
612 for (tbd = tCacheBaseDir; *tbd == '\n' || *tbd == ' ' || *tbd == '\t';
614 /* now copy in the fields not explicitly overridden by cmd args */
615 if (!sawCacheMountDir)
616 afsd_cacheMountDir = strdup(tmd);
617 if (!sawCacheBaseDir)
618 cacheBaseDir = strdup(tbd);
620 cacheBlocks = tCacheBlocks;
623 printf("%s: Cache info file successfully parsed:\n", rn);
625 ("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
626 tmd, tbd, tCacheBlocks);
628 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
629 return (PartSizeOverflow(tbd, cacheBlocks));
636 * All failures to open the partition are ignored. Also if the cache dir
637 * isn't a mounted partition it's also ignored since we can't guarantee
638 * what will be stored afterwards. Too many if's. This is now purely
639 * advisory. ODS with over 2G partition also gives warning message.
642 * 0 if everything went well,
646 PartSizeOverflow(char *path, int cs)
649 afs_int64 totalblks, mint;
650 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
651 struct statvfs statbuf;
653 if (statvfs(path, &statbuf) != 0) {
656 ("statvfs failed on %s; skip checking for adequate partition space\n",
660 totalblks = statbuf.f_blocks;
661 bsize = statbuf.f_frsize;
663 if (strcmp(statbuf.f_basetype, "jfs")) {
664 fprintf(stderr, "Cache filesystem '%s' must be jfs (now %s)\n",
665 path, statbuf.f_basetype);
668 #endif /* AFS_AIX51_ENV */
670 #else /* AFS_HAVE_STATVFS */
671 struct statfs statbuf;
673 if (statfs(path, &statbuf) < 0) {
676 ("statfs failed on %s; skip checking for adequate partition space\n",
680 totalblks = statbuf.f_blocks;
681 bsize = statbuf.f_bsize;
684 return 0; /* success */
686 /* now free and totalblks are in fragment units, but we want them in 1K units */
688 totalblks *= (bsize / 1024);
690 totalblks /= (1024 / bsize);
693 mint = totalblks / 100 * 95;
696 ("Cache size (%d) must be less than 95%% of partition size (which is %lld). Lower cache size\n",
704 /*-----------------------------------------------------------------------------
708 * Given the final component of a filename expected to be a data cache file,
709 * return the integer corresponding to the file. Note: we reject names that
710 * are not a ``V'' followed by an integer. We also reject those names having
711 * the right format but lying outside the range [0..cacheFiles-1].
714 * fname : Char ptr to the filename to parse.
715 * max : integer for the highest number to accept
718 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
722 * Nothing interesting.
726 *---------------------------------------------------------------------------*/
729 doGetXFileNumber(char *fname, char filechar, int maxNum)
731 int computedVNumber; /*The computed file number we return */
732 int filenameLen; /*Number of chars in filename */
733 int currDigit; /*Current digit being processed */
736 * The filename must have at least two characters, the first of which must be a ``filechar''
737 * and the second of which cannot be a zero unless the file is exactly two chars long.
739 filenameLen = strlen(fname);
742 if (fname[0] != filechar)
744 if ((filenameLen > 2) && (fname[1] == '0'))
748 * Scan through the characters in the given filename, failing immediately if a non-digit
751 for (currDigit = 1; currDigit < filenameLen; currDigit++)
752 if (isdigit(fname[currDigit]) == 0)
756 * All relevant characters are digits. Pull out the decimal number they represent.
757 * Reject it if it's out of range, otherwise return it.
759 computedVNumber = atoi(++fname);
760 if (computedVNumber < cacheFiles)
761 return (computedVNumber);
767 GetVFileNumber(char *fname, int maxFile)
769 return doGetXFileNumber(fname, 'V', maxFile);
773 GetDDirNumber(char *fname, int maxDir)
775 return doGetXFileNumber(fname, 'D', maxDir);
779 /*-----------------------------------------------------------------------------
783 * Given a full pathname for a file we need to create for the workstation AFS
784 * cache, go ahead and create the file.
787 * fname : Full pathname of file to create.
788 * statp : A pointer to a stat buffer which, if NON-NULL, will be
792 * 0 iff the file was created,
796 * The given cache file has been found to be missing.
800 *---------------------------------------------------------------------------*/
803 CreateCacheSubDir(char *basename, int dirNum)
805 static char rn[] = "CreateCacheSubDir"; /* Routine Name */
809 /* Build the new cache subdirectory */
810 sprintf(dir, "%s/D%d", basename, dirNum);
813 printf("%s: Creating cache subdir '%s'\n", rn, dir);
815 if ((ret = mkdir(dir, 0700)) != 0) {
816 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, dir,
822 /* Mark this directory as created */
823 cache_dir_list[dirNum] = 0;
825 /* And return success */
830 SetNoBackupAttr(char *fullpn)
832 #ifdef AFS_DARWIN80_ENV
835 ret = setxattr(fullpn, "com.apple.metadata:com_apple_backup_excludeItem",
836 "com.apple.backupd", strlen("com.apple.backupd"), 0,
841 fprintf(stderr, "afsd: Warning: failed to set attribute to preclude cache backup: %s\n", strerror(errno));
848 MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
851 static char rn[] = "MoveCacheFile";
852 char from[1024], to[1024];
855 if (cache_dir_list[toDir] < 0
856 && (ret = CreateCacheSubDir(basename, toDir))) {
857 printf("%s: Can't create directory '%s/D%d'\n", rn, basename, toDir);
861 /* Build the from,to dir */
863 /* old-style location */
864 snprintf(from, sizeof(from), "%s/V%d", basename, cacheFile);
866 snprintf(from, sizeof(from), "%s/D%d/V%d", basename, fromDir,
870 snprintf(to, sizeof(from), "%s/D%d/V%d", basename, toDir, cacheFile);
873 printf("%s: Moving cacheFile from '%s' to '%s'\n", rn, from, to);
875 if ((ret = rename(from, to)) != 0) {
876 printf("%s: Can't rename '%s' to '%s', error return is %d (%d)\n", rn,
877 from, to, ret, errno);
882 /* Reset directory pointer; fix file counts */
883 dir_for_V[cacheFile] = toDir;
884 cache_dir_list[toDir]++;
885 if (fromDir < maxDir && fromDir >= 0)
886 cache_dir_list[fromDir]--;
892 CreateCacheFile(char *fname, struct stat *statp)
894 static char rn[] = "CreateCacheFile"; /*Routine name */
895 int cfd; /*File descriptor to AFS cache file */
896 int closeResult; /*Result of close() */
899 printf("%s: Creating cache file '%s'\n", rn, fname);
900 cfd = open(fname, createAndTrunc, ownerRWmode);
902 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
907 closeResult = fstat(cfd, statp);
910 ("%s: Can't stat newly-created AFS cache file '%s' (code %d)\n",
915 closeResult = close(cfd);
918 ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
927 CreateFileIfMissing(char *fullpn, int missing)
930 if (CreateCacheFile(fullpn, NULL))
931 printf("CreateFileIfMissing: Can't create '%s'\n", fullpn);
936 UnlinkUnwantedFile(char *rn, char *fullpn_FileToDelete, char *fileToDelete)
938 if (unlink(fullpn_FileToDelete)) {
939 if ((errno == EISDIR || errno == EPERM) && *fileToDelete == 'D') {
940 if (rmdir(fullpn_FileToDelete)) {
941 printf("%s: Can't rmdir '%s', errno is %d\n", rn,
942 fullpn_FileToDelete, errno);
945 printf("%s: Can't unlink '%s', errno is %d\n", rn,
946 fullpn_FileToDelete, errno);
950 /*-----------------------------------------------------------------------------
954 * Sweep through the AFS cache directory, recording the inode number for
955 * each valid data cache file there. Also, delete any file that doesn't belong
956 * in the cache directory during this sweep, and remember which of the other
957 * residents of this directory were seen. After the sweep, we create any data
958 * cache files that were missing.
961 * vFilesFound : Set to the number of data cache files found.
964 * 0 if everything went well,
968 * This routine may be called several times. If the number of data cache files
969 * found is less than the global cacheFiles, then the caller will need to call it
970 * again to record the inodes of the missing zero-length data cache files created
971 * in the previous call.
974 * Fills up the global inode_for_V array, may create and/or delete files as
976 *---------------------------------------------------------------------------*/
980 doSweepAFSCache(int *vFilesFound,
981 char *directory, /* /path/to/cache/directory */
982 int dirNum, /* current directory number */
983 int maxDir) /* maximum directory number */
985 static char rn[] = "doSweepAFSCache"; /* Routine Name */
986 char fullpn_FileToDelete[1024]; /*File to be deleted from cache */
987 char *fileToDelete; /*Ptr to last component of above */
988 DIR *cdirp; /*Ptr to cache directory structure */
990 struct dirent64 *currp; /*Current directory entry */
992 struct dirent *currp; /*Current directory entry */
994 int vFileNum; /*Data cache file's associated number */
995 int thisDir; /* A directory number */
999 printf("%s: Opening cache directory '%s'\n", rn, directory);
1001 if (chmod(directory, 0700)) { /* force it to be 700 */
1002 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
1006 cdirp = opendir(directory);
1007 if (cdirp == (DIR *) 0) {
1008 printf("%s: Can't open AFS cache directory, '%s'.\n", rn, directory);
1013 * Scan the directory entries, remembering data cache file inodes
1014 * and the existance of other important residents. Recurse into
1015 * the data subdirectories.
1017 * Delete all files and directories that don't belong here.
1019 sprintf(fullpn_FileToDelete, "%s/", directory);
1020 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
1022 #ifdef AFS_SGI62_ENV
1023 for (currp = readdir64(cdirp); currp; currp = readdir64(cdirp))
1025 for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
1029 printf("%s: Current directory entry:\n", rn);
1030 #if defined(AFS_SGI62_ENV) || defined(AFS_DARWIN90_ENV)
1031 printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
1032 currp->d_reclen, currp->d_name);
1033 #elif defined(AFS_DFBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
1034 printf("\tinode=%ld, name='%s'\n", (long)currp->d_ino, currp->d_name);
1036 printf("\tinode=%ld, reclen=%d, name='%s'\n", (long)currp->d_ino,
1037 currp->d_reclen, currp->d_name);
1042 * If dirNum < 0, we are a top-level cache directory and should
1043 * only contain sub-directories and other sundry files. Therefore,
1044 * V-files are valid only if dirNum >= 0, and Directories are only
1045 * valid if dirNum < 0.
1048 if (*(currp->d_name) == 'V'
1049 && ((vFileNum = GetVFileNumber(currp->d_name, cacheFiles)) >=
1052 * Found a valid data cache filename. Remember this
1053 * file's inode, directory, and bump the number of files found
1054 * total and in this directory.
1056 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1057 inode_for_V[vFileNum] = currp->d_ino;
1059 dir_for_V[vFileNum] = dirNum; /* remember this directory */
1062 /* If we're in a real subdir, mark this file to be moved
1063 * if we've already got too many files in this directory
1065 assert(dirNum >= 0);
1066 cache_dir_list[dirNum]++; /* keep directory's file count */
1067 if (cache_dir_list[dirNum] > nFilesPerDir) {
1068 /* Too many files -- add to filelist */
1069 struct afsd_file_list *tmp = (struct afsd_file_list *)
1070 malloc(sizeof(*tmp));
1073 ("%s: MALLOC FAILED allocating file_list entry\n",
1076 tmp->fileNum = vFileNum;
1077 tmp->next = cache_dir_filelist[dirNum];
1078 cache_dir_filelist[dirNum] = tmp;
1083 } else if (dirNum < 0 && (*(currp->d_name) == 'D')
1084 && GetDDirNumber(currp->d_name, 1 << 30) >= 0) {
1086 if ((vFileNum = GetDDirNumber(currp->d_name, maxDir)) >= 0) {
1087 /* Found a valid cachefile sub-Directory. Remember this number
1088 * and recurse into it. Note that subdirs cannot have subdirs.
1091 } else if ((vFileNum = GetDDirNumber(currp->d_name, 1 << 30)) >=
1093 /* This directory is going away, but figure out if there
1094 * are any cachefiles in here that should be saved by
1095 * moving them to other cache directories. This directory
1096 * will be removed later.
1101 /* Save the highest directory number we've seen */
1102 if (vFileNum > highDir)
1105 /* If this directory is staying, be sure to mark it as 'found' */
1107 cache_dir_list[vFileNum] = 0;
1109 /* Print the dirname for recursion */
1110 sprintf(fileToDelete, "%s", currp->d_name);
1112 /* Note: vFileNum is the directory number */
1114 doSweepAFSCache(vFilesFound, fullpn_FileToDelete, vFileNum,
1115 (retval == 1 ? 0 : -1));
1117 printf("%s: Recursive sweep failed on directory %s\n", rn,
1121 } else if (dirNum < 0 && strcmp(currp->d_name, DCACHEFILE) == 0) {
1123 * Found the file holding the dcache entries.
1125 missing_DCacheFile = 0;
1126 SetNoBackupAttr(fullpn_DCacheFile);
1127 } else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
1129 * Found the file holding the volume info.
1131 missing_VolInfoFile = 0;
1132 SetNoBackupAttr(fullpn_VolInfoFile);
1133 } else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
1135 * Found the file holding the cell info.
1137 missing_CellInfoFile = 0;
1138 SetNoBackupAttr(fullpn_CellInfoFile);
1139 } else if ((strcmp(currp->d_name, ".") == 0)
1140 || (strcmp(currp->d_name, "..") == 0) ||
1141 #ifdef AFS_DECOSF_ENV
1142 /* these are magic AdvFS files */
1143 (strcmp(currp->d_name, ".tags") == 0)
1144 || (strcmp(currp->d_name, "quota.user") == 0)
1145 || (strcmp(currp->d_name, "quota.group") == 0) ||
1147 #ifdef AFS_LINUX22_ENV
1148 /* this is the ext3 journal file */
1149 (strcmp(currp->d_name, ".journal") == 0) ||
1151 (strcmp(currp->d_name, "lost+found") == 0)) {
1153 * Don't do anything - this file is legit, and is to be left alone.
1157 * This file/directory doesn't belong in the cache. Nuke it.
1159 sprintf(fileToDelete, "%s", currp->d_name);
1161 printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
1162 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1169 * Create all the cache files that are missing.
1171 CreateFileIfMissing(fullpn_DCacheFile, missing_DCacheFile);
1172 CreateFileIfMissing(fullpn_VolInfoFile, missing_VolInfoFile);
1173 CreateFileIfMissing(fullpn_CellInfoFile, missing_CellInfoFile);
1175 /* ADJUST CACHE FILES */
1177 /* First, let's walk through the list of files and figure out
1178 * if there are any leftover files in extra directories or
1179 * missing files. Move the former and create the latter in
1180 * subdirs with extra space.
1183 thisDir = 0; /* Keep track of which subdir has space */
1185 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++) {
1186 if (dir_for_V[vFileNum] == -1) {
1187 /* This file does not exist. Create it in the first
1188 * subdir that still has extra space.
1190 while (thisDir < maxDir
1191 && cache_dir_list[thisDir] >= nFilesPerDir)
1193 if (thisDir >= maxDir)
1194 printf("%s: can't find directory to create V%d\n", rn,
1198 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1199 assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
1201 sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
1203 printf("%s: Creating '%s'\n", rn, fullpn_VFile);
1204 if (cache_dir_list[thisDir] < 0
1205 && CreateCacheSubDir(directory, thisDir))
1206 printf("%s: Can't create directory for '%s'\n", rn,
1208 if (CreateCacheFile(fullpn_VFile, &statb))
1209 printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
1211 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1212 inode_for_V[vFileNum] = statb.st_ino;
1214 dir_for_V[vFileNum] = thisDir;
1215 cache_dir_list[thisDir]++;
1218 SetNoBackupAttr(fullpn_VFile);
1221 } else if (dir_for_V[vFileNum] >= maxDir
1222 || dir_for_V[vFileNum] == -2) {
1223 /* This file needs to move; move it to the first subdir
1224 * that has extra space. (-2 means it's in the toplevel)
1226 while (thisDir < maxDir
1227 && cache_dir_list[thisDir] >= nFilesPerDir)
1229 if (thisDir >= maxDir)
1230 printf("%s: can't find directory to move V%d\n", rn,
1234 (directory, dir_for_V[vFileNum], thisDir, vFileNum,
1236 /* Cannot move. Ignore this file??? */
1243 /* At this point, we've moved all of the valid cache files
1244 * into the valid subdirs, and created all the extra
1245 * cachefiles we need to create. Next, rebalance any subdirs
1246 * with too many cache files into the directories with not
1247 * enough cache files. Note that thisDir currently sits at
1248 * the lowest subdir that _may_ have room.
1251 for (dirNum = 0; dirNum < maxDir; dirNum++) {
1252 struct afsd_file_list *thisFile;
1254 for (thisFile = cache_dir_filelist[dirNum];
1255 thisFile && cache_dir_list[dirNum] >= nFilesPerDir;
1256 thisFile = thisFile->next) {
1257 while (thisDir < maxDir
1258 && cache_dir_list[thisDir] >= nFilesPerDir)
1260 if (thisDir >= maxDir)
1261 printf("%s: can't find directory to move V%d\n", rn,
1265 (directory, dirNum, thisDir, thisFile->fileNum,
1267 /* Cannot move. Ignore this file??? */
1271 } /* for each file to move */
1272 } /* for each directory */
1274 /* Remove any directories >= maxDir -- they should be empty */
1275 for (; highDir >= maxDir; highDir--) {
1276 sprintf(fileToDelete, "D%d", highDir);
1277 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1283 * Close the directory, return success.
1286 printf("%s: Closing cache directory.\n", rn);
1292 CheckCacheBaseDir(char *dir)
1294 struct stat statbuf;
1297 return "cache base dir not specified";
1299 if (stat(dir, &statbuf) != 0) {
1300 return "unable to stat cache base directory";
1303 /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */
1305 #ifdef AFS_LINUX24_ENV
1308 struct statfs statfsbuf;
1310 res = statfs(dir, &statfsbuf);
1312 return "unable to statfs cache base directory";
1314 #if !defined(AFS_LINUX26_ENV)
1315 if (statfsbuf.f_type == 0x52654973) { /* REISERFS_SUPER_MAGIC */
1316 return "cannot use reiserfs as cache partition";
1317 } else if (statfsbuf.f_type == 0x58465342) { /* XFS_SUPER_MAGIC */
1318 return "cannot use xfs as cache partition";
1319 } else if (statfsbuf.f_type == 0x01021994) { /* TMPFS_SUPER_MAGIC */
1320 return "cannot use tmpfs as cache partition";
1321 } else if (statfsbuf.f_type != 0xEF53) {
1322 return "must use ext2 or ext3 for cache partition";
1331 struct statfs statfsbuf;
1334 res = statfs(dir, &statfsbuf);
1336 return "unable to statfs cache base directory";
1339 if (sysfs(GETFSTYP, statfsbuf.f_fsid[1], name) != 0) {
1340 return "unable to determine filesystem type for cache base dir";
1343 if (strcmp(name, "hfs")) {
1344 return "can only use hfs filesystem for cache partition on hpux";
1353 struct stat statmnt, statci;
1355 if ((stat(dir, &statci) == 0)
1356 && ((vfstab = fopen(MNTTAB, "r")) != NULL)) {
1357 while (getmntent(vfstab, &mnt) == 0) {
1358 if (strcmp(dir, mnt.mnt_mountp) != 0) {
1362 if (cp = hasmntopt(&mnt, "dev="))
1364 (int)strtol(cp + strlen("dev="), (char **)NULL,
1367 if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
1368 rdev = statmnt.st_dev;
1370 if ((rdev == statci.st_dev)
1371 && (hasmntopt(&mnt, "logging") != NULL)) {
1375 "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n";
1389 SweepAFSCache(int *vFilesFound)
1391 static char rn[] = "SweepAFSCache"; /*Routine name */
1392 int maxDir = (cacheFiles + nFilesPerDir - 1) / nFilesPerDir;
1397 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1399 printf("%s: Memory Cache, no cache sweep done\n", rn);
1403 if (cache_dir_list == NULL) {
1404 cache_dir_list = (int *)malloc(maxDir * sizeof(*cache_dir_list));
1405 if (cache_dir_list == NULL) {
1406 printf("%s: Malloc Failed!\n", rn);
1409 for (i = 0; i < maxDir; i++)
1410 cache_dir_list[i] = -1; /* Does not exist */
1413 if (cache_dir_filelist == NULL) {
1414 cache_dir_filelist = (struct afsd_file_list **)
1415 malloc(maxDir * sizeof(*cache_dir_filelist));
1416 if (cache_dir_filelist == NULL) {
1417 printf("%s: Malloc Failed!\n", rn);
1420 memset(cache_dir_filelist, 0, maxDir * sizeof(*cache_dir_filelist));
1423 if (dir_for_V == NULL) {
1424 dir_for_V = (int *)malloc(cacheFiles * sizeof(*dir_for_V));
1425 if (dir_for_V == NULL) {
1426 printf("%s: Malloc Failed!\n", rn);
1429 for (i = 0; i < cacheFiles; i++)
1430 dir_for_V[i] = -1; /* Does not exist */
1433 /* Note, setting dirNum to -2 here will cause cachefiles found in
1434 * the toplevel directory to be marked in directory "-2". This
1435 * allows us to differentiate between 'file not seen' (-1) and
1436 * 'file seen in top-level' (-2). Then when we try to move the
1437 * file into a subdirectory, we know it's in the top-level instead
1438 * of some other cache subdir.
1440 return doSweepAFSCache(vFilesFound, cacheBaseDir, -2, maxDir);
1444 ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
1448 afs_int32 cellFlags = 0;
1449 afs_int32 hosts[MAXHOSTSPERCELL];
1451 /* figure out if this is the home cell */
1452 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
1454 cellFlags = 2; /* not home, suid is forbidden */
1455 if (enable_dynroot == 2)
1456 cellFlags |= 8; /* don't display foreign cells until looked up */
1458 /* build address list */
1459 for (i = 0; i < MAXHOSTSPERCELL; i++)
1460 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1462 if (aci->linkedCell)
1463 cellFlags |= 4; /* Flag that linkedCell arg exists,
1464 * for upwards compatibility */
1466 /* configure one cell */
1467 code = afsd_call_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
1468 aci->name, /* cell name */
1469 cellFlags, /* is this the home cell? */
1470 aci->linkedCell); /* Linked cell, if any */
1472 printf("Adding cell '%s': error %d\n", aci->name, code);
1477 ConfigCellAlias(struct afsconf_cellalias *aca,
1478 void *arock, struct afsconf_dir *adir)
1480 /* push the alias into the kernel */
1481 afsd_call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
1486 AfsdbLookupHandler(void)
1488 afs_int32 kernelMsg[64];
1489 char acellName[128];
1491 struct afsconf_cell acellInfo;
1496 acellName[0] = '\0';
1498 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
1499 /* Fork the event handler also. */
1502 afsd_install_events();
1504 } else if (code != -1) {
1509 /* On some platforms you only get 4 args to an AFS call */
1510 int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
1512 afsd_call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
1513 if (code) { /* Something is wrong? */
1518 if (*acellName == 1) /* Shutting down */
1521 code = afsconf_GetAfsdbInfo(acellName, 0, &acellInfo);
1526 kernelMsg[0] = acellInfo.numServers;
1527 if (acellInfo.timeout)
1528 kernelMsg[1] = acellInfo.timeout - time(0);
1531 for (i = 0; i < acellInfo.numServers; i++)
1532 kernelMsg[i + 2] = acellInfo.hostAddr[i].sin_addr.s_addr;
1533 strncpy(acellName, acellInfo.name, sizeof(acellName));
1534 acellName[sizeof(acellName) - 1] = '\0';
1537 #ifdef AFS_DARWIN_ENV
1538 kill(event_pid, SIGTERM);
1547 struct afs_uspc_param *uspc;
1551 uspc = (struct afs_uspc_param *)malloc(sizeof(struct afs_uspc_param));
1552 memset(uspc, 0, sizeof(struct afs_uspc_param));
1553 memset(srcName, 0, sizeof(srcName));
1554 memset(dstName, 0, sizeof(dstName));
1556 /* brscount starts at 0 */
1562 char srcpath[BUFSIZ];
1563 char dstpath[BUFSIZ];
1565 /* pushing in a buffer this large */
1568 code = afsd_call_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
1569 if (code) { /* Something is wrong? */
1570 if (code == -2) /* shutting down */
1578 switch (uspc->reqtype) {
1580 snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1581 uspc->req.umv.sCell, uspc->req.umv.sVolume,
1582 uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
1583 snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1584 uspc->req.umv.dCell, uspc->req.umv.dVolume,
1585 uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
1586 if ((child = fork()) == 0) {
1587 /* first child does cp; second, rm. mv would re-enter. */
1589 switch (uspc->req.umv.idtype) {
1591 if (setuid(uspc->req.umv.id) != 0) {
1597 break; /* notreached */
1599 execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
1600 dstpath, (char *) NULL);
1602 if (child == (pid_t) -1) {
1607 if (waitpid(child, &status, 0) == -1)
1609 else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
1610 if ((child = fork()) == 0) {
1611 switch (uspc->req.umv.idtype) {
1613 if (setuid(uspc->req.umv.id) != 0) {
1619 break; /* notreached */
1621 execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
1622 srcpath, (char *) NULL);
1624 if (child == (pid_t) -1) {
1628 if (waitpid(child, &status, 0) == -1)
1630 else if (WIFEXITED(status) != 0) {
1631 /* rm exit status */
1632 uspc->retval = WEXITSTATUS(status);
1634 /* rm signal status */
1635 uspc->retval = -(WTERMSIG(status));
1638 /* error from cp: exit or signal status */
1639 uspc->retval = (WIFEXITED(status) != 0) ?
1640 WEXITSTATUS(status) : -(WTERMSIG(status));
1642 memset(srcName, 0, sizeof(srcName));
1643 memset(dstName, 0, sizeof(dstName));
1647 /* unknown req type */
1656 afsdb_thread(void *rock)
1658 /* Since the AFSDB lookup handler runs as a user process,
1659 * need to drop the controlling TTY, etc.
1661 if (afsd_daemon(0, 0) == -1) {
1662 printf("Error starting AFSDB lookup handler: %s\n",
1666 AfsdbLookupHandler();
1671 daemon_thread(void *rock)
1674 /* Since the background daemon runs as a user process,
1675 * need to drop the controlling TTY, etc.
1677 if (afsd_daemon(0, 0) == -1) {
1678 printf("Error starting background daemon: %s\n",
1683 #elif defined(AFS_AIX32_ENV)
1684 afsd_call_syscall(AFSOP_START_BKG, 0);
1686 afsd_call_syscall(AFSOP_START_BKG);
1693 rmtsysd_thread(void *rock)
1698 #endif /* !UKERNEL */
1701 mainproc(struct cmd_syndesc *as, void *arock)
1703 afs_int32 code; /*Result of fork() */
1707 #ifdef AFS_SGI65_ENV
1708 struct sched_param sp;
1711 #ifdef AFS_SGI_VNODE_GLUE
1712 if (afs_init_kernel_config(-1) < 0) {
1713 printf("Can't determine NUMA configuration, not starting AFS.\n");
1718 /* call atoi on the appropriate parsed results */
1719 if (cmd_OptionAsInt(as, OPT_blocks, &cacheBlocks) == 0)
1722 if (cmd_OptionAsInt(as, OPT_files, &cacheFiles) == 0)
1725 if (cmd_OptionAsString(as, OPT_rootvol, &rootVolume) == 0)
1728 if (cmd_OptionAsInt(as, OPT_stat, &cacheStatEntries) == 0)
1729 sawCacheStatEntries = 1;
1731 if (cmd_OptionPresent(as, OPT_memcache)) {
1732 cacheBaseDir = NULL;
1733 sawCacheBaseDir = 1;
1734 cacheFlags |= AFSCALL_INIT_MEMCACHE;
1737 if (cmd_OptionAsString(as, OPT_cachedir, &cacheBaseDir) == 0)
1738 sawCacheBaseDir = 1;
1740 if (cmd_OptionAsString(as, OPT_mountdir, &afsd_cacheMountDir) == 0)
1741 sawCacheMountDir = 1;
1743 cmd_OptionAsInt(as, OPT_daemons, &nDaemons);
1745 afsd_verbose = cmd_OptionPresent(as, OPT_verbose);
1747 if (cmd_OptionPresent(as, OPT_rmtsys)) {
1750 printf("-rmtsys not supported for UKERNEL\n");
1755 if (cmd_OptionPresent(as, OPT_debug)) {
1760 if (cmd_OptionAsInt(as, OPT_chunksize, &chunkSize) == 0) {
1761 if (chunkSize < 0 || chunkSize > 30) {
1763 ("afsd:invalid chunk size (not in range 0-30), using default\n");
1768 if (cmd_OptionAsInt(as, OPT_dcache, &dCacheSize))
1771 cmd_OptionAsInt(as, OPT_volumes, &vCacheSize);
1773 if (cmd_OptionPresent(as, OPT_biods)) {
1775 #ifndef AFS_AIX32_ENV
1777 ("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
1779 cmd_OptionAsInt(as, OPT_biods, &nBiods);
1782 cmd_OptionAsInt(as, OPT_prealloc, &preallocs);
1784 if (cmd_OptionAsString(as, OPT_confdir, &confDir) == CMD_MISSING) {
1785 confDir = strdup(AFSDIR_CLIENT_ETC_DIRPATH);
1787 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
1789 if (cmd_OptionPresent(as, OPT_logfile)) {
1790 printf("afsd: Ignoring obsolete -logfile flag\n");
1793 afsd_CloseSynch = cmd_OptionPresent(as, OPT_waitclose);
1795 if (cmd_OptionPresent(as, OPT_shutdown)) {
1799 * Cold shutdown is the default
1801 printf("afsd: Shutting down all afs processes and afs state\n");
1802 code = afsd_call_syscall(AFSOP_SHUTDOWN, 1);
1804 printf("afsd: AFS still mounted; Not shutting down\n");
1810 enable_peer_stats = cmd_OptionPresent(as, OPT_peerstats);
1811 enable_process_stats = cmd_OptionPresent(as, OPT_processstats);
1813 if (cmd_OptionPresent(as, OPT_memallocsleep)) {
1814 printf("afsd: -mem_alloc_sleep is deprecated -- ignored\n");
1817 enable_afsdb = cmd_OptionPresent(as, OPT_afsdb);
1818 if (cmd_OptionPresent(as, OPT_filesdir)) {
1819 /* -files_per_subdir */
1821 cmd_OptionAsInt(as, OPT_filesdir, &res);
1822 if (res < 10 || res > (1 << 30)) {
1824 ("afsd:invalid number of files per subdir, \"%s\". Ignored\n",
1825 as->parms[25].items->data);
1830 enable_dynroot = cmd_OptionPresent(as, OPT_dynroot);
1832 if (cmd_OptionPresent(as, OPT_fakestat)) {
1833 enable_fakestat = 2;
1835 if (cmd_OptionPresent(as, OPT_fakestatall)) {
1836 enable_fakestat = 1;
1838 if (cmd_OptionPresent(as, OPT_settime)) {
1840 printf("afsd: -settime ignored\n");
1841 printf("afsd: the OpenAFS client no longer sets the system time; "
1842 "please use NTP or\n");
1843 printf("afsd: another such system to synchronize client time\n");
1846 enable_nomount = cmd_OptionPresent(as, OPT_nomount);
1847 enable_backuptree = cmd_OptionPresent(as, OPT_backuptree);
1848 enable_rxbind = cmd_OptionPresent(as, OPT_rxbind);
1850 /* set rx_extraPackets */
1851 if (cmd_OptionPresent(as, OPT_rxpck)) {
1854 cmd_OptionAsInt(as, OPT_rxpck, &rxpck);
1855 printf("afsd: set rxpck = %d\n", rxpck);
1856 code = afsd_call_syscall(AFSOP_SET_RXPCK, rxpck);
1858 printf("afsd: failed to set rxpck\n");
1862 if (cmd_OptionPresent(as, OPT_splitcache)) {
1866 cmd_OptionAsString(as, OPT_splitcache, &var);
1868 if (var == NULL || ((c = strchr(var, '/')) == NULL))
1870 ("ignoring splitcache (specify as RW/RO percentages: 60/40)\n");
1872 ropct = atoi(c + 1);
1875 if ((rwpct != 0) && (ropct != 0) && (ropct + rwpct == 100)) {
1877 enable_splitcache = 1;
1882 if (cmd_OptionPresent(as, OPT_nodynvcache)) {
1883 #ifdef AFS_MAXVCOUNT_ENV
1884 afsd_dynamic_vcaches = 0;
1886 printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
1890 #ifdef AFS_MAXVCOUNT_ENV
1892 /* -dynamic-vcaches */
1893 afsd_dynamic_vcaches = 1;
1897 printf("afsd: %s dynamically allocated vcaches\n", ( afsd_dynamic_vcaches ? "enabling" : "disabling" ));
1900 cmd_OptionAsInt(as, OPT_rxmaxmtu, &rxmaxmtu);
1902 if (cmd_OptionPresent(as, OPT_dynrootsparse)) {
1906 cmd_OptionAsInt(as, OPT_rxmaxfrags, &rxmaxfrags);
1908 /* parse cacheinfo file if this is a diskcache */
1909 if (ParseCacheInfoFile()) {
1919 static char rn[] = "afsd"; /*Name of this routine */
1920 struct afsconf_dir *cdir; /* config dir */
1921 int lookupResult; /*Result of GetLocalCellName() */
1923 afs_int32 code; /*Result of fork() */
1924 char *fsTypeMsg = NULL;
1925 int cacheIteration; /*How many times through cache verification */
1926 int vFilesFound; /*How many data cache files were found in sweep */
1927 int currVFile; /*Current AFS cache file number passed in */
1930 * Pull out all the configuration info for the workstation's AFS cache and
1931 * the cellular community we're willing to let our users see.
1933 cdir = afsconf_Open(confDir);
1935 printf("afsd: some file missing or bad in %s\n", confDir);
1940 afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
1942 printf("%s: Can't get my home cell name! [Error is %d]\n", rn,
1946 printf("%s: My home cell is '%s'\n", rn, LclCellName);
1949 if (!enable_nomount) {
1950 if (afsd_check_mount(rn, afsd_cacheMountDir)) {
1955 /* do some random computations in memcache case to get things to work
1956 * reasonably no matter which parameters you set.
1958 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1959 /* memory cache: size described either as blocks or dcache entries, but
1963 fprintf(stderr, "%s: -files ignored with -memcache\n", rn);
1965 if (sawDCacheSize) {
1966 if (chunkSize == 0) {
1967 chunkSize = 13; /* 8k default chunksize for memcache */
1969 if (sawCacheBlocks) {
1971 ("%s: can't set cache blocks and dcache size simultaneously when diskless.\n",
1975 /* compute the cache size based on # of chunks times the chunk size */
1976 i = (1 << chunkSize); /* bytes per chunk */
1977 cacheBlocks = i * dCacheSize;
1978 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
1980 if (chunkSize == 0) {
1981 /* Try to autotune the memcache chunksize based on size
1982 * of memcache. This is done on the assumption that approx
1983 * 1024 chunks is suitable, it's a balance between enough
1984 * chunks to be useful and ramping up nicely when using larger
1985 * memcache to improve bulk read/write performance
1988 i <= 21 && (1 << i) / 1024 < (cacheBlocks / 1024); i++);
1991 /* compute the dcache size from overall cache size and chunk size */
1992 if (chunkSize > 10) {
1993 dCacheSize = (cacheBlocks >> (chunkSize - 10));
1994 } else if (chunkSize < 10) {
1995 dCacheSize = (cacheBlocks << (10 - chunkSize));
1997 dCacheSize = cacheBlocks;
1999 /* don't have to set sawDCacheSize here since it isn't overwritten
2000 * by ParseCacheInfoFile.
2004 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
2006 /* kernel computes # of dcache entries as min of cacheFiles and
2007 * dCacheSize, so we now make them equal.
2009 cacheFiles = dCacheSize;
2012 * Compute the number of cache files based on cache size,
2013 * but only if -files isn't given on the command line.
2014 * Don't let # files be so small as to prevent full utilization
2015 * of the cache unless user has explicitly asked for it.
2017 if (chunkSize == 0) {
2018 /* Set chunksize to 256kB - 1MB depending on cache size */
2019 if (cacheBlocks < 500000) {
2021 } else if (cacheBlocks < 1000000) {
2029 cacheFiles = cacheBlocks / 32; /* Assume 32k avg filesize */
2031 cacheFiles = max(cacheFiles, 1000);
2033 /* Always allow more files than chunks. Presume average V-file
2034 * is ~67% of a chunk... (another guess, perhaps Honeyman will
2035 * have a grad student write a paper). i is KILOBYTES.
2037 i = 1 << (chunkSize < 10 ? 0 : chunkSize - 10);
2038 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
2040 /* never permit more files than blocks, while leaving space for
2041 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
2042 * CacheItems is 50 Bytes / file (== 1K/20)
2044 #define CACHEITMSZ (cacheFiles / 20)
2045 #define VOLINFOSZ 50 /* 40kB has been seen, be conservative */
2046 #define CELLINFOSZ 4 /* Assuming disk block size is 4k ... */
2047 #define INFOSZ (VOLINFOSZ+CELLINFOSZ+CACHEITMSZ)
2049 /* Sanity check: If the obtained number of disk cache files
2050 * is larger than the number of available (4k) disk blocks, we're
2051 * doing something wrong. Fail hard so we can fix the bug instead
2052 * of silently hiding it like before */
2054 if (cacheFiles > (cacheBlocks - INFOSZ) / 4) {
2056 "%s: ASSERT: cacheFiles %d diskblocks %d\n",
2057 rn, cacheFiles, (cacheBlocks - INFOSZ) / 4);
2060 if (cacheFiles < 100)
2061 fprintf(stderr, "%s: WARNING: cache probably too small!\n",
2065 printf("%s: cacheFiles autotuned to %d\n", rn, cacheFiles);
2068 /* This actually needs to
2070 2) not second-guess when a chunksize comes from the command line
2071 3) be less, um, small. 2^2??
2073 /* Sanity check chunkSize */
2074 i = max(cacheBlocks / 1000, cacheBlocks / cacheFiles);
2075 chunkSize = min(chunkSize, i);
2076 chunkSize = max(chunkSize, 2);
2078 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
2081 if (!sawDCacheSize) {
2082 dCacheSize = cacheFiles / 2;
2083 if (dCacheSize > 10000) {
2086 if (dCacheSize < 2000) {
2090 printf("%s: dCacheSize autotuned to %d\n", rn, dCacheSize);
2093 if (!sawCacheStatEntries) {
2094 if (chunkSize <= 13) {
2095 cacheStatEntries = dCacheSize / 4;
2096 } else if (chunkSize >= 16) {
2097 cacheStatEntries = dCacheSize * 1.5;
2099 cacheStatEntries = dCacheSize;
2102 printf("%s: cacheStatEntries autotuned to %d\n", rn,
2106 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
2108 * Create and zero the inode table for the desired cache files.
2110 inode_for_V = (AFSD_INO_T *) malloc(cacheFiles * sizeof(AFSD_INO_T));
2111 if (inode_for_V == (AFSD_INO_T *) 0) {
2113 ("%s: malloc() failed for cache file inode table with %d entries.\n",
2117 memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
2119 printf("%s: %d inode_for_V entries at 0x%x, %lu bytes\n", rn,
2120 cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
2124 * Set up all the pathnames we'll need for later.
2126 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
2127 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
2128 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
2129 sprintf(fullpn_VFile, "%s/", cacheBaseDir);
2130 vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
2132 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)
2133 && (fsTypeMsg = CheckCacheBaseDir(cacheBaseDir))) {
2135 printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2137 printf("%s: ERROR: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2143 * Set up all the kernel processes needed for AFS.
2146 setpgrp(getpid(), 0);
2150 * Set the primary cell name.
2152 afsd_call_syscall(AFSOP_SET_THISCELL, LclCellName);
2154 /* Initialize RX daemons and services */
2156 /* initialize the rx random number generator from user space */
2158 /* parse multihomed address files */
2159 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
2163 parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
2164 AFSDIR_CLIENT_NETINFO_FILEPATH,
2165 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
2168 code = code | 0x80000000;
2169 afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
2171 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
2175 /* Set realtime priority for most threads to same as for biod's. */
2176 afsd_set_afsd_rtpri();
2178 /* Start listener, then callback listener. Lastly, start rx event daemon.
2179 * Change in ordering is so that Linux port has socket fd in listener
2181 * preallocs are passed for both listener and callback server. Only
2182 * the one which actually does the initialization uses them though.
2184 if (preallocs < cacheStatEntries + 50)
2185 preallocs = cacheStatEntries + 50;
2186 #ifdef RXK_LISTENER_ENV
2188 printf("%s: Forking rx listener daemon.\n", rn);
2189 # ifdef AFS_SUN510_ENV
2190 fork_rx_syscall_wait(rn, AFSOP_RXLISTENER_DAEMON, preallocs,
2191 enable_peer_stats, enable_process_stats);
2192 # else /* !AFS_SUN510_ENV */
2193 fork_rx_syscall(rn, AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
2194 enable_process_stats);
2195 # endif /* !AFS_SUN510_ENV */
2198 printf("%s: Forking rx callback listener.\n", rn);
2199 #ifndef RXK_LISTENER_ENV
2200 fork_rx_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, enable_peer_stats,
2201 enable_process_stats);
2203 fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs);
2205 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
2207 printf("%s: Forking rxevent daemon.\n", rn);
2208 fork_rx_syscall(rn, AFSOP_RXEVENT_DAEMON);
2213 printf("%s: Forking AFSDB lookup handler.\n", rn);
2214 afsd_fork(0, afsdb_thread, NULL);
2216 code = afsd_call_syscall(AFSOP_BASIC_INIT, 1);
2218 printf("%s: Error %d in basic initialization.\n", rn, code);
2223 * Tell the kernel some basic information about the workstation's cache.
2227 ("%s: Calling AFSOP_CACHEINIT: %d stat cache entries, %d optimum cache files, %d blocks in the cache, flags = 0x%x, dcache entries %d\n",
2228 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
2230 memset(&cparams, '\0', sizeof(cparams));
2231 cparams.cacheScaches = cacheStatEntries;
2232 cparams.cacheFiles = cacheFiles;
2233 cparams.cacheBlocks = cacheBlocks;
2234 cparams.cacheDcaches = dCacheSize;
2235 cparams.cacheVolumes = vCacheSize;
2236 cparams.chunkSize = chunkSize;
2237 cparams.setTimeFlag = 0;
2238 cparams.memCacheFlag = cacheFlags;
2239 cparams.dynamic_vcaches = afsd_dynamic_vcaches;
2240 afsd_call_syscall(AFSOP_CACHEINIT, &cparams);
2242 /* do it before we init the cache inodes */
2243 if (enable_splitcache) {
2244 afsd_call_syscall(AFSOP_BUCKETPCT, 1, rwpct);
2245 afsd_call_syscall(AFSOP_BUCKETPCT, 2, ropct);
2248 if (afsd_CloseSynch)
2249 afsd_call_syscall(AFSOP_CLOSEWAIT);
2252 * Sweep the workstation AFS cache directory, remembering the inodes of
2253 * valid files and deleting extraneous files. Keep sweeping until we
2254 * have the right number of data cache files or we've swept too many
2257 * This also creates files in the cache directory like VolumeItems and
2258 * CellItems, and thus must be ran before those are sent to the kernel.
2261 printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
2263 /* Memory-cache based system doesn't need any of this */
2264 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2267 if (SweepAFSCache(&vFilesFound)) {
2268 printf("%s: Error on sweep %d of workstation AFS cache \
2269 directory.\n", rn, cacheIteration);
2274 ("%s: %d out of %d data cache files found in sweep %d.\n",
2275 rn, vFilesFound, cacheFiles, cacheIteration);
2276 } while ((vFilesFound < cacheFiles)
2277 && (cacheIteration < MAX_CACHE_LOOPS));
2278 } else if (afsd_verbose)
2279 printf("%s: Using memory cache, not swept\n", rn);
2282 * Pass the kernel the name of the workstation cache file holding the
2286 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
2288 /* once again, meaningless for a memory-based cache. */
2289 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2290 afsd_call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
2293 * Pass the kernel the name of the workstation cache file holding the
2296 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2298 printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
2299 fullpn_CellInfoFile);
2300 afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
2305 printf("%s: Setting rxmaxfrags in kernel = %d\n", rn, rxmaxfrags);
2306 code = afsd_call_syscall(AFSOP_SET_RXMAXFRAGS, rxmaxfrags);
2308 printf("%s: Error seting rxmaxfrags\n", rn);
2313 printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
2314 code = afsd_call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
2316 printf("%s: Error seting rxmaxmtu\n", rn);
2319 if (enable_dynroot) {
2321 printf("%s: Enabling dynroot support in kernel%s.\n", rn,
2322 (enable_dynroot==2)?", not showing cells.":"");
2323 code = afsd_call_syscall(AFSOP_SET_DYNROOT, 1);
2325 printf("%s: Error enabling dynroot support.\n", rn);
2328 if (enable_fakestat) {
2330 printf("%s: Enabling fakestat support in kernel%s.\n", rn,
2331 (enable_fakestat==2)?" for all mountpoints."
2332 :" for crosscell mountpoints");
2333 code = afsd_call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
2335 printf("%s: Error enabling fakestat support.\n", rn);
2338 if (enable_backuptree) {
2340 printf("%s: Enabling backup tree support in kernel.\n", rn);
2341 code = afsd_call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
2343 printf("%s: Error enabling backup tree support.\n", rn);
2347 * Tell the kernel about each cell in the configuration.
2349 afsconf_CellApply(cdir, ConfigCell, NULL);
2350 afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
2352 /* Initialize AFS daemon threads. */
2354 printf("%s: Forking AFS daemon.\n", rn);
2355 fork_syscall(rn, AFSOP_START_AFS);
2358 printf("%s: Forking Check Server Daemon.\n", rn);
2359 fork_syscall(rn, AFSOP_START_CS);
2362 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
2363 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
2364 /* Add one because for sgi we always "steal" the first daemon for a
2365 * different task if we only have a 4K stack.
2369 for (i = 0; i < nDaemons; i++) {
2370 afsd_fork(0, daemon_thread, NULL);
2372 #ifdef AFS_AIX32_ENV
2374 nBiods = nDaemons * 2;
2377 for (i = 0; i < nBiods; i++) {
2378 fork_syscall(rn, AFSOP_START_BKG, nBiods);
2383 * If the root volume has been explicitly set, tell the kernel.
2387 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
2389 afsd_call_syscall(AFSOP_ROOTVOLUME, rootVolume);
2393 * Pass the kernel the name of the workstation cache file holding the
2394 * volume information.
2397 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
2398 fullpn_VolInfoFile);
2399 /* once again, meaningless for a memory-based cache. */
2400 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2401 afsd_call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
2404 * Give the kernel the names of the AFS files cached on the workstation's
2409 ("%s: Calling AFSOP_CACHEFILE for each of the %d files in '%s'\n",
2410 rn, cacheFiles, cacheBaseDir);
2411 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2412 /* ... and again ... */
2413 int nocachefile = 0;
2414 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
2416 sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
2417 code = afsd_call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
2419 if (currVFile == 0) {
2422 ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
2423 rn, cacheFiles, cacheBaseDir);
2427 ("%s: Error calling AFSOP_CACHEFILE for '%s'\n",
2434 /* fall through to setup-by-inode */
2436 #ifdef AFS_SGI62_ENV
2437 afsd_call_syscall(AFSOP_CACHEINODE,
2438 (afs_uint32) (inode_for_V[currVFile] >> 32),
2439 (afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
2440 #elif !(defined(AFS_LINUX26_ENV) || defined(AFS_CACHE_VNODE_PATH))
2441 afsd_call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
2444 ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
2452 * All the necessary info has been passed into the kernel to run an AFS
2453 * system. Give the kernel our go-ahead.
2456 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
2458 afsd_call_syscall(AFSOP_GO, 0);
2461 * At this point, we have finished passing the kernel all the info
2462 * it needs to set up the AFS. Mount the AFS root.
2464 printf("%s: All AFS daemons started.\n", rn);
2467 printf("%s: Forking trunc-cache daemon.\n", rn);
2468 fork_syscall(rn, AFSOP_START_TRUNCDAEMON);
2470 if (!enable_nomount) {
2471 afsd_mount_afs(rn, afsd_cacheMountDir);
2477 printf("%s: Forking 'rmtsys' daemon.\n", rn);
2478 afsd_fork(0, rmtsysd_thread, NULL);
2480 #endif /* !UKERNEL */
2482 * Exit successfully.
2487 #include "AFS_component_version_number.c"
2492 struct cmd_syndesc *ts;
2494 ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
2497 cmd_AddParmAtOffset(ts, OPT_blocks, "-blocks", CMD_SINGLE,
2498 CMD_OPTIONAL, "1024 byte blocks in cache");
2499 cmd_AddParmAtOffset(ts, OPT_files, "-files", CMD_SINGLE,
2500 CMD_OPTIONAL, "files in cache");
2501 cmd_AddParmAtOffset(ts, OPT_rootvol, "-rootvol", CMD_SINGLE,
2502 CMD_OPTIONAL, "name of AFS root volume");
2503 cmd_AddParmAtOffset(ts, OPT_stat, "-stat", CMD_SINGLE,
2504 CMD_OPTIONAL, "number of stat entries");
2505 cmd_AddParmAtOffset(ts, OPT_memcache, "-memcache", CMD_FLAG,
2506 CMD_OPTIONAL, "run diskless");
2507 cmd_AddParmAtOffset(ts, OPT_cachedir, "-cachedir", CMD_SINGLE,
2508 CMD_OPTIONAL, "cache directory");
2509 cmd_AddParmAtOffset(ts, OPT_mountdir, "-mountdir", CMD_SINGLE,
2510 CMD_OPTIONAL, "mount location");
2511 cmd_AddParmAtOffset(ts, OPT_daemons, "-daemons", CMD_SINGLE,
2512 CMD_OPTIONAL, "number of daemons to use");
2513 cmd_AddParmAtOffset(ts, OPT_nosettime, "-nosettime", CMD_FLAG,
2514 CMD_OPTIONAL, "don't set the time");
2515 cmd_AddParmAtOffset(ts, OPT_verbose, "-verbose", CMD_FLAG,
2516 CMD_OPTIONAL, "display lots of information");
2517 cmd_AddParmAtOffset(ts, OPT_rmtsys, "-rmtsys", CMD_FLAG,
2518 CMD_OPTIONAL, "start NFS rmtsysd program");
2519 cmd_AddParmAtOffset(ts, OPT_debug, "-debug", CMD_FLAG,
2520 CMD_OPTIONAL, "display debug info");
2521 cmd_AddParmAtOffset(ts, OPT_chunksize, "-chunksize", CMD_SINGLE,
2522 CMD_OPTIONAL, "log(2) of chunk size");
2523 cmd_AddParmAtOffset(ts, OPT_dcache, "-dcache", CMD_SINGLE,
2524 CMD_OPTIONAL, "number of dcache entries");
2525 cmd_AddParmAtOffset(ts, OPT_volumes, "-volumes", CMD_SINGLE,
2526 CMD_OPTIONAL, "number of volume entries");
2527 cmd_AddParmAtOffset(ts, OPT_biods, "-biods", CMD_SINGLE,
2528 CMD_OPTIONAL, "number of bkg I/O daemons (aix vm)");
2529 cmd_AddParmAtOffset(ts, OPT_prealloc, "-prealloc", CMD_SINGLE,
2530 CMD_OPTIONAL, "number of 'small' preallocated blocks");
2531 cmd_AddParmAtOffset(ts, OPT_confdir, "-confdir", CMD_SINGLE,
2532 CMD_OPTIONAL, "configuration directory");
2533 cmd_AddParmAtOffset(ts, OPT_logfile, "-logfile", CMD_SINGLE,
2534 CMD_OPTIONAL, "Place to keep the CM log");
2535 cmd_AddParmAtOffset(ts, OPT_waitclose, "-waitclose", CMD_FLAG,
2536 CMD_OPTIONAL, "make close calls synchronous");
2537 cmd_AddParmAtOffset(ts, OPT_shutdown, "-shutdown", CMD_FLAG,
2538 CMD_OPTIONAL, "Shutdown all afs state");
2539 cmd_AddParmAtOffset(ts, OPT_peerstats, "-enable_peer_stats", CMD_FLAG,
2540 CMD_OPTIONAL | CMD_HIDE,
2541 "Collect rpc statistics by peer");
2542 cmd_AddParmAtOffset(ts, OPT_processstats, "-enable_process_stats",
2543 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2544 "Collect rpc statistics for this process");
2545 cmd_AddParmAtOffset(ts, OPT_memallocsleep, "-mem_alloc_sleep",
2546 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2547 "Allow sleeps when allocating memory cache");
2548 cmd_AddParmAtOffset(ts, OPT_afsdb, "-afsdb", CMD_FLAG,
2549 CMD_OPTIONAL, "Enable AFSDB support");
2550 cmd_AddParmAtOffset(ts, OPT_filesdir, "-files_per_subdir", CMD_SINGLE,
2552 "log(2) of the number of cache files per "
2553 "cache subdirectory");
2554 cmd_AddParmAtOffset(ts, OPT_dynroot, "-dynroot", CMD_FLAG,
2555 CMD_OPTIONAL, "Enable dynroot support");
2556 cmd_AddParmAtOffset(ts, OPT_fakestat, "-fakestat", CMD_FLAG,
2558 "Enable fakestat support for cross-cell mounts");
2559 cmd_AddParmAtOffset(ts, OPT_fakestatall, "-fakestat-all", CMD_FLAG,
2561 "Enable fakestat support for all mounts");
2562 cmd_AddParmAtOffset(ts, OPT_nomount, "-nomount", CMD_FLAG,
2563 CMD_OPTIONAL, "Do not mount AFS");
2564 cmd_AddParmAtOffset(ts, OPT_backuptree, "-backuptree", CMD_FLAG,
2566 "Prefer backup volumes for mointpoints in backup "
2568 cmd_AddParmAtOffset(ts, OPT_rxbind, "-rxbind", CMD_FLAG,
2570 "Bind the Rx socket (one interface only)");
2571 cmd_AddParmAtOffset(ts, OPT_settime, "-settime", CMD_FLAG,
2572 CMD_OPTIONAL, "set the time");
2573 cmd_AddParmAtOffset(ts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
2574 "set rx_extraPackets to this value");
2575 cmd_AddParmAtOffset(ts, OPT_splitcache, "-splitcache", CMD_SINGLE,
2577 "Percentage RW versus RO in cache (specify as 60/40)");
2578 cmd_AddParmAtOffset(ts, OPT_nodynvcache, "-disable-dynamic-vcaches",
2579 CMD_FLAG, CMD_OPTIONAL,
2580 "disable stat/vcache cache growing as needed");
2581 cmd_AddParmAtOffset(ts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
2582 CMD_OPTIONAL, "set rx max MTU to use");
2583 cmd_AddParmAtOffset(ts, OPT_dynrootsparse, "-dynroot-sparse", CMD_FLAG,
2585 "Enable dynroot support with minimal cell list");
2586 cmd_AddParmAtOffset(ts, OPT_rxmaxfrags, "-rxmaxfrags", CMD_SINGLE,
2588 "Set the maximum number of UDP fragments Rx should "
2589 "send/receive per Rx packet");
2593 afsd_parse(int argc, char **argv)
2595 return cmd_Dispatch(argc, argv);
2598 struct afsd_syscall_args {
2610 * entry point for calling a syscall from another proc/thread.
2612 * @param[in] rock a struct afsd_syscall_args* specifying what syscall to call
2615 * @retval NULL always
2618 call_syscall_thread(void *rock)
2620 struct afsd_syscall_args *args = rock;
2624 afsd_set_rx_rtpri();
2627 code = afsd_call_syscall(args->syscall, args->param1, args->param2,
2628 args->param3, args->param4, args->param5);
2629 if (code && args->syscall == AFSOP_START_CS) {
2630 printf("%s: No check server daemon in client.\n", args->rn);
2639 * common code for calling a syscall in another proc/thread.
2641 * @param[in] rx 1 if this is a thread for RX stuff, 0 otherwise
2642 * @param[in] wait 1 if we should wait for the new proc/thread to finish, 0 to
2643 * let it run in the background
2644 * @param[in] rn the name of the running program
2645 * @param[in] syscall syscall to run
2648 fork_syscall_impl(int rx, int wait, const char *rn, long syscall, long param1,
2649 long param2, long param3, long param4, long param5)
2651 struct afsd_syscall_args *args;
2653 args = malloc(sizeof(*args));
2655 args->syscall = syscall;
2656 args->param1 = param1;
2657 args->param2 = param2;
2658 args->param3 = param3;
2659 args->param4 = param4;
2660 args->param5 = param5;
2664 afsd_fork(wait, call_syscall_thread, args);
2668 * call a syscall in another process or thread.
2671 fork_syscall(const char *rn, long syscall, long param1, long param2,
2672 long param3, long param4, long param5)
2674 fork_syscall_impl(0, 0, rn, syscall, param1, param2, param3, param4, param5);
2678 * call a syscall in another process or thread, and give it RX priority.
2681 fork_rx_syscall(const char *rn, long syscall, long param1, long param2,
2682 long param3, long param4, long param5)
2684 fork_syscall_impl(1, 0, rn, syscall, param1, param2, param3, param4, param5);
2687 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
2689 * call a syscall in another process or thread, give it RX priority, and wait
2690 * for it to finish before returning.
2693 fork_rx_syscall_wait(const char *rn, long syscall, long param1, long param2,
2694 long param3, long param4, long param5)
2696 fork_syscall_impl(1, 1, rn, syscall, param1, param2, param3, param4, param5);
2698 #endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */