Use afsd code in libuafs
authorAndrew Deason <adeason@sinenomine.net>
Tue, 6 Apr 2010 22:07:33 +0000 (17:07 -0500)
committerDerrick Brashear <shadow@dementia.org>
Wed, 14 Apr 2010 22:04:51 +0000 (15:04 -0700)
Share the same CM code for the kernel client as in libuafs, so we
don't duplicate code for initializing the cache and other things. In
order to do this:

 - Remove some libuafs global variables that share name and
   functionality with those in afsd, and declare some static

 - Remove uafs_Init(), and move the ukernel-specific code in it to
   osi_Init(); replace with uafs_Setup(), uafs_ParseArgs(), and
   uafs_Run(), which just call into afsd functions

 - Remove libuafs' cache initialization code (CreateCacheFile,
   SweepAFSCache, etc); instead just use afsd's

 - Add uafs_mount(), to perform the 'mount'ing step that takes place
   in the normal kernel CM

 - Add afsd_uafs.c for the glue between afsd and libuafs

Note that this now requires libcmd for libuafs.

Change-Id: I62306a18ad255680031494caf1720b29e22856d2
Reviewed-on: http://gerrit.openafs.org/1724
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

Makefile.in
src/afs/UKERNEL/afs_usrops.c
src/afs/UKERNEL/afs_usrops.h
src/afs/UKERNEL/afsd_uafs.c [new file with mode: 0644]
src/afs/UKERNEL/sysincludes.h
src/afsd/afsd.c
src/config/stds.h
src/libuafs/Makefile.common.in
src/libuafs/linktest.c

index c1c9335..798dc48 100644 (file)
@@ -466,7 +466,7 @@ libuafs_setup: config export
 libuafs: libuafs_setup vlserver_depinstall tvlserver_depinstall rx_depinstall fsint_depinstall \
                auth_depinstall dir_depinstall libacl_depinstall rxkad_depinstall \
                ubik_depinstall afs_depinstall kauth_depinstall ptserver_depinstall \
-               rxstat_depinstall lwp_depinstall sys_depinstall des
+               rxstat_depinstall lwp_depinstall sys_depinstall des cmd
        +set -x; \
        case ${SYS_NAME} in \
        hp_ux102* | *_obsd* | sun*_4* | *_nbsd*| hp_ux11i | hp_ux112* | ia64_hpux112*) \
index 42ddd21..8bb3381 100644 (file)
@@ -30,6 +30,7 @@
 #include "afs/kautils.h"
 #include "afs/afsutil.h"
 #include "rx/rx_globals.h"
+#include "afsd/afsd.h"
 
 #define VFS 1
 #undef VIRTUE
@@ -57,79 +58,40 @@ extern int cacheDiskType;
 
 char afs_LclCellName[64];
 
-struct usr_vnode *afs_FileTable[MAX_OSI_FILES];
-int afs_FileFlags[MAX_OSI_FILES];
-off_t afs_FileOffsets[MAX_OSI_FILES];
+static struct usr_vnode *afs_FileTable[MAX_OSI_FILES];
+static int afs_FileFlags[MAX_OSI_FILES];
+static off_t afs_FileOffsets[MAX_OSI_FILES];
 
 #define MAX_CACHE_LOOPS 4
 
-struct usr_vfs afs_RootVfs;
-struct usr_vnode *afs_RootVnode = NULL;
-struct usr_vnode *afs_CurrentDir = NULL;
-
-afs_int32 cacheBlocks;         /* Num blocks in cache */
-afs_int32 cacheFiles = 1000;   /* Num files in workstation cache */
-afs_int32 cacheStatEntries = 300;      /* Num of stat cache entries */
-char cacheBaseDir[1024];       /* AFS cache directory */
-char confDir[1024];            /* AFS configuration directory */
-char afs_mountDir[1024];       /* AFS mount point */
-int afs_mountDirLen;           /* strlen of AFS mount point */
-char fullpn_DCacheFile[1024];  /* Full pathname of DCACHEFILE */
-char fullpn_VolInfoFile[1024]; /* Full pathname of VOLINFOFILE */
-char fullpn_CellInfoFile[1024];        /* Full pathname of CELLINFOFILE */
-char fullpn_AFSLogFile[1024];  /* Full pathname of AFSLOGFILE */
-char fullpn_CacheInfo[1024];   /* Full pathname of CACHEINFO */
-char fullpn_VFile[1024];       /* Full pathname of data cache files */
-char *vFileNumber;             /* Ptr to number in file pathname */
-char rootVolume[64] = "root.afs";      /* AFS root volume name */
-afs_int32 isHomeCell;          /* Is current cell info for home cell */
-int createAndTrunc = O_CREAT | O_TRUNC;        /* Create & truncate on open */
-int ownerRWmode = 0600;                /* Read/write OK by owner */
-static int nDaemons = 2;       /* Number of background daemons */
-static int chunkSize = 0;      /* 2^chunkSize bytes per chunk */
-static int dCacheSize = 300;   /* # of dcache entries */
-static int vCacheSize = 50;    /* # of volume cache entries */
-static int cacheFlags = 0;     /* Flags to cache manager */
-static int preallocs = 400;    /* Def # of allocated memory blocks */
-int afsd_verbose = 0;          /* Are we being chatty? */
-int afsd_debug = 0;            /* Are we printing debugging info? */
-int afsd_CloseSynch = 0;       /* Are closes synchronous or not? */
-
-#define AFSD_INO_T afs_uint32
-char **pathname_for_V;         /* Array of cache file pathnames */
-int missing_DCacheFile = 1;    /* Is the DCACHEFILE missing? */
-int missing_VolInfoFile = 1;   /* Is the VOLINFOFILE missing? */
-int missing_CellInfoFile = 1;
-struct afs_cacheParams cparams;        /* params passed to cache manager */
+static struct usr_vfs afs_RootVfs;
+static struct usr_vnode *afs_RootVnode = NULL;
+static struct usr_vnode *afs_CurrentDir = NULL;
+
+static char afs_mountDir[1024];        /* AFS mount point */
+static int afs_mountDirLen;            /* strlen of AFS mount point */
+
 struct afsconf_dir *afs_cdir;  /* config dir */
 
 int afs_bufferpages = 100;
-int usr_udpcksum = 0;
-
-usr_key_t afs_global_u_key;
 
-struct usr_proc *afs_global_procp = NULL;
-struct usr_ucred *afs_global_ucredp = NULL;
-struct usr_sysent usr_sysent[200];
+static usr_key_t afs_global_u_key;
 
-#ifdef AFS_USR_OSF_ENV
-char V = 'V';
-#else /* AFS_USR_OSF_ENV */
-long V = 'V';
-#endif /* AFS_USR_OSF_ENV */
+static struct usr_proc *afs_global_procp = NULL;
+static struct usr_ucred *afs_global_ucredp = NULL;
 
 struct usr_ucred afs_osi_cred, *afs_osi_credp;
 usr_mutex_t afs_global_lock;
 usr_thread_t afs_global_owner;
 usr_mutex_t rx_global_lock;
 usr_thread_t rx_global_owner;
-usr_mutex_t osi_dummy_lock;
-usr_mutex_t osi_waitq_lock;
-usr_mutex_t osi_authenticate_lock;
+
+static usr_mutex_t osi_dummy_lock;
+static usr_mutex_t osi_waitq_lock;
+static usr_mutex_t osi_authenticate_lock;
 afs_lock_t afs_ftf;
 afs_lock_t osi_flplock;
 afs_lock_t osi_fsplock;
-void *vnodefops;
 
 #ifndef NETSCAPE_NSAPI
 
