2019-05-19 12:08:55 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-07-30 20:05:19 +00:00
|
|
|
#include <linux/nfs_fs.h>
|
|
|
|
#include <linux/nfs_mount.h>
|
2014-07-07 22:21:10 +00:00
|
|
|
#include <linux/sunrpc/addr.h>
|
2012-07-30 20:05:19 +00:00
|
|
|
#include "internal.h"
|
2014-09-25 20:28:53 +00:00
|
|
|
#include "nfs3_fs.h"
|
2023-06-15 18:07:29 +00:00
|
|
|
#include "netns.h"
|
|
|
|
#include "sysfs.h"
|
2012-07-30 20:05:19 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_NFS_V3_ACL
|
|
|
|
static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
|
|
|
|
static const struct rpc_version *nfsacl_version[] = {
|
|
|
|
[3] = &nfsacl_version3,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct rpc_program nfsacl_program = {
|
|
|
|
.name = "nfsacl",
|
|
|
|
.number = NFS_ACL_PROGRAM,
|
|
|
|
.nrvers = ARRAY_SIZE(nfsacl_version),
|
|
|
|
.version = nfsacl_version,
|
|
|
|
.stats = &nfsacl_rpcstat,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise an NFSv3 ACL client connection
|
|
|
|
*/
|
|
|
|
static void nfs_init_server_aclclient(struct nfs_server *server)
|
|
|
|
{
|
|
|
|
if (server->flags & NFS_MOUNT_NOACL)
|
|
|
|
goto out_noacl;
|
|
|
|
|
|
|
|
server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
|
|
|
|
if (IS_ERR(server->client_acl))
|
|
|
|
goto out_noacl;
|
|
|
|
|
2023-06-15 18:07:29 +00:00
|
|
|
nfs_sysfs_link_rpc_client(server, server->client_acl, NULL);
|
|
|
|
|
2012-07-30 20:05:19 +00:00
|
|
|
/* No errors! Assume that Sun nfsacls are supported */
|
|
|
|
server->caps |= NFS_CAP_ACLS;
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_noacl:
|
|
|
|
server->caps &= ~NFS_CAP_ACLS;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void nfs_init_server_aclclient(struct nfs_server *server)
|
|
|
|
{
|
|
|
|
server->flags &= ~NFS_MOUNT_NOACL;
|
|
|
|
server->caps &= ~NFS_CAP_ACLS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-12-10 12:31:14 +00:00
|
|
|
struct nfs_server *nfs3_create_server(struct fs_context *fc)
|
2012-07-30 20:05:19 +00:00
|
|
|
{
|
2019-12-10 12:31:14 +00:00
|
|
|
struct nfs_server *server = nfs_create_server(fc);
|
|
|
|
|
2012-07-30 20:05:19 +00:00
|
|
|
/* Create a client RPC handle for the NFS v3 ACL management interface */
|
|
|
|
if (!IS_ERR(server))
|
|
|
|
nfs_init_server_aclclient(server);
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct nfs_server *nfs3_clone_server(struct nfs_server *source,
|
|
|
|
struct nfs_fh *fh,
|
|
|
|
struct nfs_fattr *fattr,
|
|
|
|
rpc_authflavor_t flavor)
|
|
|
|
{
|
|
|
|
struct nfs_server *server = nfs_clone_server(source, fh, fattr, flavor);
|
|
|
|
if (!IS_ERR(server) && !IS_ERR(source->client_acl))
|
|
|
|
nfs_init_server_aclclient(server);
|
|
|
|
return server;
|
|
|
|
}
|
2014-05-30 10:15:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a pNFS Data Server client over NFSv3.
|
|
|
|
*
|
|
|
|
* Return any existing nfs_client that matches server address,port,version
|
|
|
|
* and minorversion.
|
|
|
|
*
|
|
|
|
* For a new nfs_client, use a soft mount (default), a low retrans and a
|
|
|
|
* low timeout interval so that if a connection is lost, we retry through
|
|
|
|
* the MDS.
|
|
|
|
*/
|
2016-06-13 18:52:00 +00:00
|
|
|
struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
|
2022-10-17 04:36:50 +00:00
|
|
|
const struct sockaddr_storage *ds_addr, int ds_addrlen,
|
2016-11-17 20:15:55 +00:00
|
|
|
int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans)
|
2014-05-30 10:15:57 +00:00
|
|
|
{
|
2016-06-22 18:13:12 +00:00
|
|
|
struct rpc_timeout ds_timeout;
|
2023-08-19 21:32:25 +00:00
|
|
|
unsigned long connect_timeout = ds_timeo * (ds_retrans + 1) * HZ / 10;
|
2016-06-13 18:52:00 +00:00
|
|
|
struct nfs_client *mds_clp = mds_srv->nfs_client;
|
2014-05-30 10:15:57 +00:00
|
|
|
struct nfs_client_initdata cl_init = {
|
|
|
|
.addr = ds_addr,
|
|
|
|
.addrlen = ds_addrlen,
|
2016-06-22 18:13:12 +00:00
|
|
|
.nodename = mds_clp->cl_rpcclient->cl_nodename,
|
|
|
|
.ip_addr = mds_clp->cl_ipaddr,
|
2014-05-30 10:15:57 +00:00
|
|
|
.nfs_mod = &nfs_v3,
|
|
|
|
.proto = ds_proto,
|
|
|
|
.net = mds_clp->cl_net,
|
2016-06-22 18:13:12 +00:00
|
|
|
.timeparms = &ds_timeout,
|
2019-04-24 21:46:43 +00:00
|
|
|
.cred = mds_srv->cred,
|
2023-06-07 13:59:42 +00:00
|
|
|
.xprtsec = mds_clp->cl_xprtsec,
|
2023-08-19 21:32:25 +00:00
|
|
|
.connect_timeout = connect_timeout,
|
|
|
|
.reconnect_timeout = connect_timeout,
|
2014-05-30 10:15:57 +00:00
|
|
|
};
|
|
|
|
struct nfs_client *clp;
|
2014-07-07 22:21:10 +00:00
|
|
|
char buf[INET6_ADDRSTRLEN + 1];
|
|
|
|
|
|
|
|
/* fake a hostname because lockd wants it */
|
2022-10-17 04:36:50 +00:00
|
|
|
if (rpc_ntop((struct sockaddr *)ds_addr, buf, sizeof(buf)) <= 0)
|
2014-07-07 22:21:10 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
cl_init.hostname = buf;
|
2014-05-30 10:15:57 +00:00
|
|
|
|
2023-06-07 14:00:09 +00:00
|
|
|
switch (ds_proto) {
|
2024-02-13 18:31:47 +00:00
|
|
|
case XPRT_TRANSPORT_RDMA:
|
2023-06-07 14:00:09 +00:00
|
|
|
case XPRT_TRANSPORT_TCP:
|
|
|
|
case XPRT_TRANSPORT_TCP_TLS:
|
|
|
|
if (mds_clp->cl_nconnect > 1)
|
|
|
|
cl_init.nconnect = mds_clp->cl_nconnect;
|
|
|
|
}
|
2017-04-27 15:22:07 +00:00
|
|
|
|
2016-06-13 18:52:00 +00:00
|
|
|
if (mds_srv->flags & NFS_MOUNT_NORESVPORT)
|
2019-10-17 13:37:44 +00:00
|
|
|
__set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags);
|
2016-06-13 18:52:00 +00:00
|
|
|
|
2019-10-17 13:49:45 +00:00
|
|
|
__set_bit(NFS_CS_DS, &cl_init.init_flags);
|
2019-10-03 18:12:46 +00:00
|
|
|
|
2014-05-30 10:15:57 +00:00
|
|
|
/* Use the MDS nfs_client cl_ipaddr. */
|
|
|
|
nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans);
|
2016-11-17 20:15:55 +00:00
|
|
|
clp = nfs_get_client(&cl_init);
|
2014-05-30 10:15:57 +00:00
|
|
|
|
|
|
|
return clp;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs3_set_ds_client);
|