blob: ca7e108248e211208c0d2317b3b28cbd8394660f [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 */
Trond Myklebustae6ec912019-04-07 13:58:58 -040053 cl_softerr : 1,/* Timeouts return errors */
Chuck Lever43d78ef2007-02-06 18:26:11 -050054 cl_discrtry : 1,/* disconnect before retry */
Trond Myklebust8a19a0b2013-09-24 12:00:27 -040055 cl_noretranstimeo: 1,/* No retransmit timeouts */
Olga Kornievskaiab6b61522008-06-09 16:51:31 -040056 cl_autobind : 1,/* use getport() */
57 cl_chatty : 1;/* be verbose */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 struct rpc_rtt * cl_rtt; /* RTO estimator data */
Trond Myklebustba7392b2007-12-20 16:03:55 -050060 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Jeff Layton3c87ef62015-06-03 16:14:25 -040062 atomic_t cl_swapper; /* swapfile count */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 int cl_nodelen; /* nodename length */
Trond Myklebust03a9a422015-01-30 18:12:28 -050064 char cl_nodename[UNX_MAXNODENAME+1];
Trond Myklebust6739ffb2013-08-26 15:38:11 -040065 struct rpc_pipe_dir_head cl_pipedir_objects;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 struct rpc_clnt * cl_parent; /* Points to parent of clones */
67 struct rpc_rtt cl_rtt_default;
Trond Myklebustba7392b2007-12-20 16:03:55 -050068 struct rpc_timeout cl_timeout_default;
Trond Myklebusta613fa12012-01-20 13:53:56 -050069 const struct rpc_program *cl_program;
NeilBrown5e169232018-12-03 11:30:30 +110070 const char * cl_principal; /* use for machine cred */
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -050071#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
72 struct dentry *cl_debugfs; /* debugfs directory */
73#endif
Trond Myklebustad01b2c2016-01-30 14:17:26 -050074 struct rpc_xprt_iter cl_xpi;
Trond Myklebust79caa5f2019-04-24 17:46:42 -040075 const struct cred *cl_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78/*
79 * General RPC program info
80 */
81#define RPC_MAXVERSION 4
82struct rpc_program {
Trond Myklebust080b7942012-01-20 13:53:56 -050083 const char * name; /* protocol name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 u32 number; /* program number */
85 unsigned int nrvers; /* number of versions */
Trond Myklebusta613fa12012-01-20 13:53:56 -050086 const struct rpc_version ** version; /* version array */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 struct rpc_stat * stats; /* statistics */
Trond Myklebust080b7942012-01-20 13:53:56 -050088 const char * pipe_dir_name; /* path to rpc_pipefs dir */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
91struct rpc_version {
92 u32 number; /* version number */
93 unsigned int nrprocs; /* number of procs */
Christoph Hellwig499b4982017-05-12 15:36:49 +020094 const struct rpc_procinfo *procs; /* procedure array */
Christoph Hellwig1c5876d2017-05-08 23:27:10 +020095 unsigned int *counts; /* call counts */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
98/*
99 * Procedure information
100 */
101struct rpc_procinfo {
102 u32 p_proc; /* RPC procedure number */
Chuck Lever9f06c712010-12-14 14:59:18 +0000103 kxdreproc_t p_encode; /* XDR encode function */
Chuck Leverbf269552010-12-14 14:59:29 +0000104 kxdrdproc_t p_decode; /* XDR decode function */
Chuck Lever2bea90d2007-03-29 16:47:53 -0400105 unsigned int p_arglen; /* argument hdr length (u32) */
106 unsigned int p_replen; /* reply hdr length (u32) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 unsigned int p_timer; /* Which RTT timer to use */
Chuck Levercc0175c2006-03-20 13:44:22 -0500108 u32 p_statidx; /* Which procedure to account */
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500109 const char * p_name; /* name of procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
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;
Trond Myklebust612b41f2017-04-27 08:50:51 -0400125 u32 nconnect;
Chuck Leverc2866762006-08-22 20:06:20 -0400126 unsigned long flags;
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500127 char *client_name;
Alexandros Batsakisf300bab2009-09-10 17:33:30 +0300128 struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
Trond Myklebust79caa5f2019-04-24 17:46:42 -0400129 const struct cred *cred;
Chuck Leverc2866762006-08-22 20:06:20 -0400130};
131
Andy Adamsonfda0ab42016-09-09 09:22:26 -0400132struct rpc_add_xprt_test {
Santosh kumar pradhan10e037d2018-12-19 12:29:57 +0530133 void (*add_xprt_test)(struct rpc_clnt *clnt,
134 struct rpc_xprt *xprt,
Andy Adamsonfda0ab42016-09-09 09:22:26 -0400135 void *calldata);
136 void *data;
137};
138
Chuck Leverc2866762006-08-22 20:06:20 -0400139/* Values for "flags" field */
140#define RPC_CLNT_CREATE_HARDRTRY (1UL << 0)
Chuck Leverc2866762006-08-22 20:06:20 -0400141#define RPC_CLNT_CREATE_AUTOBIND (1UL << 2)
Trond Myklebust90c57552007-06-09 19:49:36 -0400142#define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3)
143#define RPC_CLNT_CREATE_NOPING (1UL << 4)
144#define RPC_CLNT_CREATE_DISCRTRY (1UL << 5)
Olga Kornievskaiab6b61522008-06-09 16:51:31 -0400145#define RPC_CLNT_CREATE_QUIET (1UL << 6)
Trond Myklebustb7993ce2013-04-14 11:42:00 -0400146#define RPC_CLNT_CREATE_INFINITE_SLOTS (1UL << 7)
J. Bruce Fields33d90ac2013-04-11 15:06:36 -0400147#define RPC_CLNT_CREATE_NO_IDLE_TIMEOUT (1UL << 8)
Trond Myklebust8a19a0b2013-09-24 12:00:27 -0400148#define RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT (1UL << 9)
Trond Myklebustae6ec912019-04-07 13:58:58 -0400149#define RPC_CLNT_CREATE_SOFTERR (1UL << 10)
Trond Myklebuste6237b62019-10-17 11:13:54 -0400150#define RPC_CLNT_CREATE_REUSEPORT (1UL << 11)
Chuck Leverc2866762006-08-22 20:06:20 -0400151
152struct rpc_clnt *rpc_create(struct rpc_create_args *args);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000153struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
Trond Myklebusta613fa12012-01-20 13:53:56 -0500154 const struct rpc_program *, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
Chuck Leverba9b5842012-09-14 17:24:02 -0400156struct rpc_clnt *rpc_clone_client_set_auth(struct rpc_clnt *,
157 rpc_authflavor_t);
Trond Myklebust40b00b6b2013-10-17 14:12:23 -0400158int rpc_switch_client_transport(struct rpc_clnt *,
159 struct xprt_create *,
160 const struct rpc_timeout *);
161
Trond Myklebust4c402b42007-06-14 16:40:32 -0400162void rpc_shutdown_client(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163void rpc_release_client(struct rpc_clnt *);
Bill Baker0f90be12018-06-19 16:24:58 -0500164void rpc_task_release_transport(struct rpc_task *);
Trond Myklebust58f96122010-07-31 14:29:08 -0400165void rpc_task_release_client(struct rpc_task *);
Trond Myklebusta101b042019-07-11 16:33:12 -0400166struct rpc_xprt *rpc_task_get_xprt(struct rpc_clnt *clnt,
167 struct rpc_xprt *xprt);
Chuck Levercce63cd2007-07-01 12:13:12 -0400168
Stanislav Kinsburskyf7a30c12012-01-13 12:52:51 +0400169int rpcb_create_local(struct net *);
170void rpcb_put_local(struct net *);
Stanislav Kinsbursky977ac312012-01-13 12:52:43 +0400171int rpcb_register(struct net *, u32, u32, int, unsigned short);
172int rpcb_v4_register(struct net *net, const u32 program,
173 const u32 version,
Chuck Leverc2e1b092008-07-14 16:03:30 -0400174 const struct sockaddr *address,
Chuck Lever14aeb212008-08-18 19:34:00 -0400175 const char *netid);
Chuck Lever45160d62007-07-01 12:13:17 -0400176void rpcb_getport_async(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Chuck Levercf500ba2019-02-11 11:25:20 -0500178void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
179 unsigned int base, unsigned int len,
180 unsigned int hdrsize);
Trond Myklebust77de2c52007-10-25 18:40:21 -0400181void rpc_call_start(struct rpc_task *);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500182int rpc_call_async(struct rpc_clnt *clnt,
183 const struct rpc_message *msg, int flags,
184 const struct rpc_call_ops *tk_ops,
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100185 void *calldata);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500186int rpc_call_sync(struct rpc_clnt *clnt,
187 const struct rpc_message *msg, int flags);
Trond Myklebust5e1550d2007-06-23 10:17:16 -0400188struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
189 int flags);
Trond Myklebustf1f88fc2010-07-31 14:29:07 -0400190int rpc_restart_call_prepare(struct rpc_task *);
191int rpc_restart_call(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500193struct net * rpc_net_ns(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194size_t rpc_max_payload(struct rpc_clnt *);
Chuck Lever6b26cc82016-05-02 14:40:40 -0400195size_t rpc_max_bc_payload(struct rpc_clnt *);
Trond Myklebust7402a4f2019-07-16 13:51:29 -0400196unsigned int rpc_num_bc_slots(struct rpc_clnt *);
Chuck Lever35f5a422006-01-03 09:55:50 +0100197void rpc_force_rebind(struct rpc_clnt *);
Chuck Levered394402006-08-22 20:06:17 -0400198size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
Chuck Leverb454ae92008-01-07 18:34:48 -0500199const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
Chuck Lever2e738fd2012-03-01 17:01:14 -0500200int rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Trond Myklebust32278862016-01-30 20:39:19 -0500202int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
203 int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
204 void *data);
205
Trond Myklebust7f554892016-01-30 23:43:35 -0500206int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
207 struct rpc_xprt_switch *xps,
208 struct rpc_xprt *xprt,
209 void *dummy);
210int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
211 int (*setup)(struct rpc_clnt *,
212 struct rpc_xprt_switch *,
213 struct rpc_xprt *,
214 void *),
215 void *data);
Trond Myklebust26ae1022017-02-08 11:17:55 -0500216void rpc_set_connect_timeout(struct rpc_clnt *clnt,
217 unsigned long connect_timeout,
218 unsigned long reconnect_timeout);
Trond Myklebust7f554892016-01-30 23:43:35 -0500219
Andy Adamsonfda0ab42016-09-09 09:22:26 -0400220int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *,
221 struct rpc_xprt_switch *,
222 struct rpc_xprt *,
223 void *);
224
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -0500225const char *rpc_proc_name(const struct rpc_task *task);
Andy Adamson3b58a8a2016-09-09 09:22:23 -0400226
227void rpc_clnt_xprt_switch_put(struct rpc_clnt *);
Andy Adamsondd691712016-09-09 09:22:24 -0400228void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *, struct rpc_xprt *);
Andy Adamson39e5d2d2016-09-09 09:22:25 -0400229bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
230 const struct sockaddr *sap);
Kinglong Meec929ea02017-01-20 16:48:39 +0800231void rpc_cleanup_clids(void);
Chuck Leverfb14ae82018-02-28 15:30:54 -0500232
233static inline int rpc_reply_expected(struct rpc_task *task)
234{
235 return (task->tk_msg.rpc_proc != NULL) &&
236 (task->tk_msg.rpc_proc->p_decode != NULL);
237}
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239#endif /* _LINUX_SUNRPC_CLNT_H */