namespace.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * linux/fs/nfs/namespace.c
  3. *
  4. * Copyright (C) 2005 Trond Myklebust <Trond.Myklebust@netapp.com>
  5. *
  6. * NFS namespace
  7. */
  8. #include <linux/config.h>
  9. #include <linux/dcache.h>
  10. #include <linux/mount.h>
  11. #include <linux/namei.h>
  12. #include <linux/nfs_fs.h>
  13. #include <linux/string.h>
  14. #include <linux/sunrpc/clnt.h>
  15. #include <linux/vfs.h>
  16. #define NFSDBG_FACILITY NFSDBG_VFS
  17. /*
  18. * nfs_follow_mountpoint - handle crossing a mountpoint on the server
  19. * @dentry - dentry of mountpoint
  20. * @nd - nameidata info
  21. *
  22. * When we encounter a mountpoint on the server, we want to set up
  23. * a mountpoint on the client too, to prevent inode numbers from
  24. * colliding, and to allow "df" to work properly.
  25. * On NFSv4, we also want to allow for the fact that different
  26. * filesystems may be migrated to different servers in a failover
  27. * situation, and that different filesystems may want to use
  28. * different security flavours.
  29. */
  30. static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
  31. {
  32. struct vfsmount *mnt;
  33. struct nfs_server *server = NFS_SERVER(dentry->d_inode);
  34. struct dentry *parent;
  35. struct nfs_fh fh;
  36. struct nfs_fattr fattr;
  37. int err;
  38. BUG_ON(IS_ROOT(dentry));
  39. dprintk("%s: enter\n", __FUNCTION__);
  40. dput(nd->dentry);
  41. nd->dentry = dget(dentry);
  42. if (d_mountpoint(nd->dentry))
  43. goto out_follow;
  44. /* Look it up again */
  45. parent = dget_parent(nd->dentry);
  46. err = server->rpc_ops->lookup(parent->d_inode, &nd->dentry->d_name, &fh, &fattr);
  47. dput(parent);
  48. if (err != 0)
  49. goto out_err;
  50. mnt = nfs_do_submount(nd->mnt, nd->dentry, &fh, &fattr);
  51. err = PTR_ERR(mnt);
  52. if (IS_ERR(mnt))
  53. goto out_err;
  54. mntget(mnt);
  55. err = do_add_mount(mnt, nd, nd->mnt->mnt_flags, NULL);
  56. if (err < 0) {
  57. mntput(mnt);
  58. if (err == -EBUSY)
  59. goto out_follow;
  60. goto out_err;
  61. }
  62. mntput(nd->mnt);
  63. dput(nd->dentry);
  64. nd->mnt = mnt;
  65. nd->dentry = dget(mnt->mnt_root);
  66. out:
  67. dprintk("%s: done, returned %d\n", __FUNCTION__, err);
  68. return ERR_PTR(err);
  69. out_err:
  70. path_release(nd);
  71. goto out;
  72. out_follow:
  73. while(d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry))
  74. ;
  75. err = 0;
  76. goto out;
  77. }
  78. struct inode_operations nfs_mountpoint_inode_operations = {
  79. .follow_link = nfs_follow_mountpoint,
  80. .getattr = nfs_getattr,
  81. };