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 = (struct afsd_file_list **)
1385 malloc(maxDir * sizeof(*cache_dir_filelist));
1386 if (cache_dir_filelist == NULL) {
1387 printf("%s: Malloc Failed!\n", rn);
1390 memset(cache_dir_filelist, 0, maxDir * sizeof(*cache_dir_filelist));
1393 if (dir_for_V == NULL) {
1394 dir_for_V = (int *)malloc(cacheFiles * sizeof(*dir_for_V));
1395 if (dir_for_V == NULL) {
1396 printf("%s: Malloc Failed!\n", rn);
1399 for (i = 0; i < cacheFiles; i++)
1400 dir_for_V[i] = -1; /* Does not exist */
1403 /* Note, setting dirNum to -2 here will cause cachefiles found in
1404 * the toplevel directory to be marked in directory "-2". This
1405 * allows us to differentiate between 'file not seen' (-1) and
1406 * 'file seen in top-level' (-2). Then when we try to move the
1407 * file into a subdirectory, we know it's in the top-level instead
1408 * of some other cache subdir.
1410 return doSweepAFSCache(vFilesFound, cacheBaseDir, -2, maxDir);
1414 ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
1418 afs_int32 cellFlags = 0;
1419 afs_int32 hosts[MAXHOSTSPERCELL];
1421 /* figure out if this is the home cell */
1422 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
1424 cellFlags = 2; /* not home, suid is forbidden */
1425 if (enable_dynroot == 2)
1426 cellFlags |= 8; /* don't display foreign cells until looked up */
1428 /* build address list */
1429 for (i = 0; i < MAXHOSTSPERCELL; i++)
1430 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1432 if (aci->linkedCell)
1433 cellFlags |= 4; /* Flag that linkedCell arg exists,
1434 * for upwards compatibility */
1436 /* configure one cell */
1437 code = afsd_call_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
1438 aci->name, /* cell name */
1439 cellFlags, /* is this the home cell? */
1440 aci->linkedCell); /* Linked cell, if any */
1442 printf("Adding cell '%s': error %d\n", aci->name, code);
1447 ConfigCellAlias(struct afsconf_cellalias *aca,
1448 void *arock, struct afsconf_dir *adir)
1450 /* push the alias into the kernel */
1451 afsd_call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
1456 AfsdbLookupHandler(void)
1458 afs_int32 kernelMsg[64];
1459 char acellName[128];
1461 struct afsconf_cell acellInfo;
1466 acellName[0] = '\0';
1468 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
1469 /* Fork the event handler also. */
1472 afsd_install_events();
1474 } else if (code != -1) {
1479 /* On some platforms you only get 4 args to an AFS call */
1480 int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
1482 afsd_call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
1483 if (code) { /* Something is wrong? */
1488 if (*acellName == 1) /* Shutting down */
1491 code = afsconf_GetAfsdbInfo(acellName, 0, &acellInfo);
1496 kernelMsg[0] = acellInfo.numServers;
1497 if (acellInfo.timeout)
1498 kernelMsg[1] = acellInfo.timeout - time(0);
1501 for (i = 0; i < acellInfo.numServers; i++)
1502 kernelMsg[i + 2] = acellInfo.hostAddr[i].sin_addr.s_addr;
1503 strncpy(acellName, acellInfo.name, sizeof(acellName));
1504 acellName[sizeof(acellName) - 1] = '\0';
1507 #ifdef AFS_DARWIN_ENV
1508 kill(event_pid, SIGTERM);
1517 struct afs_uspc_param *uspc;
1521 uspc = (struct afs_uspc_param *)malloc(sizeof(struct afs_uspc_param));
1522 memset(uspc, 0, sizeof(struct afs_uspc_param));
1523 memset(srcName, 0, sizeof(srcName));
1524 memset(dstName, 0, sizeof(dstName));
1526 /* brscount starts at 0 */
1532 char srcpath[BUFSIZ];
1533 char dstpath[BUFSIZ];
1535 /* pushing in a buffer this large */
1538 code = afsd_call_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
1539 if (code) { /* Something is wrong? */
1540 if (code == -2) /* shutting down */
1548 switch (uspc->reqtype) {
1550 snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1551 uspc->req.umv.sCell, uspc->req.umv.sVolume,
1552 uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
1553 snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1554 uspc->req.umv.dCell, uspc->req.umv.dVolume,
1555 uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
1556 if ((child = fork()) == 0) {
1557 /* first child does cp; second, rm. mv would re-enter. */
1559 switch (uspc->req.umv.idtype) {
1561 if (setuid(uspc->req.umv.id) != 0) {
1567 break; /* notreached */
1569 execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
1570 dstpath, (char *) NULL);
1572 if (child == (pid_t) -1) {
1577 if (waitpid(child, &status, 0) == -1)
1579 else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
1580 if ((child = fork()) == 0) {
1581 switch (uspc->req.umv.idtype) {
1583 if (setuid(uspc->req.umv.id) != 0) {
1589 break; /* notreached */
1591 execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
1592 srcpath, (char *) NULL);
1594 if (child == (pid_t) -1) {
1598 if (waitpid(child, &status, 0) == -1)
1600 else if (WIFEXITED(status) != 0) {
1601 /* rm exit status */
1602 uspc->retval = WEXITSTATUS(status);
1604 /* rm signal status */
1605 uspc->retval = -(WTERMSIG(status));
1608 /* error from cp: exit or signal status */
1609 uspc->retval = (WIFEXITED(status) != 0) ?
1610 WEXITSTATUS(status) : -(WTERMSIG(status));
1612 memset(srcName, 0, sizeof(srcName));
1613 memset(dstName, 0, sizeof(dstName));
1617 /* unknown req type */
1626 afsdb_thread(void *rock)
1628 /* Since the AFSDB lookup handler runs as a user process,
1629 * need to drop the controlling TTY, etc.
1631 if (afsd_daemon(0, 0) == -1) {
1632 printf("Error starting AFSDB lookup handler: %s\n",
1636 AfsdbLookupHandler();
1641 daemon_thread(void *rock)
1644 /* Since the background daemon runs as a user process,
1645 * need to drop the controlling TTY, etc.
1647 if (afsd_daemon(0, 0) == -1) {
1648 printf("Error starting background daemon: %s\n",
1653 #elif defined(AFS_AIX32_ENV)
1654 afsd_call_syscall(AFSOP_START_BKG, 0);
1656 afsd_call_syscall(AFSOP_START_BKG);
1663 rmtsysd_thread(void *rock)
1668 #endif /* !UKERNEL */
1671 mainproc(struct cmd_syndesc *as, void *arock)
1673 afs_int32 code; /*Result of fork() */
1677 #ifdef AFS_SGI65_ENV
1678 struct sched_param sp;
1681 #ifdef AFS_SGI_VNODE_GLUE
1682 if (afs_init_kernel_config(-1) < 0) {
1683 printf("Can't determine NUMA configuration, not starting AFS.\n");
1688 /* call atoi on the appropriate parsed results */
1689 if (cmd_OptionAsInt(as, OPT_blocks, &cacheBlocks) == 0)
1692 if (cmd_OptionAsInt(as, OPT_files, &cacheFiles) == 0)
1695 if (cmd_OptionAsString(as, OPT_rootvol, &rootVolume) == 0)
1698 if (cmd_OptionAsInt(as, OPT_stat, &cacheStatEntries) == 0)
1699 sawCacheStatEntries = 1;
1701 if (cmd_OptionPresent(as, OPT_memcache)) {
1702 cacheBaseDir = NULL;
1703 sawCacheBaseDir = 1;
1704 cacheFlags |= AFSCALL_INIT_MEMCACHE;
1707 if (cmd_OptionAsString(as, OPT_cachedir, &cacheBaseDir) == 0)
1708 sawCacheBaseDir = 1;
1710 if (cmd_OptionAsString(as, OPT_mountdir, &afsd_cacheMountDir) == 0)
1711 sawCacheMountDir = 1;
1713 cmd_OptionAsInt(as, OPT_daemons, &nDaemons);
1715 afsd_verbose = cmd_OptionPresent(as, OPT_verbose);
1717 if (cmd_OptionPresent(as, OPT_rmtsys)) {
1720 printf("-rmtsys not supported for UKERNEL\n");
1725 if (cmd_OptionPresent(as, OPT_debug)) {
1730 if (cmd_OptionAsInt(as, OPT_chunksize, &chunkSize) == 0) {
1731 if (chunkSize < 0 || chunkSize > 30) {
1733 ("afsd:invalid chunk size (not in range 0-30), using default\n");
1738 if (cmd_OptionAsInt(as, OPT_dcache, &dCacheSize))
1741 cmd_OptionAsInt(as, OPT_volumes, &vCacheSize);
1743 if (cmd_OptionPresent(as, OPT_biods)) {
1745 #ifndef AFS_AIX32_ENV
1747 ("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
1749 cmd_OptionAsInt(as, OPT_biods, &nBiods);
1752 cmd_OptionAsInt(as, OPT_prealloc, &preallocs);
1754 if (cmd_OptionAsString(as, OPT_confdir, &confDir) == CMD_MISSING) {
1755 confDir = strdup(AFSDIR_CLIENT_ETC_DIRPATH);
1757 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
1759 if (cmd_OptionPresent(as, OPT_logfile)) {
1760 printf("afsd: Ignoring obsolete -logfile flag\n");
1763 afsd_CloseSynch = cmd_OptionPresent(as, OPT_waitclose);
1765 if (cmd_OptionPresent(as, OPT_shutdown)) {
1769 * Cold shutdown is the default
1771 printf("afsd: Shutting down all afs processes and afs state\n");
1772 code = afsd_call_syscall(AFSOP_SHUTDOWN, 1);
1774 printf("afsd: AFS still mounted; Not shutting down\n");
1780 enable_peer_stats = cmd_OptionPresent(as, OPT_peerstats);
1781 enable_process_stats = cmd_OptionPresent(as, OPT_processstats);
1783 if (cmd_OptionPresent(as, OPT_memallocsleep)) {
1784 printf("afsd: -mem_alloc_sleep is deprecated -- ignored\n");
1787 enable_afsdb = cmd_OptionPresent(as, OPT_afsdb);
1788 if (cmd_OptionPresent(as, OPT_filesdir)) {
1789 /* -files_per_subdir */
1791 cmd_OptionAsInt(as, OPT_filesdir, &res);
1792 if (res < 10 || res > (1 << 30)) {
1794 ("afsd:invalid number of files per subdir, \"%s\". Ignored\n",
1795 as->parms[25].items->data);
1800 enable_dynroot = cmd_OptionPresent(as, OPT_dynroot);
1802 if (cmd_OptionPresent(as, OPT_fakestat)) {
1803 enable_fakestat = 2;
1805 if (cmd_OptionPresent(as, OPT_fakestatall)) {
1806 enable_fakestat = 1;
1808 if (cmd_OptionPresent(as, OPT_settime)) {
1810 printf("afsd: -settime ignored\n");
1811 printf("afsd: the OpenAFS client no longer sets the system time; "
1812 "please use NTP or\n");
1813 printf("afsd: another such system to synchronize client time\n");
1816 enable_nomount = cmd_OptionPresent(as, OPT_nomount);
1817 enable_backuptree = cmd_OptionPresent(as, OPT_backuptree);
1818 enable_rxbind = cmd_OptionPresent(as, OPT_rxbind);
1820 /* set rx_extraPackets */
1821 if (cmd_OptionPresent(as, OPT_rxpck)) {
1824 cmd_OptionAsInt(as, OPT_rxpck, &rxpck);
1825 printf("afsd: set rxpck = %d\n", rxpck);
1826 code = afsd_call_syscall(AFSOP_SET_RXPCK, rxpck);
1828 printf("afsd: failed to set rxpck\n");
1832 if (cmd_OptionPresent(as, OPT_splitcache)) {
1836 cmd_OptionAsString(as, OPT_splitcache, &var);
1838 if (var == NULL || ((c = strchr(var, '/')) == NULL))
1840 ("ignoring splitcache (specify as RW/RO percentages: 60/40)\n");
1842 ropct = atoi(c + 1);
1845 if ((rwpct != 0) && (ropct != 0) && (ropct + rwpct == 100)) {
1847 enable_splitcache = 1;
1852 if (cmd_OptionPresent(as, OPT_nodynvcache)) {
1853 #ifdef AFS_MAXVCOUNT_ENV
1854 afsd_dynamic_vcaches = 0;
1856 printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
1860 #ifdef AFS_MAXVCOUNT_ENV
1862 /* -dynamic-vcaches */
1863 afsd_dynamic_vcaches = 1;
1867 printf("afsd: %s dynamically allocated vcaches\n", ( afsd_dynamic_vcaches ? "enabling" : "disabling" ));
1870 cmd_OptionAsInt(as, OPT_rxmaxmtu, &rxmaxmtu);
1872 if (cmd_OptionPresent(as, OPT_dynrootsparse)) {
1876 cmd_OptionAsInt(as, OPT_rxmaxfrags, &rxmaxfrags);
1878 /* parse cacheinfo file if this is a diskcache */
1879 if (ParseCacheInfoFile()) {
1889 static char rn[] = "afsd"; /*Name of this routine */
1890 struct afsconf_dir *cdir; /* config dir */
1891 int lookupResult; /*Result of GetLocalCellName() */
1893 afs_int32 code; /*Result of fork() */
1894 char *fsTypeMsg = NULL;
1895 int cacheIteration; /*How many times through cache verification */
1896 int vFilesFound; /*How many data cache files were found in sweep */
1897 int currVFile; /*Current AFS cache file number passed in */
1900 * Pull out all the configuration info for the workstation's AFS cache and
1901 * the cellular community we're willing to let our users see.
1903 cdir = afsconf_Open(confDir);
1905 printf("afsd: some file missing or bad in %s\n", confDir);
1910 afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
1912 printf("%s: Can't get my home cell name! [Error is %d]\n", rn,
1916 printf("%s: My home cell is '%s'\n", rn, LclCellName);
1919 if (!enable_nomount) {
1920 if (afsd_check_mount(rn, afsd_cacheMountDir)) {
1925 /* do some random computations in memcache case to get things to work
1926 * reasonably no matter which parameters you set.
1928 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1929 /* memory cache: size described either as blocks or dcache entries, but
1933 fprintf(stderr, "%s: -files ignored with -memcache\n", rn);
1935 if (sawDCacheSize) {
1936 if (chunkSize == 0) {
1937 chunkSize = 13; /* 8k default chunksize for memcache */
1939 if (sawCacheBlocks) {
1941 ("%s: can't set cache blocks and dcache size simultaneously when diskless.\n",
1945 /* compute the cache size based on # of chunks times the chunk size */
1946 i = (1 << chunkSize); /* bytes per chunk */
1947 cacheBlocks = i * dCacheSize;
1948 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
1950 if (chunkSize == 0) {
1951 /* Try to autotune the memcache chunksize based on size
1952 * of memcache. This is done on the assumption that approx
1953 * 1024 chunks is suitable, it's a balance between enough
1954 * chunks to be useful and ramping up nicely when using larger
1955 * memcache to improve bulk read/write performance
1958 i <= 21 && (1 << i) / 1024 < (cacheBlocks / 1024); i++);
1961 /* compute the dcache size from overall cache size and chunk size */
1962 if (chunkSize > 10) {
1963 dCacheSize = (cacheBlocks >> (chunkSize - 10));
1964 } else if (chunkSize < 10) {
1965 dCacheSize = (cacheBlocks << (10 - chunkSize));
1967 dCacheSize = cacheBlocks;
1969 /* don't have to set sawDCacheSize here since it isn't overwritten
1970 * by ParseCacheInfoFile.
1974 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
1976 /* kernel computes # of dcache entries as min of cacheFiles and
1977 * dCacheSize, so we now make them equal.
1979 cacheFiles = dCacheSize;
1982 * Compute the number of cache files based on cache size,
1983 * but only if -files isn't given on the command line.
1984 * Don't let # files be so small as to prevent full utilization
1985 * of the cache unless user has explicitly asked for it.
1987 if (chunkSize == 0) {
1988 /* Set chunksize to 256kB - 1MB depending on cache size */
1989 if (cacheBlocks < 500000) {
1991 } else if (cacheBlocks < 1000000) {
1999 cacheFiles = cacheBlocks / 32; /* Assume 32k avg filesize */
2001 cacheFiles = max(cacheFiles, 1000);
2003 /* Always allow more files than chunks. Presume average V-file
2004 * is ~67% of a chunk... (another guess, perhaps Honeyman will
2005 * have a grad student write a paper). i is KILOBYTES.
2007 i = 1 << (chunkSize < 10 ? 0 : chunkSize - 10);
2008 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
2010 /* never permit more files than blocks, while leaving space for
2011 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
2012 * CacheItems is 50 Bytes / file (== 1K/20)
2014 #define CACHEITMSZ (cacheFiles / 20)
2015 #define VOLINFOSZ 50 /* 40kB has been seen, be conservative */
2016 #define CELLINFOSZ 4 /* Assuming disk block size is 4k ... */
2017 #define INFOSZ (VOLINFOSZ+CELLINFOSZ+CACHEITMSZ)
2019 /* Sanity check: If the obtained number of disk cache files
2020 * is larger than the number of available (4k) disk blocks, we're
2021 * doing something wrong. Fail hard so we can fix the bug instead
2022 * of silently hiding it like before */
2024 if (cacheFiles > (cacheBlocks - INFOSZ) / 4) {
2026 "%s: ASSERT: cacheFiles %d diskblocks %d\n",
2027 rn, cacheFiles, (cacheBlocks - INFOSZ) / 4);
2030 if (cacheFiles < 100)
2031 fprintf(stderr, "%s: WARNING: cache probably too small!\n",
2035 printf("%s: cacheFiles autotuned to %d\n", rn, cacheFiles);
2038 /* This actually needs to
2040 2) not second-guess when a chunksize comes from the command line
2041 3) be less, um, small. 2^2??
2043 /* Sanity check chunkSize */
2044 i = max(cacheBlocks / 1000, cacheBlocks / cacheFiles);
2045 chunkSize = min(chunkSize, i);
2046 chunkSize = max(chunkSize, 2);
2048 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
2051 if (!sawDCacheSize) {
2052 dCacheSize = cacheFiles / 2;
2053 if (dCacheSize > 10000) {
2056 if (dCacheSize < 2000) {
2060 printf("%s: dCacheSize autotuned to %d\n", rn, dCacheSize);
2063 if (!sawCacheStatEntries) {
2064 if (chunkSize <= 13) {
2065 cacheStatEntries = dCacheSize / 4;
2066 } else if (chunkSize >= 16) {
2067 cacheStatEntries = dCacheSize * 1.5;
2069 cacheStatEntries = dCacheSize;
2072 printf("%s: cacheStatEntries autotuned to %d\n", rn,
2076 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
2078 * Create and zero the inode table for the desired cache files.
2080 inode_for_V = (AFSD_INO_T *) malloc(cacheFiles * sizeof(AFSD_INO_T));
2081 if (inode_for_V == (AFSD_INO_T *) 0) {
2083 ("%s: malloc() failed for cache file inode table with %d entries.\n",
2087 memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
2089 printf("%s: %d inode_for_V entries at 0x%x, %lu bytes\n", rn,
2090 cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
2093 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2095 * Set up all the pathnames we'll need for later.
2097 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
2098 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
2099 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
2100 sprintf(fullpn_VFile, "%s/", cacheBaseDir);
2101 vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
2103 fsTypeMsg = CheckCacheBaseDir(cacheBaseDir);
2106 printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2108 printf("%s: ERROR: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2115 * Set up all the kernel processes needed for AFS.
2118 setpgrp(getpid(), 0);
2122 * Set the primary cell name.
2124 afsd_call_syscall(AFSOP_SET_THISCELL, LclCellName);
2126 /* Initialize RX daemons and services */
2128 /* initialize the rx random number generator from user space */
2130 /* parse multihomed address files */
2131 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
2135 parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
2136 AFSDIR_CLIENT_NETINFO_FILEPATH,
2137 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
2140 code = code | 0x80000000;
2141 afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
2143 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
2147 /* Set realtime priority for most threads to same as for biod's. */
2148 afsd_set_afsd_rtpri();
2150 /* Start listener, then callback listener. Lastly, start rx event daemon.
2151 * Change in ordering is so that Linux port has socket fd in listener
2153 * preallocs are passed for both listener and callback server. Only
2154 * the one which actually does the initialization uses them though.
2156 if (preallocs < cacheStatEntries + 50)
2157 preallocs = cacheStatEntries + 50;
2158 #ifdef RXK_LISTENER_ENV
2160 printf("%s: Forking rx listener daemon.\n", rn);
2161 # ifdef AFS_SUN510_ENV
2162 fork_rx_syscall_wait(rn, AFSOP_RXLISTENER_DAEMON, preallocs,
2163 enable_peer_stats, enable_process_stats);
2164 # else /* !AFS_SUN510_ENV */
2165 fork_rx_syscall(rn, AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
2166 enable_process_stats);
2167 # endif /* !AFS_SUN510_ENV */
2170 printf("%s: Forking rx callback listener.\n", rn);
2171 #ifndef RXK_LISTENER_ENV
2172 fork_rx_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, enable_peer_stats,
2173 enable_process_stats);
2175 fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs);
2177 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
2179 printf("%s: Forking rxevent daemon.\n", rn);
2180 fork_rx_syscall(rn, AFSOP_RXEVENT_DAEMON);
2185 printf("%s: Forking AFSDB lookup handler.\n", rn);
2186 afsd_fork(0, afsdb_thread, NULL);
2188 code = afsd_call_syscall(AFSOP_BASIC_INIT, 1);
2190 printf("%s: Error %d in basic initialization.\n", rn, code);
2195 * Tell the kernel some basic information about the workstation's cache.
2199 ("%s: Calling AFSOP_CACHEINIT: %d stat cache entries, %d optimum cache files, %d blocks in the cache, flags = 0x%x, dcache entries %d\n",
2200 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
2202 memset(&cparams, '\0', sizeof(cparams));
2203 cparams.cacheScaches = cacheStatEntries;
2204 cparams.cacheFiles = cacheFiles;
2205 cparams.cacheBlocks = cacheBlocks;
2206 cparams.cacheDcaches = dCacheSize;
2207 cparams.cacheVolumes = vCacheSize;
2208 cparams.chunkSize = chunkSize;
2209 cparams.setTimeFlag = 0;
2210 cparams.memCacheFlag = cacheFlags;
2211 cparams.dynamic_vcaches = afsd_dynamic_vcaches;
2212 afsd_call_syscall(AFSOP_CACHEINIT, &cparams);
2214 /* do it before we init the cache inodes */
2215 if (enable_splitcache) {
2216 afsd_call_syscall(AFSOP_BUCKETPCT, 1, rwpct);
2217 afsd_call_syscall(AFSOP_BUCKETPCT, 2, ropct);
2220 if (afsd_CloseSynch)
2221 afsd_call_syscall(AFSOP_CLOSEWAIT);
2224 * Sweep the workstation AFS cache directory, remembering the inodes of
2225 * valid files and deleting extraneous files. Keep sweeping until we
2226 * have the right number of data cache files or we've swept too many
2229 * This also creates files in the cache directory like VolumeItems and
2230 * CellItems, and thus must be ran before those are sent to the kernel.
2233 printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
2235 /* Memory-cache based system doesn't need any of this */
2236 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2239 if (SweepAFSCache(&vFilesFound)) {
2240 printf("%s: Error on sweep %d of workstation AFS cache \
2241 directory.\n", rn, cacheIteration);
2246 ("%s: %d out of %d data cache files found in sweep %d.\n",
2247 rn, vFilesFound, cacheFiles, cacheIteration);
2248 } while ((vFilesFound < cacheFiles)
2249 && (cacheIteration < MAX_CACHE_LOOPS));
2250 } else if (afsd_verbose)
2251 printf("%s: Using memory cache, not swept\n", rn);
2254 * Pass the kernel the name of the workstation cache file holding the
2258 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
2260 /* once again, meaningless for a memory-based cache. */
2261 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2262 afsd_call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
2265 * Pass the kernel the name of the workstation cache file holding the
2268 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2270 printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
2271 fullpn_CellInfoFile);
2272 afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
2277 printf("%s: Setting rxmaxfrags in kernel = %d\n", rn, rxmaxfrags);
2278 code = afsd_call_syscall(AFSOP_SET_RXMAXFRAGS, rxmaxfrags);
2280 printf("%s: Error seting rxmaxfrags\n", rn);
2285 printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
2286 code = afsd_call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
2288 printf("%s: Error seting rxmaxmtu\n", rn);
2291 if (enable_dynroot) {
2293 printf("%s: Enabling dynroot support in kernel%s.\n", rn,
2294 (enable_dynroot==2)?", not showing cells.":"");
2295 code = afsd_call_syscall(AFSOP_SET_DYNROOT, 1);
2297 printf("%s: Error enabling dynroot support.\n", rn);
2300 if (enable_fakestat) {
2302 printf("%s: Enabling fakestat support in kernel%s.\n", rn,
2303 (enable_fakestat==2)?" for all mountpoints."
2304 :" for crosscell mountpoints");
2305 code = afsd_call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
2307 printf("%s: Error enabling fakestat support.\n", rn);
2310 if (enable_backuptree) {
2312 printf("%s: Enabling backup tree support in kernel.\n", rn);
2313 code = afsd_call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
2315 printf("%s: Error enabling backup tree support.\n", rn);
2319 * Tell the kernel about each cell in the configuration.
2321 afsconf_CellApply(cdir, ConfigCell, NULL);
2322 afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
2324 /* Initialize AFS daemon threads. */
2326 printf("%s: Forking AFS daemon.\n", rn);
2327 fork_syscall(rn, AFSOP_START_AFS);
2330 printf("%s: Forking Check Server Daemon.\n", rn);
2331 fork_syscall(rn, AFSOP_START_CS);
2334 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
2335 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
2336 /* Add one because for sgi we always "steal" the first daemon for a
2337 * different task if we only have a 4K stack.
2341 for (i = 0; i < nDaemons; i++) {
2342 afsd_fork(0, daemon_thread, NULL);
2344 #ifdef AFS_AIX32_ENV
2346 nBiods = nDaemons * 2;
2349 for (i = 0; i < nBiods; i++) {
2350 fork_syscall(rn, AFSOP_START_BKG, nBiods);
2355 * If the root volume has been explicitly set, tell the kernel.
2359 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
2361 afsd_call_syscall(AFSOP_ROOTVOLUME, rootVolume);
2365 * Pass the kernel the name of the workstation cache file holding the
2366 * volume information.
2369 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
2370 fullpn_VolInfoFile);
2371 /* once again, meaningless for a memory-based cache. */
2372 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2373 afsd_call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
2376 * Give the kernel the names of the AFS files cached on the workstation's
2381 ("%s: Calling AFSOP_CACHEFILE for each of the %d files in '%s'\n",
2382 rn, cacheFiles, cacheBaseDir);
2383 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2384 /* ... and again ... */
2385 int nocachefile = 0;
2386 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
2388 sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
2389 code = afsd_call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
2391 if (currVFile == 0) {
2394 ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
2395 rn, cacheFiles, cacheBaseDir);
2399 ("%s: Error calling AFSOP_CACHEFILE for '%s'\n",
2406 /* fall through to setup-by-inode */
2408 #ifdef AFS_SGI62_ENV
2409 afsd_call_syscall(AFSOP_CACHEINODE,
2410 (afs_uint32) (inode_for_V[currVFile] >> 32),
2411 (afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
2412 #elif !(defined(AFS_LINUX26_ENV) || defined(AFS_CACHE_VNODE_PATH))
2413 afsd_call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
2416 ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
2424 * All the necessary info has been passed into the kernel to run an AFS
2425 * system. Give the kernel our go-ahead.
2428 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
2430 afsd_call_syscall(AFSOP_GO, 0);
2433 * At this point, we have finished passing the kernel all the info
2434 * it needs to set up the AFS. Mount the AFS root.
2436 printf("%s: All AFS daemons started.\n", rn);
2439 printf("%s: Forking trunc-cache daemon.\n", rn);
2440 fork_syscall(rn, AFSOP_START_TRUNCDAEMON);
2442 if (!enable_nomount) {
2443 afsd_mount_afs(rn, afsd_cacheMountDir);
2449 printf("%s: Forking 'rmtsys' daemon.\n", rn);
2450 afsd_fork(0, rmtsysd_thread, NULL);
2452 #endif /* !UKERNEL */
2454 * Exit successfully.
2459 #include "AFS_component_version_number.c"
2464 struct cmd_syndesc *ts;
2466 ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
2469 cmd_AddParmAtOffset(ts, OPT_blocks, "-blocks", CMD_SINGLE,
2470 CMD_OPTIONAL, "1024 byte blocks in cache");
2471 cmd_AddParmAtOffset(ts, OPT_files, "-files", CMD_SINGLE,
2472 CMD_OPTIONAL, "files in cache");
2473 cmd_AddParmAtOffset(ts, OPT_rootvol, "-rootvol", CMD_SINGLE,
2474 CMD_OPTIONAL, "name of AFS root volume");
2475 cmd_AddParmAtOffset(ts, OPT_stat, "-stat", CMD_SINGLE,
2476 CMD_OPTIONAL, "number of stat entries");
2477 cmd_AddParmAtOffset(ts, OPT_memcache, "-memcache", CMD_FLAG,
2478 CMD_OPTIONAL, "run diskless");
2479 cmd_AddParmAtOffset(ts, OPT_cachedir, "-cachedir", CMD_SINGLE,
2480 CMD_OPTIONAL, "cache directory");
2481 cmd_AddParmAtOffset(ts, OPT_mountdir, "-mountdir", CMD_SINGLE,
2482 CMD_OPTIONAL, "mount location");
2483 cmd_AddParmAtOffset(ts, OPT_daemons, "-daemons", CMD_SINGLE,
2484 CMD_OPTIONAL, "number of daemons to use");
2485 cmd_AddParmAtOffset(ts, OPT_nosettime, "-nosettime", CMD_FLAG,
2486 CMD_OPTIONAL, "don't set the time");
2487 cmd_AddParmAtOffset(ts, OPT_verbose, "-verbose", CMD_FLAG,
2488 CMD_OPTIONAL, "display lots of information");
2489 cmd_AddParmAtOffset(ts, OPT_rmtsys, "-rmtsys", CMD_FLAG,
2490 CMD_OPTIONAL, "start NFS rmtsysd program");
2491 cmd_AddParmAtOffset(ts, OPT_debug, "-debug", CMD_FLAG,
2492 CMD_OPTIONAL, "display debug info");
2493 cmd_AddParmAtOffset(ts, OPT_chunksize, "-chunksize", CMD_SINGLE,
2494 CMD_OPTIONAL, "log(2) of chunk size");
2495 cmd_AddParmAtOffset(ts, OPT_dcache, "-dcache", CMD_SINGLE,
2496 CMD_OPTIONAL, "number of dcache entries");
2497 cmd_AddParmAtOffset(ts, OPT_volumes, "-volumes", CMD_SINGLE,
2498 CMD_OPTIONAL, "number of volume entries");
2499 cmd_AddParmAtOffset(ts, OPT_biods, "-biods", CMD_SINGLE,
2500 CMD_OPTIONAL, "number of bkg I/O daemons (aix vm)");
2501 cmd_AddParmAtOffset(ts, OPT_prealloc, "-prealloc", CMD_SINGLE,
2502 CMD_OPTIONAL, "number of 'small' preallocated blocks");
2503 cmd_AddParmAtOffset(ts, OPT_confdir, "-confdir", CMD_SINGLE,
2504 CMD_OPTIONAL, "configuration directory");
2505 cmd_AddParmAtOffset(ts, OPT_logfile, "-logfile", CMD_SINGLE,
2506 CMD_OPTIONAL, "Place to keep the CM log");
2507 cmd_AddParmAtOffset(ts, OPT_waitclose, "-waitclose", CMD_FLAG,
2508 CMD_OPTIONAL, "make close calls synchronous");
2509 cmd_AddParmAtOffset(ts, OPT_shutdown, "-shutdown", CMD_FLAG,
2510 CMD_OPTIONAL, "Shutdown all afs state");
2511 cmd_AddParmAtOffset(ts, OPT_peerstats, "-enable_peer_stats", CMD_FLAG,
2512 CMD_OPTIONAL | CMD_HIDE,
2513 "Collect rpc statistics by peer");
2514 cmd_AddParmAtOffset(ts, OPT_processstats, "-enable_process_stats",
2515 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2516 "Collect rpc statistics for this process");
2517 cmd_AddParmAtOffset(ts, OPT_memallocsleep, "-mem_alloc_sleep",
2518 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2519 "Allow sleeps when allocating memory cache");
2520 cmd_AddParmAtOffset(ts, OPT_afsdb, "-afsdb", CMD_FLAG,
2521 CMD_OPTIONAL, "Enable AFSDB support");
2522 cmd_AddParmAtOffset(ts, OPT_filesdir, "-files_per_subdir", CMD_SINGLE,
2524 "log(2) of the number of cache files per "
2525 "cache subdirectory");
2526 cmd_AddParmAtOffset(ts, OPT_dynroot, "-dynroot", CMD_FLAG,
2527 CMD_OPTIONAL, "Enable dynroot support");
2528 cmd_AddParmAtOffset(ts, OPT_fakestat, "-fakestat", CMD_FLAG,
2530 "Enable fakestat support for cross-cell mounts");
2531 cmd_AddParmAtOffset(ts, OPT_fakestatall, "-fakestat-all", CMD_FLAG,
2533 "Enable fakestat support for all mounts");
2534 cmd_AddParmAtOffset(ts, OPT_nomount, "-nomount", CMD_FLAG,
2535 CMD_OPTIONAL, "Do not mount AFS");
2536 cmd_AddParmAtOffset(ts, OPT_backuptree, "-backuptree", CMD_FLAG,
2538 "Prefer backup volumes for mointpoints in backup "
2540 cmd_AddParmAtOffset(ts, OPT_rxbind, "-rxbind", CMD_FLAG,
2542 "Bind the Rx socket (one interface only)");
2543 cmd_AddParmAtOffset(ts, OPT_settime, "-settime", CMD_FLAG,
2544 CMD_OPTIONAL, "set the time");
2545 cmd_AddParmAtOffset(ts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
2546 "set rx_extraPackets to this value");
2547 cmd_AddParmAtOffset(ts, OPT_splitcache, "-splitcache", CMD_SINGLE,
2549 "Percentage RW versus RO in cache (specify as 60/40)");
2550 cmd_AddParmAtOffset(ts, OPT_nodynvcache, "-disable-dynamic-vcaches",
2551 CMD_FLAG, CMD_OPTIONAL,
2552 "disable stat/vcache cache growing as needed");
2553 cmd_AddParmAtOffset(ts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
2554 CMD_OPTIONAL, "set rx max MTU to use");
2555 cmd_AddParmAtOffset(ts, OPT_dynrootsparse, "-dynroot-sparse", CMD_FLAG,
2557 "Enable dynroot support with minimal cell list");
2558 cmd_AddParmAtOffset(ts, OPT_rxmaxfrags, "-rxmaxfrags", CMD_SINGLE,
2560 "Set the maximum number of UDP fragments Rx should "
2561 "send/receive per Rx packet");
2565 afsd_parse(int argc, char **argv)
2567 return cmd_Dispatch(argc, argv);
2570 struct afsd_syscall_args {
2582 * entry point for calling a syscall from another proc/thread.
2584 * @param[in] rock a struct afsd_syscall_args* specifying what syscall to call
2587 * @retval NULL always
2590 call_syscall_thread(void *rock)
2592 struct afsd_syscall_args *args = rock;
2596 afsd_set_rx_rtpri();
2599 code = afsd_call_syscall(args->syscall, args->param1, args->param2,
2600 args->param3, args->param4, args->param5);
2601 if (code && args->syscall == AFSOP_START_CS) {
2602 printf("%s: No check server daemon in client.\n", args->rn);
2611 * common code for calling a syscall in another proc/thread.
2613 * @param[in] rx 1 if this is a thread for RX stuff, 0 otherwise
2614 * @param[in] wait 1 if we should wait for the new proc/thread to finish, 0 to
2615 * let it run in the background
2616 * @param[in] rn the name of the running program
2617 * @param[in] syscall syscall to run
2620 fork_syscall_impl(int rx, int wait, const char *rn, long syscall, long param1,
2621 long param2, long param3, long param4, long param5)
2623 struct afsd_syscall_args *args;
2625 args = malloc(sizeof(*args));
2627 args->syscall = syscall;
2628 args->param1 = param1;
2629 args->param2 = param2;
2630 args->param3 = param3;
2631 args->param4 = param4;
2632 args->param5 = param5;
2636 afsd_fork(wait, call_syscall_thread, args);
2640 * call a syscall in another process or thread.
2643 fork_syscall(const char *rn, long syscall, long param1, long param2,
2644 long param3, long param4, long param5)
2646 fork_syscall_impl(0, 0, rn, syscall, param1, param2, param3, param4, param5);
2650 * call a syscall in another process or thread, and give it RX priority.
2653 fork_rx_syscall(const char *rn, long syscall, long param1, long param2,
2654 long param3, long param4, long param5)
2656 fork_syscall_impl(1, 0, rn, syscall, param1, param2, param3, param4, param5);
2659 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
2661 * call a syscall in another process or thread, give it RX priority, and wait
2662 * for it to finish before returning.
2665 fork_rx_syscall_wait(const char *rn, long syscall, long param1, long param2,
2666 long param3, long param4, long param5)
2668 fork_syscall_impl(1, 1, rn, syscall, param1, param2, param3, param4, param5);
2670 #endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */