// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected]) */ #include <linux/module.h> #include <linux/nfs_fs.h> #include <linux/nfs_mount.h> #include <linux/sunrpc/addr.h> #include <linux/sunrpc/auth.h> #include <linux/sunrpc/xprt.h> #include <linux/sunrpc/bc_xprt.h> #include <linux/sunrpc/rpc_pipe_fs.h> #include "internal.h" #include "callback.h" #include "delegation.h" #include "nfs4session.h" #include "nfs4idmap.h" #include "pnfs.h" #include "netns.h" #include "sysfs.h" #define NFSDBG_FACILITY … /* * Get a unique NFSv4.0 callback identifier which will be used * by the V4.0 callback service to lookup the nfs_client struct */ static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion) { … } #ifdef CONFIG_NFS_V4_1 /* * Per auth flavor data server rpc clients */ struct nfs4_ds_server { … }; /** * nfs4_find_ds_client - Common lookup case for DS I/O * @ds_clp: pointer to the DS's nfs_client * @flavor: rpc auth flavour to match */ static struct nfs4_ds_server * nfs4_find_ds_client(struct nfs_client *ds_clp, rpc_authflavor_t flavor) { … } static struct nfs4_ds_server * nfs4_add_ds_client(struct nfs_client *ds_clp, rpc_authflavor_t flavor, struct nfs4_ds_server *new) { … } static struct nfs4_ds_server * nfs4_alloc_ds_server(struct nfs_client *ds_clp, rpc_authflavor_t flavor) { … } static void nfs4_free_ds_server(struct nfs4_ds_server *dss) { … } /** * nfs4_find_or_create_ds_client - Find or create a DS rpc client * @ds_clp: pointer to the DS's nfs_client * @inode: pointer to the inode * * Find or create a DS rpc client with th MDS server rpc client auth flavor * in the nfs_client cl_ds_clients list. */ struct rpc_clnt * nfs4_find_or_create_ds_client(struct nfs_client *ds_clp, struct inode *inode) { … } EXPORT_SYMBOL_GPL(…); static void nfs4_shutdown_ds_clients(struct nfs_client *clp) { … } static void nfs4_cleanup_callback(struct nfs_client *clp) { … } void nfs41_shutdown_client(struct nfs_client *clp) { … } #endif /* CONFIG_NFS_V4_1 */ void nfs40_shutdown_client(struct nfs_client *clp) { … } struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) { … } /* * Destroy the NFS4 callback service */ static void nfs4_destroy_callback(struct nfs_client *clp) { … } static void nfs4_shutdown_client(struct nfs_client *clp) { … } void nfs4_free_client(struct nfs_client *clp) { … } /* * Initialize the NFS4 callback service */ static int nfs4_init_callback(struct nfs_client *clp) { … } /** * nfs40_init_client - nfs_client initialization tasks for NFSv4.0 * @clp: nfs_client to initialize * * Returns zero on success, or a negative errno if some error occurred. */ int nfs40_init_client(struct nfs_client *clp) { … } #if defined(CONFIG_NFS_V4_1) /** * nfs41_init_client - nfs_client initialization tasks for NFSv4.1+ * @clp: nfs_client to initialize * * Returns zero on success, or a negative errno if some error occurred. */ int nfs41_init_client(struct nfs_client *clp) { … } #endif /* CONFIG_NFS_V4_1 */ /* * Initialize the minor version specific parts of an NFS4 client record */ static int nfs4_init_client_minor_version(struct nfs_client *clp) { … } static void nfs4_add_trunk(struct nfs_client *clp, struct nfs_client *old) { … } /** * nfs4_init_client - Initialise an NFS4 client record * * @clp: nfs_client to initialise * @cl_init: pointer to nfs_client_initdata * * Returns pointer to an NFS client, or an ERR_PTR value. */ struct nfs_client *nfs4_init_client(struct nfs_client *clp, const struct nfs_client_initdata *cl_init) { … } /* * SETCLIENTID just did a callback update with the callback ident in * "drop," but server trunking discovery claims "drop" and "keep" are * actually the same server. Swap the callback IDs so that "keep" * will continue to use the callback ident the server now knows about, * and so that "keep"'s original callback ident is destroyed when * "drop" is freed. */ static void nfs4_swap_callback_idents(struct nfs_client *keep, struct nfs_client *drop) { … } static bool nfs4_match_client_owner_id(const struct nfs_client *clp1, const struct nfs_client *clp2) { … } static bool nfs4_same_verifier(nfs4_verifier *v1, nfs4_verifier *v2) { … } static int nfs4_match_client(struct nfs_client *pos, struct nfs_client *new, struct nfs_client **prev, struct nfs_net *nn) { … } /** * nfs40_walk_client_list - Find server that recognizes a client ID * * @new: nfs_client with client ID to test * @result: OUT: found nfs_client, or new * @cred: credential to use for trunking test * * Returns zero, a negative errno, or a negative NFS4ERR status. * If zero is returned, an nfs_client pointer is planted in "result." * * NB: nfs40_walk_client_list() relies on the new nfs_client being * the last nfs_client on the list. */ int nfs40_walk_client_list(struct nfs_client *new, struct nfs_client **result, const struct cred *cred) { … } #ifdef CONFIG_NFS_V4_1 /* * Returns true if the server major ids match */ bool nfs4_check_serverowner_major_id(struct nfs41_server_owner *o1, struct nfs41_server_owner *o2) { … } /* * Returns true if the server scopes match */ static bool nfs4_check_server_scope(struct nfs41_server_scope *s1, struct nfs41_server_scope *s2) { … } /** * nfs4_detect_session_trunking - Checks for session trunking. * @clp: original mount nfs_client * @res: result structure from an exchange_id using the original mount * nfs_client with a new multi_addr transport * @xprt: pointer to the transport to add. * * Called after a successful EXCHANGE_ID on a multi-addr connection. * Upon success, add the transport. * * Returns zero on success, otherwise -EINVAL * * Note: since the exchange_id for the new multi_addr transport uses the * same nfs_client from the original mount, the cl_owner_id is reused, * so eir_clientowner is the same. */ int nfs4_detect_session_trunking(struct nfs_client *clp, struct nfs41_exchange_id_res *res, struct rpc_xprt *xprt) { … } /** * nfs41_walk_client_list - Find nfs_client that matches a client/server owner * * @new: nfs_client with client ID to test * @result: OUT: found nfs_client, or new * @cred: credential to use for trunking test * * Returns zero, a negative errno, or a negative NFS4ERR status. * If zero is returned, an nfs_client pointer is planted in "result." * * NB: nfs41_walk_client_list() relies on the new nfs_client being * the last nfs_client on the list. */ int nfs41_walk_client_list(struct nfs_client *new, struct nfs_client **result, const struct cred *cred) { … } #endif /* CONFIG_NFS_V4_1 */ static void nfs4_destroy_server(struct nfs_server *server) { … } /* * NFSv4.0 callback thread helper * * Find a client by callback identifier */ struct nfs_client * nfs4_find_client_ident(struct net *net, int cb_ident) { … } #if defined(CONFIG_NFS_V4_1) /* Common match routine for v4.0 and v4.1 callback services */ static bool nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp, u32 minorversion) { … } /* * NFSv4.1 callback thread helper * For CB_COMPOUND calls, find a client by IP address, protocol version, * minorversion, and sessionID * * Returns NULL if no such client */ struct nfs_client * nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, struct nfs4_sessionid *sid, u32 minorversion) { … } #else /* CONFIG_NFS_V4_1 */ struct nfs_client * nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, struct nfs4_sessionid *sid, u32 minorversion) { return NULL; } #endif /* CONFIG_NFS_V4_1 */ /* * Set up an NFS4 client */ static int nfs4_set_client(struct nfs_server *server, const char *hostname, const struct sockaddr_storage *addr, const size_t addrlen, const char *ip_addr, int proto, const struct rpc_timeout *timeparms, u32 minorversion, unsigned int nconnect, unsigned int max_connect, struct net *net, struct xprtsec_parms *xprtsec) { … } /* * Set up a pNFS Data Server client. * * 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. */ struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv, const struct sockaddr_storage *ds_addr, int ds_addrlen, int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans, u32 minor_version) { … } EXPORT_SYMBOL_GPL(…); /* * Session has been established, and the client marked ready. * Limit the mount rsize, wsize and dtsize using negotiated fore * channel attributes. */ static void nfs4_session_limit_rwsize(struct nfs_server *server) { … } /* * Limit xattr sizes using the channel attributes. */ static void nfs4_session_limit_xasize(struct nfs_server *server) { … } void nfs4_server_set_init_caps(struct nfs_server *server) { … } static int nfs4_server_common_setup(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe) { … } /* * Create a version 4 volume record */ static int nfs4_init_server(struct nfs_server *server, struct fs_context *fc) { … } /* * Create a version 4 volume record * - keyed on server and FSID */ struct nfs_server *nfs4_create_server(struct fs_context *fc) { … } /* * Create an NFS4 referral server record */ struct nfs_server *nfs4_create_referral_server(struct fs_context *fc) { … } /** * nfs4_update_server - Move an nfs_server to a different nfs_client * * @server: represents FSID to be moved * @hostname: new end-point's hostname * @sap: new end-point's socket address * @salen: size of "sap" * @net: net namespace * * The nfs_server must be quiescent before this function is invoked. * Either its session is drained (NFSv4.1+), or its transport is * plugged and drained (NFSv4.0). * * Returns zero on success, or a negative errno value. */ int nfs4_update_server(struct nfs_server *server, const char *hostname, struct sockaddr_storage *sap, size_t salen, struct net *net) { … }