blob: e426516c1116cf829e3341e847bdc45f704e92a8 [file] [log] [blame]
Trond Myklebust55a97592006-06-09 09:34:19 -04001/*
2 * linux/fs/nfs/namespace.c
3 *
4 * Copyright (C) 2005 Trond Myklebust <Trond.Myklebust@netapp.com>
5 *
6 * NFS namespace
7 */
8
9#include <linux/config.h>
10
11#include <linux/dcache.h>
12#include <linux/mount.h>
13#include <linux/namei.h>
14#include <linux/nfs_fs.h>
15#include <linux/string.h>
16#include <linux/sunrpc/clnt.h>
17#include <linux/vfs.h>
18
19#define NFSDBG_FACILITY NFSDBG_VFS
20
Trond Myklebust51d8fa62006-06-09 09:34:20 -040021LIST_HEAD(nfs_automount_list);
22static void nfs_expire_automounts(void *list);
23static DECLARE_WORK(nfs_automount_task, nfs_expire_automounts, &nfs_automount_list);
24int nfs_mountpoint_expiry_timeout = 500 * HZ;
25
Trond Myklebust55a97592006-06-09 09:34:19 -040026/*
27 * nfs_follow_mountpoint - handle crossing a mountpoint on the server
28 * @dentry - dentry of mountpoint
29 * @nd - nameidata info
30 *
31 * When we encounter a mountpoint on the server, we want to set up
32 * a mountpoint on the client too, to prevent inode numbers from
33 * colliding, and to allow "df" to work properly.
34 * On NFSv4, we also want to allow for the fact that different
35 * filesystems may be migrated to different servers in a failover
36 * situation, and that different filesystems may want to use
37 * different security flavours.
38 */
39static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
40{
41 struct vfsmount *mnt;
42 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
43 struct dentry *parent;
44 struct nfs_fh fh;
45 struct nfs_fattr fattr;
46 int err;
47
48 BUG_ON(IS_ROOT(dentry));
49 dprintk("%s: enter\n", __FUNCTION__);
50 dput(nd->dentry);
51 nd->dentry = dget(dentry);
52 if (d_mountpoint(nd->dentry))
53 goto out_follow;
54 /* Look it up again */
55 parent = dget_parent(nd->dentry);
56 err = server->rpc_ops->lookup(parent->d_inode, &nd->dentry->d_name, &fh, &fattr);
57 dput(parent);
58 if (err != 0)
59 goto out_err;
60
61 mnt = nfs_do_submount(nd->mnt, nd->dentry, &fh, &fattr);
62 err = PTR_ERR(mnt);
63 if (IS_ERR(mnt))
64 goto out_err;
65
66 mntget(mnt);
Trond Myklebust51d8fa62006-06-09 09:34:20 -040067 err = do_add_mount(mnt, nd, nd->mnt->mnt_flags|MNT_SHRINKABLE, &nfs_automount_list);
Trond Myklebust55a97592006-06-09 09:34:19 -040068 if (err < 0) {
69 mntput(mnt);
70 if (err == -EBUSY)
71 goto out_follow;
72 goto out_err;
73 }
74 mntput(nd->mnt);
75 dput(nd->dentry);
76 nd->mnt = mnt;
77 nd->dentry = dget(mnt->mnt_root);
Trond Myklebust51d8fa62006-06-09 09:34:20 -040078 schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
Trond Myklebust55a97592006-06-09 09:34:19 -040079out:
80 dprintk("%s: done, returned %d\n", __FUNCTION__, err);
81 return ERR_PTR(err);
82out_err:
83 path_release(nd);
84 goto out;
85out_follow:
86 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
87 ;
88 err = 0;
89 goto out;
90}
91
92struct inode_operations nfs_mountpoint_inode_operations = {
93 .follow_link = nfs_follow_mountpoint,
94 .getattr = nfs_getattr,
95};
Trond Myklebust51d8fa62006-06-09 09:34:20 -040096
97static void nfs_expire_automounts(void *data)
98{
99 struct list_head *list = (struct list_head *)data;
100
101 mark_mounts_for_expiry(list);
102 if (!list_empty(list))
103 schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
104}
105
106void nfs_release_automount_timer(void)
107{
108 if (list_empty(&nfs_automount_list)) {
109 cancel_delayed_work(&nfs_automount_task);
110 flush_scheduled_work();
111 }
112}