solaris-fs-agnostic-cache-20081130
authorDouglas Engert <deengert@anl.gov>
Sun, 30 Nov 2008 20:20:55 +0000 (20:20 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sun, 30 Nov 2008 20:20:55 +0000 (20:20 +0000)
LICENSE IPL10
FIXES 123677

make the cache able to be filesystem-agnostic so a ZFS cache is possible

src/afs/SOLARIS/osi_file.c
src/config/param.sun4x_510.h
src/config/param.sun4x_511.h
src/config/param.sunx86_510.h
src/config/param.sunx86_511.h

index ac92916..54385a2 100644 (file)
@@ -175,22 +175,85 @@ void *
 osi_UfsOpen(afs_int32 ainode)
 #endif
 {
+#ifdef AFS_CACHE_VNODE_PATH
+    struct vnode *vp;
+#else
     struct inode *ip;
+#endif
     register struct osi_file *afile = NULL;
     afs_int32 code = 0;
+#ifdef AFS_CACHE_VNODE_PATH
     int dummy;
+    char fname[1024];
+    char namebuf[1024];
+    struct pathname lookpn;
+#endif
+    struct osi_stat tstat;
     afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
     AFS_GUNLOCK();
+
+/*
+ * AFS_CACHE_VNODE_PATH can be used with any file system, including ZFS or tmpfs.
+ * The ainode is not an inode number but a signed index used to generate file names. 
+ */
+#ifdef AFS_CACHE_VNODE_PATH
+       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:
+               dummy = ainode / afs_numfilesperdir;
+               snprintf(fname, 1024, "%s/D%d/V%d", afs_cachebasedir, dummy, ainode);
+    }
+               
+       /* Can not use vn_open or lookupname, they use user's CRED() 
+     * We need to run as root So must use low level lookuppnvp 
+     * assume fname starts with /
+        */
+
+       code = pn_get_buf(fname, AFS_UIOSYS, &lookpn, namebuf, sizeof(namebuf));
+    if (code != 0) 
+        osi_Panic("UfsOpen: pn_get_buf failed %ld %s %ld", code, fname, ainode);
+       VN_HOLD(rootdir); /* released in loopuppnvp */
+       code = lookuppnvp(&lookpn, NULL, FOLLOW, NULL, &vp, 
+           rootdir, rootdir, &afs_osi_cred); 
+    if (code != 0)  
+        osi_Panic("UfsOpen: lookuppnvp failed %ld %s %ld", code, fname, ainode);
+       
+#ifdef AFS_SUN511_ENV
+    code = VOP_OPEN(&vp, FREAD|FWRITE, &afs_osi_cred, NULL);
+#else
+    code = VOP_OPEN(&vp, FREAD|FWRITE, &afs_osi_cred);
+#endif
+
+    if (code != 0)
+        osi_Panic("UfsOpen: VOP_OPEN failed %ld %s %ld", code, fname, ainode);
+
+#else
     code =
        igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, &ip,
                  CRED(), &dummy);
+#endif
     AFS_GLOCK();
     if (code) {
        osi_FreeSmallSpace(afile);
-       osi_Panic("UfsOpen: igetinode failed");
+       osi_Panic("UfsOpen: igetinode failed %ld %s %ld", code, fname, ainode);
     }
+#ifdef AFS_CACHE_VNODE_PATH
+       afile->vnode = vp;
+       code = afs_osi_Stat(afile, &tstat);
+       afile->size = tstat.size;
+#else
     afile->vnode = ITOV(ip);
     afile->size = VTOI(afile->vnode)->i_size;
+#endif
     afile->offset = 0;
     afile->proc = (int (*)())0;
     afile->inum = ainode;      /* for hint validity checking */
@@ -304,12 +367,14 @@ void
 osi_DisableAtimes(struct vnode *avp)
 {
     if (afs_CacheFSType == AFS_SUN_UFS_CACHE) {
+#ifndef AFS_CACHE_VNODE_PATH 
        struct inode *ip = VTOI(avp);
        rw_enter(&ip->i_contents, RW_READER);
        mutex_enter(&ip->i_tlock);
        ip->i_flag &= ~IACC;
        mutex_exit(&ip->i_tlock);
        rw_exit(&ip->i_contents);
+#endif
     }
 }
 
index 8a78eeb..148beb1 100644 (file)
@@ -34,6 +34,8 @@
 #define AFS_3DISPARES          1       /* Utilize the 3 available disk inode 'spares' */
 #endif /* AFS_NAMEI_ENV */
 
+#define AFS_CACHE_VNODE_PATH 1
+
 #include <afs/afs_sysnames.h>
 
 #define AFS_GLOBAL_SUNLOCK     1       /* For global locking */
index 118b24e..58d36b9 100644 (file)
@@ -35,6 +35,8 @@
 #define AFS_3DISPARES          1       /* Utilize the 3 available disk inode 'spares' */
 #endif /* AFS_NAMEI_ENV */
 
+#define AFS_CACHE_VNODE_PATH 1
+
 #include <afs/afs_sysnames.h>
 
 #define AFS_GLOBAL_SUNLOCK     1       /* For global locking */
index a2ddf19..409c6dc 100644 (file)
@@ -38,6 +38,8 @@
 
 #define AFS_HAVE_FLOCK_SYSID    1
 
+#define AFS_CACHE_VNODE_PATH 1
+
 #include <afs/afs_sysnames.h>
 
 #define AFS_GLOBAL_SUNLOCK     1       /* For global locking */
index a934672..b947f42 100644 (file)
@@ -39,6 +39,8 @@
 
 #define AFS_HAVE_FLOCK_SYSID    1
 
+#define AFS_CACHE_VNODE_PATH 1
+
 #include <afs/afs_sysnames.h>
 
 #define AFS_GLOBAL_SUNLOCK     1       /* For global locking */