@@ -163,17 +125,17 @@ typedef struct osi_wait {
 /*
  * Head of the linked list of available waitq structures.
  */
-osi_wait_t *osi_waithash_avail;
+static osi_wait_t *osi_waithash_avail;
 
 /*
  * List of timed waits, NSAPI does not provide a cond_timed
  * wait, so we need to keep track of the timed waits ourselves and
  * periodically check for expirations
  */
-osi_wait_t *osi_timedwait_head;
-osi_wait_t *osi_timedwait_tail;
+static osi_wait_t *osi_timedwait_head;
+static osi_wait_t *osi_timedwait_tail;
 
-struct {
+static struct {
     osi_wait_t *head;
     osi_wait_t *tail;
 } osi_waithash_table[OSI_WAITHASH_SIZE];
@@ -1055,409 +1017,7 @@ void
 osi_Init(void)
 {
     int i;
-
-#ifndef NETSCAPE_NSAPI
-    /*
-     * Initialize the mutex and condition variable used to implement
-     * time sleeps.
-     */
-    pthread_mutex_init(&usr_sleep_mutex, NULL);
-    pthread_cond_init(&usr_sleep_cond, NULL);
-#endif /* !NETSCAPE_NSAPI */
-
-    /*
-     * Initialize the hash table used for sleep/wakeup
-     */
-    for (i = 0; i < OSI_WAITHASH_SIZE; i++) {
-       DLL_INIT_LIST(osi_waithash_table[i].head, osi_waithash_table[i].tail);
-    }
-    DLL_INIT_LIST(osi_timedwait_head, osi_timedwait_tail);
-    osi_waithash_avail = NULL;
-
-    /*
-     * Initialize the AFS file table
-     */
-    for (i = 0; i < MAX_OSI_FILES; i++) {
-       afs_FileTable[i] = NULL;
-    }
-
-    /*
-     * Initialize the global locks
-     */
-    usr_mutex_init(&afs_global_lock);
-    usr_mutex_init(&rx_global_lock);
-    usr_mutex_init(&osi_dummy_lock);
-    usr_mutex_init(&osi_waitq_lock);
-    usr_mutex_init(&osi_authenticate_lock);
-
-    /*
-     * Initialize the AFS OSI credentials
-     */
-    afs_osi_cred = *afs_global_ucredp;
-    afs_osi_credp = &afs_osi_cred;
-}
-
-/* ParseArgs is now obsolete, being handled by cmd */
-
-/*---------------------------------------------------------------------
-  * GetVFileNumber
-  *
-  * Description:
-  *    Given the final component of a filename expected to be a data cache file,
-  *    return the integer corresponding to the file.  Note: we reject names that
-  *    are not a ``V'' followed by an integer.  We also reject those names having
-  *    the right format but lying outside the range [0..cacheFiles-1].
-  *
-  * Arguments:
-  *    fname : Char ptr to the filename to parse.
-  *
-  * Returns:
-  *    >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
-  *    -1      otherwise.
-  *
-  * Environment:
-  *    Nothing interesting.
-  *
-  * Side Effects:
-  *    None.
-  *------------------------------------------------------------------------*/
-
-int
-GetVFileNumber(char *fname)
-{
-    int computedVNumber;       /*The computed file number we return */
-    int filenameLen;           /*Number of chars in filename */
-    int currDigit;             /*Current digit being processed */
-
-    /*
-     * The filename must have at least two characters, the first of which must be a ``V''
-     * and the second of which cannot be a zero unless the file is exactly two chars long.
-     */
-    filenameLen = strlen(fname);
-    if (filenameLen < 2)
-       return (-1);
-    if (fname[0] != 'V')
-       return (-1);
-    if ((filenameLen > 2) && (fname[1] == '0'))
-       return (-1);
-
-    /*
-     * Scan through the characters in the given filename, failing immediately if a non-digit
-     * is found.
-     */
-    for (currDigit = 1; currDigit < filenameLen; currDigit++)
-       if (isdigit(fname[currDigit]) == 0)
-           return (-1);
-
-    /*
-     * All relevant characters are digits.  Pull out the decimal number they represent.
-     * Reject it if it's out of range, otherwise return it.
-     */
-    computedVNumber = atoi(++fname);
-    if (computedVNumber < cacheFiles)
-       return (computedVNumber);
-    else
-       return (-1);
-}
-
-/*---------------------------------------------------------------------
-  * CreateCacheFile
-  *
-  * Description:
-  *    Given a full pathname for a file we need to create for the workstation AFS
-  *    cache, go ahead and create the file.
-  *
-  * Arguments:
-  *    fname : Full pathname of file to create.
-  *
-  * Returns:
-  *    0   iff the file was created,
-  *    -1  otherwise.
-  *
-  * Environment:
-  *    The given cache file has been found to be missing.
-  *
-  * Side Effects:
-  *    As described.
-  *------------------------------------------------------------------------*/
-
-int
-CreateCacheFile(char *fname)
-{
-    static char rn[] = "CreateCacheFile";      /*Routine name */
-    int cfd;                   /*File descriptor to AFS cache file */
-    int closeResult;           /*Result of close() */
-
-    if (afsd_verbose)
-       printf("%s: Creating cache file '%s'\n", rn, fname);
-    cfd = open(fname, createAndTrunc, ownerRWmode);
-    if (cfd <= 0) {
-       printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
-              cfd, errno);
-       return (-1);
-    }
-    closeResult = close(cfd);
-    if (closeResult) {
-       printf
-           ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
-            rn, fname, errno);
-       return (-1);
-    }
-
-    return (0);
-}
-
-/*---------------------------------------------------------------------
-  * SweepAFSCache
-  *
-  * Description:
-  *    Sweep through the AFS cache directory, recording the inode number for
-  *    each valid data cache file there.  Also, delete any file that doesn't beint32
-  *    in the cache directory during this sweep, and remember which of the other
-  *    residents of this directory were seen.  After the sweep, we create any data
-  *    cache files that were missing.
-  *
-  * Arguments:
-  *    vFilesFound : Set to the number of data cache files found.
-  *
-  * Returns:
-  *    0   if everything went well,
-  *    -1 otherwise.
-  *
-  * Environment:
-  *    This routine may be called several times.  If the number of data cache files
-  *    found is less than the global cacheFiles, then the caller will need to call it
-  *    again to record the inodes of the missing zero-length data cache files created
-  *    in the previous call.
-  *
-  * Side Effects:
-  *    Fills up the global pathname_for_V array, may create and/or
-  *     delete files as explained above.
-  *------------------------------------------------------------------------*/
-
-int
-SweepAFSCache(int *vFilesFound)
-{
-    static char rn[] = "SweepAFSCache";        /*Routine name */
-    char fullpn_FileToDelete[1024];    /*File to be deleted from cache */
-    char *fileToDelete;                /*Ptr to last component of above */
-    DIR *cdirp;                        /*Ptr to cache directory structure */
-#undef dirent
-    struct dirent *currp;      /*Current directory entry */
-    int vFileNum;              /*Data cache file's associated number */
-
-    if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
-       if (afsd_debug)
-           printf("%s: Memory Cache, no cache sweep done\n", rn);
-       *vFilesFound = 0;
-       return 0;
-    }
-
-    if (afsd_debug)
-       printf("%s: Opening cache directory '%s'\n", rn, cacheBaseDir);
-
-    if (chmod(cacheBaseDir, 0700)) {   /* force it to be 700 */
-       printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
-              cacheBaseDir);
-       return (-1);
-    }
-    cdirp = opendir(cacheBaseDir);
-    if (cdirp == (DIR *) 0) {
-       printf("%s: Can't open AFS cache directory, '%s'.\n", rn,
-              cacheBaseDir);
-       return (-1);
-    }
-
-    /*
-     * Scan the directory entries, remembering data cache file inodes and the existance
-     * of other important residents.  Delete all files that don't belong here.
-     */
-    *vFilesFound = 0;
-    sprintf(fullpn_FileToDelete, "%s/", cacheBaseDir);
-    fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
-
-    for (currp = readdir(cdirp); currp; currp = readdir(cdirp)) {
-       if (afsd_debug) {
-           printf("%s: Current directory entry:\n", rn);
-#if defined(AFS_SGI62_ENV) || defined(AFS_USR_DARWIN100_ENV)
-            printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n",
-                  currp->d_ino, currp->d_reclen, currp->d_name);
-#elif defined(AFS_USR_DFBSD_ENV)
-           printf("\tinode=%d, name='%s'\n", currp->d_ino,
-                  currp->d_name);
-#else
-           printf("\tinode=%d, reclen=%d, name='%s'\n", (int)currp->d_ino,
-                  currp->d_reclen, currp->d_name);
-#endif
-       }
-
-       /*
-        * Guess current entry is for a data cache file.
-        */
-       vFileNum = GetVFileNumber(currp->d_name);
-       if (vFileNum >= 0) {
-           /*
-            * Found a valid data cache filename.  Remember this file's name
-            * and bump the number of files found.
-            */
-           pathname_for_V[vFileNum] =
-               afs_osi_Alloc(strlen(currp->d_name) + strlen(cacheBaseDir) +
-                             2);
-           usr_assert(pathname_for_V[vFileNum] != NULL);
-           sprintf(pathname_for_V[vFileNum], "%s/%s", cacheBaseDir,
-                   currp->d_name);
-           (*vFilesFound)++;
-       } else if (strcmp(currp->d_name, DCACHEFILE) == 0) {
-           /*
-            * Found the file holding the dcache entries.
-            */
-           missing_DCacheFile = 0;
-       } else if (strcmp(currp->d_name, VOLINFOFILE) == 0) {
-           /*
-            * Found the file holding the volume info.
-            */
-           missing_VolInfoFile = 0;
-       } else if (strcmp(currp->d_name, CELLINFOFILE) == 0) {
-           missing_CellInfoFile = 0;
-       } else if ((strcmp(currp->d_name, ".") == 0)
-                  || (strcmp(currp->d_name, "..") == 0)
-                  || (strcmp(currp->d_name, "lost+found") == 0)) {
-           /*
-            * Don't do anything - this file is legit, and is to be left alone.
-            */
-       } else {
-           /*
-            * This file doesn't belong in the cache.  Nuke it.
-            */
-           sprintf(fileToDelete, "%s", currp->d_name);
-           if (afsd_verbose)
-               printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
-           if (unlink(fullpn_FileToDelete)) {
-               printf("%s: Can't unlink '%s', errno is %d\n", rn,
-                      fullpn_FileToDelete, errno);
-           }
-       }
-    }
-
-    /*
-     * Create all the cache files that are missing.
-     */
-    if (missing_DCacheFile) {
-       if (afsd_verbose)
-           printf("%s: Creating '%s'\n", rn, fullpn_DCacheFile);
-       if (CreateCacheFile(fullpn_DCacheFile))
-           printf("%s: Can't create '%s'\n", rn, fullpn_DCacheFile);
-    }
-    if (missing_VolInfoFile) {
-       if (afsd_verbose)
-           printf("%s: Creating '%s'\n", rn, fullpn_VolInfoFile);
-       if (CreateCacheFile(fullpn_VolInfoFile))
-           printf("%s: Can't create '%s'\n", rn, fullpn_VolInfoFile);
-    }
-    if (missing_CellInfoFile) {
-       if (afsd_verbose)
-           printf("%s: Creating '%s'\n", rn, fullpn_CellInfoFile);
-       if (CreateCacheFile(fullpn_CellInfoFile))
-           printf("%s: Can't create '%s'\n", rn, fullpn_CellInfoFile);
-    }
-
-    if (*vFilesFound < cacheFiles) {
-       /*
-        * We came up short on the number of data cache files found.  Scan through the inode
-        * list and create all missing files.
-        */
-       for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++)
-           if (pathname_for_V[vFileNum] == (AFSD_INO_T) 0) {
-               sprintf(vFileNumber, "%d", vFileNum);
-               if (afsd_verbose)
-                   printf("%s: Creating '%s'\n", rn, fullpn_VFile);
-               if (CreateCacheFile(fullpn_VFile))
-                   printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
-           }
-    }
-
-    /*
-     * Close the directory, return success.
-     */
-    if (afsd_debug)
-       printf("%s: Closing cache directory.\n", rn);
-    closedir(cdirp);
-    return (0);
-}
-
-static int
-ConfigCell(register struct afsconf_cell *aci, void *arock,
-          struct afsconf_dir *adir)
-{
-    register int isHomeCell;
-    register int i;
-    afs_int32 cellFlags = 0;
-    afs_int32 hosts[MAXHOSTSPERCELL];
-
-    /* figure out if this is the home cell */
-    isHomeCell = (strcmp(aci->name, afs_LclCellName) == 0);
-    if (!isHomeCell)
-       cellFlags = 2;          /* not home, suid is forbidden */
-
-    /* build address list */
-    for (i = 0; i < MAXHOSTSPERCELL; i++)
-       memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
-
-    if (aci->linkedCell)
-       cellFlags |= 4;         /* Flag that linkedCell arg exists,
-                                * for upwards compatibility */
-
-    /* configure one cell */
-    call_syscall(AFSCALL_CALL, AFSOP_ADDCELL2, (long)hosts,    /* server addresses */
-                (long)aci->name,       /* cell name */
-                (long)cellFlags,       /* is this the home cell? */
-                (long)aci->linkedCell);        /* Linked cell, if any */
-    return 0;
-}
-
-static int
-ConfigCellAlias(struct afsconf_cellalias *aca, void *arock, struct afsconf_dir *adir)
-{
-       call_syscall(AFSOP_ADDCELLALIAS, (long)aca->aliasName, 
-                    (long)aca->realName, 0, 0, 0);
-       return 0;
-}
-
-/*
- * Set the UDP port number RX uses for UDP datagrams
- */
-void
-uafs_SetRxPort(int port)
-{
-    usr_assert(usr_rx_port == 0);
-    usr_rx_port = port;
-}
-
-
-/*
- * Initialize the user space client.
- */
-void
-uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
-         char *cacheBaseDirParam, int cacheBlocksParam, int cacheFilesParam,
-         int cacheStatEntriesParam, int dCacheSizeParam, int vCacheSizeParam,
-         int chunkSizeParam, int closeSynchParam, int debugParam,
-         int nDaemonsParam, int cacheFlagsParam, char *logFile)
-{
     int st;
-    int i;
-    int rc;
-    int currVFile;             /* Current AFS cache file number */
-    int lookupResult;          /* Result of GetLocalCellName() */
-    int cacheIteration;                /* cache verification loop counter */
-    int vFilesFound;           /* Num data cache files found in sweep */
-    FILE *logfd;
-    char tbuffer[1024];
-    char *p;
-    char lastchar;
-    afs_int32 buffer[MAXIPADDRS];
-    afs_int32 maskbuffer[MAXIPADDRS];
-    afs_int32 mtubuffer[MAXIPADDRS];
 
     /*
      * Use the thread specific data to implement the user structure
@@ -1494,384 +1054,62 @@ uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
     afs_global_procp->p_ppid = (pid_t) 1;
     afs_global_procp->p_ucred = afs_global_ucredp;
 
+#ifndef NETSCAPE_NSAPI
     /*
-     * Initialize the AFS mount point, default is '/afs'.
-     * Strip duplicate/trailing slashes from mount point string.
-     * afs_mountDirLen is set to strlen(afs_mountDir).
-     */
-    if (mountDirParam) {
-       sprintf(tbuffer, "%s", mountDirParam);
-    } else {
-       sprintf(tbuffer, "afs");
-    }
-    afs_mountDir[0] = '/';
-    afs_mountDirLen = 1;
-    for (lastchar = '/', p = &tbuffer[0]; *p != '\0'; p++) {
-       if (lastchar != '/' || *p != '/') {
-           afs_mountDir[afs_mountDirLen++] = lastchar = *p;
-       }
-    }
-    if (lastchar == '/' && afs_mountDirLen > 1)
-       afs_mountDirLen--;
-    afs_mountDir[afs_mountDirLen] = '\0';
-    usr_assert(afs_mountDirLen > 1);
-
-    /*
-     * Initialize cache parameters using the input arguments
-     */
-
-    cacheBlocks = cacheBlocksParam;
-    if (cacheFilesParam != 0) {
-       cacheFiles = cacheFilesParam;
-    } else {
-       cacheFiles = cacheBlocks / 10;
-    }
-    if (cacheStatEntriesParam != 0) {
-       cacheStatEntries = cacheStatEntriesParam;
-    }
-    strcpy(cacheBaseDir, cacheBaseDirParam);
-    if (nDaemonsParam != 0) {
-       nDaemons = nDaemonsParam;
-    } else {
-       nDaemons = 3;
-    }
-    afsd_verbose = debugParam;
-    afsd_debug = debugParam;
-    chunkSize = chunkSizeParam;
-    if (dCacheSizeParam != 0) {
-       dCacheSize = dCacheSizeParam;
-    } else {
-       dCacheSize = cacheFiles / 2;
-    }
-    if (vCacheSizeParam != 0) {
-       vCacheSize = vCacheSizeParam;
-    }
-    strcpy(confDir, confDirParam);
-    afsd_CloseSynch = closeSynchParam;
-    if (cacheFlagsParam >= 0) {
-       cacheFlags = cacheFlagsParam;
-    }
-    if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
-       cacheFiles = dCacheSize;
-    }
-
-    sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
-    if (logFile == NULL) {
-       sprintf(fullpn_AFSLogFile, "%s/%s", confDir, AFSLOGFILE);
-    } else {
-       strcpy(fullpn_AFSLogFile, logFile);
-    }
-
-    printf("\n%s: Initializing user space AFS client\n\n", rn);
-    printf("    mountDir:           %s\n", afs_mountDir);
-    printf("    confDir:            %s\n", confDir);
-    printf("    cacheBaseDir:       %s\n", cacheBaseDir);
-    printf("    cacheBlocks:        %d\n", cacheBlocks);
-    printf("    cacheFiles:         %d\n", cacheFiles);
-    printf("    cacheStatEntries:   %d\n", cacheStatEntries);
-    printf("    dCacheSize:         %d\n", dCacheSize);
-    printf("    vCacheSize:         %d\n", vCacheSize);
-    printf("    chunkSize:          %d\n", chunkSize);
-    printf("    afsd_CloseSynch:    %d\n", afsd_CloseSynch);
-    printf("    afsd_debug/verbose: %d/%d\n", afsd_debug, afsd_verbose);
-    printf("    nDaemons:           %d\n", nDaemons);
-    printf("    cacheFlags:         %d\n", cacheFlags);
-    printf("    logFile:            %s\n", fullpn_AFSLogFile);
-    printf("\n");
-    fflush(stdout);
-
-    /*
-     * Initialize the AFS client
-     */
-    osi_Init();
-
-    /*
-     * Pull out all the configuration info for the workstation's AFS cache and
-     * the cellular community we're willing to let our users see.
-     */
-    afs_cdir = afsconf_Open(confDir);
-    if (!afs_cdir) {
-       printf("afsd: some file missing or bad in %s\n", confDir);
-       exit(1);
-    }
-
-    lookupResult =
-       afsconf_GetLocalCell(afs_cdir, afs_LclCellName,
-                            sizeof(afs_LclCellName));
-    if (lookupResult) {
-       printf("%s: Can't get my home cell name!  [Error is %d]\n", rn,
-              lookupResult);
-    } else {
-       if (afsd_verbose)
-           printf("%s: My home cell is '%s'\n", rn, afs_LclCellName);
-    }
-
-    if ((logfd = fopen(fullpn_AFSLogFile, "r+")) == 0) {
-       if (afsd_verbose)
-           printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile);
-       if (CreateCacheFile(fullpn_AFSLogFile)) {
-           printf
-               ("%s: Can't create '%s' (You may want to use the -logfile option)\n",
-                rn, fullpn_AFSLogFile);
-           exit(1);
-       }
-    } else
-       fclose(logfd);
-
-    /*
-     * Create and zero the pathname table for the desired cache files.
+     * Initialize the mutex and condition variable used to implement
+     * time sleeps.
      */
