NFS: Ensure the client submounts, when it crosses a server mountpoint.
[linux-2.6-block.git] / fs / nfs / namespace.c
1 /*
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
21 /*
22  * nfs_follow_mountpoint - handle crossing a mountpoint on the server
23  * @dentry - dentry of mountpoint
24  * @nd - nameidata info
25  *
26  * When we encounter a mountpoint on the server, we want to set up
27  * a mountpoint on the client too, to prevent inode numbers from
28  * colliding, and to allow "df" to work properly.
29  * On NFSv4, we also want to allow for the fact that different
30  * filesystems may be migrated to different servers in a failover
31  * situation, and that different filesystems may want to use
32  * different security flavours.
33  */
34 static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
35 {
36         struct vfsmount *mnt;
37         struct nfs_server *server = NFS_SERVER(dentry->d_inode);
38         struct dentry *parent;
39         struct nfs_fh fh;
40         struct nfs_fattr fattr;
41         int err;
42
43         BUG_ON(IS_ROOT(dentry));
44         dprintk("%s: enter\n", __FUNCTION__);
45         dput(nd->dentry);
46         nd->dentry = dget(dentry);
47         if (d_mountpoint(nd->dentry))
48                 goto out_follow;
49         /* Look it up again */
50         parent = dget_parent(nd->dentry);
51         err = server->rpc_ops->lookup(parent->d_inode, &nd->dentry->d_name, &fh, &fattr);
52         dput(parent);
53         if (err != 0)
54                 goto out_err;
55
56         mnt = nfs_do_submount(nd->mnt, nd->dentry, &fh, &fattr);
57         err = PTR_ERR(mnt);
58         if (IS_ERR(mnt))
59                 goto out_err;
60
61         mntget(mnt);
62         err = do_add_mount(mnt, nd, nd->mnt->mnt_flags, NULL);
63         if (err < 0) {
64                 mntput(mnt);
65                 if (err == -EBUSY)
66                         goto out_follow;
67                 goto out_err;
68         }
69         mntput(nd->mnt);
70         dput(nd->dentry);
71         nd->mnt = mnt;
72         nd->dentry = dget(mnt->mnt_root);
73 out:
74         dprintk("%s: done, returned %d\n", __FUNCTION__, err);
75         return ERR_PTR(err);
76 out_err:
77         path_release(nd);
78         goto out;
79 out_follow:
80         while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
81                 ;
82         err = 0;
83         goto out;
84 }
85
86 struct inode_operations nfs_mountpoint_inode_operations = {
87         .follow_link    = nfs_follow_mountpoint,
88         .getattr        = nfs_getattr,
89 };