]>
Commit | Line | Data |
---|---|---|
31b8006e SW |
1 | #ifndef __FS_CEPH_MESSENGER_H |
2 | #define __FS_CEPH_MESSENGER_H | |
3 | ||
f38a5181 | 4 | #include <linux/blk_types.h> |
c2e552e7 | 5 | #include <linux/kref.h> |
31b8006e SW |
6 | #include <linux/mutex.h> |
7 | #include <linux/net.h> | |
8 | #include <linux/radix-tree.h> | |
9 | #include <linux/uio.h> | |
31b8006e | 10 | #include <linux/workqueue.h> |
757856d2 | 11 | #include <net/net_namespace.h> |
31b8006e | 12 | |
a1ce3928 DH |
13 | #include <linux/ceph/types.h> |
14 | #include <linux/ceph/buffer.h> | |
31b8006e SW |
15 | |
16 | struct ceph_msg; | |
17 | struct ceph_connection; | |
18 | ||
31b8006e SW |
19 | /* |
20 | * Ceph defines these callbacks for handling connection events. | |
21 | */ | |
22 | struct ceph_connection_operations { | |
23 | struct ceph_connection *(*get)(struct ceph_connection *); | |
24 | void (*put)(struct ceph_connection *); | |
25 | ||
26 | /* handle an incoming message. */ | |
27 | void (*dispatch) (struct ceph_connection *con, struct ceph_msg *m); | |
28 | ||
4e7a5dcd | 29 | /* authorize an outgoing connection */ |
a3530df3 AE |
30 | struct ceph_auth_handshake *(*get_authorizer) ( |
31 | struct ceph_connection *con, | |
8f43fb53 | 32 | int *proto, int force_new); |
4e7a5dcd | 33 | int (*verify_authorizer_reply) (struct ceph_connection *con, int len); |
9bd2e6f8 | 34 | int (*invalidate_authorizer)(struct ceph_connection *con); |
4e7a5dcd | 35 | |
31b8006e SW |
36 | /* there was some error on the socket (disconnect, whatever) */ |
37 | void (*fault) (struct ceph_connection *con); | |
38 | ||
39 | /* a remote host as terminated a message exchange session, and messages | |
40 | * we sent (or they tried to send us) may be lost. */ | |
41 | void (*peer_reset) (struct ceph_connection *con); | |
42 | ||
43 | struct ceph_msg * (*alloc_msg) (struct ceph_connection *con, | |
2450418c YS |
44 | struct ceph_msg_header *hdr, |
45 | int *skip); | |
33d07337 YZ |
46 | int (*sign_message) (struct ceph_connection *con, struct ceph_msg *msg); |
47 | ||
48 | int (*check_message_signature) (struct ceph_connection *con, | |
49 | struct ceph_msg *msg); | |
31b8006e SW |
50 | }; |
51 | ||
31b8006e | 52 | /* use format string %s%d */ |
ca9d93a2 | 53 | #define ENTITY_NAME(n) ceph_entity_type_name((n).type), le64_to_cpu((n).num) |
31b8006e SW |
54 | |
55 | struct ceph_messenger { | |
56 | struct ceph_entity_inst inst; /* my name+address */ | |
63f2d211 | 57 | struct ceph_entity_addr my_enc_addr; |
31b8006e | 58 | |
a2a32584 | 59 | atomic_t stopping; |
757856d2 | 60 | possible_net_t net; |
31b8006e | 61 | bool nocrc; |
ba988f87 | 62 | bool tcp_nodelay; |
31b8006e SW |
63 | |
64 | /* | |
65 | * the global_seq counts connections i (attempt to) initiate | |
66 | * in order to disambiguate certain connect race conditions. | |
67 | */ | |
68 | u32 global_seq; | |
69 | spinlock_t global_seq_lock; | |
3d14c5d2 | 70 | |
12b4629a ID |
71 | u64 supported_features; |
72 | u64 required_features; | |
31b8006e SW |
73 | }; |
74 | ||
43794509 AE |
75 | enum ceph_msg_data_type { |
76 | CEPH_MSG_DATA_NONE, /* message contains no data payload */ | |
77 | CEPH_MSG_DATA_PAGES, /* data source/destination is a page array */ | |
78 | CEPH_MSG_DATA_PAGELIST, /* data source/destination is a pagelist */ | |
79 | #ifdef CONFIG_BLOCK | |
80 | CEPH_MSG_DATA_BIO, /* data source/destination is a bio list */ | |
81 | #endif /* CONFIG_BLOCK */ | |
82 | }; | |
83 | ||
84 | static __inline__ bool ceph_msg_data_type_valid(enum ceph_msg_data_type type) | |
85 | { | |
86 | switch (type) { | |
87 | case CEPH_MSG_DATA_NONE: | |
88 | case CEPH_MSG_DATA_PAGES: | |
89 | case CEPH_MSG_DATA_PAGELIST: | |
90 | #ifdef CONFIG_BLOCK | |
91 | case CEPH_MSG_DATA_BIO: | |
92 | #endif /* CONFIG_BLOCK */ | |
93 | return true; | |
94 | default: | |
95 | return false; | |
96 | } | |
97 | } | |
98 | ||
36153ec9 | 99 | struct ceph_msg_data { |
5240d9f9 | 100 | struct list_head links; /* ceph_msg->data */ |
36153ec9 AE |
101 | enum ceph_msg_data_type type; |
102 | union { | |
103 | #ifdef CONFIG_BLOCK | |
104 | struct { | |
105 | struct bio *bio; | |
106 | size_t bio_length; | |
107 | }; | |
108 | #endif /* CONFIG_BLOCK */ | |
109 | struct { | |
110 | struct page **pages; /* NOT OWNER. */ | |
111 | size_t length; /* total # bytes */ | |
112 | unsigned int alignment; /* first page */ | |
113 | }; | |
114 | struct ceph_pagelist *pagelist; | |
115 | }; | |
36153ec9 AE |
116 | }; |
117 | ||
fe38a2b6 | 118 | struct ceph_msg_data_cursor { |
ca8b3a69 AE |
119 | size_t total_resid; /* across all data items */ |
120 | struct list_head *data_head; /* = &ceph_msg->data */ | |
121 | ||
122 | struct ceph_msg_data *data; /* current data item */ | |
8ae4f4f5 AE |
123 | size_t resid; /* bytes not yet consumed */ |
124 | bool last_piece; /* current is last piece */ | |
125 | bool need_crc; /* crc update needed */ | |
dd236fcb | 126 | union { |
6aaa4511 AE |
127 | #ifdef CONFIG_BLOCK |
128 | struct { /* bio */ | |
129 | struct bio *bio; /* bio from list */ | |
f38a5181 | 130 | struct bvec_iter bvec_iter; |
6aaa4511 AE |
131 | }; |
132 | #endif /* CONFIG_BLOCK */ | |
e766d7b5 | 133 | struct { /* pages */ |
e766d7b5 AE |
134 | unsigned int page_offset; /* offset in page */ |
135 | unsigned short page_index; /* index in array */ | |
136 | unsigned short page_count; /* pages in array */ | |
137 | }; | |
dd236fcb AE |
138 | struct { /* pagelist */ |
139 | struct page *page; /* page from list */ | |
140 | size_t offset; /* bytes from list */ | |
141 | }; | |
142 | }; | |
fe38a2b6 AE |
143 | }; |
144 | ||
31b8006e SW |
145 | /* |
146 | * a single message. it contains a header (src, dest, message type, etc.), | |
147 | * footer (crc values, mainly), a "front" message body, and possibly a | |
148 | * data payload (stored in some number of pages). | |
149 | */ | |
150 | struct ceph_msg { | |
151 | struct ceph_msg_header hdr; /* header */ | |
33d07337 YZ |
152 | union { |
153 | struct ceph_msg_footer footer; /* footer */ | |
154 | struct ceph_msg_footer_old old_footer; /* old format footer */ | |
155 | }; | |
31b8006e SW |
156 | struct kvec front; /* unaligned blobs of message */ |
157 | struct ceph_buffer *middle; | |
38941f80 | 158 | |
36153ec9 | 159 | size_t data_length; |
5240d9f9 | 160 | struct list_head data; |
36153ec9 | 161 | struct ceph_msg_data_cursor cursor; |
02afca6c AE |
162 | |
163 | struct ceph_connection *con; | |
164 | struct list_head list_head; /* links for connection lists */ | |
165 | ||
166 | struct kref kref; | |
31b8006e | 167 | bool more_to_follow; |
e84346b7 | 168 | bool needs_out_seq; |
3cea4c30 | 169 | int front_alloc_len; |
4cf9d544 | 170 | unsigned long ack_stamp; /* tx: when we were acked */ |
31b8006e SW |
171 | |
172 | struct ceph_msgpool *pool; | |
173 | }; | |
174 | ||
31b8006e SW |
175 | /* ceph connection fault delay defaults, for exponential backoff */ |
176 | #define BASE_DELAY_INTERVAL (HZ/2) | |
177 | #define MAX_DELAY_INTERVAL (5 * 60 * HZ) | |
178 | ||
31b8006e SW |
179 | /* |
180 | * A single connection with another host. | |
181 | * | |
182 | * We maintain a queue of outgoing messages, and some session state to | |
183 | * ensure that we can preserve the lossless, ordered delivery of | |
184 | * messages in the case of a TCP disconnect. | |
185 | */ | |
186 | struct ceph_connection { | |
187 | void *private; | |
31b8006e SW |
188 | |
189 | const struct ceph_connection_operations *ops; | |
190 | ||
191 | struct ceph_messenger *msgr; | |
ce2c8903 AE |
192 | |
193 | atomic_t sock_state; | |
31b8006e | 194 | struct socket *sock; |
ce2c8903 AE |
195 | struct ceph_entity_addr peer_addr; /* peer address */ |
196 | struct ceph_entity_addr peer_addr_for_me; | |
197 | ||
928443cd AE |
198 | unsigned long flags; |
199 | unsigned long state; | |
31b8006e SW |
200 | const char *error_msg; /* error message, if any */ |
201 | ||
31b8006e | 202 | struct ceph_entity_name peer_name; /* peer name */ |
ce2c8903 | 203 | |
12b4629a | 204 | u64 peer_features; |
31b8006e SW |
205 | u32 connect_seq; /* identify the most recent connection |
206 | attempt for this connection, client */ | |
207 | u32 peer_global_seq; /* peer's global seq for this connection */ | |
208 | ||
4e7a5dcd SW |
209 | int auth_retry; /* true if we need a newer authorizer */ |
210 | void *auth_reply_buf; /* where to put the authorizer reply */ | |
211 | int auth_reply_buf_len; | |
212 | ||
ec302645 SW |
213 | struct mutex mutex; |
214 | ||
31b8006e | 215 | /* out queue */ |
31b8006e SW |
216 | struct list_head out_queue; |
217 | struct list_head out_sent; /* sending or sent but unacked */ | |
218 | u64 out_seq; /* last message queued for send */ | |
31b8006e SW |
219 | |
220 | u64 in_seq, in_seq_acked; /* last message received, acked */ | |
221 | ||
222 | /* connection negotiation temps */ | |
223 | char in_banner[CEPH_BANNER_MAX_LEN]; | |
a16cb1f7 SW |
224 | struct ceph_msg_connect out_connect; |
225 | struct ceph_msg_connect_reply in_reply; | |
31b8006e SW |
226 | struct ceph_entity_addr actual_peer_addr; |
227 | ||
228 | /* message out temps */ | |
229 | struct ceph_msg *out_msg; /* sending message (== tail of | |
230 | out_sent) */ | |
c86a2930 | 231 | bool out_msg_done; |
31b8006e SW |
232 | |
233 | struct kvec out_kvec[8], /* sending header/footer data */ | |
234 | *out_kvec_cur; | |
235 | int out_kvec_left; /* kvec's left in out_kvec */ | |
236 | int out_skip; /* skip this many bytes */ | |
237 | int out_kvec_bytes; /* total bytes left */ | |
238 | bool out_kvec_is_msg; /* kvec refers to out_msg */ | |
239 | int out_more; /* there is more data after the kvecs */ | |
240 | __le64 out_temp_ack; /* for writing an ack */ | |
7f61f545 ID |
241 | struct ceph_timespec out_temp_keepalive2; /* for writing keepalive2 |
242 | stamp */ | |
31b8006e SW |
243 | |
244 | /* message in temps */ | |
245 | struct ceph_msg_header in_hdr; | |
246 | struct ceph_msg *in_msg; | |
31b8006e SW |
247 | u32 in_front_crc, in_middle_crc, in_data_crc; /* calculated crc */ |
248 | ||
249 | char in_tag; /* protocol control byte */ | |
250 | int in_base_pos; /* bytes read */ | |
251 | __le64 in_temp_ack; /* for reading an ack */ | |
252 | ||
7f61f545 | 253 | struct timespec last_keepalive_ack; /* keepalive2 ack stamp */ |
8b9558aa | 254 | |
31b8006e SW |
255 | struct delayed_work work; /* send|recv work */ |
256 | unsigned long delay; /* current delay interval */ | |
257 | }; | |
258 | ||
259 | ||
3d14c5d2 | 260 | extern const char *ceph_pr_addr(const struct sockaddr_storage *ss); |
31b8006e SW |
261 | extern int ceph_parse_ips(const char *c, const char *end, |
262 | struct ceph_entity_addr *addr, | |
263 | int max_count, int *count); | |
264 | ||
265 | ||
266 | extern int ceph_msgr_init(void); | |
267 | extern void ceph_msgr_exit(void); | |
a922d38f | 268 | extern void ceph_msgr_flush(void); |
31b8006e | 269 | |
15d9882c AE |
270 | extern void ceph_messenger_init(struct ceph_messenger *msgr, |
271 | struct ceph_entity_addr *myaddr, | |
12b4629a ID |
272 | u64 supported_features, |
273 | u64 required_features, | |
ba988f87 CH |
274 | bool nocrc, |
275 | bool tcp_nodelay); | |
757856d2 | 276 | extern void ceph_messenger_fini(struct ceph_messenger *msgr); |
31b8006e | 277 | |
1bfd89f4 AE |
278 | extern void ceph_con_init(struct ceph_connection *con, void *private, |
279 | const struct ceph_connection_operations *ops, | |
b7a9e5dd | 280 | struct ceph_messenger *msgr); |
31b8006e | 281 | extern void ceph_con_open(struct ceph_connection *con, |
b7a9e5dd | 282 | __u8 entity_type, __u64 entity_num, |
31b8006e | 283 | struct ceph_entity_addr *addr); |
87b315a5 | 284 | extern bool ceph_con_opened(struct ceph_connection *con); |
31b8006e SW |
285 | extern void ceph_con_close(struct ceph_connection *con); |
286 | extern void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg); | |
6740a845 AE |
287 | |
288 | extern void ceph_msg_revoke(struct ceph_msg *msg); | |
8921d114 AE |
289 | extern void ceph_msg_revoke_incoming(struct ceph_msg *msg); |
290 | ||
31b8006e | 291 | extern void ceph_con_keepalive(struct ceph_connection *con); |
8b9558aa YZ |
292 | extern bool ceph_con_keepalive_expired(struct ceph_connection *con, |
293 | unsigned long interval); | |
31b8006e | 294 | |
90af3602 | 295 | extern void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages, |
f1baeb2b | 296 | size_t length, size_t alignment); |
90af3602 | 297 | extern void ceph_msg_data_add_pagelist(struct ceph_msg *msg, |
27fa8385 | 298 | struct ceph_pagelist *pagelist); |
ea96571f | 299 | #ifdef CONFIG_BLOCK |
90af3602 | 300 | extern void ceph_msg_data_add_bio(struct ceph_msg *msg, struct bio *bio, |
a1930804 | 301 | size_t length); |
ea96571f | 302 | #endif /* CONFIG_BLOCK */ |
02afca6c | 303 | |
b61c2763 SW |
304 | extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags, |
305 | bool can_fail); | |
31b8006e | 306 | |
0215e44b ID |
307 | extern struct ceph_msg *ceph_msg_get(struct ceph_msg *msg); |
308 | extern void ceph_msg_put(struct ceph_msg *msg); | |
31b8006e | 309 | |
9ec7cab1 SW |
310 | extern void ceph_msg_dump(struct ceph_msg *msg); |
311 | ||
31b8006e | 312 | #endif |