blob: 5601e47360c2865b883a40ef15a07fc9867d78f6 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Bryan Schumaker1179acc2012-07-30 16:05:19 -04002#include <linux/nfs_fs.h>
3#include <linux/nfs_mount.h>
Peng Tao36d3e3d2014-07-08 06:21:10 +08004#include <linux/sunrpc/addr.h>
Bryan Schumaker1179acc2012-07-30 16:05:19 -04005#include "internal.h"
Trond Myklebust3fc3edf2014-09-25 16:28:53 -04006#include "nfs3_fs.h"
Bryan Schumaker1179acc2012-07-30 16:05:19 -04007
8#ifdef CONFIG_NFS_V3_ACL
9static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
10static const struct rpc_version *nfsacl_version[] = {
11 [3] = &nfsacl_version3,
12};
13
14const struct rpc_program nfsacl_program = {
15 .name = "nfsacl",
16 .number = NFS_ACL_PROGRAM,
17 .nrvers = ARRAY_SIZE(nfsacl_version),
18 .version = nfsacl_version,
19 .stats = &nfsacl_rpcstat,
20};
21
22/*
23 * Initialise an NFSv3 ACL client connection
24 */
25static void nfs_init_server_aclclient(struct nfs_server *server)
26{
27 if (server->flags & NFS_MOUNT_NOACL)
28 goto out_noacl;
29
30 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
31 if (IS_ERR(server->client_acl))
32 goto out_noacl;
33
34 /* No errors! Assume that Sun nfsacls are supported */
35 server->caps |= NFS_CAP_ACLS;
36 return;
37
38out_noacl:
39 server->caps &= ~NFS_CAP_ACLS;
40}
41#else
42static inline void nfs_init_server_aclclient(struct nfs_server *server)
43{
44 server->flags &= ~NFS_MOUNT_NOACL;
45 server->caps &= ~NFS_CAP_ACLS;
46}
47#endif
48
Scott Mayhew62a55d02019-12-10 07:31:14 -050049struct nfs_server *nfs3_create_server(struct fs_context *fc)
Bryan Schumaker1179acc2012-07-30 16:05:19 -040050{
Scott Mayhew62a55d02019-12-10 07:31:14 -050051 struct nfs_server *server = nfs_create_server(fc);
52
Bryan Schumaker1179acc2012-07-30 16:05:19 -040053 /* Create a client RPC handle for the NFS v3 ACL management interface */
54 if (!IS_ERR(server))
55 nfs_init_server_aclclient(server);
56 return server;
57}
58
59struct nfs_server *nfs3_clone_server(struct nfs_server *source,
60 struct nfs_fh *fh,
61 struct nfs_fattr *fattr,
62 rpc_authflavor_t flavor)
63{
64 struct nfs_server *server = nfs_clone_server(source, fh, fattr, flavor);
65 if (!IS_ERR(server) && !IS_ERR(source->client_acl))
66 nfs_init_server_aclclient(server);
67 return server;
68}
Peng Tao1a04c6e2014-05-30 18:15:57 +080069
70/*
71 * Set up a pNFS Data Server client over NFSv3.
72 *
73 * Return any existing nfs_client that matches server address,port,version
74 * and minorversion.
75 *
76 * For a new nfs_client, use a soft mount (default), a low retrans and a
77 * low timeout interval so that if a connection is lost, we retry through
78 * the MDS.
79 */
Tigran Mkrtchyanb224f7c2016-06-13 20:52:00 +020080struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
Peng Tao1a04c6e2014-05-30 18:15:57 +080081 const struct sockaddr *ds_addr, int ds_addrlen,
Anna Schumaker7d38de32016-11-17 15:15:55 -050082 int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans)
Peng Tao1a04c6e2014-05-30 18:15:57 +080083{
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,
Trond Myklebust1a58e8a2019-04-24 17:46:43 -040095 .cred = mds_srv->cred,
Peng Tao1a04c6e2014-05-30 18:15:57 +080096 };
Peng Tao1a04c6e2014-05-30 18:15:57 +080097 struct nfs_client *clp;
Peng Tao36d3e3d2014-07-08 06:21:10 +080098 char buf[INET6_ADDRSTRLEN + 1];
99
100 /* fake a hostname because lockd wants it */
101 if (rpc_ntop(ds_addr, buf, sizeof(buf)) <= 0)
102 return ERR_PTR(-EINVAL);
103 cl_init.hostname = buf;
Peng Tao1a04c6e2014-05-30 18:15:57 +0800104
Trond Myklebustbb71e4a2017-04-27 11:22:07 -0400105 if (mds_clp->cl_nconnect > 1 && ds_proto == XPRT_TRANSPORT_TCP)
106 cl_init.nconnect = mds_clp->cl_nconnect;
107
Tigran Mkrtchyanb224f7c2016-06-13 20:52:00 +0200108 if (mds_srv->flags & NFS_MOUNT_NORESVPORT)
Trond Myklebustd0372b672019-10-17 09:37:44 -0400109 __set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags);
Tigran Mkrtchyanb224f7c2016-06-13 20:52:00 +0200110
Trond Myklebustc6eb5842019-10-03 14:12:46 -0400111 __set_bit(NFS_CS_NOPING, &cl_init.init_flags);
Trond Myklebust52f98f1a22019-10-17 09:49:45 -0400112 __set_bit(NFS_CS_DS, &cl_init.init_flags);
Trond Myklebustc6eb5842019-10-03 14:12:46 -0400113
Peng Tao1a04c6e2014-05-30 18:15:57 +0800114 /* Use the MDS nfs_client cl_ipaddr. */
115 nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans);
Anna Schumaker7d38de32016-11-17 15:15:55 -0500116 clp = nfs_get_client(&cl_init);
Peng Tao1a04c6e2014-05-30 18:15:57 +0800117
118 return clp;
119}
120EXPORT_SYMBOL_GPL(nfs3_set_ds_client);