Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-2.6-nmw
[pandora-kernel.git] / fs / afs / mntpt.c
index 8f74e84..034fcfd 100644 (file)
@@ -1,4 +1,4 @@
-/* mntpt.c: mountpoint management
+/* mountpoint management
  *
  * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
  * Written by David Howells (dhowells@redhat.com)
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
 #include <linux/pagemap.h>
 #include <linux/mount.h>
 #include <linux/namei.h>
 #include <linux/mnt_namespace.h>
-#include "super.h"
-#include "cell.h"
-#include "volume.h"
-#include "vnode.h"
 #include "internal.h"
 
 
@@ -31,12 +26,13 @@ static struct dentry *afs_mntpt_lookup(struct inode *dir,
                                       struct nameidata *nd);
 static int afs_mntpt_open(struct inode *inode, struct file *file);
 static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd);
+static void afs_mntpt_expiry_timed_out(struct work_struct *work);
 
 const struct file_operations afs_mntpt_file_operations = {
        .open           = afs_mntpt_open,
 };
 
-struct inode_operations afs_mntpt_inode_operations = {
+const struct inode_operations afs_mntpt_inode_operations = {
        .lookup         = afs_mntpt_lookup,
        .follow_link    = afs_mntpt_follow_link,
        .readlink       = page_readlink,
@@ -44,24 +40,19 @@ struct inode_operations afs_mntpt_inode_operations = {
 };
 
 static LIST_HEAD(afs_vfsmounts);
+static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out);
 
-static void afs_mntpt_expiry_timed_out(struct afs_timer *timer);
+unsigned long afs_mntpt_expiry_timeout = 10 * 60;
 
-struct afs_timer_ops afs_mntpt_expiry_timer_ops = {
-       .timed_out      = afs_mntpt_expiry_timed_out,
-};
-
-struct afs_timer afs_mntpt_expiry_timer;
-
-unsigned long afs_mntpt_expiry_timeout = 20;
-
-/*****************************************************************************/
 /*
  * check a symbolic link to see whether it actually encodes a mountpoint
  * - sets the AFS_VNODE_MOUNTPOINT flag on the vnode appropriately
  */
-int afs_mntpt_check_symlink(struct afs_vnode *vnode)
+int afs_mntpt_check_symlink(struct afs_vnode *vnode, struct key *key)
 {
+       struct file file = {
+               .private_data = key,
+       };
        struct page *page;
        size_t size;
        char *buf;
@@ -70,23 +61,21 @@ int afs_mntpt_check_symlink(struct afs_vnode *vnode)
        _enter("{%u,%u}", vnode->fid.vnode, vnode->fid.unique);
 
        /* read the contents of the symlink into the pagecache */
-       page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, NULL);
+       page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, &file);
        if (IS_ERR(page)) {
                ret = PTR_ERR(page);
                goto out;
        }
 
        ret = -EIO;
-       wait_on_page_locked(page);
-       buf = kmap(page);
-       if (!PageUptodate(page))
-               goto out_free;
        if (PageError(page))
                goto out_free;
 
+       buf = kmap(page);
+
        /* examine the symlink's contents */
        size = vnode->status.size;
-       _debug("symlink to %*.*s", size, (int) size, buf);
+       _debug("symlink to %*.*s", (int) size, (int) size, buf);
 
        if (size > 2 &&
            (buf[0] == '%' || buf[0] == '#') &&
@@ -94,22 +83,20 @@ int afs_mntpt_check_symlink(struct afs_vnode *vnode)
            ) {
                _debug("symlink is a mountpoint");
                spin_lock(&vnode->lock);
-               vnode->flags |= AFS_VNODE_MOUNTPOINT;
+               set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags);
                spin_unlock(&vnode->lock);
        }
 
        ret = 0;
 
- out_free:
        kunmap(page);
+out_free:
        page_cache_release(page);
- out:
+out:
        _leave(" = %d", ret);
        return ret;
+}
 
-} /* end afs_mntpt_check_symlink() */
-
-/*****************************************************************************/
 /*
  * no valid lookup procedure on this sort of dir
  */
@@ -117,7 +104,7 @@ static struct dentry *afs_mntpt_lookup(struct inode *dir,
                                       struct dentry *dentry,
                                       struct nameidata *nd)
 {
-       kenter("%p,%p{%p{%s},%s}",
+       _enter("%p,%p{%p{%s},%s}",
               dir,
               dentry,
               dentry->d_parent,
@@ -126,15 +113,14 @@ static struct dentry *afs_mntpt_lookup(struct inode *dir,
               dentry->d_name.name);
 
        return ERR_PTR(-EREMOTE);
-} /* end afs_mntpt_lookup() */
+}
 
-/*****************************************************************************/
 /*
  * no valid open procedure on this sort of dir
  */
 static int afs_mntpt_open(struct inode *inode, struct file *file)
 {
-       kenter("%p,%p{%p{%s},%s}",
+       _enter("%p,%p{%p{%s},%s}",
               inode, file,
               file->f_path.dentry->d_parent,
               file->f_path.dentry->d_parent ?
@@ -143,9 +129,8 @@ static int afs_mntpt_open(struct inode *inode, struct file *file)
               file->f_path.dentry->d_name.name);
 
        return -EREMOTE;
-} /* end afs_mntpt_open() */
+}
 
-/*****************************************************************************/
 /*
  * create a vfsmount to be automounted
  */
@@ -158,7 +143,7 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
        char *buf, *devname = NULL, *options = NULL;
        int ret;
 
-       kenter("{%s}", mntpt->d_name.name);
+       _enter("{%s}", mntpt->d_name.name);
 
        BUG_ON(!mntpt->d_inode);
 
@@ -184,8 +169,7 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
        }
 
        ret = -EIO;
