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