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