darwin90-disk-cache-20071010
authorDerrick Brashear <shadow@dementia.org>
Wed, 10 Oct 2007 18:38:45 +0000 (18:38 +0000)
committerDerrick Brashear <shadow@dementia.org>
Wed, 10 Oct 2007 18:38:45 +0000 (18:38 +0000)
FIXES 43303

support disk cache in darwin90

src/afs/DARWIN/osi_file.c
src/afs/afs.h
src/afs/afs_call.c
src/afs/afs_init.c
src/afsd/afsd.c
src/config/afs_args.h
src/config/param.ppc_darwin_90.h
src/config/param.x86_darwin_90.h
src/packaging/MacOS/buildpkg.sh

index 279187b..eddbb5c 100644 (file)
@@ -141,6 +141,9 @@ osi_UFSOpen(afs_int32 ainode)
     extern int cacheDiskType;
     afs_int32 code = 0;
     int dummy;
+    char fname[1024];
+    struct osi_stat tstat;
+
     AFS_STATCNT(osi_UFSOpen);
     if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
        osi_Panic("UFSOpen called for non-UFS cache\n");
@@ -154,6 +157,28 @@ osi_UFSOpen(afs_int32 ainode)
     }
     afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
     AFS_GUNLOCK();
+#ifdef AFS_CACHE_VNODE_PATH
+    if (ainode < 0) {
+       switch (ainode) {
+       case AFS_CACHE_CELLS_INODE:
+           snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CellItems");
+           break;
+       case AFS_CACHE_ITEMS_INODE:
+           snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CacheItems");
+           break;
+       case AFS_CACHE_VOLUME_INODE:
+           snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "VolumeItems");
+           break;
+       default:
+           osi_Panic("Invalid negative inode");
+       }
+    } else {
+       dummy = ainode / afs_numfilesperdir;
+       snprintf(fname, 1024, "%s/D%d/V%d", afs_cachebasedir, dummy, ainode);
+    }
+
+    code = vnode_open(fname, O_RDWR, 0, 0, &vp, afs_osi_ctxtp);
+#else
 #ifndef AFS_DARWIN80_ENV
     if (afs_CacheFSType == AFS_APPL_HFS_CACHE)
        code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, &ainode, &vp, &va, &dummy);       /* XXX hfs is broken */
@@ -166,16 +191,22 @@ osi_UFSOpen(afs_int32 ainode)
     else
        panic("osi_UFSOpen called before cacheops initialized\n");
 #endif
+#endif
     AFS_GLOCK();
     if (code) {
        osi_FreeSmallSpace(afile);
        osi_Panic("UFSOpen: igetinode failed");
     }
     afile->vnode = vp;
-    afile->size = va.va_size;
     afile->offset = 0;
     afile->proc = (int (*)())0;
     afile->inum = ainode;      /* for hint validity checking */
+#ifndef AFS_CACHE_VNODE_PATH
+    afile->size = va.va_size;
+#else
+    code = afs_osi_Stat(afile, &tstat);
+    afile->size = tstat.size;
+#endif
     return (void *)afile;
 }
 
