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>
79 /* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
81 #if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
89 #ifdef HAVE_SYS_FS_TYPES_H
90 #include <sys/fs_types.h>
93 #if defined(HAVE_SYS_MOUNT_H) && !defined(AFS_ARM_DARWIN_ENV)
94 #include <sys/mount.h>
97 #ifdef HAVE_SYS_FCNTL_H
98 #include <sys/fcntl.h>
101 #ifdef HAVE_SYS_MNTTAB_H
102 #include <sys/mnttab.h>
105 #ifdef HAVE_SYS_MNTENT_H
106 #include <sys/mntent.h>
113 #ifdef HAVE_SYS_VFS_H
117 #ifdef HAVE_SYS_FSTYP_H
118 #include <sys/fstyp.h>
123 #include <afs/afs_args.h>
124 #include <afs/cellconfig.h>
125 #include <afs/afssyscalls.h>
126 #include <afs/afsutil.h>
127 #include <afs/sys_prototypes.h>
129 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
131 #include <symconst.h>
137 #ifdef AFS_DARWIN_ENV
138 #ifdef AFS_DARWIN80_ENV
139 #include <sys/xattr.h>
141 #include <CoreFoundation/CoreFoundation.h>
143 #include <SystemConfiguration/SystemConfiguration.h>
144 #include <SystemConfiguration/SCDynamicStore.h>
146 #ifndef AFS_ARM_DARWIN_ENV
147 #include <IOKit/pwr_mgt/IOPMLib.h>
148 #include <IOKit/IOMessage.h>
150 static io_connect_t root_port;
151 static IONotificationPortRef notify;
152 static io_object_t iterator;
155 static CFRunLoopSourceRef source;
157 static int event_pid;
159 #endif /* AFS_DARWIN_ENV */
161 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
162 #include <sys/statvfs.h>
164 #if defined(AFS_SUN_ENV)
167 #ifdef HAVE_SYS_STATFS_H
168 #include <sys/statfs.h>
177 #define CACHEINFOFILE "cacheinfo"
178 #define DCACHEFILE "CacheItems"
179 #define VOLINFOFILE "VolumeItems"
180 #define CELLINFOFILE "CellItems"
182 #define MAXIPADDRS 1024
184 char LclCellName[64];
186 #define MAX_CACHE_LOOPS 4
190 * Internet address (old style... should be updated). This was pulled out of the old 4.2
191 * version of <netinet/in.h>, since it's still useful.
196 u_char s_b1, s_b2, s_b3, s_b4;
205 #define mPrintIPAddr(ipaddr) printf("[%d.%d.%d.%d] ", \
206 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b1, \
207 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b2, \
208 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b3, \
209 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b4)
212 * Global configuration variables.
214 static afs_int32 enable_rxbind = 0;
215 static afs_int32 afs_shutdown = 0;
216 static afs_int32 cacheBlocks; /*Num blocks in the cache */
217 static afs_int32 cacheFiles; /*Optimal # of files in workstation cache */
218 static afs_int32 rwpct = 0;
219 static afs_int32 ropct = 0;
220 static afs_int32 cacheStatEntries; /*Number of stat cache entries */
221 static char *cacheBaseDir; /*Where the workstation AFS cache lives */
222 static char *confDir; /*Where the workstation AFS configuration lives */
223 static char fullpn_DCacheFile[1024]; /*Full pathname of DCACHEFILE */
224 static char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE */
225 static char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE */
226 static char fullpn_CacheInfo[1024]; /*Full pathname of CACHEINFO */
227 static char fullpn_VFile[1024]; /*Full pathname of data cache files */
228 static char *vFilePtr; /*Ptr to the number part of above pathname */
229 static int sawCacheMountDir = 0; /* from cmd line */
230 static int sawCacheBaseDir = 0;
231 static int sawCacheBlocks = 0;
232 static int sawDCacheSize = 0;
234 static int sawBiod = 0;
236 static int sawCacheStatEntries = 0;
237 char *afsd_cacheMountDir;
238 static char *rootVolume = NULL;
240 static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC; /*Create & truncate on open */
242 static int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open */
244 static int ownerRWmode = 0600; /*Read/write OK by owner */
245 static int filesSet = 0; /*True if number of files explicitly set */
246 static int nFilesPerDir = 2048; /* # files per cache dir */
247 #if defined(AFS_CACHE_BYPASS)
248 #define AFSD_NDAEMONS 4
250 #define AFSD_NDAEMONS 2
252 static int nDaemons = AFSD_NDAEMONS; /* Number of background daemons */
253 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
254 static int dCacheSize; /* # of dcache entries */
255 static int vCacheSize = 200; /* # of volume cache entries */
256 static int rootVolSet = 0; /*True if root volume name explicitly set */
257 int addrNum; /*Cell server address index being printed */
258 static int cacheFlags = 0; /*Flags to cache manager */
260 static int nBiods = 5; /* AIX3.1 only */
262 static int preallocs = 400; /* Def # of allocated memory blocks */
263 static int enable_peer_stats = 0; /* enable rx stats */
264 static int enable_process_stats = 0; /* enable rx stats */
265 static int enable_afsdb = 0; /* enable AFSDB support */
266 static int enable_dynroot = 0; /* enable dynroot support */
267 static int enable_fakestat = 0; /* enable fakestat support */
268 static int enable_backuptree = 0; /* enable backup tree support */
269 static int enable_nomount = 0; /* do not mount */
270 static int enable_splitcache = 0;
271 static int afsd_dynamic_vcaches = 0; /* Enable dynamic-vcache support */
272 int afsd_verbose = 0; /*Are we being chatty? */
273 int afsd_debug = 0; /*Are we printing debugging info? */
274 static int afsd_CloseSynch = 0; /*Are closes synchronous or not? */
275 static int rxmaxmtu = 0; /* Are we forcing a limit on the mtu? */
276 static int rxmaxfrags = 0; /* Are we forcing a limit on frags? */
279 #define AFSD_INO_T ino64_t
281 #define AFSD_INO_T afs_uint32
283 struct afsd_file_list {
285 struct afsd_file_list *next;
287 struct afsd_file_list **cache_dir_filelist = NULL;
288 int *cache_dir_list = NULL; /* Array of cache subdirs */
289 int *dir_for_V = NULL; /* Array: dir of each cache file.
290 * -1: file does not exist
291 * -2: file exists in top-level
292 * >=0: file exists in Dxxx
294 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
295 AFSD_INO_T *inode_for_V; /* Array of inodes for desired
298 int missing_DCacheFile = 1; /*Is the DCACHEFILE missing? */
299 int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing? */
300 int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing? */
301 int afsd_rmtsys = 0; /* Default: don't support rmtsys */
302 struct afs_cacheParams cparams; /* params passed to cache manager */
304 int PartSizeOverflow(char *path, int cs);
306 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
307 static void fork_rx_syscall_wait();
309 static void fork_rx_syscall();
310 static void fork_syscall();
354 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
356 afsd_sleep_callback(void * refCon, io_service_t service,
357 natural_t messageType, void * messageArgument )
359 switch (messageType) {
360 case kIOMessageCanSystemSleep:
361 /* Idle sleep is about to kick in; can
362 prevent sleep by calling IOCancelPowerChange, otherwise
363 if we don't ack in 30s the system sleeps anyway */
366 IOAllowPowerChange(root_port, (long)messageArgument);
369 case kIOMessageSystemWillSleep:
370 /* The system WILL go to sleep. Ack or suffer delay */
372 IOAllowPowerChange(root_port, (long)messageArgument);
375 case kIOMessageSystemWillRestart:
376 /* The system WILL restart. Ack or suffer delay */
378 IOAllowPowerChange(root_port, (long)messageArgument);
381 case kIOMessageSystemWillPowerOn:
382 case kIOMessageSystemHasPoweredOn:
383 /* coming back from sleep */
385 IOAllowPowerChange(root_port, (long)messageArgument);
389 IOAllowPowerChange(root_port, (long)messageArgument);
395 afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
397 /* parse multihomed address files */
398 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
404 parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
405 AFSDIR_CLIENT_NETINFO_FILEPATH,
406 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
409 /* Note we're refreshing */
410 code = code | 0x40000000;
411 afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
413 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
416 /* Since it's likely this means our DNS server changed, reinit now */
421 /* This function is called when the system's ip addresses may have changed. */
423 afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
425 CFRunLoopTimerRef timer;
427 timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
428 0.0, 0, 0, afsd_update_addresses, NULL);
429 CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
430 kCFRunLoopDefaultMode);
435 afsd_event_cleanup(int signo) {
437 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
439 IODeregisterForSystemPower(&iterator);
440 IOServiceClose(root_port);
441 IONotificationPortDestroy(notify);
445 /* Adapted from "Living in a Dynamic TCP/IP Environment" technote. */
447 afsd_install_events(void)
449 SCDynamicStoreContext ctx = {0};
450 SCDynamicStoreRef store;
452 root_port = IORegisterForSystemPower(0,¬ify,afsd_sleep_callback,&iterator);
455 CFRunLoopAddSource(CFRunLoopGetCurrent(),
456 IONotificationPortGetRunLoopSource(notify),
457 kCFRunLoopDefaultMode);
461 store = SCDynamicStoreCreate (NULL,
462 CFSTR ("AddIPAddressListChangeCallbackSCF"),
463 afsd_ipaddr_callback, &ctx);
468 /* Request IPV4 address change notification */
469 keys[0] = (SCDynamicStoreKeyCreateNetworkServiceEntity
470 (NULL, kSCDynamicStoreDomainState,
471 kSCCompAnyRegex, kSCEntNetIPv4));
474 /* This should tell us when the hostname(s) change. do we care? */
475 keys[N] = SCDynamicStoreKeyCreateHostNames (NULL);
478 if (keys[0] != NULL) {
479 CFArrayRef pattern_array;
481 pattern_array = CFArrayCreate (NULL, keys, 1,
482 &kCFTypeArrayCallBacks);
484 if (pattern_array != NULL)
486 SCDynamicStoreSetNotificationKeys (store, NULL, pattern_array);
487 source = SCDynamicStoreCreateRunLoopSource (NULL, store, 0);
489 CFRelease (pattern_array);
499 if (source != NULL) {
500 CFRunLoopAddSource (CFRunLoopGetCurrent(),
501 source, kCFRunLoopDefaultMode);
504 signal(SIGTERM, afsd_event_cleanup);
510 /* ParseArgs is now obsolete, being handled by cmd */
512 /*------------------------------------------------------------------------------
516 * Open the file containing the description of the workstation's AFS cache
517 * and pull out its contents. The format of this file is as follows:
519 * cacheMountDir:cacheBaseDir:cacheBlocks
525 * 0 if everything went well,
529 * Nothing interesting.
533 *---------------------------------------------------------------------------*/
536 ParseCacheInfoFile(void)
538 static char rn[] = "ParseCacheInfoFile"; /*This routine's name */
539 FILE *cachefd; /*Descriptor for cache info file */
540 int parseResult; /*Result of our fscanf() */
541 afs_int32 tCacheBlocks;
542 char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
545 printf("%s: Opening cache info file '%s'...\n", rn, fullpn_CacheInfo);
547 cachefd = fopen(fullpn_CacheInfo, "r");
549 printf("%s: Can't read cache info file '%s'\n", rn, fullpn_CacheInfo);
554 * Parse the contents of the cache info file. All chars up to the first
555 * colon are the AFS mount directory, all chars to the next colon are the
556 * full path name of the workstation cache directory and all remaining chars
557 * represent the number of blocks in the cache.
559 tCacheMountDir[0] = tCacheBaseDir[0] = '\0';
561 fscanf(cachefd, "%1024[^:]:%1024[^:]:%d", tCacheMountDir,
562 tCacheBaseDir, &tCacheBlocks);
565 * Regardless of how the parse went, we close the cache info file.
569 if (parseResult == EOF || parseResult < 3) {
570 printf("%s: Format error in cache info file!\n", rn);
571 if (parseResult == EOF)
572 printf("\tEOF encountered before any field parsed.\n");
574 printf("\t%d out of 3 fields successfully parsed.\n",
580 for (tmd = tCacheMountDir; *tmd == '\n' || *tmd == ' ' || *tmd == '\t';
582 for (tbd = tCacheBaseDir; *tbd == '\n' || *tbd == ' ' || *tbd == '\t';
584 /* now copy in the fields not explicitly overridden by cmd args */
585 if (!sawCacheMountDir)
586 afsd_cacheMountDir = strdup(tmd);
587 if (!sawCacheBaseDir)
588 cacheBaseDir = strdup(tbd);
590 cacheBlocks = tCacheBlocks;
593 printf("%s: Cache info file successfully parsed:\n", rn);
595 ("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
596 tmd, tbd, tCacheBlocks);
598 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
599 return (PartSizeOverflow(tbd, cacheBlocks));
606 * All failures to open the partition are ignored. Also if the cache dir
607 * isn't a mounted partition it's also ignored since we can't guarantee
608 * what will be stored afterwards. Too many if's. This is now purely
609 * advisory. ODS with over 2G partition also gives warning message.
612 * 0 if everything went well,
616 PartSizeOverflow(char *path, int cs)
619 afs_int64 totalblks, mint;
620 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
621 struct statvfs statbuf;
623 if (statvfs(path, &statbuf) != 0) {
626 ("statvfs failed on %s; skip checking for adequate partition space\n",
630 totalblks = statbuf.f_blocks;
631 bsize = statbuf.f_frsize;
633 if (strcmp(statbuf.f_basetype, "jfs")) {
634 fprintf(stderr, "Cache filesystem '%s' must be jfs (now %s)\n",
635 path, statbuf.f_basetype);
638 #endif /* AFS_AIX51_ENV */
640 #else /* AFS_HAVE_STATVFS */
641 struct statfs statbuf;
643 if (statfs(path, &statbuf) < 0) {
646 ("statfs failed on %s; skip checking for adequate partition space\n",
650 totalblks = statbuf.f_blocks;
651 bsize = statbuf.f_bsize;
654 return 0; /* success */
656 /* now free and totalblks are in fragment units, but we want them in 1K units */
658 totalblks *= (bsize / 1024);
660 totalblks /= (1024 / bsize);
663 mint = totalblks / 100 * 95;
666 ("Cache size (%d) must be less than 95%% of partition size (which is %lld). Lower cache size\n",
674 /*-----------------------------------------------------------------------------
678 * Given the final component of a filename expected to be a data cache file,
679 * return the integer corresponding to the file. Note: we reject names that
680 * are not a ``V'' followed by an integer. We also reject those names having
681 * the right format but lying outside the range [0..cacheFiles-1].
684 * fname : Char ptr to the filename to parse.
685 * max : integer for the highest number to accept
688 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
692 * Nothing interesting.
696 *---------------------------------------------------------------------------*/
699 doGetXFileNumber(char *fname, char filechar, int maxNum)
701 int computedVNumber; /*The computed file number we return */
702 int filenameLen; /*Number of chars in filename */
703 int currDigit; /*Current digit being processed */
706 * The filename must have at least two characters, the first of which must be a ``filechar''
707 * and the second of which cannot be a zero unless the file is exactly two chars long.
709 filenameLen = strlen(fname);
712 if (fname[0] != filechar)
714 if ((filenameLen > 2) && (fname[1] == '0'))
718 * Scan through the characters in the given filename, failing immediately if a non-digit
721 for (currDigit = 1; currDigit < filenameLen; currDigit++)
722 if (isdigit(fname[currDigit]) == 0)
726 * All relevant characters are digits. Pull out the decimal number they represent.
727 * Reject it if it's out of range, otherwise return it.
729 computedVNumber = atoi(++fname);
730 if (computedVNumber < cacheFiles)
731 return (computedVNumber);
737 GetVFileNumber(char *fname, int maxFile)
739 return doGetXFileNumber(fname, 'V', maxFile);
743 GetDDirNumber(char *fname, int maxDir)
745 return doGetXFileNumber(fname, 'D', maxDir);
749 /*-----------------------------------------------------------------------------
753 * Given a full pathname for a file we need to create for the workstation AFS
754 * cache, go ahead and create the file.
757 * fname : Full pathname of file to create.
758 * statp : A pointer to a stat buffer which, if NON-NULL, will be
762 * 0 iff the file was created,
766 * The given cache file has been found to be missing.
770 *---------------------------------------------------------------------------*/
773 CreateCacheSubDir(char *basename, int dirNum)
775 static char rn[] = "CreateCacheSubDir"; /* Routine Name */
779 /* Build the new cache subdirectory */
780 sprintf(dir, "%s/D%d", basename, dirNum);
783 printf("%s: Creating cache subdir '%s'\n", rn, dir);
785 if ((ret = mkdir(dir, 0700)) != 0) {
786 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, dir,
792 /* Mark this directory as created */
793 cache_dir_list[dirNum] = 0;
795 /* And return success */
800 SetNoBackupAttr(char *fullpn)
802 #ifdef AFS_DARWIN80_ENV
805 ret = setxattr(fullpn, "com.apple.metadata:com_apple_backup_excludeItem",
806 "com.apple.backupd", strlen("com.apple.backupd"), 0,
811 fprintf(stderr, "afsd: Warning: failed to set attribute to preclude cache backup: %s\n", strerror(errno));
818 MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
821 static char rn[] = "MoveCacheFile";
822 char from[1024], to[1024];
825 if (cache_dir_list[toDir] < 0
826 && (ret = CreateCacheSubDir(basename, toDir))) {
827 printf("%s: Can't create directory '%s/D%d'\n", rn, basename, toDir);
831 /* Build the from,to dir */
833 /* old-style location */
834 snprintf(from, sizeof(from), "%s/V%d", basename, cacheFile);
836 snprintf(from, sizeof(from), "%s/D%d/V%d", basename, fromDir,
840 snprintf(to, sizeof(from), "%s/D%d/V%d", basename, toDir, cacheFile);
843 printf("%s: Moving cacheFile from '%s' to '%s'\n", rn, from, to);
845 if ((ret = rename(from, to)) != 0) {
846 printf("%s: Can't rename '%s' to '%s', error return is %d (%d)\n", rn,
847 from, to, ret, errno);
852 /* Reset directory pointer; fix file counts */
853 dir_for_V[cacheFile] = toDir;
854 cache_dir_list[toDir]++;
855 if (fromDir < maxDir && fromDir >= 0)
856 cache_dir_list[fromDir]--;
862 CreateCacheFile(char *fname, struct stat *statp)
864 static char rn[] = "CreateCacheFile"; /*Routine name */
865 int cfd; /*File descriptor to AFS cache file */
866 int closeResult; /*Result of close() */
869 printf("%s: Creating cache file '%s'\n", rn, fname);
870 cfd = open(fname, createAndTrunc, ownerRWmode);
872 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
877 closeResult = fstat(cfd, statp);
880 ("%s: Can't stat newly-created AFS cache file '%s' (code %d)\n",
885 closeResult = close(cfd);
888 ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
897 CreateFileIfMissing(char *fullpn, int missing)
900 if (CreateCacheFile(fullpn, NULL))
901 printf("CreateFileIfMissing: Can't create '%s'\n", fullpn);
906 UnlinkUnwantedFile(char *rn, char *fullpn_FileToDelete, char *fileToDelete)
908 if (unlink(fullpn_FileToDelete)) {
909 if ((errno == EISDIR || errno == EPERM) && *fileToDelete == 'D') {
910 if (rmdir(fullpn_FileToDelete)) {
911 printf("%s: Can't rmdir '%s', errno is %d\n", rn,
912 fullpn_FileToDelete, errno);
915 printf("%s: Can't unlink '%s', errno is %d\n", rn,
916 fullpn_FileToDelete, errno);
920 /*-----------------------------------------------------------------------------
924 * Sweep through the AFS cache directory, recording the inode number for
925 * each valid data cache file there. Also, delete any file that doesn't belong
926 * in the cache directory during this sweep, and remember which of the other
927 * residents of this directory were seen. After the sweep, we create any data
928 * cache files that were missing.
931 * vFilesFound : Set to the number of data cache files found.
934 * 0 if everything went well,
938 * This routine may be called several times. If the number of data cache files
939 * found is less than the global cacheFiles, then the caller will need to call it
940 * again to record the inodes of the missing zero-length data cache files created
941 * in the previous call.
944 * Fills up the global inode_for_V array, may create and/or delete files as
946 *---------------------------------------------------------------------------*/
950 doSweepAFSCache(int *vFilesFound,
951 char *directory, /* /path/to/cache/directory */
952 int dirNum, /* current directory number */
953 int maxDir) /* maximum directory number */
955 static char rn[] = "doSweepAFSCache"; /* Routine Name */
956 char fullpn_FileToDelete[1024]; /*File to be deleted from cache */
957 char *fileToDelete; /*Ptr to last component of above */
958 DIR *cdirp; /*Ptr to cache directory structure */
960 struct dirent64 *currp; /*Current directory entry */
962 struct dirent *currp; /*Current directory entry */
964 int vFileNum; /*Data cache file's associated number */
965 int thisDir; /* A directory number */
969 printf("%s: Opening cache directory '%s'\n", rn, directory);
971 if (chmod(directory, 0700)) { /* force it to be 700 */
972 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
976 cdirp = opendir(directory);
977 if (cdirp == (DIR *) 0) {
978 printf("%s: Can't open AFS cache directory, '%s'.\n", rn, directory);
983 * Scan the directory entries, remembering data cache file inodes
984 * and the existance of other important residents. Recurse into
985 * the data subdirectories.
987 * Delete all files and directories that don't belong here.
989 sprintf(fullpn_FileToDelete, "%s/", directory);
990 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
993 for (currp = readdir64(cdirp); currp; currp = readdir64(cdirp))
995 for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
999 printf("%s: Current directory entry:\n", rn);
1000 #if defined(AFS_SGI62_ENV) || defined(AFS_DARWIN90_ENV)
1001 printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
1002 currp->d_reclen, currp->d_name);
1003 #elif defined(AFS_DFBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
1004 printf("\tinode=%ld, name='%s'\n", (long)currp->d_ino, currp->d_name);
1006 printf("\tinode=%ld, reclen=%d, name='%s'\n", (long)currp->d_ino,
1007 currp->d_reclen, currp->d_name);
1012 * If dirNum < 0, we are a top-level cache directory and should
1013 * only contain sub-directories and other sundry files. Therefore,
1014 * V-files are valid only if dirNum >= 0, and Directories are only
1015 * valid if dirNum < 0.
1018 if (*(currp->d_name) == 'V'
1019 && ((vFileNum = GetVFileNumber(currp->d_name, cacheFiles)) >=
1022 * Found a valid data cache filename. Remember this
1023 * file's inode, directory, and bump the number of files found
1024 * total and in this directory.
1026 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1027 inode_for_V[vFileNum] = currp->d_ino;
1029 dir_for_V[vFileNum] = dirNum; /* remember this directory */
1032 /* If we're in a real subdir, mark this file to be moved
1033 * if we've already got too many files in this directory
1035 assert(dirNum >= 0);
1036 cache_dir_list[dirNum]++; /* keep directory's file count */
1037 if (cache_dir_list[dirNum] > nFilesPerDir) {
1038 /* Too many files -- add to filelist */
1039 struct afsd_file_list *tmp = (struct afsd_file_list *)
1040 malloc(sizeof(*tmp));
1043 ("%s: MALLOC FAILED allocating file_list entry\n",
1046 tmp->fileNum = vFileNum;
1047 tmp->next = cache_dir_filelist[dirNum];
1048 cache_dir_filelist[dirNum] = tmp;
1053 } else if (dirNum < 0 && (*(currp->d_name) == 'D')
1054 && GetDDirNumber(currp->d_name, 1 << 30) >= 0) {
1056 if ((vFileNum = GetDDirNumber(currp->d_name, maxDir)) >= 0) {
1057 /* Found a valid cachefile sub-Directory. Remember this number
1058 * and recurse into it. Note that subdirs cannot have subdirs.
1061 } else if ((vFileNum = GetDDirNumber(currp->d_name, 1 << 30)) >=
1063 /* This directory is going away, but figure out if there
1064 * are any cachefiles in here that should be saved by
1065 * moving them to other cache directories. This directory
1066 * will be removed later.
1071 /* Save the highest directory number we've seen */
1072 if (vFileNum > highDir)
1075 /* If this directory is staying, be sure to mark it as 'found' */
1077 cache_dir_list[vFileNum] = 0;
1079 /* Print the dirname for recursion */
1080 sprintf(fileToDelete, "%s", currp->d_name);
1082 /* Note: vFileNum is the directory number */
1084 doSweepAFSCache(vFilesFound, fullpn_FileToDelete, vFileNum,
1085 (retval == 1 ? 0 : -1));
1087 printf("%s: Recursive sweep failed on directory %s\n", rn,
1091 } else if (dirNum < 0 && strcmp(currp->d_name, DCACHEFILE) == 0) {
1093 * Found the file holding the dcache entries.
1095 missing_DCacheFile = 0;
1096 SetNoBackupAttr(fullpn_DCacheFile);
1097 } else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
1099 * Found the file holding the volume info.
1101 missing_VolInfoFile = 0;
1102 SetNoBackupAttr(fullpn_VolInfoFile);
1103 } else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
1105 * Found the file holding the cell info.
1107 missing_CellInfoFile = 0;
1108 SetNoBackupAttr(fullpn_CellInfoFile);
1109 } else if ((strcmp(currp->d_name, ".") == 0)
1110 || (strcmp(currp->d_name, "..") == 0) ||
1111 #ifdef AFS_DECOSF_ENV
1112 /* these are magic AdvFS files */
1113 (strcmp(currp->d_name, ".tags") == 0)
1114 || (strcmp(currp->d_name, "quota.user") == 0)
1115 || (strcmp(currp->d_name, "quota.group") == 0) ||
1117 #ifdef AFS_LINUX22_ENV
1118 /* this is the ext3 journal file */
1119 (strcmp(currp->d_name, ".journal") == 0) ||
1121 (strcmp(currp->d_name, "lost+found") == 0)) {
1123 * Don't do anything - this file is legit, and is to be left alone.
1127 * This file/directory doesn't belong in the cache. Nuke it.
1129 sprintf(fileToDelete, "%s", currp->d_name);
1131 printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
1132 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1139 * Create all the cache files that are missing.
1141 CreateFileIfMissing(fullpn_DCacheFile, missing_DCacheFile);
1142 CreateFileIfMissing(fullpn_VolInfoFile, missing_VolInfoFile);
1143 CreateFileIfMissing(fullpn_CellInfoFile, missing_CellInfoFile);
1145 /* ADJUST CACHE FILES */
1147 /* First, let's walk through the list of files and figure out
1148 * if there are any leftover files in extra directories or
1149 * missing files. Move the former and create the latter in
1150 * subdirs with extra space.
1153 thisDir = 0; /* Keep track of which subdir has space */
1155 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++) {
1156 if (dir_for_V[vFileNum] == -1) {
1157 /* This file does not exist. Create it in the first
1158 * subdir that still has extra space.
1160 while (thisDir < maxDir
1161 && cache_dir_list[thisDir] >= nFilesPerDir)
1163 if (thisDir >= maxDir)
1164 printf("%s: can't find directory to create V%d\n", rn,
1168 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1169 assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
1171 sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
1173 printf("%s: Creating '%s'\n", rn, fullpn_VFile);
1174 if (cache_dir_list[thisDir] < 0
1175 && CreateCacheSubDir(directory, thisDir))
1176 printf("%s: Can't create directory for '%s'\n", rn,
1178 if (CreateCacheFile(fullpn_VFile, &statb))
1179 printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
1181 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1182 inode_for_V[vFileNum] = statb.st_ino;
1184 dir_for_V[vFileNum] = thisDir;
1185 cache_dir_list[thisDir]++;
1188 SetNoBackupAttr(fullpn_VFile);
1191 } else if (dir_for_V[vFileNum] >= maxDir
1192 || dir_for_V[vFileNum] == -2) {
1193 /* This file needs to move; move it to the first subdir
1194 * that has extra space. (-2 means it's in the toplevel)
1196 while (thisDir < maxDir
1197 && cache_dir_list[thisDir] >= nFilesPerDir)
1199 if (thisDir >= maxDir)
1200 printf("%s: can't find directory to move V%d\n", rn,
1204 (directory, dir_for_V[vFileNum], thisDir, vFileNum,
1206 /* Cannot move. Ignore this file??? */
1213 /* At this point, we've moved all of the valid cache files
1214 * into the valid subdirs, and created all the extra
1215 * cachefiles we need to create. Next, rebalance any subdirs
1216 * with too many cache files into the directories with not
1217 * enough cache files. Note that thisDir currently sits at
1218 * the lowest subdir that _may_ have room.
1221 for (dirNum = 0; dirNum < maxDir; dirNum++) {
1222 struct afsd_file_list *thisFile;
1224 for (thisFile = cache_dir_filelist[dirNum];
1225 thisFile && cache_dir_list[dirNum] >= nFilesPerDir;
1226 thisFile = thisFile->next) {
1227 while (thisDir < maxDir
1228 && cache_dir_list[thisDir] >= nFilesPerDir)
1230 if (thisDir >= maxDir)
1231 printf("%s: can't find directory to move V%d\n", rn,
1235 (directory, dirNum, thisDir, thisFile->fileNum,
1237 /* Cannot move. Ignore this file??? */
1241 } /* for each file to move */
1242 } /* for each directory */
1244 /* Remove any directories >= maxDir -- they should be empty */
1245 for (; highDir >= maxDir; highDir--) {
1246 sprintf(fileToDelete, "D%d", highDir);
1247 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1253 * Close the directory, return success.
1256 printf("%s: Closing cache directory.\n", rn);
1262 CheckCacheBaseDir(char *dir)
1264 struct stat statbuf;
1267 return "cache base dir not specified";
1269 if (stat(dir, &statbuf) != 0) {
1270 return "unable to stat cache base directory";
1273 /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */
1275 #ifdef AFS_LINUX24_ENV
1278 struct statfs statfsbuf;
1280 res = statfs(dir, &statfsbuf);
1282 return "unable to statfs cache base directory";
1284 #if !defined(AFS_LINUX26_ENV)
1285 if (statfsbuf.f_type == 0x52654973) { /* REISERFS_SUPER_MAGIC */
1286 return "cannot use reiserfs as cache partition";
1287 } else if (statfsbuf.f_type == 0x58465342) { /* XFS_SUPER_MAGIC */
1288 return "cannot use xfs as cache partition";
1289 } else if (statfsbuf.f_type == 0x01021994) { /* TMPFS_SUPER_MAGIC */
1290 return "cannot use tmpfs as cache partition";
1291 } else if (statfsbuf.f_type != 0xEF53) {
1292 return "must use ext2 or ext3 for cache partition";
1301 struct statfs statfsbuf;
1304 res = statfs(dir, &statfsbuf);
1306 return "unable to statfs cache base directory";
1309 if (sysfs(GETFSTYP, statfsbuf.f_fsid[1], name) != 0) {
1310 return "unable to determine filesystem type for cache base dir";
1313 if (strcmp(name, "hfs")) {
1314 return "can only use hfs filesystem for cache partition on hpux";
1323 struct stat statmnt, statci;
1325 if ((stat(dir, &statci) == 0)
1326 && ((vfstab = fopen(MNTTAB, "r")) != NULL)) {
1327 while (getmntent(vfstab, &mnt) == 0) {
1328 if (strcmp(dir, mnt.mnt_mountp) != 0) {
1332 if (cp = hasmntopt(&mnt, "dev="))
1334 (int)strtol(cp + strlen("dev="), (char **)NULL,
1337 if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
1338 rdev = statmnt.st_dev;
1340 if ((rdev == statci.st_dev)
1341 && (hasmntopt(&mnt, "logging") != NULL)) {
1345 "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n";
1359 SweepAFSCache(int *vFilesFound)
1361 static char rn[] = "SweepAFSCache"; /*Routine name */
1362 int maxDir = (cacheFiles + nFilesPerDir - 1) / nFilesPerDir;
1367 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1369 printf("%s: Memory Cache, no cache sweep done\n", rn);
1373 if (cache_dir_list == NULL) {
1374 cache_dir_list = (int *)malloc(maxDir * sizeof(*cache_dir_list));
1375 if (cache_dir_list == NULL) {
1376 printf("%s: Malloc Failed!\n", rn);
1379 for (i = 0; i < maxDir; i++)
1380 cache_dir_list[i] = -1; /* Does not exist */
1383 if (cache_dir_filelist == NULL) {
1384 cache_dir_filelist = calloc(maxDir, sizeof(*cache_dir_filelist));
1385 if (cache_dir_filelist == NULL) {
1386 printf("%s: Malloc Failed!\n", rn);
1391 if (dir_for_V == NULL) {
1392 dir_for_V = (int *)malloc(cacheFiles * sizeof(*dir_for_V));
1393 if (dir_for_V == NULL) {
1394 printf("%s: Malloc Failed!\n", rn);
1397 for (i = 0; i < cacheFiles; i++)
1398 dir_for_V[i] = -1; /* Does not exist */
1401 /* Note, setting dirNum to -2 here will cause cachefiles found in
1402 * the toplevel directory to be marked in directory "-2". This
1403 * allows us to differentiate between 'file not seen' (-1) and
1404 * 'file seen in top-level' (-2). Then when we try to move the
1405 * file into a subdirectory, we know it's in the top-level instead
1406 * of some other cache subdir.
1408 return doSweepAFSCache(vFilesFound, cacheBaseDir, -2, maxDir);
1412 ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
1416 afs_int32 cellFlags = 0;
1417 afs_int32 hosts[MAXHOSTSPERCELL];
1419 /* figure out if this is the home cell */
1420 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
1422 cellFlags = 2; /* not home, suid is forbidden */
1423 if (enable_dynroot == 2)
1424 cellFlags |= 8; /* don't display foreign cells until looked up */
1426 /* build address list */
1427 for (i = 0; i < MAXHOSTSPERCELL; i++)
1428 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1430 if (aci->linkedCell)
1431 cellFlags |= 4; /* Flag that linkedCell arg exists,
1432 * for upwards compatibility */
1434 /* configure one cell */
1435 code = afsd_call_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
1436 aci->name, /* cell name */
1437 cellFlags, /* is this the home cell? */
1438 aci->linkedCell); /* Linked cell, if any */
1440 printf("Adding cell '%s': error %d\n", aci->name, code);
1445 ConfigCellAlias(struct afsconf_cellalias *aca,
1446 void *arock, struct afsconf_dir *adir)
1448 /* push the alias into the kernel */
1449 afsd_call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
1454 AfsdbLookupHandler(void)
1456 afs_int32 kernelMsg[64];
1457 char acellName[128];
1459 struct afsconf_cell acellInfo;
1464 acellName[0] = '\0';
1466 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
1467 /* Fork the event handler also. */
1470 afsd_install_events();
1472 } else if (code != -1) {
1477 /* On some platforms you only get 4 args to an AFS call */
1478 int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
1480 afsd_call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
1481 if (code) { /* Something is wrong? */
1486 if (*acellName == 1) /* Shutting down */
1489 code = afsconf_GetAfsdbInfo(acellName, 0, &acellInfo);
1494 kernelMsg[0] = acellInfo.numServers;
1495 if (acellInfo.timeout)
1496 kernelMsg[1] = acellInfo.timeout - time(0);
1499 for (i = 0; i < acellInfo.numServers; i++)
1500 kernelMsg[i + 2] = acellInfo.hostAddr[i].sin_addr.s_addr;
1501 strncpy(acellName, acellInfo.name, sizeof(acellName));
1502 acellName[sizeof(acellName) - 1] = '\0';
1505 #ifdef AFS_DARWIN_ENV
1506 kill(event_pid, SIGTERM);
1515 struct afs_uspc_param *uspc;
1519 uspc = calloc(1, sizeof(struct afs_uspc_param));
1520 memset(srcName, 0, sizeof(srcName));
1521 memset(dstName, 0, sizeof(dstName));
1523 /* brscount starts at 0 */
1529 char srcpath[BUFSIZ];
1530 char dstpath[BUFSIZ];
1532 /* pushing in a buffer this large */
1535 code = afsd_call_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
1536 if (code) { /* Something is wrong? */
1537 if (code == -2) /* shutting down */
1545 switch (uspc->reqtype) {
1547 snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1548 uspc->req.umv.sCell, uspc->req.umv.sVolume,
1549 uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
1550 snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1551 uspc->req.umv.dCell, uspc->req.umv.dVolume,
1552 uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
1553 if ((child = fork()) == 0) {
1554 /* first child does cp; second, rm. mv would re-enter. */
1556 switch (uspc->req.umv.idtype) {
1558 if (setuid(uspc->req.umv.id) != 0) {
1564 break; /* notreached */
1566 execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
1567 dstpath, (char *) NULL);
1569 if (child == (pid_t) -1) {
1574 if (waitpid(child, &status, 0) == -1)
1576 else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
1577 if ((child = fork()) == 0) {
1578 switch (uspc->req.umv.idtype) {
1580 if (setuid(uspc->req.umv.id) != 0) {
1586 break; /* notreached */
1588 execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
1589 srcpath, (char *) NULL);
1591 if (child == (pid_t) -1) {
1595 if (waitpid(child, &status, 0) == -1)
1597 else if (WIFEXITED(status) != 0) {
1598 /* rm exit status */
1599 uspc->retval = WEXITSTATUS(status);
1601 /* rm signal status */
1602 uspc->retval = -(WTERMSIG(status));
1605 /* error from cp: exit or signal status */
1606 uspc->retval = (WIFEXITED(status) != 0) ?
1607 WEXITSTATUS(status) : -(WTERMSIG(status));
1609 memset(srcName, 0, sizeof(srcName));
1610 memset(dstName, 0, sizeof(dstName));
1614 /* unknown req type */
1623 afsdb_thread(void *rock)
1625 /* Since the AFSDB lookup handler runs as a user process,
1626 * need to drop the controlling TTY, etc.
1628 if (afsd_daemon(0, 0) == -1) {
1629 printf("Error starting AFSDB lookup handler: %s\n",
1633 AfsdbLookupHandler();
1638 daemon_thread(void *rock)
1641 /* Since the background daemon runs as a user process,
1642 * need to drop the controlling TTY, etc.
1644 if (afsd_daemon(0, 0) == -1) {
1645 printf("Error starting background daemon: %s\n",
1650 #elif defined(AFS_AIX32_ENV)
1651 afsd_call_syscall(AFSOP_START_BKG, 0);
1653 afsd_call_syscall(AFSOP_START_BKG);
1660 rmtsysd_thread(void *rock)
1665 #endif /* !UKERNEL */
1668 mainproc(struct cmd_syndesc *as, void *arock)
1670 afs_int32 code; /*Result of fork() */
1674 #ifdef AFS_SGI65_ENV
1675 struct sched_param sp;
1678 #ifdef AFS_SGI_VNODE_GLUE
1679 if (afs_init_kernel_config(-1) < 0) {
1680 printf("Can't determine NUMA configuration, not starting AFS.\n");
1685 /* call atoi on the appropriate parsed results */
1686 if (cmd_OptionAsInt(as, OPT_blocks, &cacheBlocks) == 0)
1689 if (cmd_OptionAsInt(as, OPT_files, &cacheFiles) == 0)
1692 if (cmd_OptionAsString(as, OPT_rootvol, &rootVolume) == 0)
1695 if (cmd_OptionAsInt(as, OPT_stat, &cacheStatEntries) == 0)
1696 sawCacheStatEntries = 1;
1698 if (cmd_OptionPresent(as, OPT_memcache)) {
1699 cacheBaseDir = NULL;
1700 sawCacheBaseDir = 1;
1701 cacheFlags |= AFSCALL_INIT_MEMCACHE;
1704 if (cmd_OptionAsString(as, OPT_cachedir, &cacheBaseDir) == 0)
1705 sawCacheBaseDir = 1;
1707 if (cmd_OptionAsString(as, OPT_mountdir, &afsd_cacheMountDir) == 0)
1708 sawCacheMountDir = 1;
1710 cmd_OptionAsInt(as, OPT_daemons, &nDaemons);
1712 afsd_verbose = cmd_OptionPresent(as, OPT_verbose);
1714 if (cmd_OptionPresent(as, OPT_rmtsys)) {
1717 printf("-rmtsys not supported for UKERNEL\n");
1722 if (cmd_OptionPresent(as, OPT_debug)) {
1727 if (cmd_OptionAsInt(as, OPT_chunksize, &chunkSize) == 0) {
1728 if (chunkSize < 0 || chunkSize > 30) {
1730 ("afsd:invalid chunk size (not in range 0-30), using default\n");
1735 if (cmd_OptionAsInt(as, OPT_dcache, &dCacheSize) == 0)
1738 cmd_OptionAsInt(as, OPT_volumes, &vCacheSize);
1740 if (cmd_OptionPresent(as, OPT_biods)) {
1742 #ifndef AFS_AIX32_ENV
1744 ("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
1746 cmd_OptionAsInt(as, OPT_biods, &nBiods);
1749 cmd_OptionAsInt(as, OPT_prealloc, &preallocs);
1751 if (cmd_OptionAsString(as, OPT_confdir, &confDir) == CMD_MISSING) {
1752 confDir = strdup(AFSDIR_CLIENT_ETC_DIRPATH);
1754 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
1756 if (cmd_OptionPresent(as, OPT_logfile)) {
1757 printf("afsd: Ignoring obsolete -logfile flag\n");
1760 afsd_CloseSynch = cmd_OptionPresent(as, OPT_waitclose);
1762 if (cmd_OptionPresent(as, OPT_shutdown)) {
1766 * Cold shutdown is the default
1768 printf("afsd: Shutting down all afs processes and afs state\n");
1769 code = afsd_call_syscall(AFSOP_SHUTDOWN, 1);
1771 printf("afsd: AFS still mounted; Not shutting down\n");
1777 enable_peer_stats = cmd_OptionPresent(as, OPT_peerstats);
1778 enable_process_stats = cmd_OptionPresent(as, OPT_processstats);
1780 if (cmd_OptionPresent(as, OPT_memallocsleep)) {
1781 printf("afsd: -mem_alloc_sleep is deprecated -- ignored\n");
1784 enable_afsdb = cmd_OptionPresent(as, OPT_afsdb);
1785 if (cmd_OptionPresent(as, OPT_filesdir)) {
1786 /* -files_per_subdir */
1788 cmd_OptionAsInt(as, OPT_filesdir, &res);
1789 if (res < 10 || res > (1 << 30)) {
1791 ("afsd:invalid number of files per subdir, \"%s\". Ignored\n",
1792 as->parms[25].items->data);
1797 enable_dynroot = cmd_OptionPresent(as, OPT_dynroot);
1799 if (cmd_OptionPresent(as, OPT_fakestat)) {
1800 enable_fakestat = 2;
1802 if (cmd_OptionPresent(as, OPT_fakestatall)) {
1803 enable_fakestat = 1;
1805 if (cmd_OptionPresent(as, OPT_settime)) {
1807 printf("afsd: -settime ignored\n");
1808 printf("afsd: the OpenAFS client no longer sets the system time; "
1809 "please use NTP or\n");
1810 printf("afsd: another such system to synchronize client time\n");
1813 enable_nomount = cmd_OptionPresent(as, OPT_nomount);
1814 enable_backuptree = cmd_OptionPresent(as, OPT_backuptree);
1815 enable_rxbind = cmd_OptionPresent(as, OPT_rxbind);
1817 /* set rx_extraPackets */
1818 if (cmd_OptionPresent(as, OPT_rxpck)) {
1821 cmd_OptionAsInt(as, OPT_rxpck, &rxpck);
1822 printf("afsd: set rxpck = %d\n", rxpck);
1823 code = afsd_call_syscall(AFSOP_SET_RXPCK, rxpck);
1825 printf("afsd: failed to set rxpck\n");
1829 if (cmd_OptionPresent(as, OPT_splitcache)) {
1833 cmd_OptionAsString(as, OPT_splitcache, &var);
1835 if (var == NULL || ((c = strchr(var, '/')) == NULL))
1837 ("ignoring splitcache (specify as RW/RO percentages: 60/40)\n");
1839 ropct = atoi(c + 1);
1842 if ((rwpct != 0) && (ropct != 0) && (ropct + rwpct == 100)) {
1844 enable_splitcache = 1;
1849 if (cmd_OptionPresent(as, OPT_nodynvcache)) {
1850 #ifdef AFS_MAXVCOUNT_ENV
1851 afsd_dynamic_vcaches = 0;
1853 printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
1857 #ifdef AFS_MAXVCOUNT_ENV
1859 /* -dynamic-vcaches */
1860 afsd_dynamic_vcaches = 1;
1864 printf("afsd: %s dynamically allocated vcaches\n", ( afsd_dynamic_vcaches ? "enabling" : "disabling" ));
1867 cmd_OptionAsInt(as, OPT_rxmaxmtu, &rxmaxmtu);
1869 if (cmd_OptionPresent(as, OPT_dynrootsparse)) {
1873 cmd_OptionAsInt(as, OPT_rxmaxfrags, &rxmaxfrags);
1875 /* parse cacheinfo file if this is a diskcache */
1876 if (ParseCacheInfoFile()) {
1886 static char rn[] = "afsd"; /*Name of this routine */
1887 struct afsconf_dir *cdir; /* config dir */
1888 int lookupResult; /*Result of GetLocalCellName() */
1890 afs_int32 code; /*Result of fork() */
1891 char *fsTypeMsg = NULL;
1892 int cacheIteration; /*How many times through cache verification */
1893 int vFilesFound; /*How many data cache files were found in sweep */
1894 int currVFile; /*Current AFS cache file number passed in */
1897 * Pull out all the configuration info for the workstation's AFS cache and
1898 * the cellular community we're willing to let our users see.
1900 cdir = afsconf_Open(confDir);
1902 printf("afsd: some file missing or bad in %s\n", confDir);
1907 afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
1909 printf("%s: Can't get my home cell name! [Error is %d]\n", rn,
1913 printf("%s: My home cell is '%s'\n", rn, LclCellName);
1916 if (!enable_nomount) {
1917 if (afsd_check_mount(rn, afsd_cacheMountDir)) {
1922 /* do some random computations in memcache case to get things to work
1923 * reasonably no matter which parameters you set.
1925 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1926 /* memory cache: size described either as blocks or dcache entries, but
1930 fprintf(stderr, "%s: -files ignored with -memcache\n", rn);
1932 if (sawDCacheSize) {
1933 if (chunkSize == 0) {
1934 chunkSize = 13; /* 8k default chunksize for memcache */
1936 if (sawCacheBlocks) {
1938 ("%s: can't set cache blocks and dcache size simultaneously when diskless.\n",
1942 /* compute the cache size based on # of chunks times the chunk size */
1943 i = (1 << chunkSize); /* bytes per chunk */
1944 cacheBlocks = i * dCacheSize;
1945 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
1947 if (chunkSize == 0) {
1948 /* Try to autotune the memcache chunksize based on size
1949 * of memcache. This is done on the assumption that approx
1950 * 1024 chunks is suitable, it's a balance between enough
1951 * chunks to be useful and ramping up nicely when using larger
1952 * memcache to improve bulk read/write performance
1955 i <= 21 && (1 << i) / 1024 < (cacheBlocks / 1024); i++);
1958 /* compute the dcache size from overall cache size and chunk size */
1959 if (chunkSize > 10) {
1960 dCacheSize = (cacheBlocks >> (chunkSize - 10));
1961 } else if (chunkSize < 10) {
1962 dCacheSize = (cacheBlocks << (10 - chunkSize));
1964 dCacheSize = cacheBlocks;
1966 /* don't have to set sawDCacheSize here since it isn't overwritten
1967 * by ParseCacheInfoFile.
1971 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
1973 /* kernel computes # of dcache entries as min of cacheFiles and
1974 * dCacheSize, so we now make them equal.
1976 cacheFiles = dCacheSize;
1979 * Compute the number of cache files based on cache size,
1980 * but only if -files isn't given on the command line.
1981 * Don't let # files be so small as to prevent full utilization
1982 * of the cache unless user has explicitly asked for it.
1984 if (chunkSize == 0) {
1985 /* Set chunksize to 256kB - 1MB depending on cache size */
1986 if (cacheBlocks < 500000) {
1988 } else if (cacheBlocks < 1000000) {
1996 cacheFiles = cacheBlocks / 32; /* Assume 32k avg filesize */
1998 cacheFiles = max(cacheFiles, 1000);
2000 /* Always allow more files than chunks. Presume average V-file
2001 * is ~67% of a chunk... (another guess, perhaps Honeyman will
2002 * have a grad student write a paper). i is KILOBYTES.
2004 i = 1 << (chunkSize < 10 ? 0 : chunkSize - 10);
2005 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
2007 /* never permit more files than blocks, while leaving space for
2008 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
2009 * CacheItems is 50 Bytes / file (== 1K/20)
2011 #define CACHEITMSZ (cacheFiles / 20)
2012 #define VOLINFOSZ 50 /* 40kB has been seen, be conservative */
2013 #define CELLINFOSZ 4 /* Assuming disk block size is 4k ... */
2014 #define INFOSZ (VOLINFOSZ+CELLINFOSZ+CACHEITMSZ)
2016 /* Sanity check: If the obtained number of disk cache files
2017 * is larger than the number of available (4k) disk blocks, we're
2018 * doing something wrong. Fail hard so we can fix the bug instead
2019 * of silently hiding it like before */
2021 if (cacheFiles > (cacheBlocks - INFOSZ) / 4) {
2023 "%s: ASSERT: cacheFiles %d diskblocks %d\n",
2024 rn, cacheFiles, (cacheBlocks - INFOSZ) / 4);
2027 if (cacheFiles < 100)
2028 fprintf(stderr, "%s: WARNING: cache probably too small!\n",
2032 printf("%s: cacheFiles autotuned to %d\n", rn, cacheFiles);
2035 /* This actually needs to
2037 2) not second-guess when a chunksize comes from the command line
2038 3) be less, um, small. 2^2??
2040 /* Sanity check chunkSize */
2041 i = max(cacheBlocks / 1000, cacheBlocks / cacheFiles);
2042 chunkSize = min(chunkSize, i);
2043 chunkSize = max(chunkSize, 2);
2045 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
2048 if (!sawDCacheSize) {
2049 dCacheSize = cacheFiles / 2;
2050 if (dCacheSize > 10000) {
2053 if (dCacheSize < 2000) {
2057 printf("%s: dCacheSize autotuned to %d\n", rn, dCacheSize);
2060 if (!sawCacheStatEntries) {
2061 if (chunkSize <= 13) {
2062 cacheStatEntries = dCacheSize / 4;
2063 } else if (chunkSize >= 16) {
2064 cacheStatEntries = dCacheSize * 1.5;
2066 cacheStatEntries = dCacheSize;
2069 printf("%s: cacheStatEntries autotuned to %d\n", rn,
2073 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
2075 * Create and zero the inode table for the desired cache files.
2077 inode_for_V = calloc(cacheFiles, sizeof(AFSD_INO_T));
2078 if (inode_for_V == (AFSD_INO_T *) 0) {
2080 ("%s: malloc() failed for cache file inode table with %d entries.\n",
2085 printf("%s: %d inode_for_V entries at 0x%x, %lu bytes\n", rn,
2086 cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
2089 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2091 * Set up all the pathnames we'll need for later.
2093 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
2094 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
2095 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
2096 sprintf(fullpn_VFile, "%s/", cacheBaseDir);
2097 vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
2099 fsTypeMsg = CheckCacheBaseDir(cacheBaseDir);
2102 printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2104 printf("%s: ERROR: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2111 * Set up all the kernel processes needed for AFS.
2114 setpgrp(getpid(), 0);
2118 * Set the primary cell name.
2120 afsd_call_syscall(AFSOP_SET_THISCELL, LclCellName);
2122 /* Initialize RX daemons and services */
2124 /* initialize the rx random number generator from user space */
2126 /* parse multihomed address files */
2127 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
2131 parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
2132 AFSDIR_CLIENT_NETINFO_FILEPATH,
2133 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
2136 code = code | 0x80000000;
2137 afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
2139 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
2143 /* Set realtime priority for most threads to same as for biod's. */
2144 afsd_set_afsd_rtpri();
2146 /* Start listener, then callback listener. Lastly, start rx event daemon.
2147 * Change in ordering is so that Linux port has socket fd in listener
2149 * preallocs are passed for both listener and callback server. Only
2150 * the one which actually does the initialization uses them though.
2152 if (preallocs < cacheStatEntries + 50)
2153 preallocs = cacheStatEntries + 50;
2154 #ifdef RXK_LISTENER_ENV
2156 printf("%s: Forking rx listener daemon.\n", rn);
2157 # ifdef AFS_SUN510_ENV
2158 fork_rx_syscall_wait(rn, AFSOP_RXLISTENER_DAEMON, preallocs,
2159 enable_peer_stats, enable_process_stats);
2160 # else /* !AFS_SUN510_ENV */
2161 fork_rx_syscall(rn, AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
2162 enable_process_stats);
2163 # endif /* !AFS_SUN510_ENV */
2166 printf("%s: Forking rx callback listener.\n", rn);
2167 #ifndef RXK_LISTENER_ENV
2168 fork_rx_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, enable_peer_stats,
2169 enable_process_stats);
2171 fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs);
2173 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
2175 printf("%s: Forking rxevent daemon.\n", rn);
2176 fork_rx_syscall(rn, AFSOP_RXEVENT_DAEMON);
2181 printf("%s: Forking AFSDB lookup handler.\n", rn);
2182 afsd_fork(0, afsdb_thread, NULL);
2184 code = afsd_call_syscall(AFSOP_BASIC_INIT, 1);
2186 printf("%s: Error %d in basic initialization.\n", rn, code);
2191 * Tell the kernel some basic information about the workstation's cache.
2195 ("%s: Calling AFSOP_CACHEINIT: %d stat cache entries, %d optimum cache files, %d blocks in the cache, flags = 0x%x, dcache entries %d\n",
2196 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
2198 memset(&cparams, '\0', sizeof(cparams));
2199 cparams.cacheScaches = cacheStatEntries;
2200 cparams.cacheFiles = cacheFiles;
2201 cparams.cacheBlocks = cacheBlocks;
2202 cparams.cacheDcaches = dCacheSize;
2203 cparams.cacheVolumes = vCacheSize;
2204 cparams.chunkSize = chunkSize;
2205 cparams.setTimeFlag = 0;
2206 cparams.memCacheFlag = cacheFlags;
2207 cparams.dynamic_vcaches = afsd_dynamic_vcaches;
2208 afsd_call_syscall(AFSOP_CACHEINIT, &cparams);
2210 /* do it before we init the cache inodes */
2211 if (enable_splitcache) {
2212 afsd_call_syscall(AFSOP_BUCKETPCT, 1, rwpct);
2213 afsd_call_syscall(AFSOP_BUCKETPCT, 2, ropct);
2216 if (afsd_CloseSynch)
2217 afsd_call_syscall(AFSOP_CLOSEWAIT);
2220 * Sweep the workstation AFS cache directory, remembering the inodes of
2221 * valid files and deleting extraneous files. Keep sweeping until we
2222 * have the right number of data cache files or we've swept too many
2225 * This also creates files in the cache directory like VolumeItems and
2226 * CellItems, and thus must be ran before those are sent to the kernel.
2229 printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
2231 /* Memory-cache based system doesn't need any of this */
2232 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2235 if (SweepAFSCache(&vFilesFound)) {
2236 printf("%s: Error on sweep %d of workstation AFS cache \
2237 directory.\n", rn, cacheIteration);
2242 ("%s: %d out of %d data cache files found in sweep %d.\n",
2243 rn, vFilesFound, cacheFiles, cacheIteration);
2244 } while ((vFilesFound < cacheFiles)
2245 && (cacheIteration < MAX_CACHE_LOOPS));
2246 } else if (afsd_verbose)
2247 printf("%s: Using memory cache, not swept\n", rn);
2250 * Pass the kernel the name of the workstation cache file holding the
2254 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
2256 /* once again, meaningless for a memory-based cache. */
2257 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2258 afsd_call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
2261 * Pass the kernel the name of the workstation cache file holding the
2264 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2266 printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
2267 fullpn_CellInfoFile);
2268 afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
2273 printf("%s: Setting rxmaxfrags in kernel = %d\n", rn, rxmaxfrags);
2274 code = afsd_call_syscall(AFSOP_SET_RXMAXFRAGS, rxmaxfrags);
2276 printf("%s: Error seting rxmaxfrags\n", rn);
2281 printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
2282 code = afsd_call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
2284 printf("%s: Error seting rxmaxmtu\n", rn);
2287 if (enable_dynroot) {
2289 printf("%s: Enabling dynroot support in kernel%s.\n", rn,
2290 (enable_dynroot==2)?", not showing cells.":"");
2291 code = afsd_call_syscall(AFSOP_SET_DYNROOT, 1);
2293 printf("%s: Error enabling dynroot support.\n", rn);
2296 if (enable_fakestat) {
2298 printf("%s: Enabling fakestat support in kernel%s.\n", rn,
2299 (enable_fakestat==1)?" for all mountpoints."
2300 :" for crosscell mountpoints");
2301 code = afsd_call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
2303 printf("%s: Error enabling fakestat support.\n", rn);
2306 if (enable_backuptree) {
2308 printf("%s: Enabling backup tree support in kernel.\n", rn);
2309 code = afsd_call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
2311 printf("%s: Error enabling backup tree support.\n", rn);
2315 * Tell the kernel about each cell in the configuration.
2317 afsconf_CellApply(cdir, ConfigCell, NULL);
2318 afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
2320 /* Initialize AFS daemon threads. */
2322 printf("%s: Forking AFS daemon.\n", rn);
2323 fork_syscall(rn, AFSOP_START_AFS);
2326 printf("%s: Forking Check Server Daemon.\n", rn);
2327 fork_syscall(rn, AFSOP_START_CS);
2330 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
2331 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
2332 /* Add one because for sgi we always "steal" the first daemon for a
2333 * different task if we only have a 4K stack.
2337 for (i = 0; i < nDaemons; i++) {
2338 afsd_fork(0, daemon_thread, NULL);
2340 #ifdef AFS_AIX32_ENV
2342 nBiods = nDaemons * 2;
2345 for (i = 0; i < nBiods; i++) {
2346 fork_syscall(rn, AFSOP_START_BKG, nBiods);
2351 * If the root volume has been explicitly set, tell the kernel.
2355 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
2357 afsd_call_syscall(AFSOP_ROOTVOLUME, rootVolume);
2361 * Pass the kernel the name of the workstation cache file holding the
2362 * volume information.
2365 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
2366 fullpn_VolInfoFile);
2367 /* once again, meaningless for a memory-based cache. */
2368 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2369 afsd_call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
2372 * Give the kernel the names of the AFS files cached on the workstation's
2375 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2376 int nocachefile = 0;
2379 ("%s: Calling AFSOP_CACHEFILE for each of the %d files in '%s'\n",
2380 rn, cacheFiles, cacheBaseDir);
2381 /* ... and again ... */
2382 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
2384 sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
2385 code = afsd_call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
2387 if (currVFile == 0) {
2390 ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
2391 rn, cacheFiles, cacheBaseDir);
2395 ("%s: Error calling AFSOP_CACHEFILE for '%s'\n",
2402 /* fall through to setup-by-inode */
2404 #ifdef AFS_SGI62_ENV
2405 afsd_call_syscall(AFSOP_CACHEINODE,
2406 (afs_uint32) (inode_for_V[currVFile] >> 32),
2407 (afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
2408 #elif !(defined(AFS_LINUX26_ENV) || defined(AFS_CACHE_VNODE_PATH))
2409 afsd_call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
2412 ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
2420 * All the necessary info has been passed into the kernel to run an AFS
2421 * system. Give the kernel our go-ahead.
2424 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
2426 afsd_call_syscall(AFSOP_GO, 0);
2429 * At this point, we have finished passing the kernel all the info
2430 * it needs to set up the AFS. Mount the AFS root.
2432 printf("%s: All AFS daemons started.\n", rn);
2435 printf("%s: Forking trunc-cache daemon.\n", rn);
2436 fork_syscall(rn, AFSOP_START_TRUNCDAEMON);
2438 if (!enable_nomount) {
2439 afsd_mount_afs(rn, afsd_cacheMountDir);
2445 printf("%s: Forking 'rmtsys' daemon.\n", rn);
2446 afsd_fork(0, rmtsysd_thread, NULL);
2448 #endif /* !UKERNEL */
2450 * Exit successfully.
2455 #include "AFS_component_version_number.c"
2460 struct cmd_syndesc *ts;
2462 ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
2465 cmd_AddParmAtOffset(ts, OPT_blocks, "-blocks", CMD_SINGLE,
2466 CMD_OPTIONAL, "1024 byte blocks in cache");
2467 cmd_AddParmAtOffset(ts, OPT_files, "-files", CMD_SINGLE,
2468 CMD_OPTIONAL, "files in cache");
2469 cmd_AddParmAtOffset(ts, OPT_rootvol, "-rootvol", CMD_SINGLE,
2470 CMD_OPTIONAL, "name of AFS root volume");
2471 cmd_AddParmAtOffset(ts, OPT_stat, "-stat", CMD_SINGLE,
2472 CMD_OPTIONAL, "number of stat entries");
2473 cmd_AddParmAtOffset(ts, OPT_memcache, "-memcache", CMD_FLAG,
2474 CMD_OPTIONAL, "run diskless");
2475 cmd_AddParmAtOffset(ts, OPT_cachedir, "-cachedir", CMD_SINGLE,
2476 CMD_OPTIONAL, "cache directory");
2477 cmd_AddParmAtOffset(ts, OPT_mountdir, "-mountdir", CMD_SINGLE,
2478 CMD_OPTIONAL, "mount location");
2479 cmd_AddParmAtOffset(ts, OPT_daemons, "-daemons", CMD_SINGLE,
2480 CMD_OPTIONAL, "number of daemons to use");
2481 cmd_AddParmAtOffset(ts, OPT_nosettime, "-nosettime", CMD_FLAG,
2482 CMD_OPTIONAL, "don't set the time");
2483 cmd_AddParmAtOffset(ts, OPT_verbose, "-verbose", CMD_FLAG,
2484 CMD_OPTIONAL, "display lots of information");
2485 cmd_AddParmAtOffset(ts, OPT_rmtsys, "-rmtsys", CMD_FLAG,
2486 CMD_OPTIONAL, "start NFS rmtsysd program");
2487 cmd_AddParmAtOffset(ts, OPT_debug, "-debug", CMD_FLAG,
2488 CMD_OPTIONAL, "display debug info");
2489 cmd_AddParmAtOffset(ts, OPT_chunksize, "-chunksize", CMD_SINGLE,
2490 CMD_OPTIONAL, "log(2) of chunk size");
2491 cmd_AddParmAtOffset(ts, OPT_dcache, "-dcache", CMD_SINGLE,
2492 CMD_OPTIONAL, "number of dcache entries");
2493 cmd_AddParmAtOffset(ts, OPT_volumes, "-volumes", CMD_SINGLE,
2494 CMD_OPTIONAL, "number of volume entries");
2495 cmd_AddParmAtOffset(ts, OPT_biods, "-biods", CMD_SINGLE,
2496 CMD_OPTIONAL, "number of bkg I/O daemons (aix vm)");
2497 cmd_AddParmAtOffset(ts, OPT_prealloc, "-prealloc", CMD_SINGLE,
2498 CMD_OPTIONAL, "number of 'small' preallocated blocks");
2499 cmd_AddParmAtOffset(ts, OPT_confdir, "-confdir", CMD_SINGLE,
2500 CMD_OPTIONAL, "configuration directory");
2501 cmd_AddParmAtOffset(ts, OPT_logfile, "-logfile", CMD_SINGLE,
2502 CMD_OPTIONAL, "Place to keep the CM log");
2503 cmd_AddParmAtOffset(ts, OPT_waitclose, "-waitclose", CMD_FLAG,
2504 CMD_OPTIONAL, "make close calls synchronous");
2505 cmd_AddParmAtOffset(ts, OPT_shutdown, "-shutdown", CMD_FLAG,
2506 CMD_OPTIONAL, "Shutdown all afs state");
2507 cmd_AddParmAtOffset(ts, OPT_peerstats, "-enable_peer_stats", CMD_FLAG,
2508 CMD_OPTIONAL | CMD_HIDE,
2509 "Collect rpc statistics by peer");
2510 cmd_AddParmAtOffset(ts, OPT_processstats, "-enable_process_stats",
2511 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2512 "Collect rpc statistics for this process");
2513 cmd_AddParmAtOffset(ts, OPT_memallocsleep, "-mem_alloc_sleep",
2514 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2515 "Allow sleeps when allocating memory cache");
2516 cmd_AddParmAtOffset(ts, OPT_afsdb, "-afsdb", CMD_FLAG,
2517 CMD_OPTIONAL, "Enable AFSDB support");
2518 cmd_AddParmAtOffset(ts, OPT_filesdir, "-files_per_subdir", CMD_SINGLE,
2520 "log(2) of the number of cache files per "
2521 "cache subdirectory");
2522 cmd_AddParmAtOffset(ts, OPT_dynroot, "-dynroot", CMD_FLAG,
2523 CMD_OPTIONAL, "Enable dynroot support");
2524 cmd_AddParmAtOffset(ts, OPT_fakestat, "-fakestat", CMD_FLAG,
2526 "Enable fakestat support for cross-cell mounts");
2527 cmd_AddParmAtOffset(ts, OPT_fakestatall, "-fakestat-all", CMD_FLAG,
2529 "Enable fakestat support for all mounts");
2530 cmd_AddParmAtOffset(ts, OPT_nomount, "-nomount", CMD_FLAG,
2531 CMD_OPTIONAL, "Do not mount AFS");
2532 cmd_AddParmAtOffset(ts, OPT_backuptree, "-backuptree", CMD_FLAG,
2534 "Prefer backup volumes for mointpoints in backup "
2536 cmd_AddParmAtOffset(ts, OPT_rxbind, "-rxbind", CMD_FLAG,
2538 "Bind the Rx socket (one interface only)");
2539 cmd_AddParmAtOffset(ts, OPT_settime, "-settime", CMD_FLAG,
2540 CMD_OPTIONAL, "set the time");
2541 cmd_AddParmAtOffset(ts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
2542 "set rx_extraPackets to this value");
2543 cmd_AddParmAtOffset(ts, OPT_splitcache, "-splitcache", CMD_SINGLE,
2545 "Percentage RW versus RO in cache (specify as 60/40)");
2546 cmd_AddParmAtOffset(ts, OPT_nodynvcache, "-disable-dynamic-vcaches",
2547 CMD_FLAG, CMD_OPTIONAL,
2548 "disable stat/vcache cache growing as needed");
2549 cmd_AddParmAtOffset(ts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
2550 CMD_OPTIONAL, "set rx max MTU to use");
2551 cmd_AddParmAtOffset(ts, OPT_dynrootsparse, "-dynroot-sparse", CMD_FLAG,
2553 "Enable dynroot support with minimal cell list");
2554 cmd_AddParmAtOffset(ts, OPT_rxmaxfrags, "-rxmaxfrags", CMD_SINGLE,
2556 "Set the maximum number of UDP fragments Rx should "
2557 "send/receive per Rx packet");
2561 afsd_parse(int argc, char **argv)
2563 return cmd_Dispatch(argc, argv);
2566 struct afsd_syscall_args {
2578 * entry point for calling a syscall from another proc/thread.
2580 * @param[in] rock a struct afsd_syscall_args* specifying what syscall to call
2583 * @retval NULL always
2586 call_syscall_thread(void *rock)
2588 struct afsd_syscall_args *args = rock;
2592 afsd_set_rx_rtpri();
2595 code = afsd_call_syscall(args->syscall, args->param1, args->param2,
2596 args->param3, args->param4, args->param5);
2597 if (code && args->syscall == AFSOP_START_CS) {
2598 printf("%s: No check server daemon in client.\n", args->rn);
2607 * common code for calling a syscall in another proc/thread.
2609 * @param[in] rx 1 if this is a thread for RX stuff, 0 otherwise
2610 * @param[in] wait 1 if we should wait for the new proc/thread to finish, 0 to
2611 * let it run in the background
2612 * @param[in] rn the name of the running program
2613 * @param[in] syscall syscall to run
2616 fork_syscall_impl(int rx, int wait, const char *rn, long syscall, long param1,
2617 long param2, long param3, long param4, long param5)
2619 struct afsd_syscall_args *args;
2621 args = malloc(sizeof(*args));
2623 args->syscall = syscall;
2624 args->param1 = param1;
2625 args->param2 = param2;
2626 args->param3 = param3;
2627 args->param4 = param4;
2628 args->param5 = param5;
2632 afsd_fork(wait, call_syscall_thread, args);
2636 * call a syscall in another process or thread.
2639 fork_syscall(const char *rn, long syscall, long param1, long param2,
2640 long param3, long param4, long param5)
2642 fork_syscall_impl(0, 0, rn, syscall, param1, param2, param3, param4, param5);
2646 * call a syscall in another process or thread, and give it RX priority.
2649 fork_rx_syscall(const char *rn, long syscall, long param1, long param2,
2650 long param3, long param4, long param5)
2652 fork_syscall_impl(1, 0, rn, syscall, param1, param2, param3, param4, param5);
2655 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
2657 * call a syscall in another process or thread, give it RX priority, and wait
2658 * for it to finish before returning.
2661 fork_rx_syscall_wait(const char *rn, long syscall, long param1, long param2,
2662 long param3, long param4, long param5)
2664 fork_syscall_impl(1, 1, rn, syscall, param1, param2, param3, param4, param5);
2666 #endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */