1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
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
13 #include <linux/types.h>
14 #include <linux/socket.h>
15 #include <linux/in.h>
16 #include <linux/in6.h>
17 #include <linux/refcount.h>
18
19 #include <linux/sunrpc/msg_prot.h>
20 #include <linux/sunrpc/sched.h>
21 #include <linux/sunrpc/xprt.h>
22 #include <linux/sunrpc/auth.h>
23 #include <linux/sunrpc/stats.h>
24 #include <linux/sunrpc/xdr.h>
25 #include <linux/sunrpc/timer.h>
26 #include <linux/sunrpc/rpc_pipe_fs.h>
27 #include <asm/signal.h>
28 #include <linux/path.h>
29 #include <net/ipv6.h>
30 #include <linux/sunrpc/xprtmultipath.h>
31
32 struct rpc_inode;
33 struct rpc_sysfs_client;
34
35 /*
36 * The high-level client handle
37 */
38 struct rpc_clnt {
39 refcount_t cl_count; /* Number of references */
40 unsigned int cl_clid; /* client id */
41 struct list_head cl_clients; /* Global list of clients */
42 struct list_head cl_tasks; /* List of tasks */
43 atomic_t cl_pid; /* task PID counter */
44 spinlock_t cl_lock; /* spinlock */
45 struct rpc_xprt __rcu * cl_xprt; /* transport */
46 const struct rpc_procinfo *cl_procinfo; /* procedure info */
47 u32 cl_prog, /* RPC program number */
48 cl_vers, /* RPC version number */
49 cl_maxproc; /* max procedure number */
50
51 struct rpc_auth * cl_auth; /* authenticator */
52 struct rpc_stat * cl_stats; /* per-program statistics */
53 struct rpc_iostats * cl_metrics; /* per-client statistics */
54
55 unsigned int cl_softrtry : 1,/* soft timeouts */
56 cl_softerr : 1,/* Timeouts return errors */
57 cl_discrtry : 1,/* disconnect before retry */
58 cl_noretranstimeo: 1,/* No retransmit timeouts */
59 cl_autobind : 1,/* use getport() */
60 cl_chatty : 1;/* be verbose */
61
62 struct rpc_rtt * cl_rtt; /* RTO estimator data */
63 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
64
65 atomic_t cl_swapper; /* swapfile count */
66 int cl_nodelen; /* nodename length */
67 char cl_nodename[UNX_MAXNODENAME+1];
68 struct rpc_pipe_dir_head cl_pipedir_objects;
69 struct rpc_clnt * cl_parent; /* Points to parent of clones */
70 struct rpc_rtt cl_rtt_default;
71 struct rpc_timeout cl_timeout_default;
72 const struct rpc_program *cl_program;
73 const char * cl_principal; /* use for machine cred */
74 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
75 struct dentry *cl_debugfs; /* debugfs directory */
76 #endif
77 struct rpc_sysfs_client *cl_sysfs; /* sysfs directory */
78 /* cl_work is only needed after cl_xpi is no longer used,
79 * and that are of similar size
80 */
81 union {
82 struct rpc_xprt_iter cl_xpi;
83 struct work_struct cl_work;
84 };
85 const struct cred *cl_cred;
86 unsigned int cl_max_connect; /* max number of transports not to the same IP */
87 };
88
89 /*
90 * General RPC program info
91 */
92 #define RPC_MAXVERSION 4
93 struct rpc_program {
94 const char * name; /* protocol name */
95 u32 number; /* program number */
96 unsigned int nrvers; /* number of versions */
97 const struct rpc_version ** version; /* version array */
98 struct rpc_stat * stats; /* statistics */
99 const char * pipe_dir_name; /* path to rpc_pipefs dir */
100 };
101
102 struct rpc_version {
103 u32 number; /* version number */
104 unsigned int nrprocs; /* number of procs */
105 const struct rpc_procinfo *procs; /* procedure array */
106 unsigned int *counts; /* call counts */
107 };
108
109 /*
110 * Procedure information
111 */
112 struct rpc_procinfo {
113 u32 p_proc; /* RPC procedure number */
114 kxdreproc_t p_encode; /* XDR encode function */
115 kxdrdproc_t p_decode; /* XDR decode function */
116 unsigned int p_arglen; /* argument hdr length (u32) */
117 unsigned int p_replen; /* reply hdr length (u32) */
118 unsigned int p_timer; /* Which RTT timer to use */
119 u32 p_statidx; /* Which procedure to account */
120 const char * p_name; /* name of procedure */
121 };
122
123 struct rpc_create_args {
124 struct net *net;
125 int protocol;
126 struct sockaddr *address;
127 size_t addrsize;
128 struct sockaddr *saddress;
129 const struct rpc_timeout *timeout;
130 const char *servername;
131 const char *nodename;
132 const struct rpc_program *program;
133 u32 prognumber; /* overrides program->number */
134 u32 version;
135 rpc_authflavor_t authflavor;
136 u32 nconnect;
137 unsigned long flags;
138 char *client_name;
139 struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
140 const struct cred *cred;
141 unsigned int max_connect;
142 };
143
144 struct rpc_add_xprt_test {
145 void (*add_xprt_test)(struct rpc_clnt *clnt,
146 struct rpc_xprt *xprt,
147 void *calldata);
148 void *data;
149 };
150
151 /* Values for "flags" field */
152 #define RPC_CLNT_CREATE_HARDRTRY (1UL << 0)
153 #define RPC_CLNT_CREATE_AUTOBIND (1UL << 2)
154 #define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3)
155 #define RPC_CLNT_CREATE_NOPING (1UL << 4)
156 #define RPC_CLNT_CREATE_DISCRTRY (1UL << 5)
157 #define RPC_CLNT_CREATE_QUIET (1UL << 6)
158 #define RPC_CLNT_CREATE_INFINITE_SLOTS (1UL << 7)
159 #define RPC_CLNT_CREATE_NO_IDLE_TIMEOUT (1UL << 8)
160 #define RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT (1UL << 9)
161 #define RPC_CLNT_CREATE_SOFTERR (1UL << 10)
162 #define RPC_CLNT_CREATE_REUSEPORT (1UL << 11)
163
164 struct rpc_clnt *rpc_create(struct rpc_create_args *args);
165 struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
166 const struct rpc_program *, u32);
167 struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
168 struct rpc_clnt *rpc_clone_client_set_auth(struct rpc_clnt *,
169 rpc_authflavor_t);
170 int rpc_switch_client_transport(struct rpc_clnt *,
171 struct xprt_create *,
172 const struct rpc_timeout *);
173
174 void rpc_shutdown_client(struct rpc_clnt *);
175 void rpc_release_client(struct rpc_clnt *);
176 void rpc_task_release_transport(struct rpc_task *);
177 void rpc_task_release_client(struct rpc_task *);
178 struct rpc_xprt *rpc_task_get_xprt(struct rpc_clnt *clnt,
179 struct rpc_xprt *xprt);
180
181 int rpcb_create_local(struct net *);
182 void rpcb_put_local(struct net *);
183 int rpcb_register(struct net *, u32, u32, int, unsigned short);
184 int rpcb_v4_register(struct net *net, const u32 program,
185 const u32 version,
186 const struct sockaddr *address,
187 const char *netid);
188 void rpcb_getport_async(struct rpc_task *);
189
190 void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
191 unsigned int base, unsigned int len,
192 unsigned int hdrsize);
193 void rpc_call_start(struct rpc_task *);
194 int rpc_call_async(struct rpc_clnt *clnt,
195 const struct rpc_message *msg, int flags,
196 const struct rpc_call_ops *tk_ops,
197 void *calldata);
198 int rpc_call_sync(struct rpc_clnt *clnt,
199 const struct rpc_message *msg, int flags);
200 struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
201 int flags);
202 int rpc_restart_call_prepare(struct rpc_task *);
203 int rpc_restart_call(struct rpc_task *);
204 void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
205 struct net * rpc_net_ns(struct rpc_clnt *);
206 size_t rpc_max_payload(struct rpc_clnt *);
207 size_t rpc_max_bc_payload(struct rpc_clnt *);
208 unsigned int rpc_num_bc_slots(struct rpc_clnt *);
209 void rpc_force_rebind(struct rpc_clnt *);
210 size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
211 const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
212 int rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
213
214 int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
215 int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
216 void *data);
217
218 int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
219 struct rpc_xprt_switch *xps,
220 struct rpc_xprt *xprt,
221 void *dummy);
222 int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
223 int (*setup)(struct rpc_clnt *,
224 struct rpc_xprt_switch *,
225 struct rpc_xprt *,
226 void *),
227 void *data);
228 void rpc_set_connect_timeout(struct rpc_clnt *clnt,
229 unsigned long connect_timeout,
230 unsigned long reconnect_timeout);
231
232 int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *,
233 struct rpc_xprt_switch *,
234 struct rpc_xprt *,
235 void *);
236
237 const char *rpc_proc_name(const struct rpc_task *task);
238
239 void rpc_clnt_xprt_switch_put(struct rpc_clnt *);
240 void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *, struct rpc_xprt *);
241 bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
242 const struct sockaddr *sap);
243 void rpc_cleanup_clids(void);
244
rpc_reply_expected(struct rpc_task * task)245 static inline int rpc_reply_expected(struct rpc_task *task)
246 {
247 return (task->tk_msg.rpc_proc != NULL) &&
248 (task->tk_msg.rpc_proc->p_decode != NULL);
249 }
250
rpc_task_close_connection(struct rpc_task * task)251 static inline void rpc_task_close_connection(struct rpc_task *task)
252 {
253 if (task->tk_xprt)
254 xprt_force_disconnect(task->tk_xprt);
255 }
256 #endif /* _LINUX_SUNRPC_CLNT_H */
257