index e9f6fd4..8b4859c 100644 (file)
@@ -270,6 +270,9 @@ enum { AFS_GCPAGS_NOTCOMPILED = 0, AFS_GCPAGS_OK =
 extern afs_int32 afs_gcpags;
 extern afs_int32 afs_gcpags_procsize;
 extern afs_int32 afs_bkvolpref;
+extern char afs_cachebasedir[1024];
+extern afs_int32 afs_numcachefiles;
+extern afs_int32 afs_numfilesperdir;
 
 struct unixuser {
     struct unixuser *next;     /* next hash pointer */
index e24855d..8e0f728 100644 (file)
@@ -66,6 +66,9 @@ static int afs_Go_Done = 0;
 extern struct interfaceAddr afs_cb_interface;
 static int afs_RX_Running = 0;
 static int afs_InitSetup_done = 0;
+afs_int32 afs_numcachefiles = -1;
+afs_int32 afs_numfilesperdir = -1;
+char afs_cachebasedir[1024];
 
 afs_int32 afs_rx_deadtime = AFS_RXDEADTIME;
 afs_int32 afs_rx_harddead = AFS_HARDDEADTIME;
@@ -461,6 +464,17 @@ afs_DaemonOp(long parm, long parm2, long parm3, long parm4, long parm5,
 }
 #endif
 
+static void
+wait_for_cachedefs(void) {
+#ifdef AFS_CACHE_VNODE_PATH
+    while ((afs_numcachefiles < 1) || (afs_numfilesperdir < 1) ||
+          (afs_cachebasedir[0] != '/')) {
+       printf("afs: waiting for cache parameter definitions\n");
+       afs_osi_Sleep(&afs_initState);
+    }
+#endif
+}
+
 /* leaving as is, probably will barf if we add prototypes here since it's likely being called
 with partial list */
 int
@@ -792,6 +806,12 @@ afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
 #ifdef AFS_DARWIN80_ENV
        put_vfs_context();
 #endif
+    } else if (parm == AFSOP_CACHEDIRS) {
+       afs_numfilesperdir = parm2;
+       afs_osi_Wakeup(&afs_initState);
+    } else if (parm == AFSOP_CACHEFILES) {
+       afs_numcachefiles = parm2;
+       afs_osi_Wakeup(&afs_initState);
     } else if (parm == AFSOP_ROOTVOLUME) {
        /* wait for basic init */
        while (afs_initState < AFSOP_START_BKG)
@@ -805,7 +825,7 @@ afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
            code = 0;
     } else if (parm == AFSOP_CACHEFILE || parm == AFSOP_CACHEINFO
               || parm == AFSOP_VOLUMEINFO || parm == AFSOP_AFSLOG
-              || parm == AFSOP_CELLINFO) {
+              || parm == AFSOP_CELLINFO || parm == AFSOP_CACHEBASEDIR) {
        char *tbuffer = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
 
        code = 0;
@@ -821,20 +841,47 @@ afs_syscall_call(parm, parm2, parm3, parm4, parm5, parm6)
 #ifdef AFS_DARWIN80_ENV
     get_vfs_context();
 #endif
-           if (parm == AFSOP_CACHEFILE)
+           if (parm == AFSOP_CACHEBASEDIR) {
+               strncpy(afs_cachebasedir, tbuffer, 1024);
+               afs_cachebasedir[1023] = '\0';
+               afs_osi_Wakeup(&afs_initState);
+           } else if (parm == AFSOP_CACHEFILE) {
+               wait_for_cachedefs();
                code = afs_InitCacheFile(tbuffer, 0);
-           else if (parm == AFSOP_CACHEINFO)
+           } else if (parm == AFSOP_CACHEINFO) {
+               wait_for_cachedefs();
                code = afs_InitCacheInfo(tbuffer);
-           else if (parm == AFSOP_VOLUMEINFO)
+           } else if (parm == AFSOP_VOLUMEINFO) {
+               wait_for_cachedefs();
                code = afs_InitVolumeInfo(tbuffer);
-           else if (parm == AFSOP_CELLINFO)
+           } else if (parm == AFSOP_CELLINFO) {
+               wait_for_cachedefs();
                code = afs_InitCellInfo(tbuffer);
+           }
 #ifdef AFS_DARWIN80_ENV
            put_vfs_context();
 #endif
        }
        osi_FreeSmallSpace(tbuffer);
     } else if (parm == AFSOP_GO) {
+#ifdef AFS_CACHE_VNODE_PATH
+       afs_int32 dummy;
+
+       wait_for_cachedefs();
+
+#ifdef AFS_DARWIN80_ENV
+       get_vfs_context();
+#endif
+       if ((afs_numcachefiles > 0) && (afs_numfilesperdir > 0) && 
+           (afs_cachebasedir[0] == '/')) {
+           for (dummy = 0; dummy < afs_numcachefiles; dummy++) {
+               code = afs_InitCacheFile(NULL, dummy);
+           }
+       }
+#ifdef AFS_DARWIN80_ENV
+       put_vfs_context();
+#endif
+#endif
        /* the generic initialization calls come here.  One parameter: should we do the
         * set-time operation on this workstation */
        if (afs_Go_Done)
index ad6defa..87b2b73 100644 (file)
@@ -245,8 +245,12 @@ afs_InitCellInfo(char *afile)
     ino_t inode;
     int code;
 
+#ifdef AFS_CACHE_VNODE_PATH
+    return afs_cellname_init(AFS_CACHE_CELLS_INODE, code);
+#else
     code = LookupInodeByPath(afile, &inode, NULL);
     return afs_cellname_init(inode, code);
+#endif
 }
 
 /*
@@ -287,6 +291,8 @@ afs_InitVolumeInfo(char *afile)
      * it in the cache...
      */
     code = LookupInodeByPath(afile, &volumeInode, &volumeVnode);
