From f77c078a291025d593f3170c57b6be5f257fc3e5 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Thu, 8 Apr 2010 16:37:51 -0500 Subject: [PATCH] Split afsd into afsd.c and afsd_kernel.c Move the parts of afsd.c that depend on using the kernel module into afsd_kernel.c. Keep in afsd.c code that can be used with libuafs drivers. Change-Id: I22c4dd698e8c12c42dabd85ea38226ffd8746d11 Reviewed-on: http://gerrit.openafs.org/1723 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- README.WARNINGS | 5 +- src/afsd/Makefile.in | 7 +- src/afsd/afsd.c | 745 +++++++++++++++---------------------------------- src/afsd/afsd.h | 36 +++ src/afsd/afsd_kernel.c | 524 ++++++++++++++++++++++++++++++++++ 5 files changed, 795 insertions(+), 522 deletions(-) create mode 100644 src/afsd/afsd.h create mode 100644 src/afsd/afsd_kernel.c diff --git a/README.WARNINGS b/README.WARNINGS index 50918ff..e3e0a1c 100644 --- a/README.WARNINGS +++ b/README.WARNINGS @@ -42,8 +42,9 @@ Inhibited warnings afs/afs_syscall.c : old-style : strict-proto : all (ukernel) : syscall pointer issues -afsd/afsd.c : deprecated : daemon() marked as deprecated on Darwin - : all : call_syscall missing prototype +afsd/afsd.c : all : call_syscall nonsense +afsd/afsd_kernel.c : deprecated : daemon() marked as deprecated on Darwin + : strict-proto : call_syscall missing prototype auth/ktc.c : all (ukernel) : call_syscall doesn't have a prototype bozo/bosserver.c : deprecated : daemon() marked as deprecated on Darwin bucoord/ubik_db_if.c : strict-proto : Ubik_Call diff --git a/src/afsd/Makefile.in b/src/afsd/Makefile.in index bf60000..d1c2d71 100644 --- a/src/afsd/Makefile.in +++ b/src/afsd/Makefile.in @@ -26,8 +26,8 @@ all: afsd vsys AFSLIBS=${TOP_LIBDIR}/libauth.a ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/util.a ${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/util.a -afsd: afsd.o $(AFSLIBS) $(AFSD_LIBS) - ${CC} ${CFLAGS} -o afsd afsd.o @CFLAGS_NOERROR@ $(NON_SHARED) $(LDFLAGS) $(AFSD_LDFLAGS) $(AFSLIBS) ${XLIBS} ${AFSD_LIBS} +afsd: afsd.o afsd_kernel.o $(AFSLIBS) $(AFSD_LIBS) + ${CC} ${CFLAGS} -o afsd afsd.o afsd_kernel.o $(NON_SHARED) $(LDFLAGS) $(AFSD_LDFLAGS) $(AFSLIBS) ${XLIBS} ${AFSD_LIBS} vsys: vsys.o ${CC} ${CFLAGS} -o vsys vsys.o ${TOP_LIBDIR}/libsys.a $(LDFLAGS) ${XLIBS} @@ -38,6 +38,9 @@ vsys: vsys.o afsd.o: afsd.c AFS_component_version_number.c $(CC) $(CFLAGS) @CFLAGS_NOERROR@ -c $< +afsd_kernel.o: afsd_kernel.c + $(CC) $(CFLAGS) @CFLAGS_NOERROR@ -c $< + vsys.o: vsys.c AFS_component_version_number.c clean: diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 697b664..96999f0 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -64,6 +64,8 @@ #include +#include "afsd.h" + #include #include #include @@ -152,22 +154,13 @@ void set_staticaddrs(void); #ifdef AFS_SGI65_ENV #include #endif -#ifdef AFS_LINUX20_ENV -#include -#endif + #ifdef AFS_DARWIN_ENV #ifdef AFS_DARWIN80_ENV #include #include #endif #include -#ifndef AFS_DARWIN100_ENV -/* Symbols from the DiskArbitration framework */ -kern_return_t DiskArbStart(mach_port_t *); -kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int, - char *); -#define DISK_ARB_NETWORK_DISK_FLAG 8 -#endif #include #include #include @@ -180,15 +173,6 @@ kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int, #include #include -#include - -typedef struct DNSSDState -{ - DNSServiceRef service; - CFRunLoopSourceRef source; - CFSocketRef socket; -} DNSSDState; - static io_connect_t root_port; static IONotificationPortRef notify; static io_object_t iterator; @@ -198,10 +182,6 @@ static int event_pid; #endif /* AFS_DARWIN_ENV */ -#ifndef MOUNT_AFS -#define MOUNT_AFS AFS_MOUNT_AFS -#endif /* MOUNT_AFS */ - #if AFS_HAVE_STATVFS #include #else @@ -214,7 +194,6 @@ static int event_pid; #endif #endif - #undef VIRTUE #undef VICE @@ -282,7 +261,7 @@ int sawCacheBlocks = 0; int sawDCacheSize = 0; int sawBiod = 0; int sawCacheStatEntries = 0; -char cacheMountDir[1024]; /*Mount directory for AFS */ +char afsd_cacheMountDir[1024]; /*Mount directory for AFS */ char rootVolume[64] = "root.afs"; /*AFS root volume name */ afs_int32 cacheSetTime = FALSE; /*Keep checking time to avoid drift? */ afs_int32 isHomeCell; /*Is current cell info for the home cell? */ @@ -350,11 +329,15 @@ int missing_CellInfoFile = 1; /*Is the CELLINFOFILE missing? */ int afsd_rmtsys = 0; /* Default: don't support rmtsys */ struct afs_cacheParams cparams; /* params passed to cache manager */ -static int HandleMTab(void); int PartSizeOverflow(char *path, int cs); -/* for now, not prototyped fully as it can't be */ -int call_syscall(); +#if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV) +static void fork_rx_syscall_wait(); +#endif +#if defined(AFS_SUN510_ENV) || defined(RXK_LISTENER_ENV) +static void fork_rx_syscall(); +#endif +static void fork_syscall(); #ifdef AFS_DARWIN_ENV static void @@ -413,7 +396,7 @@ afsd_update_addresses(CFRunLoopTimerRef timer, void *info) if (code > 0) { /* Note we're refreshing */ code = code | 0x40000000; - call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf); + afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf); } else printf("ADVISEADDR: Error in specifying interface addresses:%s\n", reason); @@ -585,7 +568,7 @@ ParseCacheInfoFile(void) tbd++); /* now copy in the fields not explicitly overridden by cmd args */ if (!sawCacheMountDir) - strcpy(cacheMountDir, tmd); + strcpy(afsd_cacheMountDir, tmd); if (!sawCacheBaseDir) strcpy(cacheBaseDir, tbd); if (!sawCacheBlocks) @@ -1434,7 +1417,7 @@ ConfigCell(struct afsconf_cell *aci, void *arock, struct afsconf_dir *adir) * for upwards compatibility */ /* configure one cell */ - code = call_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */ + code = afsd_call_syscall(AFSOP_ADDCELL2, hosts, /* server addresses */ aci->name, /* cell name */ cellFlags, /* is this the home cell? */ aci->linkedCell); /* Linked cell, if any */ @@ -1448,7 +1431,7 @@ ConfigCellAlias(struct afsconf_cellalias *aca, void *arock, struct afsconf_dir *adir) { /* push the alias into the kernel */ - call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName); + afsd_call_syscall(AFSOP_ADDCELLALIAS, aca->aliasName, aca->realName); return 0; } @@ -1470,7 +1453,7 @@ AfsdbLookupHandler(void) code = fork(); if (code == 0) { afsd_install_events(); - exit(1); + return; } else if (code != -1) { event_pid = code; } @@ -1479,7 +1462,7 @@ AfsdbLookupHandler(void) /* On some platforms you only get 4 args to an AFS call */ int sizeArg = ((sizeof acellName) << 16) | (sizeof kernelMsg); code = - call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg); + afsd_call_syscall(AFSOP_AFSDB_HANDLER, acellName, kernelMsg, sizeArg); if (code) { /* Something is wrong? */ sleep(1); continue; @@ -1507,7 +1490,6 @@ AfsdbLookupHandler(void) #ifdef AFS_DARWIN_ENV kill(event_pid, SIGTERM); #endif - exit(1); } #ifdef AFS_DARWIN_ENV @@ -1536,7 +1518,7 @@ BkgHandler(void) /* pushing in a buffer this large */ uspc->bufSz = 256; - code = call_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName); + code = afsd_call_syscall(AFSOP_BKG_HANDLER, uspc, srcName, dstName); if (code) { /* Something is wrong? */ if (code == -2) /* shutting down */ break; @@ -1620,45 +1602,59 @@ BkgHandler(void) break; } } - exit(1); } #endif -#ifdef AFS_SGI65_ENV -#define SET_RTPRI(P) { \ - struct sched_param sp; \ - sp.sched_priority = P; \ - if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \ - perror("sched_setscheduler"); \ - } \ +static void * +afsdb_thread(void *rock) +{ + /* Since the AFSDB lookup handler runs as a user process, + * need to drop the controlling TTY, etc. + */ + if (afsd_daemon(0, 0) == -1) { + printf("Error starting AFSDB lookup handler: %s\n", + strerror(errno)); + exit(1); + } + AfsdbLookupHandler(); + return NULL; } -#define SET_AFSD_RTPRI() SET_RTPRI(68) -#define SET_RX_RTPRI() SET_RTPRI(199) -#else -#ifdef AFS_LINUX20_ENV -#define SET_AFSD_RTPRI() -#define SET_RX_RTPRI() do { if (setpriority(PRIO_PROCESS, 0, -10)<0) \ - perror("setting rx priority"); \ - } while (0) + +static void * +daemon_thread(void *rock) +{ +#ifdef AFS_DARWIN80_ENV + /* Since the background daemon runs as a user process, + * need to drop the controlling TTY, etc. + */ + if (afsd_daemon(0, 0) == -1) { + printf("Error starting background daemon: %s\n", + strerror(errno)); + exit(1); + } + BkgHandler(); +#elif defined(AFS_AIX32_ENV) + afsd_call_syscall(AFSOP_START_BKG, 0); #else -#define SET_AFSD_RTPRI() -#define SET_RX_RTPRI() -#endif + afsd_call_syscall(AFSOP_START_BKG); #endif + return NULL; +} + +static void * +rmtsysd_thread(void *rock) +{ + rmtsysd(); + return NULL; +} int mainproc(struct cmd_syndesc *as, void *arock) { - static char rn[] = "afsd"; /*Name of this routine */ afs_int32 code; /*Result of fork() */ - int i; - int currVFile; /*Current AFS cache file number passed in */ - int mountFlags; /*Flags passed to mount() */ - int lookupResult; /*Result of GetLocalCellName() */ - int cacheIteration; /*How many times through cache verification */ - int vFilesFound; /*How many data cache files were found in sweep */ - struct afsconf_dir *cdir; /* config dir */ - char *fsTypeMsg = NULL; +#ifdef AFS_AIX32_ENV + int sawBiod = 0; +#endif #ifdef AFS_SUN5_ENV struct stat st; #endif @@ -1707,7 +1703,7 @@ mainproc(struct cmd_syndesc *as, void *arock) } if (as->parms[6].items) { /* -mountdir */ - strcpy(cacheMountDir, as->parms[6].items->data); + strcpy(afsd_cacheMountDir, as->parms[6].items->data); sawCacheMountDir = 1; } if (as->parms[7].items) { @@ -1784,7 +1780,7 @@ mainproc(struct cmd_syndesc *as, void *arock) * Cold shutdown is the default */ printf("afsd: Shutting down all afs processes and afs state\n"); - code = call_syscall(AFSOP_SHUTDOWN, 1); + code = afsd_call_syscall(AFSOP_SHUTDOWN, 1); if (code) { printf("afsd: AFS still mounted; Not shutting down\n"); exit(1); @@ -1852,7 +1848,7 @@ mainproc(struct cmd_syndesc *as, void *arock) /* -rxpck */ int rxpck = atoi(as->parms[33].items->data); printf("afsd: set rxpck = %d\n", rxpck); - code = call_syscall(AFSOP_SET_RXPCK, rxpck); + code = afsd_call_syscall(AFSOP_SET_RXPCK, rxpck); if (code) { printf("afsd: failed to set rxpck\n"); exit(1); @@ -1898,6 +1894,21 @@ mainproc(struct cmd_syndesc *as, void *arock) /* -rxmaxmtu */ rxmaxmtu = atoi(as->parms[36].items->data); } + return 0; +} + +int +afsd_run(void) +{ + static char rn[] = "afsd"; /*Name of this routine */ + struct afsconf_dir *cdir; /* config dir */ + int lookupResult; /*Result of GetLocalCellName() */ + int i; + afs_int32 code; /*Result of fork() */ + char *fsTypeMsg = NULL; + int cacheIteration; /*How many times through cache verification */ + int vFilesFound; /*How many data cache files were found in sweep */ + int currVFile; /*Current AFS cache file number passed in */ /* * Pull out all the configuration info for the workstation's AFS cache and @@ -2132,14 +2143,14 @@ mainproc(struct cmd_syndesc *as, void *arock) if (code > 0) { if (enable_rxbind) code = code | 0x80000000; - call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf); + afsd_call_syscall(AFSOP_ADVISEADDR, code, addrbuf, maskbuf, mtubuf); } else printf("ADVISEADDR: Error in specifying interface addresses:%s\n", reason); } /* Set realtime priority for most threads to same as for biod's. */ - SET_AFSD_RTPRI(); + afsd_set_afsd_rtpri(); #ifdef AFS_SGI53_ENV #ifdef AFS_SGI61_ENV @@ -2147,7 +2158,7 @@ mainproc(struct cmd_syndesc *as, void *arock) #else /* AFS_SGI61_ENV */ code = get_nfsstaticaddr(); if (code) - call_syscall(AFSOP_NFSSTATICADDR, code); + afsd_call_syscall(AFSOP_NFSSTATICADDR, code); #endif /* AFS_SGI61_ENV */ #endif /* AFS_SGI_53_ENV */ @@ -2162,57 +2173,30 @@ mainproc(struct cmd_syndesc *as, void *arock) #ifdef RXK_LISTENER_ENV if (afsd_verbose) printf("%s: Forking rx listener daemon.\n", rn); - code = fork(); - if (code == 0) { - /* Child */ - SET_RX_RTPRI(); /* max advised for non-interrupts */ - call_syscall(AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats, - enable_process_stats); - exit(1); - } -#ifdef AFS_SUN510_ENV - waitpid((pid_t) -1, NULL, 0); -#endif +# ifdef AFS_SUN510_ENV + fork_rx_syscall_wait(rn, AFSOP_RXLISTENER_DAEMON, preallocs, + enable_peer_stats, enable_process_stats); +# else /* !AFS_SUN510_ENV */ + fork_rx_syscall(rn, AFSOP_RXLISTENER_DAEMON, preallocs, enable_peer_stats, + enable_process_stats); +# endif /* !AFS_SUN510_ENV */ #endif if (afsd_verbose) printf("%s: Forking rx callback listener.\n", rn); - code = fork(); - if (code == 0) { - /* Child */ - call_syscall(AFSOP_START_RXCALLBACK, preallocs); - exit(1); - } + fork_syscall(rn, AFSOP_START_RXCALLBACK, preallocs); #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) if (afsd_verbose) printf("%s: Forking rxevent daemon.\n", rn); - code = fork(); - if (code == 0) { - /* Child */ - SET_RX_RTPRI(); /* max advised for non-interrupts */ - call_syscall(AFSOP_RXEVENT_DAEMON); - exit(1); - } + fork_rx_syscall(rn, AFSOP_RXEVENT_DAEMON); #endif if (enable_afsdb) { if (afsd_verbose) printf("%s: Forking AFSDB lookup handler.\n", rn); - code = fork(); - if (code == 0) { - /* Since the AFSDB lookup handler runs as a user process, - * need to drop the controlling TTY, etc. - */ - if (daemon(0, 0) == -1) { - printf("Error starting AFSDB lookup handler: %s\n", - strerror(errno)); - exit(1); - } - AfsdbLookupHandler(); - exit(1); - } + afsd_fork(0, afsdb_thread, NULL); } - code = call_syscall(AFSOP_BASIC_INIT, 1); + code = afsd_call_syscall(AFSOP_BASIC_INIT, 1); if (code) { printf("%s: Error %d in basic initialization.\n", rn, code); exit(1); @@ -2236,16 +2220,16 @@ mainproc(struct cmd_syndesc *as, void *arock) cparams.setTimeFlag = cacheSetTime; cparams.memCacheFlag = cacheFlags; cparams.dynamic_vcaches = afsd_dynamic_vcaches; - call_syscall(AFSOP_CACHEINIT, &cparams); + afsd_call_syscall(AFSOP_CACHEINIT, &cparams); /* do it before we init the cache inodes */ if (enable_splitcache) { - call_syscall(AFSOP_BUCKETPCT, 1, rwpct); - call_syscall(AFSOP_BUCKETPCT, 2, ropct); + afsd_call_syscall(AFSOP_BUCKETPCT, 1, rwpct); + afsd_call_syscall(AFSOP_BUCKETPCT, 2, ropct); } if (afsd_CloseSynch) - call_syscall(AFSOP_CLOSEWAIT); + afsd_call_syscall(AFSOP_CLOSEWAIT); /* * Sweep the workstation AFS cache directory, remembering the inodes of @@ -2286,7 +2270,7 @@ mainproc(struct cmd_syndesc *as, void *arock) fullpn_DCacheFile); /* once again, meaningless for a memory-based cache. */ if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) - call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile); + afsd_call_syscall(AFSOP_CACHEINFO, fullpn_DCacheFile); /* * Pass the kernel the name of the workstation cache file holding the @@ -2295,12 +2279,12 @@ mainproc(struct cmd_syndesc *as, void *arock) if (afsd_debug) printf("%s: Calling AFSOP_CELLINFO: cell info file is '%s'\n", rn, fullpn_CellInfoFile); - call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile); + afsd_call_syscall(AFSOP_CELLINFO, fullpn_CellInfoFile); if (rxmaxmtu) { if (afsd_verbose) printf("%s: Setting rxmaxmtu in kernel = %d\n", rn, rxmaxmtu); - code = call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu); + code = afsd_call_syscall(AFSOP_SET_RXMAXMTU, rxmaxmtu); if (code) printf("%s: Error seting rxmaxmtu\n", rn); } @@ -2308,7 +2292,7 @@ mainproc(struct cmd_syndesc *as, void *arock) if (enable_dynroot) { if (afsd_verbose) printf("%s: Enabling dynroot support in kernel.\n", rn); - code = call_syscall(AFSOP_SET_DYNROOT, 1); + code = afsd_call_syscall(AFSOP_SET_DYNROOT, 1); if (code) printf("%s: Error enabling dynroot support.\n", rn); } @@ -2316,7 +2300,7 @@ mainproc(struct cmd_syndesc *as, void *arock) if (enable_fakestat) { if (afsd_verbose) printf("%s: Enabling fakestat support in kernel.\n", rn); - code = call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat); + code = afsd_call_syscall(AFSOP_SET_FAKESTAT, enable_fakestat); if (code) printf("%s: Error enabling fakestat support.\n", rn); } @@ -2324,7 +2308,7 @@ mainproc(struct cmd_syndesc *as, void *arock) if (enable_backuptree) { if (afsd_verbose) printf("%s: Enabling backup tree support in kernel.\n", rn); - code = call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree); + code = afsd_call_syscall(AFSOP_SET_BACKUPTREE, enable_backuptree); if (code) printf("%s: Error enabling backup tree support.\n", rn); } @@ -2338,28 +2322,16 @@ mainproc(struct cmd_syndesc *as, void *arock) /* * Set the primary cell name. */ - call_syscall(AFSOP_SET_THISCELL, LclCellName); + afsd_call_syscall(AFSOP_SET_THISCELL, LclCellName); /* Initialize AFS daemon threads. */ if (afsd_verbose) printf("%s: Forking AFS daemon.\n", rn); - code = fork(); - if (code == 0) { - /* Child */ - call_syscall(AFSOP_START_AFS); - exit(1); - } + fork_syscall(rn, AFSOP_START_AFS); if (afsd_verbose) printf("%s: Forking Check Server Daemon.\n", rn); - code = fork(); - if (code == 0) { - /* Child */ - code = call_syscall(AFSOP_START_CS); - if (code) - printf("%s: No check server daemon in client.\n", rn); - exit(1); - } + fork_syscall(rn, AFSOP_START_CS); if (afsd_verbose) printf("%s: Forking %d background daemons.\n", rn, nDaemons); @@ -2370,25 +2342,7 @@ mainproc(struct cmd_syndesc *as, void *arock) nDaemons++; #endif for (i = 0; i < nDaemons; i++) { - code = fork(); - if (code == 0) { -#ifdef AFS_DARWIN80_ENV - /* Since the background daemon runs as a user process, - * need to drop the controlling TTY, etc. - */ - if (daemon(0, 0) == -1) { - printf("Error starting background daemon: %s\n", - strerror(errno)); - exit(1); - } - BkgHandler(); -#elif defined(AFS_AIX32_ENV) - call_syscall(AFSOP_START_BKG, 0); -#else - call_syscall(AFSOP_START_BKG); -#endif - exit(1); - } + afsd_fork(0, daemon_thread, NULL); } #ifdef AFS_AIX32_ENV if (!sawBiod) @@ -2396,11 +2350,7 @@ mainproc(struct cmd_syndesc *as, void *arock) if (nBiods < 5) nBiods = 5; for (i = 0; i < nBiods; i++) { - code = fork(); - if (code == 0) { /* Child */ - call_syscall(AFSOP_START_BKG, nBiods); - exit(1); - } + fork_syscall(rn, AFSOP_START_BKG, nBiods); } #endif @@ -2411,7 +2361,7 @@ mainproc(struct cmd_syndesc *as, void *arock) if (afsd_verbose) printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn, rootVolume); - call_syscall(AFSOP_ROOTVOLUME, rootVolume); + afsd_call_syscall(AFSOP_ROOTVOLUME, rootVolume); } /* @@ -2423,7 +2373,7 @@ mainproc(struct cmd_syndesc *as, void *arock) fullpn_VolInfoFile); /* once again, meaningless for a memory-based cache. */ if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) - call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile); + afsd_call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile); /* * Give the kernel the names of the AFS files cached on the workstation's @@ -2439,7 +2389,7 @@ mainproc(struct cmd_syndesc *as, void *arock) for (currVFile = 0; currVFile < cacheFiles; currVFile++) { if (!nocachefile) { sprintf(fullpn_VFile, "%s/D%d/V%d", cacheBaseDir, dir_for_V[currVFile], currVFile); - code = call_syscall(AFSOP_CACHEFILE, fullpn_VFile); + code = afsd_call_syscall(AFSOP_CACHEFILE, fullpn_VFile); if (code) { if (currVFile == 0) { if (afsd_debug) @@ -2459,11 +2409,11 @@ mainproc(struct cmd_syndesc *as, void *arock) /* fall through to setup-by-inode */ } #ifdef AFS_SGI62_ENV - call_syscall(AFSOP_CACHEINODE, + afsd_call_syscall(AFSOP_CACHEINODE, (afs_uint32) (inode_for_V[currVFile] >> 32), (afs_uint32) (inode_for_V[currVFile] & 0xffffffff)); #elif !(defined(LINUX_USE_FH) || defined(AFS_CACHE_VNODE_PATH)) - call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]); + afsd_call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]); #else printf ("%s: Error calling AFSOP_CACHEINODE: not configured\n", @@ -2480,7 +2430,7 @@ mainproc(struct cmd_syndesc *as, void *arock) if (afsd_debug) printf("%s: Calling AFSOP_GO with cacheSetTime = %d\n", rn, cacheSetTime); - call_syscall(AFSOP_GO, cacheSetTime); + afsd_call_syscall(AFSOP_GO, cacheSetTime); /* * At this point, we have finished passing the kernel all the info @@ -2490,82 +2440,27 @@ mainproc(struct cmd_syndesc *as, void *arock) if (afsd_verbose) printf("%s: Forking trunc-cache daemon.\n", rn); - code = fork(); - if (code == 0) { - /* Child */ - call_syscall(AFSOP_START_TRUNCDAEMON); - exit(1); - } + fork_syscall(rn, AFSOP_START_TRUNCDAEMON); if (!enable_nomount) { - - mountFlags = 0; /* Read/write file system, can do setuid() */ -#if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV) -#ifdef AFS_SUN5_ENV - mountFlags |= MS_DATA; -#else - mountFlags |= M_NEWTYPE; /* This searches by name in vfs_conf.c so don't need to recompile vfs.c because MOUNT_MAXTYPE has changed; it seems that Sun fixed this at last... */ -#endif -#endif - -#if defined(AFS_HPUX100_ENV) - mountFlags |= MS_DATA; -#endif - - if (afsd_verbose) - printf("%s: Mounting the AFS root on '%s', flags: %d.\n", rn, - cacheMountDir, mountFlags); -#if defined(AFS_FBSD60_ENV) - /* data must be non-NULL but is otherwise ignored */ - if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, rn)) < 0) { -#elif defined(AFS_FBSD_ENV) - if ((mount("AFS", cacheMountDir, mountFlags, (caddr_t) 0)) < 0) { -#elif defined(AFS_AIX_ENV) - if (aix_vmount()) { -#elif defined(AFS_HPUX100_ENV) - if ((mount("", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) { -#elif defined(AFS_SUN5_ENV) - if ((mount("AFS", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) { -#elif defined(AFS_SGI_ENV) - mountFlags = MS_FSS; - if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) MOUNT_AFS)) - < 0) { -#elif defined(AFS_LINUX20_ENV) - if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL)) < 0) { -#else -/* This is the standard mount used by the suns and rts */ - if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) { -#endif - printf("%s: Can't mount AFS on %s(%d)\n", rn, cacheMountDir, - errno); - exit(1); - } - - HandleMTab(); - + afsd_mount_afs(rn, afsd_cacheMountDir); } if (afsd_rmtsys) { if (afsd_verbose) printf("%s: Forking 'rmtsys' daemon.\n", rn); - code = fork(); - if (code == 0) { - /* Child */ - rmtsysd(); - exit(1); - } + afsd_fork(0, rmtsysd_thread, NULL); } /* * Exit successfully. */ - exit(0); + return 0; } #include "AFS_component_version_number.c" - -int -main(int argc, char **argv) +void +afsd_init(void) { struct cmd_syndesc *ts; @@ -2643,303 +2538,13 @@ main(int argc, char **argv) cmd_AddParm(ts, "-disable-dynamic-vcaches", CMD_FLAG, CMD_OPTIONAL, "disable stat/vcache cache growing as needed"); cmd_AddParm(ts, "-rxmaxmtu", CMD_SINGLE, CMD_OPTIONAL, "set rx max MTU to use"); - - return (cmd_Dispatch(argc, argv)); -} - - -#ifdef AFS_HPUX_ENV -#define MOUNTED_TABLE MNT_MNTTAB -#else -#ifdef AFS_SUN5_ENV -#define MOUNTED_TABLE MNTTAB -#else -#define MOUNTED_TABLE MOUNTED -#endif -#endif - -static int -HandleMTab(void) -{ -#if (defined (AFS_SUN_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)) && !defined(AFS_SUN58_ENV) - FILE *tfilep; -#ifdef AFS_SUN5_ENV - char tbuf[16]; - struct mnttab tmntent; - - memset(&tmntent, '\0', sizeof(struct mnttab)); - if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) { - printf("Can't open %s\n", MOUNTED_TABLE); - perror(MNTTAB); - exit(-1); - } - tmntent.mnt_special = "AFS"; - tmntent.mnt_mountp = cacheMountDir; - tmntent.mnt_fstype = "xx"; - tmntent.mnt_mntopts = "rw"; - sprintf(tbuf, "%ld", (long)time((time_t *) 0)); - tmntent.mnt_time = tbuf; - putmntent(tfilep, &tmntent); - fclose(tfilep); -#else -#if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV) - struct mntent tmntent; - - tfilep = setmntent("/etc/mtab", "a+"); - tmntent.mnt_fsname = "AFS"; - tmntent.mnt_dir = cacheMountDir; - tmntent.mnt_type = "afs"; - tmntent.mnt_opts = "rw"; - tmntent.mnt_freq = 1; - tmntent.mnt_passno = 3; - addmntent(tfilep, &tmntent); - endmntent(tfilep); -#else - struct mntent tmntent; - - memset(&tmntent, '\0', sizeof(struct mntent)); - tfilep = setmntent(MOUNTED_TABLE, "a+"); - if (!tfilep) { - printf("Can't open %s for write; Not adding afs entry to it\n", - MOUNTED_TABLE); - return 1; - } - tmntent.mnt_fsname = "AFS"; - tmntent.mnt_dir = cacheMountDir; - tmntent.mnt_type = "xx"; - tmntent.mnt_opts = "rw"; - tmntent.mnt_freq = 1; - tmntent.mnt_passno = 3; -#ifdef AFS_HPUX_ENV - tmntent.mnt_type = "afs"; - tmntent.mnt_time = time(0); - tmntent.mnt_cnode = 0; -#endif - addmntent(tfilep, &tmntent); - endmntent(tfilep); -#endif /* AFS_SGI_ENV */ -#endif /* AFS_SUN5_ENV */ -#endif /* unreasonable systems */ -#ifdef AFS_DARWIN_ENV -#ifndef AFS_DARWIN100_ENV - mach_port_t diskarb_port; - kern_return_t status; - - status = DiskArbStart(&diskarb_port); - if (status == KERN_SUCCESS) { - status = - DiskArbDiskAppearedWithMountpointPing_auto("AFS", - DISK_ARB_NETWORK_DISK_FLAG, - cacheMountDir); - } - - return status; -#endif -#endif /* AFS_DARWIN_ENV */ - return 0; } -#if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV) int -call_syscall(long param1, long param2, long param3, long param4, long param5, - long param6, long param7) +afsd_parse(int argc, char **argv) { - int error; -#ifdef AFS_LINUX20_ENV - long eparm[4]; - struct afsprocdata syscall_data; - int fd = open(PROC_SYSCALL_FNAME, O_RDWR); - if (fd < 0) - fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR); - eparm[0] = param4; - eparm[1] = param5; - eparm[2] = param6; - eparm[3] = param7; - - param4 = (long)eparm; - - syscall_data.syscall = AFSCALL_CALL; - syscall_data.param1 = param1; - syscall_data.param2 = param2; - syscall_data.param3 = param3; - syscall_data.param4 = param4; - if (fd > 0) { - error = ioctl(fd, VIOC_SYSCALL, &syscall_data); - close(fd); - } else -#endif -#ifdef AFS_DARWIN80_ENV - struct afssysargs syscall_data; - void *ioctldata; - int fd = open(SYSCALL_DEV_FNAME,O_RDWR); - int syscallnum; -#ifdef AFS_DARWIN100_ENV - int is64 = 0; - struct afssysargs64 syscall64_data; - if (sizeof(param1) == 8) { - syscallnum = VIOC_SYSCALL64; - is64 = 1; - ioctldata = &syscall64_data; - syscall64_data.syscall = (int)AFSCALL_CALL; - syscall64_data.param1 = param1; - syscall64_data.param2 = param2; - syscall64_data.param3 = param3; - syscall64_data.param4 = param4; - syscall64_data.param5 = param5; - syscall64_data.param6 = param6; - } else { -#endif - syscallnum = VIOC_SYSCALL; - ioctldata = &syscall_data; - syscall_data.syscall = AFSCALL_CALL; - syscall_data.param1 = param1; - syscall_data.param2 = param2; - syscall_data.param3 = param3; - syscall_data.param4 = param4; - syscall_data.param5 = param5; - syscall_data.param6 = param6; -#ifdef AFS_DARWIN100_ENV - } -#endif - if(fd >= 0) { - error = ioctl(fd, syscallnum, ioctldata); - close(fd); - } else { - error = -1; - } - if (!error) { -#ifdef AFS_DARWIN100_ENV - if (is64) - error=syscall64_data.retval; - else -#endif - error=syscall_data.retval; - } -#else - error = - syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4, - param5, param6, param7); -#endif - - if (afsd_debug) - printf("SScall(%d, %d, %ld)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1, - error); - return (error); + return cmd_Dispatch(argc, argv); } -#else /* AFS_AIX32_ENV */ -#if defined(AFS_SGI_ENV) -call_syscall(call, parm0, parm1, parm2, parm3, parm4) -{ - - int error; - - error = afs_syscall(call, parm0, parm1, parm2, parm3, parm4); - if (afsd_verbose) - printf("SScall(%d, %d)=%d ", call, parm0, error); - - return error; -} -#else -call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6) -{ - - return syscall(AFSCALL_CALL, call, parm0, parm1, parm2, parm3, parm4, - parm5, parm6); -} -#endif /* AFS_SGI_ENV */ -#endif /* AFS_AIX32_ENV */ - - -#ifdef AFS_AIX_ENV -/* Special handling for AIX's afs mount operation since they require much more miscl. information before making the vmount(2) syscall */ -#include - -#define ROUNDUP(x) (((x) + 3) & ~3) - -aix_vmount() -{ - struct vmount *vmountp; - int size, error; - - size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4; - /* Malloc the vmount structure */ - if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) { - printf("Can't allocate space for the vmount structure (AIX)\n"); - exit(1); - } - - /* zero out the vmount structure */ - memset(vmountp, '\0', size); - - /* transfer info into the vmount structure */ - vmountp->vmt_revision = VMT_REVISION; - vmountp->vmt_length = size; - vmountp->vmt_fsid.fsid_dev = 0; - vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS; - vmountp->vmt_vfsnumber = 0; - vmountp->vmt_time = 0; /* We'll put the time soon! */ - vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */ - vmountp->vmt_gfstype = AFS_MOUNT_AFS; - vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw"); - - /* Do the actual mount system call */ - error = vmount(vmountp, size); - free(vmountp); - return (error); -} - -vmountdata(struct vmount * vmtp, char *obj, char *stub, char *host, - char *hostsname, char *info, char *args) -{ - struct data { - short vmt_off; - short vmt_size; - } *vdp, *vdprev; - int size; - - vdp = (struct data *)vmtp->vmt_data; - vdp->vmt_off = sizeof(struct vmount); - size = ROUNDUP(strlen(obj) + 1); - vdp->vmt_size = size; - strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj); - - vdprev = vdp; - vdp++; - vdp->vmt_off = vdprev->vmt_off + size; - size = ROUNDUP(strlen(stub) + 1); - vdp->vmt_size = size; - strcpy(vmt2dataptr(vmtp, VMT_STUB), stub); - - vdprev = vdp; - vdp++; - vdp->vmt_off = vdprev->vmt_off + size; - size = ROUNDUP(strlen(host) + 1); - vdp->vmt_size = size; - strcpy(vmt2dataptr(vmtp, VMT_HOST), host); - - vdprev = vdp; - vdp++; - vdp->vmt_off = vdprev->vmt_off + size; - size = ROUNDUP(strlen(hostsname) + 1); - vdp->vmt_size = size; - strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname); - - - vdprev = vdp; - vdp++; - vdp->vmt_off = vdprev->vmt_off + size; - size = ROUNDUP(strlen(info) + 1); - vdp->vmt_size = size; - strcpy(vmt2dataptr(vmtp, VMT_INFO), info); - - vdprev = vdp; - vdp++; - vdp->vmt_off = vdprev->vmt_off + size; - size = ROUNDUP(strlen(args) + 1); - vdp->vmt_size = size; - strcpy(vmt2dataptr(vmtp, VMT_ARGS), args); -} -#endif /* AFS_AIX_ENV */ #ifdef AFS_SGI53_ENV #ifdef AFS_SGI61_ENV @@ -3022,7 +2627,7 @@ set_staticaddrs(void) findDwarfStaticAddresses(fileList, AFS_N_FILELISTS); if (fileList[0].addrList[0].found) { - call_syscall(AFSOP_NFSSTATICADDR2, fileList[0].addrList[0].addr.high, + afsd_call_syscall(AFSOP_NFSSTATICADDR2, fileList[0].addrList[0].addr.high, fileList[0].addrList[0].addr.low); } else { if (afsd_verbose) @@ -3031,7 +2636,7 @@ set_staticaddrs(void) free(fileList[0].addrList); #if defined(AFS_SGI62_ENV) && !defined(AFS_SGI65_ENV) if (fileList[1].addrList[0].found && fileList[1].addrList[1].found) { - call_syscall(AFSOP_SBLOCKSTATICADDR2, + afsd_call_syscall(AFSOP_SBLOCKSTATICADDR2, fileList[1].addrList[0].addr.high, fileList[1].addrList[0].addr.low, fileList[1].addrList[1].addr.high, @@ -3449,3 +3054,107 @@ get_nfsstaticaddr() } #endif /* AFS_SGI61_ENV */ #endif /* AFS_SGI53_ENV */ + +struct afsd_syscall_args { + long syscall; + long param1; + long param2; + long param3; + long param4; + long param5; + const char *rn; + int rxpri; +}; + +/** + * entry point for calling a syscall from another proc/thread. + * + * @param[in] rock a struct afsd_syscall_args* specifying what syscall to call + * + * @return unused + * @retval NULL always + */ +static void * +call_syscall_thread(void *rock) +{ + struct afsd_syscall_args *args = rock; + int code; + + if (args->rxpri) { + afsd_set_rx_rtpri(); + } + + code = afsd_call_syscall(args->syscall, args->param1, args->param2, + args->param3, args->param4, args->param5); + if (code && args->syscall == AFSOP_START_CS) { + printf("%s: No check server daemon in client.\n", args->rn); + } + + free(args); + + return NULL; +} + +/** + * common code for calling a syscall in another proc/thread. + * + * @param[in] rx 1 if this is a thread for RX stuff, 0 otherwise + * @param[in] wait 1 if we should wait for the new proc/thread to finish, 0 to + * let it run in the background + * @param[in] rn the name of the running program + * @param[in] syscall syscall to run + */ +static void +fork_syscall_impl(int rx, int wait, const char *rn, long syscall, long param1, + long param2, long param3, long param4, long param5) +{ + struct afsd_syscall_args *args; + + args = malloc(sizeof(*args)); + + args->syscall = syscall; + args->param1 = param1; + args->param2 = param2; + args->param3 = param3; + args->param4 = param4; + args->param5 = param5; + args->rxpri = rx; + args->rn = rn; + + afsd_fork(wait, call_syscall_thread, args); +} + +/** + * call a syscall in another process or thread. + */ +static void +fork_syscall(const char *rn, long syscall, long param1, long param2, + long param3, long param4, long param5) +{ + fork_syscall_impl(0, 0, rn, syscall, param1, param2, param3, param4, param5); +} + +#if defined(AFS_SUN510_ENV) || defined(RXK_LISTENER_ENV) +/** + * call a syscall in another process or thread, and give it RX priority. + */ +static void +fork_rx_syscall(const char *rn, long syscall, long param1, long param2, + long param3, long param4, long param5) +{ + fork_syscall_impl(1, 0, rn, syscall, param1, param2, param3, param4, param5); +} +#endif /* AFS_SUN510_ENV || RXK_LISTENER_ENV */ + +#if defined(AFS_SUN510_ENV) && defined(RXK_LISTENER_ENV) +/** + * call a syscall in another process or thread, give it RX priority, and wait + * for it to finish before returning. + */ +static void +fork_rx_syscall_wait(const char *rn, long syscall, long param1, long param2, + long param3, long param4, long param5) +{ + fork_syscall_impl(1, 1, rn, syscall, param1, param2, param3, param4, param5); +} +#endif /* AFS_SUN510_ENV && RXK_LISTENER_ENV */ diff --git a/src/afsd/afsd.h b/src/afsd/afsd.h new file mode 100644 index 0000000..bb965a8 --- /dev/null +++ b/src/afsd/afsd.h @@ -0,0 +1,36 @@ +/* + * Copyright 2000, International Business Machines Corporation and others. + * All Rights Reserved. + * + * This software has been released under the terms of the IBM Public + * License. For details, see the LICENSE file in the top-level source + * directory or online at http://www.openafs.org/dl/license10.html + */ + +#ifndef AFSD_AFSD_H +#define AFSD_AFSD_H + +#ifdef IGNORE_SOME_GCC_WARNINGS +# pragma GCC diagnostic warning "-Wstrict-prototypes" +#endif + +extern int afsd_debug; +extern int afsd_verbose; +extern char afsd_cacheMountDir[]; + +void afsd_init(void); +int afsd_parse(int argc, char **argv); +int afsd_run(void); + +/* a function that is called from afsd_fork in a new process/thread */ +typedef void* (*afsd_callback_func) (void *rock); + +/* afsd.c expects these to be implemented; it does not implement them itself! */ +void afsd_mount_afs(const char *rn, const char *mountdir); +void afsd_set_rx_rtpri(void); +void afsd_set_afsd_rtpri(void); +int afsd_call_syscall(); +int afsd_fork(int wait, afsd_callback_func cbf, void *rock); +int afsd_daemon(int nochdir, int noclose); + +#endif /* AFSD_AFSD_H */ diff --git a/src/afsd/afsd_kernel.c b/src/afsd/afsd_kernel.c new file mode 100644 index 0000000..88122ad --- /dev/null +++ b/src/afsd/afsd_kernel.c @@ -0,0 +1,524 @@ +/* + * Copyright 2000, International Business Machines Corporation and others. + * All Rights Reserved. + * + * This software has been released under the terms of the IBM Public + * License. For details, see the LICENSE file in the top-level source + * directory or online at http://www.openafs.org/dl/license10.html + */ + +#include +#include + +#define VFS 1 + +#include + +#include "afsd.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifdef HAVE_SYS_FS_TYPES_H +#include +#endif + +#ifdef HAVE_SYS_MOUNT_H +#include +#endif + +#ifdef HAVE_SYS_FCNTL_H +#include +#endif + +#ifdef HAVE_SYS_MNTTAB_H +#include +#endif + +#ifdef HAVE_SYS_MNTENT_H +#include +#endif + +#ifdef HAVE_MNTENT_H +#include +#endif + +#ifdef HAVE_SYS_MOUNT_H +#include +#endif + +#ifdef HAVE_SYS_VFS_H +#include +#endif + +#ifdef HAVE_SYS_FSTYP_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef HAVE_FCNTL_H +#include +#endif + +#include +#include +#include +#include +#include +#include + +#ifdef AFS_DARWIN_ENV +#ifdef AFS_DARWIN80_ENV +#include +#include +#endif +#include +#ifndef AFS_DARWIN100_ENV +/* Symbols from the DiskArbitration framework */ +kern_return_t DiskArbStart(mach_port_t *); +kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int, + char *); +#define DISK_ARB_NETWORK_DISK_FLAG 8 +#endif +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include + +typedef struct DNSSDState +{ + DNSServiceRef service; + CFRunLoopSourceRef source; + CFSocketRef socket; +} DNSSDState; + +#endif /* AFS_DARWIN_ENV */ + +#ifndef MOUNT_AFS +#define MOUNT_AFS AFS_MOUNT_AFS +#endif /* MOUNT_AFS */ + +#ifdef AFS_SGI65_ENV +# define SET_RTPRI(P) { \ + struct sched_param sp; \ + sp.sched_priority = P; \ + if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \ + perror("sched_setscheduler"); \ + } \ +} +# define SET_AFSD_RTPRI() SET_RTPRI(68) +# define SET_RX_RTPRI() SET_RTPRI(199) +#else +# ifdef AFS_LINUX20_ENV +# define SET_AFSD_RTPRI() +# define SET_RX_RTPRI() do { \ + if (setpriority(PRIO_PROCESS, 0, -10) < 0) \ + perror("setting rx priority"); \ +} while (0) +# else +# define SET_AFSD_RTPRI() +# define SET_RX_RTPRI() +# endif +#endif + +void +afsd_set_rx_rtpri(void) +{ + SET_RX_RTPRI(); +} + +void +afsd_set_afsd_rtpri(void) +{ + SET_AFSD_RTPRI(); +} + +#if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV) + +int +afsd_call_syscall(long param1, long param2, long param3, long param4, long param5, + long param6, long param7) +{ + int error; +# ifdef AFS_LINUX20_ENV + long eparm[4]; + struct afsprocdata syscall_data; + int fd = open(PROC_SYSCALL_FNAME, O_RDWR); + if (fd < 0) + fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR); + eparm[0] = param4; + eparm[1] = param5; + eparm[2] = param6; + eparm[3] = param7; + + param4 = (long)eparm; + + syscall_data.syscall = AFSCALL_CALL; + syscall_data.param1 = param1; + syscall_data.param2 = param2; + syscall_data.param3 = param3; + syscall_data.param4 = param4; + if (fd > 0) { + error = ioctl(fd, VIOC_SYSCALL, &syscall_data); + close(fd); + } else +# endif /* AFS_LINUX20_ENV */ +# ifdef AFS_DARWIN80_ENV + struct afssysargs syscall_data; + int fd = open(SYSCALL_DEV_FNAME,O_RDWR); + syscall_data.syscall = AFSCALL_CALL; + syscall_data.param1 = param1; + syscall_data.param2 = param2; + syscall_data.param3 = param3; + syscall_data.param4 = param4; + syscall_data.param5 = param5; + syscall_data.param6 = param6; + if(fd >= 0) { + error = ioctl(fd, VIOC_SYSCALL, &syscall_data); + close(fd); + } else { + error = -1; + } + if (!error) + error=syscall_data.retval; +# else /* AFS_DARWIN80_ENV */ + error = + syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4, + param5, param6, param7); +# endif /* !AFS_DARWIN80_ENV */ + + if (afsd_debug) + printf("SScall(%d, %d, %ld)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1, + error); + return (error); +} +#else /* !AFS_SGI_ENV && !AFS_AIX32_ENV */ +# if defined(AFS_SGI_ENV) +int +afsd_call_syscall(call, parm0, parm1, parm2, parm3, parm4) +{ + + int error; + + error = afs_syscall(call, parm0, parm1, parm2, parm3, parm4); + if (afsd_verbose) + printf("SScall(%d, %d)=%d ", call, parm0, error); + + return error; +} +# else /* AFS_SGI_ENV */ +int +afsd_call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6) +{ + + return syscall(AFSCALL_CALL, call, parm0, parm1, parm2, parm3, parm4, + parm5, parm6); +} +# endif /* !AFS_SGI_ENV */ +#endif /* AFS_SGI_ENV || AFS_AIX32_ENV */ + + +#ifdef AFS_AIX_ENV +/* Special handling for AIX's afs mount operation since they require much more + * miscl. information before making the vmount(2) syscall */ +#include + +#define ROUNDUP(x) (((x) + 3) & ~3) + +aix_vmount() +{ + struct vmount *vmountp; + int size, error; + + size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4; + /* Malloc the vmount structure */ + if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) { + printf("Can't allocate space for the vmount structure (AIX)\n"); + exit(1); + } + + /* zero out the vmount structure */ + memset(vmountp, '\0', size); + + /* transfer info into the vmount structure */ + vmountp->vmt_revision = VMT_REVISION; + vmountp->vmt_length = size; + vmountp->vmt_fsid.fsid_dev = 0; + vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS; + vmountp->vmt_vfsnumber = 0; + vmountp->vmt_time = 0; /* We'll put the time soon! */ + vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */ + vmountp->vmt_gfstype = AFS_MOUNT_AFS; + vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw"); + + /* Do the actual mount system call */ + error = vmount(vmountp, size); + free(vmountp); + return (error); +} + +vmountdata(struct vmount * vmtp, char *obj, char *stub, char *host, + char *hostsname, char *info, char *args) +{ + struct data { + short vmt_off; + short vmt_size; + } *vdp, *vdprev; + int size; + + vdp = (struct data *)vmtp->vmt_data; + vdp->vmt_off = sizeof(struct vmount); + size = ROUNDUP(strlen(obj) + 1); + vdp->vmt_size = size; + strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj); + + vdprev = vdp; + vdp++; + vdp->vmt_off = vdprev->vmt_off + size; + size = ROUNDUP(strlen(stub) + 1); + vdp->vmt_size = size; + strcpy(vmt2dataptr(vmtp, VMT_STUB), stub); + + vdprev = vdp; + vdp++; + vdp->vmt_off = vdprev->vmt_off + size; + size = ROUNDUP(strlen(host) + 1); + vdp->vmt_size = size; + strcpy(vmt2dataptr(vmtp, VMT_HOST), host); + + vdprev = vdp; + vdp++; + vdp->vmt_off = vdprev->vmt_off + size; + size = ROUNDUP(strlen(hostsname) + 1); + vdp->vmt_size = size; + strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname); + + + vdprev = vdp; + vdp++; + vdp->vmt_off = vdprev->vmt_off + size; + size = ROUNDUP(strlen(info) + 1); + vdp->vmt_size = size; + strcpy(vmt2dataptr(vmtp, VMT_INFO), info); + + vdprev = vdp; + vdp++; + vdp->vmt_off = vdprev->vmt_off + size; + size = ROUNDUP(strlen(args) + 1); + vdp->vmt_size = size; + strcpy(vmt2dataptr(vmtp, VMT_ARGS), args); +} +#endif /* AFS_AIX_ENV */ + +#ifdef AFS_HPUX_ENV +#define MOUNTED_TABLE MNT_MNTTAB +#else +#ifdef AFS_SUN5_ENV +#define MOUNTED_TABLE MNTTAB +#else +#define MOUNTED_TABLE MOUNTED +#endif +#endif + +static int +HandleMTab(char *cacheMountDir) +{ +#if (defined (AFS_SUN_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)) && !defined(AFS_SUN58_ENV) + FILE *tfilep; +#ifdef AFS_SUN5_ENV + char tbuf[16]; + struct mnttab tmntent; + + memset(&tmntent, '\0', sizeof(struct mnttab)); + if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) { + printf("Can't open %s\n", MOUNTED_TABLE); + perror(MNTTAB); + exit(-1); + } + tmntent.mnt_special = "AFS"; + tmntent.mnt_mountp = cacheMountDir; + tmntent.mnt_fstype = "xx"; + tmntent.mnt_mntopts = "rw"; + sprintf(tbuf, "%ld", (long)time((time_t *) 0)); + tmntent.mnt_time = tbuf; + putmntent(tfilep, &tmntent); + fclose(tfilep); +#else +#if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV) + struct mntent tmntent; + + tfilep = setmntent("/etc/mtab", "a+"); + tmntent.mnt_fsname = "AFS"; + tmntent.mnt_dir = cacheMountDir; + tmntent.mnt_type = "afs"; + tmntent.mnt_opts = "rw"; + tmntent.mnt_freq = 1; + tmntent.mnt_passno = 3; + addmntent(tfilep, &tmntent); + endmntent(tfilep); +#else + struct mntent tmntent; + + memset(&tmntent, '\0', sizeof(struct mntent)); + tfilep = setmntent(MOUNTED_TABLE, "a+"); + if (!tfilep) { + printf("Can't open %s for write; Not adding afs entry to it\n", + MOUNTED_TABLE); + return 1; + } + tmntent.mnt_fsname = "AFS"; + tmntent.mnt_dir = cacheMountDir; + tmntent.mnt_type = "xx"; + tmntent.mnt_opts = "rw"; + tmntent.mnt_freq = 1; + tmntent.mnt_passno = 3; +#ifdef AFS_HPUX_ENV + tmntent.mnt_type = "afs"; + tmntent.mnt_time = time(0); + tmntent.mnt_cnode = 0; +#endif + addmntent(tfilep, &tmntent); + endmntent(tfilep); +#endif /* AFS_SGI_ENV */ +#endif /* AFS_SUN5_ENV */ +#endif /* unreasonable systems */ +#ifdef AFS_DARWIN_ENV +#ifndef AFS_DARWIN100_ENV + mach_port_t diskarb_port; + kern_return_t status; + + status = DiskArbStart(&diskarb_port); + if (status == KERN_SUCCESS) { + status = + DiskArbDiskAppearedWithMountpointPing_auto("AFS", + DISK_ARB_NETWORK_DISK_FLAG, + cacheMountDir); + } + + return status; +#endif +#endif /* AFS_DARWIN_ENV */ + return 0; +} + +void +afsd_mount_afs(const char *rn, const char *cacheMountDir) +{ + int mountFlags; /*Flags passed to mount() */ + char *mountDir; /* For HandleMTab() */ + + mountFlags = 0; /* Read/write file system, can do setuid() */ +#if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV) +#ifdef AFS_SUN5_ENV + mountFlags |= MS_DATA; +#else + mountFlags |= M_NEWTYPE; /* This searches by name in vfs_conf.c so don't need to recompile vfs.c because MOUNT_MAXTYPE has changed; it seems that Sun fixed this at last... */ +#endif +#endif + +#if defined(AFS_HPUX100_ENV) + mountFlags |= MS_DATA; +#endif + + if (afsd_verbose) + printf("%s: Mounting the AFS root on '%s', flags: %d.\n", rn, + cacheMountDir, mountFlags); +#if defined(AFS_FBSD60_ENV) + /* data must be non-NULL but is otherwise ignored */ + if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, rn)) < 0) { +#elif defined(AFS_FBSD_ENV) + if ((mount("AFS", cacheMountDir, mountFlags, (caddr_t) 0)) < 0) { +#elif defined(AFS_AIX_ENV) + if (aix_vmount()) { +#elif defined(AFS_HPUX100_ENV) + if ((mount("", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) { +#elif defined(AFS_SUN5_ENV) + if ((mount("AFS", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) { +#elif defined(AFS_SGI_ENV) + mountFlags = MS_FSS; + if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) MOUNT_AFS)) + < 0) { +#elif defined(AFS_LINUX20_ENV) + if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL)) < 0) { +#else + /* This is the standard mount used by the suns and rts */ + if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) { +#endif + printf("%s: Can't mount AFS on %s(%d)\n", rn, cacheMountDir, + errno); + exit(1); + } + + mountDir = strdup(cacheMountDir); + HandleMTab(mountDir); + free(mountDir); +} + +int +afsd_fork(int wait, afsd_callback_func cb, void *rock) +{ + int code; + code = fork(); + if (code == 0) { + (*cb) (rock); + exit(1); + } else { + assert(code > 0); + if (wait) { + assert(waitpid(code, NULL, 0) != -1); + } + } + return 0; +} + +int +afsd_daemon(int nochdir, int noclose) +{ + return daemon(nochdir, noclose); +} + +int +main(int argc, char **argv) +{ + int code; + + afsd_init(); + + code = afsd_parse(argc, argv); + if (code) { + return -1; + } + + return afsd_run(); +} -- 1.9.4