xprt.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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/kref.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 (128U)
  21. /*
  22. * This describes a timeout strategy
  23. */
  24. struct rpc_timeout {
  25. unsigned long to_initval, /* initial timeout */
  26. to_maxval, /* max timeout */
  27. to_increment; /* if !exponential */
  28. unsigned int to_retries; /* max # of retries */
  29. unsigned char to_exponential;
  30. };
  31. enum rpc_display_format_t {
  32. RPC_DISPLAY_ADDR = 0,
  33. RPC_DISPLAY_PORT,
  34. RPC_DISPLAY_PROTO,
  35. RPC_DISPLAY_ALL,
  36. RPC_DISPLAY_HEX_ADDR,
  37. RPC_DISPLAY_HEX_PORT,
  38. RPC_DISPLAY_UNIVERSAL_ADDR,
  39. RPC_DISPLAY_NETID,
  40. RPC_DISPLAY_MAX,
  41. };
  42. struct rpc_task;
  43. struct rpc_xprt;
  44. struct seq_file;
  45. /*
  46. * This describes a complete RPC request
  47. */
  48. struct rpc_rqst {
  49. /*
  50. * This is the user-visible part
  51. */
  52. struct rpc_xprt * rq_xprt; /* RPC client */
  53. struct xdr_buf rq_snd_buf; /* send buffer */
  54. struct xdr_buf rq_rcv_buf; /* recv buffer */
  55. /*
  56. * This is the private part
  57. */
  58. struct rpc_task * rq_task; /* RPC task data */
  59. __be32 rq_xid; /* request XID */
  60. int rq_cong; /* has incremented xprt->cong */
  61. int rq_received; /* receive completed */
  62. u32 rq_seqno; /* gss seq no. used on req. */
  63. int rq_enc_pages_num;
  64. struct page **rq_enc_pages; /* scratch pages for use by
  65. gss privacy code */
  66. void (*rq_release_snd_buf)(struct rpc_rqst *); /* release rq_enc_pages */
  67. struct list_head rq_list;
  68. __u32 * rq_buffer; /* XDR encode buffer */
  69. size_t rq_callsize,
  70. rq_rcvsize;
  71. struct xdr_buf rq_private_buf; /* The receive buffer
  72. * used in the softirq.
  73. */
  74. unsigned long rq_majortimeo; /* major timeout alarm */
  75. unsigned long rq_timeout; /* Current timeout value */
  76. unsigned int rq_retries; /* # of retries */
  77. unsigned int rq_connect_cookie;
  78. /* A cookie used to track the
  79. state of the transport
  80. connection */
  81. /*
  82. * Partial send handling
  83. */
  84. u32 rq_bytes_sent; /* Bytes we have sent */
  85. unsigned long rq_xtime; /* when transmitted */
  86. int rq_ntrans;
  87. #if defined(CONFIG_NFS_V4_1)
  88. struct list_head rq_bc_list; /* Callback service list */
  89. unsigned long rq_bc_pa_state; /* Backchannel prealloc state */
  90. struct list_head rq_bc_pa_list; /* Backchannel prealloc list */
  91. #endif /* CONFIG_NFS_V4_1 */
  92. };
  93. #define rq_svec rq_snd_buf.head
  94. #define rq_slen rq_snd_buf.len
  95. struct rpc_xprt_ops {
  96. void (*set_buffer_size)(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize);
  97. int (*reserve_xprt)(struct rpc_task *task);
  98. void (*release_xprt)(struct rpc_xprt *xprt, struct rpc_task *task);
  99. void (*rpcbind)(struct rpc_task *task);
  100. void (*set_port)(struct rpc_xprt *xprt, unsigned short port);
  101. void (*connect)(struct rpc_task *task);
  102. void * (*buf_alloc)(struct rpc_task *task, size_t size);
  103. void (*buf_free)(void *buffer);
  104. int (*send_request)(struct rpc_task *task);
  105. void (*set_retrans_timeout)(struct rpc_task *task);
  106. void (*timer)(struct rpc_task *task);
  107. void (*release_request)(struct rpc_task *task);
  108. void (*close)(struct rpc_xprt *xprt);
  109. void (*destroy)(struct rpc_xprt *xprt);
  110. void (*print_stats)(struct rpc_xprt *xprt, struct seq_file *seq);
  111. };
  112. struct rpc_xprt {
  113. struct kref kref; /* Reference count */
  114. struct rpc_xprt_ops * ops; /* transport methods */
  115. const struct rpc_timeout *timeout; /* timeout parms */
  116. struct sockaddr_storage addr; /* server address */
  117. size_t addrlen; /* size of server address */
  118. int prot; /* IP protocol */
  119. unsigned long cong; /* current congestion */
  120. unsigned long cwnd; /* congestion window */
  121. size_t max_payload; /* largest RPC payload size,
  122. in bytes */
  123. unsigned int tsh_size; /* size of transport specific
  124. header */
  125. struct rpc_wait_queue binding; /* requests waiting on rpcbind */
  126. struct rpc_wait_queue sending; /* requests waiting to send */
  127. struct rpc_wait_queue resend; /* requests waiting to resend */
  128. struct rpc_wait_queue pending; /* requests in flight */
  129. struct rpc_wait_queue backlog; /* waiting for slot */
  130. struct list_head free; /* free slots */
  131. struct rpc_rqst * slot; /* slot table storage */
  132. unsigned int max_reqs; /* total slots */
  133. unsigned long state; /* transport state */
  134. unsigned char shutdown : 1, /* being shut down */
  135. resvport : 1; /* use a reserved port */
  136. unsigned int bind_index; /* bind function index */
  137. /*
  138. * Connection of transports
  139. */
  140. unsigned long connect_timeout,
  141. bind_timeout,
  142. reestablish_timeout;
  143. unsigned int connect_cookie; /* A cookie that gets bumped
  144. every time the transport
  145. is reconnected */
  146. /*
  147. * Disconnection of idle transports
  148. */
  149. struct work_struct task_cleanup;
  150. struct timer_list timer;
  151. unsigned long last_used,
  152. idle_timeout;
  153. /*
  154. * Send stuff
  155. */
  156. spinlock_t transport_lock; /* lock transport info */
  157. spinlock_t reserve_lock; /* lock slot table */
  158. u32 xid; /* Next XID value to use */
  159. struct rpc_task * snd_task; /* Task blocked in send */
  160. #if defined(CONFIG_NFS_V4_1)
  161. struct svc_serv *bc_serv; /* The RPC service which will */
  162. /* process the callback */
  163. spinlock_t bc_pa_lock; /* Protects the preallocated
  164. * items */
  165. struct list_head bc_pa_list; /* List of preallocated
  166. * backchannel rpc_rqst's */
  167. #endif /* CONFIG_NFS_V4_1 */
  168. struct list_head recv;
  169. struct {
  170. unsigned long bind_count, /* total number of binds */
  171. connect_count, /* total number of connects */
  172. connect_start, /* connect start timestamp */
  173. connect_time, /* jiffies waiting for connect */
  174. sends, /* how many complete requests */
  175. recvs, /* how many complete requests */
  176. bad_xids; /* lookup_rqst didn't find XID */
  177. unsigned long long req_u, /* average requests on the wire */
  178. bklog_u; /* backlog queue utilization */
  179. } stat;
  180. const char *address_strings[RPC_DISPLAY_MAX];
  181. };
  182. #if defined(CONFIG_NFS_V4_1)
  183. /*
  184. * Backchannel flags
  185. */
  186. #define RPC_BC_PA_IN_USE 0x0001 /* Preallocated backchannel */
  187. /* buffer in use */
  188. #endif /* CONFIG_NFS_V4_1 */
  189. struct xprt_create {
  190. int ident; /* XPRT_TRANSPORT identifier */
  191. struct sockaddr * srcaddr; /* optional local address */
  192. struct sockaddr * dstaddr; /* remote peer address */
  193. size_t addrlen;
  194. };
  195. struct xprt_class {
  196. struct list_head list;
  197. int ident; /* XPRT_TRANSPORT identifier */
  198. struct rpc_xprt * (*setup)(struct xprt_create *);
  199. struct module *owner;
  200. char name[32];
  201. };
  202. /*
  203. * Generic internal transport functions
  204. */
  205. struct rpc_xprt *xprt_create_transport(struct xprt_create *args);
  206. void xprt_connect(struct rpc_task *task);
  207. void xprt_reserve(struct rpc_task *task);
  208. int xprt_reserve_xprt(struct rpc_task *task);
  209. int xprt_reserve_xprt_cong(struct rpc_task *task);
  210. int xprt_prepare_transmit(struct rpc_task *task);
  211. void xprt_transmit(struct rpc_task *task);
  212. void xprt_end_transmit(struct rpc_task *task);
  213. int xprt_adjust_timeout(struct rpc_rqst *req);
  214. void xprt_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task);
  215. void xprt_release_xprt_cong(struct rpc_xprt *xprt, struct rpc_task *task);
  216. void xprt_release(struct rpc_task *task);
  217. struct rpc_xprt * xprt_get(struct rpc_xprt *xprt);
  218. void xprt_put(struct rpc_xprt *xprt);
  219. static inline __be32 *xprt_skip_transport_header(struct rpc_xprt *xprt, __be32 *p)
  220. {
  221. return p + xprt->tsh_size;
  222. }
  223. /*
  224. * Transport switch helper functions
  225. */
  226. int xprt_register_transport(struct xprt_class *type);
  227. int xprt_unregister_transport(struct xprt_class *type);
  228. int xprt_load_transport(const char *);
  229. void xprt_set_retrans_timeout_def(struct rpc_task *task);
  230. void xprt_set_retrans_timeout_rtt(struct rpc_task *task);
  231. void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status);
  232. void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action);
  233. void xprt_write_space(struct rpc_xprt *xprt);
  234. void xprt_update_rtt(struct rpc_task *task);
  235. void xprt_adjust_cwnd(struct rpc_task *task, int result);
  236. struct rpc_rqst * xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid);
  237. void xprt_complete_rqst(struct rpc_task *task, int copied);
  238. void xprt_release_rqst_cong(struct rpc_task *task);
  239. void xprt_disconnect_done(struct rpc_xprt *xprt);
  240. void xprt_force_disconnect(struct rpc_xprt *xprt);
  241. void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie);
  242. /*
  243. * Reserved bit positions in xprt->state
  244. */
  245. #define XPRT_LOCKED (0)
  246. #define XPRT_CONNECTED (1)
  247. #define XPRT_CONNECTING (2)
  248. #define XPRT_CLOSE_WAIT (3)
  249. #define XPRT_BOUND (4)
  250. #define XPRT_BINDING (5)
  251. #define XPRT_CLOSING (6)
  252. #define XPRT_CONNECTION_ABORT (7)
  253. #define XPRT_CONNECTION_CLOSE (8)
  254. static inline void xprt_set_connected(struct rpc_xprt *xprt)
  255. {
  256. set_bit(XPRT_CONNECTED, &xprt->state);
  257. }
  258. static inline void xprt_clear_connected(struct rpc_xprt *xprt)
  259. {
  260. clear_bit(XPRT_CONNECTED, &xprt->state);
  261. }
  262. static inline int xprt_connected(struct rpc_xprt *xprt)
  263. {
  264. return test_bit(XPRT_CONNECTED, &xprt->state);
  265. }
  266. static inline int xprt_test_and_set_connected(struct rpc_xprt *xprt)
  267. {
  268. return test_and_set_bit(XPRT_CONNECTED, &xprt->state);
  269. }
  270. static inline int xprt_test_and_clear_connected(struct rpc_xprt *xprt)
  271. {
  272. return test_and_clear_bit(XPRT_CONNECTED, &xprt->state);
  273. }
  274. static inline void xprt_clear_connecting(struct rpc_xprt *xprt)
  275. {
  276. smp_mb__before_clear_bit();
  277. clear_bit(XPRT_CONNECTING, &xprt->state);
  278. smp_mb__after_clear_bit();
  279. }
  280. static inline int xprt_connecting(struct rpc_xprt *xprt)
  281. {
  282. return test_bit(XPRT_CONNECTING, &xprt->state);
  283. }
  284. static inline int xprt_test_and_set_connecting(struct rpc_xprt *xprt)
  285. {
  286. return test_and_set_bit(XPRT_CONNECTING, &xprt->state);
  287. }
  288. static inline void xprt_set_bound(struct rpc_xprt *xprt)
  289. {
  290. test_and_set_bit(XPRT_BOUND, &xprt->state);
  291. }
  292. static inline int xprt_bound(struct rpc_xprt *xprt)
  293. {
  294. return test_bit(XPRT_BOUND, &xprt->state);
  295. }
  296. static inline void xprt_clear_bound(struct rpc_xprt *xprt)
  297. {
  298. clear_bit(XPRT_BOUND, &xprt->state);
  299. }
  300. static inline void xprt_clear_binding(struct rpc_xprt *xprt)
  301. {
  302. smp_mb__before_clear_bit();
  303. clear_bit(XPRT_BINDING, &xprt->state);
  304. smp_mb__after_clear_bit();
  305. }
  306. static inline int xprt_test_and_set_binding(struct rpc_xprt *xprt)
  307. {
  308. return test_and_set_bit(XPRT_BINDING, &xprt->state);
  309. }
  310. #endif /* __KERNEL__*/
  311. #endif /* _LINUX_SUNRPC_XPRT_H */