nfs3client.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include <linux/nfs_fs.h>
  2. #include <linux/nfs_mount.h>
  3. #include <linux/sunrpc/addr.h>
  4. #include "internal.h"
  5. #include "nfs3_fs.h"
  6. #ifdef CONFIG_NFS_V3_ACL
  7. static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
  8. static const struct rpc_version *nfsacl_version[] = {
  9. [3] = &nfsacl_version3,
  10. };
  11. const struct rpc_program nfsacl_program = {
  12. .name = "nfsacl",
  13. .number = NFS_ACL_PROGRAM,
  14. .nrvers = ARRAY_SIZE(nfsacl_version),
  15. .version = nfsacl_version,
  16. .stats = &nfsacl_rpcstat,
  17. };
  18. /*
  19. * Initialise an NFSv3 ACL client connection
  20. */
  21. static void nfs_init_server_aclclient(struct nfs_server *server)
  22. {
  23. if (server->flags & NFS_MOUNT_NOACL)
  24. goto out_noacl;
  25. server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
  26. if (IS_ERR(server->client_acl))
  27. goto out_noacl;
  28. /* No errors! Assume that Sun nfsacls are supported */
  29. server->caps |= NFS_CAP_ACLS;
  30. return;
  31. out_noacl:
  32. server->caps &= ~NFS_CAP_ACLS;
  33. }
  34. #else
  35. static inline void nfs_init_server_aclclient(struct nfs_server *server)
  36. {
  37. server->flags &= ~NFS_MOUNT_NOACL;
  38. server->caps &= ~NFS_CAP_ACLS;
  39. }
  40. #endif
  41. struct nfs_server *nfs3_create_server(struct nfs_mount_info *mount_info,
  42. struct nfs_subversion *nfs_mod)
  43. {
  44. struct nfs_server *server = nfs_create_server(mount_info, nfs_mod);
  45. /* Create a client RPC handle for the NFS v3 ACL management interface */
  46. if (!IS_ERR(server))
  47. nfs_init_server_aclclient(server);
  48. return server;
  49. }
  50. struct nfs_server *nfs3_clone_server(struct nfs_server *source,
  51. struct nfs_fh *fh,
  52. struct nfs_fattr *fattr,
  53. rpc_authflavor_t flavor)
  54. {
  55. struct nfs_server *server = nfs_clone_server(source, fh, fattr, flavor);
  56. if (!IS_ERR(server) && !IS_ERR(source->client_acl))
  57. nfs_init_server_aclclient(server);
  58. return server;
  59. }
  60. /*
  61. * Set up a pNFS Data Server client over NFSv3.
  62. *
  63. * Return any existing nfs_client that matches server address,port,version
  64. * and minorversion.
  65. *
  66. * For a new nfs_client, use a soft mount (default), a low retrans and a
  67. * low timeout interval so that if a connection is lost, we retry through
  68. * the MDS.
  69. */
  70. struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
  71. const struct sockaddr *ds_addr, int ds_addrlen,
  72. int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans,
  73. rpc_authflavor_t au_flavor)
  74. {
  75. struct rpc_timeout ds_timeout;
  76. struct nfs_client *mds_clp = mds_srv->nfs_client;
  77. struct nfs_client_initdata cl_init = {
  78. .addr = ds_addr,
  79. .addrlen = ds_addrlen,
  80. .nodename = mds_clp->cl_rpcclient->cl_nodename,
  81. .ip_addr = mds_clp->cl_ipaddr,
  82. .nfs_mod = &nfs_v3,
  83. .proto = ds_proto,
  84. .net = mds_clp->cl_net,
  85. .timeparms = &ds_timeout,
  86. };
  87. struct nfs_client *clp;
  88. char buf[INET6_ADDRSTRLEN + 1];
  89. /* fake a hostname because lockd wants it */
  90. if (rpc_ntop(ds_addr, buf, sizeof(buf)) <= 0)
  91. return ERR_PTR(-EINVAL);
  92. cl_init.hostname = buf;
  93. if (mds_srv->flags & NFS_MOUNT_NORESVPORT)
  94. set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags);
  95. /* Use the MDS nfs_client cl_ipaddr. */
  96. nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans);
  97. clp = nfs_get_client(&cl_init, au_flavor);
  98. return clp;
  99. }
  100. EXPORT_SYMBOL_GPL(nfs3_set_ds_client);