xprt.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * linux/include/linux/sunrpc/clnt_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/sunrpc/sched.h>
  14. #include <linux/sunrpc/xdr.h>
  15. /*
  16. * The transport code maintains an estimate on the maximum number of out-
  17. * standing RPC requests, using a smoothed version of the congestion
  18. * avoidance implemented in 44BSD. This is basically the Van Jacobson
  19. * congestion algorithm: If a retransmit occurs, the congestion window is
  20. * halved; otherwise, it is incremented by 1/cwnd when
  21. *
  22. * - a reply is received and
  23. * - a full number of requests are outstanding and
  24. * - the congestion window hasn't been updated recently.
  25. *
  26. * Upper procedures may check whether a request would block waiting for
  27. * a free RPC slot by using the RPC_CONGESTED() macro.
  28. */
  29. extern unsigned int xprt_udp_slot_table_entries;
  30. extern unsigned int xprt_tcp_slot_table_entries;
  31. #define RPC_MIN_SLOT_TABLE (2U)
  32. #define RPC_DEF_SLOT_TABLE (16U)
  33. #define RPC_MAX_SLOT_TABLE (128U)
  34. #define RPC_CWNDSHIFT (8U)
  35. #define RPC_CWNDSCALE (1U << RPC_CWNDSHIFT)
  36. #define RPC_INITCWND RPC_CWNDSCALE
  37. #define RPC_MAXCWND(xprt) ((xprt)->max_reqs << RPC_CWNDSHIFT)
  38. #define RPCXPRT_CONGESTED(xprt) ((xprt)->cong >= (xprt)->cwnd)
  39. /* Default timeout values */
  40. #define RPC_MAX_UDP_TIMEOUT (60*HZ)
  41. #define RPC_MAX_TCP_TIMEOUT (600*HZ)
  42. /*
  43. * Wait duration for an RPC TCP connection to be established. Solaris
  44. * NFS over TCP uses 60 seconds, for example, which is in line with how
  45. * long a server takes to reboot.
  46. */
  47. #define RPC_CONNECT_TIMEOUT (60*HZ)
  48. /*
  49. * Delay an arbitrary number of seconds before attempting to reconnect
  50. * after an error.
  51. */
  52. #define RPC_REESTABLISH_TIMEOUT (15*HZ)
  53. /*
  54. * RPC transport idle timeout.
  55. */
  56. #define RPC_IDLE_DISCONNECT_TIMEOUT (5*60*HZ)
  57. /*
  58. * RPC call and reply header size as number of 32bit words (verifier
  59. * size computed separately)
  60. */
  61. #define RPC_CALLHDRSIZE 6
  62. #define RPC_REPHDRSIZE 4
  63. /*
  64. * This describes a timeout strategy
  65. */
  66. struct rpc_timeout {
  67. unsigned long to_initval, /* initial timeout */
  68. to_maxval, /* max timeout */
  69. to_increment; /* if !exponential */
  70. unsigned int to_retries; /* max # of retries */
  71. unsigned char to_exponential;
  72. };
  73. /*
  74. * This describes a complete RPC request
  75. */
  76. struct rpc_rqst {
  77. /*
  78. * This is the user-visible part
  79. */
  80. struct rpc_xprt * rq_xprt; /* RPC client */
  81. struct xdr_buf rq_snd_buf; /* send buffer */
  82. struct xdr_buf rq_rcv_buf; /* recv buffer */
  83. /*
  84. * This is the private part
  85. */
  86. struct rpc_task * rq_task; /* RPC task data */
  87. __u32 rq_xid; /* request XID */
  88. int rq_cong; /* has incremented xprt->cong */
  89. int rq_received; /* receive completed */
  90. u32 rq_seqno; /* gss seq no. used on req. */
  91. struct list_head rq_list;
  92. struct xdr_buf rq_private_buf; /* The receive buffer
  93. * used in the softirq.
  94. */
  95. unsigned long rq_majortimeo; /* major timeout alarm */
  96. unsigned long rq_timeout; /* Current timeout value */
  97. unsigned int rq_retries; /* # of retries */
  98. /*
  99. * For authentication (e.g. auth_des)
  100. */
  101. u32 rq_creddata[2];
  102. /*
  103. * Partial send handling
  104. */
  105. u32 rq_bytes_sent; /* Bytes we have sent */
  106. unsigned long rq_xtime; /* when transmitted */
  107. int rq_ntrans;
  108. };
  109. #define rq_svec rq_snd_buf.head
  110. #define rq_slen rq_snd_buf.len
  111. struct rpc_task;
  112. struct rpc_xprt;
  113. struct rpc_xprt_ops {
  114. void (*set_buffer_size)(struct rpc_xprt *xprt);
  115. void (*connect)(struct rpc_task *task);
  116. int (*send_request)(struct rpc_task *task);
  117. void (*close)(struct rpc_xprt *xprt);
  118. void (*destroy)(struct rpc_xprt *xprt);
  119. };
  120. struct rpc_xprt {
  121. struct rpc_xprt_ops * ops; /* transport methods */
  122. struct socket * sock; /* BSD socket layer */
  123. struct sock * inet; /* INET layer */
  124. struct rpc_timeout timeout; /* timeout parms */
  125. struct sockaddr_in addr; /* server address */
  126. int prot; /* IP protocol */
  127. unsigned long cong; /* current congestion */
  128. unsigned long cwnd; /* congestion window */
  129. unsigned int rcvsize, /* socket receive buffer size */
  130. sndsize; /* socket send buffer size */
  131. size_t max_payload; /* largest RPC payload size,
  132. in bytes */
  133. struct rpc_wait_queue sending; /* requests waiting to send */
  134. struct rpc_wait_queue resend; /* requests waiting to resend */
  135. struct rpc_wait_queue pending; /* requests in flight */
  136. struct rpc_wait_queue backlog; /* waiting for slot */
  137. struct list_head free; /* free slots */
  138. struct rpc_rqst * slot; /* slot table storage */
  139. unsigned int max_reqs; /* total slots */
  140. unsigned long sockstate; /* Socket state */
  141. unsigned char shutdown : 1, /* being shut down */
  142. nocong : 1, /* no congestion control */
  143. resvport : 1, /* use a reserved port */
  144. stream : 1; /* TCP */
  145. /*
  146. * XID
  147. */
  148. __u32 xid; /* Next XID value to use */
  149. /*
  150. * State of TCP reply receive stuff
  151. */
  152. u32 tcp_recm, /* Fragment header */
  153. tcp_xid, /* Current XID */
  154. tcp_reclen, /* fragment length */
  155. tcp_offset; /* fragment offset */
  156. unsigned long tcp_copied, /* copied to request */
  157. tcp_flags;
  158. /*
  159. * Connection of sockets
  160. */
  161. struct work_struct sock_connect;
  162. unsigned short port;
  163. /*
  164. * Disconnection of idle sockets
  165. */
  166. struct work_struct task_cleanup;
  167. struct timer_list timer;
  168. unsigned long last_used;
  169. /*
  170. * Send stuff
  171. */
  172. spinlock_t transport_lock; /* lock transport info */
  173. spinlock_t reserve_lock; /* lock slot table */
  174. struct rpc_task * snd_task; /* Task blocked in send */
  175. struct list_head recv;
  176. void (*old_data_ready)(struct sock *, int);
  177. void (*old_state_change)(struct sock *);
  178. void (*old_write_space)(struct sock *);
  179. wait_queue_head_t cong_wait;
  180. };
  181. #define XPRT_LAST_FRAG (1 << 0)
  182. #define XPRT_COPY_RECM (1 << 1)
  183. #define XPRT_COPY_XID (1 << 2)
  184. #define XPRT_COPY_DATA (1 << 3)
  185. #ifdef __KERNEL__
  186. struct rpc_xprt * xprt_create_proto(int proto, struct sockaddr_in *addr,
  187. struct rpc_timeout *toparms);
  188. void xprt_disconnect(struct rpc_xprt *);
  189. int xprt_destroy(struct rpc_xprt *);
  190. void xprt_set_timeout(struct rpc_timeout *, unsigned int,
  191. unsigned long);
  192. struct rpc_rqst * xprt_lookup_rqst(struct rpc_xprt *, u32);
  193. void xprt_complete_rqst(struct rpc_xprt *,
  194. struct rpc_rqst *, int);
  195. void xprt_reserve(struct rpc_task *);
  196. int xprt_prepare_transmit(struct rpc_task *);
  197. void xprt_transmit(struct rpc_task *);
  198. void xprt_receive(struct rpc_task *);
  199. int xprt_adjust_timeout(struct rpc_rqst *req);
  200. void xprt_release(struct rpc_task *);
  201. void xprt_connect(struct rpc_task *);
  202. int xs_setup_udp(struct rpc_xprt *,
  203. struct rpc_timeout *);
  204. int xs_setup_tcp(struct rpc_xprt *,
  205. struct rpc_timeout *);
  206. #define XPRT_LOCKED 0
  207. #define XPRT_CONNECT 1
  208. #define XPRT_CONNECTING 2
  209. #define xprt_connected(xp) (test_bit(XPRT_CONNECT, &(xp)->sockstate))
  210. #define xprt_set_connected(xp) (set_bit(XPRT_CONNECT, &(xp)->sockstate))
  211. #define xprt_test_and_set_connected(xp) (test_and_set_bit(XPRT_CONNECT, &(xp)->sockstate))
  212. #define xprt_test_and_clear_connected(xp) \
  213. (test_and_clear_bit(XPRT_CONNECT, &(xp)->sockstate))
  214. #define xprt_clear_connected(xp) (clear_bit(XPRT_CONNECT, &(xp)->sockstate))
  215. #endif /* __KERNEL__*/
  216. #endif /* _LINUX_SUNRPC_XPRT_H */