linux-flock-downmap-64-ops-20021120
[openafs.git] / src / afs / LINUX / osi_vnodeops.c
index ae11f4e..dd11032 100644 (file)
  */
 
 #include <afsconfig.h>
-#include "../afs/param.h"
+#include "afs/param.h"
 
 RCSID("$Header$");
 
-#include "../afs/sysincludes.h"
-#include "../afs/afsincludes.h"
-#include "../afs/afs_stats.h"
-#include "../afs/afs_osidnlc.h"
-#include "../h/mm.h"
-#include "../h/pagemap.h"
+#include "afs/sysincludes.h"
+#include "afsincludes.h"
+#include "afs/afs_stats.h"
+#include "afs/afs_osidnlc.h"
+#include "h/mm.h"
+#include "h/pagemap.h"
 #if defined(AFS_LINUX24_ENV)
-#include "../h/smp_lock.h"
+#include "h/smp_lock.h"
 #endif
 
 #ifdef pgoff2loff
@@ -105,6 +105,10 @@ static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count,
             code = afs_read(vcp, &tuio, credp, 0, 0, 0);
            xfered += count - tuio.uio_resid;
            if (code != 0) {
+               afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
+                       ICL_TYPE_OFFSET, offp,
+                       ICL_TYPE_INT32, -1,
+                       ICL_TYPE_INT32, code);
                code = xfered;
                *offp += count - tuio.uio_resid;
            } else {
@@ -334,7 +338,7 @@ tagain:
        if (!dirpos)
            break;
 
-       de = (struct DirEntry*)afs_dir_GetBlob(&tdc->f.inode, dirpos);
+       de = afs_dir_GetBlob(&tdc->f.inode, dirpos);
        if (!de)
            break;
 
@@ -356,7 +360,7 @@ tagain:
              if ((avc->states & CForeign) == 0 &&
                  (ntohl(de->fid.vnode) & 1)) {
                 type=DT_DIR;
-             } else if ((tvc=afs_FindVCache(&afid,0,0,0,0))) {
+             } else if ((tvc=afs_FindVCache(&afid,0,0))) {
                   if (tvc->mvstat) {
                        type=DT_DIR;
                   } else if (((tvc->states) & (CStatd|CTruth))) {
@@ -373,7 +377,7 @@ tagain:
                        /* what other types does AFS support? */
                   }
                   /* clean up from afs_FindVCache */
-                  afs_PutVCache(tvc, WRITE_LOCK);
+                  afs_PutVCache(tvc);
              }
              code = (*filldir)(dirbuf, de->name, len, offset, ino, type);
         }
@@ -637,6 +641,16 @@ static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
     flock.l_start = flp->fl_start;
     flock.l_len = flp->fl_end - flp->fl_start;
 
+    /* Safe because there are no large files, yet */
+#if F_GETLK != F_GETLK64
+    if (cmd = F_GETLK64)
+       cmd = F_GETLK;
+    else if (cmd = F_SETLK64)
+       cmd = F_SETLK;
+    else if (cmd = F_SETLKW64)
+       cmd = F_SETLKW;
+#endif /* F_GETLK != F_GETLK64 */
+
     AFS_GLOCK();
     code = afs_lockctl(vcp, &flock, cmd, credp);
     AFS_GUNLOCK();
@@ -778,7 +792,7 @@ static int afs_linux_revalidate(struct dentry *dp)
     if (afs_fakestat_enable && vcp->mvstat == 1 && vcp->mvid &&
        (vcp->states & CMValid) && (vcp->states & CStatd)) {
        ObtainSharedLock(&afs_xvcache, 680);
-       rootvp = afs_FindVCache(vcp->mvid, 0, 0, 0, 0);
+       rootvp = afs_FindVCache(vcp->mvid, 0, 0);
        ReleaseSharedLock(&afs_xvcache);
     }
 
@@ -797,7 +811,7 @@ static int afs_linux_revalidate(struct dentry *dp)
 #ifdef AFS_LINUX24_ENV
        unlock_kernel();
 #endif
-       if (rootvp) afs_PutVCache(rootvp, 0);
+       if (rootvp) afs_PutVCache(rootvp);
        AFS_GUNLOCK();
        return 0;
     }
@@ -840,6 +854,7 @@ static int afs_linux_dentry_revalidate(struct dentry *dp)
     struct vcache *parentvcp = ITOAFS(dp->d_parent->d_inode);
 
     AFS_GLOCK();
+    lock_kernel();
 
     sysState.allocked = 0;
 
@@ -854,14 +869,14 @@ static int afs_linux_dentry_revalidate(struct dentry *dp)
        goto done;
     }
 
-    if (code = afs_InitReq(&treq, credp))
+    if ((code = afs_InitReq(&treq, credp)))
         goto done;
 
     Check_AtSys(parentvcp, dp->d_name.name, &sysState, &treq);
     name = sysState.name;
 
     /* First try looking up the DNLC */
-    if (lookupvcp = osi_dnlc_lookup(parentvcp, name, WRITE_LOCK)) {
+    if ((lookupvcp = osi_dnlc_lookup(parentvcp, name, WRITE_LOCK))) {
         /* Verify that the dentry does not point to an old inode */
         if (vcp != lookupvcp)
             goto done;
@@ -885,7 +900,7 @@ static int afs_linux_dentry_revalidate(struct dentry *dp)
 done:
     /* Clean up */
     if (lookupvcp)
-        afs_PutVCache(lookupvcp, WRITE_LOCK);
+        afs_PutVCache(lookupvcp);
     if (sysState.allocked)
         osi_FreeLargeSpace(name);
 
@@ -896,6 +911,7 @@ done:
         shrink_dcache_parent(dp);
         d_drop(dp);
     }
+    unlock_kernel();
 
     return !bad_dentry;
 }
@@ -1352,6 +1368,7 @@ int afs_linux_readpage(struct file *fp, struct page *pp)
     struct iovec iovec;
     struct inode *ip = FILE_INODE(fp);
     int cnt = atomic_read(&pp->count);
+    struct vcache *avc = ITOAFS(ip);
 
     AFS_GLOCK();
     afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
@@ -1372,7 +1389,7 @@ int afs_linux_readpage(struct file *fp, struct page *pp)
 
     setup_uio(&tuio, &iovec, (char*)address, offset, PAGESIZE,
              UIO_READ, AFS_UIOSYS);
-    code = afs_rdwr(ITOAFS(ip), &tuio, UIO_READ, 0, credp);
+    code = afs_rdwr(avc, &tuio, UIO_READ, 0, credp);
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
     unlock_kernel();
 #endif
@@ -1398,6 +1415,22 @@ int afs_linux_readpage(struct file *fp, struct page *pp)
     free_page(address);
 #endif
 
+    if (!code && AFS_CHUNKOFFSET(offset) == 0) {
+       struct dcache *tdc;
+       struct vrequest treq;
+
+       code = afs_InitReq(&treq, credp);
+       if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
+           tdc = afs_FindDCache(avc, offset);
+           if (tdc) {
+               if (!(tdc->mflags & DFNextStarted))
+                   afs_PrefetchChunk(avc, tdc, credp, &treq);
+               afs_PutDCache(tdc);
+           }
+           ReleaseWriteLock(&avc->lock);
+       }
+    }
+
     crfree(credp);
     afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
               ICL_TYPE_POINTER, ip,