#include <netinet/in.h>
#include <afs/afs_args.h>
#include <afs/cellconfig.h>
-#include <afs/auth.h>
#include <ctype.h>
#include <afs/afssyscalls.h>
#include <afs/afsutil.h>
kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int,
char *);
#define DISK_ARB_NETWORK_DISK_FLAG 8
+
+#include <mach/mach_port.h>
+#include <mach/mach_interface.h>
+#include <mach/mach_init.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <SystemConfiguration/SCDynamicStore.h>
+
+#include <IOKit/pwr_mgt/IOPMLib.h>
+#include <IOKit/IOMessage.h>
+
+#include <dns_sd.h>
+
+typedef struct DNSSDState
+{
+ DNSServiceRef service;
+ CFRunLoopSourceRef source;
+ CFSocketRef socket;
+} DNSSDState;
+
+static io_connect_t root_port;
+static IONotificationPortRef notify;
+static io_object_t iterator;
+static CFRunLoopSourceRef source;
+static DNSSDState dnsstate;
+
+static int event_pid;
+
#endif /* AFS_DARWIN_ENV */
#ifndef MOUNT_AFS
int ownerRWmode = 0600; /*Read/write OK by owner */
static int filesSet = 0; /*True if number of files explicitly set */
static int nFilesPerDir = 2048; /* # files per cache dir */
-static int nDaemons = 2; /* Number of background daemons */
+#if defined(AFS_CACHE_BYPASS)
+#define AFSD_NDAEMONS 4
+#else
+#define AFSD_NDAEMONS 2
+#endif
+static int nDaemons = AFSD_NDAEMONS; /* Number of background daemons */
static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
static int dCacheSize; /* # of dcache entries */
static int vCacheSize = 200; /* # of volume cache entries */
* -2: file exists in top-level
* >=0: file exists in Dxxx
*/
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
AFSD_INO_T *inode_for_V; /* Array of inodes for desired
* cache files */
+#endif
int missing_DCacheFile = 1; /*Is the DCACHEFILE missing? */
int missing_VolInfoFile = 1; /*Is the VOLINFOFILE missing? */
int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing? */
static int HandleMTab();
+#ifdef AFS_DARWIN_ENV
+static void
+afsd_sleep_callback(void * refCon, io_service_t service,
+ natural_t messageType, void * messageArgument )
+{
+ afs_int32 code;
+
+ switch (messageType) {
+ case kIOMessageCanSystemSleep:
+ /* Idle sleep is about to kick in; can
+ prevent sleep by calling IOCancelPowerChange, otherwise
+ if we don't ack in 30s the system sleeps anyway */
+
+ /* allow it */
+ IOAllowPowerChange(root_port, (long)messageArgument);
+ break;
+
+ case kIOMessageSystemWillSleep:
+ /* The system WILL go to sleep. Ack or suffer delay */
+
+ IOAllowPowerChange(root_port, (long)messageArgument);
+ break;
+
+ case kIOMessageSystemWillRestart:
+ /* The system WILL restart. Ack or suffer delay */
+
+ IOAllowPowerChange(root_port, (long)messageArgument);
+ break;
+
+ case kIOMessageSystemWillPowerOn:
+ case kIOMessageSystemHasPoweredOn:
+ /* coming back from sleep */
+
+ IOAllowPowerChange(root_port, (long)messageArgument);
+ break;
+
+ default:
+ IOAllowPowerChange(root_port, (long)messageArgument);
+ break;
+ }
+}
+
+static void
+afsd_update_addresses(CFRunLoopTimerRef timer, void *info)
+{
+ /* parse multihomed address files */
+ afs_int32 addrbuf[MAXIPADDRS], maskbuf[MAXIPADDRS],
+ mtubuf[MAXIPADDRS];
+ char reason[1024];
+ afs_int32 code;
+
+ code =
+ parseNetFiles(addrbuf, maskbuf, mtubuf, MAXIPADDRS, reason,
+ AFSDIR_CLIENT_NETINFO_FILEPATH,
+ AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
+
+ if (code > 0) {
+ /* Note we're refreshing */
+ code = code | 0x40000000;
+ call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf);
+ } else
+ printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
+ reason);
+}
+
+/* This function is called when the system's ip addresses may have changed. */
+static void
+afsd_ipaddr_callback (SCDynamicStoreRef store, CFArrayRef changed_keys, void *info)
+{
+ CFRunLoopTimerRef timer;
+
+ timer = CFRunLoopTimerCreate (NULL, CFAbsoluteTimeGetCurrent () + 1.0,
+ 0.0, 0, 0, afsd_update_addresses, NULL);
+ CFRunLoopAddTimer (CFRunLoopGetCurrent (), timer,
+ kCFRunLoopDefaultMode);
+ CFRelease (timer);
+}
+
+static void
+afsd_event_cleanup(int signo) {
+ DNSSDState *query = &dnsstate;
+
+ CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
+ CFRelease (source);
+ IODeregisterForSystemPower(&iterator);
+ IOServiceClose(root_port);
+ IONotificationPortDestroy(notify);
+
+ exit(0);
+}
+
+/* Adapted from "Living in a Dynamic TCP/IP Environment" technote. */
+static Boolean
+afsd_install_events(void)
+{
+ SCDynamicStoreContext ctx = {0};
+ SCDynamicStoreRef store;
+
+ root_port = IORegisterForSystemPower(0,¬ify,afsd_sleep_callback,&iterator);
+
+ if (root_port) {
+ CFRunLoopAddSource(CFRunLoopGetCurrent(),
+ IONotificationPortGetRunLoopSource(notify),
+ kCFRunLoopDefaultMode);
+ }
+
+
+ store = SCDynamicStoreCreate (NULL,
+ CFSTR ("AddIPAddressListChangeCallbackSCF"),
+ afsd_ipaddr_callback, &ctx);
+
+ if (store) {
+ const void *keys[1];
+
+ /* Request IPV4 address change notification */
+ keys[0] = (SCDynamicStoreKeyCreateNetworkServiceEntity
+ (NULL, kSCDynamicStoreDomainState,
+ kSCCompAnyRegex, kSCEntNetIPv4));
+
+#if 0
+ /* This should tell us when the hostname(s) change. do we care? */
+ keys[N] = SCDynamicStoreKeyCreateHostNames (NULL);
+#endif
+
+ if (keys[0] != NULL) {
+ CFArrayRef pattern_array;
+
+ pattern_array = CFArrayCreate (NULL, keys, 1,
+ &kCFTypeArrayCallBacks);
+
+ if (pattern_array != NULL)
+ {
+ SCDynamicStoreSetNotificationKeys (store, NULL, pattern_array);
+ source = SCDynamicStoreCreateRunLoopSource (NULL, store, 0);
+
+ CFRelease (pattern_array);
+ }
+
+ if (keys[0] != NULL)
+ CFRelease (keys[0]);
+ }
+
+ CFRelease (store);
+ }
+
+ if (source != NULL) {
+ CFRunLoopAddSource (CFRunLoopGetCurrent(),
+ source, kCFRunLoopDefaultMode);
+ }
+
+ signal(SIGTERM, afsd_event_cleanup);
+
+ CFRunLoopRun();
+}
+#endif
+
/* ParseArgs is now obsolete, being handled by cmd */
/*------------------------------------------------------------------------------
if (afsd_debug) {
printf("%s: Current directory entry:\n", rn);
#ifdef AFS_SGI62_ENV
- printf("\tinode=%lld, reclen=%d, name='%s'\n", currp->d_ino,
+ printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n", currp->d_ino,
currp->d_reclen, currp->d_name);
#else
printf("\tinode=%d, reclen=%d, name='%s'\n", currp->d_ino,
* file's inode, directory, and bump the number of files found
* total and in this directory.
*/
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
inode_for_V[vFileNum] = currp->d_ino;
+#endif
dir_for_V[vFileNum] = dirNum; /* remember this directory */
if (!maxDir) {
vFileNum);
else {
struct stat statb;
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
+#endif
sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
if (afsd_verbose)
printf("%s: Creating '%s'\n", rn, fullpn_VFile);
if (CreateCacheFile(fullpn_VFile, &statb))
printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
else {
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
inode_for_V[vFileNum] = statb.st_ino;
+#endif
dir_for_V[vFileNum] = thisDir;
cache_dir_list[thisDir]++;
(*vFilesFound)++;
if (res != 0) {
return "unable to statfs cache base directory";
}
+#if !defined(LINUX_USE_FH)
if (statfsbuf.f_type == 0x52654973) { /* REISERFS_SUPER_MAGIC */
return "cannot use reiserfs as cache partition";
} else if (statfsbuf.f_type == 0x58465342) { /* XFS_SUPER_MAGIC */
} else if (statfsbuf.f_type != 0xEF53) {
return "must use ext2 or ext3 for cache partition";
}
+#endif
}
#endif
return doSweepAFSCache(vFilesFound, cacheBaseDir, -2, maxDir);
}
-static
-ConfigCell(struct afsconf_cell *aci, char *arock, struct afsconf_dir *adir)
+static int
+ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir)
{
int isHomeCell;
int i, code;
static
ConfigCellAlias(struct afsconf_cellalias *aca,
- char *arock, struct afsconf_dir *adir)
+ void *arock, struct afsconf_dir *adir)
{
/* push the alias into the kernel */
call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName);
kernelMsg[1] = 0;
acellName[0] = '\0';
+#ifdef AFS_DARWIN_ENV
+ /* Fork the event handler also. */
+ code = fork();
+ if (code == 0) {
+ afsd_install_events();
+ exit(1);
+ } else if (code != -1) {
+ event_pid = code;
+ }
+#endif
while (1) {
/* On some platforms you only get 4 args to an AFS call */
int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg);
acellName[sizeof(acellName) - 1] = '\0';
}
}
-
+#ifdef AFS_DARWIN_ENV
+ kill(event_pid, SIGTERM);
+#endif
exit(1);
}
#endif
#endif
#endif
-mainproc(struct cmd_syndesc *as, char *arock)
+mainproc(struct cmd_syndesc *as, void *arock)
{
static char rn[] = "afsd"; /*Name of this routine */
afs_int32 code; /*Result of fork() */
if (afsd_verbose)
printf("%s: cacheFiles autotuned to %d\n", rn, cacheFiles);
}
+#if 0
+ /* This actually needs to
+ 1) use powers of 2
+ 2) not second-guess when a chunksize comes from the command line
+ 3) be less, um, small. 2^2??
+ */
/* Sanity check chunkSize */
i = max(cacheBlocks / 1000, cacheBlocks / cacheFiles);
chunkSize = min(chunkSize, i);
chunkSize = max(chunkSize, 2);
if (afsd_verbose)
printf("%s: chunkSize autotuned to %d\n", rn, chunkSize);
+#endif
if (!sawDCacheSize) {
dCacheSize = cacheFiles / 2;
cacheStatEntries);
}
+#if !defined(AFS_CACHE_VNODE_PATH) && !defined(LINUX_USE_FH)
/*
* Create and zero the inode table for the desired cache files.
*/
if (afsd_debug)
printf("%s: %d inode_for_V entries at 0x%x, %d bytes\n", rn,
cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
+#endif
/*
* Set up all the pathnames we'll need for later.
exit(1);
#endif
}
-#if 0
- fputs(AFS_GOVERNMENT_MESSAGE, stdout);
- fflush(stdout);
-#endif
/*
* Set up all the kernel processes needed for AFS.
rn, vFilesFound, cacheFiles, cacheIteration);
} while ((vFilesFound < cacheFiles)
&& (cacheIteration < MAX_CACHE_LOOPS));
+#ifdef AFS_CACHE_VNODE_PATH
+ if (afsd_debug)
+ printf
+ ("%s: Calling AFSOP_CACHEBASEDIR with '%s'\n",
+ rn, cacheBaseDir);
+ call_syscall(AFSOP_CACHEBASEDIR, cacheBaseDir);
+ if (afsd_debug)
+ printf
+ ("%s: Calling AFSOP_CACHEDIRS with %d dirs\n",
+ rn, nFilesPerDir);
+ call_syscall(AFSOP_CACHEDIRS, nFilesPerDir);
+ if (afsd_debug)
+ printf
+ ("%s: Calling AFSOP_CACHEFILES with %d files\n",
+ rn, cacheFiles);
+ call_syscall(AFSOP_CACHEFILES, cacheFiles);
+#endif
} else if (afsd_verbose)
printf("%s: Using memory cache, not swept\n", rn);
if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
+#ifndef AFS_CACHE_VNODE_PATH
/*
* Give the kernel the names of the AFS files cached on the workstation's
* disk.
(afs_uint32) (inode_for_V[currVFile] >> 32),
(afs_uint32) (inode_for_V[currVFile] & 0xffffffff));
#else
+#if defined(LINUX_USE_FH)
+ sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile);
+ call_syscall(AFSOP_CACHEFILE, fullpn_VFile);
+#else
call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
#endif
+#endif
}
-
+#endif
/*end for */
/*