afs: more cache truncation stats
[openafs.git] / src / afs / SOLARIS / osi_vnodeops.c
index fdfa905..81147d5 100644 (file)
@@ -76,41 +76,43 @@ extern struct as kas;               /* kernel addr space */
 extern unsigned char *afs_indexFlags;
 extern afs_lock_t afs_xdcache;
 
-/* Additional vnodeops for SunOS 4.0.x */
-int afs_nfsrdwr(), afs_getpage(), afs_putpage(), afs_map();
-int afs_dump(), afs_cmp(), afs_realvp(), afs_GetOnePage();
+static int afs_nfsrdwr(struct vcache *avc, struct uio *auio, enum uio_rw arw,
+                       int ioflag, afs_ucred_t *acred);
+static int afs_GetOnePage(struct vnode *vp, u_offset_t off, u_int alen,
+                          u_int *protp, struct page *pl[], u_int plsz,
+                          struct seg *seg, caddr_t addr, enum seg_rw rw,
+                          afs_ucred_t *acred);
 
 int afs_pvn_vptrunc;
 
-int
-afs_addmap(register struct vnode *avp, offset_t offset, struct as *asp, 
+static int
+afs_addmap(struct vnode *avp, offset_t offset, struct as *asp, 
           caddr_t addr, int length, int prot, int maxprot, int flags, 
-          struct AFS_UCRED *credp)
+          afs_ucred_t *credp)
 {
     /* XXX What should we do here?? XXX */
     return (0);
 }
 
-int
-afs_delmap(register struct vnode *avp, offset_t offset, struct as *asp, 
+static int
+afs_delmap(struct vnode *avp, offset_t offset, struct as *asp, 
           caddr_t addr, int length, int prot, int maxprot, int flags, 
-          struct AFS_UCRED *credp)
+          afs_ucred_t *credp)
 {
     /* XXX What should we do here?? XXX */
     return (0);
 }
 
+static int
 #ifdef AFS_SUN510_ENV
-int
-afs_vmread(register struct vnode *avp, struct uio *auio, int ioflag, 
-          struct AFS_UCRED *acred, caller_context_t *ct)
+afs_vmread(struct vnode *avp, struct uio *auio, int ioflag, 
+          afs_ucred_t *acred, caller_context_t *ct)
 #else
-int
-afs_vmread(register struct vnode *avp, struct uio *auio, int ioflag, 
-          struct AFS_UCRED *acred)
+afs_vmread(struct vnode *avp, struct uio *auio, int ioflag, 
+          afs_ucred_t *acred)
 #endif
 {
-    register int code;
+    int code;
 
     if (!RW_READ_HELD(&(VTOAFS(avp))->rwlock))
        osi_Panic("afs_vmread: !rwlock");
@@ -121,17 +123,16 @@ afs_vmread(register struct vnode *avp, struct uio *auio, int ioflag,
 }
 
 
+static int
 #ifdef AFS_SUN510_ENV
-int
-afs_vmwrite(register struct vnode *avp, struct uio *auio, int ioflag, 
-           struct AFS_UCRED *acred, caller_context_t *ct)
+afs_vmwrite(struct vnode *avp, struct uio *auio, int ioflag, 
+           afs_ucred_t *acred, caller_context_t *ct)
 #else
-int
-afs_vmwrite(register struct vnode *avp, struct uio *auio, int ioflag, 
-           struct AFS_UCRED *acred)
+afs_vmwrite(struct vnode *avp, struct uio *auio, int ioflag, 
+           afs_ucred_t *acred)
 #endif
 {
-    register int code;
+    int code;
 
     if (!RW_WRITE_HELD(&(VTOAFS(avp))->rwlock))
        osi_Panic("afs_vmwrite: !rwlock");
@@ -141,12 +142,12 @@ afs_vmwrite(register struct vnode *avp, struct uio *auio, int ioflag,
     return code;
 }
 
-int
+static int
 afs_getpage(struct vnode *vp, offset_t off, u_int len, u_int *protp, 
            struct page *pl[], u_int plsz, struct seg *seg, caddr_t addr, 
-           enum seg_rw rw, struct AFS_UCRED *acred)
+           enum seg_rw rw, afs_ucred_t *acred)
 {
-    register afs_int32 code = 0;
+    afs_int32 code = 0;
     AFS_STATCNT(afs_getpage);
 
     if (vp->v_flag & VNOMAP)   /* File doesn't allow mapping */
@@ -156,26 +157,41 @@ afs_getpage(struct vnode *vp, offset_t off, u_int len, u_int *protp,
 
     if (len <= PAGESIZE)
        code =
-           afs_GetOnePage(vp, 
-#if !defined(AFS_SUN56_ENV)
-                          (u_int)
-#endif
-                          off, len, protp, pl, plsz, seg, addr, rw, acred);
+           afs_GetOnePage(vp, off, len, protp, pl, plsz, seg, addr, rw, acred);
     else {
+       struct multiPage_range range;
        struct vcache *vcp = VTOAFS(vp);
+
+       /* We've been asked to get more than one page. We must return all
+        * requested pages at once, all of them locked, which means all of
+        * these dcache entries cannot be kicked out of the cache before we
+        * return (since their pages cannot be invalidated).
+        *
+        * afs_GetOnePage will be called multiple times by pvn_getpages in
+        * order to get all of the requested pages. One of the later
+        * afs_GetOnePage calls may need to evict some cache entries in order
+        * to perform its read. If we try to kick out one of the entries an
+        * earlier afs_GetOnePage call used, we will deadlock since we have
+        * the page locked. So, to tell afs_GetDownD that it should skip over
+        * any entries we've read in due to this afs_getpage call, record the
+        * offset and length in avc->multiPage.
+        *
+        * Ideally we would just set something in each dcache as we get it,
+        * but that is rather difficult, since pvn_getpages doesn't let us
+        * retain any information between calls to afs_GetOnePage. So instead
+        * just record the offset and length, and let afs_GetDownD calculate
+        * which dcache entries should be skipped. */
+
+       range.off = off;
+       range.len = len;
+
        ObtainWriteLock(&vcp->vlock, 548);
-       vcp->multiPage++;
+       QAdd(&vcp->multiPage, &range.q);
        ReleaseWriteLock(&vcp->vlock);
-       afs_BozonLock(&vcp->pvnLock, vcp);
        code =
-           pvn_getpages(afs_GetOnePage, vp, 
-#if !defined(AFS_SUN56_ENV)
-                        (u_int)
-#endif
-                        off, len, protp, pl, plsz, seg, addr, rw, acred);
-       afs_BozonUnlock(&vcp->pvnLock, vcp);
+           pvn_getpages(afs_GetOnePage, vp, off, len, protp, pl, plsz, seg, addr, rw, acred);
        ObtainWriteLock(&vcp->vlock, 549);
-       vcp->multiPage--;
+       QRemove(&range.q);
        ReleaseWriteLock(&vcp->vlock);
     }
     AFS_GUNLOCK();
@@ -183,24 +199,18 @@ afs_getpage(struct vnode *vp, offset_t off, u_int len, u_int *protp,
 }
 
 /* Return all the pages from [off..off+len) in file */
-int
-#if    defined(AFS_SUN56_ENV)
+static int
 afs_GetOnePage(struct vnode *vp, u_offset_t off, u_int alen, u_int *protp, 
               struct page *pl[], u_int plsz, struct seg *seg, caddr_t addr, 
-              enum seg_rw rw, struct AFS_UCRED *acred)
-#else
-afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp, 
-              struct page *pl[], u_int plsz, struct seg *seg, caddr_t addr, 
-              enum seg_rw rw, struct AFS_UCRED *acred)
-#endif
+              enum seg_rw rw, afs_ucred_t *acred)
 {
-    register struct page *page;
-    register afs_int32 code = 0;
+    struct page *page;
+    afs_int32 code = 0;
     u_int len;
     struct buf *buf;
     afs_int32 tlen;
-    register struct vcache *avc;
-    register struct dcache *tdc;
+    struct vcache *avc;
+    struct dcache *tdc;
     int i, s, pexists;
     int slot;
     afs_size_t offset, nlen = 0;
@@ -245,7 +255,8 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
 
                tdc->mflags |= DFFetchReq;
                bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred,
-                               (afs_size_t) off, (afs_size_t) 1, tdc);
+                               (afs_size_t) off, (afs_size_t) 1, tdc,
+                               (void *)0, (void *)0);
                if (!bp) {
                    /* Unable to start background fetch; might as well stop */
                    tdc->mflags &= ~DFFetchReq;
@@ -304,7 +315,6 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
        return afs_CheckCode(code, &treq, 44);  /* failed to get it */
     }
 
