Clean up the prefetch code for Linux, by calling afs_PrefetchChunk
[openafs.git] / src / afs / VNOPS / afs_vnop_read.c
index a0222f4..142c686 100644 (file)
@@ -258,7 +258,7 @@ tagain:
                ReleaseReadLock(&avc->lock);
                tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 1);
                ObtainReadLock(&avc->lock);
-               ObtainReadLock(&tdc->lock);
+               if (tdc) ObtainReadLock(&tdc->lock);
            }
        }
 
@@ -330,7 +330,7 @@ tagain:
      */
     if (tdc) {
        ReleaseReadLock(&tdc->lock);
-#ifndef        AFS_VM_RDWR_ENV
+#if !defined(AFS_VM_RDWR_ENV)
        /* try to queue prefetch, if needed */
        if (!noLock) {
            afs_PrefetchChunk(avc, tdc, acred, &treq);
@@ -535,6 +535,13 @@ afs_UFSReadFast(avc, auio, acred, albn, abpp, noLock)
             VOP_UNLOCK(tfile->vnode, 0, current_proc());
             AFS_GLOCK();
 #else
+#if defined(AFS_FBSD_ENV)
+            AFS_GUNLOCK();
+            VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc);
+            code = VOP_READ(tfile->vnode, auio, 0, &afs_osi_cred);
+            VOP_UNLOCK(tfile->vnode, 0, curproc);
+            AFS_GLOCK();
+#else
            code = VOP_RDWR(tfile->vnode, auio, UIO_READ, 0, &afs_osi_cred);
 #endif
 #endif
@@ -543,6 +550,7 @@ afs_UFSReadFast(avc, auio, acred, albn, abpp, noLock)
 #endif
 #endif
 #endif
+#endif
            auio->afsio_offset += avc->quick.minLoc;
            osi_UFSClose(tfile);
            /* Fix up LRU info */
@@ -551,7 +559,7 @@ afs_UFSReadFast(avc, auio, acred, albn, abpp, noLock)
 
            if (!noLock) {
                ReleaseReadLock(&avc->lock);
-#ifndef        AFS_VM_RDWR_ENV
+#if !defined(AFS_VM_RDWR_ENV)
                if (!(code = afs_InitReq(&treq, acred))) {
                    if (!(tdc->mflags & DFNextStarted))
                        afs_PrefetchChunk(avc, tdc, acred, &treq);
@@ -601,7 +609,7 @@ afs_UFSRead(avc, auio, acred, albn, abpp, noLock)
     struct vrequest treq;
 
     AFS_STATCNT(afs_UFSRead);
-    if (avc->vc_error)
+    if (avc && avc->vc_error)
        return EIO;
 
     /* check that we have the latest status info in the vnode cache */
@@ -793,7 +801,7 @@ tagain:
                ReleaseReadLock(&avc->lock);
                tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 1);
                ObtainReadLock(&avc->lock);
-               ObtainReadLock(&tdc->lock);
+               if (tdc) ObtainReadLock(&tdc->lock);
            }
        }
        
@@ -926,6 +934,13 @@ tagain:
             VOP_UNLOCK(tfile->vnode, 0, current_proc());
             AFS_GLOCK();
 #else
+#if defined(AFS_FBSD_ENV)
+            AFS_GUNLOCK();
+            VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc);
+            code = VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred);
+            VOP_UNLOCK(tfile->vnode, 0, curproc);
+            AFS_GLOCK();
+#else
            code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, &afs_osi_cred);
 #endif
 #endif
@@ -935,6 +950,7 @@ tagain:
 #endif
 #endif
 #endif
+#endif
 
 #ifdef IHINT
             if (!tdc->ihint && nihints < maxIHint) {
@@ -966,7 +982,7 @@ tagain:
      */
     if (tdc) {
        ReleaseReadLock(&tdc->lock);
-#ifndef        AFS_VM_RDWR_ENV
+#if !defined(AFS_VM_RDWR_ENV)
        /* try to queue prefetch, if needed */
        if (!noLock) {
            if (!(tdc->mflags & DFNextStarted))