blob: b6810c92b8bb14d9ef8c9d1036a0b25d40530ac3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/include/linux/sunrpc/clnt.h
3 *
4 * Declarations for the high-level RPC client interface
5 *
6 * Copyright (C) 1995, 1996, Olaf Kirch <okir@monad.swb.de>
7 */
8
9#ifndef _LINUX_SUNRPC_CLNT_H
10#define _LINUX_SUNRPC_CLNT_H
11
Trond Myklebustd77385f2011-10-17 16:08:10 -070012#include <linux/types.h>
Chuck Levera02d6922009-08-09 15:09:34 -040013#include <linux/socket.h>
14#include <linux/in.h>
15#include <linux/in6.h>
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/sunrpc/msg_prot.h>
18#include <linux/sunrpc/sched.h>
19#include <linux/sunrpc/xprt.h>
20#include <linux/sunrpc/auth.h>
21#include <linux/sunrpc/stats.h>
22#include <linux/sunrpc/xdr.h>
23#include <linux/sunrpc/timer.h>
Trond Myklebust6739ffb2013-08-26 15:38:11 -040024#include <linux/sunrpc/rpc_pipe_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/signal.h>
Trond Myklebust7d217ca2009-08-09 15:14:24 -040026#include <linux/path.h>
Jeff Layton4516fc02009-08-14 12:57:54 -040027#include <net/ipv6.h>
Trond Myklebustad01b2c2016-01-30 14:17:26 -050028#include <linux/sunrpc/xprtmultipath.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030struct rpc_inode;
31
32/*
33 * The high-level client handle
34 */
35struct rpc_clnt {
Trond Myklebust006abe82010-09-12 19:55:25 -040036 atomic_t cl_count; /* Number of references */
Trond Myklebust2f048db2013-09-04 21:51:44 -040037 unsigned int cl_clid; /* client id */
Trond Myklebust6529eba2007-06-14 16:40:14 -040038 struct list_head cl_clients; /* Global list of clients */
39 struct list_head cl_tasks; /* List of tasks */
Trond Myklebust4bef61f2007-06-16 14:17:01 -040040 spinlock_t cl_lock; /* spinlock */
Trond Myklebust2446ab62012-03-01 17:00:56 -050041 struct rpc_xprt __rcu * cl_xprt; /* transport */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 struct rpc_procinfo * cl_procinfo; /* procedure info */
Chuck Lever4a681792006-08-22 20:06:15 -040043 u32 cl_prog, /* RPC program number */
44 cl_vers, /* RPC version number */
45 cl_maxproc; /* max procedure number */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 struct rpc_auth * cl_auth; /* authenticator */
Chuck Lever11c556b2006-03-20 13:44:22 -050048 struct rpc_stat * cl_stats; /* per-program statistics */
49 struct rpc_iostats * cl_metrics; /* per-client statistics */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51 unsigned int cl_softrtry : 1,/* soft timeouts */
Chuck Lever43d78ef2007-02-06 18:26:11 -050052 cl_discrtry : 1,/* disconnect before retry */
Trond Myklebust8a19a0b2013-09-24 12:00:27 -040053 cl_noretranstimeo: 1,/* No retransmit timeouts */
Olga Kornievskaiab6b61522008-06-09 16:51:31 -040054 cl_autobind : 1,/* use getport() */
55 cl_chatty : 1;/* be verbose */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 struct rpc_rtt * cl_rtt; /* RTO estimator data */
Trond Myklebustba7392b2007-12-20 16:03:55 -050058 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Jeff Layton3c87ef62015-06-03 16:14:25 -040060 atomic_t cl_swapper; /* swapfile count */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 int cl_nodelen; /* nodename length */
Trond Myklebust03a9a422015-01-30 18:12:28 -050062 char cl_nodename[UNX_MAXNODENAME+1];
Trond Myklebust6739ffb2013-08-26 15:38:11 -040063 struct rpc_pipe_dir_head cl_pipedir_objects;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 struct rpc_clnt * cl_parent; /* Points to parent of clones */
65 struct rpc_rtt cl_rtt_default;
Trond Myklebustba7392b2007-12-20 16:03:55 -050066 struct rpc_timeout cl_timeout_default;
Trond Myklebusta613fa12012-01-20 13:53:56 -050067 const struct rpc_program *cl_program;
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -050068#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
69 struct dentry *cl_debugfs; /* debugfs directory */
70#endif
Trond Myklebustad01b2c2016-01-30 14:17:26 -050071 struct rpc_xprt_iter cl_xpi;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072};
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/*
75 * General RPC program info
76 */
77#define RPC_MAXVERSION 4
78struct rpc_program {
Trond Myklebust080b7942012-01-20 13:53:56 -050079 const char * name; /* protocol name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 u32 number; /* program number */
81 unsigned int nrvers; /* number of versions */
Trond Myklebusta613fa12012-01-20 13:53:56 -050082 const struct rpc_version ** version; /* version array */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 struct rpc_stat * stats; /* statistics */
Trond Myklebust080b7942012-01-20 13:53:56 -050084 const char * pipe_dir_name; /* path to rpc_pipefs dir */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
87struct rpc_version {
88 u32 number; /* version number */
89 unsigned int nrprocs; /* number of procs */
90 struct rpc_procinfo * procs; /* procedure array */
91};
92
93/*
94 * Procedure information
95 */
96struct rpc_procinfo {
97 u32 p_proc; /* RPC procedure number */
Chuck Lever9f06c712010-12-14 14:59:18 +000098 kxdreproc_t p_encode; /* XDR encode function */
Chuck Leverbf269552010-12-14 14:59:29 +000099 kxdrdproc_t p_decode; /* XDR decode function */
Chuck Lever2bea90d2007-03-29 16:47:53 -0400100 unsigned int p_arglen; /* argument hdr length (u32) */
101 unsigned int p_replen; /* reply hdr length (u32) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 unsigned int p_count; /* call count */
103 unsigned int p_timer; /* Which RTT timer to use */
Chuck Levercc0175c2006-03-20 13:44:22 -0500104 u32 p_statidx; /* Which procedure to account */
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500105 const char * p_name; /* name of procedure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106};
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#ifdef __KERNEL__
109
Chuck Leverc2866762006-08-22 20:06:20 -0400110struct rpc_create_args {
Pavel Emelyanovc653ce32010-09-29 16:04:45 +0400111 struct net *net;
Chuck Leverc2866762006-08-22 20:06:20 -0400112 int protocol;
113 struct sockaddr *address;
114 size_t addrsize;
Frank van Maarseveend3bc9a12007-07-09 22:23:35 +0200115 struct sockaddr *saddress;
Trond Myklebustba7392b2007-12-20 16:03:55 -0500116 const struct rpc_timeout *timeout;
Trond Myklebust6eac7d32012-01-20 13:53:37 -0500117 const char *servername;
Trond Myklebust03a9a422015-01-30 18:12:28 -0500118 const char *nodename;
Trond Myklebusta613fa12012-01-20 13:53:56 -0500119 const struct rpc_program *program;
Benny Halevyd5b337b2008-09-28 09:21:26 +0300120 u32 prognumber; /* overrides program->number */
Chuck Leverc2866762006-08-22 20:06:20 -0400121 u32 version;
122 rpc_authflavor_t authflavor;
123 unsigned long flags;
Olga Kornievskaia608207e2008-12-23 16:17:40 -0500124 char *client_name;
Alexandros Batsakisf300bab2009-09-10 17:33:30 +0300125 struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
Chuck Leverc2866762006-08-22 20:06:20 -0400126};
127
128/* Values for "flags" field */
129#define RPC_CLNT_CREATE_HARDRTRY (1UL << 0)
Chuck Leverc2866762006-08-22 20:06:20 -0400130#define RPC_CLNT_CREATE_AUTOBIND (1UL << 2)
Trond Myklebust90c57552007-06-09 19:49:36 -0400131#define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3)
132#define RPC_CLNT_CREATE_NOPING (1UL << 4)
133#define RPC_CLNT_CREATE_DISCRTRY (1UL << 5)
Olga Kornievskaiab6b61522008-06-09 16:51:31 -0400134#define RPC_CLNT_CREATE_QUIET (1UL << 6)
Trond Myklebustb7993ce2013-04-14 11:42:00 -0400135#define RPC_CLNT_CREATE_INFINITE_SLOTS (1UL << 7)
J. Bruce Fields33d90ac2013-04-11 15:06:36 -0400136#define RPC_CLNT_CREATE_NO_IDLE_TIMEOUT (1UL << 8)
Trond Myklebust8a19a0b2013-09-24 12:00:27 -0400137#define RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT (1UL << 9)
Chuck Leverc2866762006-08-22 20:06:20 -0400138
139struct rpc_clnt *rpc_create(struct rpc_create_args *args);
Andreas Gruenbacher007e2512005-06-22 17:16:23 +0000140struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
Trond Myklebusta613fa12012-01-20 13:53:56 -0500141 const struct rpc_program *, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
Chuck Leverba9b5842012-09-14 17:24:02 -0400143struct rpc_clnt *rpc_clone_client_set_auth(struct rpc_clnt *,
144 rpc_authflavor_t);
Trond Myklebust40b00b6b2013-10-17 14:12:23 -0400145int rpc_switch_client_transport(struct rpc_clnt *,
146 struct xprt_create *,
147 const struct rpc_timeout *);
148
Trond Myklebust4c402b42007-06-14 16:40:32 -0400149void rpc_shutdown_client(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150void rpc_release_client(struct rpc_clnt *);
Trond Myklebust58f96122010-07-31 14:29:08 -0400151void rpc_task_release_client(struct rpc_task *);
Chuck Levercce63cd2007-07-01 12:13:12 -0400152
Stanislav Kinsburskyf7a30c12012-01-13 12:52:51 +0400153int rpcb_create_local(struct net *);
154void rpcb_put_local(struct net *);
Stanislav Kinsbursky977ac312012-01-13 12:52:43 +0400155int rpcb_register(struct net *, u32, u32, int, unsigned short);
156int rpcb_v4_register(struct net *net, const u32 program,
157 const u32 version,
Chuck Leverc2e1b092008-07-14 16:03:30 -0400158 const struct sockaddr *address,
Chuck Lever14aeb212008-08-18 19:34:00 -0400159 const char *netid);
Chuck Lever45160d62007-07-01 12:13:17 -0400160void rpcb_getport_async(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Trond Myklebust77de2c52007-10-25 18:40:21 -0400162void rpc_call_start(struct rpc_task *);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500163int rpc_call_async(struct rpc_clnt *clnt,
164 const struct rpc_message *msg, int flags,
165 const struct rpc_call_ops *tk_ops,
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100166 void *calldata);
Trond Myklebustcbc20052008-02-14 11:11:30 -0500167int rpc_call_sync(struct rpc_clnt *clnt,
168 const struct rpc_message *msg, int flags);
Trond Myklebust5e1550d2007-06-23 10:17:16 -0400169struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
170 int flags);
Trond Myklebustf1f88fc2010-07-31 14:29:07 -0400171int rpc_restart_call_prepare(struct rpc_task *);
172int rpc_restart_call(struct rpc_task *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500174int rpc_protocol(struct rpc_clnt *);
175struct net * rpc_net_ns(struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176size_t rpc_max_payload(struct rpc_clnt *);
Chuck Lever6b26cc82016-05-02 14:40:40 -0400177size_t rpc_max_bc_payload(struct rpc_clnt *);
Weston Andros Adamsonedddbb12013-02-28 20:30:09 -0500178unsigned long rpc_get_timeout(struct rpc_clnt *clnt);
Chuck Lever35f5a422006-01-03 09:55:50 +0100179void rpc_force_rebind(struct rpc_clnt *);
Chuck Levered394402006-08-22 20:06:17 -0400180size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
Chuck Leverb454ae92008-01-07 18:34:48 -0500181const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
Chuck Lever2e738fd2012-03-01 17:01:14 -0500182int rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Trond Myklebust32278862016-01-30 20:39:19 -0500184int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
185 int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
186 void *data);
187
Trond Myklebust7f554892016-01-30 23:43:35 -0500188int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
189 struct rpc_xprt_switch *xps,
190 struct rpc_xprt *xprt,
191 void *dummy);
192int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
193 int (*setup)(struct rpc_clnt *,
194 struct rpc_xprt_switch *,
195 struct rpc_xprt *,
196 void *),
197 void *data);
198
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -0500199const char *rpc_proc_name(const struct rpc_task *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif /* __KERNEL__ */
201#endif /* _LINUX_SUNRPC_CLNT_H */