+#elif defined(AFS_CACHE_VNODE_PATH)
+    volumeInode = AFS_CACHE_VOLUME_INODE;
 #else
     code = LookupInodeByPath(afile, &volumeInode, NULL);
 #endif
@@ -417,11 +423,15 @@ afs_InitCacheInfo(register char *afile)
 #if defined(AFS_SGI62_ENV) || defined(AFS_HAVE_VXFS) || defined(AFS_DARWIN_ENV)
     afs_InitDualFSCacheOps(filevp);
 #endif
-    cacheInode = afs_vnodeToInumber(filevp);
-    cacheDev.dev = afs_vnodeToDev(filevp);
+#ifndef AFS_CACHE_VNODE_PATH
 #ifndef AFS_DARWIN80_ENV
     afs_cacheVfsp = filevp->v_vfsp;
 #endif
+    cacheInode = afs_vnodeToInumber(filevp);
+#else
+    cacheInode = AFS_CACHE_ITEMS_INODE;
+#endif
+    cacheDev.dev = afs_vnodeToDev(filevp);
 #endif /* AFS_LINUX20_ENV */
     AFS_RELE(filevp);
 #endif /* AFS_LINUX22_ENV */
index 40a50ba..6ee2615 100644 (file)
@@ -334,8 +334,10 @@ int *dir_for_V = NULL;             /* Array: dir of each cache file.
                                 * -2: file exists in top-level
                                 * >=0: file exists in Dxxx
                                 */
+#ifndef AFS_CACHE_VNODE_PATH
 AFSD_INO_T *inode_for_V;       /* Array of inodes for desired
                                 * cache files */
+#endif
 int missing_DCacheFile = 1;    /*Is the DCACHEFILE missing? */
 int missing_VolInfoFile = 1;   /*Is the VOLINFOFILE missing? */
 int missing_CellInfoFile = 1;  /*Is the CELLINFOFILE missing? */
@@ -1007,7 +1009,9 @@ doSweepAFSCache(vFilesFound, directory, dirNum, maxDir)
             * file's inode, directory, and bump the number of files found
             * total and in this directory.
             */
+#ifndef AFS_CACHE_VNODE_PATH
            inode_for_V[vFileNum] = currp->d_ino;
+#endif
            dir_for_V[vFileNum] = dirNum;       /* remember this directory */
 
            if (!maxDir) {
@@ -1144,7 +1148,9 @@ doSweepAFSCache(vFilesFound, directory, dirNum, maxDir)
                           vFileNum);
                else {
                    struct stat statb;
+#ifndef AFS_CACHE_VNODE_PATH
                    assert(inode_for_V[vFileNum] == (AFSD_INO_T) 0);
+#endif
                    sprintf(vFilePtr, "D%d/V%d", thisDir, vFileNum);
                    if (afsd_verbose)
                        printf("%s: Creating '%s'\n", rn, fullpn_VFile);
@@ -1155,7 +1161,9 @@ doSweepAFSCache(vFilesFound, directory, dirNum, maxDir)
                    if (CreateCacheFile(fullpn_VFile, &statb))
                        printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
                    else {
+#ifndef AFS_CACHE_VNODE_PATH
                        inode_for_V[vFileNum] = statb.st_ino;
+#endif
                        dir_for_V[vFileNum] = thisDir;
                        cache_dir_list[thisDir]++;
                        (*vFilesFound)++;
@@ -1923,6 +1931,7 @@ mainproc(struct cmd_syndesc *as, char *arock)
                   cacheStatEntries);
     }
 
+#ifndef AFS_CACHE_VNODE_PATH
     /*
      * Create and zero the inode table for the desired cache files.
      */
