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 [OBSOLETE] 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 [IGNORED] 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 * -volumes The number of volume entries.
48 * -biods Number of bkg I/O daemons (AIX3.1 only)
49 * -prealloc Number of preallocated "small" memory blocks
50 * -logfile [IGNORED] Place where to put the logfile (default in
52 * -waitclose make close calls always synchronous (slows em down, tho)
53 * -files_per_subdir [n] number of files per cache subdir. (def=2048)
54 * -shutdown Shutdown afs daemons
55 * -enable_peer_stats Collect RPC statistics by peer.
56 * -enable_process_stats Collect RPC statistics for this process.
57 * -mem_alloc_sleep [IGNORED] Sleep when allocating memory.
58 * -afsdb Enable AFSDB support.
59 * -dynroot Enable dynroot support.
60 * -dynroot-sparse Enable dynroot support with minimal cell list.
61 * -fakestat Enable fake stat() for cross-cell mounts.
62 * -fakestat-all Enable fake stat() for all mounts.
63 * -nomount Do not mount /afs.
64 * -backuptree Prefer backup volumes for mountpoints in backup volumes.
65 * -rxbind Bind the rx socket.
66 * -rxpck Value for rx_extraPackets.
67 * -splitcache RW/RO ratio for cache.
68 * -rxmaxfrags Max number of UDP fragments per rx packet.
69 * -inumcalc inode number calculation method; 0=compat, 1=MD5 digest
70 * -volume-ttl vldb cache timeout in seconds
71 *---------------------------------------------------------------------------*/
73 #include <afsconfig.h>
74 #include <afs/param.h>
75 /* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
76 * defined, and roken includes dirent */
77 #if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
89 #include <afs/opr_assert.h>
95 #include <afs/afsutil.h>
99 #include <hcrypto/rand.h>
101 /* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
103 #if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
111 #ifdef HAVE_SYS_FS_TYPES_H
112 #include <sys/fs_types.h>
115 #if defined(HAVE_SYS_MOUNT_H) && !defined(AFS_ARM_DARWIN_ENV)
116 #include <sys/mount.h>
119 #ifdef HAVE_SYS_FCNTL_H
120 #include <sys/fcntl.h>
123 #ifdef HAVE_SYS_MNTTAB_H
124 #include <sys/mnttab.h>
127 #ifdef HAVE_SYS_MNTENT_H
128 #include <sys/mntent.h>
135 #ifdef HAVE_SYS_VFS_H
139 #ifdef HAVE_SYS_FSTYP_H
140 #include <sys/fstyp.h>
145 #include <afs/afs_args.h>
146 #include <afs/cellconfig.h>
147 #include <afs/afssyscalls.h>
148 #include <afs/afsutil.h>
149 #include <afs/sys_prototypes.h>
151 #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV)
153 #include <symconst.h>
159 #ifdef AFS_DARWIN_ENV
160 #ifdef AFS_DARWIN80_ENV
161 #include <sys/xattr.h>
163 #include <CoreFoundation/CoreFoundation.h>
165 static int event_pid;
166 #ifndef AFS_ARM_DARWIN_ENV
167 #define MACOS_EVENT_HANDLING 1
169 #endif /* AFS_DARWIN_ENV */
171 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
172 #include <sys/statvfs.h>
174 #if defined(AFS_SUN_ENV)
177 #ifdef HAVE_SYS_STATFS_H
178 #include <sys/statfs.h>
186 #ifdef AFS_SOCKPROXY_ENV
187 # include <sys/types.h>
188 # include <sys/socket.h>
191 #define CACHEINFOFILE "cacheinfo"
192 #define DCACHEFILE "CacheItems"
193 #define VOLINFOFILE "VolumeItems"
194 #define CELLINFOFILE "CellItems"
196 #define MAXIPADDRS 1024
198 char LclCellName[64];
200 #define MAX_CACHE_LOOPS 4
204 * Internet address (old style... should be updated). This was pulled out of the old 4.2
205 * version of <netinet/in.h>, since it's still useful.
210 u_char s_b1, s_b2, s_b3, s_b4;
219 #define mPrintIPAddr(ipaddr) printf("[%d.%d.%d.%d] ", \
220 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b1, \
221 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b2, \
222 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b3, \
223 ((struct in_addr_42 *) &(ipaddr))->S_un.S_un_b.s_b4)
226 * Global configuration variables.
228 static int enable_rxbind = 0;
229 static int cacheBlocks; /*Num blocks in the cache */
230 static int cacheFiles; /*Optimal # of files in workstation cache */
231 static int rwpct = 0;
232 static int ropct = 0;
233 static int cacheStatEntries; /*Number of stat cache entries */
234 static char *cacheBaseDir; /*Where the workstation AFS cache lives */
235 static char *confDir; /*Where the workstation AFS configuration lives */
236 static char fullpn_DCacheFile[1024]; /*Full pathname of DCACHEFILE */
237 static char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE */
238 static char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE */
239 static char fullpn_CacheInfo[1024]; /*Full pathname of CACHEINFO */
240 static char fullpn_VFile[1024]; /*Full pathname of data cache files */
241 static char *vFilePtr; /*Ptr to the number part of above pathname */
242 static int sawCacheMountDir = 0; /* from cmd line */
243 static int sawCacheBaseDir = 0;
244 static int sawCacheBlocks = 0;
245 static int sawDCacheSize = 0;
247 static int sawBiod = 0;
249 static int sawCacheStatEntries = 0;
250 char *afsd_cacheMountDir;
251 static char *rootVolume = NULL;
253 static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC; /*Create & truncate on open */
255 static int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open */
257 static int ownerRWmode = 0600; /*Read/write OK by owner */
258 static int filesSet = 0; /*True if number of files explicitly set */
259 static int nFilesPerDir = 2048; /* # files per cache dir */
260 #if defined(AFS_CACHE_BYPASS)
261 #define AFSD_NDAEMONS 4
263 #define AFSD_NDAEMONS 2
265 static int nDaemons = AFSD_NDAEMONS; /* Number of background daemons */
266 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
267 static int dCacheSize; /* # of dcache entries */
268 static int vCacheSize = 200; /* # of volume cache entries */
269 static int rootVolSet = 0; /*True if root volume name explicitly set */
270 int addrNum; /*Cell server address index being printed */
271 static int cacheFlags = 0; /*Flags to cache manager */
273 static int nBiods = 5; /* AIX3.1 only */
275 static int preallocs = 400; /* Def # of allocated memory blocks */
276 static int enable_peer_stats = 0; /* enable rx stats */
277 static int enable_process_stats = 0; /* enable rx stats */
278 static int enable_afsdb = 0; /* enable AFSDB support */
279 static int enable_dynroot = 0; /* enable dynroot support */
280 static int enable_fakestat = 0; /* enable fakestat support */
281 static int enable_backuptree = 0; /* enable backup tree support */
282 static int enable_nomount = 0; /* do not mount */
283 static int enable_splitcache = 0;
284 static char *inumcalc = NULL; /* inode number calculation method */
285 static int afsd_dynamic_vcaches = 0; /* Enable dynamic-vcache support */
286 int afsd_verbose = 0; /*Are we being chatty? */
287 int afsd_debug = 0; /*Are we printing debugging info? */
288 static int afsd_CloseSynch = 0; /*Are closes synchronous or not? */
289 static int rxmaxmtu = 0; /* Are we forcing a limit on the mtu? */
290 static int rxmaxfrags = 0; /* Are we forcing a limit on frags? */
291 static int volume_ttl = 0; /* enable vldb cache timeout support */
294 #define AFSD_INO_T ino64_t
296 #define AFSD_INO_T afs_uint32
298 struct afsd_file_list {
300 struct afsd_file_list *next;
302 struct afsd_file_list **cache_dir_filelist = NULL;
303 int *cache_dir_list = NULL; /* Array of cache subdirs */
304 int *dir_for_V = NULL; /* Array: dir of each cache file.
305 * -1: file does not exist
306 * -2: file exists in top-level
307 * >=0: file exists in Dxxx
309 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX_ENV)
310 AFSD_INO_T *inode_for_V; /* Array of inodes for desired
313 int missing_DCacheFile = 1; /*Is the DCACHEFILE missing? */
314 int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing? */
315 int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing? */
316 int afsd_rmtsys = 0; /* Default: don't support rmtsys */
317 struct afs_cacheParams cparams; /* params passed to cache manager */
319 int PartSizeOverflow(char *path, int cs);
321 static int afsd_syscall(int code, ...);
323 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
324 static void fork_rx_syscall_wait(const char *rn, int syscall, ...);
326 static void fork_rx_syscall(const char *rn, int syscall, ...);
327 static void fork_syscall(const char *rn, int syscall, ...);
373 #ifdef MACOS_EVENT_HANDLING
374 #include <SystemConfiguration/SystemConfiguration.h>
375 #include <SystemConfiguration/SCDynamicStore.h>
377 #include <IOKit/pwr_mgt/IOPMLib.h>
378 #include <IOKit/IOMessage.h>
380 static io_connect_t root_port;
381 static IONotificationPortRef notify;
382 static io_object_t iterator;
383 static CFRunLoopSourceRef source;
386 afsd_sleep_callback(void * refCon, io_service_t service,
387 natural_t messageType, void * messageArgument )
389 switch (messageType) {
390 case kIOMessageCanSystemSleep:
391 /* Idle sleep is about to kick in; can
392 prevent sleep by calling IOCancelPowerChange, otherwise
393 if we don't ack in 30s the system sleeps anyway */
396 IOAllowPowerChange(root_port, (long)messageArgument);
399 case kIOMessageSystemWillSleep:
400 /* The system WILL go to sleep. Ack or suffer delay */
402 IOAllowPowerChange(root_port, (long)messageArgument);
405 case kIOMessageSystemWillRestart:
406 /* The system WILL restart. Ack or suffer delay */
408 IOAllowPowerChange(root_port, (long)messageArgument);
411 case kIOMessageSystemWillPowerOn:
412 case kIOMessageSystemHasPoweredOn:
413 /* coming back from sleep */
415 IOAllowPowerChange(root_port, (long)messageArgument);
419 IOAllowPowerChange(root_port, (long)messageArgument);
425 afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
427 /* parse multihomed address files */
428 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
433 code = afsconf_ParseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS,
434 reason, AFSDIR_CLIENT_NETINFO_FILEPATH,
435 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
438 /* Note we're refreshing */
439 code = code | 0x40000000;
440 afsd_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
442 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
445 /* Since it's likely this means our DNS server changed, reinit now */
450 /* This function is called when the system's ip addresses may have changed. */
452 afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
454 CFRunLoopTimerRef timer;
456 timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
457 0.0, 0, 0, afsd_update_addresses, NULL);
458 CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
459 kCFRunLoopDefaultMode);
464 afsd_event_cleanup(int signo) {
466 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
468 IODeregisterForSystemPower(&iterator);
469 IOServiceClose(root_port);
470 IONotificationPortDestroy(notify);
474 /* Adapted from "Living in a Dynamic TCP/IP Environment" technote. */
476 afsd_install_events(void)
478 SCDynamicStoreContext ctx = {0};
479 SCDynamicStoreRef store;
481 root_port = IORegisterForSystemPower(0,¬ify,afsd_sleep_callback,&iterator);
484 CFRunLoopAddSource(CFRunLoopGetCurrent(),
485 IONotificationPortGetRunLoopSource(notify),
486 kCFRunLoopDefaultMode);
490 store = SCDynamicStoreCreate (NULL,
491 CFSTR ("AddIPAddressListChangeCallbackSCF"),
492 afsd_ipaddr_callback, &ctx);
497 /* Request IPV4 address change notification */
498 keys[0] = (SCDynamicStoreKeyCreateNetworkServiceEntity
499 (NULL, kSCDynamicStoreDomainState,
500 kSCCompAnyRegex, kSCEntNetIPv4));
502 if (keys[0] != NULL) {
503 CFArrayRef pattern_array;
505 pattern_array = CFArrayCreate (NULL, keys, 1,
506 &kCFTypeArrayCallBacks);
508 if (pattern_array != NULL)
510 SCDynamicStoreSetNotificationKeys (store, NULL, pattern_array);
511 source = SCDynamicStoreCreateRunLoopSource (NULL, store, 0);
513 CFRelease (pattern_array);
523 if (source != NULL) {
524 CFRunLoopAddSource (CFRunLoopGetCurrent(),
525 source, kCFRunLoopDefaultMode);
528 signal(SIGTERM, afsd_event_cleanup);
534 /* ParseArgs is now obsolete, being handled by cmd */
536 /*------------------------------------------------------------------------------
540 * Open the file containing the description of the workstation's AFS cache
541 * and pull out its contents. The format of this file is as follows:
543 * cacheMountDir:cacheBaseDir:cacheBlocks
549 * 0 if everything went well,
553 * Nothing interesting.
557 *---------------------------------------------------------------------------*/
560 ParseCacheInfoFile(void)
562 static char rn[] = "ParseCacheInfoFile"; /*This routine's name */
563 FILE *cachefd; /*Descriptor for cache info file */
564 int parseResult; /*Result of our fscanf() */
566 char tCacheBaseDir[1024], *tbd, tCacheMountDir[1024], *tmd;
569 printf("%s: Opening cache info file '%s'...\n", rn, fullpn_CacheInfo);
571 cachefd = fopen(fullpn_CacheInfo, "r");
573 printf("%s: Can't read cache info file '%s'\n", rn, fullpn_CacheInfo);
578 * Parse the contents of the cache info file. All chars up to the first
579 * colon are the AFS mount directory, all chars to the next colon are the
580 * full path name of the workstation cache directory and all remaining chars
581 * represent the number of blocks in the cache.
583 tCacheMountDir[0] = tCacheBaseDir[0] = '\0';
585 fscanf(cachefd, "%1024[^:]:%1024[^:]:%d", tCacheMountDir,
586 tCacheBaseDir, &tCacheBlocks);
589 * Regardless of how the parse went, we close the cache info file.
593 if (parseResult == EOF || parseResult < 3) {
594 printf("%s: Format error in cache info file!\n", rn);
595 if (parseResult == EOF)
596 printf("\tEOF encountered before any field parsed.\n");
598 printf("\t%d out of 3 fields successfully parsed.\n",
604 for (tmd = tCacheMountDir; *tmd == '\n' || *tmd == ' ' || *tmd == '\t';
606 for (tbd = tCacheBaseDir; *tbd == '\n' || *tbd == ' ' || *tbd == '\t';
608 /* now copy in the fields not explicitly overridden by cmd args */
609 if (!sawCacheMountDir)
610 afsd_cacheMountDir = strdup(tmd);
611 if (!sawCacheBaseDir)
612 cacheBaseDir = strdup(tbd);
614 cacheBlocks = tCacheBlocks;
617 printf("%s: Cache info file successfully parsed:\n", rn);
619 ("\tcacheMountDir: '%s'\n\tcacheBaseDir: '%s'\n\tcacheBlocks: %d\n",
620 tmd, tbd, tCacheBlocks);
622 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
623 return (PartSizeOverflow(tbd, cacheBlocks));
630 * All failures to open the partition are ignored. Also if the cache dir
631 * isn't a mounted partition it's also ignored since we can't guarantee
632 * what will be stored afterwards. Too many if's. This is now purely
633 * advisory. ODS with over 2G partition also gives warning message.
636 * 0 if everything went well,
640 PartSizeOverflow(char *path, int cs)
643 afs_int64 totalblks, mint;
644 #if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
645 struct statvfs statbuf;
647 if (statvfs(path, &statbuf) != 0) {
650 ("statvfs failed on %s; skip checking for adequate partition space\n",
654 totalblks = statbuf.f_blocks;
655 bsize = statbuf.f_frsize;
657 if (strcmp(statbuf.f_basetype, "jfs")) {
658 fprintf(stderr, "Cache filesystem '%s' must be jfs (now %s)\n",
659 path, statbuf.f_basetype);
662 #endif /* AFS_AIX51_ENV */
664 #else /* AFS_HAVE_STATVFS */
665 struct statfs statbuf;
667 if (statfs(path, &statbuf) < 0) {
670 ("statfs failed on %s; skip checking for adequate partition space\n",
674 totalblks = statbuf.f_blocks;
675 bsize = statbuf.f_bsize;
678 return 0; /* success */
680 /* now free and totalblks are in fragment units, but we want them in 1K units */
682 totalblks *= (bsize / 1024);
684 totalblks /= (1024 / bsize);
687 mint = totalblks / 100 * 95;
690 ("Cache size (%d) must be less than 95%% of partition size (which is %lld). Lower cache size\n",
698 /*-----------------------------------------------------------------------------
702 * Given the final component of a filename expected to be a data cache file,
703 * return the integer corresponding to the file. Note: we reject names that
704 * are not a ``V'' followed by an integer. We also reject those names having
705 * the right format but lying outside the range [0..cacheFiles-1].
708 * fname : Char ptr to the filename to parse.
709 * max : integer for the highest number to accept
712 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
716 * Nothing interesting.
720 *---------------------------------------------------------------------------*/
723 doGetXFileNumber(char *fname, char filechar, int maxNum)
725 int computedVNumber; /*The computed file number we return */
726 int filenameLen; /*Number of chars in filename */
727 int currDigit; /*Current digit being processed */
730 * The filename must have at least two characters, the first of which must be a ``filechar''
731 * and the second of which cannot be a zero unless the file is exactly two chars long.
733 filenameLen = strlen(fname);
736 if (fname[0] != filechar)
738 if ((filenameLen > 2) && (fname[1] == '0'))
742 * Scan through the characters in the given filename, failing immediately if a non-digit
745 for (currDigit = 1; currDigit < filenameLen; currDigit++)
746 if (isdigit(fname[currDigit]) == 0)
750 * All relevant characters are digits. Pull out the decimal number they represent.
751 * Reject it if it's out of range, otherwise return it.
753 computedVNumber = atoi(++fname);
754 if (computedVNumber < cacheFiles)
755 return (computedVNumber);
761 GetVFileNumber(char *fname, int maxFile)
763 return doGetXFileNumber(fname, 'V', maxFile);
767 GetDDirNumber(char *fname, int maxDir)
769 return doGetXFileNumber(fname, 'D', maxDir);
773 /*-----------------------------------------------------------------------------
777 * Given a full pathname for a file we need to create for the workstation AFS
778 * cache, go ahead and create the file.
781 * fname : Full pathname of file to create.
782 * statp : A pointer to a stat buffer which, if NON-NULL, will be
786 * 0 iff the file was created,
790 * The given cache file has been found to be missing.
794 *---------------------------------------------------------------------------*/
797 CreateCacheSubDir(char *basename, int dirNum)
799 static char rn[] = "CreateCacheSubDir"; /* Routine Name */
803 /* Build the new cache subdirectory */
804 sprintf(dir, "%s/D%d", basename, dirNum);
807 printf("%s: Creating cache subdir '%s'\n", rn, dir);
809 if ((ret = mkdir(dir, 0700)) != 0) {
810 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, dir,
816 /* Mark this directory as created */
817 cache_dir_list[dirNum] = 0;
819 /* And return success */
824 SetNoBackupAttr(char *fullpn)
826 #ifdef AFS_DARWIN80_ENV
829 ret = setxattr(fullpn, "com.apple.metadata:com_apple_backup_excludeItem",
830 "com.apple.backupd", strlen("com.apple.backupd"), 0,
835 fprintf(stderr, "afsd: Warning: failed to set attribute to preclude cache backup: %s\n", strerror(errno));
842 MoveCacheFile(char *basename, int fromDir, int toDir, int cacheFile,
845 static char rn[] = "MoveCacheFile";
846 char from[1024], to[1024];
849 if (cache_dir_list[toDir] < 0
850 && (ret = CreateCacheSubDir(basename, toDir))) {
851 printf("%s: Can't create directory '%s/D%d'\n", rn, basename, toDir);
855 /* Build the from,to dir */
857 /* old-style location */
858 snprintf(from, sizeof(from), "%s/V%d", basename, cacheFile);
860 snprintf(from, sizeof(from), "%s/D%d/V%d", basename, fromDir,
864 snprintf(to, sizeof(from), "%s/D%d/V%d", basename, toDir, cacheFile);
867 printf("%s: Moving cacheFile from '%s' to '%s'\n", rn, from, to);
869 if ((ret = rename(from, to)) != 0) {
870 printf("%s: Can't rename '%s' to '%s', error return is %d (%d)\n", rn,
871 from, to, ret, errno);
876 /* Reset directory pointer; fix file counts */
877 dir_for_V[cacheFile] = toDir;
878 cache_dir_list[toDir]++;
879 if (fromDir < maxDir && fromDir >= 0)
880 cache_dir_list[fromDir]--;
886 CreateCacheFile(char *fname, struct stat *statp)
888 static char rn[] = "CreateCacheFile"; /*Routine name */
889 int cfd; /*File descriptor to AFS cache file */
890 int closeResult; /*Result of close() */
893 printf("%s: Creating cache file '%s'\n", rn, fname);
894 cfd = open(fname, createAndTrunc, ownerRWmode);
896 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
901 closeResult = fstat(cfd, statp);
904 ("%s: Can't stat newly-created AFS cache file '%s' (code %d)\n",
909 closeResult = close(cfd);
912 ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
921 CreateFileIfMissing(char *fullpn, int missing)
924 if (CreateCacheFile(fullpn, NULL))
925 printf("CreateFileIfMissing: Can't create '%s'\n", fullpn);
930 UnlinkUnwantedFile(char *rn, char *fullpn_FileToDelete, char *fileToDelete)
932 if (unlink(fullpn_FileToDelete)) {
933 if ((errno == EISDIR || errno == EPERM) && *fileToDelete == 'D') {
934 if (rmdir(fullpn_FileToDelete)) {
935 printf("%s: Can't rmdir '%s', errno is %d\n", rn,
936 fullpn_FileToDelete, errno);
939 printf("%s: Can't unlink '%s', errno is %d\n", rn,
940 fullpn_FileToDelete, errno);
944 /*-----------------------------------------------------------------------------
948 * Sweep through the AFS cache directory, recording the inode number for
949 * each valid data cache file there. Also, delete any file that doesn't belong
950 * in the cache directory during this sweep, and remember which of the other
951 * residents of this directory were seen. After the sweep, we create any data
952 * cache files that were missing.
955 * vFilesFound : Set to the number of data cache files found.
958 * 0 if everything went well,
962 * This routine may be called several times. If the number of data cache files
963 * found is less than the global cacheFiles, then the caller will need to call it
964 * again to record the inodes of the missing zero-length data cache files created
965 * in the previous call.
968 * Fills up the global inode_for_V array, may create and/or delete files as
970 *---------------------------------------------------------------------------*/
974 doSweepAFSCache(int *vFilesFound,
975 char *directory, /* /path/to/cache/directory */
976 int dirNum, /* current directory number */
977 int maxDir) /* maximum directory number */
979 static char rn[] = "doSweepAFSCache"; /* Routine Name */
980 char fullpn_FileToDelete[1024]; /*File to be deleted from cache */
981 char *fileToDelete; /*Ptr to last component of above */
982 DIR *cdirp; /*Ptr to cache directory structure */
984 struct dirent64 *currp; /*Current directory entry */
986 struct dirent *currp; /*Current directory entry */
988 int vFileNum; /*Data cache file's associated number */
989 int thisDir; /* A directory number */
993 printf("%s: Opening cache directory '%s'\n", rn, directory);
995 if (chmod(directory, 0700)) { /* force it to be 700 */
996 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
1000 cdirp = opendir(directory);
1001 if (cdirp == (DIR *) 0) {
1002 printf("%s: Can't open AFS cache directory, '%s'.\n", rn, directory);
1007 * Scan the directory entries, remembering data cache file inodes
1008 * and the existance of other important residents. Recurse into
1009 * the data subdirectories.
1011 * Delete all files and directories that don't belong here.
1013 sprintf(fullpn_FileToDelete, "%s/", directory);
1014 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
1016 #ifdef AFS_SGI62_ENV
1017 for (currp = readdir64(cdirp); currp; currp = readdir64(cdirp))
1019 for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
1023 printf("%s: Current directory entry:\n", rn);
1024 #if defined(AFS_SGI62_ENV) || defined(AFS_DARWIN90_ENV)
1025 printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
1026 currp->d_reclen, currp->d_name);
1027 #elif defined(AFS_DFBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
1028 printf("\tinode=%ld, name='%s'\n", (long)currp->d_ino, currp->d_name);
1030 printf("\tinode=%ld, reclen=%d, name='%s'\n", (long)currp->d_ino,
1031 currp->d_reclen, currp->d_name);
1036 * If dirNum < 0, we are a top-level cache directory and should
1037 * only contain sub-directories and other sundry files. Therefore,
1038 * V-files are valid only if dirNum >= 0, and Directories are only
1039 * valid if dirNum < 0.
1042 if (*(currp->d_name) == 'V'
1043 && ((vFileNum = GetVFileNumber(currp->d_name, cacheFiles)) >=
1046 * Found a valid data cache filename. Remember this
1047 * file's inode, directory, and bump the number of files found
1048 * total and in this directory.
1050 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX_ENV)
1051 inode_for_V[vFileNum] = currp->d_ino;
1053 dir_for_V[vFileNum] = dirNum; /* remember this directory */
1056 /* If we're in a real subdir, mark this file to be moved
1057 * if we've already got too many files in this directory
1059 assert(dirNum >= 0);
1060 cache_dir_list[dirNum]++; /* keep directory's file count */
1061 if (cache_dir_list[dirNum] > nFilesPerDir) {
1062 /* Too many files -- add to filelist */
1063 struct afsd_file_list *tmp = malloc(sizeof(*tmp));
1066 ("%s: MALLOC FAILED allocating file_list entry\n",
1069 tmp->fileNum = vFileNum;
1070 tmp->next = cache_dir_filelist[dirNum];
1071 cache_dir_filelist[dirNum] = tmp;
1076 } else if (dirNum < 0 && (*(currp->d_name) == 'D')
1077 && GetDDirNumber(currp->d_name, 1 << 30) >= 0) {
1079 if ((vFileNum = GetDDirNumber(currp->d_name, maxDir)) >= 0) {
1080 /* Found a valid cachefile sub-Directory. Remember this number
1081 * and recurse into it. Note that subdirs cannot have subdirs.
1084 } else if ((vFileNum = GetDDirNumber(currp->d_name, 1 << 30)) >=
1086 /* This directory is going away, but figure out if there
1087 * are any cachefiles in here that should be saved by
1088 * moving them to other cache directories. This directory
1089 * will be removed later.
1094 /* Save the highest directory number we've seen */
1095 if (vFileNum > highDir)
1098 /* If this directory is staying, be sure to mark it as 'found' */
1100 cache_dir_list[vFileNum] = 0;
1102 /* Print the dirname for recursion */
1103 sprintf(fileToDelete, "%s", currp->d_name);
1105 /* Note: vFileNum is the directory number */
1107 doSweepAFSCache(vFilesFound, fullpn_FileToDelete, vFileNum,
1108 (retval == 1 ? 0 : -1));
1110 printf("%s: Recursive sweep failed on directory %s\n", rn,
1114 } else if (dirNum < 0 && strcmp(currp->d_name, DCACHEFILE) == 0) {
1116 * Found the file holding the dcache entries.
1118 missing_DCacheFile = 0;
1119 SetNoBackupAttr(fullpn_DCacheFile);
1120 } else if (dirNum < 0 && strcmp(currp->d_name, VOLINFOFILE) == 0) {
1122 * Found the file holding the volume info.
1124 missing_VolInfoFile = 0;
1125 SetNoBackupAttr(fullpn_VolInfoFile);
1126 } else if (dirNum < 0 && strcmp(currp->d_name, CELLINFOFILE) == 0) {
1128 * Found the file holding the cell info.
1130 missing_CellInfoFile = 0;
1131 SetNoBackupAttr(fullpn_CellInfoFile);
1132 } else if ((strcmp(currp->d_name, ".") == 0)
1133 || (strcmp(currp->d_name, "..") == 0) ||
1134 #ifdef AFS_LINUX_ENV
1135 /* this is the ext3 journal file */
1136 (strcmp(currp->d_name, ".journal") == 0) ||
1138 (strcmp(currp->d_name, "lost+found") == 0)) {
1140 * Don't do anything - this file is legit, and is to be left alone.
1144 * This file/directory doesn't belong in the cache. Nuke it.
1146 sprintf(fileToDelete, "%s", currp->d_name);
1148 printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
1149 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1156 * Create all the cache files that are missing.
1158 CreateFileIfMissing(fullpn_DCacheFile, missing_DCacheFile);
1159 CreateFileIfMissing(fullpn_VolInfoFile, missing_VolInfoFile);
1160 CreateFileIfMissing(fullpn_CellInfoFile, missing_CellInfoFile);
1162 /* ADJUST CACHE FILES */
1164 /* First, let's walk through the list of files and figure out
1165 * if there are any leftover files in extra directories or
1166 * missing files. Move the former and create the latter in
1167 * subdirs with extra space.
1170 thisDir = 0; /* Keep track of which subdir has space */
1172 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++) {
1173 if (dir_for_V[vFileNum] == -1) {
1174 /* This file does not exist. Create it in the first
1175 * subdir that still has extra space.
1177 while (thisDir < maxDir
1178 && cache_dir_list[thisDir] >= nFilesPerDir)
1180 if (thisDir >= maxDir)
1181 printf("%s: can't find directory to create V%d\n", rn,
1185 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX_ENV)
1186 assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
1188 sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
1190 printf("%s: Creating '%s'\n", rn, fullpn_VFile);
1191 if (cache_dir_list[thisDir] < 0
1192 && CreateCacheSubDir(directory, thisDir))
1193 printf("%s: Can't create directory for '%s'\n", rn,
1195 if (CreateCacheFile(fullpn_VFile, &statb))
1196 printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
1198 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX_ENV)
1199 inode_for_V[vFileNum] = statb.st_ino;
1201 dir_for_V[vFileNum] = thisDir;
1202 cache_dir_list[thisDir]++;
1205 SetNoBackupAttr(fullpn_VFile);
1208 } else if (dir_for_V[vFileNum] >= maxDir
1209 || dir_for_V[vFileNum] == -2) {
1210 /* This file needs to move; move it to the first subdir
1211 * that has extra space. (-2 means it's in the toplevel)
1213 while (thisDir < maxDir
1214 && cache_dir_list[thisDir] >= nFilesPerDir)
1216 if (thisDir >= maxDir)
1217 printf("%s: can't find directory to move V%d\n", rn,
1221 (directory, dir_for_V[vFileNum], thisDir, vFileNum,
1223 /* Cannot move. Ignore this file??? */
1230 /* At this point, we've moved all of the valid cache files
1231 * into the valid subdirs, and created all the extra
1232 * cachefiles we need to create. Next, rebalance any subdirs
1233 * with too many cache files into the directories with not
1234 * enough cache files. Note that thisDir currently sits at
1235 * the lowest subdir that _may_ have room.
1238 for (dirNum = 0; dirNum < maxDir; dirNum++) {
1239 struct afsd_file_list *thisFile;
1241 for (thisFile = cache_dir_filelist[dirNum];
1242 thisFile && cache_dir_list[dirNum] >= nFilesPerDir;
1243 thisFile = thisFile->next) {
1244 while (thisDir < maxDir
1245 && cache_dir_list[thisDir] >= nFilesPerDir)
1247 if (thisDir >= maxDir)
1248 printf("%s: can't find directory to move V%d\n", rn,
1252 (directory, dirNum, thisDir, thisFile->fileNum,
1254 /* Cannot move. Ignore this file??? */
1258 } /* for each file to move */
1259 } /* for each directory */
1261 /* Remove any directories >= maxDir -- they should be empty */
1262 for (; highDir >= maxDir; highDir--) {
1263 sprintf(fileToDelete, "D%d", highDir);
1264 UnlinkUnwantedFile(rn, fullpn_FileToDelete, fileToDelete);
1270 * Close the directory, return success.
1273 printf("%s: Closing cache directory.\n", rn);
1279 CheckCacheBaseDir(char *dir)
1281 struct stat statbuf;
1284 return "cache base dir not specified";
1286 if (stat(dir, &statbuf) != 0) {
1287 return "unable to stat cache base directory";
1290 /* might want to check here for anything else goofy, like cache pointed at a non-dedicated directory, etc */
1292 #ifdef AFS_LINUX_ENV
1295 struct statfs statfsbuf;
1297 res = statfs(dir, &statfsbuf);
1299 return "unable to statfs cache base directory";
1301 #if !defined(AFS_LINUX_ENV)
1302 if (statfsbuf.f_type == 0x52654973) { /* REISERFS_SUPER_MAGIC */
1303 return "cannot use reiserfs as cache partition";
1304 } else if (statfsbuf.f_type == 0x58465342) { /* XFS_SUPER_MAGIC */
1305 return "cannot use xfs as cache partition";
1306 } else if (statfsbuf.f_type == 0x01021994) { /* TMPFS_SUPER_MAGIC */
1307 return "cannot use tmpfs as cache partition";
1308 } else if (statfsbuf.f_type != 0xEF53) {
1309 return "must use ext2 or ext3 for cache partition";
1318 struct statfs statfsbuf;
1321 res = statfs(dir, &statfsbuf);
1323 return "unable to statfs cache base directory";
1326 if (sysfs(GETFSTYP, statfsbuf.f_fsid[1], name) != 0) {
1327 return "unable to determine filesystem type for cache base dir";
1330 if (strcmp(name, "hfs")) {
1331 return "can only use hfs filesystem for cache partition on hpux";
1340 struct stat statmnt, statci;
1342 if ((stat(dir, &statci) == 0)
1343 && ((vfstab = fopen(MNTTAB, "r")) != NULL)) {
1344 while (getmntent(vfstab, &mnt) == 0) {
1345 if (strcmp(dir, mnt.mnt_mountp) != 0) {
1349 if (cp = hasmntopt(&mnt, "dev="))
1351 (int)strtol(cp + strlen("dev="), NULL,
1354 if ((rdev == 0) && (stat(mnt.mnt_mountp, &statmnt) == 0))
1355 rdev = statmnt.st_dev;
1357 if ((rdev == statci.st_dev)
1358 && (hasmntopt(&mnt, "logging") != NULL)) {
1362 "mounting a multi-use partition which contains the AFS cache with the\n\"logging\" option may deadlock your system.\n\n";
1376 SweepAFSCache(int *vFilesFound)
1378 static char rn[] = "SweepAFSCache"; /*Routine name */
1379 int maxDir = (cacheFiles + nFilesPerDir - 1) / nFilesPerDir;
1384 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1386 printf("%s: Memory Cache, no cache sweep done\n", rn);
1390 if (cache_dir_list == NULL) {
1391 cache_dir_list = malloc(maxDir * sizeof(*cache_dir_list));
1392 if (cache_dir_list == NULL) {
1393 printf("%s: Malloc Failed!\n", rn);
1396 for (i = 0; i < maxDir; i++)
1397 cache_dir_list[i] = -1; /* Does not exist */
1400 if (cache_dir_filelist == NULL) {
1401 cache_dir_filelist = calloc(maxDir, sizeof(*cache_dir_filelist));
1402 if (cache_dir_filelist == NULL) {
1403 printf("%s: Malloc Failed!\n", rn);
1408 if (dir_for_V == NULL) {
1409 dir_for_V = malloc(cacheFiles * sizeof(*dir_for_V));
1410 if (dir_for_V == NULL) {
1411 printf("%s: Malloc Failed!\n", rn);
1414 for (i = 0; i < cacheFiles; i++)
1415 dir_for_V[i] = -1; /* Does not exist */
1418 /* Note, setting dirNum to -2 here will cause cachefiles found in
1419 * the toplevel directory to be marked in directory "-2". This
1420 * allows us to differentiate between 'file not seen' (-1) and
1421 * 'file seen in top-level' (-2). Then when we try to move the
1422 * file into a subdirectory, we know it's in the top-level instead
1423 * of some other cache subdir.
1425 return doSweepAFSCache(vFilesFound, cacheBaseDir, -2, maxDir);
1429 ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
1434 afs_int32 hosts[MAXHOSTSPERCELL];
1436 /* figure out if this is the home cell */
1437 isHomeCell = (strcmp(aci->name, LclCellName) == 0);
1439 cellFlags = 2; /* not home, suid is forbidden */
1440 if (enable_dynroot == 2)
1441 cellFlags |= 8; /* don't display foreign cells until looked up */
1443 /* build address list */
1444 for (i = 0; i < MAXHOSTSPERCELL; i++)
1445 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1447 if (aci->linkedCell)
1448 cellFlags |= 4; /* Flag that linkedCell arg exists,
1449 * for upwards compatibility */
1451 /* configure one cell */
1452 code = afsd_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */
1453 aci->name, /* cell name */
1454 cellFlags, /* is this the home cell? */
1455 aci->linkedCell); /* Linked cell, if any */
1457 printf("Adding cell '%s': error %d\n", aci->name, code);
1462 ConfigCellAlias(struct afsconf_cellalias *aca,
1463 void *arock, struct afsconf_dir *adir)
1465 /* push the alias into the kernel */
1466 afsd_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
1471 AfsdbLookupHandler(void)
1473 afs_int32 kernelMsg[64];
1474 char acellName[128];
1476 struct afsconf_cell acellInfo;
1481 acellName[0] = '\0';
1483 #ifdef MACOS_EVENT_HANDLING
1484 /* Fork the event handler also. */
1487 afsd_install_events();
1489 } else if (code != -1) {
1494 /* On some platforms you only get 4 args to an AFS call */
1495 int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
1497 afsd_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg);
1498 if (code) { /* Something is wrong? */
1503 if (*acellName == 1) /* Shutting down */
1506 code = afsconf_GetAfsdbInfo(acellName, 0, &acellInfo);
1511 kernelMsg[0] = acellInfo.numServers;
1512 if (acellInfo.timeout)
1513 kernelMsg[1] = acellInfo.timeout - time(0);
1516 for (i = 0; i < acellInfo.numServers; i++)
1517 kernelMsg[i + 2] = acellInfo.hostAddr[i].sin_addr.s_addr;
1518 strncpy(acellName, acellInfo.name, sizeof(acellName));
1519 acellName[sizeof(acellName) - 1] = '\0';
1522 #ifdef AFS_DARWIN_ENV
1523 kill(event_pid, SIGTERM);
1532 struct afs_uspc_param *uspc;
1536 uspc = calloc(1, sizeof(struct afs_uspc_param));
1537 memset(srcName, 0, sizeof(srcName));
1538 memset(dstName, 0, sizeof(dstName));
1540 /* brscount starts at 0 */
1544 /* pushing in a buffer this large */
1547 code = afsd_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName);
1548 if (code) { /* Something is wrong? */
1551 * Before AFS_USPC_SHUTDOWN existed, the kernel module used to
1552 * indicate it was shutting down by returning -2. Treat this
1553 * like a AFS_USPC_SHUTDOWN, in case we're running with an
1554 * older kernel module.
1564 switch (uspc->reqtype) {
1565 case AFS_USPC_SHUTDOWN:
1566 /* Client is shutting down */
1571 memset(srcName, 0, sizeof(srcName));
1572 memset(dstName, 0, sizeof(dstName));
1575 # ifdef AFS_DARWIN_ENV
1580 char srcpath[BUFSIZ];
1581 char dstpath[BUFSIZ];
1582 snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1583 uspc->req.umv.sCell, uspc->req.umv.sVolume,
1584 uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
1585 snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
1586 uspc->req.umv.dCell, uspc->req.umv.dVolume,
1587 uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
1588 if ((child = fork()) == 0) {
1589 /* first child does cp; second, rm. mv would re-enter. */
1591 switch (uspc->req.umv.idtype) {
1593 if (setuid(uspc->req.umv.id) != 0) {
1599 break; /* notreached */
1601 execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
1602 dstpath, (char *) NULL);
1604 if (child == (pid_t) -1) {
1609 if (waitpid(child, &status, 0) == -1)
1611 else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
1612 if ((child = fork()) == 0) {
1613 switch (uspc->req.umv.idtype) {
1615 if (setuid(uspc->req.umv.id) != 0) {
1621 break; /* notreached */
1623 execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
1624 srcpath, (char *) NULL);
1626 if (child == (pid_t) -1) {
1630 if (waitpid(child, &status, 0) == -1)
1632 else if (WIFEXITED(status) != 0) {
1633 /* rm exit status */
1634 uspc->retval = WEXITSTATUS(status);
1636 /* rm signal status */
1637 uspc->retval = -(WTERMSIG(status));
1640 /* error from cp: exit or signal status */
1641 uspc->retval = (WIFEXITED(status) != 0) ?
1642 WEXITSTATUS(status) : -(WTERMSIG(status));
1645 memset(srcName, 0, sizeof(srcName));
1646 memset(dstName, 0, sizeof(dstName));
1648 # endif /* AFS_DARWIN_ENV */
1651 /* unknown req type */
1659 #ifdef AFS_SOCKPROXY_ENV
1661 # define AFS_SOCKPROXY_RECV_IDX 0
1662 # define AFS_SOCKPROXY_INIT_IDX 1
1665 * Must be less than or equal to the limits supported by libafs:
1666 * AFS_SOCKPROXY_PKT_MAX and AFS_SOCKPROXY_PAYLOAD_MAX.
1668 # define AFS_SOCKPROXY_PKT_ALLOC 32
1669 # define AFS_SOCKPROXY_PAYLOAD_ALLOC 2832
1672 * Create socket, set send and receive buffer size, and bind a name to it.
1674 * @param[in] a_addr address to be assigned to the socket
1675 * @param[in] a_port port to be assigned to the socket
1676 * @param[out] a_sock socket
1678 * @return 0 on success; errno otherwise.
1681 SockProxyStart(afs_int32 a_addr, afs_int32 a_port, int *a_sock)
1687 struct sockaddr_in ip4;
1691 /* create an endpoint for communication */
1692 sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
1698 /* set options on socket */
1700 bsize = sizeof(blen);
1701 for (attempt_i = 0; attempt_i < 2; attempt_i++) {
1702 code = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &blen, bsize);
1703 code |= setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &blen, bsize);
1707 /* setsockopt didn't succeed. try a smaller size. */
1714 /* assign addr to the socket */
1715 ip4.sin_family = AF_INET;
1716 ip4.sin_port = a_port;
1717 ip4.sin_addr.s_addr = a_addr;
1719 code = bind(sock, (struct sockaddr *)&ip4, sizeof(ip4));
1737 * Create and initialize socket with address received from kernel-space.
1739 * @param[in] a_idx index of the process responsible for this task
1740 * @param[out] a_sock socket
1743 SockProxyStartProc(int a_idx, int *a_sock)
1745 int code, initialized;
1746 struct afs_uspc_param uspc;
1750 memset(&uspc, 0, sizeof(uspc));
1751 uspc.req.usp.idx = a_idx;
1753 while (!initialized) {
1754 uspc.reqtype = AFS_USPC_SOCKPROXY_START;
1756 code = afsd_syscall(AFSOP_SOCKPROXY_HANDLER, &uspc, NULL);
1758 /* Error; try again. */
1764 switch (uspc.reqtype) {
1765 case AFS_USPC_SHUTDOWN:
1769 case AFS_USPC_SOCKPROXY_START:
1771 SockProxyStart(uspc.req.usp.addr, uspc.req.usp.port, a_sock);
1772 if (uspc.retval == 0) {
1773 /* We've setup the socket successfully. */
1779 /* Error; try again. We must handle AFS_USPC_SOCKPROXY_START before
1780 * doing anything else. */
1785 /* Startup is done. */
1789 * Send list of packets received from kernel-space.
1791 * @param[in] a_sock socket
1792 * @param[in] a_pktlist list of packets
1793 * @param[in] a_npkts number of packets
1795 * @return number of packets successfully sent; -1 if couldn't send any packet.
1798 SockProxySend(int a_sock, struct afs_pkt_hdr *a_pktlist, int a_npkts)
1805 for (pkt_i = 0; pkt_i < a_npkts; pkt_i++) {
1806 struct afs_pkt_hdr *pkt = &a_pktlist[pkt_i];
1807 struct sockaddr_in addr;
1811 memset(&iov, 0, sizeof(iov));
1812 memset(&msg, 0, sizeof(msg));
1813 memset(&addr, 0, sizeof(addr));
1815 addr.sin_addr.s_addr = pkt->addr;
1816 addr.sin_port = pkt->port;
1818 iov.iov_base = pkt->payload;
1819 iov.iov_len = pkt->size;
1821 msg.msg_name = &addr;
1822 msg.msg_namelen = sizeof(addr);
1826 code = sendmsg(a_sock, &msg, 0);
1840 * Alloc maximum number of packets, each with the largest payload possible.
1842 * @param[out] a_pktlist allocated packets
1843 * @param[out] a_npkts number of packets allocated
1846 pkts_alloc(struct afs_pkt_hdr **a_pktlist, int *a_npkts)
1849 struct afs_pkt_hdr *pktlist;
1851 n_pkts = AFS_SOCKPROXY_PKT_ALLOC;
1852 pktlist = calloc(n_pkts, sizeof(pktlist[0]));
1853 opr_Assert(pktlist != NULL);
1855 for (pkt_i = 0; pkt_i < n_pkts; pkt_i++) {
1856 struct afs_pkt_hdr *pkt = &pktlist[pkt_i];
1857 pkt->size = AFS_SOCKPROXY_PAYLOAD_ALLOC;
1859 pkt->payload = calloc(1, pkt->size);
1860 opr_Assert(pkt->payload != NULL);
1863 *a_pktlist = pktlist;
1868 * Reset pkt->size for all packets.
1870 * @param[in] a_pktlist list of packets
1871 * @param[in] a_npkts number of packets
1874 pkts_resetsize(struct afs_pkt_hdr *a_pktlist, int a_npkts)
1878 for (pkt_i = 0; pkt_i < a_npkts; pkt_i++) {
1879 struct afs_pkt_hdr *pkt = &a_pktlist[pkt_i];
1880 pkt->size = AFS_SOCKPROXY_PAYLOAD_ALLOC;
1885 * Serve packet sending requests from kernel-space.
1887 * @param[in] a_sock socket
1888 * @param[in] a_idx index of the process responsible for this task
1889 * @param[in] a_recvpid pid of process responsible for receiving packets
1890 * (used to simplify shutdown procedures)
1893 SockProxySendProc(int a_sock, int a_idx, int a_recvpid)
1896 struct afs_pkt_hdr *pktlist;
1897 struct afs_uspc_param uspc;
1901 memset(&uspc, 0, sizeof(uspc));
1903 pkts_alloc(&pktlist, &n_pkts);
1904 uspc.reqtype = AFS_USPC_SOCKPROXY_SEND;
1905 uspc.req.usp.idx = a_idx;
1908 uspc.req.usp.npkts = n_pkts;
1909 pkts_resetsize(pktlist, n_pkts);
1911 code = afsd_syscall(AFSOP_SOCKPROXY_HANDLER, &uspc, pktlist);
1918 switch (uspc.reqtype) {
1919 case AFS_USPC_SHUTDOWN:
1920 if (a_recvpid != 0) {
1922 * We're shutting down, so kill the SockProxyReceiveProc
1923 * process. We don't wait for that process to get its own
1924 * AFS_USPC_SHUTDOWN response, since it may be stuck in
1925 * recvmsg() waiting for packets from the net.
1927 kill(a_recvpid, SIGKILL);
1932 case AFS_USPC_SOCKPROXY_SEND:
1933 uspc.retval = SockProxySend(a_sock, pktlist, uspc.req.usp.npkts);
1937 /* Some other operation? */
1946 * Receive list of packets from the socket received as an argument.
1948 * @param[in] a_sock socket
1949 * @param[out] a_pkts packets received
1950 * @param[in] a_maxpkts maximum number of packets we can receive
1952 * @return number of packets received.
1955 SockProxyRecv(int a_sock, struct afs_pkt_hdr *a_pkts, int a_maxpkts)
1962 struct sockaddr_in from;
1967 for (pkt_i = 0; pkt_i < a_maxpkts; pkt_i++) {
1968 struct afs_pkt_hdr *pkt = &a_pkts[pkt_i];
1971 pkt->size = AFS_SOCKPROXY_PAYLOAD_ALLOC;
1973 memset(&iov, 0, sizeof(iov));
1974 iov.iov_base = pkt->payload;
1975 iov.iov_len = pkt->size;
1977 memset(&from, 0, sizeof(from));
1978 memset(&msg, 0, sizeof(msg));
1979 msg.msg_name = &from;
1980 msg.msg_namelen = sizeof(from);
1984 nbytes = recvmsg(a_sock, &msg, flags);
1990 pkt->addr = from.sin_addr.s_addr;
1991 pkt->port = from.sin_port;
1994 flags = MSG_DONTWAIT;
2000 * Receive packets addressed to kernel-space and deliver those packages to it.
2002 * @param[in] a_sock socket
2003 * @param[in] a_idx index of the process responsible for this task
2006 SockProxyReceiveProc(int a_sock, int a_idx)
2009 struct afs_pkt_hdr *pktlist;
2010 struct afs_uspc_param uspc;
2014 pkts_alloc(&pktlist, &n_pkts);
2016 memset(&uspc, 0, sizeof(uspc));
2017 uspc.req.usp.idx = a_idx;
2018 uspc.req.usp.npkts = 0;
2021 uspc.reqtype = AFS_USPC_SOCKPROXY_RECV;
2023 code = afsd_syscall(AFSOP_SOCKPROXY_HANDLER, &uspc, pktlist);
2030 switch (uspc.reqtype) {
2031 case AFS_USPC_SHUTDOWN:
2035 case AFS_USPC_SOCKPROXY_RECV:
2036 uspc.req.usp.npkts = SockProxyRecv(a_sock, pktlist, n_pkts);
2041 /* Some other operation? */
2043 uspc.req.usp.npkts = 0;
2051 * Start processes responsible for sending and receiving packets for libafs.
2053 * @param[in] a_rock not used
2056 sockproxy_thread(void *a_rock)
2064 * Since the socket proxy handler runs as a user process,
2065 * need to drop the controlling TTY, etc.
2067 if (afsd_daemon(0, 0) == -1) {
2068 printf("Error starting socket proxy handler: %s\n", strerror(errno));
2073 * Before we do anything else, we must first wait for a
2074 * AFS_USPC_SOCKPROXY_START request to setup our udp socket.
2076 SockProxyStartProc(AFS_SOCKPROXY_INIT_IDX, &sock);
2078 /* Now fork our AFS_USPC_SOCKPROXY_RECV process. */
2080 opr_Assert(recvpid >= 0);
2082 SockProxyReceiveProc(sock, AFS_SOCKPROXY_RECV_IDX);
2086 /* Now fork our AFS_USPC_SOCKPROXY_SEND processes. */
2087 for (idx = 0; idx < AFS_SOCKPROXY_NPROCS; idx++) {
2090 if (idx == AFS_SOCKPROXY_RECV_IDX) {
2091 /* Receiver already forked. */
2094 if (idx == AFS_SOCKPROXY_INIT_IDX) {
2095 /* We'll start the handler for this index in this process, below. */
2100 opr_Assert(child >= 0);
2102 SockProxySendProc(sock, idx, 0);
2106 SockProxySendProc(sock, AFS_SOCKPROXY_INIT_IDX, recvpid);
2110 #endif /* AFS_SOCKPROXY_ENV */
2113 afsdb_thread(void *rock)
2115 /* Since the AFSDB lookup handler runs as a user process,
2116 * need to drop the controlling TTY, etc.
2118 if (afsd_daemon(0, 0) == -1) {
2119 printf("Error starting AFSDB lookup handler: %s\n",
2123 AfsdbLookupHandler();
2128 daemon_thread(void *rock)
2131 /* Since the background daemon runs as a user process,
2132 * need to drop the controlling TTY, etc.
2134 if (afsd_daemon(0, 0) == -1) {
2135 printf("Error starting background daemon: %s\n",
2141 afsd_syscall(AFSOP_START_BKG, 0);
2148 rmtsysd_thread(void *rock)
2153 #endif /* !UKERNEL */
2156 * Check the command line and cacheinfo options.
2158 * @param[in] as parsed command line arguments
2160 * @note Invokes the shutdown syscall and exits with 0 when
2161 * -shutdown is given.
2164 CheckOptions(struct cmd_syndesc *as)
2166 afs_int32 code; /*Result of fork() */
2170 #ifdef AFS_SGI65_ENV
2171 struct sched_param sp;
2174 #ifdef AFS_SGI_VNODE_GLUE
2175 if (afs_init_kernel_config(-1) < 0) {
2176 printf("Can't determine NUMA configuration, not starting AFS.\n");
2181 cmd_OpenConfigFile(AFSDIR_CLIENT_CONFIG_FILE_FILEPATH);
2182 cmd_SetCommandName("afsd");
2184 /* call atoi on the appropriate parsed results */
2185 if (cmd_OptionAsInt(as, OPT_blocks, &cacheBlocks) == 0)
2188 if (cmd_OptionAsInt(as, OPT_files, &cacheFiles) == 0)
2191 if (cmd_OptionAsString(as, OPT_rootvol, &rootVolume) == 0)
2194 if (cmd_OptionAsInt(as, OPT_stat, &cacheStatEntries) == 0)
2195 sawCacheStatEntries = 1;
2197 if (cmd_OptionPresent(as, OPT_memcache)) {
2198 cacheBaseDir = NULL;
2199 sawCacheBaseDir = 1;
2200 cacheFlags |= AFSCALL_INIT_MEMCACHE;
2203 if (cmd_OptionAsString(as, OPT_cachedir, &cacheBaseDir) == 0)
2204 sawCacheBaseDir = 1;
2206 if (cmd_OptionAsString(as, OPT_mountdir, &afsd_cacheMountDir) == 0)
2207 sawCacheMountDir = 1;
2209 cmd_OptionAsInt(as, OPT_daemons, &nDaemons);
2211 afsd_verbose = cmd_OptionPresent(as, OPT_verbose);
2213 if (cmd_OptionPresent(as, OPT_rmtsys)) {
2216 printf("-rmtsys not supported for UKERNEL\n");
2221 if (cmd_OptionPresent(as, OPT_debug)) {
2226 if (cmd_OptionAsInt(as, OPT_chunksize, &chunkSize) == 0) {
2227 if (chunkSize < 0 || chunkSize > 30) {
2229 ("afsd:invalid chunk size (not in range 0-30), using default\n");
2234 if (cmd_OptionAsInt(as, OPT_dcache, &dCacheSize) == 0)
2237 cmd_OptionAsInt(as, OPT_volumes, &vCacheSize);
2239 if (cmd_OptionPresent(as, OPT_biods)) {
2241 #ifndef AFS_AIX32_ENV
2243 ("afsd: [-biods] currently only enabled for aix3.x VM supported systems\n");
2245 cmd_OptionAsInt(as, OPT_biods, &nBiods);
2248 cmd_OptionAsInt(as, OPT_prealloc, &preallocs);
2250 if (cmd_OptionAsString(as, OPT_confdir, &confDir) == CMD_MISSING) {
2251 confDir = strdup(AFSDIR_CLIENT_ETC_DIRPATH);
2253 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
2255 if (cmd_OptionPresent(as, OPT_logfile)) {
2256 printf("afsd: Ignoring obsolete -logfile flag\n");
2259 afsd_CloseSynch = cmd_OptionPresent(as, OPT_waitclose);
2261 if (cmd_OptionPresent(as, OPT_shutdown)) {
2264 * Cold shutdown is the default
2266 printf("afsd: Shutting down all afs processes and afs state\n");
2267 code = afsd_syscall(AFSOP_SHUTDOWN, 1); /* always AFS_COLD */
2269 printf("afsd: AFS still mounted; Not shutting down\n");
2275 enable_peer_stats = cmd_OptionPresent(as, OPT_peerstats);
2276 enable_process_stats = cmd_OptionPresent(as, OPT_processstats);
2278 if (cmd_OptionPresent(as, OPT_memallocsleep)) {
2279 printf("afsd: -mem_alloc_sleep is deprecated -- ignored\n");
2282 enable_afsdb = cmd_OptionPresent(as, OPT_afsdb);
2283 if (cmd_OptionPresent(as, OPT_filesdir)) {
2284 /* -files_per_subdir */
2286 cmd_OptionAsInt(as, OPT_filesdir, &res);
2287 if (res < 10 || res > (1 << 30)) {
2289 ("afsd:invalid number of files per subdir, \"%s\". Ignored\n",
2290 as->parms[25].items->data);
2295 enable_dynroot = cmd_OptionPresent(as, OPT_dynroot);
2297 if (cmd_OptionPresent(as, OPT_fakestat)) {
2298 enable_fakestat = 2;
2300 if (cmd_OptionPresent(as, OPT_fakestatall)) {
2301 enable_fakestat = 1;
2303 if (cmd_OptionPresent(as, OPT_settime)) {
2305 printf("afsd: -settime ignored\n");
2306 printf("afsd: the OpenAFS client no longer sets the system time; "
2307 "please use NTP or\n");
2308 printf("afsd: another such system to synchronize client time\n");
2311 enable_nomount = cmd_OptionPresent(as, OPT_nomount);
2312 enable_backuptree = cmd_OptionPresent(as, OPT_backuptree);
2313 enable_rxbind = cmd_OptionPresent(as, OPT_rxbind);
2315 /* set rx_extraPackets */
2316 if (cmd_OptionPresent(as, OPT_rxpck)) {
2319 cmd_OptionAsInt(as, OPT_rxpck, &rxpck);
2320 printf("afsd: set rxpck = %d\n", rxpck);
2321 code = afsd_syscall(AFSOP_SET_RXPCK, rxpck);
2323 printf("afsd: failed to set rxpck\n");
2327 if (cmd_OptionPresent(as, OPT_splitcache)) {
2331 cmd_OptionAsString(as, OPT_splitcache, &var);
2333 if (var == NULL || ((c = strchr(var, '/')) == NULL))
2335 ("ignoring splitcache (specify as RW/RO percentages: 60/40)\n");
2337 ropct = atoi(c + 1);
2340 if ((rwpct != 0) && (ropct != 0) && (ropct + rwpct == 100)) {
2342 enable_splitcache = 1;
2347 if (cmd_OptionPresent(as, OPT_nodynvcache)) {
2348 #ifdef AFS_MAXVCOUNT_ENV
2349 afsd_dynamic_vcaches = 0;
2351 printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n");
2355 #ifdef AFS_MAXVCOUNT_ENV
2357 /* -dynamic-vcaches */
2358 afsd_dynamic_vcaches = 1;
2362 printf("afsd: %s dynamically allocated vcaches\n", ( afsd_dynamic_vcaches ? "enabling" : "disabling" ));
2365 cmd_OptionAsInt(as, OPT_rxmaxmtu, &rxmaxmtu);
2367 if (cmd_OptionPresent(as, OPT_dynrootsparse)) {
2371 cmd_OptionAsInt(as, OPT_rxmaxfrags, &rxmaxfrags);
2372 if (cmd_OptionPresent(as, OPT_inumcalc)) {
2373 cmd_OptionAsString(as, OPT_inumcalc, &inumcalc);
2375 cmd_OptionAsInt(as, OPT_volume_ttl, &volume_ttl);
2377 /* parse cacheinfo file if this is a diskcache */
2378 if (ParseCacheInfoFile()) {
2388 static char rn[] = "afsd"; /*Name of this routine */
2389 struct afsconf_dir *cdir; /* config dir */
2390 int lookupResult; /*Result of GetLocalCellName() */
2392 int code; /*Result of fork() */
2393 char *fsTypeMsg = NULL;
2394 int cacheIteration; /*How many times through cache verification */
2395 int vFilesFound; /*How many data cache files were found in sweep */
2396 int currVFile; /*Current AFS cache file number passed in */
2399 * Pull out all the configuration info for the workstation's AFS cache and
2400 * the cellular community we're willing to let our users see.
2402 cdir = afsconf_Open(confDir);
2404 printf("afsd: some file missing or bad in %s\n", confDir);
2409 afsconf_GetLocalCell(cdir, LclCellName, sizeof(LclCellName));
2411 printf("%s: Can't get my home cell name! [Error is %d]\n", rn,
2415 printf("%s: My home cell is '%s'\n", rn, LclCellName);
2418 if (!enable_nomount) {
2419 if (afsd_check_mount(rn, afsd_cacheMountDir)) {
2424 /* do some random computations in memcache case to get things to work
2425 * reasonably no matter which parameters you set.
2427 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
2428 /* memory cache: size described either as blocks or dcache entries, but
2432 fprintf(stderr, "%s: -files ignored with -memcache\n", rn);
2434 if (sawDCacheSize) {
2435 if (chunkSize == 0) {
2436 chunkSize = 13; /* 8k default chunksize for memcache */
2438 if (sawCacheBlocks) {
2440 ("%s: can't set cache blocks and dcache size simultaneously when diskless.\n",
2444 /* compute the cache size based on # of chunks times the chunk size */
2445 i = (1 << chunkSize); /* bytes per chunk */
2446 cacheBlocks = i * dCacheSize;
2447 sawCacheBlocks = 1; /* so that ParseCacheInfoFile doesn't overwrite */
2449 if (chunkSize == 0) {
2450 /* Try to autotune the memcache chunksize based on size
2451 * of memcache. This is done on the assumption that approx
2452 * 1024 chunks is suitable, it's a balance between enough
2453 * chunks to be useful and ramping up nicely when using larger
2454 * memcache to improve bulk read/write performance
2457 i <= 21 && (1 << i) / 1024 < (cacheBlocks / 1024); i++);
2460 /* compute the dcache size from overall cache size and chunk size */
2461 if (chunkSize > 10) {
2462 dCacheSize = (cacheBlocks >> (chunkSize - 10));
2463 } else if (chunkSize < 10) {
2464 dCacheSize = (cacheBlocks << (10 - chunkSize));
2466 dCacheSize = cacheBlocks;
2468 /* don't have to set sawDCacheSize here since it isn't overwritten
2469 * by ParseCacheInfoFile.
2473 printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
2475 /* kernel computes # of dcache entries as min of cacheFiles and
2476 * dCacheSize, so we now make them equal.
2478 cacheFiles = dCacheSize;
2481 * Compute the number of cache files based on cache size,
2482 * but only if -files isn't given on the command line.
2483 * Don't let # files be so small as to prevent full utilization
2484 * of the cache unless user has explicitly asked for it.
2486 if (chunkSize == 0) {
2487 /* Set chunksize to 256kB - 1MB depending on cache size */
2488 if (cacheBlocks < 500000) {
2490 } else if (cacheBlocks < 1000000) {
2498 cacheFiles = cacheBlocks / 32; /* Assume 32k avg filesize */
2500 cacheFiles = max(cacheFiles, 1000);
2502 /* Always allow more files than chunks. Presume average V-file
2503 * is ~67% of a chunk... (another guess, perhaps Honeyman will
2504 * have a grad student write a paper). i is KILOBYTES.
2506 i = 1 << (chunkSize < 10 ? 0 : chunkSize - 10);
2507 cacheFiles = max(cacheFiles, 1.5 * (cacheBlocks / i));
2509 /* never permit more files than blocks, while leaving space for
2510 * VolumeInfo and CacheItems files. VolumeInfo is usually 20K,
2511 * CacheItems is 50 Bytes / file (== 1K/20)
2513 #define CACHEITMSZ (cacheFiles / 20)
2514 #define VOLINFOSZ 50 /* 40kB has been seen, be conservative */
2515 #define CELLINFOSZ 4 /* Assuming disk block size is 4k ... */
2516 #define INFOSZ (VOLINFOSZ+CELLINFOSZ+CACHEITMSZ)
2518 /* Sanity check: If the obtained number of disk cache files
2519 * is larger than the number of available (4k) disk blocks, we're
2520 * doing something wrong. Fail hard so we can fix the bug instead
2521 * of silently hiding it like before */
2523 if (cacheFiles > (cacheBlocks - INFOSZ) / 4) {
2525 "%s: ASSERT: cacheFiles %d diskblocks %d\n",
2526 rn, cacheFiles, (cacheBlocks - INFOSZ) / 4);
2529 if (cacheFiles < 100)
2530 fprintf(stderr, "%s: WARNING: cache probably too small!\n",
2534 printf("%s: cacheFiles autotuned to %d\n", rn, cacheFiles);
2536 if (!sawDCacheSize) {
2537 dCacheSize = cacheFiles / 2;
2538 if (dCacheSize > 10000) {
2541 if (dCacheSize < 2000) {
2545 printf("%s: dCacheSize autotuned to %d\n", rn, dCacheSize);
2548 if (!sawCacheStatEntries) {
2549 if (chunkSize <= 13) {
2550 cacheStatEntries = dCacheSize / 4;
2551 } else if (chunkSize >= 16) {
2552 cacheStatEntries = dCacheSize * 1.5;
2554 cacheStatEntries = dCacheSize;
2557 printf("%s: cacheStatEntries autotuned to %d\n", rn,
2561 #if !defined(AFS_CACHE_VNODE_PATH) && !defined(AFS_LINUX_ENV)
2563 * Create and zero the inode table for the desired cache files.
2565 inode_for_V = calloc(cacheFiles, sizeof(AFSD_INO_T));
2566 if (inode_for_V == (AFSD_INO_T *) 0) {
2568 ("%s: malloc() failed for cache file inode table with %d entries.\n",
2573 printf("%s: %d inode_for_V entries at %p, %lu bytes\n", rn,
2574 cacheFiles, inode_for_V,
2575 (unsigned long)cacheFiles * sizeof(AFSD_INO_T));
2578 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2580 * Set up all the pathnames we'll need for later.
2582 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
2583 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
2584 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
2585 sprintf(fullpn_VFile, "%s/", cacheBaseDir);
2586 vFilePtr = fullpn_VFile + strlen(fullpn_VFile);
2588 fsTypeMsg = CheckCacheBaseDir(cacheBaseDir);
2591 printf("%s: WARNING: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2593 printf("%s: ERROR: Cache dir check failed (%s)\n", rn, fsTypeMsg);
2600 * Set up all the kernel processes needed for AFS.
2603 setpgrp(getpid(), 0);
2607 * Set the primary cell name.
2609 afsd_syscall(AFSOP_SET_THISCELL, LclCellName);
2611 /* Initialize RX daemons and services */
2613 /* initialize the rx random number generator from user space */
2615 /* rand-fortuna wants at least 128 bytes of seed; be generous. */
2616 unsigned char seedbuf[256];
2617 if (RAND_bytes(seedbuf, sizeof(seedbuf)) != 1) {
2618 printf("SEED_ENTROPY: Error retrieving seed entropy\n");
2620 afsd_syscall(AFSOP_SEED_ENTROPY, seedbuf, sizeof(seedbuf));
2621 memset(seedbuf, 0, sizeof(seedbuf));
2622 /* parse multihomed address files */
2623 afs_uint32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
2626 code = afsconf_ParseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
2627 AFSDIR_CLIENT_NETINFO_FILEPATH,
2628 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
2631 code = code | 0x80000000;
2632 afsd_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
2634 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
2638 /* Set realtime priority for most threads to same as for biod's. */
2639 afsd_set_afsd_rtpri();
2641 /* Start listener, then callback listener. Lastly, start rx event daemon.
2642 * Change in ordering is so that Linux port has socket fd in listener
2644 * preallocs are passed for both listener and callback server. Only
2645 * the one which actually does the initialization uses them though.
2647 if (preallocs < cacheStatEntries + 50)
2648 preallocs = cacheStatEntries + 50;
2649 #ifdef RXK_LISTENER_ENV
2651 printf("%s: Forking rx listener daemon.\n", rn);
2652 # ifdef AFS_SUN510_ENV
2653 fork_rx_syscall_wait(rn, AFSOP_RXLISTENER_DAEMON, preallocs,
2654 enable_peer_stats, enable_process_stats);
2655 # else /* !AFS_SUN510_ENV */
2656 fork_rx_syscall(rn, AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats,
2657 enable_process_stats);
2658 # endif /* !AFS_SUN510_ENV */
2661 printf("%s: Forking rx callback listener.\n", rn);
2662 #ifndef RXK_LISTENER_ENV
2663 fork_rx_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, enable_peer_stats,
2664 enable_process_stats);
2666 fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs, 0, 0);
2668 #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) || defined(RXK_UPCALL_ENV)
2670 printf("%s: Forking rxevent daemon.\n", rn);
2671 fork_rx_syscall(rn, AFSOP_RXEVENT_DAEMON);
2674 #ifdef AFS_SOCKPROXY_ENV
2676 printf("%s: Forking socket proxy handlers.\n", rn);
2677 afsd_fork(0, sockproxy_thread, NULL);
2682 printf("%s: Forking AFSDB lookup handler.\n", rn);
2683 afsd_fork(0, afsdb_thread, NULL);
2685 code = afsd_syscall(AFSOP_BASIC_INIT, 1);
2687 printf("%s: Error %d in basic initialization.\n", rn, code);
2692 * Tell the kernel some basic information about the workstation's cache.
2696 ("%s: Calling AFSOP_CACHEINIT: %d stat cache entries, %d optimum cache files, %d blocks in the cache, flags = 0x%x, dcache entries %d\n",
2697 rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
2699 memset(&cparams, '\0', sizeof(cparams));
2700 cparams.cacheScaches = cacheStatEntries;
2701 cparams.cacheFiles = cacheFiles;
2702 cparams.cacheBlocks = cacheBlocks;
2703 cparams.cacheDcaches = dCacheSize;
2704 cparams.cacheVolumes = vCacheSize;
2705 cparams.chunkSize = chunkSize;
2706 cparams.setTimeFlag = 0;
2707 cparams.memCacheFlag = cacheFlags;
2708 cparams.dynamic_vcaches = afsd_dynamic_vcaches;
2709 code = afsd_syscall(AFSOP_CACHEINIT, &cparams);
2711 printf("%s: Error %d during cache init.\n", rn, code);
2715 /* do it before we init the cache inodes */
2716 if (enable_splitcache) {
2717 afsd_syscall(AFSOP_BUCKETPCT, 1, rwpct);
2718 afsd_syscall(AFSOP_BUCKETPCT, 2, ropct);
2721 if (afsd_CloseSynch)
2722 afsd_syscall(AFSOP_CLOSEWAIT);
2725 * Sweep the workstation AFS cache directory, remembering the inodes of
2726 * valid files and deleting extraneous files. Keep sweeping until we
2727 * have the right number of data cache files or we've swept too many
2730 * This also creates files in the cache directory like VolumeItems and
2731 * CellItems, and thus must be ran before those are sent to the kernel.
2734 printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
2736 /* Memory-cache based system doesn't need any of this */
2737 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2740 if (SweepAFSCache(&vFilesFound)) {
2741 printf("%s: Error on sweep %d of workstation AFS cache \
2742 directory.\n", rn, cacheIteration);
2747 ("%s: %d out of %d data cache files found in sweep %d.\n",
2748 rn, vFilesFound, cacheFiles, cacheIteration);
2749 } while ((vFilesFound < cacheFiles)
2750 && (cacheIteration < MAX_CACHE_LOOPS));
2751 } else if (afsd_verbose)
2752 printf("%s: Using memory cache, not swept\n", rn);
2755 * Pass the kernel the name of the workstation cache file holding the
2759 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
2761 /* once again, meaningless for a memory-based cache. */
2762 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2763 afsd_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile);
2766 * Pass the kernel the name of the workstation cache file holding the
2769 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2771 printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn,
2772 fullpn_CellInfoFile);
2773 afsd_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile);
2778 printf("%s: Setting rxmaxfrags in kernel = %d\n", rn, rxmaxfrags);
2779 code = afsd_syscall(AFSOP_SET_RXMAXFRAGS, rxmaxfrags);
2781 printf("%s: Error seting rxmaxfrags\n", rn);
2786 printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu);
2787 code = afsd_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu);
2789 printf("%s: Error seting rxmaxmtu\n", rn);
2792 if (inumcalc != NULL) {
2793 if (strcmp(inumcalc, "compat") == 0) {
2795 printf("%s: Setting original inode number calculation method in kernel.\n",
2798 code = afsd_syscall(AFSOP_SET_INUMCALC, AFS_INUMCALC_COMPAT);
2800 printf("%s: Error setting inode calculation method: code=%d.\n",
2803 } else if (strcmp(inumcalc, "md5") == 0) {
2805 printf("%s: Setting md5 digest inode number calculation in kernel.\n",
2808 code = afsd_syscall(AFSOP_SET_INUMCALC, AFS_INUMCALC_MD5);
2810 printf("%s: Error setting inode calculation method: code=%d.\n",
2814 printf("%s: Unknown value for -inumcalc: %s."
2815 "Using default inode calculation method.\n", rn, inumcalc);
2819 if (enable_dynroot) {
2821 printf("%s: Enabling dynroot support in kernel%s.\n", rn,
2822 (enable_dynroot==2)?", not showing cells.":"");
2823 code = afsd_syscall(AFSOP_SET_DYNROOT, 1);
2825 printf("%s: Error enabling dynroot support.\n", rn);
2828 if (enable_fakestat) {
2830 printf("%s: Enabling fakestat support in kernel%s.\n", rn,
2831 (enable_fakestat==1)?" for all mountpoints."
2832 :" for crosscell mountpoints");
2833 code = afsd_syscall(AFSOP_SET_FAKESTAT, enable_fakestat);
2835 printf("%s: Error enabling fakestat support.\n", rn);
2838 if (enable_backuptree) {
2840 printf("%s: Enabling backup tree support in kernel.\n", rn);
2841 code = afsd_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree);
2843 printf("%s: Error enabling backup tree support.\n", rn);
2847 * Tell the kernel about each cell in the configuration.
2849 afsconf_CellApply(cdir, ConfigCell, NULL);
2850 afsconf_CellAliasApply(cdir, ConfigCellAlias, NULL);
2852 /* Initialize AFS daemon threads. */
2854 printf("%s: Forking AFS daemon.\n", rn);
2855 fork_syscall(rn, AFSOP_START_AFS);
2858 printf("%s: Forking Check Server Daemon.\n", rn);
2859 fork_syscall(rn, AFSOP_START_CS);
2862 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
2863 #if defined(AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
2864 /* Add one because for sgi we always "steal" the first daemon for a
2865 * different task if we only have a 4K stack.
2869 for (i = 0; i < nDaemons; i++) {
2870 afsd_fork(0, daemon_thread, NULL);
2872 #ifdef AFS_AIX32_ENV
2874 nBiods = nDaemons * 2;
2877 for (i = 0; i < nBiods; i++) {
2878 fork_syscall(rn, AFSOP_START_BKG, nBiods);
2883 * If the root volume has been explicitly set, tell the kernel.
2887 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn,
2889 afsd_syscall(AFSOP_ROOTVOLUME, rootVolume);
2892 if (volume_ttl != 0) {
2894 printf("%s: Calling AFSOP_SET_VOLUME_TTL with '%d'\n", rn, volume_ttl);
2895 code = afsd_syscall(AFSOP_SET_VOLUME_TTL, volume_ttl);
2896 if (code == EFAULT) {
2897 if (volume_ttl < AFS_MIN_VOLUME_TTL)
2898 printf("%s: Failed to set volume ttl to %d seconds; "
2899 "value is too low.\n", rn, volume_ttl);
2900 else if (volume_ttl > AFS_MAX_VOLUME_TTL)
2901 printf("%s: Failed to set volume ttl to %d seconds; "
2902 "value is too high.\n", rn, volume_ttl);
2904 printf("%s: Failed to set volume ttl to %d seconds; "
2905 "value is out of range.\n", rn, volume_ttl);
2906 } else if (code != 0) {
2907 printf("%s: Failed to set volume ttl to %d seconds; "
2908 "code=%d.\n", rn, volume_ttl, code);
2913 * Pass the kernel the name of the workstation cache file holding the
2914 * volume information.
2917 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
2918 fullpn_VolInfoFile);
2919 /* once again, meaningless for a memory-based cache. */
2920 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
2921 afsd_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
2924 * Give the kernel the names of the AFS files cached on the workstation's
2927 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
2928 int nocachefile = 0;
2931 ("%s: Calling AFSOP_CACHEFILE for each of the %d files in '%s'\n",
2932 rn, cacheFiles, cacheBaseDir);
2933 /* ... and again ... */
2934 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
2936 sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
2937 code = afsd_syscall(AFSOP_CACHEFILE, fullpn_VFile);
2939 if (currVFile == 0) {
2942 ("%s: Calling AFSOP_CACHEINODE for each of the %d files in '%s'\n",
2943 rn, cacheFiles, cacheBaseDir);
2947 ("%s: Error calling AFSOP_CACHEFILE for '%s'\n",
2954 /* fall through to setup-by-inode */
2956 #if defined(AFS_SGI62_ENV) || !(defined(AFS_LINUX_ENV) || defined(AFS_CACHE_VNODE_PATH))
2957 afsd_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
2960 ("%s: Error calling AFSOP_CACHEINODE: not configured\n",
2968 * All the necessary info has been passed into the kernel to run an AFS
2969 * system. Give the kernel our go-ahead.
2972 printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn,
2974 afsd_syscall(AFSOP_GO, 0);
2977 * At this point, we have finished passing the kernel all the info
2978 * it needs to set up the AFS. Mount the AFS root.
2980 printf("%s: All AFS daemons started.\n", rn);
2983 printf("%s: Forking trunc-cache daemon.\n", rn);
2984 fork_syscall(rn, AFSOP_START_TRUNCDAEMON);
2986 if (!enable_nomount) {
2987 afsd_mount_afs(rn, afsd_cacheMountDir);
2993 printf("%s: Forking 'rmtsys' daemon.\n", rn);
2994 afsd_fork(0, rmtsysd_thread, NULL);
2995 code = afsd_syscall(AFSOP_SET_RMTSYS_FLAG, 1);
2997 printf("%s: Error enabling rmtsys support.\n", rn);
2999 #endif /* !UKERNEL */
3001 * Exit successfully.
3007 #include "AFS_component_version_number.c"
3013 struct cmd_syndesc *ts;
3015 ts = cmd_CreateSyntax(NULL, NULL, NULL, 0, "start AFS");
3018 cmd_AddParmAtOffset(ts, OPT_blocks, "-blocks", CMD_SINGLE,
3019 CMD_OPTIONAL, "1024 byte blocks in cache");
3020 cmd_AddParmAtOffset(ts, OPT_files, "-files", CMD_SINGLE,
3021 CMD_OPTIONAL, "files in cache");
3022 cmd_AddParmAtOffset(ts, OPT_rootvol, "-rootvol", CMD_SINGLE,
3023 CMD_OPTIONAL, "name of AFS root volume");
3024 cmd_AddParmAtOffset(ts, OPT_stat, "-stat", CMD_SINGLE,
3025 CMD_OPTIONAL, "number of stat entries");
3026 cmd_AddParmAtOffset(ts, OPT_memcache, "-memcache", CMD_FLAG,
3027 CMD_OPTIONAL, "run diskless");
3028 cmd_AddParmAtOffset(ts, OPT_cachedir, "-cachedir", CMD_SINGLE,
3029 CMD_OPTIONAL, "cache directory");
3030 cmd_AddParmAtOffset(ts, OPT_mountdir, "-mountdir", CMD_SINGLE,
3031 CMD_OPTIONAL, "mount location");
3032 cmd_AddParmAtOffset(ts, OPT_daemons, "-daemons", CMD_SINGLE,
3033 CMD_OPTIONAL, "number of daemons to use");
3034 cmd_AddParmAtOffset(ts, OPT_nosettime, "-nosettime", CMD_FLAG,
3035 CMD_OPTIONAL, "don't set the time");
3036 cmd_AddParmAtOffset(ts, OPT_verbose, "-verbose", CMD_FLAG,
3037 CMD_OPTIONAL, "display lots of information");
3038 cmd_AddParmAtOffset(ts, OPT_rmtsys, "-rmtsys", CMD_FLAG,
3039 CMD_OPTIONAL, "start NFS rmtsysd program");
3040 cmd_AddParmAtOffset(ts, OPT_debug, "-debug", CMD_FLAG,
3041 CMD_OPTIONAL, "display debug info");
3042 cmd_AddParmAtOffset(ts, OPT_chunksize, "-chunksize", CMD_SINGLE,
3043 CMD_OPTIONAL, "log(2) of chunk size");
3044 cmd_AddParmAtOffset(ts, OPT_dcache, "-dcache", CMD_SINGLE,
3045 CMD_OPTIONAL, "number of dcache entries");
3046 cmd_AddParmAtOffset(ts, OPT_volumes, "-volumes", CMD_SINGLE,
3047 CMD_OPTIONAL, "number of volume entries");
3048 cmd_AddParmAtOffset(ts, OPT_biods, "-biods", CMD_SINGLE,
3049 CMD_OPTIONAL, "number of bkg I/O daemons (aix vm)");
3050 cmd_AddParmAtOffset(ts, OPT_prealloc, "-prealloc", CMD_SINGLE,
3051 CMD_OPTIONAL, "number of 'small' preallocated blocks");
3052 cmd_AddParmAtOffset(ts, OPT_confdir, "-confdir", CMD_SINGLE,
3053 CMD_OPTIONAL, "configuration directory");
3054 cmd_AddParmAtOffset(ts, OPT_logfile, "-logfile", CMD_SINGLE,
3055 CMD_OPTIONAL, "Place to keep the CM log");
3056 cmd_AddParmAtOffset(ts, OPT_waitclose, "-waitclose", CMD_FLAG,
3057 CMD_OPTIONAL, "make close calls synchronous");
3058 cmd_AddParmAtOffset(ts, OPT_shutdown, "-shutdown", CMD_FLAG,
3059 CMD_OPTIONAL, "Shutdown all afs state");
3060 cmd_AddParmAtOffset(ts, OPT_peerstats, "-enable_peer_stats", CMD_FLAG,
3061 CMD_OPTIONAL, "Collect rpc statistics by peer");
3062 cmd_AddParmAtOffset(ts, OPT_processstats, "-enable_process_stats",
3063 CMD_FLAG, CMD_OPTIONAL, "Collect rpc statistics for this process");
3064 cmd_AddParmAtOffset(ts, OPT_memallocsleep, "-mem_alloc_sleep",
3065 CMD_FLAG, CMD_OPTIONAL | CMD_HIDE,
3066 "Allow sleeps when allocating memory cache");
3067 cmd_AddParmAtOffset(ts, OPT_afsdb, "-afsdb", CMD_FLAG,
3068 CMD_OPTIONAL, "Enable AFSDB support");
3069 cmd_AddParmAtOffset(ts, OPT_filesdir, "-files_per_subdir", CMD_SINGLE,
3071 "log(2) of the number of cache files per "
3072 "cache subdirectory");
3073 cmd_AddParmAtOffset(ts, OPT_dynroot, "-dynroot", CMD_FLAG,
3074 CMD_OPTIONAL, "Enable dynroot support");
3075 cmd_AddParmAtOffset(ts, OPT_fakestat, "-fakestat", CMD_FLAG,
3077 "Enable fakestat support for cross-cell mounts");
3078 cmd_AddParmAtOffset(ts, OPT_fakestatall, "-fakestat-all", CMD_FLAG,
3080 "Enable fakestat support for all mounts");
3081 cmd_AddParmAtOffset(ts, OPT_nomount, "-nomount", CMD_FLAG,
3082 CMD_OPTIONAL, "Do not mount AFS");
3083 cmd_AddParmAtOffset(ts, OPT_backuptree, "-backuptree", CMD_FLAG,
3085 "Prefer backup volumes for mountpoints in backup "
3087 cmd_AddParmAtOffset(ts, OPT_rxbind, "-rxbind", CMD_FLAG,
3089 "Bind the Rx socket (one interface only)");
3090 cmd_AddParmAtOffset(ts, OPT_settime, "-settime", CMD_FLAG,
3091 CMD_OPTIONAL, "set the time");
3092 cmd_AddParmAtOffset(ts, OPT_rxpck, "-rxpck", CMD_SINGLE, CMD_OPTIONAL,
3093 "set rx_extraPackets to this value");
3094 cmd_AddParmAtOffset(ts, OPT_splitcache, "-splitcache", CMD_SINGLE,
3096 "Percentage RW versus RO in cache (specify as 60/40)");
3097 cmd_AddParmAtOffset(ts, OPT_nodynvcache, "-disable-dynamic-vcaches",
3098 CMD_FLAG, CMD_OPTIONAL,
3099 "disable stat/vcache cache growing as needed");
3100 cmd_AddParmAtOffset(ts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE,
3101 CMD_OPTIONAL, "set rx max MTU to use");
3102 cmd_AddParmAtOffset(ts, OPT_dynrootsparse, "-dynroot-sparse", CMD_FLAG,
3104 "Enable dynroot support with minimal cell list");
3105 cmd_AddParmAtOffset(ts, OPT_rxmaxfrags, "-rxmaxfrags", CMD_SINGLE,
3107 "Set the maximum number of UDP fragments Rx should "
3108 "send/receive per Rx packet");
3109 cmd_AddParmAtOffset(ts, OPT_inumcalc, "-inumcalc", CMD_SINGLE, CMD_OPTIONAL,
3110 "Set inode number calculation method");
3111 cmd_AddParmAtOffset(ts, OPT_volume_ttl, "-volume-ttl", CMD_SINGLE,
3113 "Set the vldb cache timeout value in seconds.");
3117 * Parse and check the command line options.
3119 * @note The -shutdown command is handled in CheckOptions().
3122 afsd_parse(int argc, char **argv)
3124 struct cmd_syndesc *ts = NULL;
3127 code = cmd_Parse(argc, argv, &ts);
3131 code = CheckOptions(ts);
3132 cmd_FreeOptions(&ts);
3137 * entry point for calling a syscall from another proc/thread.
3139 * @param[in] rock a struct afsd_syscall_args* specifying what syscall to call
3142 * @retval NULL always
3145 call_syscall_thread(void *rock)
3147 struct afsd_syscall_args *args = rock;
3151 afsd_set_rx_rtpri();
3154 code = afsd_call_syscall(args);
3155 if (code && args->syscall == AFSOP_START_CS) {
3156 printf("%s: No check server daemon in client.\n", args->rn);
3165 afsd_syscall_populate(struct afsd_syscall_args *args, int syscall, va_list ap)
3167 afsd_syscall_param_t *params;
3169 memset(args, 0, sizeof(struct afsd_syscall_args));
3171 args->syscall = syscall;
3172 params = args->params;
3175 case AFSOP_RXEVENT_DAEMON:
3176 case AFSOP_CLOSEWAIT:
3177 case AFSOP_START_AFS:
3178 case AFSOP_START_CS:
3179 case AFSOP_START_TRUNCDAEMON:
3181 case AFSOP_START_BKG:
3182 case AFSOP_SHUTDOWN:
3183 case AFSOP_SET_RXPCK:
3184 case AFSOP_BASIC_INIT:
3185 case AFSOP_SET_RXMAXFRAGS:
3186 case AFSOP_SET_RXMAXMTU:
3187 case AFSOP_SET_DYNROOT:
3188 case AFSOP_SET_FAKESTAT:
3189 case AFSOP_SET_BACKUPTREE:
3190 case AFSOP_BUCKETPCT:
3192 case AFSOP_SET_RMTSYS_FLAG:
3193 case AFSOP_SET_INUMCALC:
3194 case AFSOP_SET_VOLUME_TTL:
3195 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
3197 case AFSOP_SET_THISCELL:
3198 case AFSOP_ROOTVOLUME:
3199 case AFSOP_VOLUMEINFO:
3200 case AFSOP_CACHEFILE:
3201 case AFSOP_CACHEINFO:
3202 case AFSOP_CACHEINIT:
3203 case AFSOP_CELLINFO:
3204 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3206 case AFSOP_ADDCELLALIAS:
3207 #ifdef AFS_SOCKPROXY_ENV
3208 case AFSOP_SOCKPROXY_HANDLER:
3210 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3211 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3213 case AFSOP_AFSDB_HANDLER:
3214 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3215 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3216 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
3218 case AFSOP_BKG_HANDLER:
3219 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3220 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3221 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3223 case AFSOP_RXLISTENER_DAEMON:
3224 case AFSOP_START_RXCALLBACK:
3225 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
3226 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
3227 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
3229 case AFSOP_ADVISEADDR:
3230 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int)));
3231 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3232 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3233 params[3] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3235 case AFSOP_ADDCELL2:
3236 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3237 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3238 params[2] = CAST_SYSCALL_PARAM((va_arg(ap, afs_int32)));
3239 params[3] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3241 case AFSOP_CACHEINODE:
3242 #if defined AFS_SGI62_ENV
3244 afs_int64 tmp = va_arg(ap, afs_int64);
3245 params[0] = CAST_SYSCALL_PARAM((afs_uint32)(tmp >> 32));
3246 params[1] = CAST_SYSCALL_PARAM((afs_uint32)(tmp & 0xffffffff));
3249 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, afs_uint32)));
3252 case AFSOP_SEED_ENTROPY:
3253 params[0] = CAST_SYSCALL_PARAM((va_arg(ap, void *)));
3254 params[1] = CAST_SYSCALL_PARAM((va_arg(ap, afs_uint32)));
3257 printf("Unknown syscall enountered: %d\n", syscall);
3263 * common code for calling a syscall in another proc/thread.
3265 * @param[in] rx 1 if this is a thread for RX stuff, 0 otherwise
3266 * @param[in] wait 1 if we should wait for the new proc/thread to finish, 0 to
3267 * let it run in the background
3268 * @param[in] rn the name of the running program
3269 * @param[in] syscall syscall to run
3272 fork_syscall_impl(int rx, int wait, const char *rn, int syscall, va_list ap)
3274 struct afsd_syscall_args *args;
3276 args = malloc(sizeof(*args));
3277 afsd_syscall_populate(args, syscall, ap);
3281 afsd_fork(wait, call_syscall_thread, args);
3285 * call a syscall in another process or thread.
3288 fork_syscall(const char *rn, int syscall, ...)
3292 va_start(ap, syscall);
3293 fork_syscall_impl(0, 0, rn, syscall, ap);
3298 * call a syscall in another process or thread, and give it RX priority.
3301 fork_rx_syscall(const char *rn, int syscall, ...)
3305 va_start(ap, syscall);
3306 fork_syscall_impl(1, 0, rn, syscall, ap);
3310 #if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV)
3312 * call a syscall in another process or thread, give it RX priority, and wait
3313 * for it to finish before returning.
3316 fork_rx_syscall_wait(const char *rn, int syscall, ...)
3320 va_start(ap, syscall);
3321 fork_syscall_impl(1, 1, rn, syscall, ap);
3324 #endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */
3327 afsd_syscall(int syscall, ...)
3330 struct afsd_syscall_args args;
3332 va_start(ap, syscall);
3333 afsd_syscall_populate(&args, syscall, ap);
3336 return afsd_call_syscall(&args);