xprt.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * linux/include/linux/sunrpc/xprt.h
  3. *
  4. * Declarations for the RPC transport interface.
  5. *
  6. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #ifndef _LINUX_SUNRPC_XPRT_H
  9. #define _LINUX_SUNRPC_XPRT_H
  10. #include <linux/uio.h>
  11. #include <linux/socket.h>
  12. #include <linux/in.h>
  13. #include <linux/ktime.h>
  14. #include <linux/sunrpc/sched.h>
  15. #include <linux/sunrpc/xdr.h>
  16. #include <linux/sunrpc/msg_prot.h>
  17. #ifdef __KERNEL__
  18. #define RPC_MIN_SLOT_TABLE (2U)
  19. #define RPC_DEF_SLOT_TABLE (16U)
  20. #define RPC_MAX_SLOT_TABLE_LIMIT (65536U)
  21. #define RPC_MAX_SLOT_TABLE RPC_MAX_SLOT_TABLE_LIMIT
  22. #define RPC_CWNDSHIFT (8U)
  23. #define RPC_CWNDSCALE (1U << RPC_CWNDSHIFT)
  24. #define RPC_INITCWND RPC_CWNDSCALE
  25. #define RPC_MAXCWND(xprt) ((xprt)->max_reqs << RPC_CWNDSHIFT)
  26. #define RPCXPRT_CONGESTED(xprt) ((xprt)->cong >= (xprt)->cwnd)
  27. /*
  28. * This describes a timeout strategy
  29. */
  30. struct rpc_timeout {
  31. unsigned long to_initval, /* initial timeout */
  32. to_maxval, /* max timeout */
  33. to_increment; /* if !exponential */
  34. unsigned int to_retries; /* max # of retries */
  35. unsigned char to_exponential;
  36. };
  37. enum rpc_display_format_t {
  38. RPC_DISPLAY_ADDR = 0,
  39. RPC_DISPLAY_PORT,
  40. RPC_DISPLAY_PROTO,
  41. RPC_DISPLAY_HEX_ADDR,
  42. RPC_DISPLAY_HEX_PORT,
  43. RPC_DISPLAY_NETID,
  44. RPC_DISPLAY_MAX,
  45. };
  46. struct rpc_task;
  47. struct rpc_xprt;
  48. struct seq_file;
  49. /*
  50. * This describes a complete RPC request
  51. */
  52. struct rpc_rqst {
  53. /*
  54. * This is the user-visible part
  55. */
  56. struct rpc_xprt * rq_xprt; /* RPC client */
  57. struct xdr_buf rq_snd_buf; /* send buffer */
  58. struct xdr_buf rq_rcv_buf; /* recv buffer */
  59. /*
  60. * This is the private part
  61. */
  62. struct rpc_task * rq_task; /* RPC task data */
  63. struct rpc_cred * rq_cred; /* Bound cred */
  64. __be32 rq_xid; /* request XID */
  65. int rq_cong; /* has incremented xprt->cong */
  66. u32 rq_seqno; /* gss seq no. used on req. */
  67. int rq_enc_pages_num;
  68. struct page **rq_enc_pages; /* scratch pages for use by
  69. gss privacy code */
  70. void (*rq_release_snd_buf)(struct rpc_rqst *); /* release rq_enc_pages */
  71. struct list_head rq_list;
  72. __u32 * rq_buffer; /* XDR encode buffer */
  73. size_t rq_callsize,
  74. rq_rcvsize;
  75. size_t rq_xmit_bytes_sent; /* total bytes sent */
  76. size_t rq_reply_bytes_recvd; /* total reply bytes */
  77. /* received */
  78. struct xdr_buf rq_private_buf; /* The receive buffer
  79. * used in the softirq.
  80. */
  81. unsigned long rq_majortimeo; /* major timeout alarm */
  82. unsigned long rq_timeout; /* Current timeout value */
  83. ktime_t rq_rtt; /* round-trip time */
  84. unsigned int rq_retries; /* # of retries */
  85. unsigned int rq_connect_cookie;
  86. /* A cookie used to track the
  87. state of the transport
  88. connection */
  89. /*
  90. * Partial send handling
  91. */
  92. u32 rq_bytes_sent; /* Bytes we have sent */
  93. ktime_t rq_xtime; /* transmit time stamp */
  94. int rq_ntrans;
  95. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  96. struct list_head rq_bc_list; /* Callback service list */
  97. unsigned long rq_bc_pa_state; /* Backchannel prealloc state */
  98. struct list_head rq_bc_pa_list; /* Backchannel prealloc list */
  99. #endif /* CONFIG_SUNRPC_BACKCHANEL */
  100. };
  101. #define rq_svec rq_snd_buf.head
  102. #define rq_slen rq_snd_buf.len
  103. struct rpc_xprt_ops {
  104. void (*set_buffer_size)(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize);
  105. int (*reserve_xprt)(struct rpc_xprt *xprt, struct rpc_task *task);
  106. void (*release_xprt)(struct rpc_xprt *xprt, struct rpc_task *task);
  107. void (*alloc_slot)(struct rpc_xprt *xprt, struct rpc_task *task);
  108. void (*rpcbind)(struct rpc_task *task);
  109. void (*set_port)(struct rpc_xprt *xprt, unsigned short port);
  110. void (*connect)(struct rpc_xprt *xprt, struct rpc_task *task);
  111. void * (*buf_alloc)(struct rpc_task *task, size_t size);
  112. void (*buf_free)(void *buffer);
  113. int (*send_request)(struct rpc_task *task);
  114. void (*set_retrans_timeout)(struct rpc_task *task);
  115. void (*timer)(struct rpc_xprt *xprt, struct rpc_task *task);
  116. void (*release_request)(struct rpc_task *task);
  117. void (*close)(struct rpc_xprt *xprt);
  118. void (*destroy)(struct rpc_xprt *xprt);
  119. void (*print_stats)(struct rpc_xprt *xprt, struct seq_file *seq);
  120. };
  121. /*
  122. * RPC transport identifiers
  123. *
  124. * To preserve compatibility with the historical use of raw IP protocol
  125. * id's for transport selection, UDP and TCP identifiers are specified
  126. * with the previous values. No such restriction exists for new transports,
  127. * except that they may not collide with these values (17 and 6,
  128. * respectively).
  129. */
  130. #define XPRT_TRANSPORT_BC (1 << 31)
  131. enum xprt_transports {
  132. XPRT_TRANSPORT_UDP = IPPROTO_UDP,
  133. XPRT_TRANSPORT_TCP = IPPROTO_TCP,
  134. XPRT_TRANSPORT_BC_TCP = IPPROTO_TCP | XPRT_TRANSPORT_BC,
  135. XPRT_TRANSPORT_RDMA = 256,
  136. XPRT_TRANSPORT_LOCAL = 257,
  137. };
  138. struct rpc_xprt {
  139. atomic_t count; /* Reference count */
  140. struct rpc_xprt_ops * ops; /* transport methods */
  141. const struct rpc_timeout *timeout; /* timeout parms */
  142. struct sockaddr_storage addr; /* server address */
  143. size_t addrlen; /* size of server address */
  144. int prot; /* IP protocol */
  145. unsigned long cong; /* current congestion */
  146. unsigned long cwnd; /* congestion window */
  147. size_t max_payload; /* largest RPC payload size,
  148. in bytes */
  149. unsigned int tsh_size; /* size of transport specific
  150. header */
  151. struct rpc_wait_queue binding; /* requests waiting on rpcbind */
  152. struct rpc_wait_queue sending; /* requests waiting to send */
  153. struct rpc_wait_queue pending; /* requests in flight */
  154. struct rpc_wait_queue backlog; /* waiting for slot */
  155. struct list_head free; /* free slots */
  156. unsigned int max_reqs; /* max number of slots */
  157. unsigned int min_reqs; /* min number of slots */
  158. atomic_t num_reqs; /* total slots */
  159. unsigned long state; /* transport state */
  160. unsigned char resvport : 1; /* use a reserved port */
  161. unsigned int swapper; /* we're swapping over this
  162. transport */
  163. unsigned int bind_index; /* bind function index */
  164. /*
  165. * Connection of transports
  166. */
  167. unsigned long bind_timeout,
  168. reestablish_timeout;
  169. unsigned int connect_cookie; /* A cookie that gets bumped
  170. every time the transport
  171. is reconnected */
  172. /*
  173. * Disconnection of idle transports
  174. */
  175. struct work_struct task_cleanup;
  176. struct timer_list timer;
  177. unsigned long last_used,
  178. idle_timeout;
  179. /*
  180. * Send stuff
  181. */
  182. spinlock_t transport_lock; /* lock transport info */
  183. spinlock_t reserve_lock; /* lock slot table */
  184. u32 xid; /* Next XID value to use */
  185. struct rpc_task * snd_task; /* Task blocked in send */
  186. struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
  187. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  188. struct svc_serv *bc_serv; /* The RPC service which will */
  189. /* process the callback */
  190. unsigned int bc_alloc_count; /* Total number of preallocs */
  191. spinlock_t bc_pa_lock; /* Protects the preallocated
  192. * items */
  193. struct list_head bc_pa_list; /* List of preallocated
  194. * backchannel rpc_rqst's */
  195. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  196. struct list_head recv;
  197. struct {
  198. unsigned long bind_count, /* total number of binds */
  199. connect_count, /* total number of connects */
  200. connect_start, /* connect start timestamp */
  201. connect_time, /* jiffies waiting for connect */
  202. sends, /* how many complete requests */
  203. recvs, /* how many complete requests */
  204. bad_xids, /* lookup_rqst didn't find XID */
  205. max_slots; /* max rpc_slots used */
  206. unsigned long long req_u, /* average requests on the wire */
  207. bklog_u, /* backlog queue utilization */
  208. sending_u, /* send q utilization */
  209. pending_u; /* pend q utilization */
  210. } stat;
  211. struct net *xprt_net;
  212. const char *servername;
  213. const char *address_strings[RPC_DISPLAY_MAX];
  214. };
  215. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  216. /*
  217. * Backchannel flags
  218. */
  219. #define RPC_BC_PA_IN_USE 0x0001 /* Preallocated backchannel */
  220. /* buffer in use */
  221. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  222. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  223. static inline int bc_prealloc(struct rpc_rqst *req)
  224. {
  225. return test_bit(RPC_BC_PA_IN_USE, &req->rq_bc_pa_state);
  226. }
  227. #else
  228. static inline int bc_prealloc(struct rpc_rqst *req)
  229. {
  230. return 0;
  231. }
  232. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  233. #define XPRT_CREATE_INFINITE_SLOTS (1U)
  234. #define XPRT_CREATE_NO_IDLE_TIMEOUT (1U << 1)
  235. struct xprt_create {
  236. int ident; /* XPRT_TRANSPORT identifier */
  237. struct net * net;
  238. struct sockaddr * srcaddr; /* optional local address */
  239. struct sockaddr * dstaddr; /* remote peer address */
  240. size_t addrlen;
  241. const char *servername;
  242. struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */
  243. unsigned int flags;
  244. };
  245. struct xprt_class {
  246. struct list_head list;
  247. int ident; /* XPRT_TRANSPORT identifier */
  248. struct rpc_xprt * (*setup)(struct xprt_create *);
  249. struct module *owner;
  250. char name[32];
  251. };
  252. /*
  253. * Generic internal transport functions
  254. */
  255. struct rpc_xprt *xprt_create_transport(struct xprt_create *args);
  256. void xprt_connect(struct rpc_task *task);
  257. void xprt_reserve(struct rpc_task *task);
  258. void xprt_retry_reserve(struct rpc_task *task);
  259. int xprt_reserve_xprt(struct rpc_xprt *xprt, struct rpc_task *task);
  260. int xprt_reserve_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task);
  261. void xprt_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task);
  262. void xprt_lock_and_alloc_slot(struct rpc_xprt *xprt, struct rpc_task *task);
  263. bool xprt_prepare_transmit(struct rpc_task *task);
  264. void xprt_transmit(struct rpc_task *task);
  265. void xprt_end_transmit(struct rpc_task *task);
  266. int xprt_adjust_timeout(struct rpc_rqst *req);
  267. void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task);
  268. void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task);
  269. void xprt_release(struct rpc_task *task);
  270. void xprt_put(struct rpc_xprt *xprt);
  271. struct rpc_xprt * xprt_alloc(struct net *net, size_t size,
  272. unsigned int num_prealloc,
  273. unsigned int max_req);
  274. void xprt_free(struct rpc_xprt *);
  275. /**
  276. * xprt_get - return a reference to an RPC transport.
  277. * @xprt: pointer to the transport
  278. *
  279. */
  280. static inline struct rpc_xprt *xprt_get(struct rpc_xprt *xprt)
  281. {
  282. if (atomic_inc_not_zero(&xprt->count))
  283. return xprt;
  284. return NULL;
  285. }
  286. static inline __be32 *xprt_skip_transport_header(struct rpc_xprt *xprt, __be32 *p)
  287. {
  288. return p + xprt->tsh_size;
  289. }
  290. /*
  291. * Transport switch helper functions
  292. */
  293. int xprt_register_transport(struct xprt_class *type);
  294. int xprt_unregister_transport(struct xprt_class *type);
  295. int xprt_load_transport(const char *);
  296. void xprt_set_retrans_timeout_def(struct rpc_task *task);
  297. void xprt_set_retrans_timeout_rtt(struct rpc_task *task);
  298. void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status);
  299. void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action);
  300. void xprt_write_space(struct rpc_xprt *xprt);
  301. void xprt_adjust_cwnd(struct rpc_xprt *xprt, struct rpc_task *task, int result);
  302. struct rpc_rqst * xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid);
  303. void xprt_complete_rqst(struct rpc_task *task, int copied);
  304. void xprt_release_rqst_cong(struct rpc_task *task);
  305. void xprt_disconnect_done(struct rpc_xprt *xprt);
  306. void xprt_force_disconnect(struct rpc_xprt *xprt);
  307. void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie);
  308. int xs_swapper(struct rpc_xprt *xprt, int enable);
  309. /*
  310. * Reserved bit positions in xprt->state
  311. */
  312. #define XPRT_LOCKED (0)
  313. #define XPRT_CONNECTED (1)
  314. #define XPRT_CONNECTING (2)
  315. #define XPRT_CLOSE_WAIT (3)
  316. #define XPRT_BOUND (4)
  317. #define XPRT_BINDING (5)
  318. #define XPRT_CLOSING (6)
  319. #define XPRT_CONNECTION_ABORT (7)
  320. #define XPRT_CONNECTION_CLOSE (8)
  321. #define XPRT_CONGESTED (9)
  322. #define XPRT_CONNECTION_REUSE (10)
  323. static inline void xprt_set_connected(struct rpc_xprt *xprt)
  324. {
  325. set_bit(XPRT_CONNECTED, &xprt->state);
  326. }
  327. static inline void xprt_clear_connected(struct rpc_xprt *xprt)
  328. {
  329. clear_bit(XPRT_CONNECTED, &xprt->state);
  330. }
  331. static inline int xprt_connected(struct rpc_xprt *xprt)
  332. {
  333. return test_bit(XPRT_CONNECTED, &xprt->state);
  334. }
  335. static inline int xprt_test_and_set_connected(struct rpc_xprt *xprt)
  336. {
  337. return test_and_set_bit(XPRT_CONNECTED, &xprt->state);
  338. }
  339. static inline int xprt_test_and_clear_connected(struct rpc_xprt *xprt)
  340. {
  341. return test_and_clear_bit(XPRT_CONNECTED, &xprt->state);
  342. }
  343. static inline void xprt_clear_connecting(struct rpc_xprt *xprt)
  344. {
  345. smp_mb__before_atomic();
  346. clear_bit(XPRT_CONNECTING, &xprt->state);
  347. smp_mb__after_atomic();
  348. }
  349. static inline int xprt_connecting(struct rpc_xprt *xprt)
  350. {
  351. return test_bit(XPRT_CONNECTING, &xprt->state);
  352. }
  353. static inline int xprt_test_and_set_connecting(struct rpc_xprt *xprt)
  354. {
  355. return test_and_set_bit(XPRT_CONNECTING, &xprt->state);
  356. }
  357. static inline void xprt_set_bound(struct rpc_xprt *xprt)
  358. {
  359. test_and_set_bit(XPRT_BOUND, &xprt->state);
  360. }
  361. static inline int xprt_bound(struct rpc_xprt *xprt)
  362. {
  363. return test_bit(XPRT_BOUND, &xprt->state);
  364. }
  365. static inline void xprt_clear_bound(struct rpc_xprt *xprt)
  366. {
  367. clear_bit(XPRT_BOUND, &xprt->state);
  368. }
  369. static inline void xprt_clear_binding(struct rpc_xprt *xprt)
  370. {
  371. smp_mb__before_atomic();
  372. clear_bit(XPRT_BINDING, &xprt->state);
  373. smp_mb__after_atomic();
  374. }
  375. static inline int xprt_test_and_set_binding(struct rpc_xprt *xprt)
  376. {
  377. return test_and_set_bit(XPRT_BINDING, &xprt->state);
  378. }
  379. #endif /* __KERNEL__*/
  380. #endif /* _LINUX_SUNRPC_XPRT_H */