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