Commit | Line | Data |
---|---|---|
457c8996 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1179acc6 BS |
2 | #include <linux/nfs_fs.h> |
3 | #include <linux/nfs_mount.h> | |
36d3e3dc | 4 | #include <linux/sunrpc/addr.h> |
1179acc6 | 5 | #include "internal.h" |
3fc3edf1 | 6 | #include "nfs3_fs.h" |
1179acc6 BS |
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 | ||
62a55d08 | 49 | struct nfs_server *nfs3_create_server(struct fs_context *fc) |
1179acc6 | 50 | { |
62a55d08 SM |
51 | struct nfs_server *server = nfs_create_server(fc); |
52 | ||
1179acc6 BS |
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 | } | |
1a04c6e1 PT |
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 | */ | |
b224f7cb | 80 | struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv, |
1a04c6e1 | 81 | const struct sockaddr *ds_addr, int ds_addrlen, |
7d38de3f | 82 | int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans) |
1a04c6e1 | 83 | { |
5c6e5b60 | 84 | struct rpc_timeout ds_timeout; |
b224f7cb | 85 | struct nfs_client *mds_clp = mds_srv->nfs_client; |
1a04c6e1 PT |
86 | struct nfs_client_initdata cl_init = { |
87 | .addr = ds_addr, | |
88 | .addrlen = ds_addrlen, | |
5c6e5b60 TM |
89 | .nodename = mds_clp->cl_rpcclient->cl_nodename, |
90 | .ip_addr = mds_clp->cl_ipaddr, | |
1a04c6e1 PT |
91 | .nfs_mod = &nfs_v3, |
92 | .proto = ds_proto, | |
93 | .net = mds_clp->cl_net, | |
5c6e5b60 | 94 | .timeparms = &ds_timeout, |
1a58e8a0 | 95 | .cred = mds_srv->cred, |
1a04c6e1 | 96 | }; |
1a04c6e1 | 97 | struct nfs_client *clp; |
36d3e3dc PT |
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; | |
1a04c6e1 | 104 | |
bb71e4a5 TM |
105 | if (mds_clp->cl_nconnect > 1 && ds_proto == XPRT_TRANSPORT_TCP) |
106 | cl_init.nconnect = mds_clp->cl_nconnect; | |
107 | ||
b224f7cb | 108 | if (mds_srv->flags & NFS_MOUNT_NORESVPORT) |
d0372b67 | 109 | __set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags); |
b224f7cb | 110 | |
c6eb5843 | 111 | __set_bit(NFS_CS_NOPING, &cl_init.init_flags); |
52f98f1a | 112 | __set_bit(NFS_CS_DS, &cl_init.init_flags); |
c6eb5843 | 113 | |
1a04c6e1 PT |
114 | /* Use the MDS nfs_client cl_ipaddr. */ |
115 | nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans); | |
7d38de3f | 116 | clp = nfs_get_client(&cl_init); |
1a04c6e1 PT |
117 | |
118 | return clp; | |
119 | } | |
120 | EXPORT_SYMBOL_GPL(nfs3_set_ds_client); |