2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Information Technology Center
15 * The Andrew File System startup process. It is responsible for
16 * reading and parsing the various configuration files, starting up
17 * the kernel processes required by AFS and feeding the configuration
18 * information to the kernel.
20 * Recognized flags are:
21 * -blocks The number of blocks available in the workstation cache.
22 * -files The target number of files in the workstation cache (Default:
24 * -rootvol The name of the root volume to use.
25 * -stat The number of stat cache entries.
26 * -hosts List of servers to check for volume location info FOR THE
28 * -memcache Use an in-memory cache rather than disk.
29 * -cachedir The base directory for the workstation cache.
30 * -mountdir The directory on which the AFS is to be mounted.
31 * -confdir The configuration directory .
32 * -nosettime Don't keep checking the time to avoid drift (default).
33 * -settime Keep checking the time to avoid drift.
34 * -rxmaxmtu Set the max mtu to help with VPN issues.
36 * -disable-dynamic-vcaches Disable the use of -stat value as the starting size of
37 * the size of the vcache/stat cache pool,
38 * but increase that pool dynamically as needed.
39 * -debug Print out additional debugging info.
40 * -kerndev [OBSOLETE] The kernel device for AFS.
41 * -dontfork [OBSOLETE] Don't fork off as a new process.
42 * -daemons The number of background daemons to start (Default: 2).
43 * -rmtsys Also fires up an afs remote sys call (e.g. pioctl, setpag)
45 * -chunksize [n] 2^n is the chunksize to be used. 0 is default.
46 * -dcache The number of data cache entries.
47 * -biods Number of bkg I/O daemons (AIX3.1 only)
48 * -prealloc Number of preallocated "small" memory blocks
49 * -logfile [OBSOLETE] Place where to put the logfile (default in
51 * -waitclose make close calls always synchronous (slows em down, tho)
52 * -files_per_subdir [n] number of files per cache subdir. (def=2048)
53 * -shutdown Shutdown afs daemons
54 *---------------------------------------------------------------------------*/
56 #include <afsconfig.h>
57 #include <afs/param.h>
60 #ifdef IGNORE_SOME_GCC_WARNINGS
61 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
68 #include <afs/opr_assert.h>
74 #include <afs/afsutil.h>
81 #include <sys/types.h>
88 /* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
90 #if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
99 #ifdef HAVE_SYS_PARAM_H
100 #include <sys/param.h>
103 #ifdef HAVE_SYS_FS_TYPES_H
104 #include <sys/fs_types.h>
107 #if defined(HAVE_SYS_MOUNT_H) && !defined(AFS_ARM_DARWIN_ENV)
108 #include <sys/mount.h>
111 #ifdef HAVE_SYS_FCNTL_H
112 #include <sys/fcntl.h>
115 #ifdef HAVE_SYS_MNTTAB_H
116 #include <sys/mnttab.h>
119 #ifdef HAVE_SYS_MNTENT_H
120 #include <sys/mntent.h>
127 #ifdef HAVE_SYS_VFS_H
131 #ifdef HAVE_SYS_FSTYP_H
132 #include <sys/fstyp.h>
143 #include <netinet/in.h>
144 #include <afs/afs_args.h>
145 #include <afs/cellconfig.h>
147 #include <afs/afssyscalls.h>
148 #include <afs/afsutil.h>
149 #include <afs/sys_prototypes.h>
155 #include <libdwarf.h>
156 void set_staticaddrs(void);
157 #endif /* AFS_SGI61_ENV */
158 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
160 #include <symconst.h>
166 #ifdef AFS_DARWIN_ENV
167 #ifdef AFS_DARWIN80_ENV
168 #include <sys/ioctl.h>
169 #include <sys/xattr.h>
171 #include <CoreFoundation/CoreFoundation.h>
173 #include <SystemConfiguration/SystemConfiguration.h>
174 #include <SystemConfiguration/SCDynamicStore.h>
176 #ifndef AFS_ARM_DARWIN_ENV
177 #include <IOKit/pwr_mgt/IOPMLib.h>
178 #include <IOKit/IOMessage.h>
180 static io_connect_t root_port;
181 static IONotificationPortRef notify;
182 static io_object_t iterator;
185 static CFRunLoopSourceRef source;
187 static int event_pid;
189 #endif /* AFS_DARWIN_ENV */
191 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
192 #include <sys/statvfs.h>
194 #if defined(AFS_SUN_ENV)
197 #ifdef HAVE_SYS_STATFS_H
198 #include <sys/statfs.h>
207 #define CACHEINFOFILE "cacheinfo"
208 #define DCACHEFILE "CacheItems"
209 #define VOLINFOFILE "VolumeItems"
210 #define CELLINFOFILE "CellItems"
212 #define MAXIPADDRS 1024
214 char LclCellName[64];
216 #define MAX_CACHE_LOOPS 4
220 * Internet address (old style... should be updated). This was pulled out of the old 4.2
221 * version of <netinet/in.h>, since it's still useful.
226 u_char s_b1, s_b2, s_b3, s_b4;
235 #define mPrintIPAddr(ipaddr) printf("[%d.%d.%d.%d] ", \
236 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b1, \
237 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b2, \
238 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b3, \
239 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b4)
242 * Global configuration variables.
244 static afs_int32 enable_rxbind = 0;
245 static afs_int32 afs_shutdown = 0;
246 static afs_int32 cacheBlocks; /*Num blocks in the cache */
247 static afs_int32 cacheFiles; /*Optimal # of files in workstation cache */
248 static afs_int32 rwpct = 0;
249 static afs_int32 ropct = 0;
250 static afs_int32 cacheStatEntries; /*Number of stat cache entries */
251 static char cacheBaseDir[1024]; /*Where the workstation AFS cache lives */
252 static char confDir[1024]; /*Where the workstation AFS configuration lives */
253 static char fullpn_DCacheFile[1024]; /*Full pathname of DCACHEFILE */
254 static char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE */
255 static char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE */
256 static char fullpn_CacheInfo[1024]; /*Full pathname of CACHEINFO */
257 static char fullpn_VFile[1024]; /*Full pathname of data cache files */
258 static char *vFilePtr; /*Ptr to the number part of above pathname */
259 static int sawCacheMountDir = 0; /* from cmd line */
260 static int sawCacheBaseDir = 0;
261 static int sawCacheBlocks = 0;
262 static int sawDCacheSize = 0;
264 static int sawBiod = 0;
266 static int sawCacheStatEntries = 0;
267 char afsd_cacheMountDir[1024]; /*Mount directory for AFS */
268 static char rootVolume[64] = "root.afs"; /*AFS root volume name */
269 static afs_int32 cacheSetTime = 0; /*Keep checking time to avoid drift? */
271 static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC; /*Create & truncate on open */
273 static int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open */
275 static int ownerRWmode = 0600; /*Read/write OK by owner */
276 static int filesSet = 0; /*True if number of files explicitly set */
277 static int nFilesPerDir = 2048; /* # files per cache dir */
278 #if defined(AFS_CACHE_BYPASS)
279 #define AFSD_NDAEMONS 4
281 #define AFSD_NDAEMONS 2
283 static int nDaemons = AFSD_NDAEMONS; /* Number of background daemons */
284 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
285 static int dCacheSize; /* # of dcache entries */
286 static int vCacheSize = 200; /* # of volume cache entries */
287 static int rootVolSet = 0; /*True if root volume name explicitly set */
288 int addrNum; /*Cell server address index being printed */
289 static int cacheFlags = 0; /*Flags to cache manager */
291 static int nBiods = 5; /* AIX3.1 only */
293 static int preallocs = 400; /* Def # of allocated memory blocks */
294 static int enable_peer_stats = 0; /* enable rx stats */
295 static int enable_process_stats = 0; /* enable rx stats */
296 static int enable_afsdb = 0; /* enable AFSDB support */
297 static int enable_dynroot = 0; /* enable dynroot support */
298 static int enable_fakestat = 0; /* enable fakestat support */
299 static int enable_backuptree = 0; /* enable backup tree support */
300 static int enable_nomount = 0; /* do not mount */
301 static int enable_splitcache = 0;
302 static int afsd_dynamic_vcaches = 0; /* Enable dynamic-vcache support */
303 int afsd_verbose = 0; /*Are we being chatty? */
304 int afsd_debug = 0; /*Are we printing debugging info? */
305 static int afsd_CloseSynch = 0; /*Are closes synchronous or not? */
306 static int rxmaxmtu = 0; /* Are we forcing a limit on the mtu? */
307 static int rxmaxfrags = 0; /* Are we forcing a limit on frags? */
310 #define AFSD_INO_T ino64_t
312 #define AFSD_INO_T afs_uint32
314 struct afsd_file_list {
316 struct afsd_file_list *next;
318 struct afsd_file_list **cache_dir_filelist = NULL;
319 int *cache_dir_list = NULL; /* Array of cache subdirs */
320 int *dir_for_V = NULL; /* Array: dir of each cache file.
321 * -1: file does not exist
322 * -2: file exists in top-level
323 * >=0: file exists in Dxxx
325 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
326 AFSD_INO_T *inode_for_V; /* Array of inodes for desired
329 int missing_DCacheFile = 1; /*Is the DCACHEFILE missing? */
330 int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing? */
331 int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing? */
332 int afsd_rmtsys = 0; /* Default: don't support rmtsys */
333 struct afs_cacheParams cparams; /* params passed to cache manager */
335 int PartSizeOverflow(char *path, int cs);
337 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
338 static void fork_rx_syscall_wait();
340 static void fork_rx_syscall();
341 static void fork_syscall();
343 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
345 afsd_sleep_callback(void * refCon, io_service_t service,
346 natural_t messageType, void * messageArgument )
348 switch (messageType) {
349 case kIOMessageCanSystemSleep:
350 /* Idle sleep is about to kick in; can
351 prevent sleep by calling IOCancelPowerChange, otherwise
352 if we don't ack in 30s the system sleeps anyway */
355 IOAllowPowerChange(root_port, (long)messageArgument);
358 case kIOMessageSystemWillSleep:
359 /* The system WILL go to sleep. Ack or suffer delay */
361 IOAllowPowerChange(root_port, (long)messageArgument);
364 case kIOMessageSystemWillRestart:
365 /* The system WILL restart. Ack or suffer delay */
367 IOAllowPowerChange(root_port, (long)messageArgument);
370 case kIOMessageSystemWillPowerOn:
371 case kIOMessageSystemHasPoweredOn:
372 /* coming back from sleep */
374 IOAllowPowerChange(root_port, (long)messageArgument);
378 IOAllowPowerChange(root_port, (long)messageArgument);
384 afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
386 /* parse multihomed address files */
387 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
393 parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
394 AFSDIR_CLIENT_NETINFO_FILEPATH,
395 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
398 /* Note we're refreshing */
399 code = code | 0x40000000;
400 afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
402 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
405 /* Since it's likely this means our DNS server changed, reinit now */
410 /* This function is called when the system's ip addresses may have changed. */
412 afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
414 CFRunLoopTimerRef timer;
416 timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
417 0.0, 0, 0, afsd_update_addresses, NULL);
418 CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
419 kCFRunLoopDefaultMode);
424 afsd_event_cleanup(int signo) {
426 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
428 IODeregisterForSystemPower(&iterator);
429 IOServiceClose(root_port);
430 IONotificationPortDestroy(notify);
434 /* Adapted from "Living in a Dynamic TCP/IP Environment" technote. */
436 afsd_install_events(void)
438 SCDynamicStoreContext ctx = {0};
439 SCDynamicStoreRef store;
441 root_port = IORegisterForSystemPower(0,¬ify,afsd_sleep_callback,&iterator);
444 CFRunLoopAddSource(CFRunLoopGetCurrent(),
445 IONotificationPortGetRunLoopSource(notify),
446 kCFRunLoopDefaultMode);
450 store = SCDynamicStoreCreate (NULL,
451 CFSTR ("AddIPAddressListChangeCallbackSCF"),
452 afsd_ipaddr_callback, &ctx);
457 /* Request IPV4 address change notification */
458 keys[0] = (SCDynamicStoreKeyCreateNetworkServiceEntity
459 (NULL, kSCDynamicStoreDomainState,
460 kSCCompAnyRegex, kSCEntNetIPv4));
463 /* This should tell us when the hostname(s) change. do we care? */
464 keys[N] = SCDynamicStoreKeyCreateHostNames (NULL);
467 if (keys[0] != NULL) {
468 CFArrayRef pattern_array;
470 pattern_array = CFArrayCreate (NULL, keys, 1,
471 &kCFTypeArrayCallBacks);
473 if (pattern_array != NULL)
475 SCDynamicStoreSetNotificationKeys (store, NULL, pattern_array);
476 source = SCDynamicStoreCreateRunLoopSource (NULL, store, 0);
478 CFRelease (pattern_array);
488 if (source != NULL) {
489 CFRunLoopAddSource (CFRunLoopGetCurrent(),
490 source, kCFRunLoopDefaultMode);
493 signal(SIGTERM, afsd_event_cleanup);
499 /* ParseArgs is now obsolete, being handled by cmd */
501 /*------------------------------------------------------------------------------
505 * Open the file containing the description of the workstation's AFS cache
506 * and pull out its contents. The format of this file is as follows:
508 * cacheMountDir:cacheBaseDir:cacheBlocks
514 * 0 if everything went well,
518 * Nothing interesting.
522 *---------------------------------------------------------------------------*/
525 ParseCacheInfoFile(void)
527 static char rn[] = "ParseCacheInfoFile"; /*This routine's name */
528 FILE *cachefd; /*Descriptor for cache info file */
529 int parseResult; /*Result of our fscanf() */
530 afs_int32 tCacheBlocks;
531 char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
534 printf("%s: Opening cache info file '%s'...\n", rn, fullpn_CacheInfo);
536 cachefd = fopen(fullpn_CacheInfo, "r");
538 printf("%s: Can't read cache info file '%s'\n", rn, fullpn_CacheInfo);
543 * Parse the contents of the cache info file. All chars up to the first
544 * colon are the AFS mount directory, all chars to the next colon are the
545 * full path name of the workstation cache directory and all remaining chars
546 * represent the number of blocks in the cache.
548 tCacheMountDir[0] = tCacheBaseDir[0] = '\0';
550 fscanf(cachefd, "%1024[^:]:%1024[^:]:%d", tCacheMountDir,
551 tCacheBaseDir, &tCacheBlocks);
554 * Regardless of how the parse went, we close the cache info file.
558 if (parseResult == EOF || parseResult < 3) {
559 printf("%s: Format error in cache info file!\n", rn);
560 if (parseResult == EOF)
561 printf("\tEOF encountered before any field parsed.\n");
563 printf("\t%d out of 3 fields successfully parsed.\n",
569 for (tmd = tCacheMountDir; *tmd == '\n' || *tmd == ' ' || *tmd == '\t';
571 for (tbd = tCacheBaseDir; *tbd == '\n' || *tbd == ' ' || *tbd == '\t';
573 /* now copy in the fields not explicitly overridden by cmd args */
574 if (!sawCacheMountDir)
575 strcpy(afsd_cacheMountDir, tmd);
576 if (!sawCacheBaseDir)
577 strcpy(cacheBaseDir, tbd);
579 cacheBlocks = tCacheBlocks;
582 printf("%s: Cache info file successfully parsed:\n", rn);
584 ("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
585 tmd, tbd, tCacheBlocks);
587 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
588 return (PartSizeOverflow(tbd, cacheBlocks));
595 * All failures to open the partition are ignored. Also if the cache dir
596 * isn't a mounted partition it's also ignored since we can't guarantee
597 * what will be stored afterwards. Too many if's. This is now purely
598 * advisory. ODS with over 2G partition also gives warning message.
601 * 0 if everything went well,
605 PartSizeOverflow(char *path, int cs)
608 afs_int64 totalblks, mint;
609 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
610 struct statvfs statbuf;
612 if (statvfs(path, &statbuf) != 0) {
615 ("statvfs failed on %s; skip checking for adequate partition space\n",
619 totalblks = statbuf.f_blocks;
620 bsize = statbuf.f_frsize;
622 if (strcmp(statbuf.f_basetype, "jfs")) {
623 fprintf(stderr, "Cache filesystem '%s' must be jfs (now %s)\n",
624 path, statbuf.f_basetype);
627 #endif /* AFS_AIX51_ENV */
629 #else /* AFS_HAVE_STATVFS */
630 struct statfs statbuf;
632 if (statfs(path, &statbuf) < 0) {
635 ("statfs failed on %s; skip checking for adequate partition space\n",
639 totalblks = statbuf.f_blocks;
640 bsize = statbuf.f_bsize;
643 return 0; /* success */
645 /* now free and totalblks are in fragment units, but we want them in 1K units */
647 totalblks *= (bsize / 1024);
649 totalblks /= (1024 / bsize);
652 mint = totalblks / 100 * 95;
655 ("Cache size (%d) must be less than 95%% of partition size (which is %lld). Lower cache size\n",
663 /*-----------------------------------------------------------------------------
667 * Given the final component of a filename expected to be a data cache file,
668 * return the integer corresponding to the file. Note: we reject names that
669 * are not a ``V'' followed by an integer. We also reject those names having
670 * the right format but lying outside the range [0..cacheFiles-1].
673 * fname : Char ptr to the filename to parse.
674 * max : integer for the highest number to accept
677 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
681 * Nothing interesting.
685 *---------------------------------------------------------------------------*/
688 doGetXFileNumber(char *fname, char filechar, int maxNum)
690 int computedVNumber; /*The computed file number we return */
691 int filenameLen; /*Number of chars in filename */
692 int currDigit; /*Current digit being processed */
695 * The filename must have at least two characters, the first of which must be a ``filechar''
696 * and the second of which cannot be a zero unless the file is exactly two chars long.
698 filenameLen = strlen(fname);
701 if (fname[0] != filechar)
703 if ((filenameLen > 2) && (fname[1] == '0'))
707 * Scan through the characters in the given filename, failing immediately if a non-digit
710 for (currDigit = 1; currDigit < filenameLen; currDigit++)
711 if (isdigit(fname[currDigit]) == 0)
715 * All relevant characters are digits. Pull out the decimal number they represent.
716 * Reject it if it's out of range, otherwise return it.
718 computedVNumber = atoi(++fname);
719 if (computedVNumber < cacheFiles)
720 return (computedVNumber);
726 GetVFileNumber(char *fname, int maxFile)
728 return doGetXFileNumber(fname, 'V', maxFile);
732 GetDDirNumber(char *fname, int maxDir)
734 return doGetXFileNumber(fname, 'D', maxDir);
738 /*-----------------------------------------------------------------------------
742 * Given a full pathname for a file we need to create for the workstation AFS
743 * cache, go ahead and create the file.
746 * fname : Full pathname of file to create.
747 * statp : A pointer to a stat buffer which, if NON-NULL, will be
751 * 0 iff the file was created,
755 * The given cache file has been found to be missing.
759 *---------------------------------------------------------------------------*/
762 CreateCacheSubDir(char *basename, int dirNum)
764 static char rn[] = "CreateCacheSubDir"; /* Routine Name */
768 /* Build the new cache subdirectory */
769 sprintf(dir, "%s/D%d", basename, dirNum);
772 printf("%s: Creating cache subdir '%s'\n", rn, dir);
774 if ((ret = mkdir(dir, 0700)) != 0) {
775 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, dir,
781 /* Mark this directory as created */
782 cache_dir_list[dirNum] = 0;
784 /* And return success */
789 SetNoBackupAttr(char *fullpn)
791 #ifdef AFS_DARWIN80_ENV
794 ret = setxattr(fullpn, "com.apple.metadata:com_apple_backup_excludeItem",
795 "com.apple.backupd", strlen("com.apple.backupd"), 0,
800 fprintf(stderr, "afsd: Warning: failed to set attribute to preclude cache backup: %s\n", strerror(errno));
807 MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
810 static char rn[] = "MoveCacheFile";
811 char from[1024], to[1024];
814 if (cache_dir_list[toDir] < 0
815 && (ret = CreateCacheSubDir(basename, toDir))) {
816 printf("%s: Can't create directory '%s/D%d'\n", rn, basename, toDir);
820 /* Build the from,to dir */
822 /* old-style location */
823 snprintf(from, sizeof(from), "%s/V%d", basename, cacheFile);
825 snprintf(from, sizeof(from), "%s/D%d/V%d", basename, fromDir,
829 snprintf(to, sizeof(from), "%s/D%d/V%d", basename, toDir, cacheFile);
832 printf("%s: Moving cacheFile from '%s' to '%s'\n", rn, from, to);
834 if ((ret = rename(from, to)) != 0) {
835 printf("%s: Can't rename '%s' to '%s', error return is %d (%d)\n", rn,
836 from, to, ret, errno);
841 /* Reset directory pointer; fix file counts */
842 dir_for_V[cacheFile] = toDir;
843 cache_dir_list[toDir]++;
844 if (fromDir < maxDir && fromDir >= 0)
845 cache_dir_list[fromDir]--;
851 CreateCacheFile(char *fname, struct stat *statp)
853 static char rn[] = "CreateCacheFile"; /*Routine name */
854 int cfd; /*File descriptor to AFS cache file */
855 int closeResult; /*Result of close() */
858 printf("%s: Creating cache file '%s'\n", rn, fname);
859 cfd = open(fname, createAndTrunc, ownerRWmode);
861 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
866 closeResult = fstat(cfd, statp);
869 ("%s: Can't stat newly-created AFS cache file '%s' (code %d)\n",
874 closeResult = close(cfd);
877 ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
886 CreateFileIfMissing(char *fullpn, int missing)
889 if (CreateCacheFile(fullpn, NULL))
890 printf("CreateFileIfMissing: Can't create '%s'\n", fullpn);
895 UnlinkUnwantedFile(char *rn, char *fullpn_FileToDelete, char *fileToDelete)
897 if (unlink(fullpn_FileToDelete)) {
898 if ((errno == EISDIR || errno == EPERM) && *fileToDelete == 'D') {
899 if (rmdir(fullpn_FileToDelete)) {
900 printf("%s: Can't rmdir '%s', errno is %d\n", rn,
901 fullpn_FileToDelete, errno);
904 printf("%s: Can't unlink '%s', errno is %d\n", rn,
905 fullpn_FileToDelete, errno);
909 /*-----------------------------------------------------------------------------
913 * Sweep through the AFS cache directory, recording the inode number for
914 * each valid data cache file there. Also, delete any file that doesn't belong
915 * in the cache directory during this sweep, and remember which of the other
916 * residents of this directory were seen. After the sweep, we create any data
917 * cache files that were missing.
920 * vFilesFound : Set to the number of data cache files found.
923 * 0 if everything went well,
927 * This routine may be called several times. If the number of data cache files
928 * found is less than the global cacheFiles, then the caller will need to call it
929 * again to record the inodes of the missing zero-length data cache files created
930 * in the previous call.
933 * Fills up the global inode_for_V array, may create and/or delete files as
935 *---------------------------------------------------------------------------*/
939 doSweepAFSCache(int *vFilesFound,
940 char *directory, /* /path/to/cache/directory */
941 int dirNum, /* current directory number */
942 int maxDir) /* maximum directory number */
944 static char rn[] = "doSweepAFSCache"; /* Routine Name */
945 char fullpn_FileToDelete[1024]; /*File to be deleted from cache */
946 char *fileToDelete; /*Ptr to last component of above */
947 DIR *cdirp; /*Ptr to cache directory structure */
949 struct dirent64 *currp; /*Current directory entry */
951 struct dirent *currp; /*Current directory entry */
953 int vFileNum; /*Data cache file's associated number */
954 int thisDir; /* A directory number */
958 printf("%s: Opening cache directory '%s'\n", rn, directory);
960 if (chmod(directory, 0700)) { /* force it to be 700 */
961 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
965 cdirp = opendir(directory);
966 if (cdirp == (DIR *) 0) {
967 printf("%s: Can't open AFS cache directory, '%s'.\n", rn, directory);
972 * Scan the directory entries, remembering data cache file inodes
973 * and the existance of other important residents. Recurse into
974 * the data subdirectories.
976 * Delete all files and directories that don't belong here.
978 sprintf(fullpn_FileToDelete, "%s/", directory);
979 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
982 for (currp = readdir64(cdirp); currp; currp = readdir64(cdirp))
984 for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
988 printf("%s: Current directory entry:\n", rn);
989 #if defined(AFS_SGI62_ENV) || defined(AFS_DARWIN90_ENV)
990 printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
991 currp->d_reclen, currp->d_name);
992 #elif defined(AFS_DFBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
993 printf("\tinode=%ld, name='%s'\n", (long)currp->d_ino, currp->d_name);
995 printf("\tinode=%ld, reclen=%d, name='%s'\n", (long)currp->d_ino,
996 currp->d_reclen, currp->d_name);
1001 * If dirNum < 0, we are a top-level cache directory and should
1002 * only contain sub-directories and other sundry files. Therefore,
1003 * V-files are valid only if dirNum >= 0, and Directories are only
1004 * valid if dirNum < 0.
1007 if (*(currp->d_name) == 'V'
1008 && ((vFileNum = GetVFileNumber(currp->d_name, cacheFiles)) >=
1011 * Found a valid data cache filename. Remember this
1012 * file's inode, directory, and bump the number of files found
1013 * total and in this directory.
1015 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1016 inode_for_V[vFileNum] = currp->d_ino;
1018 dir_for_V[vFileNum] = dirNum; /* remember this directory */
1021 /* If we're in a real subdir, mark this file to be moved
1022 * if we've already got too many files in this directory
1024 assert(dirNum >= 0);
1025 cache_dir_list[dirNum]++; /* keep directory's file count */
1026 if (cache_dir_list[dirNum] > nFilesPerDir) {
1027 /* Too many files -- add to filelist */
1028 struct afsd_file_list *tmp = (struct afsd_file_list *)
1029 malloc(sizeof(*tmp));
1032 ("%s: MALLOC FAILED allocating file_list entry\n",
1035 tmp->fileNum = vFileNum;
1036 tmp->next = cache_dir_filelist[dirNum];
1037 cache_dir_filelist[dirNum] = tmp;
1042 } else if (dirNum < 0 && (*(currp->d_name) == 'D')
1043 && GetDDirNumber(currp->d_name, 1 << 30) >= 0) {
1045 if ((vFileNum = GetDDirNumber(currp->d_name, maxDir)) >= 0) {
1046 /* Found a valid cachefile sub-Directory. Remember this number
1047 * and recurse into it. Note that subdirs cannot have subdirs.
1050 } else if ((vFileNum = GetDDirNumber(currp->d_name, 1 << 30)) >=
1052 /* This directory is going away, but figure out if there
1053 * are any cachefiles in here that should be saved by
1054 * moving them to other cache directories. This directory
1055 * will be removed later.
1060 /* Save the highest directory number we've seen */
1061 if (vFileNum > highDir)
1064 /* If this directory is staying, be sure to mark it as 'found' */
1066 cache_dir_list[vFileNum] = 0;
1068 /* Print the dirname for recursion */
1069 sprintf(fileToDelete, "%s", currp->d_name);
1071 /* Note: vFileNum is the directory number */
1073 doSweepAFSCache(vFilesFound, fullpn_FileToDelete, vFileNum,
1074 (retval == 1 ? 0 : -1));
1076 printf("%s: Recursive sweep failed on directory %s\n", rn,
1080 } else if (dirNum < 0 && strcmp(currp->d_name, DCACHEFILE) == 0) {
1082 * Found the file holding the dcache entries.
1084 missing_DCacheFile = 0;
1085 SetNoBackupAttr(fullpn_DCacheFile);
1086 } else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
1088 * Found the file holding the volume info.
1090 missing_VolInfoFile = 0;
1091 SetNoBackupAttr(fullpn_VolInfoFile);
1092 } else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
1094 * Found the file holding the cell info.
1096 missing_CellInfoFile = 0;
1097 SetNoBackupAttr(fullpn_CellInfoFile);
1098 } else if ((strcmp(currp->d_name, ".") == 0)
1099 || (strcmp(currp->d_name, "..") == 0) ||
1100 #ifdef AFS_DECOSF_ENV
1101 /* these are magic AdvFS files */
1102 (strcmp(currp->d_name, ".tags") == 0)
1103 || (strcmp(currp->d_name, "quota.user") == 0)
1104 || (strcmp(currp->d_name, "quota.group") == 0) ||
1106 #ifdef AFS_LINUX22_ENV
1107 /* this is the ext3 journal file */
1108 (strcmp(currp->d_name, ".journal") == 0) ||
1110 (strcmp(currp->d_name, "lost+found") == 0)) {
1112 * Don't do anything - this file is legit, and is to be left alone.
1116 * This file/directory doesn't belong in the cache. Nuke it.
1118 sprintf(fileToDelete, "%s", currp->d_name);
1120 printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
1121 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1128 * Create all the cache files that are missing.
1130 CreateFileIfMissing(fullpn_DCacheFile, missing_DCacheFile);
1131 CreateFileIfMissing(fullpn_VolInfoFile, missing_VolInfoFile);
1132 CreateFileIfMissing(fullpn_CellInfoFile, missing_CellInfoFile);
1134 /* ADJUST CACHE FILES */
1136 /* First, let's walk through the list of files and figure out
1137 * if there are any leftover files in extra directories or
1138 * missing files. Move the former and create the latter in
1139 * subdirs with extra space.
1142 thisDir = 0; /* Keep track of which subdir has space */
1144 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++) {
1145 if (dir_for_V[vFileNum] == -1) {
1146 /* This file does not exist. Create it in the first
1147 * subdir that still has extra space.
1149 while (thisDir < maxDir
1150 && cache_dir_list[thisDir] >= nFilesPerDir)
1152 if (thisDir >= maxDir)
1153 printf("%s: can't find directory to create V%d\n", rn,
1157 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1158 assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
1160 sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
1162 printf("%s: Creating '%s'\n", rn, fullpn_VFile);
1163 if (cache_dir_list[thisDir] < 0
1164 && CreateCacheSubDir(directory, thisDir))
1165 printf("%s: Can't create directory for '%s'\n", rn,
1167 if (CreateCacheFile(fullpn_VFile, &statb))
1168 printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
1170 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
1171 inode_for_V[vFileNum] = statb.st_ino;
1173 dir_for_V[vFileNum] = thisDir;
1174 cache_dir_list[thisDir]++;
1177 SetNoBackupAttr(fullpn_VFile);
1180 } else if (dir_for_V[vFileNum] >= maxDir
1181 || dir_for_V[vFileNum] == -2) {
1182 /* This file needs to move; move it to the first subdir
1183 * that has extra space. (-2 means it's in the toplevel)
1185 while (thisDir < maxDir
1186 && cache_dir_list[thisDir] >= nFilesPerDir)
1188 if (thisDir >= maxDir)
1189 printf("%s: can't find directory to move V%d\n", rn,
1193 (directory, dir_for_V[vFileNum], thisDir, vFileNum,
1195 /* Cannot move. Ignore this file??? */
1202 /* At this point, we've moved all of the valid cache files
1203 * into the valid subdirs, and created all the extra
1204 * cachefiles we need to create. Next, rebalance any subdirs
1205 * with too many cache files into the directories with not
1206 * enough cache files. Note that thisDir currently sits at
1207 * the lowest subdir that _may_ have room.
1210 for (dirNum = 0; dirNum < maxDir; dirNum++) {
1211 struct afsd_file_list *thisFile;
1213 for (thisFile = cache_dir_filelist[dirNum];
1214 thisFile && cache_dir_list[dirNum] >= nFilesPerDir;
1215 thisFile = thisFile->next) {
1216 while (thisDir < maxDir
1217 && cache_dir_list[thisDir] >= nFilesPerDir)
1219 if (thisDir >= maxDir)
1220 printf("%s: can't find directory to move V%d\n", rn,
1224 (directory, dirNum, thisDir, thisFile->fileNum,
1226 /* Cannot move. Ignore this file??? */
1230 } /* for each file to move */
1231 } /* for each directory */
1233 /* Remove any directories >= maxDir -- they should be empty */
1234 for (; highDir >= maxDir; highDir--) {
1235 sprintf(fileToDelete, "D%d", highDir);
1236 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1242 * Close the directory, return success.
1245 printf("%s: Closing cache directory.\n", rn);
1251 CheckCacheBaseDir(char *dir)
1253 struct stat statbuf;
1256 return "cache base dir not specified";
1258 if (stat(dir, &statbuf) != 0) {
1259 return "unable to stat cache base directory";
1262 /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */
1264 #ifdef AFS_LINUX24_ENV
1267 struct statfs statfsbuf;
1269 res = statfs(dir, &statfsbuf);
1271 return "unable to statfs cache base directory";
1273 #if !defined(AFS_LINUX26_ENV)
1274 if (statfsbuf.f_type == 0x52654973) { /* REISERFS_SUPER_MAGIC */
1275 return "cannot use reiserfs as cache partition";
1276 } else if (statfsbuf.f_type == 0x58465342) { /* XFS_SUPER_MAGIC */
1277 return "cannot use xfs as cache partition";
1278 } else if (statfsbuf.f_type == 0x01021994) { /* TMPFS_SUPER_MAGIC */
1279 return "cannot use tmpfs as cache partition";
1280 } else if (statfsbuf.f_type != 0xEF53) {
1281 return "must use ext2 or ext3 for cache partition";
1290 struct statfs statfsbuf;
1293 res = statfs(dir, &statfsbuf);
1295 return "unable to statfs cache base directory";
1298 if (sysfs(GETFSTYP, statfsbuf.f_fsid[1], name) != 0) {
1299 return "unable to determine filesystem type for cache base dir";
1302 if (strcmp(name, "hfs")) {
1303 return "can only use hfs filesystem for cache partition on hpux";
1312 struct stat statmnt, statci;
1314 if ((stat(dir, &statci) == 0)
1315 && ((vfstab = fopen(MNTTAB, "r")) != NULL)) {
1316 while (getmntent(vfstab, &mnt) == 0) {
1317 if (strcmp(dir, mnt.mnt_mountp) != 0) {
1321 if (cp = hasmntopt(&mnt, "dev="))
1323 (int)strtol(cp + strlen("dev="), (char **)NULL,
1326 if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
1327 rdev = statmnt.st_dev;
1329 if ((rdev == statci.st_dev)
1330 && (hasmntopt(&mnt, "logging") != NULL)) {
1334 "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n";
1348 SweepAFSCache(int *vFilesFound)
1350 static char rn[] = "SweepAFSCache"; /*Routine name */
1351 int maxDir = (cacheFiles + nFilesPerDir - 1) / nFilesPerDir;
1356 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1358 printf("%s: Memory Cache, no cache sweep done\n", rn);
1362 if (cache_dir_list == NULL) {
1363 cache_dir_list = (int *)malloc(maxDir * sizeof(*cache_dir_list));
1364 if (cache_dir_list == NULL) {
1365 printf("%s: Malloc Failed!\n", rn);
1368 for (i = 0; i < maxDir; i++)
1369 cache_dir_list[i] = -1; /* Does not exist */
1372 if (cache_dir_filelist == NULL) {
1373 cache_dir_filelist = (struct afsd_file_list **)
1374 malloc(maxDir * sizeof(*cache_dir_filelist));
1375 if (cache_dir_filelist == NULL) {
1376 printf("%s: Malloc Failed!\n", rn);
1379 memset(cache_dir_filelist, 0, maxDir * sizeof(*cache_dir_filelist));
1382 if (dir_for_V == NULL) {
1383 dir_for_V = (int *)malloc(cacheFiles * sizeof(*dir_for_V));
1384 if (dir_for_V == NULL) {
1385 printf("%s: Malloc Failed!\n", rn);
1388 for (i = 0; i < cacheFiles; i++)
1389 dir_for_V[i] = -1; /* Does not exist */
1392 /* Note, setting dirNum to -2 here will cause cachefiles found in
1393 * the toplevel directory to be marked in directory "-2". This
1394 * allows us to differentiate between 'file not seen' (-1) and
1395 * 'file seen in top-level' (-2). Then when we try to move the
1396 * file into a subdirectory, we know it's in the top-level instead
1397 * of some other cache subdir.
1399 return doSweepAFSCache(vFilesFound, cacheBaseDir, -2, maxDir);
1403 ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
1407 afs_int32 cellFlags = 0;
1408 afs_int32 hosts[MAXHOSTSPERCELL];
1410 /* figure out if this is the home cell */
1411 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
1413 cellFlags = 2; /* not home, suid is forbidden */
1414 if (enable_dynroot == 2)
1415 cellFlags |= 8; /* don't display foreign cells until looked up */
1417 /* build address list */
1418 for (i = 0; i < MAXHOSTSPERCELL; i++)
1419 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1421 if (aci->linkedCell)
1422 cellFlags |= 4; /* Flag that linkedCell arg exists,
1423 * for upwards compatibility */
1425 /* configure one cell */
1426 code = afsd_call_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
1427 aci->name, /* cell name */
1428 cellFlags, /* is this the home cell? */
1429 aci->linkedCell); /* Linked cell, if any */
1431 printf("Adding cell '%s': error %d\n", aci->name, code);
1436 ConfigCellAlias(struct afsconf_cellalias *aca,
1437 void *arock, struct afsconf_dir *adir)
1439 /* push the alias into the kernel */
1440 afsd_call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
1445 AfsdbLookupHandler(void)
1447 afs_int32 kernelMsg[64];
1448 char acellName[128];
1450 struct afsconf_cell acellInfo;
1455 acellName[0] = '\0';
1457 #if defined(AFS_DARWIN_ENV) && !defined(AFS_ARM_DARWIN_ENV)
1458 /* Fork the event handler also. */
1461 afsd_install_events();
1463 } else if (code != -1) {
1468 /* On some platforms you only get 4 args to an AFS call */
1469 int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
1471 afsd_call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
1472 if (code) { /* Something is wrong? */
1477 if (*acellName == 1) /* Shutting down */
1480 code = afsconf_GetAfsdbInfo(acellName, 0, &acellInfo);
1485 kernelMsg[0] = acellInfo.numServers;
1486 if (acellInfo.timeout)
1487 kernelMsg[1] = acellInfo.timeout - time(0);
1490 for (i = 0; i < acellInfo.numServers; i++)
1491 kernelMsg[i + 2] = acellInfo.hostAddr[i].sin_addr.s_addr;
1492 strncpy(acellName, acellInfo.name, sizeof(acellName));
1493 acellName[sizeof(acellName) - 1] = '\0';
1496 #ifdef AFS_DARWIN_ENV
1497 kill(event_pid, SIGTERM);
1501 #ifdef AFS_DARWIN_ENV
1506 struct afs_uspc_param *uspc;
1510 uspc = (struct afs_uspc_param *)malloc(sizeof(struct afs_uspc_param));
1511 memset(uspc, 0, sizeof(struct afs_uspc_param));
1512 memset(srcName, 0, sizeof(srcName));
1513 memset(dstName, 0, sizeof(dstName));
1515 /* brscount starts at 0 */
1521 char srcpath[BUFSIZ];
1522 char dstpath[BUFSIZ];
1524 /* pushing in a buffer this large */
1527 code = afsd_call_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
1528 if (code) { /* Something is wrong? */
1529 if (code == -2) /* shutting down */
1537 switch (uspc->reqtype) {
1539 snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1540 uspc->req.umv.sCell, uspc->req.umv.sVolume,
1541 uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
1542 snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1543 uspc->req.umv.dCell, uspc->req.umv.dVolume,
1544 uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
1545 if ((child = fork()) == 0) {
1546 /* first child does cp; second, rm. mv would re-enter. */
1548 switch (uspc->req.umv.idtype) {
1550 if (setuid(uspc->req.umv.id) != 0) {
1556 break; /* notreached */
1558 execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
1559 dstpath, (char *) NULL);
1561 if (child == (pid_t) -1) {
1566 if (waitpid(child, &status, 0) == -1)
1568 else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
1569 if ((child = fork()) == 0) {
1570 switch (uspc->req.umv.idtype) {
1572 if (setuid(uspc->req.umv.id) != 0) {
1578 break; /* notreached */
1580 execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
1581 srcpath, (char *) NULL);
1583 if (child == (pid_t) -1) {
1587 if (waitpid(child, &status, 0) == -1)
1589 else if (WIFEXITED(status) != 0) {
1590 /* rm exit status */
1591 uspc->retval = WEXITSTATUS(status);
1593 /* rm signal status */
1594 uspc->retval = -(WTERMSIG(status));
1597 /* error from cp: exit or signal status */
1598 uspc->retval = (WIFEXITED(status) != 0) ?
1599 WEXITSTATUS(status) : -(WTERMSIG(status));
1601 memset(srcName, 0, sizeof(srcName));
1602 memset(dstName, 0, sizeof(dstName));
1606 /* unknown req type */
1615 afsdb_thread(void *rock)
1617 /* Since the AFSDB lookup handler runs as a user process,
1618 * need to drop the controlling TTY, etc.
1620 if (afsd_daemon(0, 0) == -1) {
1621 printf("Error starting AFSDB lookup handler: %s\n",
1625 AfsdbLookupHandler();
1630 daemon_thread(void *rock)
1632 #ifdef AFS_DARWIN80_ENV
1633 /* Since the background daemon runs as a user process,
1634 * need to drop the controlling TTY, etc.
1636 if (afsd_daemon(0, 0) == -1) {
1637 printf("Error starting background daemon: %s\n",
1642 #elif defined(AFS_AIX32_ENV)
1643 afsd_call_syscall(AFSOP_START_BKG, 0);
1645 afsd_call_syscall(AFSOP_START_BKG);
1652 rmtsysd_thread(void *rock)
1657 #endif /* !UKERNEL */
1660 mainproc(struct cmd_syndesc *as, void *arock)
1662 afs_int32 code; /*Result of fork() */
1666 #ifdef AFS_SGI65_ENV
1667 struct sched_param sp;
1670 #ifdef AFS_SGI_VNODE_GLUE
1671 if (afs_init_kernel_config(-1) < 0) {
1672 printf("Can't determine NUMA configuration, not starting AFS.\n");
1677 /* call atoi on the appropriate parsed results */
1678 if (as->parms[0].items) {
1680 cacheBlocks = atoi(as->parms[0].items->data);
1683 if (as->parms[1].items) {
1685 cacheFiles = atoi(as->parms[1].items->data);
1686 filesSet = 1; /* set when spec'd on cmd line */
1688 if (as->parms[2].items) {
1690 strcpy(rootVolume, as->parms[2].items->data);
1693 if (as->parms[3].items) {
1695 cacheStatEntries = atoi(as->parms[3].items->data);
1696 sawCacheStatEntries = 1;
1698 if (as->parms[4].items) {
1700 cacheBaseDir[0] = '\0';
1701 sawCacheBaseDir = 1;
1702 cacheFlags |= AFSCALL_INIT_MEMCACHE;
1704 if (as->parms[5].items) {
1706 strcpy(cacheBaseDir, as->parms[5].items->data);
1707 sawCacheBaseDir = 1;
1709 if (as->parms[6].items) {
1711 strcpy(afsd_cacheMountDir, as->parms[6].items->data);
1712 sawCacheMountDir = 1;
1714 if (as->parms[7].items) {
1716 nDaemons = atoi(as->parms[7].items->data);
1718 if (as->parms[8].items) {
1722 if (as->parms[9].items) {
1726 if (as->parms[10].items) {
1730 printf("-rmtsys not supported for UKERNEL\n");
1734 if (as->parms[11].items) {
1739 if (as->parms[12].items) {
1741 chunkSize = atoi(as->parms[12].items->data);
1742 if (chunkSize < 0 || chunkSize > 30) {
1744 ("afsd:invalid chunk size (not in range 0-30), using default\n");
1748 if (as->parms[13].items) {
1750 dCacheSize = atoi(as->parms[13].items->data);
1753 if (as->parms[14].items) {
1755 vCacheSize = atoi(as->parms[14].items->data);
1757 if (as->parms[15].items) {
1759 #ifndef AFS_AIX32_ENV
1761 ("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
1763 nBiods = atoi(as->parms[15].items->data);
1767 if (as->parms[16].items) {
1769 preallocs = atoi(as->parms[16].items->data);
1771 strcpy(confDir, AFSDIR_CLIENT_ETC_DIRPATH);
1772 if (as->parms[17].items) {
1774 strcpy(confDir, as->parms[17].items->data);
1776 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
1777 if (as->parms[18].items) {
1779 printf("afsd: Ignoring obsolete -logfile flag\n");
1781 if (as->parms[19].items) {
1783 afsd_CloseSynch = 1;
1785 if (as->parms[20].items) {
1789 * Cold shutdown is the default
1791 printf("afsd: Shutting down all afs processes and afs state\n");
1792 code = afsd_call_syscall(AFSOP_SHUTDOWN, 1);
1794 printf("afsd: AFS still mounted; Not shutting down\n");
1799 if (as->parms[21].items) {
1800 /* -enable_peer_stats */
1801 enable_peer_stats = 1;
1803 if (as->parms[22].items) {
1804 /* -enable_process_stats */
1805 enable_process_stats = 1;
1807 if (as->parms[23].items) {
1808 /* -mem_alloc_sleep */
1809 printf("afsd: -mem_alloc_sleep is deprecated -- ignored\n");
1811 if (as->parms[24].items) {
1815 if (as->parms[25].items) {
1816 /* -files_per_subdir */
1817 int res = atoi(as->parms[25].items->data);
1818 if (res < 10 || res > (1 << 30)) {
1820 ("afsd:invalid number of files per subdir, \"%s\". Ignored\n",
1821 as->parms[25].items->data);
1826 if (as->parms[26].items) {
1830 if (as->parms[27].items) {
1832 enable_fakestat = 2;
1834 if (as->parms[28].items) {
1836 enable_fakestat = 1;
1838 if (as->parms[29].items) {
1842 if (as->parms[30].items) {
1844 enable_backuptree = 1;
1846 if (as->parms[31].items) {
1850 if (as->parms[32].items) {
1855 /* set rx_extraPackets */
1856 if (as->parms[33].items) {
1858 int rxpck = atoi(as->parms[33].items->data);
1859 printf("afsd: set rxpck = %d\n", rxpck);
1860 code = afsd_call_syscall(AFSOP_SET_RXPCK, rxpck);
1862 printf("afsd: failed to set rxpck\n");
1866 if (as->parms[34].items) {
1868 if (!as->parms[34].items->data ||
1869 ((c = strchr(as->parms[34].items->data, '/')) == NULL))
1871 ("ignoring splitcache (specify as RW/RO percentages: 60/40)\n");
1873 ropct = atoi((char *)c + 1);
1875 rwpct = atoi((char *)as->parms[34].items->data);
1876 if ((rwpct != 0) && (ropct != 0) && (ropct + rwpct == 100)) {
1878 enable_splitcache = 1;
1882 if (as->parms[35].items) {
1883 #ifdef AFS_MAXVCOUNT_ENV
1884 /* -disable-dynamic-vcaches */
1885 afsd_dynamic_vcaches = 0;
1887 printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
1891 #ifdef AFS_MAXVCOUNT_ENV
1893 /* -dynamic-vcaches */
1894 afsd_dynamic_vcaches = 1;
1898 printf("afsd: %s dynamically allocated vcaches\n", ( afsd_dynamic_vcaches ? "enabling" : "disabling" ));
1902 if (as->parms[36].items) {
1904 rxmaxmtu = atoi(as->parms[36].items->data);
1906 if (as->parms[37].items) {
1907 /* -dynroot-sparse */
1910 if (as->parms[38].items) {
1912 rxmaxfrags = atoi(as->parms[38].items->data);
1920 static char rn[] = "afsd"; /*Name of this routine */
1921 struct afsconf_dir *cdir; /* config dir */
1922 int lookupResult; /*Result of GetLocalCellName() */
1924 afs_int32 code; /*Result of fork() */
1925 char *fsTypeMsg = NULL;
1926 int cacheIteration; /*How many times through cache verification */
1927 int vFilesFound; /*How many data cache files were found in sweep */
1928 int currVFile; /*Current AFS cache file number passed in */
1931 * Pull out all the configuration info for the workstation's AFS cache and
1932 * the cellular community we're willing to let our users see.
1934 cdir = afsconf_Open(confDir);
1936 printf("afsd: some file missing or bad in %s\n", confDir);
1941 afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
1943 printf("%s: Can't get my home cell name! [Error is %d]\n", rn,
1947 printf("%s: My home cell is '%s'\n", rn, LclCellName);
1950 /* parse cacheinfo file if this is a diskcache */
1951 if (ParseCacheInfoFile()) {
1955 if (!enable_nomount) {
1956 if (afsd_check_mount(rn, afsd_cacheMountDir)) {
1961 /* do some random computations in memcache case to get things to work
1962 * reasonably no matter which parameters you set.
1964 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1965 /* memory cache: size described either as blocks or dcache entries, but
1969 fprintf(stderr, "%s: -files ignored with -memcache\n", rn);
1971 if (sawDCacheSize) {
1972 if (chunkSize == 0) {
1973 chunkSize = 13; /* 8k default chunksize for memcache */
1975 if (sawCacheBlocks) {
1977 ("%s: can't set cache blocks and dcache size simultaneously when diskless.\n",
1981 /* compute the cache size based on # of chunks times the chunk size */
1982 i = (1 << chunkSize); /* bytes per chunk */
1983 cacheBlocks = i * dCacheSize;
1984 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
1986 if (chunkSize == 0) {
1987 /* Try to autotune the memcache chunksize based on size
1988 * of memcache. This is done on the assumption that approx
1989 * 1024 chunks is suitable, it's a balance between enough
1990 * chunks to be useful and ramping up nicely when using larger
1991 * memcache to improve bulk read/write performance
1994 i <= 21 && (1 << i) / 1024 < (cacheBlocks / 1024); i++);
1997 /* compute the dcache size from overall cache size and chunk size */
1998 if (chunkSize > 10) {
1999 dCacheSize = (cacheBlocks >> (chunkSize - 10));
2000 } else if (chunkSize < 10) {
2001 dCacheSize = (cacheBlocks << (10 - chunkSize));
2003 dCacheSize = cacheBlocks;
2005 /* don't have to set sawDCacheSize here since it isn't overwritten
2006 * by ParseCacheInfoFile.
2010 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
2012 /* kernel computes # of dcache entries as min of cacheFiles and
2013 * dCacheSize, so we now make them equal.
2015 cacheFiles = dCacheSize;
2018 * Compute the number of cache files based on cache size,
2019 * but only if -files isn't given on the command line.
2020 * Don't let # files be so small as to prevent full utilization
2021 * of the cache unless user has explicitly asked for it.
2023 if (chunkSize == 0) {
2024 /* Set chunksize to 256kB - 1MB depending on cache size */
2025 if (cacheBlocks < 500000) {
2027 } else if (cacheBlocks < 1000000) {
2034 cacheFiles = cacheBlocks / 32; /* Assume 32k avg filesize */
2036 cacheFiles = max(cacheFiles, 1000);
2038 /* Always allow more files than chunks. Presume average V-file
2039 * is ~67% of a chunk... (another guess, perhaps Honeyman will
2040 * have a grad student write a paper). i is KILOBYTES.
2042 i = 1 << (chunkSize < 10 ? 0 : chunkSize - 10);
2043 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
2045 /* never permit more files than blocks, while leaving space for
2046 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
2047 * CacheItems is 50 Bytes / file (== 1K/20)
2049 #define CACHEITMSZ (cacheFiles / 20)
2050 #define VOLINFOSZ 50 /* 40kB has been seen, be conservative */
2051 #define CELLINFOSZ 4 /* Assuming disk block size is 4k ... */
2052 #define INFOSZ (VOLINFOSZ+CELLINFOSZ+CACHEITMSZ)
2054 /* Sanity check: If the obtained number of disk cache files
2055 * is larger than the number of available (4k) disk blocks, we're
2056 * doing something wrong. Fail hard so we can fix the bug instead
2057 * of silently hiding it like before */
2059 if (cacheFiles > (cacheBlocks - INFOSZ) / 4) {
2061 "%s: ASSERT: cacheFiles %d diskblocks %d\n",
2062 rn, cacheFiles, (cacheBlocks - INFOSZ) / 4);
2065 if (cacheFiles < 100)
2066 fprintf(stderr, "%s: WARNING: cache probably too small!\n",
2070 printf("%s: cacheFiles autotuned to %d\n", rn, cacheFiles);
2073 /* This actually needs to
2075 2) not second-guess when a chunksize comes from the command line
2076 3) be less, um, small. 2^2??
2078 /* Sanity check chunkSize */
2079 i = max(cacheBlocks / 1000, cacheBlocks / cacheFiles);
2080 chunkSize = min(chunkSize, i);
2081 chunkSize = max(chunkSize, 2);
2083 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
2086 if (!sawDCacheSize) {
2087 dCacheSize = cacheFiles / 2;
2088 if (dCacheSize > 10000) {
2091 if (dCacheSize < 2000) {
2095 printf("%s: dCacheSize autotuned to %d\n", rn, dCacheSize);
2098 if (!sawCacheStatEntries) {
2099 if (chunkSize <= 13) {
2100 cacheStatEntries = dCacheSize / 4;
2101 } else if (chunkSize >= 16) {
2102 cacheStatEntries = dCacheSize * 1.5;
2104 cacheStatEntries = dCacheSize;
2107 printf("%s: cacheStatEntries autotuned to %d\n", rn,
2111 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX26_ENV)
2113 * Create and zero the inode table for the desired cache files.
2115 inode_for_V = (AFSD_INO_T *) malloc(cacheFiles * sizeof(AFSD_INO_T));
2116 if (inode_for_V == (AFSD_INO_T *) 0) {
2118 ("%s: malloc() failed for cache file inode table with %d entries.\n",
2122 memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
2124 printf("%s: %d inode_for_V entries at 0x%x, %lu bytes\n", rn,
2125 cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
2129 * Set up all the pathnames we'll need for later.
2131 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
2132 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
2133 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
2134 sprintf(fullpn_VFile, "%s/", cacheBaseDir);
2135 vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
2137 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)
2138 && (fsTypeMsg = CheckCacheBaseDir(cacheBaseDir))) {
2140 printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2142 printf("%s: ERROR: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2148 * Set up all the kernel processes needed for AFS.
2151 setpgrp(getpid(), 0);
2155 * Set the primary cell name.
2157 afsd_call_syscall(AFSOP_SET_THISCELL, LclCellName);
2159 /* Initialize RX daemons and services */
2161 /* initialize the rx random number generator from user space */
2163 /* parse multihomed address files */
2164 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
2168 parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
2169 AFSDIR_CLIENT_NETINFO_FILEPATH,
2170 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
2173 code = code | 0x80000000;
2174 afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
2176 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
2180 /* Set realtime priority for most threads to same as for biod's. */
2181 afsd_set_afsd_rtpri();
2183 /* Start listener, then callback listener. Lastly, start rx event daemon.
2184 * Change in ordering is so that Linux port has socket fd in listener
2186 * preallocs are passed for both listener and callback server. Only
2187 * the one which actually does the initialization uses them though.
2189 if (preallocs < cacheStatEntries + 50)
2190 preallocs = cacheStatEntries + 50;
2191 #ifdef RXK_LISTENER_ENV
2193 printf("%s: Forking rx listener daemon.\n", rn);
2194 # ifdef AFS_SUN510_ENV
2195 fork_rx_syscall_wait(rn, AFSOP_RXLISTENER_DAEMON, preallocs,
2196 enable_peer_stats, enable_process_stats);
2197 # else /* !AFS_SUN510_ENV */
2198 fork_rx_syscall(rn, AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
2199 enable_process_stats);
2200 # endif /* !AFS_SUN510_ENV */
2203 printf("%s: Forking rx callback listener.\n", rn);
2204 #ifndef RXK_LISTENER_ENV
2205 fork_rx_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, enable_peer_stats,
2206 enable_process_stats);
2208 fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs);
2210 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
2212 printf("%s: Forking rxevent daemon.\n", rn);
2213 fork_rx_syscall(rn, AFSOP_RXEVENT_DAEMON);
2218 printf("%s: Forking AFSDB lookup handler.\n", rn);
2219 afsd_fork(0, afsdb_thread, NULL);
2221 code = afsd_call_syscall(AFSOP_BASIC_INIT, 1);
2223 printf("%s: Error %d in basic initialization.\n", rn, code);
2228 * Tell the kernel some basic information about the workstation's cache.
2232 ("%s: Calling AFSOP_CACHEINIT: %d stat cache entries, %d optimum cache files, %d blocks in the cache, flags = 0x%x, dcache entries %d\n",
2233 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
2235 memset(&cparams, '\0', sizeof(cparams));
2236 cparams.cacheScaches = cacheStatEntries;
2237 cparams.cacheFiles = cacheFiles;
2238 cparams.cacheBlocks = cacheBlocks;
2239 cparams.cacheDcaches = dCacheSize;
2240 cparams.cacheVolumes = vCacheSize;
2241 cparams.chunkSize = chunkSize;
2242 cparams.setTimeFlag = cacheSetTime;
2243 cparams.memCacheFlag = cacheFlags;
2244 cparams.dynamic_vcaches = afsd_dynamic_vcaches;
2245 afsd_call_syscall(AFSOP_CACHEINIT, &cparams);
2247 /* do it before we init the cache inodes */
2248 if (enable_splitcache) {
2249 afsd_call_syscall(AFSOP_BUCKETPCT, 1, rwpct);
2250 afsd_call_syscall(AFSOP_BUCKETPCT, 2, ropct);
2253 if (afsd_CloseSynch)
2254 afsd_call_syscall(AFSOP_CLOSEWAIT);
2257 * Sweep the workstation AFS cache directory, remembering the inodes of
2258 * valid files and deleting extraneous files. Keep sweeping until we
2259 * have the right number of data cache files or we've swept too many
2262 * This also creates files in the cache directory like VolumeItems and
2263 * CellItems, and thus must be ran before those are sent to the kernel.
2266 printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
2268 /* Memory-cache based system doesn't need any of this */
2269 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2272 if (SweepAFSCache(&vFilesFound)) {
2273 printf("%s: Error on sweep %d of workstation AFS cache \
2274 directory.\n", rn, cacheIteration);
2279 ("%s: %d out of %d data cache files found in sweep %d.\n",
2280 rn, vFilesFound, cacheFiles, cacheIteration);
2281 } while ((vFilesFound < cacheFiles)
2282 && (cacheIteration < MAX_CACHE_LOOPS));
2283 } else if (afsd_verbose)
2284 printf("%s: Using memory cache, not swept\n", rn);
2287 * Pass the kernel the name of the workstation cache file holding the
2291 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
2293 /* once again, meaningless for a memory-based cache. */
2294 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2295 afsd_call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
2298 * Pass the kernel the name of the workstation cache file holding the
2301 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2303 printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
2304 fullpn_CellInfoFile);
2305 afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
2310 printf("%s: Setting rxmaxfrags in kernel = %d\n", rn, rxmaxfrags);
2311 code = afsd_call_syscall(AFSOP_SET_RXMAXFRAGS, rxmaxfrags);
2313 printf("%s: Error seting rxmaxfrags\n", rn);
2318 printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
2319 code = afsd_call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
2321 printf("%s: Error seting rxmaxmtu\n", rn);
2324 if (enable_dynroot) {
2326 printf("%s: Enabling dynroot support in kernel%s.\n", rn,
2327 (enable_dynroot==2)?", not showing cells.":"");
2328 code = afsd_call_syscall(AFSOP_SET_DYNROOT, 1);
2330 printf("%s: Error enabling dynroot support.\n", rn);
2333 if (enable_fakestat) {
2335 printf("%s: Enabling fakestat support in kernel%s.\n", rn,
2336 (enable_fakestat==2)?" for all mountpoints."
2337 :" for crosscell mountpoints");
2338 code = afsd_call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
2340 printf("%s: Error enabling fakestat support.\n", rn);
2343 if (enable_backuptree) {
2345 printf("%s: Enabling backup tree support in kernel.\n", rn);
2346 code = afsd_call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
2348 printf("%s: Error enabling backup tree support.\n", rn);
2352 * Tell the kernel about each cell in the configuration.
2354 afsconf_CellApply(cdir, ConfigCell, NULL);
2355 afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
2357 /* Initialize AFS daemon threads. */
2359 printf("%s: Forking AFS daemon.\n", rn);
2360 fork_syscall(rn, AFSOP_START_AFS);
2363 printf("%s: Forking Check Server Daemon.\n", rn);
2364 fork_syscall(rn, AFSOP_START_CS);
2367 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
2368 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
2369 /* Add one because for sgi we always "steal" the first daemon for a
2370 * different task if we only have a 4K stack.
2374 for (i = 0; i < nDaemons; i++) {
2375 afsd_fork(0, daemon_thread, NULL);
2377 #ifdef AFS_AIX32_ENV
2379 nBiods = nDaemons * 2;
2382 for (i = 0; i < nBiods; i++) {
2383 fork_syscall(rn, AFSOP_START_BKG, nBiods);
2388 * If the root volume has been explicitly set, tell the kernel.
2392 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
2394 afsd_call_syscall(AFSOP_ROOTVOLUME, rootVolume);
2398 * Pass the kernel the name of the workstation cache file holding the
2399 * volume information.
2402 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
2403 fullpn_VolInfoFile);
2404 /* once again, meaningless for a memory-based cache. */
2405 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2406 afsd_call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
2409 * Give the kernel the names of the AFS files cached on the workstation's
2414 ("%s: Calling AFSOP_CACHEFILE for each of the %d files in '%s'\n",
2415 rn, cacheFiles, cacheBaseDir);
2416 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2417 /* ... and again ... */
2418 int nocachefile = 0;
2419 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
2421 sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
2422 code = afsd_call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
2424 if (currVFile == 0) {
2427 ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
2428 rn, cacheFiles, cacheBaseDir);
2432 ("%s: Error calling AFSOP_CACHEFILE for '%s'\n",
2439 /* fall through to setup-by-inode */
2441 #ifdef AFS_SGI62_ENV
2442 afsd_call_syscall(AFSOP_CACHEINODE,
2443 (afs_uint32) (inode_for_V[currVFile] >> 32),
2444 (afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
2445 #elif !(defined(AFS_LINUX26_ENV) || defined(AFS_CACHE_VNODE_PATH))
2446 afsd_call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
2449 ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
2457 * All the necessary info has been passed into the kernel to run an AFS
2458 * system. Give the kernel our go-ahead.
2461 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
2463 afsd_call_syscall(AFSOP_GO, cacheSetTime);
2466 * At this point, we have finished passing the kernel all the info
2467 * it needs to set up the AFS. Mount the AFS root.
2469 printf("%s: All AFS daemons started.\n", rn);
2472 printf("%s: Forking trunc-cache daemon.\n", rn);
2473 fork_syscall(rn, AFSOP_START_TRUNCDAEMON);
2475 if (!enable_nomount) {
2476 afsd_mount_afs(rn, afsd_cacheMountDir);
2482 printf("%s: Forking 'rmtsys' daemon.\n", rn);
2483 afsd_fork(0, rmtsysd_thread, NULL);
2485 #endif /* !UKERNEL */
2487 * Exit successfully.
2492 #include "AFS_component_version_number.c"
2497 struct cmd_syndesc *ts;
2499 ts = cmd_CreateSyntax(NULL, mainproc, NULL, "start AFS");
2502 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
2503 "1024 byte blocks in cache");
2504 cmd_AddParm(ts, "-files", CMD_SINGLE, CMD_OPTIONAL, "files in cache");
2505 cmd_AddParm(ts, "-rootvol", CMD_SINGLE, CMD_OPTIONAL,
2506 "name of AFS root volume");
2507 cmd_AddParm(ts, "-stat", CMD_SINGLE, CMD_OPTIONAL,
2508 "number of stat entries");
2509 cmd_AddParm(ts, "-memcache", CMD_FLAG, CMD_OPTIONAL, "run diskless");
2510 cmd_AddParm(ts, "-cachedir", CMD_SINGLE, CMD_OPTIONAL, "cache directory");
2511 cmd_AddParm(ts, "-mountdir", CMD_SINGLE, CMD_OPTIONAL, "mount location");
2512 cmd_AddParm(ts, "-daemons", CMD_SINGLE, CMD_OPTIONAL,
2513 "number of daemons to use");
2514 cmd_AddParm(ts, "-nosettime", CMD_FLAG, CMD_OPTIONAL,
2515 "don't set the time");
2516 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL,
2517 "display lots of information");
2518 cmd_AddParm(ts, "-rmtsys", CMD_FLAG, CMD_OPTIONAL,
2519 "start NFS rmtsysd program");
2522 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "display debug info");
2523 cmd_AddParm(ts, "-chunksize", CMD_SINGLE, CMD_OPTIONAL,
2524 "log(2) of chunk size");
2525 cmd_AddParm(ts, "-dcache", CMD_SINGLE, CMD_OPTIONAL,
2526 "number of dcache entries");
2527 cmd_AddParm(ts, "-volumes", CMD_SINGLE, CMD_OPTIONAL,
2528 "number of volume entries");
2529 cmd_AddParm(ts, "-biods", CMD_SINGLE, CMD_OPTIONAL,
2530 "number of bkg I/O daemons (aix vm)");
2531 cmd_AddParm(ts, "-prealloc", CMD_SINGLE, CMD_OPTIONAL,
2532 "number of 'small' preallocated blocks");
2533 cmd_AddParm(ts, "-confdir", CMD_SINGLE, CMD_OPTIONAL,
2534 "configuration directory");
2535 cmd_AddParm(ts, "-logfile", CMD_SINGLE, CMD_OPTIONAL,
2536 "Place to keep the CM log");
2537 cmd_AddParm(ts, "-waitclose", CMD_FLAG, CMD_OPTIONAL,
2538 "make close calls synchronous");
2539 cmd_AddParm(ts, "-shutdown", CMD_FLAG, CMD_OPTIONAL,
2540 "Shutdown all afs state");
2542 cmd_AddParm(ts, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
2543 "Collect rpc statistics by peer");
2544 cmd_AddParm(ts, "-enable_process_stats", CMD_FLAG,
2545 CMD_OPTIONAL | CMD_HIDE,
2546 "Collect rpc statistics for this process");
2547 cmd_AddParm(ts, "-mem_alloc_sleep", CMD_FLAG, (CMD_OPTIONAL | CMD_HIDE),
2548 "Allow sleeps when allocating memory cache");
2549 cmd_AddParm(ts, "-afsdb", CMD_FLAG, (CMD_OPTIONAL),
2550 "Enable AFSDB support");
2551 cmd_AddParm(ts, "-files_per_subdir", CMD_SINGLE, CMD_OPTIONAL,
2552 "log(2) of the number of cache files per cache subdirectory");
2553 cmd_AddParm(ts, "-dynroot", CMD_FLAG, CMD_OPTIONAL,
2554 "Enable dynroot support");
2555 cmd_AddParm(ts, "-fakestat", CMD_FLAG, CMD_OPTIONAL,
2556 "Enable fakestat support for cross-cell mounts");
2557 cmd_AddParm(ts, "-fakestat-all", CMD_FLAG, CMD_OPTIONAL,
2558 "Enable fakestat support for all mounts");
2559 cmd_AddParm(ts, "-nomount", CMD_FLAG, CMD_OPTIONAL, "Do not mount AFS");
2560 cmd_AddParm(ts, "-backuptree", CMD_FLAG, CMD_OPTIONAL,
2561 "Prefer backup volumes for mointpoints in backup volumes");
2563 cmd_AddParm(ts, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
2564 "Bind the Rx socket (one interface only)");
2565 cmd_AddParm(ts, "-settime", CMD_FLAG, CMD_OPTIONAL, "set the time");
2566 cmd_AddParm(ts, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
2567 "set rx_extraPackets to this value");
2568 cmd_AddParm(ts, "-splitcache", CMD_SINGLE, CMD_OPTIONAL,
2569 "Percentage RW versus RO in cache (specify as 60/40)");
2570 cmd_AddParm(ts, "-disable-dynamic-vcaches", CMD_FLAG, CMD_OPTIONAL,
2571 "disable stat/vcache cache growing as needed");
2572 cmd_AddParm(ts, "-rxmaxmtu", CMD_SINGLE, CMD_OPTIONAL, "set rx max MTU to use");
2573 cmd_AddParm(ts, "-dynroot-sparse", CMD_FLAG, CMD_OPTIONAL,
2574 "Enable dynroot support with minimal cell list");
2575 cmd_AddParm(ts, "-rxmaxfrags", CMD_SINGLE, CMD_OPTIONAL,
2576 "Set the maximum number of UDP fragments Rx should send/receive"
2581 afsd_parse(int argc, char **argv)
2583 return cmd_Dispatch(argc, argv);
2586 struct afsd_syscall_args {
2598 * entry point for calling a syscall from another proc/thread.
2600 * @param[in] rock a struct afsd_syscall_args* specifying what syscall to call
2603 * @retval NULL always
2606 call_syscall_thread(void *rock)
2608 struct afsd_syscall_args *args = rock;
2612 afsd_set_rx_rtpri();
2615 code = afsd_call_syscall(args->syscall, args->param1, args->param2,
2616 args->param3, args->param4, args->param5);
2617 if (code && args->syscall == AFSOP_START_CS) {
2618 printf("%s: No check server daemon in client.\n", args->rn);
2627 * common code for calling a syscall in another proc/thread.
2629 * @param[in] rx 1 if this is a thread for RX stuff, 0 otherwise
2630 * @param[in] wait 1 if we should wait for the new proc/thread to finish, 0 to
2631 * let it run in the background
2632 * @param[in] rn the name of the running program
2633 * @param[in] syscall syscall to run
2636 fork_syscall_impl(int rx, int wait, const char *rn, long syscall, long param1,
2637 long param2, long param3, long param4, long param5)
2639 struct afsd_syscall_args *args;
2641 args = malloc(sizeof(*args));
2643 args->syscall = syscall;
2644 args->param1 = param1;
2645 args->param2 = param2;
2646 args->param3 = param3;
2647 args->param4 = param4;
2648 args->param5 = param5;
2652 afsd_fork(wait, call_syscall_thread, args);
2656 * call a syscall in another process or thread.
2659 fork_syscall(const char *rn, long syscall, long param1, long param2,
2660 long param3, long param4, long param5)
2662 fork_syscall_impl(0, 0, rn, syscall, param1, param2, param3, param4, param5);
2666 * call a syscall in another process or thread, and give it RX priority.
2669 fork_rx_syscall(const char *rn, long syscall, long param1, long param2,
2670 long param3, long param4, long param5)
2672 fork_syscall_impl(1, 0, rn, syscall, param1, param2, param3, param4, param5);
2675 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
2677 * call a syscall in another process or thread, give it RX priority, and wait
2678 * for it to finish before returning.
2681 fork_rx_syscall_wait(const char *rn, long syscall, long param1, long param2,
2682 long param3, long param4, long param5)
2684 fork_syscall_impl(1, 1, rn, syscall, param1, param2, param3, param4, param5);
2686 #endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */