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