blob: 9b11b6a0978c95467761d142716c873ac5c201d4 [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;
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -050069#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
70 struct dentry *cl_debugfs; /* debugfs directory */
71#endif
Trond Myklebustad01b2c2016-01-30 14:17:26 -050072 struct rpc_xprt_iter cl_xpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/*
76 * General RPC program info
77 */
78#define RPC_MAXVERSION 4
79struct rpc_program {
Trond Myklebust080b7942012-01-20 13:53:56 -050080 const char * name; /* protocol name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 u32 number; /* program number */
82 unsigned int nrvers; /* number of versions */
Trond Myklebusta613fa12012-01-20 13:53:56 -050083 const struct rpc_version ** version; /* version array */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 struct rpc_stat * stats; /* statistics */
Trond Myklebust080b7942012-01-20 13:53:56 -050085 const char * pipe_dir_name; /* path to rpc_pipefs dir */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
88struct rpc_version {
89 u32 number; /* version number */
90 unsigned int nrprocs; /* number of procs */
Christoph Hellwig499b4982017-05-12 15:36:49 +020091 const struct rpc_procinfo *procs; /* procedure array */
Christoph Hellwig1c5876d2017-05-08 23:27:10 +020092 unsigned int *counts; /* call counts */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093};
94
95/*
96 * Procedure information
97 */
98struct rpc_procinfo {
99 u32 p_proc; /* RPC procedure number */
Chuck Lever9f06c712010-12-14 14:59:18 +0000100 kxdreproc_t p_encode; /* XDR encode function */
Chuck Leverbf269552010-12-14 14:59:29 +0000101 kxdrdproc_t p_decode; /* XDR decode function */
Chuck Lever2bea90d2007-03-29 16:47:53 -0400102 unsigned int p_arglen; /* argument hdr length (u32) */
103 unsigned int p_replen; /* reply hdr length (u32) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 unsigned int p_timer; /* Which RTT timer to use */
Chuck Levercc0175c2006-03-20 13:44:22 -0500105 u32 p_statidx; /* Which procedure to account */
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500106 const char * p_name; /* name of procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#ifdef __KERNEL__
110
Chuck Leverc2866762006-08-22 20:06:20 -0400111struct rpc_create_args {
Pavel Emelyanovc653ce32010-09-29 16:04:45 +0400112 struct net *net;
Chuck Leverc2866762006-08-22 20:06:20 -0400113 int protocol;
114 struct sockaddr *address;
115 size_t addrsize;
Frank van Maarseveend3bc9a12007-07-09 22:23:35 +0200116 struct sockaddr *saddress;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500117 const struct rpc_timeout *timeout;
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500118 const char *servername;
Trond Myklebust03a9a422015-01-30 18:12:28 -0500119 const char *nodename;
Trond Myklebusta613fa12012-01-20 13:53:56 -0500120 const struct rpc_program *program;
Benny Halevyd5b337b2008-09-28 09:21:26 +0300121 u32 prognumber; /* overrides program->number */
Chuck Leverc2866762006-08-22 20:06:20 -0400122 u32 version;
123 rpc_authflavor_t authflavor;
124 unsigned long flags;
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500125 char *client_name;
Alexandros Batsakisf300bab2009-09-10 17:33:30 +0300126 struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
Chuck Leverc2866762006-08-22 20:06:20 -0400127};
128
Andy Adamsonfda0ab42016-09-09 09:22:26 -0400129struct rpc_add_xprt_test {
130 int (*add_xprt_test)(struct rpc_clnt *,
131 struct rpc_xprt *,
132 void *calldata);
133 void *data;
134};
135
Chuck Leverc2866762006-08-22 20:06:20 -0400136/* Values for "flags" field */
137#define RPC_CLNT_CREATE_HARDRTRY (1UL << 0)
Chuck Leverc2866762006-08-22 20:06:20 -0400138#define RPC_CLNT_CREATE_AUTOBIND (1UL << 2)
Trond Myklebust90c57552007-06-09 19:49:36 -0400139#define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3)
140#define RPC_CLNT_CREATE_NOPING (1UL << 4)
141#define RPC_CLNT_CREATE_DISCRTRY (1UL << 5)
Olga Kornievskaiab6b61522008-06-09 16:51:31 -0400142#define RPC_CLNT_CREATE_QUIET (1UL << 6)
Trond Myklebustb7993ce2013-04-14 11:42:00 -0400143#define RPC_CLNT_CREATE_INFINITE_SLOTS (1UL << 7)
J. Bruce Fields33d90ac2013-04-11 15:06:36 -0400144#define RPC_CLNT_CREATE_NO_IDLE_TIMEOUT (1UL << 8)
Trond Myklebust8a19a0b2013-09-24 12:00:27 -0400145#define RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT (1UL << 9)
Chuck Leverc2866762006-08-22 20:06:20 -0400146
147struct rpc_clnt *rpc_create(struct rpc_create_args *args);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000148struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
Trond Myklebusta613fa12012-01-20 13:53:56 -0500149 const struct rpc_program *, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
Chuck Leverba9b5842012-09-14 17:24:02 -0400151struct rpc_clnt *rpc_clone_client_set_auth(struct rpc_clnt *,
152 rpc_authflavor_t);
Trond Myklebust40b00b6b2013-10-17 14:12:23 -0400153int rpc_switch_client_transport(struct rpc_clnt *,
154 struct xprt_create *,
155 const struct rpc_timeout *);
156
Trond Myklebust4c402b42007-06-14 16:40:32 -0400157void rpc_shutdown_client(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158void rpc_release_client(struct rpc_clnt *);
Trond Myklebust58f96122010-07-31 14:29:08 -0400159void rpc_task_release_client(struct rpc_task *);
Chuck Levercce63cd2007-07-01 12:13:12 -0400160
Stanislav Kinsburskyf7a30c12012-01-13 12:52:51 +0400161int rpcb_create_local(struct net *);
162void rpcb_put_local(struct net *);
Stanislav Kinsbursky977ac312012-01-13 12:52:43 +0400163int rpcb_register(struct net *, u32, u32, int, unsigned short);
164int rpcb_v4_register(struct net *net, const u32 program,
165 const u32 version,
Chuck Leverc2e1b092008-07-14 16:03:30 -0400166 const struct sockaddr *address,
Chuck Lever14aeb212008-08-18 19:34:00 -0400167 const char *netid);
Chuck Lever45160d62007-07-01 12:13:17 -0400168void rpcb_getport_async(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Trond Myklebust77de2c52007-10-25 18:40:21 -0400170void rpc_call_start(struct rpc_task *);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500171int rpc_call_async(struct rpc_clnt *clnt,
172 const struct rpc_message *msg, int flags,
173 const struct rpc_call_ops *tk_ops,
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100174 void *calldata);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500175int rpc_call_sync(struct rpc_clnt *clnt,
176 const struct rpc_message *msg, int flags);
Trond Myklebust5e1550d2007-06-23 10:17:16 -0400177struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
178 int flags);
Trond Myklebustf1f88fc2010-07-31 14:29:07 -0400179int rpc_restart_call_prepare(struct rpc_task *);
180int rpc_restart_call(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500182struct net * rpc_net_ns(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183size_t rpc_max_payload(struct rpc_clnt *);
Chuck Lever6b26cc82016-05-02 14:40:40 -0400184size_t rpc_max_bc_payload(struct rpc_clnt *);
Chuck Lever35f5a422006-01-03 09:55:50 +0100185void rpc_force_rebind(struct rpc_clnt *);
Chuck Levered394402006-08-22 20:06:17 -0400186size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
Chuck Leverb454ae92008-01-07 18:34:48 -0500187const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
Chuck Lever2e738fd2012-03-01 17:01:14 -0500188int rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Trond Myklebust32278862016-01-30 20:39:19 -0500190int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
191 int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
192 void *data);
193
Trond Myklebust7f554892016-01-30 23:43:35 -0500194int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
195 struct rpc_xprt_switch *xps,
196 struct rpc_xprt *xprt,
197 void *dummy);
198int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
199 int (*setup)(struct rpc_clnt *,
200 struct rpc_xprt_switch *,
201 struct rpc_xprt *,
202 void *),
203 void *data);
Trond Myklebust26ae1022017-02-08 11:17:55 -0500204void rpc_set_connect_timeout(struct rpc_clnt *clnt,
205 unsigned long connect_timeout,
206 unsigned long reconnect_timeout);
Trond Myklebust7f554892016-01-30 23:43:35 -0500207
Andy Adamsonfda0ab42016-09-09 09:22:26 -0400208int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *,
209 struct rpc_xprt_switch *,
210 struct rpc_xprt *,
211 void *);
212
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -0500213const char *rpc_proc_name(const struct rpc_task *task);
Andy Adamson3b58a8a2016-09-09 09:22:23 -0400214
215void rpc_clnt_xprt_switch_put(struct rpc_clnt *);
Andy Adamsondd691712016-09-09 09:22:24 -0400216void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *, struct rpc_xprt *);
Andy Adamson39e5d2d2016-09-09 09:22:25 -0400217bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
218 const struct sockaddr *sap);
Kinglong Meec929ea02017-01-20 16:48:39 +0800219void rpc_cleanup_clids(void);
Chuck Leverfb14ae82018-02-28 15:30:54 -0500220
221static inline int rpc_reply_expected(struct rpc_task *task)
222{
223 return (task->tk_msg.rpc_proc != NULL) &&
224 (task->tk_msg.rpc_proc->p_decode != NULL);
225}
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#endif /* __KERNEL__ */
228#endif /* _LINUX_SUNRPC_CLNT_H */