-    pathname_for_V = (char **)afs_osi_Alloc(cacheFiles * sizeof(char *));
-    if (pathname_for_V == NULL) {
-       printf("%s: malloc() failed for cache file table with %d entries.\n",
-              rn, cacheFiles);
-       exit(1);
-    }
-    memset(pathname_for_V, 0, (cacheFiles * sizeof(char *)));
-    if (afsd_debug)
-       printf("%s: %d pathname_for_V entries at %" AFS_PTR_FMT
-              ", %lud bytes\n", rn, cacheFiles, pathname_for_V,
-              afs_printable_uint32_lu(cacheFiles * sizeof(AFSD_INO_T)));
+    pthread_mutex_init(&usr_sleep_mutex, NULL);
+    pthread_cond_init(&usr_sleep_cond, NULL);
+#endif /* !NETSCAPE_NSAPI */
 
     /*
-     * Set up all the pathnames we'll need for later.
+     * Initialize the hash table used for sleep/wakeup
      */
-    sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
-    sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
-    sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
-    sprintf(fullpn_VFile, "%s/V", cacheBaseDir);
-    vFileNumber = fullpn_VFile + strlen(fullpn_VFile);
-
-    /* initialize AFS callback interface */
-    {
-       /* parse multihomed address files */
-       char reason[1024];
-       st = parseNetFiles((afs_uint32*)buffer,(afs_uint32*) maskbuffer, (afs_uint32*)mtubuffer, MAXIPADDRS, reason,
-                          AFSDIR_CLIENT_NETINFO_FILEPATH,
-                          AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
-       if (st > 0)
-           call_syscall(AFSCALL_CALL, AFSOP_ADVISEADDR, st,
-                        (long)(&buffer[0]), (long)(&maskbuffer[0]),
-                        (long)(&mtubuffer[0]));
-       else {
-           printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
-                  reason);
-           exit(1);
-       }
+    for (i = 0; i < OSI_WAITHASH_SIZE; i++) {
+       DLL_INIT_LIST(osi_waithash_table[i].head, osi_waithash_table[i].tail);
     }
+    DLL_INIT_LIST(osi_timedwait_head, osi_timedwait_tail);
+    osi_waithash_avail = NULL;
 
     /*
-     * Start the RX listener.
-     */
-    if (afsd_debug)
-       printf("%s: Calling AFSOP_RXLISTENER_DAEMON\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_RXLISTENER_DAEMON, FALSE, FALSE, FALSE, 0);
-
-    if (afsd_verbose)
-       printf("%s: Forking rx callback listener.\n", rn);
-    /* Child */
-    if (preallocs < cacheStatEntries + 50)
-       preallocs = cacheStatEntries + 50;
-    fork_syscall(AFSCALL_CALL, AFSOP_START_RXCALLBACK, preallocs, 0, 0, 0);
-
-    /*
-     * Start the RX event handler.
-     */
-    if (afsd_debug)
-       printf("%s: Calling AFSOP_RXEVENT_DAEMON\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_RXEVENT_DAEMON, FALSE, 0, 0, 0);
-
-    /*
-     * Set up all the kernel processes needed for AFS.
-     */
-
-    if (afsd_verbose)
-       printf("%s: Initializing AFS daemon.\n", rn);
-    call_syscall(AFSCALL_CALL, AFSOP_BASIC_INIT, 1, 0, 0, 0);
-
-    /*
-     * Tell the kernel some basic information about the workstation's cache.
-     */
-    if (afsd_verbose)
-       printf("%s: Calling AFSOP_CACHEINIT: %d stat cache entries,"
-              " %d optimum cache files, %d blocks in the cache,"
-              " flags = 0x%x, dcache entries %d\n", rn, cacheStatEntries,
-              cacheFiles, cacheBlocks, cacheFlags, dCacheSize);
-    memset(&cparams, 0, sizeof(cparams));
-    cparams.cacheScaches = cacheStatEntries;
-    cparams.cacheFiles = cacheFiles;
-    cparams.cacheBlocks = cacheBlocks;
-    cparams.cacheDcaches = dCacheSize;
-    cparams.cacheVolumes = vCacheSize;
-    cparams.chunkSize = chunkSize;
-    cparams.setTimeFlag = FALSE;
-    cparams.memCacheFlag = cacheFlags;
-    call_syscall(AFSCALL_CALL, AFSOP_CACHEINIT, (long)&cparams, 0, 0, 0);
-    if (afsd_CloseSynch)
-       call_syscall(AFSCALL_CALL, AFSOP_CLOSEWAIT, 0, 0, 0, 0);
-
-    /*
-     * Sweep the workstation AFS cache directory, remembering the inodes of
-     * valid files and deleting extraneous files.  Keep sweeping until we
-     * have the right number of data cache files or we've swept too many
-     * times.
-     */
-    if (afsd_verbose)
-       printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
-    cacheIteration = 0;
-    /* Memory-cache based system doesn't need any of this */
-    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
-       do {
-           cacheIteration++;
-           if (SweepAFSCache(&vFilesFound)) {
-               printf("%s: Error on sweep %d of workstation AFS cache \
-                      directory.\n", rn, cacheIteration);
-               exit(1);
-           }
-           if (afsd_verbose)
-               printf
-                   ("%s: %d out of %d data cache files found in sweep %d.\n",
-                    rn, vFilesFound, cacheFiles, cacheIteration);
-       } while ((vFilesFound < cacheFiles)
-                && (cacheIteration < MAX_CACHE_LOOPS));
-    } else if (afsd_verbose)
-       printf("%s: Using memory cache, not swept\n", rn);
-
-    /*
-     * Pass the kernel the name of the workstation cache file holding the 
-     * dcache entries.
-     */
-    if (afsd_debug)
-       printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
-              fullpn_DCacheFile);
-    /* once again, meaningless for a memory-based cache. */
-    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
-       call_syscall(AFSCALL_CALL, AFSOP_CACHEINFO, (long)fullpn_DCacheFile,
-                    0, 0, 0);
-
-    call_syscall(AFSCALL_CALL, AFSOP_CELLINFO, (long)fullpn_CellInfoFile, 0,
-                0, 0);
-
-    /*
-     * Pass the kernel the name of the workstation cache file holding the
-     * volume information.
-     */
-    if (afsd_debug)
-       printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
-              fullpn_VolInfoFile);
-    call_syscall(AFSCALL_CALL, AFSOP_VOLUMEINFO, (long)fullpn_VolInfoFile, 0,
-                0, 0);
-
-    /*
-     * Pass the kernel the name of the afs logging file holding the volume
-     * information.
-     */
-    if (afsd_debug)
-       printf("%s: Calling AFSOP_AFSLOG: volume info file is '%s'\n", rn,
-              fullpn_AFSLogFile);
-    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... nor this ... */
-       call_syscall(AFSCALL_CALL, AFSOP_AFSLOG, (long)fullpn_AFSLogFile, 0,
-                    0, 0);
-
-    /*
-     * Tell the kernel about each cell in the configuration.
-     */
-    afsconf_CellApply(afs_cdir, ConfigCell, NULL);
-    afsconf_CellAliasApply(afs_cdir, ConfigCellAlias, NULL);
-
-    /*
-     * Set the primary cell name.
+     * Initialize the AFS file table
      */
