/include/linux/ceph/messenger.h

https://github.com/airy09/android_kernel_sony_apq8064 · C Header · 255 lines · 172 code · 45 blank · 38 comment · 0 complexity · 924418a1c24dc03e3f33ce6ac459a755 MD5 · raw file

  1. #ifndef __FS_CEPH_MESSENGER_H
  2. #define __FS_CEPH_MESSENGER_H
  3. #include <linux/kref.h>
  4. #include <linux/mutex.h>
  5. #include <linux/net.h>
  6. #include <linux/radix-tree.h>
  7. #include <linux/uio.h>
  8. #include <linux/workqueue.h>
  9. #include "types.h"
  10. #include "buffer.h"
  11. struct ceph_msg;
  12. struct ceph_connection;
  13. /*
  14. * Ceph defines these callbacks for handling connection events.
  15. */
  16. struct ceph_connection_operations {
  17. struct ceph_connection *(*get)(struct ceph_connection *);
  18. void (*put)(struct ceph_connection *);
  19. /* handle an incoming message. */
  20. void (*dispatch) (struct ceph_connection *con, struct ceph_msg *m);
  21. /* authorize an outgoing connection */
  22. int (*get_authorizer) (struct ceph_connection *con,
  23. void **buf, int *len, int *proto,
  24. void **reply_buf, int *reply_len, int force_new);
  25. int (*verify_authorizer_reply) (struct ceph_connection *con, int len);
  26. int (*invalidate_authorizer)(struct ceph_connection *con);
  27. /* protocol version mismatch */
  28. void (*bad_proto) (struct ceph_connection *con);
  29. /* there was some error on the socket (disconnect, whatever) */
  30. void (*fault) (struct ceph_connection *con);
  31. /* a remote host as terminated a message exchange session, and messages
  32. * we sent (or they tried to send us) may be lost. */
  33. void (*peer_reset) (struct ceph_connection *con);
  34. struct ceph_msg * (*alloc_msg) (struct ceph_connection *con,
  35. struct ceph_msg_header *hdr,
  36. int *skip);
  37. };
  38. /* use format string %s%d */
  39. #define ENTITY_NAME(n) ceph_entity_type_name((n).type), le64_to_cpu((n).num)
  40. struct ceph_messenger {
  41. struct ceph_entity_inst inst; /* my name+address */
  42. struct ceph_entity_addr my_enc_addr;
  43. bool nocrc;
  44. /*
  45. * the global_seq counts connections i (attempt to) initiate
  46. * in order to disambiguate certain connect race conditions.
  47. */
  48. u32 global_seq;
  49. spinlock_t global_seq_lock;
  50. u32 supported_features;
  51. u32 required_features;
  52. };
  53. /*
  54. * a single message. it contains a header (src, dest, message type, etc.),
  55. * footer (crc values, mainly), a "front" message body, and possibly a
  56. * data payload (stored in some number of pages).
  57. */
  58. struct ceph_msg {
  59. struct ceph_msg_header hdr; /* header */
  60. struct ceph_msg_footer footer; /* footer */
  61. struct kvec front; /* unaligned blobs of message */
  62. struct ceph_buffer *middle;
  63. struct page **pages; /* data payload. NOT OWNER. */
  64. unsigned nr_pages; /* size of page array */
  65. unsigned page_alignment; /* io offset in first page */
  66. struct ceph_pagelist *pagelist; /* instead of pages */
  67. struct list_head list_head;
  68. struct kref kref;
  69. struct bio *bio; /* instead of pages/pagelist */
  70. struct bio *bio_iter; /* bio iterator */
  71. int bio_seg; /* current bio segment */
  72. struct ceph_pagelist *trail; /* the trailing part of the data */
  73. bool front_is_vmalloc;
  74. bool more_to_follow;
  75. bool needs_out_seq;
  76. int front_max;
  77. unsigned long ack_stamp; /* tx: when we were acked */
  78. struct ceph_msgpool *pool;
  79. };
  80. struct ceph_msg_pos {
  81. int page, page_pos; /* which page; offset in page */
  82. int data_pos; /* offset in data payload */
  83. bool did_page_crc; /* true if we've calculated crc for current page */
  84. };
  85. /* ceph connection fault delay defaults, for exponential backoff */
  86. #define BASE_DELAY_INTERVAL (HZ/2)
  87. #define MAX_DELAY_INTERVAL (5 * 60 * HZ)
  88. /*
  89. * ceph_connection state bit flags
  90. */
  91. #define LOSSYTX 0 /* we can close channel or drop messages on errors */
  92. #define CONNECTING 1
  93. #define NEGOTIATING 2
  94. #define KEEPALIVE_PENDING 3
  95. #define WRITE_PENDING 4 /* we have data ready to send */
  96. #define STANDBY 8 /* no outgoing messages, socket closed. we keep
  97. * the ceph_connection around to maintain shared
  98. * state with the peer. */
  99. #define CLOSED 10 /* we've closed the connection */
  100. #define SOCK_CLOSED 11 /* socket state changed to closed */
  101. #define OPENING 13 /* open connection w/ (possibly new) peer */
  102. #define DEAD 14 /* dead, about to kfree */
  103. #define BACKOFF 15
  104. /*
  105. * A single connection with another host.
  106. *
  107. * We maintain a queue of outgoing messages, and some session state to
  108. * ensure that we can preserve the lossless, ordered delivery of
  109. * messages in the case of a TCP disconnect.
  110. */
  111. struct ceph_connection {
  112. void *private;
  113. atomic_t nref;
  114. const struct ceph_connection_operations *ops;
  115. struct ceph_messenger *msgr;
  116. struct socket *sock;
  117. unsigned long state; /* connection state (see flags above) */
  118. const char *error_msg; /* error message, if any */
  119. struct ceph_entity_addr peer_addr; /* peer address */
  120. struct ceph_entity_name peer_name; /* peer name */
  121. struct ceph_entity_addr peer_addr_for_me;
  122. unsigned peer_features;
  123. u32 connect_seq; /* identify the most recent connection
  124. attempt for this connection, client */
  125. u32 peer_global_seq; /* peer's global seq for this connection */
  126. int auth_retry; /* true if we need a newer authorizer */
  127. void *auth_reply_buf; /* where to put the authorizer reply */
  128. int auth_reply_buf_len;
  129. struct mutex mutex;
  130. /* out queue */
  131. struct list_head out_queue;
  132. struct list_head out_sent; /* sending or sent but unacked */
  133. u64 out_seq; /* last message queued for send */
  134. u64 in_seq, in_seq_acked; /* last message received, acked */
  135. /* connection negotiation temps */
  136. char in_banner[CEPH_BANNER_MAX_LEN];
  137. union {
  138. struct { /* outgoing connection */
  139. struct ceph_msg_connect out_connect;
  140. struct ceph_msg_connect_reply in_reply;
  141. };
  142. struct { /* incoming */
  143. struct ceph_msg_connect in_connect;
  144. struct ceph_msg_connect_reply out_reply;
  145. };
  146. };
  147. struct ceph_entity_addr actual_peer_addr;
  148. /* message out temps */
  149. struct ceph_msg *out_msg; /* sending message (== tail of
  150. out_sent) */
  151. bool out_msg_done;
  152. struct ceph_msg_pos out_msg_pos;
  153. struct kvec out_kvec[8], /* sending header/footer data */
  154. *out_kvec_cur;
  155. int out_kvec_left; /* kvec's left in out_kvec */
  156. int out_skip; /* skip this many bytes */
  157. int out_kvec_bytes; /* total bytes left */
  158. bool out_kvec_is_msg; /* kvec refers to out_msg */
  159. int out_more; /* there is more data after the kvecs */
  160. __le64 out_temp_ack; /* for writing an ack */
  161. /* message in temps */
  162. struct ceph_msg_header in_hdr;
  163. struct ceph_msg *in_msg;
  164. struct ceph_msg_pos in_msg_pos;
  165. u32 in_front_crc, in_middle_crc, in_data_crc; /* calculated crc */
  166. char in_tag; /* protocol control byte */
  167. int in_base_pos; /* bytes read */
  168. __le64 in_temp_ack; /* for reading an ack */
  169. struct delayed_work work; /* send|recv work */
  170. unsigned long delay; /* current delay interval */
  171. };
  172. extern const char *ceph_pr_addr(const struct sockaddr_storage *ss);
  173. extern int ceph_parse_ips(const char *c, const char *end,
  174. struct ceph_entity_addr *addr,
  175. int max_count, int *count);
  176. extern int ceph_msgr_init(void);
  177. extern void ceph_msgr_exit(void);
  178. extern void ceph_msgr_flush(void);
  179. extern struct ceph_messenger *ceph_messenger_create(
  180. struct ceph_entity_addr *myaddr,
  181. u32 features, u32 required);
  182. extern void ceph_messenger_destroy(struct ceph_messenger *);
  183. extern void ceph_con_init(struct ceph_messenger *msgr,
  184. struct ceph_connection *con);
  185. extern void ceph_con_open(struct ceph_connection *con,
  186. struct ceph_entity_addr *addr);
  187. extern bool ceph_con_opened(struct ceph_connection *con);
  188. extern void ceph_con_close(struct ceph_connection *con);
  189. extern void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg);
  190. extern void ceph_con_revoke(struct ceph_connection *con, struct ceph_msg *msg);
  191. extern void ceph_con_revoke_message(struct ceph_connection *con,
  192. struct ceph_msg *msg);
  193. extern void ceph_con_keepalive(struct ceph_connection *con);
  194. extern struct ceph_connection *ceph_con_get(struct ceph_connection *con);
  195. extern void ceph_con_put(struct ceph_connection *con);
  196. extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
  197. bool can_fail);
  198. extern void ceph_msg_kfree(struct ceph_msg *m);
  199. static inline struct ceph_msg *ceph_msg_get(struct ceph_msg *msg)
  200. {
  201. kref_get(&msg->kref);
  202. return msg;
  203. }
  204. extern void ceph_msg_last_put(struct kref *kref);
  205. static inline void ceph_msg_put(struct ceph_msg *msg)
  206. {
  207. kref_put(&msg->kref, ceph_msg_last_put);
  208. }
  209. extern void ceph_msg_dump(struct ceph_msg *msg);
  210. #endif