Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
31b8006e SW |
2 | #ifndef __FS_CEPH_MESSENGER_H |
3 | #define __FS_CEPH_MESSENGER_H | |
4 | ||
9f082171 | 5 | #include <linux/bvec.h> |
cd1a677c | 6 | #include <linux/crypto.h> |
c2e552e7 | 7 | #include <linux/kref.h> |
31b8006e SW |
8 | #include <linux/mutex.h> |
9 | #include <linux/net.h> | |
10 | #include <linux/radix-tree.h> | |
11 | #include <linux/uio.h> | |
31b8006e | 12 | #include <linux/workqueue.h> |
757856d2 | 13 | #include <net/net_namespace.h> |
31b8006e | 14 | |
a1ce3928 DH |
15 | #include <linux/ceph/types.h> |
16 | #include <linux/ceph/buffer.h> | |
31b8006e SW |
17 | |
18 | struct ceph_msg; | |
19 | struct ceph_connection; | |
20 | ||
31b8006e SW |
21 | /* |
22 | * Ceph defines these callbacks for handling connection events. | |
23 | */ | |
24 | struct ceph_connection_operations { | |
25 | struct ceph_connection *(*get)(struct ceph_connection *); | |
26 | void (*put)(struct ceph_connection *); | |
27 | ||
28 | /* handle an incoming message. */ | |
29 | void (*dispatch) (struct ceph_connection *con, struct ceph_msg *m); | |
30 | ||
4e7a5dcd | 31 | /* authorize an outgoing connection */ |
a3530df3 AE |
32 | struct ceph_auth_handshake *(*get_authorizer) ( |
33 | struct ceph_connection *con, | |
8f43fb53 | 34 | int *proto, int force_new); |
6daca13d ID |
35 | int (*add_authorizer_challenge)(struct ceph_connection *con, |
36 | void *challenge_buf, | |
37 | int challenge_buf_len); | |
0dde5848 | 38 | int (*verify_authorizer_reply) (struct ceph_connection *con); |
9bd2e6f8 | 39 | int (*invalidate_authorizer)(struct ceph_connection *con); |
4e7a5dcd | 40 | |
31b8006e SW |
41 | /* there was some error on the socket (disconnect, whatever) */ |
42 | void (*fault) (struct ceph_connection *con); | |
43 | ||
44 | /* a remote host as terminated a message exchange session, and messages | |
45 | * we sent (or they tried to send us) may be lost. */ | |
46 | void (*peer_reset) (struct ceph_connection *con); | |
47 | ||
48 | struct ceph_msg * (*alloc_msg) (struct ceph_connection *con, | |
2450418c YS |
49 | struct ceph_msg_header *hdr, |
50 | int *skip); | |
33d07337 | 51 | |
98ad5ebd ID |
52 | void (*reencode_message) (struct ceph_msg *msg); |
53 | ||
79dbd1ba ID |
54 | int (*sign_message) (struct ceph_msg *msg); |
55 | int (*check_message_signature) (struct ceph_msg *msg); | |
cd1a677c ID |
56 | |
57 | /* msgr2 authentication exchange */ | |
58 | int (*get_auth_request)(struct ceph_connection *con, | |
59 | void *buf, int *buf_len, | |
60 | void **authorizer, int *authorizer_len); | |
61 | int (*handle_auth_reply_more)(struct ceph_connection *con, | |
62 | void *reply, int reply_len, | |
63 | void *buf, int *buf_len, | |
64 | void **authorizer, int *authorizer_len); | |
65 | int (*handle_auth_done)(struct ceph_connection *con, | |
66 | u64 global_id, void *reply, int reply_len, | |
67 | u8 *session_key, int *session_key_len, | |
68 | u8 *con_secret, int *con_secret_len); | |
69 | int (*handle_auth_bad_method)(struct ceph_connection *con, | |
70 | int used_proto, int result, | |
71 | const int *allowed_protos, int proto_cnt, | |
72 | const int *allowed_modes, int mode_cnt); | |
31b8006e SW |
73 | }; |
74 | ||
b07720d0 | 75 | /* use format string %s%lld */ |
ca9d93a2 | 76 | #define ENTITY_NAME(n) ceph_entity_type_name((n).type), le64_to_cpu((n).num) |
31b8006e SW |
77 | |
78 | struct ceph_messenger { | |
79 | struct ceph_entity_inst inst; /* my name+address */ | |
63f2d211 | 80 | struct ceph_entity_addr my_enc_addr; |
31b8006e | 81 | |
a2a32584 | 82 | atomic_t stopping; |
757856d2 | 83 | possible_net_t net; |
31b8006e SW |
84 | |
85 | /* | |
86 | * the global_seq counts connections i (attempt to) initiate | |
87 | * in order to disambiguate certain connect race conditions. | |
88 | */ | |
89 | u32 global_seq; | |
90 | spinlock_t global_seq_lock; | |
91 | }; | |
92 | ||
43794509 AE |
93 | enum ceph_msg_data_type { |
94 | CEPH_MSG_DATA_NONE, /* message contains no data payload */ | |
95 | CEPH_MSG_DATA_PAGES, /* data source/destination is a page array */ | |
96 | CEPH_MSG_DATA_PAGELIST, /* data source/destination is a pagelist */ | |
97 | #ifdef CONFIG_BLOCK | |
98 | CEPH_MSG_DATA_BIO, /* data source/destination is a bio list */ | |
99 | #endif /* CONFIG_BLOCK */ | |
b9e281c2 | 100 | CEPH_MSG_DATA_BVECS, /* data source/destination is a bio_vec array */ |
43794509 AE |
101 | }; |
102 | ||
5359a17d ID |
103 | #ifdef CONFIG_BLOCK |
104 | ||
105 | struct ceph_bio_iter { | |
106 | struct bio *bio; | |
107 | struct bvec_iter iter; | |
108 | }; | |
109 | ||
110 | #define __ceph_bio_iter_advance_step(it, n, STEP) do { \ | |
111 | unsigned int __n = (n), __cur_n; \ | |
112 | \ | |
113 | while (__n) { \ | |
114 | BUG_ON(!(it)->iter.bi_size); \ | |
115 | __cur_n = min((it)->iter.bi_size, __n); \ | |
116 | (void)(STEP); \ | |
117 | bio_advance_iter((it)->bio, &(it)->iter, __cur_n); \ | |
118 | if (!(it)->iter.bi_size && (it)->bio->bi_next) { \ | |
119 | dout("__ceph_bio_iter_advance_step next bio\n"); \ | |
120 | (it)->bio = (it)->bio->bi_next; \ | |
121 | (it)->iter = (it)->bio->bi_iter; \ | |
122 | } \ | |
123 | __n -= __cur_n; \ | |
124 | } \ | |
125 | } while (0) | |
126 | ||
127 | /* | |
128 | * Advance @it by @n bytes. | |
129 | */ | |
130 | #define ceph_bio_iter_advance(it, n) \ | |
131 | __ceph_bio_iter_advance_step(it, n, 0) | |
132 | ||
133 | /* | |
134 | * Advance @it by @n bytes, executing BVEC_STEP for each bio_vec. | |
135 | */ | |
136 | #define ceph_bio_iter_advance_step(it, n, BVEC_STEP) \ | |
137 | __ceph_bio_iter_advance_step(it, n, ({ \ | |
138 | struct bio_vec bv; \ | |
139 | struct bvec_iter __cur_iter; \ | |
140 | \ | |
141 | __cur_iter = (it)->iter; \ | |
142 | __cur_iter.bi_size = __cur_n; \ | |
143 | __bio_for_each_segment(bv, (it)->bio, __cur_iter, __cur_iter) \ | |
144 | (void)(BVEC_STEP); \ | |
145 | })) | |
146 | ||
147 | #endif /* CONFIG_BLOCK */ | |
148 | ||
b9e281c2 ID |
149 | struct ceph_bvec_iter { |
150 | struct bio_vec *bvecs; | |
151 | struct bvec_iter iter; | |
152 | }; | |
153 | ||
154 | #define __ceph_bvec_iter_advance_step(it, n, STEP) do { \ | |
155 | BUG_ON((n) > (it)->iter.bi_size); \ | |
156 | (void)(STEP); \ | |
157 | bvec_iter_advance((it)->bvecs, &(it)->iter, (n)); \ | |
158 | } while (0) | |
159 | ||
160 | /* | |
161 | * Advance @it by @n bytes. | |
162 | */ | |
163 | #define ceph_bvec_iter_advance(it, n) \ | |
164 | __ceph_bvec_iter_advance_step(it, n, 0) | |
165 | ||
166 | /* | |
167 | * Advance @it by @n bytes, executing BVEC_STEP for each bio_vec. | |
168 | */ | |
169 | #define ceph_bvec_iter_advance_step(it, n, BVEC_STEP) \ | |
170 | __ceph_bvec_iter_advance_step(it, n, ({ \ | |
171 | struct bio_vec bv; \ | |
172 | struct bvec_iter __cur_iter; \ | |
173 | \ | |
174 | __cur_iter = (it)->iter; \ | |
175 | __cur_iter.bi_size = (n); \ | |
176 | for_each_bvec(bv, (it)->bvecs, __cur_iter, __cur_iter) \ | |
177 | (void)(BVEC_STEP); \ | |
178 | })) | |
179 | ||
180 | #define ceph_bvec_iter_shorten(it, n) do { \ | |
181 | BUG_ON((n) > (it)->iter.bi_size); \ | |
182 | (it)->iter.bi_size = (n); \ | |
183 | } while (0) | |
184 | ||
36153ec9 AE |
185 | struct ceph_msg_data { |
186 | enum ceph_msg_data_type type; | |
187 | union { | |
188 | #ifdef CONFIG_BLOCK | |
189 | struct { | |
5359a17d ID |
190 | struct ceph_bio_iter bio_pos; |
191 | u32 bio_length; | |
36153ec9 AE |
192 | }; |
193 | #endif /* CONFIG_BLOCK */ | |
b9e281c2 | 194 | struct ceph_bvec_iter bvec_pos; |
36153ec9 | 195 | struct { |
e8862740 | 196 | struct page **pages; |
36153ec9 AE |
197 | size_t length; /* total # bytes */ |
198 | unsigned int alignment; /* first page */ | |
e8862740 | 199 | bool own_pages; |
36153ec9 AE |
200 | }; |
201 | struct ceph_pagelist *pagelist; | |
202 | }; | |
36153ec9 AE |
203 | }; |
204 | ||
fe38a2b6 | 205 | struct ceph_msg_data_cursor { |
ca8b3a69 | 206 | size_t total_resid; /* across all data items */ |
ca8b3a69 AE |
207 | |
208 | struct ceph_msg_data *data; /* current data item */ | |
8ae4f4f5 | 209 | size_t resid; /* bytes not yet consumed */ |
8ae4f4f5 | 210 | bool need_crc; /* crc update needed */ |
dd236fcb | 211 | union { |
6aaa4511 | 212 | #ifdef CONFIG_BLOCK |
5359a17d | 213 | struct ceph_bio_iter bio_iter; |
6aaa4511 | 214 | #endif /* CONFIG_BLOCK */ |
b9e281c2 | 215 | struct bvec_iter bvec_iter; |
e766d7b5 | 216 | struct { /* pages */ |
e766d7b5 AE |
217 | unsigned int page_offset; /* offset in page */ |
218 | unsigned short page_index; /* index in array */ | |
219 | unsigned short page_count; /* pages in array */ | |
220 | }; | |
dd236fcb AE |
221 | struct { /* pagelist */ |
222 | struct page *page; /* page from list */ | |
223 | size_t offset; /* bytes from list */ | |
224 | }; | |
225 | }; | |
fe38a2b6 AE |
226 | }; |
227 | ||
31b8006e SW |
228 | /* |
229 | * a single message. it contains a header (src, dest, message type, etc.), | |
230 | * footer (crc values, mainly), a "front" message body, and possibly a | |
231 | * data payload (stored in some number of pages). | |
232 | */ | |
233 | struct ceph_msg { | |
234 | struct ceph_msg_header hdr; /* header */ | |
33d07337 YZ |
235 | union { |
236 | struct ceph_msg_footer footer; /* footer */ | |
237 | struct ceph_msg_footer_old old_footer; /* old format footer */ | |
238 | }; | |
31b8006e SW |
239 | struct kvec front; /* unaligned blobs of message */ |
240 | struct ceph_buffer *middle; | |
38941f80 | 241 | |
36153ec9 | 242 | size_t data_length; |
0d9c1ab3 ID |
243 | struct ceph_msg_data *data; |
244 | int num_data_items; | |
245 | int max_data_items; | |
36153ec9 | 246 | struct ceph_msg_data_cursor cursor; |
02afca6c AE |
247 | |
248 | struct ceph_connection *con; | |
249 | struct list_head list_head; /* links for connection lists */ | |
250 | ||
251 | struct kref kref; | |
31b8006e | 252 | bool more_to_follow; |
e84346b7 | 253 | bool needs_out_seq; |
3cea4c30 | 254 | int front_alloc_len; |
31b8006e SW |
255 | |
256 | struct ceph_msgpool *pool; | |
257 | }; | |
258 | ||
6d7f62bf ID |
259 | /* |
260 | * connection states | |
261 | */ | |
262 | #define CEPH_CON_S_CLOSED 1 | |
263 | #define CEPH_CON_S_PREOPEN 2 | |
264 | #define CEPH_CON_S_V1_BANNER 3 | |
265 | #define CEPH_CON_S_V1_CONNECT_MSG 4 | |
cd1a677c ID |
266 | #define CEPH_CON_S_V2_BANNER_PREFIX 5 |
267 | #define CEPH_CON_S_V2_BANNER_PAYLOAD 6 | |
268 | #define CEPH_CON_S_V2_HELLO 7 | |
269 | #define CEPH_CON_S_V2_AUTH 8 | |
270 | #define CEPH_CON_S_V2_AUTH_SIGNATURE 9 | |
271 | #define CEPH_CON_S_V2_SESSION_CONNECT 10 | |
272 | #define CEPH_CON_S_V2_SESSION_RECONNECT 11 | |
273 | #define CEPH_CON_S_OPEN 12 | |
274 | #define CEPH_CON_S_STANDBY 13 | |
6d7f62bf | 275 | |
3fefd43e ID |
276 | /* |
277 | * ceph_connection flag bits | |
278 | */ | |
279 | #define CEPH_CON_F_LOSSYTX 0 /* we can close channel or drop | |
280 | messages on errors */ | |
281 | #define CEPH_CON_F_KEEPALIVE_PENDING 1 /* we need to send a keepalive */ | |
282 | #define CEPH_CON_F_WRITE_PENDING 2 /* we have data ready to send */ | |
283 | #define CEPH_CON_F_SOCK_CLOSED 3 /* socket state changed to closed */ | |
284 | #define CEPH_CON_F_BACKOFF 4 /* need to retry queuing delayed | |
285 | work */ | |
286 | ||
31b8006e | 287 | /* ceph connection fault delay defaults, for exponential backoff */ |
418af5b3 ID |
288 | #define BASE_DELAY_INTERVAL (HZ / 4) |
289 | #define MAX_DELAY_INTERVAL (15 * HZ) | |
31b8006e | 290 | |
a56dd9bf ID |
291 | struct ceph_connection_v1_info { |
292 | struct kvec out_kvec[8], /* sending header/footer data */ | |
293 | *out_kvec_cur; | |
294 | int out_kvec_left; /* kvec's left in out_kvec */ | |
295 | int out_skip; /* skip this many bytes */ | |
296 | int out_kvec_bytes; /* total bytes left */ | |
297 | bool out_more; /* there is more data after the kvecs */ | |
298 | bool out_msg_done; | |
299 | ||
300 | struct ceph_auth_handshake *auth; | |
301 | int auth_retry; /* true if we need a newer authorizer */ | |
302 | ||
303 | /* connection negotiation temps */ | |
304 | u8 in_banner[CEPH_BANNER_MAX_LEN]; | |
305 | struct ceph_entity_addr actual_peer_addr; | |
306 | struct ceph_entity_addr peer_addr_for_me; | |
307 | struct ceph_msg_connect out_connect; | |
308 | struct ceph_msg_connect_reply in_reply; | |
309 | ||
310 | int in_base_pos; /* bytes read */ | |
311 | ||
312 | /* message in temps */ | |
313 | u8 in_tag; /* protocol control byte */ | |
314 | struct ceph_msg_header in_hdr; | |
315 | __le64 in_temp_ack; /* for reading an ack */ | |
316 | ||
317 | /* message out temps */ | |
318 | struct ceph_msg_header out_hdr; | |
319 | __le64 out_temp_ack; /* for writing an ack */ | |
320 | struct ceph_timespec out_temp_keepalive2; /* for writing keepalive2 | |
321 | stamp */ | |
322 | ||
323 | u32 connect_seq; /* identify the most recent connection | |
324 | attempt for this session */ | |
325 | u32 peer_global_seq; /* peer's global seq for this connection */ | |
326 | }; | |
327 | ||
cd1a677c ID |
328 | #define CEPH_CRC_LEN 4 |
329 | #define CEPH_GCM_KEY_LEN 16 | |
330 | #define CEPH_GCM_IV_LEN sizeof(struct ceph_gcm_nonce) | |
331 | #define CEPH_GCM_BLOCK_LEN 16 | |
332 | #define CEPH_GCM_TAG_LEN 16 | |
333 | ||
334 | #define CEPH_PREAMBLE_LEN 32 | |
335 | #define CEPH_PREAMBLE_INLINE_LEN 48 | |
336 | #define CEPH_PREAMBLE_PLAIN_LEN CEPH_PREAMBLE_LEN | |
337 | #define CEPH_PREAMBLE_SECURE_LEN (CEPH_PREAMBLE_LEN + \ | |
338 | CEPH_PREAMBLE_INLINE_LEN + \ | |
339 | CEPH_GCM_TAG_LEN) | |
340 | #define CEPH_EPILOGUE_PLAIN_LEN (1 + 3 * CEPH_CRC_LEN) | |
341 | #define CEPH_EPILOGUE_SECURE_LEN (CEPH_GCM_BLOCK_LEN + CEPH_GCM_TAG_LEN) | |
342 | ||
343 | #define CEPH_FRAME_MAX_SEGMENT_COUNT 4 | |
344 | ||
345 | struct ceph_frame_desc { | |
346 | int fd_tag; /* FRAME_TAG_* */ | |
347 | int fd_seg_cnt; | |
348 | int fd_lens[CEPH_FRAME_MAX_SEGMENT_COUNT]; /* logical */ | |
349 | int fd_aligns[CEPH_FRAME_MAX_SEGMENT_COUNT]; | |
350 | }; | |
351 | ||
352 | struct ceph_gcm_nonce { | |
353 | __le32 fixed; | |
354 | __le64 counter __packed; | |
355 | }; | |
356 | ||
357 | struct ceph_connection_v2_info { | |
358 | struct iov_iter in_iter; | |
359 | struct kvec in_kvecs[5]; /* recvmsg */ | |
360 | struct bio_vec in_bvec; /* recvmsg (in_cursor) */ | |
361 | int in_kvec_cnt; | |
362 | int in_state; /* IN_S_* */ | |
363 | ||
364 | struct iov_iter out_iter; | |
365 | struct kvec out_kvecs[8]; /* sendmsg */ | |
366 | struct bio_vec out_bvec; /* sendpage (out_cursor, out_zero), | |
367 | sendmsg (out_enc_pages) */ | |
368 | int out_kvec_cnt; | |
369 | int out_state; /* OUT_S_* */ | |
370 | ||
371 | int out_zero; /* # of zero bytes to send */ | |
372 | bool out_iter_sendpage; /* use sendpage if possible */ | |
373 | ||
374 | struct ceph_frame_desc in_desc; | |
375 | struct ceph_msg_data_cursor in_cursor; | |
376 | struct ceph_msg_data_cursor out_cursor; | |
377 | ||
378 | struct crypto_shash *hmac_tfm; /* post-auth signature */ | |
379 | struct crypto_aead *gcm_tfm; /* on-wire encryption */ | |
380 | struct aead_request *gcm_req; | |
381 | struct crypto_wait gcm_wait; | |
382 | struct ceph_gcm_nonce in_gcm_nonce; | |
383 | struct ceph_gcm_nonce out_gcm_nonce; | |
384 | ||
2ea88716 ID |
385 | struct page **in_enc_pages; |
386 | int in_enc_page_cnt; | |
387 | int in_enc_resid; | |
388 | int in_enc_i; | |
cd1a677c ID |
389 | struct page **out_enc_pages; |
390 | int out_enc_page_cnt; | |
391 | int out_enc_resid; | |
392 | int out_enc_i; | |
393 | ||
394 | int con_mode; /* CEPH_CON_MODE_* */ | |
395 | ||
396 | void *conn_bufs[16]; | |
397 | int conn_buf_cnt; | |
398 | ||
399 | struct kvec in_sign_kvecs[8]; | |
400 | struct kvec out_sign_kvecs[8]; | |
401 | int in_sign_kvec_cnt; | |
402 | int out_sign_kvec_cnt; | |
403 | ||
404 | u64 client_cookie; | |
405 | u64 server_cookie; | |
406 | u64 global_seq; | |
407 | u64 connect_seq; | |
408 | u64 peer_global_seq; | |
409 | ||
410 | u8 in_buf[CEPH_PREAMBLE_SECURE_LEN]; | |
411 | u8 out_buf[CEPH_PREAMBLE_SECURE_LEN]; | |
412 | struct { | |
413 | u8 late_status; /* FRAME_LATE_STATUS_* */ | |
414 | union { | |
415 | struct { | |
416 | u32 front_crc; | |
417 | u32 middle_crc; | |
418 | u32 data_crc; | |
419 | } __packed; | |
420 | u8 pad[CEPH_GCM_BLOCK_LEN - 1]; | |
421 | }; | |
422 | } out_epil; | |
423 | }; | |
424 | ||
31b8006e SW |
425 | /* |
426 | * A single connection with another host. | |
427 | * | |
428 | * We maintain a queue of outgoing messages, and some session state to | |
429 | * ensure that we can preserve the lossless, ordered delivery of | |
430 | * messages in the case of a TCP disconnect. | |
431 | */ | |
432 | struct ceph_connection { | |
433 | void *private; | |
31b8006e SW |
434 | |
435 | const struct ceph_connection_operations *ops; | |
436 | ||
437 | struct ceph_messenger *msgr; | |
ce2c8903 | 438 | |
6d7f62bf | 439 | int state; /* CEPH_CON_S_* */ |
ce2c8903 | 440 | atomic_t sock_state; |
31b8006e | 441 | struct socket *sock; |
ce2c8903 | 442 | |
3fefd43e | 443 | unsigned long flags; /* CEPH_CON_F_* */ |
31b8006e SW |
444 | const char *error_msg; /* error message, if any */ |
445 | ||
31b8006e | 446 | struct ceph_entity_name peer_name; /* peer name */ |
a56dd9bf | 447 | struct ceph_entity_addr peer_addr; /* peer address */ |
12b4629a | 448 | u64 peer_features; |
4e7a5dcd | 449 | |
ec302645 SW |
450 | struct mutex mutex; |
451 | ||
31b8006e | 452 | /* out queue */ |
31b8006e SW |
453 | struct list_head out_queue; |
454 | struct list_head out_sent; /* sending or sent but unacked */ | |
455 | u64 out_seq; /* last message queued for send */ | |
31b8006e SW |
456 | |
457 | u64 in_seq, in_seq_acked; /* last message received, acked */ | |
458 | ||
a56dd9bf | 459 | struct ceph_msg *in_msg; |
31b8006e SW |
460 | struct ceph_msg *out_msg; /* sending message (== tail of |
461 | out_sent) */ | |
31b8006e | 462 | |
038b8d1d | 463 | struct page *bounce_page; |
31b8006e SW |
464 | u32 in_front_crc, in_middle_crc, in_data_crc; /* calculated crc */ |
465 | ||
473bd2d7 | 466 | struct timespec64 last_keepalive_ack; /* keepalive2 ack stamp */ |
8b9558aa | 467 | |
31b8006e SW |
468 | struct delayed_work work; /* send|recv work */ |
469 | unsigned long delay; /* current delay interval */ | |
a56dd9bf | 470 | |
cd1a677c ID |
471 | union { |
472 | struct ceph_connection_v1_info v1; | |
473 | struct ceph_connection_v2_info v2; | |
474 | }; | |
31b8006e SW |
475 | }; |
476 | ||
699921d9 | 477 | extern struct page *ceph_zero_page; |
31b8006e | 478 | |
6503e0b6 ID |
479 | void ceph_con_flag_clear(struct ceph_connection *con, unsigned long con_flag); |
480 | void ceph_con_flag_set(struct ceph_connection *con, unsigned long con_flag); | |
481 | bool ceph_con_flag_test(struct ceph_connection *con, unsigned long con_flag); | |
482 | bool ceph_con_flag_test_and_clear(struct ceph_connection *con, | |
483 | unsigned long con_flag); | |
484 | bool ceph_con_flag_test_and_set(struct ceph_connection *con, | |
485 | unsigned long con_flag); | |
486 | ||
487 | void ceph_encode_my_addr(struct ceph_messenger *msgr); | |
488 | ||
489 | int ceph_tcp_connect(struct ceph_connection *con); | |
490 | int ceph_con_close_socket(struct ceph_connection *con); | |
491 | void ceph_con_reset_session(struct ceph_connection *con); | |
492 | ||
493 | u32 ceph_get_global_seq(struct ceph_messenger *msgr, u32 gt); | |
494 | void ceph_con_discard_sent(struct ceph_connection *con, u64 ack_seq); | |
495 | void ceph_con_discard_requeued(struct ceph_connection *con, u64 reconnect_seq); | |
496 | ||
497 | void ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor, | |
498 | struct ceph_msg *msg, size_t length); | |
499 | struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor, | |
da4ab869 | 500 | size_t *page_offset, size_t *length); |
6503e0b6 ID |
501 | void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor, size_t bytes); |
502 | ||
503 | u32 ceph_crc32c_page(u32 crc, struct page *page, unsigned int page_offset, | |
504 | unsigned int length); | |
505 | ||
506 | bool ceph_addr_is_blank(const struct ceph_entity_addr *addr); | |
507 | int ceph_addr_port(const struct ceph_entity_addr *addr); | |
508 | void ceph_addr_set_port(struct ceph_entity_addr *addr, int p); | |
509 | ||
510 | void ceph_con_process_message(struct ceph_connection *con); | |
511 | int ceph_con_in_msg_alloc(struct ceph_connection *con, | |
512 | struct ceph_msg_header *hdr, int *skip); | |
513 | void ceph_con_get_out_msg(struct ceph_connection *con); | |
514 | ||
2f713615 | 515 | /* messenger_v1.c */ |
566050e1 ID |
516 | int ceph_con_v1_try_read(struct ceph_connection *con); |
517 | int ceph_con_v1_try_write(struct ceph_connection *con); | |
518 | void ceph_con_v1_revoke(struct ceph_connection *con); | |
519 | void ceph_con_v1_revoke_incoming(struct ceph_connection *con); | |
520 | bool ceph_con_v1_opened(struct ceph_connection *con); | |
521 | void ceph_con_v1_reset_session(struct ceph_connection *con); | |
522 | void ceph_con_v1_reset_protocol(struct ceph_connection *con); | |
523 | ||
cd1a677c ID |
524 | /* messenger_v2.c */ |
525 | int ceph_con_v2_try_read(struct ceph_connection *con); | |
526 | int ceph_con_v2_try_write(struct ceph_connection *con); | |
527 | void ceph_con_v2_revoke(struct ceph_connection *con); | |
528 | void ceph_con_v2_revoke_incoming(struct ceph_connection *con); | |
529 | bool ceph_con_v2_opened(struct ceph_connection *con); | |
530 | void ceph_con_v2_reset_session(struct ceph_connection *con); | |
531 | void ceph_con_v2_reset_protocol(struct ceph_connection *con); | |
532 | ||
6503e0b6 | 533 | |
b726ec97 JL |
534 | extern const char *ceph_pr_addr(const struct ceph_entity_addr *addr); |
535 | ||
31b8006e SW |
536 | extern int ceph_parse_ips(const char *c, const char *end, |
537 | struct ceph_entity_addr *addr, | |
2d7c86a8 | 538 | int max_count, int *count, char delim); |
31b8006e | 539 | |
31b8006e SW |
540 | extern int ceph_msgr_init(void); |
541 | extern void ceph_msgr_exit(void); | |
a922d38f | 542 | extern void ceph_msgr_flush(void); |
31b8006e | 543 | |
15d9882c | 544 | extern void ceph_messenger_init(struct ceph_messenger *msgr, |
859bff51 | 545 | struct ceph_entity_addr *myaddr); |
757856d2 | 546 | extern void ceph_messenger_fini(struct ceph_messenger *msgr); |
120a75ea | 547 | extern void ceph_messenger_reset_nonce(struct ceph_messenger *msgr); |
31b8006e | 548 | |
1bfd89f4 AE |
549 | extern void ceph_con_init(struct ceph_connection *con, void *private, |
550 | const struct ceph_connection_operations *ops, | |
b7a9e5dd | 551 | struct ceph_messenger *msgr); |
31b8006e | 552 | extern void ceph_con_open(struct ceph_connection *con, |
b7a9e5dd | 553 | __u8 entity_type, __u64 entity_num, |
31b8006e | 554 | struct ceph_entity_addr *addr); |
87b315a5 | 555 | extern bool ceph_con_opened(struct ceph_connection *con); |
31b8006e SW |
556 | extern void ceph_con_close(struct ceph_connection *con); |
557 | extern void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg); | |
6740a845 AE |
558 | |
559 | extern void ceph_msg_revoke(struct ceph_msg *msg); | |
8921d114 AE |
560 | extern void ceph_msg_revoke_incoming(struct ceph_msg *msg); |
561 | ||
31b8006e | 562 | extern void ceph_con_keepalive(struct ceph_connection *con); |
8b9558aa YZ |
563 | extern bool ceph_con_keepalive_expired(struct ceph_connection *con, |
564 | unsigned long interval); | |
31b8006e | 565 | |
e8862740 ID |
566 | void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages, |
567 | size_t length, size_t alignment, bool own_pages); | |
90af3602 | 568 | extern void ceph_msg_data_add_pagelist(struct ceph_msg *msg, |
27fa8385 | 569 | struct ceph_pagelist *pagelist); |
ea96571f | 570 | #ifdef CONFIG_BLOCK |
5359a17d ID |
571 | void ceph_msg_data_add_bio(struct ceph_msg *msg, struct ceph_bio_iter *bio_pos, |
572 | u32 length); | |
ea96571f | 573 | #endif /* CONFIG_BLOCK */ |
b9e281c2 ID |
574 | void ceph_msg_data_add_bvecs(struct ceph_msg *msg, |
575 | struct ceph_bvec_iter *bvec_pos); | |
02afca6c | 576 | |
0d9c1ab3 ID |
577 | struct ceph_msg *ceph_msg_new2(int type, int front_len, int max_data_items, |
578 | gfp_t flags, bool can_fail); | |
b61c2763 SW |
579 | extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags, |
580 | bool can_fail); | |
31b8006e | 581 | |
0215e44b ID |
582 | extern struct ceph_msg *ceph_msg_get(struct ceph_msg *msg); |
583 | extern void ceph_msg_put(struct ceph_msg *msg); | |
31b8006e | 584 | |
9ec7cab1 SW |
585 | extern void ceph_msg_dump(struct ceph_msg *msg); |
586 | ||
31b8006e | 587 | #endif |