Linux: Only use automount for volume roots
[openafs.git] / src / afs / LINUX / osi_vnodeops.c
index 70f2fb3..4c8ae35 100644 (file)
@@ -339,7 +339,7 @@ afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
     tdc = afs_GetDCache(avc, (afs_size_t) 0, treq, &origOffset, &tlen, 1);
     len = tlen;
     if (!tdc) {
-       code = -ENOENT;
+       code = -EIO;
        goto out;
     }
     ObtainWriteLock(&avc->lock, 811);
@@ -403,7 +403,7 @@ afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
                UpgradeSToWLock(&avc->lock, 814);
                avc->f.states |= CCorrupt;
            }
-           code = -ENOENT;
+           code = -EIO;
            goto unlock_out;
         }
 
@@ -425,7 +425,7 @@ afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
            if ((avc->f.states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
                type = DT_DIR;
            } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
-               if (tvc->mvstat) {
+               if (tvc->mvstat != AFS_MVSTAT_FILE) {
                    type = DT_DIR;
                } else if (((tvc->f.states) & (CStatd | CTruth))) {
                    /* CTruth will be set if the object has
@@ -819,8 +819,10 @@ struct file_operations afs_file_fops = {
 #ifdef STRUCT_FILE_OPERATIONS_HAS_READ_ITER
   .read_iter = afs_linux_read_iter,
   .write_iter =        afs_linux_write_iter,
+# if !defined(HAVE_LINUX___VFS_READ)
   .read =      new_sync_read,
   .write =     new_sync_write,
+# endif
 #elif defined(HAVE_LINUX_GENERIC_FILE_AIO_READ)
   .aio_read =  afs_linux_aio_read,
   .aio_write = afs_linux_aio_write,
@@ -957,7 +959,7 @@ afs_linux_revalidate(struct dentry *dp)
      * changes in afs_getattr that don't get replicated here!
      */
     if (vcp->f.states & CStatd &&
-        (!afs_fakestat_enable || vcp->mvstat != 1) &&
+        (!afs_fakestat_enable || vcp->mvstat != AFS_MVSTAT_MTPT) &&
        !afs_nfsexporter &&
        (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
        code = afs_CopyOutAttrs(vcp, vattr);
@@ -1098,7 +1100,7 @@ parent_vcache_dv(struct inode *inode, cred_t *credp)
      * us.  The fake entry is the one with the useful DataVersion.
      */
     pvcp = VTOAFS(inode);
-    if (pvcp->mvstat == 1 && afs_fakestat_enable) {
+    if (pvcp->mvstat == AFS_MVSTAT_MTPT && afs_fakestat_enable) {
        struct vrequest treq;
        struct afs_fakestat_state fakestate;
 
@@ -1164,37 +1166,41 @@ afs_linux_dentry_revalidate(struct dentry *dp, int flags)
        parent = dget_parent(dp);
        pvcp = VTOAFS(parent->d_inode);
 
-       if ((vcp->mvstat == 1) || (vcp->mvstat == 2) ||
-               (pvcp->mvstat == 1 && afs_fakestat_enable)) {   /* need to lock */
+       if ((vcp->mvstat != AFS_MVSTAT_FILE) ||
+               (pvcp->mvstat == AFS_MVSTAT_MTPT && afs_fakestat_enable)) {     /* need to lock */
            credp = crref();
            AFS_GLOCK();
            locked = 1;
        }
 
-       if (locked && vcp->mvstat == 1) {         /* mount point */
-           if (vcp->mvid && (vcp->f.states & CMValid)) {
-               int tryEvalOnly = 0;
-               int code = 0;
-               struct vrequest *treq = NULL;
-
-               code = afs_CreateReq(&treq, credp);
-               if (code) {
-                   dput(parent);
-                   goto bad_dentry;
-               }
-               if ((strcmp(dp->d_name.name, ".directory") == 0)) {
-                   tryEvalOnly = 1;
-               }
-               if (tryEvalOnly)
-                   code = afs_TryEvalFakeStat(&vcp, &fakestate, treq);
-               else
-                   code = afs_EvalFakeStat(&vcp, &fakestate, treq);
-               afs_DestroyReq(treq);
-               if ((tryEvalOnly && vcp->mvstat == 1) || code) {
-                   /* a mount point, not yet replaced by its directory */
-                   dput(parent);
-                   goto bad_dentry;
+       if (locked) {
+           if (vcp->mvstat == AFS_MVSTAT_MTPT) {
+               if (vcp->mvid.target_root && (vcp->f.states & CMValid)) {
+                   int tryEvalOnly = 0;
+                   int code = 0;
+                   struct vrequest *treq = NULL;
+
+                   code = afs_CreateReq(&treq, credp);
+                   if (code) {
+                       dput(parent);
+                       goto bad_dentry;
+                   }
+                   if ((strcmp(dp->d_name.name, ".directory") == 0)) {
+                       tryEvalOnly = 1;
+                   }
+                   if (tryEvalOnly)
+                       code = afs_TryEvalFakeStat(&vcp, &fakestate, treq);
+                   else
+                       code = afs_EvalFakeStat(&vcp, &fakestate, treq);
+                   afs_DestroyReq(treq);
+                   if ((tryEvalOnly && vcp->mvstat == AFS_MVSTAT_MTPT) || code) {
+                       /* a mount point, not yet replaced by its directory */
+                       dput(parent);
+                       goto bad_dentry;
+                   }
                }
+           } else if (vcp->mvstat == AFS_MVSTAT_ROOT && *dp->d_name.name != '/') {
+               osi_Assert(vcp->mvid.parent != NULL);
            }
        }
 
@@ -1384,9 +1390,17 @@ afs_dentry_automount(afs_linux_path_t *path)
 {
     struct dentry *target;
 
-    /* avoid symlink resolution limits when resolving; we cannot contribute to
-     * an infinite symlink loop */
+    /* 
+     * Avoid symlink resolution limits when resolving; we cannot contribute to
+     * an infinite symlink loop.
+     *
+     * On newer kernels the field has moved to the private nameidata structure
+     * so we can't adjust it here.  This may cause ELOOP when using a path with
+     * 40 or more directories that are not already in the dentry cache.
+     */
+#if defined(STRUCT_TASK_STRUCT_HAS_TOTAL_LINK_COUNT)
     current->total_link_count--;
+#endif
 
     target = canonical_dentry(path->dentry->d_inode);
 
@@ -1547,7 +1561,9 @@ afs_linux_lookup(struct inode *dip, struct dentry *dp)
        d_prune_aliases(ip);
 
 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
-       ip->i_flags |= S_AUTOMOUNT;
+       /* Only needed if this is a volume root */
+       if (vcp->mvstat == 2)
+           ip->i_flags |= S_AUTOMOUNT;
 #endif
     }
     /*
@@ -1657,7 +1673,7 @@ afs_linux_sillyrename(struct inode *dir, struct dentry *dentry,
                      VTOAFS(dir), (char *)__dp->d_name.name,
                      credp);
     if (!code) {
-       tvc->mvid = (void *) __name;
+       tvc->mvid.silly_name = __name;
        crhold(credp);
        if (tvc->uncred) {
            crfree(tvc->uncred);
@@ -1888,14 +1904,22 @@ afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
 /* afs_linux_follow_link
  * a file system dependent link following routine.
  */
+#if defined(HAVE_LINUX_INODE_OPERATIONS_FOLLOW_LINK_NO_NAMEIDATA)
+static const char *afs_linux_follow_link(struct dentry *dentry, void **link_data)
+#else
 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
+#endif
 {
     int code;
     char *name;
 
     name = kmalloc(PATH_MAX, GFP_NOFS);
     if (!name) {
+#if defined(HAVE_LINUX_INODE_OPERATIONS_FOLLOW_LINK_NO_NAMEIDATA)
+       return ERR_PTR(-EIO);
+#else
        return -EIO;
+#endif
     }
 
     AFS_GLOCK();
@@ -1903,14 +1927,32 @@ static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
     AFS_GUNLOCK();
 
     if (code < 0) {
+#if defined(HAVE_LINUX_INODE_OPERATIONS_FOLLOW_LINK_NO_NAMEIDATA)
+       return ERR_PTR(code);
+#else
        return code;
+#endif
     }
 
     name[code] = '\0';
+#if defined(HAVE_LINUX_INODE_OPERATIONS_FOLLOW_LINK_NO_NAMEIDATA)
+    return *link_data = name;
+#else
     nd_set_link(nd, name);
     return 0;
+#endif
 }
 
+#if defined(HAVE_LINUX_INODE_OPERATIONS_PUT_LINK_NO_NAMEIDATA)
+static void
+afs_linux_put_link(struct inode *inode, void *link_data)
+{
+    char *name = link_data;
+
+    if (name && !IS_ERR(name))
+       kfree(name);
+}
+#else
 static void
 afs_linux_put_link(struct dentry *dentry, struct nameidata *nd)
 {
@@ -1919,6 +1961,7 @@ afs_linux_put_link(struct dentry *dentry, struct nameidata *nd)
     if (name && !IS_ERR(name))
        kfree(name);
 }
+#endif /* HAVE_LINUX_INODE_OPERATIONS_PUT_LINK_NO_NAMEIDATA */
 
 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
 
@@ -2572,10 +2615,27 @@ out:
  * locked */
 static inline int
 afs_linux_prepare_writeback(struct vcache *avc) {
-    if (avc->f.states & CPageWrite) {
-       return AOP_WRITEPAGE_ACTIVATE;
+    pid_t pid;
+    struct pagewriter *pw;
+
+    pid = MyPidxx2Pid(MyPidxx);
+    /* Prevent recursion into the writeback code */
+    spin_lock(&avc->pagewriter_lock);
+    list_for_each_entry(pw, &avc->pagewriters, link) {
+       if (pw->writer == pid) {
+           spin_unlock(&avc->pagewriter_lock);
+           return AOP_WRITEPAGE_ACTIVATE;
+       }
     }
-    avc->f.states |= CPageWrite;
+    spin_unlock(&avc->pagewriter_lock);
+
+    /* Add ourselves to writer list */
+    pw = osi_Alloc(sizeof(struct pagewriter));
+    pw->writer = pid;
+    spin_lock(&avc->pagewriter_lock);
+    list_add_tail(&pw->link, &avc->pagewriters);
+    spin_unlock(&avc->pagewriter_lock);
+
     return 0;
 }
 
@@ -2594,7 +2654,26 @@ afs_linux_dopartialwrite(struct vcache *avc, cred_t *credp) {
 
 static inline void
 afs_linux_complete_writeback(struct vcache *avc) {
-    avc->f.states &= ~CPageWrite;
+    struct pagewriter *pw, *store;
+    pid_t pid;
+    struct list_head tofree;
+
+    INIT_LIST_HEAD(&tofree);
+    pid = MyPidxx2Pid(MyPidxx);
+    /* Remove ourselves from writer list */
+    spin_lock(&avc->pagewriter_lock);
+    list_for_each_entry_safe(pw, store, &avc->pagewriters, link) {
+       if (pw->writer == pid) {
+           list_del(&pw->link);
+           /* osi_Free may sleep so we need to defer it */
+           list_add_tail(&pw->link, &tofree);
+       }
+    }
+    spin_unlock(&avc->pagewriter_lock);
+    list_for_each_entry_safe(pw, store, &tofree, link) {
+       list_del(&pw->link);
+       osi_Free(pw, sizeof(struct pagewriter));
+    }
 }
 
 /* Writeback a given page syncronously. Called with no AFS locks held */
@@ -3052,7 +3131,9 @@ afs_fill_inode(struct inode *ip, struct vattr *vattr)
     if (vattr)
        vattr2inode(ip, vattr);
 
+#ifdef STRUCT_ADDRESS_SPACE_HAS_BACKING_DEV_INFO
     ip->i_mapping->backing_dev_info = afs_backing_dev_info;
+#endif
 /* Reset ops if symlink or directory. */
     if (S_ISREG(ip->i_mode)) {
        ip->i_op = &afs_file_iops;