1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/nfs_fs.h>
3 #include <linux/nfs_mount.h>
4 #include <linux/sunrpc/addr.h>
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
,
14 const struct rpc_program nfsacl_program
= {
16 .number
= NFS_ACL_PROGRAM
,
17 .nrvers
= ARRAY_SIZE(nfsacl_version
),
18 .version
= nfsacl_version
,
19 .stats
= &nfsacl_rpcstat
,
23 * Initialise an NFSv3 ACL client connection
25 static void nfs_init_server_aclclient(struct nfs_server
*server
)
27 if (server
->flags
& NFS_MOUNT_NOACL
)
30 server
->client_acl
= rpc_bind_new_program(server
->client
, &nfsacl_program
, 3);
31 if (IS_ERR(server
->client_acl
))
34 /* No errors! Assume that Sun nfsacls are supported */
35 server
->caps
|= NFS_CAP_ACLS
;
39 server
->caps
&= ~NFS_CAP_ACLS
;
42 static inline void nfs_init_server_aclclient(struct nfs_server
*server
)
44 server
->flags
&= ~NFS_MOUNT_NOACL
;
45 server
->caps
&= ~NFS_CAP_ACLS
;
49 struct nfs_server
*nfs3_create_server(struct fs_context
*fc
)
51 struct nfs_server
*server
= nfs_create_server(fc
);
53 /* Create a client RPC handle for the NFS v3 ACL management interface */
55 nfs_init_server_aclclient(server
);
59 struct nfs_server
*nfs3_clone_server(struct nfs_server
*source
,
61 struct nfs_fattr
*fattr
,
62 rpc_authflavor_t flavor
)
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
);
71 * Set up a pNFS Data Server client over NFSv3.
73 * Return any existing nfs_client that matches server address,port,version
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
80 struct nfs_client
*nfs3_set_ds_client(struct nfs_server
*mds_srv
,
81 const struct sockaddr
*ds_addr
, int ds_addrlen
,
82 int ds_proto
, unsigned int ds_timeo
, unsigned int ds_retrans
)
84 struct rpc_timeout ds_timeout
;
85 struct nfs_client
*mds_clp
= mds_srv
->nfs_client
;
86 struct nfs_client_initdata cl_init
= {
88 .addrlen
= ds_addrlen
,
89 .nodename
= mds_clp
->cl_rpcclient
->cl_nodename
,
90 .ip_addr
= mds_clp
->cl_ipaddr
,
93 .net
= mds_clp
->cl_net
,
94 .timeparms
= &ds_timeout
,
95 .cred
= mds_srv
->cred
,
97 struct nfs_client
*clp
;
98 char buf
[INET6_ADDRSTRLEN
+ 1];
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
;
105 if (mds_clp
->cl_nconnect
> 1 && ds_proto
== XPRT_TRANSPORT_TCP
)
106 cl_init
.nconnect
= mds_clp
->cl_nconnect
;
108 if (mds_srv
->flags
& NFS_MOUNT_NORESVPORT
)
109 __set_bit(NFS_CS_NORESVPORT
, &cl_init
.init_flags
);
111 __set_bit(NFS_CS_NOPING
, &cl_init
.init_flags
);
112 __set_bit(NFS_CS_DS
, &cl_init
.init_flags
);
114 /* Use the MDS nfs_client cl_ipaddr. */
115 nfs_init_timeout_values(&ds_timeout
, ds_proto
, ds_timeo
, ds_retrans
);
116 clp
= nfs_get_client(&cl_init
);
120 EXPORT_SYMBOL_GPL(nfs3_set_ds_client
);