linux: Fix leaked dentry reference in the revalidate op
[openafs.git] / src / afs / LINUX / osi_vnodeops.c
index 4a4c96a..ca7fe85 100644 (file)
@@ -804,7 +804,7 @@ canonical_dentry(struct inode *ip)
 {
     struct vcache *vcp = VTOAFS(ip);
     struct dentry *first = NULL, *ret = NULL, *cur;
-#if defined(D_ALIAS_IS_HLIST)
+#if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
     struct hlist_node *p;
 #endif
 
@@ -827,7 +827,11 @@ canonical_dentry(struct inode *ip)
 # endif
 
 #if defined(D_ALIAS_IS_HLIST)
+# if defined(HLIST_ITERATOR_NO_NODE)
+    hlist_for_each_entry(cur, &ip->i_dentry, d_alias) {
+# else
     hlist_for_each_entry(cur, p, &ip->i_dentry, d_alias) {
+# endif
 #else
     list_for_each_entry_reverse(cur, &ip->i_dentry, d_alias) {
 #endif
@@ -1130,6 +1134,7 @@ afs_linux_dentry_revalidate(struct dentry *dp, int flags)
                    code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
                if ((tryEvalOnly && vcp->mvstat == 1) || code) {
                    /* a mount point, not yet replaced by its directory */
+                   dput(parent);
                    goto bad_dentry;
                }
            }
@@ -1146,8 +1151,10 @@ afs_linux_dentry_revalidate(struct dentry *dp, int flags)
         * always require a crref() which would be "slow".
         */
        if (vcp->last_looker != treq.uid) {
-           if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
+           if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS)) {
+               dput(parent);
                goto bad_dentry;
+           }
 
            vcp->last_looker = treq.uid;
        }
@@ -1409,24 +1416,7 @@ afs_linux_lookup(struct inode *dip, struct dentry *dp)
     AFS_GUNLOCK();
 
     if (ip && S_ISDIR(ip->i_mode)) {
-       int retry = 1;
-       struct dentry *alias;
-
-       while (retry) {
-           retry = 0;
-
-           /* Try to invalidate an existing alias in favor of our new one */
-           alias = d_find_alias(ip);
-           /* But not if it's disconnected; then we want d_splice_alias below */
-           if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
-               if (d_invalidate(alias) == 0) {
-                   /* there may be more aliases; try again until we run out */
-                   retry = 1;
-               }
-           }
-
-           dput(alias);
-       }
+       d_prune_aliases(ip);
 
 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
        ip->i_flags |= S_AUTOMOUNT;
@@ -2129,7 +2119,7 @@ afs_linux_bypass_readpages(struct file *fp, struct address_space *mapping,
 
        if(page_ix == 0) {
            offset = page_offset(pp);
-           auio->uio_offset = offset;
+           ancr->offset = auio->uio_offset = offset;
            base_index = pp->index;
        }
         iovecp[page_ix].iov_len = PAGE_SIZE;
@@ -2241,13 +2231,14 @@ afs_linux_bypass_readpage(struct file *fp, struct page *pp)
 
 static inline int
 afs_linux_can_bypass(struct inode *ip) {
+
     switch(cache_bypass_strategy) {
        case NEVER_BYPASS_CACHE:
            return 0;
        case ALWAYS_BYPASS_CACHE:
            return 1;
        case LARGE_FILES_BYPASS_CACHE:
-           if(i_size_read(ip) > cache_bypass_threshold)
+           if (i_size_read(ip) > cache_bypass_threshold)
                return 1;
        default:
            return 0;
@@ -2762,6 +2753,8 @@ afs_linux_dir_follow_link(struct dentry *dentry, struct nameidata *nd)
        *dpp = dget(dentry);
     }
 
+    nd->last_type = LAST_BIND;
+
     return NULL;
 }
 #endif /* !STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */