blob: fc6dfbf77a9d24ceceef01fdf1586b466e23c2d4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/include/linux/sunrpc/clnt.h
4 *
5 * Declarations for the high-level RPC client interface
6 *
7 * Copyright (C) 1995, 1996, Olaf Kirch <okir@monad.swb.de>
8 */
9
10#ifndef _LINUX_SUNRPC_CLNT_H
11#define _LINUX_SUNRPC_CLNT_H
12
Trond Myklebustd77385f2011-10-17 16:08:10 -070013#include <linux/types.h>
Chuck Levera02d6922009-08-09 15:09:34 -040014#include <linux/socket.h>
15#include <linux/in.h>
16#include <linux/in6.h>
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/sunrpc/msg_prot.h>
19#include <linux/sunrpc/sched.h>
20#include <linux/sunrpc/xprt.h>
21#include <linux/sunrpc/auth.h>
22#include <linux/sunrpc/stats.h>
23#include <linux/sunrpc/xdr.h>
24#include <linux/sunrpc/timer.h>
Trond Myklebust6739ffb2013-08-26 15:38:11 -040025#include <linux/sunrpc/rpc_pipe_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/signal.h>
Trond Myklebust7d217ca2009-08-09 15:14:24 -040027#include <linux/path.h>
Jeff Layton4516fc02009-08-14 12:57:54 -040028#include <net/ipv6.h>
Trond Myklebustad01b2c2016-01-30 14:17:26 -050029#include <linux/sunrpc/xprtmultipath.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031struct rpc_inode;
32
33/*
34 * The high-level client handle
35 */
36struct rpc_clnt {
Trond Myklebust006abe82010-09-12 19:55:25 -040037 atomic_t cl_count; /* Number of references */
Trond Myklebust2f048db2013-09-04 21:51:44 -040038 unsigned int cl_clid; /* client id */
Trond Myklebust6529eba2007-06-14 16:40:14 -040039 struct list_head cl_clients; /* Global list of clients */
40 struct list_head cl_tasks; /* List of tasks */
Trond Myklebust4bef61f2007-06-16 14:17:01 -040041 spinlock_t cl_lock; /* spinlock */
Trond Myklebust2446ab62012-03-01 17:00:56 -050042 struct rpc_xprt __rcu * cl_xprt; /* transport */
Christoph Hellwig499b4982017-05-12 15:36:49 +020043 const struct rpc_procinfo *cl_procinfo; /* procedure info */
Chuck Lever4a681792006-08-22 20:06:15 -040044 u32 cl_prog, /* RPC program number */
45 cl_vers, /* RPC version number */
46 cl_maxproc; /* max procedure number */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 struct rpc_auth * cl_auth; /* authenticator */
Chuck Lever11c556b2006-03-20 13:44:22 -050049 struct rpc_stat * cl_stats; /* per-program statistics */
50 struct rpc_iostats * cl_metrics; /* per-client statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 unsigned int cl_softrtry : 1,/* soft timeouts */
Chuck Lever43d78ef2007-02-06 18:26:11 -050053 cl_discrtry : 1,/* disconnect before retry */
Trond Myklebust8a19a0b2013-09-24 12:00:27 -040054 cl_noretranstimeo: 1,/* No retransmit timeouts */
Olga Kornievskaiab6b61522008-06-09 16:51:31 -040055 cl_autobind : 1,/* use getport() */
56 cl_chatty : 1;/* be verbose */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 struct rpc_rtt * cl_rtt; /* RTO estimator data */
Trond Myklebustba7392b2007-12-20 16:03:55 -050059 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Jeff Layton3c87ef62015-06-03 16:14:25 -040061 atomic_t cl_swapper; /* swapfile count */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 int cl_nodelen; /* nodename length */
Trond Myklebust03a9a422015-01-30 18:12:28 -050063 char cl_nodename[UNX_MAXNODENAME+1];
Trond Myklebust6739ffb2013-08-26 15:38:11 -040064 struct rpc_pipe_dir_head cl_pipedir_objects;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 struct rpc_clnt * cl_parent; /* Points to parent of clones */
66 struct rpc_rtt cl_rtt_default;
Trond Myklebustba7392b2007-12-20 16:03:55 -050067 struct rpc_timeout cl_timeout_default;
Trond Myklebusta613fa12012-01-20 13:53:56 -050068 const struct rpc_program *cl_program;
NeilBrown5e169232018-12-03 11:30:30 +110069 const char * cl_principal; /* use for machine cred */
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -050070#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
71 struct dentry *cl_debugfs; /* debugfs directory */
72#endif
Trond Myklebustad01b2c2016-01-30 14:17:26 -050073 struct rpc_xprt_iter cl_xpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/*
77 * General RPC program info
78 */
79#define RPC_MAXVERSION 4
80struct rpc_program {
Trond Myklebust080b7942012-01-20 13:53:56 -050081 const char * name; /* protocol name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 u32 number; /* program number */
83 unsigned int nrvers; /* number of versions */
Trond Myklebusta613fa12012-01-20 13:53:56 -050084 const struct rpc_version ** version; /* version array */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 struct rpc_stat * stats; /* statistics */
Trond Myklebust080b7942012-01-20 13:53:56 -050086 const char * pipe_dir_name; /* path to rpc_pipefs dir */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087};
88
89struct rpc_version {
90 u32 number; /* version number */
91 unsigned int nrprocs; /* number of procs */
Christoph Hellwig499b4982017-05-12 15:36:49 +020092 const struct rpc_procinfo *procs; /* procedure array */
Christoph Hellwig1c5876d2017-05-08 23:27:10 +020093 unsigned int *counts; /* call counts */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094};
95
96/*
97 * Procedure information
98 */
99struct rpc_procinfo {
100 u32 p_proc; /* RPC procedure number */
Chuck Lever9f06c712010-12-14 14:59:18 +0000101 kxdreproc_t p_encode; /* XDR encode function */
Chuck Leverbf269552010-12-14 14:59:29 +0000102 kxdrdproc_t p_decode; /* XDR decode function */
Chuck Lever2bea90d2007-03-29 16:47:53 -0400103 unsigned int p_arglen; /* argument hdr length (u32) */
104 unsigned int p_replen; /* reply hdr length (u32) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 unsigned int p_timer; /* Which RTT timer to use */
Chuck Levercc0175c2006-03-20 13:44:22 -0500106 u32 p_statidx; /* Which procedure to account */
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500107 const char * p_name; /* name of procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108};
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#ifdef __KERNEL__
111
Chuck Leverc2866762006-08-22 20:06:20 -0400112struct rpc_create_args {
Pavel Emelyanovc653ce32010-09-29 16:04:45 +0400113 struct net *net;
Chuck Leverc2866762006-08-22 20:06:20 -0400114 int protocol;
115 struct sockaddr *address;
116 size_t addrsize;
Frank van Maarseveend3bc9a12007-07-09 22:23:35 +0200117 struct sockaddr *saddress;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500118 const struct rpc_timeout *timeout;
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500119 const char *servername;
Trond Myklebust03a9a422015-01-30 18:12:28 -0500120 const char *nodename;
Trond Myklebusta613fa12012-01-20 13:53:56 -0500121 const struct rpc_program *program;
Benny Halevyd5b337b2008-09-28 09:21:26 +0300122 u32 prognumber; /* overrides program->number */
Chuck Leverc2866762006-08-22 20:06:20 -0400123 u32 version;
124 rpc_authflavor_t authflavor;
125 unsigned long flags;
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500126 char *client_name;
Alexandros Batsakisf300bab2009-09-10 17:33:30 +0300127 struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
Chuck Leverc2866762006-08-22 20:06:20 -0400128};
129
Andy Adamsonfda0ab42016-09-09 09:22:26 -0400130struct rpc_add_xprt_test {
131 int (*add_xprt_test)(struct rpc_clnt *,
132 struct rpc_xprt *,
133 void *calldata);
134 void *data;
135};
136
Chuck Leverc2866762006-08-22 20:06:20 -0400137/* Values for "flags" field */
138#define RPC_CLNT_CREATE_HARDRTRY (1UL << 0)
Chuck Leverc2866762006-08-22 20:06:20 -0400139#define RPC_CLNT_CREATE_AUTOBIND (1UL << 2)
Trond Myklebust90c57552007-06-09 19:49:36 -0400140#define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3)
141#define RPC_CLNT_CREATE_NOPING (1UL << 4)
142#define RPC_CLNT_CREATE_DISCRTRY (1UL << 5)
Olga Kornievskaiab6b61522008-06-09 16:51:31 -0400143#define RPC_CLNT_CREATE_QUIET (1UL << 6)
Trond Myklebustb7993ce2013-04-14 11:42:00 -0400144#define RPC_CLNT_CREATE_INFINITE_SLOTS (1UL << 7)
J. Bruce Fields33d90ac2013-04-11 15:06:36 -0400145#define RPC_CLNT_CREATE_NO_IDLE_TIMEOUT (1UL << 8)
Trond Myklebust8a19a0b2013-09-24 12:00:27 -0400146#define RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT (1UL << 9)
Chuck Leverc2866762006-08-22 20:06:20 -0400147
148struct rpc_clnt *rpc_create(struct rpc_create_args *args);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000149struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
Trond Myklebusta613fa12012-01-20 13:53:56 -0500150 const struct rpc_program *, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
Chuck Leverba9b5842012-09-14 17:24:02 -0400152struct rpc_clnt *rpc_clone_client_set_auth(struct rpc_clnt *,
153 rpc_authflavor_t);
Trond Myklebust40b00b6b2013-10-17 14:12:23 -0400154int rpc_switch_client_transport(struct rpc_clnt *,
155 struct xprt_create *,
156 const struct rpc_timeout *);
157
Trond Myklebust4c402b42007-06-14 16:40:32 -0400158void rpc_shutdown_client(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159void rpc_release_client(struct rpc_clnt *);
Bill Baker0f90be12018-06-19 16:24:58 -0500160void rpc_task_release_transport(struct rpc_task *);
Trond Myklebust58f96122010-07-31 14:29:08 -0400161void rpc_task_release_client(struct rpc_task *);
Chuck Levercce63cd2007-07-01 12:13:12 -0400162
Stanislav Kinsburskyf7a30c12012-01-13 12:52:51 +0400163int rpcb_create_local(struct net *);
164void rpcb_put_local(struct net *);
Stanislav Kinsbursky977ac312012-01-13 12:52:43 +0400165int rpcb_register(struct net *, u32, u32, int, unsigned short);
166int rpcb_v4_register(struct net *net, const u32 program,
167 const u32 version,
Chuck Leverc2e1b092008-07-14 16:03:30 -0400168 const struct sockaddr *address,
Chuck Lever14aeb212008-08-18 19:34:00 -0400169 const char *netid);
Chuck Lever45160d62007-07-01 12:13:17 -0400170void rpcb_getport_async(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Trond Myklebust77de2c52007-10-25 18:40:21 -0400172void rpc_call_start(struct rpc_task *);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500173int rpc_call_async(struct rpc_clnt *clnt,
174 const struct rpc_message *msg, int flags,
175 const struct rpc_call_ops *tk_ops,
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100176 void *calldata);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500177int rpc_call_sync(struct rpc_clnt *clnt,
178 const struct rpc_message *msg, int flags);
Trond Myklebust5e1550d2007-06-23 10:17:16 -0400179struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
180 int flags);
Trond Myklebustf1f88fc2010-07-31 14:29:07 -0400181int rpc_restart_call_prepare(struct rpc_task *);
182int rpc_restart_call(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500184struct net * rpc_net_ns(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185size_t rpc_max_payload(struct rpc_clnt *);
Chuck Lever6b26cc82016-05-02 14:40:40 -0400186size_t rpc_max_bc_payload(struct rpc_clnt *);
Chuck Lever35f5a422006-01-03 09:55:50 +0100187void rpc_force_rebind(struct rpc_clnt *);
Chuck Levered394402006-08-22 20:06:17 -0400188size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
Chuck Leverb454ae92008-01-07 18:34:48 -0500189const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
Chuck Lever2e738fd2012-03-01 17:01:14 -0500190int rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Trond Myklebust32278862016-01-30 20:39:19 -0500192int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
193 int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
194 void *data);
195
Trond Myklebust7f554892016-01-30 23:43:35 -0500196int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
197 struct rpc_xprt_switch *xps,
198 struct rpc_xprt *xprt,
199 void *dummy);
200int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
201 int (*setup)(struct rpc_clnt *,
202 struct rpc_xprt_switch *,
203 struct rpc_xprt *,
204 void *),
205 void *data);
Trond Myklebust26ae1022017-02-08 11:17:55 -0500206void rpc_set_connect_timeout(struct rpc_clnt *clnt,
207 unsigned long connect_timeout,
208 unsigned long reconnect_timeout);
Trond Myklebust7f554892016-01-30 23:43:35 -0500209
Andy Adamsonfda0ab42016-09-09 09:22:26 -0400210int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *,
211 struct rpc_xprt_switch *,
212 struct rpc_xprt *,
213 void *);
214
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -0500215const char *rpc_proc_name(const struct rpc_task *task);
Andy Adamson3b58a8a2016-09-09 09:22:23 -0400216
217void rpc_clnt_xprt_switch_put(struct rpc_clnt *);
Andy Adamsondd691712016-09-09 09:22:24 -0400218void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *, struct rpc_xprt *);
Andy Adamson39e5d2d2016-09-09 09:22:25 -0400219bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
220 const struct sockaddr *sap);
Kinglong Meec929ea02017-01-20 16:48:39 +0800221void rpc_cleanup_clids(void);
Chuck Leverfb14ae82018-02-28 15:30:54 -0500222
223static inline int rpc_reply_expected(struct rpc_task *task)
224{
225 return (task->tk_msg.rpc_proc != NULL) &&
226 (task->tk_msg.rpc_proc->p_decode != NULL);
227}
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#endif /* __KERNEL__ */
230#endif /* _LINUX_SUNRPC_CLNT_H */