-    afs_BozonLock(&avc->pvnLock, avc);
     ObtainReadLock(&avc->lock);
 
     afs_Trace4(afs_iclSetp, CM_TRACE_PAGEIN, ICL_TYPE_POINTER, (afs_int32) vp,
@@ -320,7 +330,6 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
     if (avc->activeV) {
        ReleaseReadLock(&avc->lock);
        ReleaseWriteLock(&avc->vlock);
-       afs_BozonUnlock(&avc->pvnLock, avc);
        afs_PutDCache(tdc);
        /* Check activeV again, it may have been turned off
         * while we were waiting for a lock in afs_PutDCache */
@@ -341,10 +350,9 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
 
     /* Check to see whether the cache entry is still valid */
     if (!(avc->f.states & CStatd)
-       || !hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
+       || !afs_IsDCacheFresh(tdc, avc)) {
        ReleaseReadLock(&tdc->lock);
        ReleaseReadLock(&avc->lock);
-       afs_BozonUnlock(&avc->pvnLock, avc);
        afs_PutDCache(tdc);
        goto retry;
     }
@@ -361,24 +369,14 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
        /* if we make it here, we can't find the page in memory.  Do a real disk read
         * from the cache to get the data */
        Code |= 0x200;          /* XXX */
-#if    defined(AFS_SUN54_ENV)
        /* use PG_EXCL because we know the page does not exist already.  If it 
         * actually does exist, we have somehow raced between lookup and create.
         * As of 4/98, that shouldn't be possible, but we'll be defensive here
         * in case someone tries to relax all the serialization of read and write
         * operations with harmless things like stat. */
-#if    defined(AFS_SUN58_ENV)
        page =
            page_create_va(vp, toffset, PAGESIZE, PG_WAIT | PG_EXCL, seg,
                           addr);
-#else
-       page =
-           page_create_va(vp, toffset, PAGESIZE, PG_WAIT | PG_EXCL,
-                          seg->s_as, addr);
-#endif
-#else
-       page = page_create(vp, toffset, PAGESIZE, PG_WAIT);
-#endif
        if (!page) {
            continue;
        }
@@ -394,11 +392,7 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
            buf = pageio_setup(page, PAGESIZE, vp, B_READ);     /* allocate a buf structure */
            buf->b_edev = 0;
            buf->b_dev = 0;
-#if defined(AFS_SUN56_ENV)
            buf->b_lblkno = lbtodb(toffset);
-#else
-           buf->b_blkno = btodb(toffset);
-#endif
            bp_mapin(buf);      /* map it in to our address space */
 
            AFS_GLOCK();
@@ -421,12 +415,7 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
       nextpage:
        /* put page in array and continue */
        /* The p_selock must be downgraded to a shared lock after the page is read */
-#if    defined(AFS_SUN56_ENV)
-       if ((rw != S_CREATE) && !(PAGE_SHARED(page)))
-#else
-       if ((rw != S_CREATE) && !(se_shared_assert(&page->p_selock)))
-#endif
-       {
+       if ((rw != S_CREATE) && !(PAGE_SHARED(page))) {
            page_downgrade(page);
        }
        pl[slot++] = page;
@@ -457,7 +446,6 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
     }
     afs_indexFlags[tdc->index] |= IFAnyPages;
     ReleaseWriteLock(&afs_xdcache);
-    afs_BozonUnlock(&avc->pvnLock, avc);
     afs_PutDCache(tdc);
     afs_Trace3(afs_iclSetp, CM_TRACE_PAGEINDONE, ICL_TYPE_LONG, code,
               ICL_TYPE_LONG, (int)page, ICL_TYPE_LONG, Code);
@@ -471,32 +459,36 @@ afs_GetOnePage(struct vnode *vp, u_int off, u_int alen, u_int *protp,
     if (page)
        pvn_read_done(page, B_ERROR);
     ReleaseReadLock(&avc->lock);
-    afs_BozonUnlock(&avc->pvnLock, avc);
     ReleaseReadLock(&tdc->lock);
     afs_PutDCache(tdc);
     return code;
 }
 
+/**
+ * Dummy pvn_vplist_dirty() handler for non-writable vnodes.
+ */
+static int
+afs_never_putapage(struct vnode *vp, struct page *pages, u_offset_t * offp,
+            size_t * lenp, int flags, afs_ucred_t *credp)
+{
+    struct vcache *avc = VTOAFS(vp);
+    osi_Assert((avc->f.states & CRO) != 0);
+    osi_Panic("Dirty pages while flushing a read-only volume vnode.");
+    AFS_UNREACHED(return EIO);
+}
+
 int
 afs_putpage(struct vnode *vp, offset_t off, u_int len, int flags, 
-           struct AFS_UCRED *cred)
+           afs_ucred_t *cred)
 {
     struct vcache *avc;
     struct page *pages;
     afs_int32 code = 0;
-#if    defined(AFS_SUN58_ENV)
     size_t tlen;
-#else
-    afs_int32 tlen;
-#endif
     afs_offs_t endPos;
     afs_int32 NPages = 0;
-#if    defined(AFS_SUN56_ENV)
     u_offset_t toff = off;
-#else
-    int toff = (int)off;
-#endif
-    int didWriteLock;
+    int didLock = 0;
 
     AFS_STATCNT(afs_putpage);
     if (vp->v_flag & VNOMAP)   /* file doesn't allow mapping */
@@ -510,12 +502,11 @@ afs_putpage(struct vnode *vp, offset_t off, u_int len, int flags,
               (afs_int32) vp, ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(off),
               ICL_TYPE_INT32, (afs_int32) len, ICL_TYPE_LONG, (int)flags);
     avc = VTOAFS(vp);
-    afs_BozonLock(&avc->pvnLock, avc);
-    ObtainSharedLock(&avc->lock, 247);
-    didWriteLock = 0;
 
     /* Get a list of modified (or whatever) pages */
     if (len) {
+       ObtainSharedLock(&avc->lock, 247);
+       didLock = SHARED_LOCK;
        endPos = (afs_offs_t) off + len;        /* position we're supposed to write up to */
        while ((afs_offs_t) toff < endPos
               && (afs_offs_t) toff < avc->f.m.Length) {
@@ -530,9 +521,9 @@ afs_putpage(struct vnode *vp, offset_t off, u_int len, int flags,
            if (!pages || !pvn_getdirty(pages, flags))
                tlen = PAGESIZE;
            else {
-               if (!didWriteLock) {
+               if (didLock == SHARED_LOCK) {
                    AFS_GLOCK();
-                   didWriteLock = 1;
+                   didLock = WRITE_LOCK;
                    UpgradeSToWLock(&avc->lock, 671);
                    AFS_GUNLOCK();
                }
@@ -547,51 +538,60 @@ afs_putpage(struct vnode *vp, offset_t off, u_int len, int flags,
            AFS_GLOCK();
        }
     } else {
-       if (!didWriteLock) {
-           UpgradeSToWLock(&avc->lock, 670);
-           didWriteLock = 1;
+       /*
+        * We normally arrive here due to a vm flush.
+        *
+        * If this vnode belongs to a writable volume, obtain a vcache lock
+        * then call pvn_vplist_dirty to free, invalidate, or to write out
+        * dirty pages with afs_putapage.  The afs_putapage routine requires a
+        * vcache lock, so we obtain it here before any page locks are taken.
+        * This locking order is done to avoid deadlocking due to races with
+        * afs_getpage, which also takes vcache and page locks.
+        *
+        * If this vnode belongs to a non-writable volume, then it will not
+        * contain dirty pages, so we do not need to lock the vcache and since
+        * afs_putapage will not be called.  Instead, forgo the vcache lock and
+        * call pvn_vplist_dirty to free, or invalidate pages. Pass a dummy
+        * page out handler to pvn_vplist_dirty which we do not expect to be
+        * called.  Panic if the dummy handler is called, since something went
+        * horribly wrong.
+        */
+       if ((avc->f.states & CRO) == 0) {
+           ObtainWriteLock(&avc->lock, 670);
+           didLock = WRITE_LOCK;
        }
-
        AFS_GUNLOCK();
-#if    defined(AFS_SUN56_ENV)
-       code = pvn_vplist_dirty(vp, toff, afs_putapage, flags, cred);
-#else
-       code = pvn_vplist_dirty(vp, (u_int) off, afs_putapage, flags, cred);
-#endif
+       if ((avc->f.states & CRO) == 0)
+           code = pvn_vplist_dirty(vp, toff, afs_putapage, flags, cred);
+       else
+           code = pvn_vplist_dirty(vp, toff, afs_never_putapage, flags, cred);
        AFS_GLOCK();
     }
 
     if (code && !avc->vc_error) {
-       if (!didWriteLock) {
+       if (didLock == 0) {
+           ObtainWriteLock(&avc->lock, 668);
+           didLock = WRITE_LOCK;
+       } else if (didLock == SHARED_LOCK) {
            UpgradeSToWLock(&avc->lock, 669);
-           didWriteLock = 1;
+           didLock = WRITE_LOCK;
        }
        avc->vc_error = code;
     }
 
-    if (didWriteLock)
+    if (didLock == WRITE_LOCK)
        ReleaseWriteLock(&avc->lock);
-    else
+    else if (didLock == SHARED_LOCK)
        ReleaseSharedLock(&avc->lock);
-    afs_BozonUnlock(&avc->pvnLock, avc);
     afs_Trace2(afs_iclSetp, CM_TRACE_PAGEOUTDONE, ICL_TYPE_LONG, code,
               ICL_TYPE_LONG, NPages);
     AFS_GUNLOCK();
     return (code);
 }
 
-
 int
-#if defined(AFS_SUN58_ENV)
-afs_putapage(struct vnode *vp, struct page *pages, u_offset_t * offp,
-            size_t * lenp, int flags, struct AFS_UCRED *credp)
-#elif defined(AFS_SUN56_ENV)
 afs_putapage(struct vnode *vp, struct page *pages, u_offset_t * offp,
-            u_int * lenp, int flags, struct AFS_UCRED *credp)
-#else
-afs_putapage(struct vnode *vp, struct page *pages, u_int * offp,
-            u_int * lenp, int flags, struct AFS_UCRED *credp)
-#endif
+            size_t * lenp, int flags, afs_ucred_t *credp)
 {
     struct buf *tbuf;
     struct vcache *avc = VTOAFS(vp);
@@ -620,11 +620,7 @@ afs_putapage(struct vnode *vp, struct page *pages, u_int * offp,
            return (ENOMEM);
 
        tbuf->b_dev = 0;
-#if defined(AFS_SUN56_ENV)
        tbuf->b_lblkno = lbtodb(pages->p_offset);
-#else
-       tbuf->b_blkno = btodb(pages->p_offset);
-#endif
        bp_mapin(tbuf);
        AFS_GLOCK();
        afs_Trace4(afs_iclSetp, CM_TRACE_PAGEOUTONE, ICL_TYPE_LONG, avc,
@@ -644,22 +640,23 @@ afs_putapage(struct vnode *vp, struct page *pages, u_int * offp,
     return code;
 }
 
-int
-afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
-           int ioflag, struct AFS_UCRED *acred)
+static int
+afs_nfsrdwr(struct vcache *avc, struct uio *auio, enum uio_rw arw,
+           int ioflag, afs_ucred_t *acred)
 {
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 code2;
+    afs_int32 code_checkcode = 0;
     int counter;
     afs_int32 mode, sflags;
-    register char *data;
+    char *data;
     struct dcache *dcp, *dcp_newpage;
     afs_size_t fileBase, size;
     afs_size_t pageBase;
-    register afs_int32 tsize;
-    register afs_int32 pageOffset, extraResid = 0;
-    register afs_size_t origLength;    /* length when reading/writing started */
-    register long appendLength;        /* length when this call will finish */
+    afs_int32 tsize;
+    afs_int32 pageOffset, extraResid = 0;
+    afs_size_t origLength;     /* length when reading/writing started */
+    long appendLength; /* length when this call will finish */
     int created;               /* created pages instead of faulting them */
     int lockCode;
     int didFakeOpen, eof;
@@ -700,6 +697,8 @@ afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
           && (afs_blocksUsed > PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks))) {
        if (afs_blocksUsed - afs_blocksDiscarded >
            PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) {
+           if (afs_WaitForCacheDrain == 0)
+               afs_WaitForCacheDrainCount++;
            afs_WaitForCacheDrain = 1;
            afs_osi_Sleep(&afs_WaitForCacheDrain);
        }
@@ -710,29 +709,22 @@ afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
     if (code)
        return afs_CheckCode(code, &treq, 45);
 
-    afs_BozonLock(&avc->pvnLock, avc);
-    osi_FlushPages(avc, acred);        /* hold bozon lock, but not basic vnode lock */
+    osi_FlushPages(avc, acred);
 
     ObtainWriteLock(&avc->lock, 250);
 
     /* adjust parameters when appending files */
     if ((ioflag & IO_APPEND) && arw == UIO_WRITE) {
-#if defined(AFS_SUN56_ENV)
        auio->uio_loffset = avc->f.m.Length;    /* write at EOF position */
-#else
-       auio->uio_offset = avc->f.m.Length;     /* write at EOF position */
-#endif
     }
     if (auio->afsio_offset < 0 || (auio->afsio_offset + auio->uio_resid) < 0) {
        ReleaseWriteLock(&avc->lock);
-       afs_BozonUnlock(&avc->pvnLock, avc);
        return EINVAL;
     }
 #ifndef AFS_64BIT_CLIENT
     /* file is larger than 2GB */
     if (AfsLargeFileSize(auio->uio_offset, auio->uio_resid)) {
        ReleaseWriteLock(&avc->lock);
-       afs_BozonUnlock(&avc->pvnLock, avc);
        return EFBIG;
     }
 #endif
@@ -740,11 +732,9 @@ afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
     didFakeOpen = 0;           /* keep track of open so we can do close */
     if (arw == UIO_WRITE) {
        /* do ulimit processing; shrink resid or fail */
-#if    defined(AFS_SUN56_ENV)
        if (auio->uio_loffset + auio->afsio_resid > auio->uio_llimit) {
            if (auio->uio_loffset >= auio->uio_llimit) {
                ReleaseWriteLock(&avc->lock);
-               afs_BozonUnlock(&avc->pvnLock, avc);
                return EFBIG;
            } else {
                /* track # of bytes we should write, but won't because of
@@ -756,25 +746,6 @@ afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
                extraResid -= auio->uio_resid;
            }
        }
-#else
-#ifdef AFS_SUN52_ENV
-       if (auio->afsio_offset + auio->afsio_resid > auio->uio_limit) {
-           if (auio->afsio_offset >= auio->uio_limit) {
-               ReleaseWriteLock(&avc->lock);
-               afs_BozonUnlock(&avc->pvnLock, avc);
-               return EFBIG;
-           } else {
-               /* track # of bytes we should write, but won't because of
-                * ulimit; we must add this into the final resid value
-                * so caller knows we punted some data.
-                */
-               extraResid = auio->uio_resid;
-               auio->uio_resid = auio->uio_limit - auio->afsio_offset;
-               extraResid -= auio->uio_resid;
-           }
-       }
-#endif
-#endif /* SUN56 */
        mode = S_WRITE;         /* segment map-in mode */
        afs_FakeOpen(avc);      /* do this for writes, so data gets put back
                                 * when we want it to be put back */
@@ -804,7 +775,6 @@ afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
                (avc, PRSFS_READ, &treq,
                 CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) {
                ReleaseWriteLock(&avc->lock);
-               afs_BozonUnlock(&avc->pvnLock, avc);
                return EACCES;
            }
        }
@@ -891,19 +861,14 @@ afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
            afs_size_t toff, tlen;
            dcp = afs_GetDCache(avc, fileBase, &treq, &toff, &tlen, 2);
            if (!dcp) {
-               code = ENOENT;
+               code = EIO;
                break;
            }
        }
        ReleaseWriteLock(&avc->lock);   /* uiomove may page fault */
        AFS_GUNLOCK();
-#if    defined(AFS_SUN56_ENV)
        data = segmap_getmap(segkmap, AFSTOV(avc), (u_offset_t) pageBase);
        raddr = (caddr_t) (((uintptr_t) data + pageOffset) & PAGEMASK);
-#else
-       data = segmap_getmap(segkmap, AFSTOV(avc), pageBase);
-       raddr = (caddr_t) (((u_int) data + pageOffset) & PAGEMASK);
-#endif
        rsize =
            (((u_int) data + pageOffset + tsize + PAGEOFFSET) & PAGEMASK) -
            (u_int) raddr;
@@ -923,12 +888,12 @@ afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
                AFS_GLOCK();
                dcp_newpage = afs_FindDCache(avc, pageBase);
                if (dcp_newpage
-                   && hsame(avc->f.m.DataVersion, dcp_newpage->f.versionNo)) {
+                   && afs_IsDCacheFresh(dcp_newpage, avc)) {
                    ObtainWriteLock(&avc->lock, 251);
                    ObtainWriteLock(&avc->vlock, 576);
                    ObtainReadLock(&dcp_newpage->lock);
                    if ((avc->activeV == 0)
-                       && hsame(avc->f.m.DataVersion, dcp_newpage->f.versionNo)
+                       && afs_IsDCacheFresh(dcp_newpage, avc)
                        && !(dcp_newpage->dflags & (DFFetching))) {
                        AFS_GUNLOCK();
                        segmap_pagecreate(segkmap, raddr, rsize, 1);
@@ -982,39 +947,34 @@ afs_nfsrdwr(register struct vcache *avc, struct uio *auio, enum uio_rw arw,
     }
 
     if (!code && avc->vc_error) {
-       code = avc->vc_error;
+       code = code_checkcode = avc->vc_error;
     }
     ReleaseWriteLock(&avc->lock);
-    afs_BozonUnlock(&avc->pvnLock, avc);
     if (!code) {
-#ifdef AFS_SUN53_ENV
        if ((ioflag & FSYNC) && (arw == UIO_WRITE)
            && !AFS_NFSXLATORREQ(acred))
            code = afs_fsync(avc, 0, acred);
-#else
-       if ((ioflag & IO_SYNC) && (arw == UIO_WRITE)
-           && !AFS_NFSXLATORREQ(acred))
-           code = afs_fsync(avc, acred);
-#endif
     }
-#ifdef AFS_SUN52_ENV
     /* 
      * If things worked, add in as remaining in request any bytes
      * we didn't write due to file size ulimit.
      */
     if (code == 0 && extraResid > 0)
        auio->uio_resid += extraResid;
-#endif
-    return afs_CheckCode(code, &treq, 46);
+    if (code_checkcode) {
+       return code_checkcode;
+    } else {
+       return afs_CheckCode(code, &treq, 46);
+    }
 }
 
-int
-afs_map(struct vnode *vp, offset_t off, struct as *as, caddr_t *addr, u_int len, u_char prot, u_char maxprot, u_int flags, struct AFS_UCRED *cred)
+static int
+afs_map(struct vnode *vp, offset_t off, struct as *as, caddr_t *addr, size_t len, u_char prot, u_char maxprot, u_int flags, afs_ucred_t *cred)
 {
     struct segvn_crargs crargs;
-    register afs_int32 code;
+    afs_int32 code;
     struct vrequest treq;
-    register struct vcache *avc = VTOAFS(vp);
+    struct vcache *avc = VTOAFS(vp);
 
     AFS_STATCNT(afs_map);
 
@@ -1049,20 +1009,16 @@ afs_map(struct vnode *vp, offset_t off, struct as *as, caddr_t *addr, u_int len,
     if (code) {
        goto out;
     }
-    afs_BozonLock(&avc->pvnLock, avc);
     osi_FlushPages(avc, cred); /* ensure old pages are gone */
     avc->f.states |= CMAPPED;  /* flag cleared at afs_inactive */
-    afs_BozonUnlock(&avc->pvnLock, avc);
 
     AFS_GUNLOCK();
     as_rangelock(as);
     if ((flags & MAP_FIXED) == 0) {
-#if    defined(AFS_SUN57_ENV)
-       map_addr(addr, len, off, 1, flags);
-#elif  defined(AFS_SUN56_ENV)
-       map_addr(addr, len, off, 1);
+#ifdef MAPADDR_LACKS_VACALIGN
+       map_addr(addr, len, off, flags);
 #else
-       map_addr(addr, len, (off_t) off, 1);
+       map_addr(addr, len, off, 1, flags);
 #endif
        if (*addr == NULL) {
            as_rangeunlock(as);
@@ -1073,7 +1029,7 @@ afs_map(struct vnode *vp, offset_t off, struct as *as, caddr_t *addr, u_int len,
        (void)as_unmap(as, *addr, len); /* unmap old address space use */
     /* setup the create parameter block for the call */
     crargs.vp = AFSTOV(avc);
-    crargs.offset = (u_int) off;
+    crargs.offset = (u_offset_t)off;
     crargs.cred = cred;
     crargs.type = flags & MAP_TYPE;
     crargs.prot = prot;
@@ -1099,9 +1055,14 @@ afs_map(struct vnode *vp, offset_t off, struct as *as, caddr_t *addr, u_int len,
  * For Now We use standard local kernel params for AFS system values. Change this
  * at some point.
  */
-int
-afs_pathconf(struct vnode *vp, int cmd, u_long *outdatap, 
-            register struct AFS_UCRED *credp)
+static int
+#ifdef AFS_SUN511_ENV
+afs_pathconf(struct vnode *vp, int cmd, u_long *outdatap,
+            afs_ucred_t *credp, caller_context_t *ct)
+#else
+afs_pathconf(struct vnode *vp, int cmd, u_long *outdatap,
+            afs_ucred_t *credp)
+#endif /* AFS_SUN511_ENV */
 {
     AFS_STATCNT(afs_cntl);
     switch (cmd) {
@@ -1120,27 +1081,38 @@ afs_pathconf(struct vnode *vp, int cmd, u_long *outdatap,
     case _PC_NO_TRUNC:
        *outdatap = 1;
        break;
+    case _PC_FILESIZEBITS:
+#ifdef AFS_64BIT_CLIENT
+       *outdatap = 64;
+#else
+       *outdatap = 32;
+#endif
+       break;
     default:
-       return EINVAL;
+#ifdef AFS_SUN511_ENV
+       return fs_pathconf(vp, cmd, outdatap, credp, ct);
+#else
+       return fs_pathconf(vp, cmd, outdatap, credp);
+#endif /* AFS_SUN511_ENV */
     }
     return 0;
 }
 
-int
+static int
 afs_ioctl(struct vnode *vnp, int com, int arg, int flag, cred_t *credp, 
          int *rvalp)
 {
     return (ENOTTY);
 }
 
-void
+static void
 afs_rwlock(struct vnode *vnp, int wlock)
 {
     rw_enter(&(VTOAFS(vnp))->rwlock, (wlock ? RW_WRITER : RW_READER));
 }
 
 
-void
+static void
 afs_rwunlock(struct vnode *vnp, int wlock)
 {
     rw_exit(&(VTOAFS(vnp))->rwlock);
@@ -1148,10 +1120,10 @@ afs_rwunlock(struct vnode *vnp, int wlock)
 
 
 /* NOT SUPPORTED */
-int
+static int
 afs_seek(struct vnode *vnp, offset_t ooff, offset_t *noffp)
 {
-    register int code = 0;
+    int code = 0;
 
 #ifndef AFS_64BIT_CLIENT
 # define __MAXOFF_T MAXOFF_T
@@ -1164,19 +1136,16 @@ afs_seek(struct vnode *vnp, offset_t ooff, offset_t *noffp)
     return code;
 }
 
-int
+static int
 #ifdef AFS_SUN59_ENV
 afs_frlock(struct vnode *vnp, int cmd, struct flock64 *ap, int flag, 
-          offset_t off, struct flk_callback *flkcb, struct AFS_UCRED *credp)
-#elif defined(AFS_SUN56_ENV)
-afs_frlock(struct vnode *vnp, int cmd, struct flock64 *ap, int flag, 
-          offset_t off, struct AFS_UCRED *credp)
+          offset_t off, struct flk_callback *flkcb, afs_ucred_t *credp)
 #else
-afs_frlock(struct vnode *vnp, int cmd, struct flock *ap, int flag, 
-          offset_t off, struct AFS_UCRED *credp)
+afs_frlock(struct vnode *vnp, int cmd, struct flock64 *ap, int flag,
+          offset_t off, afs_ucred_t *credp)
 #endif
 {
-    register afs_int32 code = 0;
+    afs_int32 code = 0;
     /*
      * Implement based on afs_lockctl
      */
@@ -1187,20 +1156,11 @@ afs_frlock(struct vnode *vnp, int cmd, struct flock *ap, int flag,
 #endif
     if ((cmd == F_GETLK) || (cmd == F_O_GETLK) || (cmd == F_SETLK)
        || (cmd == F_SETLKW)) {
-#ifdef AFS_SUN53_ENV
        ap->l_pid = ttoproc(curthread)->p_pid;
        ap->l_sysid = 0;
-#else
-       ap->l_pid = ttoproc(curthread)->p_epid;
-       ap->l_sysid = ttoproc(curthread)->p_sysid;
-#endif
 
        AFS_GUNLOCK();
-#ifdef AFS_SUN56_ENV
        code = convoff(vnp, ap, 0, off);
-#else
-       code = convoff(vnp, ap, 0, (off_t) off);
-#endif
        if (code)
            return code;
        AFS_GLOCK();
@@ -1212,24 +1172,15 @@ afs_frlock(struct vnode *vnp, int cmd, struct flock *ap, int flag,
 }
 
 
-int
-#if    defined(AFS_SUN56_ENV)
+static int
 afs_space(struct vnode *vnp, int cmd, struct flock64 *ap, int flag, 
-         offset_t off, struct AFS_UCRED *credp)
-#else
-afs_space(struct vnode *vnp, int cmd, struct flock *ap, int flag, 
-         offset_t off, struct AFS_UCRED *credp)
-#endif
+         offset_t off, afs_ucred_t *credp)
 {
-    register afs_int32 code = EINVAL;
+    afs_int32 code = EINVAL;
     struct vattr vattr;
 
     if ((cmd == F_FREESP)
-#ifdef AFS_SUN56_ENV
        && ((code = convoff(vnp, ap, 0, off)) == 0)) {
-#else
-       && ((code = convoff(vnp, ap, 0, (off_t) off)) == 0)) {
-#endif
        AFS_GLOCK();
        if (!ap->l_len) {
            vattr.va_mask = AT_SIZE;
@@ -1241,7 +1192,7 @@ afs_space(struct vnode *vnp, int cmd, struct flock *ap, int flag,
     return (code);
 }
 
-int
+static int
 afs_dump(struct vnode *vp, caddr_t addr, int i1, int i2)
 {
     AFS_STATCNT(afs_dump);
@@ -1251,7 +1202,7 @@ afs_dump(struct vnode *vp, caddr_t addr, int i1, int i2)
 
 
 /* Nothing fancy here; just compare if vnodes are identical ones */
-int
+static int
 afs_cmp(struct vnode *vp1, struct vnode *vp2)
 {
     AFS_STATCNT(afs_cmp);
@@ -1259,7 +1210,7 @@ afs_cmp(struct vnode *vp1, struct vnode *vp2)
 }
 
 
-int
+static int
 afs_realvp(struct vnode *vp, struct vnode **vpp)
 {
     AFS_STATCNT(afs_realvp);
@@ -1267,7 +1218,7 @@ afs_realvp(struct vnode *vp, struct vnode **vpp)
 }
 
 
-int
+static int
 afs_pageio(struct vnode *vp, struct page *pp, u_int ui1, u_int ui2, int i1, 
           struct cred *credp)
 {
@@ -1275,7 +1226,7 @@ afs_pageio(struct vnode *vp, struct page *pp, u_int ui1, u_int ui2, int i1,
     return EINVAL;
 }
 
-int
+static int
 #ifdef AFS_SUN59_ENV
 afs_dumpctl(struct vnode *vp, int i, int *blkp)
 #else
@@ -1286,369 +1237,181 @@ afs_dumpctl(struct vnode *vp, int i)
     return EINVAL;
 }
 
-#ifdef AFS_SUN54_ENV
 #ifdef AFS_SUN511_ENV
-extern void
+static void
 afs_dispose(struct vnode *vp, struct page *p, int fl, int dn, struct cred *cr, struct caller_context_t *ct)
 {
     fs_dispose(vp, p, fl, dn, cr,ct);
 }
 
-int
+static int
 afs_setsecattr(struct vnode *vp, vsecattr_t *vsecattr, int flag, struct cred *creds, struct caller_context_t *ct)
 {
     return ENOSYS;
 }
 
-int
+static int
 afs_getsecattr(struct vnode *vp, vsecattr_t *vsecattr, int flag, struct cred *creds, struct caller_context_t *ct)
 {
   return fs_fab_acl(vp, vsecattr, flag, creds,ct);
 }
 #else
-extern void
+static void
 afs_dispose(struct vnode *vp, struct page *p, int fl, int dn, struct cred *cr)
 {
     fs_dispose(vp, p, fl, dn, cr);
 }
 
-int
+static int
 afs_setsecattr(struct vnode *vp, vsecattr_t *vsecattr, int flag, 
               struct cred *creds)
 {
     return ENOSYS;
 }
 
-int
+static int
 afs_getsecattr(struct vnode *vp, vsecattr_t *vsecattr, int flag, struct cred *creds)
 {
     return fs_fab_acl(vp, vsecattr, flag, creds);
 }
 #endif
-#endif
 
 #ifdef AFS_GLOBAL_SUNLOCK
-extern int gafs_open(register struct vcache **avcp, afs_int32 aflags, 
-                    struct AFS_UCRED *acred);
-extern int gafs_close(register struct vcache *avc, afs_int32 aflags, 
-                     int count, offset_t offset, struct AFS_UCRED *acred);
-extern int afs_ioctl(struct vnode *vnp, int com, int arg, int flag, 
-                    cred_t *credp, int *rvalp);
-extern int gafs_access(register struct vcache *avc, register afs_int32 amode,
-                      int flags, struct AFS_UCRED *acred);
-extern int gafs_getattr(register struct vcache *avc, 
-                       register struct vattr *attrs, int flags, 
-                       struct AFS_UCRED *acred);
-extern int gafs_setattr(register struct vcache *avc, 
-                       register struct vattr *attrs, int flags, 
-                       struct AFS_UCRED *acred);
-extern int gafs_lookup(register struct vcache *adp, char *aname, 
-                      register struct vcache **avcp, struct pathname *pnp,
-                      int flags, struct vnode *rdir, struct AFS_UCRED *acred);
-extern int gafs_remove(register struct vcache *adp, char *aname, 
-                      struct AFS_UCRED *acred);
-extern int gafs_link(register struct vcache *adp, register struct vcache *avc,
-                    char *aname, struct AFS_UCRED *acred);
-extern int gafs_rename(register struct vcache *aodp, char *aname1,
-                      register struct vcache *andp, char *aname2,
-                      struct AFS_UCRED *acred);
-extern int gafs_symlink(register struct vcache *adp, char *aname, 
-                       struct vattr *attrs, register char *atargetName, 
-                       struct AFS_UCRED *acred);
-extern int gafs_rmdir(register struct vcache *adp, char *aname, 
-                     struct vnode *cdirp, struct AFS_UCRED *acred);
-extern int gafs_mkdir(register struct vcache *adp, char *aname, 
-                     struct vattr *attrs, register struct vcache **avcp, 
-                     struct AFS_UCRED *acred);
-extern int
-#ifdef  AFS_SUN53_ENV
-gafs_fsync(register struct vcache *avc, int flag, struct AFS_UCRED *acred);
-#else
-gafs_fsync(register struct vcache *avc, struct AFS_UCRED *acred);
-#endif
-extern int gafs_readlink(register struct vcache *avc, struct uio *auio, 
-                        struct AFS_UCRED *acred);
-extern int gafs_readdir(register struct vcache *avc, struct uio *auio,
-                       struct AFS_UCRED *acred, int *eofp);
-extern void gafs_inactive(register struct vcache *avc, 
-                         struct AFS_UCRED *acred);
-extern int gafs_fid(struct vcache *avc, struct fid **fidpp);
-extern int gafs_create(register struct vcache *adp, char *aname, 
-                      struct vattr *attrs, enum vcexcl aexcl, int amode, 
-                      struct vcache **avcp, struct AFS_UCRED *acred);
-extern int afs_pathconf(struct vnode *vp, int cmd, u_long *outdatap,
-                       register struct AFS_UCRED *credp);
 
-#if defined(AFS_SUN511_ENV)
-/* The following list must always be NULL-terminated */
-const fs_operation_def_t afs_vnodeops_template[] = {
-    VOPNAME_OPEN,              { .vop_open = gafs_open },
-    VOPNAME_CLOSE,             { .vop_close = gafs_close },
-    VOPNAME_READ,              { .vop_read = afs_vmread },
-    VOPNAME_WRITE,             { .vop_write = afs_vmwrite },
-    VOPNAME_IOCTL,             { .vop_ioctl = afs_ioctl },
-    VOPNAME_SETFL,             { .vop_setfl = fs_setfl },
-    VOPNAME_GETATTR,           { .vop_getattr = gafs_getattr },
-    VOPNAME_SETATTR,           { .vop_setattr = gafs_setattr },
-    VOPNAME_ACCESS,            { .vop_access = gafs_access },
-    VOPNAME_LOOKUP,            { .vop_lookup = gafs_lookup },
-    VOPNAME_CREATE,            { .vop_create = gafs_create },
-    VOPNAME_REMOVE,            { .vop_remove = gafs_remove },
-    VOPNAME_LINK,              { .vop_link = gafs_link },
-    VOPNAME_RENAME,            { .vop_rename = gafs_rename },
-    VOPNAME_MKDIR,             { .vop_mkdir = gafs_mkdir },
-    VOPNAME_RMDIR,             { .vop_rmdir = gafs_rmdir },
-    VOPNAME_READDIR,           { .vop_readdir = gafs_readdir },
-    VOPNAME_SYMLINK,           { .vop_symlink = gafs_symlink },   
-    VOPNAME_READLINK,          { .vop_readlink = gafs_readlink },
-    VOPNAME_FSYNC,             { .vop_fsync = gafs_fsync },
-    VOPNAME_INACTIVE,          { .vop_inactive = gafs_inactive },
-    VOPNAME_FID,               { .vop_fid = gafs_fid },
-    VOPNAME_RWLOCK,            { .vop_rwlock = afs_rwlock },
-    VOPNAME_RWUNLOCK,          { .vop_rwunlock = afs_rwunlock },
-    VOPNAME_SEEK,              { .vop_seek = afs_seek },
-    VOPNAME_CMP,               { .vop_cmp = afs_cmp },
-    VOPNAME_FRLOCK,            { .vop_frlock = afs_frlock },
-    VOPNAME_SPACE,             { .vop_space = afs_space },
-    VOPNAME_REALVP,            { .vop_realvp = afs_realvp },
-    VOPNAME_GETPAGE,           { .vop_getpage = afs_getpage },
-    VOPNAME_PUTPAGE,           { .vop_putpage = afs_putpage },
-    VOPNAME_MAP,               { .vop_map = afs_map },
-    VOPNAME_ADDMAP,            { .vop_addmap = afs_addmap },
-    VOPNAME_DELMAP,            { .vop_delmap = afs_delmap },
-    VOPNAME_POLL,              { .vop_poll = fs_poll },
-    VOPNAME_PATHCONF,          { .vop_pathconf = afs_pathconf },
-    VOPNAME_PAGEIO,            { .vop_pageio = afs_pageio },
-    VOPNAME_DUMP,              { .vop_dump = afs_dump },
-    VOPNAME_DUMPCTL,           { .vop_dumpctl = afs_dumpctl },   
-    VOPNAME_DISPOSE,           { .vop_dispose = afs_dispose },
-    VOPNAME_GETSECATTR,                { .vop_getsecattr = afs_getsecattr },
-    VOPNAME_SETSECATTR,        { .vop_setsecattr = afs_setsecattr },
-    VOPNAME_SHRLOCK,           { .vop_shrlock = fs_shrlock },
-    NULL,                      NULL
-};
-vnodeops_t *afs_ops;
-#elif defined(AFS_SUN510_ENV)
-/* The following list must always be NULL-terminated */
-const fs_operation_def_t afs_vnodeops_template[] = {
-    VOPNAME_OPEN,              gafs_open,
-    VOPNAME_CLOSE,             gafs_close,
-    VOPNAME_READ,              afs_vmread,
-    VOPNAME_WRITE,             afs_vmwrite,
-    VOPNAME_IOCTL,             afs_ioctl,
-    VOPNAME_SETFL,             fs_setfl,
-    VOPNAME_GETATTR,           gafs_getattr,
-    VOPNAME_SETATTR,           gafs_setattr,
-    VOPNAME_ACCESS,            gafs_access,
-    VOPNAME_LOOKUP,            gafs_lookup,
-    VOPNAME_CREATE,            gafs_create,
-    VOPNAME_REMOVE,            gafs_remove,
-    VOPNAME_LINK,              gafs_link,
-    VOPNAME_RENAME,            gafs_rename,
-    VOPNAME_MKDIR,             gafs_mkdir,
-    VOPNAME_RMDIR,             gafs_rmdir,
-    VOPNAME_READDIR,           gafs_readdir,
-    VOPNAME_SYMLINK,           gafs_symlink,   
-    VOPNAME_READLINK,          gafs_readlink,
-    VOPNAME_FSYNC,             gafs_fsync,
-    VOPNAME_INACTIVE,          gafs_inactive,
-    VOPNAME_FID,               gafs_fid,
-    VOPNAME_RWLOCK,            afs_rwlock,
-    VOPNAME_RWUNLOCK,          afs_rwunlock,
-    VOPNAME_SEEK,              afs_seek,
-    VOPNAME_CMP,               afs_cmp,
-    VOPNAME_FRLOCK,            afs_frlock,
-    VOPNAME_SPACE,             afs_space,
-    VOPNAME_REALVP,            afs_realvp,
-    VOPNAME_GETPAGE,           afs_getpage,
-    VOPNAME_PUTPAGE,           afs_putpage,
-    VOPNAME_MAP,               afs_map,
-    VOPNAME_ADDMAP,            afs_addmap,
-    VOPNAME_DELMAP,            afs_delmap,
-    VOPNAME_POLL,              fs_poll,
-    VOPNAME_DUMP,              afs_dump,
-    VOPNAME_PATHCONF,          afs_pathconf,
-    VOPNAME_PAGEIO,            afs_pageio,
-    VOPNAME_DUMPCTL,           afs_dumpctl,   
-    VOPNAME_DISPOSE,           afs_dispose,
-    VOPNAME_GETSECATTR,       afs_getsecattr,
-    VOPNAME_SETSECATTR,        afs_setsecattr,
-    VOPNAME_SHRLOCK,           fs_shrlock,
-    NULL,                     NULL
-};
-struct vnodeops *afs_ops;
-#else
-struct vnodeops Afs_vnodeops = {
-    gafs_open,
-    gafs_close,
-    afs_vmread,
-    afs_vmwrite,
-    afs_ioctl,
-    fs_setfl,
-    gafs_getattr,
-    gafs_setattr,
-    gafs_access,
-    gafs_lookup,
-    gafs_create,
-    gafs_remove,
-    gafs_link,
-    gafs_rename,
-    gafs_mkdir,
-    gafs_rmdir,
-    gafs_readdir,
-    gafs_symlink,
-    gafs_readlink,
-    gafs_fsync,
-    gafs_inactive,
-    gafs_fid,
-    afs_rwlock,
-    afs_rwunlock,
-    afs_seek,
-    afs_cmp,
-    afs_frlock,
-    afs_space,
-    afs_realvp,
-    afs_getpage,
-    afs_putpage,
-    afs_map,
-    afs_addmap,
-    afs_delmap,
-    fs_poll,
-    afs_dump,
-    afs_pathconf,
-    afs_pageio,
-    afs_dumpctl,
-#ifdef AFS_SUN54_ENV
-    afs_dispose,
-    afs_setsecattr,
-    afs_getsecattr,
-#endif
-#if    defined(AFS_SUN56_ENV)
-    fs_shrlock,
-#endif
-};
-struct vnodeops *afs_ops = &Afs_vnodeops;
-#endif
-
-int
-gafs_open(register struct vcache **avcp, afs_int32 aflags, 
-         struct AFS_UCRED *acred)
+static int
+gafs_open(struct vnode **vpp, afs_int32 aflags, 
+         afs_ucred_t *acred)
 {
-    register int code;
+    int code;
+    struct vcache *avc = VTOAFS(*vpp);
 
     AFS_GLOCK();
-    code = afs_open(avcp, aflags, acred);
+    code = afs_open(&avc, aflags, acred);
     AFS_GUNLOCK();
+
+    /* afs_open currently never changes avc, but just in case... */
+    *vpp = AFSTOV(avc);
+
     return (code);
 }
 
-int
-gafs_close(register struct vcache *avc, afs_int32 aflags, int count, 
-          offset_t offset, struct AFS_UCRED *acred)
+static int
+gafs_close(struct vnode *vp, afs_int32 aflags, int count, 
+          offset_t offset, afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_close(avc, aflags, count, offset, acred);
+    code = afs_close(VTOAFS(vp), aflags, count, offset, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
-int
-gafs_getattr(register struct vcache *avc, register struct vattr *attrs, 
-            int flags, struct AFS_UCRED *acred)
+static int
+gafs_getattr(struct vnode *vp, struct vattr *attrs, 
+            int flags, afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_getattr(avc, attrs, flags, acred);
+    code = afs_getattr(VTOAFS(vp), attrs, flags, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
 
-int
-gafs_setattr(register struct vcache *avc, register struct vattr *attrs, 
-            int flags, struct AFS_UCRED *acred)
+static int
+gafs_setattr(struct vnode *vp, struct vattr *attrs, 
+            int flags, afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_setattr(avc, attrs, flags, acred);
+    code = afs_setattr(VTOAFS(vp), attrs, flags, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
 
-int
-gafs_access(register struct vcache *avc, register afs_int32 amode, int flags, 
-           struct AFS_UCRED *acred)
+static int
+gafs_access(struct vnode *vp, afs_int32 amode, int flags, 
+           afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_access(avc, amode, flags, acred);
+    code = afs_access(VTOAFS(vp), amode, flags, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
 
-int
-gafs_lookup(register struct vcache *adp, char *aname, 
-           register struct vcache **avcp, struct pathname *pnp, int flags, 
-           struct vnode *rdir, struct AFS_UCRED *acred)
+static int
+gafs_lookup(struct vnode *dvp, char *aname, 
+           struct vnode **vpp, struct pathname *pnp, int flags, 
+           struct vnode *rdir, afs_ucred_t *acred)
 {
-    register int code;
+    int code;
+    struct vcache *tvc = NULL;
 
     AFS_GLOCK();
-    code = afs_lookup(adp, aname, avcp, pnp, flags, rdir, acred);
+    code = afs_lookup(VTOAFS(dvp), aname, &tvc, pnp, flags, rdir, acred);
     AFS_GUNLOCK();
+
+    *vpp = NULL;
+    if (tvc) {
+        *vpp = AFSTOV(tvc);
+    }
+
     return (code);
 }
 
 
-int
-gafs_create(register struct vcache *adp, char *aname, struct vattr *attrs, 
-           enum vcexcl aexcl, int amode, struct vcache **avcp, 
-           struct AFS_UCRED *acred)
+static int
+gafs_create(struct vnode *dvp, char *aname, struct vattr *attrs, 
+           enum vcexcl aexcl, int amode, struct vnode **vpp, 
+           afs_ucred_t *acred)
 {
-    register int code;
+    int code;
+    struct vcache *tvc = NULL;
 
     AFS_GLOCK();
-    code = afs_create(adp, aname, attrs, aexcl, amode, avcp, acred);
+    code = afs_create(VTOAFS(dvp), aname, attrs, aexcl, amode, &tvc, acred);
     AFS_GUNLOCK();
+
+    *vpp = NULL;
+    if (tvc) {
+        *vpp = AFSTOV(tvc);
+    }
+
     return (code);
 }
 
-int
-gafs_remove(register struct vcache *adp, char *aname, struct AFS_UCRED *acred)
+static int
+gafs_remove(struct vnode *vp, char *aname, afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_remove(adp, aname, acred);
+    code = afs_remove(VTOAFS(vp), aname, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
-int
-gafs_link(register struct vcache *adp, register struct vcache *avc, 
-         char *aname, struct AFS_UCRED *acred)
+static int
+gafs_link(struct vnode *dvp, struct vnode *svp, 
+         char *aname, afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_link(adp, avc, aname, acred);
+    code = afs_link(VTOAFS(dvp), VTOAFS(svp), aname, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
-int
-gafs_rename(register struct vcache *aodp, char *aname1, 
-           register struct vcache *andp, char *aname2, 
-           struct AFS_UCRED *acred)
+static int
+gafs_rename(struct vnode *odvp, char *aname1, 
+           struct vnode *ndvp, char *aname2, 
+           afs_ucred_t *acred)
 {
-    register int code;
+    int code;
+    struct vcache *aodp = VTOAFS(odvp);
+    struct vcache *andp = VTOAFS(ndvp);
 
     AFS_GLOCK();
     code = afs_rename(aodp, aname1, andp, aname2, acred);
@@ -1659,7 +1422,10 @@ gafs_rename(register struct vcache *aodp, char *aname1,
        (void) afs_lookup(andp, aname2, &avcp, NULL, 0, NULL, acred);
        if (avcp) {
            struct vnode *vp = AFSTOV(avcp), *pvp = AFSTOV(andp);
-           
+
+# ifdef HAVE_VN_RENAMEPATH
+           vn_renamepath(pvp, vp, aname2, strlen(aname2));
+# else
            mutex_enter(&vp->v_lock);
            if (vp->v_path != NULL) {
                kmem_free(vp->v_path, strlen(vp->v_path) + 1);
@@ -1667,8 +1433,9 @@ gafs_rename(register struct vcache *aodp, char *aname1,
            }
            mutex_exit(&vp->v_lock);
            vn_setpath(afs_globalVp, pvp, vp, aname2, strlen(aname2));
+# endif /* !HAVE_VN_RENAMEPATH */
 
-           AFS_RELE(avcp);
+           AFS_RELE(AFSTOV(avcp));
        }
     }
 #endif
@@ -1676,91 +1443,85 @@ gafs_rename(register struct vcache *aodp, char *aname1,
     return (code);
 }
 
-int
-gafs_mkdir(register struct vcache *adp, char *aname, struct vattr *attrs, 
-          register struct vcache **avcp, struct AFS_UCRED *acred)
+static int
+gafs_mkdir(struct vnode *dvp, char *aname, struct vattr *attrs, 
+          struct vnode **vpp, afs_ucred_t *acred)
 {
-    register int code;
+    int code;
+    struct vcache *tvc = NULL;
 
     AFS_GLOCK();
-    code = afs_mkdir(adp, aname, attrs, avcp, acred);
+    code = afs_mkdir(VTOAFS(dvp), aname, attrs, &tvc, acred);
     AFS_GUNLOCK();
+
+    *vpp = NULL;
+    if (tvc) {
+        *vpp = AFSTOV(tvc);
+    }
+
     return (code);
 }
 
-int
-gafs_rmdir(register struct vcache *adp, char *aname, struct vnode *cdirp, 
-          struct AFS_UCRED *acred)
+static int
+gafs_rmdir(struct vnode *vp, char *aname, struct vnode *cdirp, 
+          afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_rmdir(adp, aname, cdirp, acred);
+    code = afs_rmdir(VTOAFS(vp), aname, cdirp, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
 
-int
-gafs_readdir(register struct vcache *avc, struct uio *auio,
-            struct AFS_UCRED *acred, int *eofp)
+static int
+gafs_readdir(struct vnode *vp, struct uio *auio,
+            afs_ucred_t *acred, int *eofp)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_readdir(avc, auio, acred, eofp);
+    code = afs_readdir(VTOAFS(vp), auio, acred, eofp);
     AFS_GUNLOCK();
     return (code);
 }
 
-int
-gafs_symlink(register struct vcache *adp, char *aname, struct vattr *attrs,
-            register char *atargetName, struct AFS_UCRED *acred)
+static int
+gafs_symlink(struct vnode *vp, char *aname, struct vattr *attrs,
+            char *atargetName, afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_symlink(adp, aname, attrs, atargetName, acred);
+    code = afs_symlink(VTOAFS(vp), aname, attrs, atargetName, NULL, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
 
-int
-gafs_readlink(register struct vcache *avc, struct uio *auio, struct AFS_UCRED *acred)
+static int
+gafs_readlink(struct vnode *vp, struct uio *auio, afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_readlink(avc, auio, acred);
+    code = afs_readlink(VTOAFS(vp), auio, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
-int
-#ifdef AFS_SUN53_ENV
-gafs_fsync(register struct vcache *avc, int flag, struct AFS_UCRED *acred)
-#else
-gafs_fsync(register struct vcache *avc, struct AFS_UCRED *acred)
-#endif
+static int
+gafs_fsync(struct vnode *vp, int flag, afs_ucred_t *acred)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-#ifdef AFS_SUN53_ENV
-    code = afs_fsync(avc, flag, acred);
-#else
-    code = afs_fsync(avc, acred);
-#endif
+    code = afs_fsync(VTOAFS(vp), flag, acred);
     AFS_GUNLOCK();
     return (code);
 }
 
-int
-afs_inactive(struct vcache *avc, struct AFS_UCRED *acred)
+static int
+afs_inactive(struct vcache *avc, afs_ucred_t *acred)
 {
     struct vnode *vp = AFSTOV(avc);
-    if (afs_shuttingdown)
+    if (afs_shuttingdown != AFS_RUNNING)
        return 0;
 
     /*
@@ -1781,39 +1542,194 @@ afs_inactive(struct vcache *avc, struct AFS_UCRED *acred)
     }
     mutex_exit(&vp->v_lock);
 
+#ifndef AFS_SUN511_ENV
     /*
      * Solaris calls VOP_OPEN on exec, but doesn't call VOP_CLOSE when
      * the executable exits.  So we clean up the open count here.
      *
-     * Only do this for mvstat 0 vnodes: when using fakestat, we can't
-     * lose the open count for volume roots (mvstat 2), even though they
+     * Only do this for AFS_MVSTAT_FILE vnodes: when using fakestat, we can't
+     * lose the open count for volume roots (AFS_MVSTAT_ROOT), even though they
      * will get VOP_INACTIVE'd when released by afs_PutFakeStat().
      */
-    if (avc->opens > 0 && avc->mvstat == 0 && !(avc->f.states & CCore))
+    if (avc->opens > 0 && avc->mvstat == AFS_MVSTAT_FILE && !(avc->f.states & CCore))
        avc->opens = avc->execsOrWriters = 0;
+#endif
 
     afs_InactiveVCache(avc, acred);
+
+    AFS_GUNLOCK();
+    /* VFS_RELE must be called outside of GLOCK, since it can potentially
+     * call afs_freevfs, which acquires GLOCK */
+    VFS_RELE(afs_globalVFS);
+    AFS_GLOCK();
+
     return 0;
 }
 
-void
-gafs_inactive(register struct vcache *avc, struct AFS_UCRED *acred)
+static void
+gafs_inactive(struct vnode *vp, afs_ucred_t *acred)
 {
     AFS_GLOCK();
-    (void)afs_inactive(avc, acred);
+    (void)afs_inactive(VTOAFS(vp), acred);
     AFS_GUNLOCK();
 }
 
 
-int
-gafs_fid(struct vcache *avc, struct fid **fidpp)
+static int
+gafs_fid(struct vnode *vp, struct fid **fidpp)
 {
-    register int code;
-
+    int code;
     AFS_GLOCK();
-    code = afs_fid(avc, fidpp);
+    code = afs_fid(VTOAFS(vp), fidpp);
     AFS_GUNLOCK();
     return (code);
 }
 
+#if defined(AFS_SUN511_ENV)
+/* The following list must always be NULL-terminated */
+const fs_operation_def_t afs_vnodeops_template[] = {
+    VOPNAME_OPEN,              { .vop_open = gafs_open },
+    VOPNAME_CLOSE,             { .vop_close = gafs_close },
+    VOPNAME_READ,              { .vop_read = afs_vmread },
+    VOPNAME_WRITE,             { .vop_write = afs_vmwrite },
+    VOPNAME_IOCTL,             { .vop_ioctl = afs_ioctl },
+    VOPNAME_SETFL,             { .vop_setfl = fs_setfl },
+    VOPNAME_GETATTR,           { .vop_getattr = gafs_getattr },
+    VOPNAME_SETATTR,           { .vop_setattr = gafs_setattr },
+    VOPNAME_ACCESS,            { .vop_access = gafs_access },
+    VOPNAME_LOOKUP,            { .vop_lookup = gafs_lookup },
+    VOPNAME_CREATE,            { .vop_create = gafs_create },
+    VOPNAME_REMOVE,            { .vop_remove = gafs_remove },
+    VOPNAME_LINK,              { .vop_link = gafs_link },
+    VOPNAME_RENAME,            { .vop_rename = gafs_rename },
+    VOPNAME_MKDIR,             { .vop_mkdir = gafs_mkdir },
+    VOPNAME_RMDIR,             { .vop_rmdir = gafs_rmdir },
+    VOPNAME_READDIR,           { .vop_readdir = gafs_readdir },
+    VOPNAME_SYMLINK,           { .vop_symlink = gafs_symlink },
+    VOPNAME_READLINK,          { .vop_readlink = gafs_readlink },
+    VOPNAME_FSYNC,             { .vop_fsync = gafs_fsync },
+    VOPNAME_INACTIVE,          { .vop_inactive = gafs_inactive },
+    VOPNAME_FID,               { .vop_fid = gafs_fid },
+    VOPNAME_RWLOCK,            { .vop_rwlock = afs_rwlock },
+    VOPNAME_RWUNLOCK,          { .vop_rwunlock = afs_rwunlock },
+    VOPNAME_SEEK,              { .vop_seek = afs_seek },
+    VOPNAME_CMP,               { .vop_cmp = afs_cmp },
+    VOPNAME_FRLOCK,            { .vop_frlock = afs_frlock },
+    VOPNAME_SPACE,             { .vop_space = afs_space },
+    VOPNAME_REALVP,            { .vop_realvp = afs_realvp },
+    VOPNAME_GETPAGE,           { .vop_getpage = afs_getpage },
+    VOPNAME_PUTPAGE,           { .vop_putpage = afs_putpage },
+    VOPNAME_MAP,               { .vop_map = afs_map },
+    VOPNAME_ADDMAP,            { .vop_addmap = afs_addmap },
+    VOPNAME_DELMAP,            { .vop_delmap = afs_delmap },
+    VOPNAME_POLL,              { .vop_poll = fs_poll },
+    VOPNAME_PATHCONF,          { .vop_pathconf = afs_pathconf },
+    VOPNAME_PAGEIO,            { .vop_pageio = afs_pageio },
+    VOPNAME_DUMP,              { .vop_dump = afs_dump },
+    VOPNAME_DUMPCTL,           { .vop_dumpctl = afs_dumpctl },
+    VOPNAME_DISPOSE,           { .vop_dispose = afs_dispose },
+    VOPNAME_GETSECATTR,                { .vop_getsecattr = afs_getsecattr },
+    VOPNAME_SETSECATTR,        { .vop_setsecattr = afs_setsecattr },
+    VOPNAME_SHRLOCK,           { .vop_shrlock = fs_shrlock },
+    NULL,                      NULL
+};
+vnodeops_t *afs_ops;
+#elif defined(AFS_SUN510_ENV)
+/* The following list must always be NULL-terminated */
+const fs_operation_def_t afs_vnodeops_template[] = {
+    VOPNAME_OPEN,              gafs_open,
+    VOPNAME_CLOSE,             gafs_close,
+    VOPNAME_READ,              afs_vmread,
+    VOPNAME_WRITE,             afs_vmwrite,
+    VOPNAME_IOCTL,             afs_ioctl,
+    VOPNAME_SETFL,             fs_setfl,
+    VOPNAME_GETATTR,           gafs_getattr,
+    VOPNAME_SETATTR,           gafs_setattr,
+    VOPNAME_ACCESS,            gafs_access,
+    VOPNAME_LOOKUP,            gafs_lookup,
+    VOPNAME_CREATE,            gafs_create,
+    VOPNAME_REMOVE,            gafs_remove,
+    VOPNAME_LINK,              gafs_link,
+    VOPNAME_RENAME,            gafs_rename,
+    VOPNAME_MKDIR,             gafs_mkdir,
+    VOPNAME_RMDIR,             gafs_rmdir,
+    VOPNAME_READDIR,           gafs_readdir,
+    VOPNAME_SYMLINK,           gafs_symlink,
+    VOPNAME_READLINK,          gafs_readlink,
+    VOPNAME_FSYNC,             gafs_fsync,
+    VOPNAME_INACTIVE,          gafs_inactive,
+    VOPNAME_FID,               gafs_fid,
+    VOPNAME_RWLOCK,            afs_rwlock,
+    VOPNAME_RWUNLOCK,          afs_rwunlock,
+    VOPNAME_SEEK,              afs_seek,
+    VOPNAME_CMP,               afs_cmp,
+    VOPNAME_FRLOCK,            afs_frlock,
+    VOPNAME_SPACE,             afs_space,
+    VOPNAME_REALVP,            afs_realvp,
+    VOPNAME_GETPAGE,           afs_getpage,
+    VOPNAME_PUTPAGE,           afs_putpage,
+    VOPNAME_MAP,               afs_map,
+    VOPNAME_ADDMAP,            afs_addmap,
+    VOPNAME_DELMAP,            afs_delmap,
+    VOPNAME_POLL,              fs_poll,
+    VOPNAME_DUMP,              afs_dump,
+    VOPNAME_PATHCONF,          afs_pathconf,
+    VOPNAME_PAGEIO,            afs_pageio,
+    VOPNAME_DUMPCTL,           afs_dumpctl,
+    VOPNAME_DISPOSE,           afs_dispose,
+    VOPNAME_GETSECATTR,       afs_getsecattr,
+    VOPNAME_SETSECATTR,        afs_setsecattr,
+    VOPNAME_SHRLOCK,           fs_shrlock,
+    NULL,                     NULL
+};
+struct vnodeops *afs_ops;
+#else
+struct vnodeops Afs_vnodeops = {
+    gafs_open,
+    gafs_close,
+    afs_vmread,
+    afs_vmwrite,
+    afs_ioctl,
+    fs_setfl,
+    gafs_getattr,
+    gafs_setattr,
+    gafs_access,
+    gafs_lookup,
+    gafs_create,
+    gafs_remove,
+    gafs_link,
+    gafs_rename,
+    gafs_mkdir,
+    gafs_rmdir,
+    gafs_readdir,
+    gafs_symlink,
+    gafs_readlink,
+    gafs_fsync,
+    gafs_inactive,
+    gafs_fid,
+    afs_rwlock,
+    afs_rwunlock,
+    afs_seek,
+    afs_cmp,
+    afs_frlock,
+    afs_space,
+    afs_realvp,
+    afs_getpage,
+    afs_putpage,
+    afs_map,
+    afs_addmap,
+    afs_delmap,
+    fs_poll,
+    afs_dump,
+    afs_pathconf,
+    afs_pageio,
+    afs_dumpctl,
+    afs_dispose,
+    afs_setsecattr,
+    afs_getsecattr,
+    fs_shrlock,
+};
+struct vnodeops *afs_ops = &Afs_vnodeops;
+#endif
+
 #endif /* AFS_GLOBAL_SUNLOCK */