Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 2 | #include <linux/nfs_fs.h> |
| 3 | #include <linux/nfs_mount.h> |
Peng Tao | 36d3e3d | 2014-07-08 06:21:10 +0800 | [diff] [blame] | 4 | #include <linux/sunrpc/addr.h> |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 5 | #include "internal.h" |
Trond Myklebust | 3fc3edf | 2014-09-25 16:28:53 -0400 | [diff] [blame] | 6 | #include "nfs3_fs.h" |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7 | |
| 8 | #ifdef CONFIG_NFS_V3_ACL |
| 9 | static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; |
| 10 | static const struct rpc_version *nfsacl_version[] = { |
| 11 | [3] = &nfsacl_version3, |
| 12 | }; |
| 13 | |
| 14 | const 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 | */ |
| 25 | static 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 | |
| 38 | out_noacl: |
| 39 | server->caps &= ~NFS_CAP_ACLS; |
| 40 | } |
| 41 | #else |
| 42 | static 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 Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 49 | struct nfs_server *nfs3_create_server(struct fs_context *fc) |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 50 | { |
Scott Mayhew | 62a55d0 | 2019-12-10 07:31:14 -0500 | [diff] [blame] | 51 | struct nfs_server *server = nfs_create_server(fc); |
| 52 | |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 53 | /* 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 | |
| 59 | struct 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 Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 69 | |
| 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 Mkrtchyan | b224f7c | 2016-06-13 20:52:00 +0200 | [diff] [blame] | 80 | struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv, |
Peng Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 81 | const struct sockaddr *ds_addr, int ds_addrlen, |
Anna Schumaker | 7d38de3 | 2016-11-17 15:15:55 -0500 | [diff] [blame] | 82 | int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans) |
Peng Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 83 | { |
Trond Myklebust | 5c6e5b6 | 2016-06-22 14:13:12 -0400 | [diff] [blame] | 84 | struct rpc_timeout ds_timeout; |
Tigran Mkrtchyan | b224f7c | 2016-06-13 20:52:00 +0200 | [diff] [blame] | 85 | struct nfs_client *mds_clp = mds_srv->nfs_client; |
Peng Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 86 | struct nfs_client_initdata cl_init = { |
| 87 | .addr = ds_addr, |
| 88 | .addrlen = ds_addrlen, |
Trond Myklebust | 5c6e5b6 | 2016-06-22 14:13:12 -0400 | [diff] [blame] | 89 | .nodename = mds_clp->cl_rpcclient->cl_nodename, |
| 90 | .ip_addr = mds_clp->cl_ipaddr, |
Peng Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 91 | .nfs_mod = &nfs_v3, |
| 92 | .proto = ds_proto, |
| 93 | .net = mds_clp->cl_net, |
Trond Myklebust | 5c6e5b6 | 2016-06-22 14:13:12 -0400 | [diff] [blame] | 94 | .timeparms = &ds_timeout, |
Trond Myklebust | 1a58e8a | 2019-04-24 17:46:43 -0400 | [diff] [blame] | 95 | .cred = mds_srv->cred, |
Peng Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 96 | }; |
Peng Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 97 | struct nfs_client *clp; |
Peng Tao | 36d3e3d | 2014-07-08 06:21:10 +0800 | [diff] [blame] | 98 | 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 Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 104 | |
Trond Myklebust | bb71e4a | 2017-04-27 11:22:07 -0400 | [diff] [blame] | 105 | if (mds_clp->cl_nconnect > 1 && ds_proto == XPRT_TRANSPORT_TCP) |
| 106 | cl_init.nconnect = mds_clp->cl_nconnect; |
| 107 | |
Tigran Mkrtchyan | b224f7c | 2016-06-13 20:52:00 +0200 | [diff] [blame] | 108 | if (mds_srv->flags & NFS_MOUNT_NORESVPORT) |
Trond Myklebust | d0372b67 | 2019-10-17 09:37:44 -0400 | [diff] [blame] | 109 | __set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags); |
Tigran Mkrtchyan | b224f7c | 2016-06-13 20:52:00 +0200 | [diff] [blame] | 110 | |
Trond Myklebust | c6eb584 | 2019-10-03 14:12:46 -0400 | [diff] [blame] | 111 | __set_bit(NFS_CS_NOPING, &cl_init.init_flags); |
Trond Myklebust | 52f98f1a2 | 2019-10-17 09:49:45 -0400 | [diff] [blame] | 112 | __set_bit(NFS_CS_DS, &cl_init.init_flags); |
Trond Myklebust | c6eb584 | 2019-10-03 14:12:46 -0400 | [diff] [blame] | 113 | |
Peng Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 114 | /* Use the MDS nfs_client cl_ipaddr. */ |
| 115 | nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans); |
Anna Schumaker | 7d38de3 | 2016-11-17 15:15:55 -0500 | [diff] [blame] | 116 | clp = nfs_get_client(&cl_init); |
Peng Tao | 1a04c6e | 2014-05-30 18:15:57 +0800 | [diff] [blame] | 117 | |
| 118 | return clp; |
| 119 | } |
| 120 | EXPORT_SYMBOL_GPL(nfs3_set_ds_client); |