-    call_syscall(AFSCALL_CALL, AFSOP_SET_THISCELL, (long)afs_LclCellName, 0, 0, 0);
-
-    if (afsd_verbose)
-       printf("%s: Forking AFS daemon.\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_START_AFS, 0, 0, 0, 0);
-
-    if (afsd_verbose)
-       printf("%s: Forking check server daemon.\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_START_CS, 0, 0, 0, 0);
-
-    if (afsd_verbose)
-       printf("%s: Forking %d background daemons.\n", rn, nDaemons);
-    for (i = 0; i < nDaemons; i++) {
-       fork_syscall(AFSCALL_CALL, AFSOP_START_BKG, 0, 0, 0, 0);
+    for (i = 0; i < MAX_OSI_FILES; i++) {
+       afs_FileTable[i] = NULL;
     }
 
-    if (afsd_verbose)
-       printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn, rootVolume);
-    call_syscall(AFSCALL_CALL, AFSOP_ROOTVOLUME, (long)rootVolume, 0, 0, 0);
-
     /*
-     * Give the kernel the names of the AFS files cached on the workstation's
-     * disk.
+     * Initialize the global locks
      */
-    if (afsd_debug)
-       printf
-           ("%s: Calling AFSOP_CACHEFILES for each of the %d files in '%s'\n",
-            rn, cacheFiles, cacheBaseDir);
-    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
-       for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
-           call_syscall(AFSCALL_CALL, AFSOP_CACHEFILE,
-                        (long)pathname_for_V[currVFile], 0, 0, 0);
-       }
-    /*end for */
-/*#ifndef NETSCAPE_NSAPI*/
-#if 0
-/* this breaks solaris if the kernel-mode client has never been installed,
- * and it doesn't seem to work now anyway, so just disable it */
+    usr_mutex_init(&afs_global_lock);
+    usr_mutex_init(&rx_global_lock);
+    usr_mutex_init(&osi_dummy_lock);
+    usr_mutex_init(&osi_waitq_lock);
+    usr_mutex_init(&osi_authenticate_lock);
 
     /*
-     * Copy our tokens from the kernel to the user space client
+     * Initialize the AFS OSI credentials
      */
-    for (i = 0; i < 200; i++) {
-       /*
-        * Get the i'th token from the kernel
-        */
-       memset((void *)&tbuffer[0], 0, sizeof(tbuffer));
-       memcpy((void *)&tbuffer[0], (void *)&i, sizeof(int));
-       iob.in = tbuffer;
-       iob.in_size = sizeof(int);
-       iob.out = tbuffer;
-       iob.out_size = sizeof(tbuffer);
-
-#if defined(AFS_USR_SUN5_ENV) || defined(AFS_USR_OSF_ENV) || defined(AFS_USR_HPUX_ENV) || defined(AFS_USR_LINUX22_ENV) || defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV)
-       rc = syscall(AFS_SYSCALL, AFSCALL_PIOCTL, 0, _VICEIOCTL(8), &iob, 0);
-#elif defined(AFS_USR_SGI_ENV)
-       rc = syscall(AFS_PIOCTL, 0, _VICEIOCTL(8), &iob, 0);
-#else /* AFS_USR_AIX_ENV */
-       rc = lpioctl(0, _VICEIOCTL(8), &iob, 0);
-#endif
-       if (rc < 0) {
-           usr_assert(errno == EDOM || errno == ENOSYS || errno == ERANGE);
-           break;
-       }
-
-       /*
-        * Now pass the token into the user space kernel
-        */
-       rc = uafs_SetTokens(tbuffer, iob.out_size);
-       usr_assert(rc == 0);
-    }
-#endif /* !NETSCAPE_NSAPI */
+    afs_osi_cred = *afs_global_ucredp;
+    afs_osi_credp = &afs_osi_cred;
 
-    /*
-     * All the necessary info has been passed into the kernel to run an AFS
-     * system.  Give the kernel our go-ahead.
-     */
-    if (afsd_debug)
-       printf("%s: Calling AFSOP_GO\n", rn);
-    call_syscall(AFSCALL_CALL, AFSOP_GO, FALSE, 0, 0, 0);
+    init_et_to_sys_error();
+}
 