-       wait_on_page_locked(page);
-       if (!PageUptodate(page) || PageError(page))
+       if (PageError(page))
                goto error;
 
        buf = kmap(page);
@@ -202,79 +186,108 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
                strcat(options, ",rwpath");
 
        /* try and do the mount */
-       kdebug("--- attempting mount %s -o %s ---", devname, options);
+       _debug("--- attempting mount %s -o %s ---", devname, options);
        mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options);
-       kdebug("--- mount result %p ---", mnt);
+       _debug("--- mount result %p ---", mnt);
 
        free_page((unsigned long) devname);
        free_page((unsigned long) options);
-       kleave(" = %p", mnt);
+       _leave(" = %p", mnt);
        return mnt;
 
- error:
+error:
        if (page)
                page_cache_release(page);
        if (devname)
                free_page((unsigned long) devname);
        if (options)
                free_page((unsigned long) options);
-       kleave(" = %d", ret);
+       _leave(" = %d", ret);
        return ERR_PTR(ret);
-} /* end afs_mntpt_do_automount() */
+}
 
-/*****************************************************************************/
 /*
  * follow a link from a mountpoint directory, thus causing it to be mounted
  */
 static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
        struct vfsmount *newmnt;
-       struct dentry *old_dentry;
        int err;
 
-       kenter("%p{%s},{%s:%p{%s}}",
+       _enter("%p{%s},{%s:%p{%s},}",
               dentry,
               dentry->d_name.name,
               nd->mnt->mnt_devname,
               dentry,
               nd->dentry->d_name.name);
 
-       newmnt = afs_mntpt_do_automount(dentry);
+       dput(nd->dentry);
+       nd->dentry = dget(dentry);
+
+       newmnt = afs_mntpt_do_automount(nd->dentry);
        if (IS_ERR(newmnt)) {
                path_release(nd);
                return (void *)newmnt;
        }
 
-       old_dentry = nd->dentry;
-       nd->dentry = dentry;
-       err = do_add_mount(newmnt, nd, 0, &afs_vfsmounts);
-       nd->dentry = old_dentry;
-
-       path_release(nd);
-
-       if (!err) {
-               mntget(newmnt);
+       mntget(newmnt);
+       err = do_add_mount(newmnt, nd, MNT_SHRINKABLE, &afs_vfsmounts);
+       switch (err) {
+       case 0:
+               mntput(nd->mnt);
+               dput(nd->dentry);
                nd->mnt = newmnt;
-               dget(newmnt->mnt_root);
-               nd->dentry = newmnt->mnt_root;
+               nd->dentry = dget(newmnt->mnt_root);
+               schedule_delayed_work(&afs_mntpt_expiry_timer,
+                                     afs_mntpt_expiry_timeout * HZ);
+               break;
+       case -EBUSY:
+               /* someone else made a mount here whilst we were busy */
+               while (d_mountpoint(nd->dentry) &&
+                      follow_down(&nd->mnt, &nd->dentry))
+                       ;
+               err = 0;
+       default:
+               mntput(newmnt);
+               break;
        }
 
-       kleave(" = %d", err);
+       _leave(" = %d", err);
        return ERR_PTR(err);
-} /* end afs_mntpt_follow_link() */
+}
 
-/*****************************************************************************/
 /*
  * handle mountpoint expiry timer going off
  */
-static void afs_mntpt_expiry_timed_out(struct afs_timer *timer)
+static void afs_mntpt_expiry_timed_out(struct work_struct *work)
 {
-       kenter("");
+       _enter("");
 
-       mark_mounts_for_expiry(&afs_vfsmounts);
+       if (!list_empty(&afs_vfsmounts)) {
+               mark_mounts_for_expiry(&afs_vfsmounts);
+               schedule_delayed_work(&afs_mntpt_expiry_timer,
+                                     afs_mntpt_expiry_timeout * HZ);
+       }
 
-       afs_kafstimod_add_timer(&afs_mntpt_expiry_timer,
-                               afs_mntpt_expiry_timeout * HZ);
+       _leave("");
+}
 
-       kleave("");
-} /* end afs_mntpt_expiry_timed_out() */
+/*
+ * kill the AFS mountpoint timer if it's still running
+ */
+void afs_mntpt_kill_timer(void)
+{
+       _enter("");
+
+       ASSERT(list_empty(&afs_vfsmounts));
+       cancel_delayed_work(&afs_mntpt_expiry_timer);
+       flush_scheduled_work();
+}
+
+/*
+ * begin unmount by attempting to remove all automounted mountpoints we added
+ */
+void afs_umount_begin(struct vfsmount *vfsmnt, int flags)
+{
+       shrink_submounts(vfsmnt, &afs_vfsmounts);
+}