blob: 8ca44b7b25c360e96c1a568e9a55547fc0a65fd0 [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
Manoj Naik6b97fd32006-06-09 09:34:29 -040061 if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL)
62 mnt = nfs_do_refmount(nd->mnt, nd->dentry);
63 else
64 mnt = nfs_do_submount(nd->mnt, nd->dentry, &fh, &fattr);
Trond Myklebust55a97592006-06-09 09:34:19 -040065 err = PTR_ERR(mnt);
66 if (IS_ERR(mnt))
67 goto out_err;
68
69 mntget(mnt);
Trond Myklebust51d8fa62006-06-09 09:34:20 -040070 err = do_add_mount(mnt, nd, nd->mnt->mnt_flags|MNT_SHRINKABLE, &nfs_automount_list);
Trond Myklebust55a97592006-06-09 09:34:19 -040071 if (err < 0) {
72 mntput(mnt);
73 if (err == -EBUSY)
74 goto out_follow;
75 goto out_err;
76 }
77 mntput(nd->mnt);
78 dput(nd->dentry);
79 nd->mnt = mnt;
80 nd->dentry = dget(mnt->mnt_root);
Trond Myklebust51d8fa62006-06-09 09:34:20 -040081 schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
Trond Myklebust55a97592006-06-09 09:34:19 -040082out:
83 dprintk("%s: done, returned %d\n", __FUNCTION__, err);
84 return ERR_PTR(err);
85out_err:
86 path_release(nd);
87 goto out;
88out_follow:
89 while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
90 ;
91 err = 0;
92 goto out;
93}
94
95struct inode_operations nfs_mountpoint_inode_operations = {
96 .follow_link = nfs_follow_mountpoint,
97 .getattr = nfs_getattr,
98};
Trond Myklebust51d8fa62006-06-09 09:34:20 -040099
Manoj Naik6b97fd32006-06-09 09:34:29 -0400100struct inode_operations nfs_referral_inode_operations = {
101 .follow_link = nfs_follow_mountpoint,
102};
103
Trond Myklebust51d8fa62006-06-09 09:34:20 -0400104static void nfs_expire_automounts(void *data)
105{
106 struct list_head *list = (struct list_head *)data;
107
108 mark_mounts_for_expiry(list);
109 if (!list_empty(list))
110 schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
111}
112
113void nfs_release_automount_timer(void)
114{
115 if (list_empty(&nfs_automount_list)) {
116 cancel_delayed_work(&nfs_automount_task);
117 flush_scheduled_work();
118 }
119}