-    /*
-     * At this point, we have finished passing the kernel all the info 
-     * it needs to set up the AFS.  Mount the AFS root.
-     */
-    printf("%s: All AFS daemons started.\n", rn);
+/*
+ * Set the UDP port number RX uses for UDP datagrams
+ */
+void
+uafs_SetRxPort(int port)
+{
+    usr_assert(usr_rx_port == 0);
+    usr_rx_port = port;
+}
 
-    if (afsd_verbose)
-       printf("%s: Forking trunc-cache daemon.\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_START_TRUNCDAEMON, 0, 0, 0, 0);
+void
+uafs_mount(void) {
+    int rc;
 
     /*
      * Mount the AFS filesystem
@@ -2049,6 +1287,74 @@ call_syscall(long syscall, long afscall, long param1, long param2,
 }
 
 int
+uafs_Setup(const char *mount)
+{
+    char buf[1024];
+    char lastchar;
+    char *p;
+    static int inited = 0;
+
+    if (inited) {
+       return EEXIST;
+    }
+    inited = 1;
+
+    if (mount && strlen(mount) > 1023) {
+       return ENAMETOOLONG;
+    }
+
+    /*
+     * Initialize the AFS mount point, default is '/afs'.
+     * Strip duplicate/trailing slashes from mount point string.
+     * afs_mountDirLen is set to strlen(afs_mountDir).
+     */
+    if (!mount) {
+       mount = "afs";
+    }
+    sprintf(buf, "%s", mount);
+
+    afs_mountDir[0] = '/';
+    afs_mountDirLen = 1;
+    for (lastchar = '/', p = &buf[0]; *p != '\0'; p++) {
+        if (lastchar != '/' || *p != '/') {
+            afs_mountDir[afs_mountDirLen++] = lastchar = *p;
+        }
+    }
+    if (lastchar == '/' && afs_mountDirLen > 1)
+        afs_mountDirLen--;
+    afs_mountDir[afs_mountDirLen] = '\0';
+    if (afs_mountDirLen <= 1) {
+       return EINVAL;
+    }
+
+    /* initialize global vars and such */
+    osi_Init();
+
+    /* initialize cache manager foo */
+    afsd_init();
+
+    return 0;
+}
+
+int
+uafs_ParseArgs(int argc, char **argv)
+{
+    return afsd_parse(argc, argv);
+}
+
+int
+uafs_Run(void)
+{
+    return afsd_run();
+}
+
+const char *
+uafs_MountDir(void)
+{
+    return afsd_cacheMountDir;
+}
+
+int
 uafs_SetTokens(char *tbuffer, int tlen)
 {
     int rc;
index 8a0bec6..c3c8c20 100644 (file)
 #ifndef __AFS_USROPS_H__
 #define __AFS_USROPS_H__ 1
 
-#if !defined(UKERNEL)
-#include <afs/sysincludes.h>
-#endif /* !defined(UKERNEL) */
+#ifdef KERNEL
+# include "afs/sysincludes.h"
+# include "afsincludes.h"
+#endif /* KERNEL */
 
 /*
  * Macros to manipulate doubly linked lists
     _ELEM->_PREV = NULL; \
 }
 
+extern char *uafs_mountDir;
+
 extern struct afsconf_dir *afs_cdir;
 extern char afs_LclCellName[64];
 
 extern int afs_osicred_Initialized;
 
-extern struct usr_vnode *afs_RootVnode;
-
-extern struct usr_vnode *afs_CurrentDir;
-extern struct usr_vnode *afs_FileTable[];
-extern int afs_FileFlags[];
-extern off_t afs_FileOffsets[];
-
-extern char afs_mountDir[];
-extern int afs_mountDirLen;
-
 extern void uafs_InitClient(void);
 extern void uafs_InitThread(void);
-extern void uafs_Init(char *, char *, char *, char *, int, int, int, int, int,
-                     int, int, int, int, int, char *);
+extern int uafs_Setup(const char *mount);
+extern int uafs_ParseArgs(int argc, char **argv);
+extern int uafs_Run(void);
+extern const char* uafs_MountDir(void);
 extern void uafs_RxServerProc(void);
 extern int uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentP,
                           struct usr_vnode **vpp);
@@ -153,5 +148,6 @@ extern int uafs_IsRoot(char *path);
 extern int uafs_statmountpoint_r(char *path);
 extern int uafs_statvfs(struct statvfs *buf);
 extern void uafs_Shutdown(void);
+extern void uafs_mount(void);
 
 #endif /* __AFS_USROPS_H__ */
diff --git a/src/afs/UKERNEL/afsd_uafs.c b/src/afs/UKERNEL/afsd_uafs.c
new file mode 100644 (file)
index 0000000..06c61df
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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
+ */
+
+/*
+ * User space client glue for the afsd cache manager interface
+ */
+
+#include <afsconfig.h>
+#include <afs/param.h>
+
+#ifdef UKERNEL
+
+#include "afs/sysincludes.h"
+#include "afsincludes.h"
+#include "afs_usrops.h"
+#include "afs/afsutil.h"
+#include "afs/afs_args.h"
+#include "afsd/afsd.h"
+
+extern int call_syscall(long, long, long, long, long, long);
+
+void
+afsd_mount_afs(const char *rn, const char *mountdir)
+{
+    uafs_mount();
+}
+
+void
+afsd_set_rx_rtpri(void)
+{
+    /* noop */
+}
+void
+afsd_set_afsd_rtpri(void)
+{
+    /* noop */
+}
+
+int
+afsd_call_syscall(long param1, long param2, long param3, long param4,
+                  long param5)
+{
+    return call_syscall(AFSCALL_CALL, param1, param2, param3, param4, param5);
+}
+
+int
+afsd_fork(int wait, afsd_callback_func cbf, void *rock)
+{
+    int code;
+    usr_thread_t tid;
+    usr_thread_create(&tid, cbf, rock);
+    if (wait) {
+       code = usr_thread_join(tid, NULL);
+    } else {
+       code = usr_thread_detach(tid);
+    }
+    return code;
+}
+
+int
+afsd_daemon(int nochdir, int noclose)
+{
+    /* noop */
+    return 0;
+}
+
+#endif /* UKERNEL */
index f9f8e78..07f4895 100644 (file)
@@ -1152,7 +1152,6 @@ extern struct usr_ucred *usr_crget(void);
 extern struct usr_ucred *usr_crcopy(struct usr_ucred *);
 extern int usr_crhold(struct usr_ucred *);
 extern int usr_crfree(struct usr_ucred *);
-extern struct usr_ucred *afs_global_ucredp;
 
 struct usr_proc {
     unsigned long p_flag;
@@ -1291,12 +1290,6 @@ struct usr_vfs {
     struct usr_vfsops *vfs_op;
 };
 
-struct usr_sysent {
-    char sy_narg;
-    int (*sy_call) (void);
-};
-extern struct usr_sysent usr_sysent[];
-
 struct usr_ifnet {
     struct usr_ifnet *if_next;
     short if_flags;
@@ -1331,14 +1324,6 @@ struct usr_in_ifaddr {
 };
 extern struct usr_in_ifaddr *usr_in_ifaddr;
 
-extern usr_key_t afs_global_u_key;     /* for per thread authentication */
-
-#if defined(AFS_USR_OSF_ENV)
-extern char V;
-#else
-extern long V;
-#endif
-
 #endif /* UKERNEL */
 
 struct min_direct {
index 96999f0..f794ad0 100644 (file)
@@ -62,6 +62,8 @@
 
 #define VFS 1
 
+#include <afs/stds.h>
+
 #include <afs/cmd.h>
 
 #include "afsd.h"
 #include <sys/file.h>
 #include <errno.h>
 #include <sys/time.h>
-#include <dirent.h>
 #include <sys/wait.h>
 
+/* darwin dirent.h doesn't give us the prototypes we want if KERNEL is
+ * defined */
+#if defined(UKERNEL) && defined(AFS_USR_DARWIN_ENV)
+# undef KERNEL
+# include <dirent.h>
+# define KERNEL
+#else
+# include <dirent.h>
+#endif
+
 
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
@@ -182,13 +193,13 @@ static int event_pid;
 
 #endif /* AFS_DARWIN_ENV */
 
-#if AFS_HAVE_STATVFS
+#if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
 #include <sys/statvfs.h>
 #else
 #if defined(AFS_SUN_ENV)
 #include <sys/vfs.h>
 #else
-#if !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
+#ifdef HAVE_SYS_STATFS_H
 #include <sys/statfs.h>
 #endif
 #endif
@@ -240,37 +251,38 @@ struct in_addr_42 {
 /*
  * Global configuration variables.
  */
-afs_int32 enable_rxbind = 0;
-afs_int32 afs_shutdown = 0;
-afs_int32 cacheBlocks;         /*Num blocks in the cache */
-afs_int32 cacheFiles;          /*Optimal # of files in workstation cache */
-afs_int32 rwpct = 0;
-afs_int32 ropct = 0;
-afs_int32 cacheStatEntries;    /*Number of stat cache entries */
-char cacheBaseDir[1024];       /*Where the workstation AFS cache lives */
-char confDir[1024];            /*Where the workstation AFS configuration lives */
-char fullpn_DCacheFile[1024];  /*Full pathname of DCACHEFILE */
-char fullpn_VolInfoFile[1024]; /*Full pathname of VOLINFOFILE */
-char fullpn_CellInfoFile[1024];        /*Full pathanem of CELLINFOFILE */
-char fullpn_CacheInfo[1024];   /*Full pathname of CACHEINFO */
-char fullpn_VFile[1024];       /*Full pathname of data cache files */
-char *vFilePtr;                        /*Ptr to the number part of above pathname */
-int sawCacheMountDir = 0;      /* from cmd line */
-int sawCacheBaseDir = 0;
-int sawCacheBlocks = 0;
-int sawDCacheSize = 0;
-int sawBiod = 0;
-int sawCacheStatEntries = 0;
+static afs_int32 enable_rxbind = 0;
+static afs_int32 afs_shutdown = 0;
+static afs_int32 cacheBlocks;          /*Num blocks in the cache */
+static afs_int32 cacheFiles;           /*Optimal # of files in workstation cache */
+static afs_int32 rwpct = 0;
+static afs_int32 ropct = 0;
+static afs_int32 cacheStatEntries;     /*Number of stat cache entries */
+static char cacheBaseDir[1024];        /*Where the workstation AFS cache lives */
+static char confDir[1024];             /*Where the workstation AFS configuration lives */
+static char fullpn_DCacheFile[1024];   /*Full pathname of DCACHEFILE */
+static char fullpn_VolInfoFile[1024];  /*Full pathname of VOLINFOFILE */
+static char fullpn_CellInfoFile[1024]; /*Full pathanem of CELLINFOFILE */
+static char fullpn_CacheInfo[1024];    /*Full pathname of CACHEINFO */
+static char fullpn_VFile[1024];        /*Full pathname of data cache files */
+static char *vFilePtr;                 /*Ptr to the number part of above pathname */
+static int sawCacheMountDir = 0;       /* from cmd line */
+static int sawCacheBaseDir = 0;
+static int sawCacheBlocks = 0;
+static int sawDCacheSize = 0;
+#ifdef AFS_AIX32_ENV
+static int sawBiod = 0;
+#endif
+static int sawCacheStatEntries = 0;
 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? */
+static char rootVolume[64] = "root.afs";       /*AFS root volume name */
+static afs_int32 cacheSetTime = FALSE; /*Keep checking time to avoid drift? */
 #ifdef AFS_XBSD_ENV
-int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC;       /*Create & truncate on open */
+static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC;        /*Create & truncate on open */
 #else
-int createAndTrunc = O_CREAT | O_TRUNC;        /*Create & truncate on open */
+static int createAndTrunc = O_CREAT | O_TRUNC; /*Create & truncate on open */
 #endif
-int ownerRWmode = 0600;                /*Read/write OK by owner */
+static 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 */
 #if defined(AFS_CACHE_BYPASS)
@@ -297,11 +309,11 @@ static int enable_fakestat = 0;   /* enable fakestat support */
 static int enable_backuptree = 0;      /* enable backup tree support */
 static int enable_nomount = 0; /* do not mount */
 static int enable_splitcache = 0;
-int afsd_dynamic_vcaches = 0;  /* Enable dynamic-vcache support */
+static int afsd_dynamic_vcaches = 0;   /* Enable dynamic-vcache support */
 int afsd_verbose = 0;          /*Are we being chatty? */
 int afsd_debug = 0;            /*Are we printing debugging info? */
-int afsd_CloseSynch = 0;       /*Are closes synchronous or not? */
-int rxmaxmtu = 0;       /* Are we forcing a limit on the mtu? */
+static int afsd_CloseSynch = 0;        /*Are closes synchronous or not? */
+static int rxmaxmtu = 0;       /* Are we forcing a limit on the mtu? */
 
 #ifdef AFS_SGI62_ENV
 #define AFSD_INO_T ino64_t
@@ -602,7 +614,7 @@ PartSizeOverflow(char *path, int cs)
 {
   int bsize = -1;
   afs_int64 totalblks, mint;
-#if AFS_HAVE_STATVFS
+#if AFS_HAVE_STATVFS || defined(HAVE_SYS_STATVFS_H)
     struct statvfs statbuf;
 
     if (statvfs(path, &statbuf) != 0) {
@@ -1641,20 +1653,19 @@ daemon_thread(void *rock)
     return NULL;
 }
 
+#ifndef UKERNEL
 static void *
 rmtsysd_thread(void *rock)
 {
     rmtsysd();
     return NULL;
 }
+#endif /* !UKERNEL */
 
 int
 mainproc(struct cmd_syndesc *as, void *arock)
 {
     afs_int32 code;            /*Result of fork() */
-#ifdef AFS_AIX32_ENV
-    int sawBiod = 0;
-#endif
 #ifdef AFS_SUN5_ENV
     struct stat st;
 #endif
@@ -1721,6 +1732,10 @@ mainproc(struct cmd_syndesc *as, void *arock)
     if (as->parms[10].items) {
        /* -rmtsys */
        afsd_rmtsys = 1;
+#ifdef UKERNEL
+       printf("-rmtsys not supported for UKERNEL\n");
+       return -1;
+#endif
     }
     if (as->parms[11].items) {
        /* -debug */
@@ -2446,11 +2461,13 @@ afsd_run(void)
        afsd_mount_afs(rn, afsd_cacheMountDir);
     }
 
+#ifndef UKERNEL
     if (afsd_rmtsys) {
        if (afsd_verbose)
            printf("%s: Forking 'rmtsys' daemon.\n", rn);
        afsd_fork(0, rmtsysd_thread, NULL);
     }
+#endif /* !UKERNEL */
     /*
      * Exit successfully.
      */
index 46b411a..3c9dc78 100644 (file)
@@ -234,7 +234,7 @@ typedef struct afs_hyper_t {        /* unsigned 64 bit integers */
 #define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)
 #endif /* AFS_64BIT_ENV */
 
-#ifndef        KERNEL
+#if !defined(KERNEL) || defined(UKERNEL)
 #ifndef AFS_NT40_ENV
 #define max(a, b)               ((a) < (b) ? (b) : (a))
 #define min(a, b)               ((a) > (b) ? (b) : (a))
index ecb5a74..238ee0c 100644 (file)
@@ -74,7 +74,7 @@ webinstall: all \
        ${TOP_LIBDIR}/$(LIBAFSWEBKRB) 
 
 linktest: UAFS/$(LIBUAFS) ${TOP_OBJDIR}/lib/libdes.a
-       $(CC) $(TEST_CFLAGS) $(TEST_LDFLAGS) -o linktest ${srcdir}/linktest.c $(COMMON_INCLUDE) -DUKERNEL UAFS/$(LIBUAFS) ${TOP_LIBDIR}/libdes.a ${TOP_LIBDIR}/libafsutil.a $(TEST_LIBS) $(XLIBS)
+       $(CC) $(TEST_CFLAGS) $(TEST_LDFLAGS) -o linktest ${srcdir}/linktest.c $(COMMON_INCLUDE) -DUKERNEL UAFS/$(LIBUAFS) ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libdes.a ${TOP_LIBDIR}/libafsutil.a $(TEST_LIBS) $(XLIBS)
 
 
 CRULE1=        $(CC) $(COMMON_INCLUDE) $(OPTF) -DKERNEL $(LIBJUAFS_FLAGS) $(CFLAGS) -c $?
@@ -137,6 +137,8 @@ UAFSOBJ = \
        $(UOBJ)/afs_pioctl.o \
        $(UOBJ)/osi_vfsops.o \
        $(UOBJ)/afs_usrops.o \
+       $(UOBJ)/afsd.o \
+       $(UOBJ)/afsd_uafs.o \
        $(UOBJ)/xdr.o \
        $(UOBJ)/xdr_afsuuid.o \
        $(UOBJ)/afs_uuid.o \
@@ -270,6 +272,8 @@ AFSWEBOBJ = \
        $(WEBOBJ)/afs_pioctl.o \
        $(WEBOBJ)/osi_vfsops.o \
        $(WEBOBJ)/afs_usrops.o \
+       $(WEBOBJ)/afsd.o \
+       $(WEBOBJ)/afsd_uafs.o \
        $(WEBOBJ)/xdr.o \
        $(WEBOBJ)/xdr_afsuuid.o \
        $(WEBOBJ)/afs_uuid.o \
@@ -403,6 +407,8 @@ AFSWEBOBJKRB = \
        $(WEBOBJ)/afs_pioctl.o \
        $(WEBOBJ)/osi_vfsops.o \
        $(WEBOBJ)/afs_usrops.o \
+       $(WEBOBJ)/afsd.o \
+       $(WEBOBJ)/afsd_uafs.o \
        $(WEBOBJ)/osi_vnodeops.o \
        $(WEBOBJ)/osi_vm.o \
        $(WEBOBJ)/osi_groups.o \
@@ -531,6 +537,8 @@ JUAFSOBJ = \
        $(JUAFS)/afs_pioctl.o \
        $(JUAFS)/osi_vfsops.o \
        $(JUAFS)/afs_usrops.o \
+       $(JUAFS)/afsd.o \
+       $(JUAFS)/afsd_uafs.o \
        $(JUAFS)/xdr.o \
        $(JUAFS)/xdr_afsuuid.o \
        $(JUAFS)/afs_uuid.o \
@@ -757,6 +765,10 @@ $(UOBJ)/xdr_int64.o: $(TOP_SRC_RX)/xdr_int64.c
        $(CRULE1)
 $(UOBJ)/afs_usrops.o: $(TOP_SRC_AFS)/UKERNEL/afs_usrops.c
        $(CRULE1)
+$(UOBJ)/afsd.o: $(TOP_SRCDIR)/afsd/afsd.c
+       $(CRULE1) @CFLAGS_NOERROR@
+$(UOBJ)/afsd_uafs.o: $(TOP_SRC_AFS)/UKERNEL/afsd_uafs.c
+       $(CRULE1)
 $(UOBJ)/afs_uuid.o: $(TOP_SRCDIR)/util/uuid.c
        $(CRULE1) -o afs_uuid.o
 $(UOBJ)/assert.o: $(TOP_SRCDIR)/util/assert.c
@@ -1026,6 +1038,10 @@ $(WEBOBJ)/xdr_rx.o: $(TOP_SRC_RX)/xdr_rx.c
        $(CRULE2)
 $(WEBOBJ)/afs_usrops.o: $(TOP_SRC_AFS)/UKERNEL/afs_usrops.c
        $(CRULE2)
+$(WEBOBJ)/afsd.o: $(TOP_SRCDIR)/afsd/afsd.c
+       $(CRULE2) @CFLAGS_NOERROR@
+$(WEBOBJ)/afsd_uafs.o: $(TOP_SRC_AFS)/UKERNEL/afsd_uafs.c
+       $(CRULE2)
 $(WEBOBJ)/afs_uuid.o: $(TOP_SRCDIR)/util/uuid.c
        $(CRULE2) -o afs_uuid.o
 $(WEBOBJ)/assert.o: $(TOP_SRCDIR)/util/assert.c
@@ -1305,6 +1321,10 @@ $(JUAFS)/xdr_int64.o: $(TOP_SRC_RX)/xdr_int64.c
        $(CRULE1)
 $(JUAFS)/afs_usrops.o: $(TOP_SRC_AFS)/UKERNEL/afs_usrops.c
        $(CRULE1)
+$(JUAFS)/afsd.o: $(TOP_SRCDIR)/afsd/afsd.c
+       $(CRULE1) @CFLAGS_NOERROR@
+$(JUAFS)/afsd_uafs.o: $(TOP_SRC_AFS)/UKERNEL/afsd_uafs.c
+       $(CRULE1)
 $(JUAFS)/afs_uuid.o: $(TOP_SRCDIR)/util/uuid.c
        $(CRULE1) -o afs_uuid.o
 $(JUAFS)/assert.o: $(TOP_SRCDIR)/util/assert.c
@@ -1483,6 +1503,7 @@ setup_common:
        -ln -s /usr/include/nfs nfs
        -ln -s /usr/include/inet inet
        -ln -s /usr/include/ufs ufs
+       -ln -s $(TOP_SRCDIR)/afsd afsd
        -ln -s $(NS_INCL) nsapi
 
 setup_uafs: UAFS setup_common
index d1b8188..c9e83c2 100644 (file)
 #include <rx/rx.h>
 #include <afs_usrops.h>
 
-void uafs_Shutdown(void);
-
 int
 main(int argc, char **argv)
 {
     int port = 0;
-    char *afsMount = 0;
-    char *confDir = 0;
-    char *cacheBaseDir = 0;
-    long cacheBlocks = 0;
-    long cacheFiles = 0;
-    long cacheStatEntries = 0;
-    long dCacheSize = 0;
-    long vCacheSize = 0;
-    long chunkSize = 0;
-    long closeSynch = 0;
-    long debug = 0;
-    long nDaemons = 0;
-    long memCache = 0;
-    char *logFile = 0;
-
     /*
      * Initialize the AFS client
      */
     uafs_SetRxPort(port);
 
-    uafs_Init("linktest", afsMount, confDir, cacheBaseDir, cacheBlocks,
-             cacheFiles, cacheStatEntries, dCacheSize, vCacheSize, chunkSize,
-             closeSynch, debug, nDaemons, memCache, logFile);
+    uafs_Setup(NULL);
+    uafs_ParseArgs(0, NULL);
+    uafs_Run();
 
     uafs_RxServerProc();