@@ -1937,6 +1946,7 @@ mainproc(struct cmd_syndesc *as, char *arock)
     if (afsd_debug)
        printf("%s: %d inode_for_V entries at 0x%x, %d bytes\n", rn,
               cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
+#endif
 
     /*
      * Set up all the pathnames we'll need for later.
@@ -2125,6 +2135,23 @@ mainproc(struct cmd_syndesc *as, char *arock)
                     rn, vFilesFound, cacheFiles, cacheIteration);
        } while ((vFilesFound < cacheFiles)
                 && (cacheIteration < MAX_CACHE_LOOPS));
+#ifdef AFS_CACHE_VNODE_PATH
+       if (afsd_debug)
+           printf
+               ("%s: Calling AFSOP_CACHEBASEDIR with '%s'\n",
+                rn, cacheBaseDir);
+       call_syscall(AFSOP_CACHEBASEDIR, cacheBaseDir);
+       if (afsd_debug)
+           printf
+               ("%s: Calling AFSOP_CACHEDIRS with %d dirs\n",
+                rn, nFilesPerDir);
+       call_syscall(AFSOP_CACHEDIRS, nFilesPerDir);
+       if (afsd_debug)
+           printf
+               ("%s: Calling AFSOP_CACHEFILES with %d files\n",
+                rn, cacheFiles);
+       call_syscall(AFSOP_CACHEFILES, cacheFiles);
+#endif
     } else if (afsd_verbose)
        printf("%s: Using memory cache, not swept\n", rn);
 
@@ -2259,6 +2286,7 @@ mainproc(struct cmd_syndesc *as, char *arock)
     if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
        call_syscall(AFSOP_VOLUMEINFO, fullpn_VolInfoFile);
 
+#ifndef AFS_CACHE_VNODE_PATH
     /*
      * Give the kernel the names of the AFS files cached on the workstation's
      * disk.
@@ -2277,7 +2305,7 @@ mainproc(struct cmd_syndesc *as, char *arock)
            call_syscall(AFSOP_CACHEINODE, inode_for_V[currVFile]);
 #endif
        }
-
+#endif
 
     /*end for */
     /*
index 7860e77..7e362e7 100644 (file)
 /* For SGI, this can't interfere with any of the 64 bit inode calls. */
 #define AFSOP_RXLISTENER_DAEMON  48    /* starts kernel RX listener */
 
+/* skip 64 bit calls */
+#define AFSOP_CACHEBASEDIR       50     /* cache base dir */
+#define AFSOP_CACHEDIRS          51     /* number of files per dir */
+#define AFSOP_CACHEFILES         52     /* number of files */
+
+#define AFSOP_SETINT             60     /* we should just set key/value pairs 
+                                          for things which are just ints */
+
 /* these are for initialization flags */
 
 #define AFSCALL_INIT_MEMCACHE 0x1
@@ -227,4 +235,10 @@ struct afssysargs {
 #define SYSCALL_DEV_FNAME "/dev/openafs_ioctl"
 #endif
 
+#ifdef AFS_CACHE_VNODE_PATH
+#define AFS_CACHE_CELLS_INODE -2
+#define AFS_CACHE_ITEMS_INODE -3
+#define AFS_CACHE_VOLUME_INODE -4
+#endif
+
 #endif /* _AFS_ARGS_H_ */
index ac74560..a62b855 100644 (file)
@@ -30,6 +30,7 @@
 #define AFS_SYSCALL             230
 #define AFS_NAMEI_ENV 1
 #define DARWIN_REFBASE 3
+#define AFS_CACHE_VNODE_PATH
 
 /* File system entry (used if mount.h doesn't define MOUNT_AFS */
 #define AFS_MOUNT_AFS    "afs"
index ac74560..a62b855 100644 (file)
@@ -30,6 +30,7 @@
 #define AFS_SYSCALL             230
 #define AFS_NAMEI_ENV 1
 #define DARWIN_REFBASE 3
+#define AFS_CACHE_VNODE_PATH
 
 /* File system entry (used if mount.h doesn't define MOUNT_AFS */
 #define AFS_MOUNT_AFS    "afs"
index d7f6db0..2b54058 100644 (file)
@@ -122,11 +122,7 @@ if [ $firstpass = yes ]; then
     else
        echo /Network/afs:/var/db/openafs/cache:30000 > $PKGROOT/private/var/db/openafs/etc/cacheinfo.sample
     fi
-    if [ $majorvers -ge 9 ]; then
-    echo '-memcache -afsdb -stat 2000 -dcache 800 -daemons 3 -volumes 70 -dynroot -fakestat-all' > $PKGROOT/private/var/db/openafs/etc/config/afsd.options.sample
-    else
     echo '-afsdb -stat 2000 -dcache 800 -daemons 3 -volumes 70 -dynroot -fakestat-all' > $PKGROOT/private/var/db/openafs/etc/config/afsd.options.sample
-    fi
 
     strip -X -S $PKGROOT/Library/OpenAFS/Tools/root.client/usr/vice/etc/afs.kext/Contents/MacOS/afs