1#ifndef __FS_CEPH_MESSENGER_H
2#define __FS_CEPH_MESSENGER_H
3
4#include <linux/blk_types.h>
5#include <linux/kref.h>
6#include <linux/mutex.h>
7#include <linux/net.h>
8#include <linux/radix-tree.h>
9#include <linux/uio.h>
10#include <linux/workqueue.h>
11#include <net/net_namespace.h>
12
13#include <linux/ceph/types.h>
14#include <linux/ceph/buffer.h>
15
16struct ceph_msg;
17struct ceph_connection;
18
19
20
21
22struct ceph_connection_operations {
23 struct ceph_connection *(*get)(struct ceph_connection *);
24 void (*put)(struct ceph_connection *);
25
26
27 void (*dispatch) (struct ceph_connection *con, struct ceph_msg *m);
28
29
30 struct ceph_auth_handshake *(*get_authorizer) (
31 struct ceph_connection *con,
32 int *proto, int force_new);
33 int (*verify_authorizer_reply) (struct ceph_connection *con, int len);
34 int (*invalidate_authorizer)(struct ceph_connection *con);
35
36
37 void (*fault) (struct ceph_connection *con);
38
39
40
41 void (*peer_reset) (struct ceph_connection *con);
42
43 struct ceph_msg * (*alloc_msg) (struct ceph_connection *con,
44 struct ceph_msg_header *hdr,
45 int *skip);
46
47 int (*sign_message) (struct ceph_msg *msg);
48 int (*check_message_signature) (struct ceph_msg *msg);
49};
50
51
52#define ENTITY_NAME(n) ceph_entity_type_name((n).type), le64_to_cpu((n).num)
53
54struct ceph_messenger {
55 struct ceph_entity_inst inst;
56 struct ceph_entity_addr my_enc_addr;
57
58 atomic_t stopping;
59 possible_net_t net;
60
61
62
63
64
65 u32 global_seq;
66 spinlock_t global_seq_lock;
67};
68
69enum ceph_msg_data_type {
70 CEPH_MSG_DATA_NONE,
71 CEPH_MSG_DATA_PAGES,
72 CEPH_MSG_DATA_PAGELIST,
73#ifdef CONFIG_BLOCK
74 CEPH_MSG_DATA_BIO,
75#endif
76};
77
78static __inline__ bool ceph_msg_data_type_valid(enum ceph_msg_data_type type)
79{
80 switch (type) {
81 case CEPH_MSG_DATA_NONE:
82 case CEPH_MSG_DATA_PAGES:
83 case CEPH_MSG_DATA_PAGELIST:
84#ifdef CONFIG_BLOCK
85 case CEPH_MSG_DATA_BIO:
86#endif
87 return true;
88 default:
89 return false;
90 }
91}
92
93struct ceph_msg_data {
94 struct list_head links;
95 enum ceph_msg_data_type type;
96 union {
97#ifdef CONFIG_BLOCK
98 struct {
99 struct bio *bio;
100 size_t bio_length;
101 };
102#endif
103 struct {
104 struct page **pages;
105 size_t length;
106 unsigned int alignment;
107 };
108 struct ceph_pagelist *pagelist;
109 };
110};
111
112struct ceph_msg_data_cursor {
113 size_t total_resid;
114 struct list_head *data_head;
115
116 struct ceph_msg_data *data;
117 size_t resid;
118 bool last_piece;
119 bool need_crc;
120 union {
121#ifdef CONFIG_BLOCK
122 struct {
123 struct bio *bio;
124 struct bvec_iter bvec_iter;
125 };
126#endif
127 struct {
128 unsigned int page_offset;
129 unsigned short page_index;
130 unsigned short page_count;
131 };
132 struct {
133 struct page *page;
134 size_t offset;
135 };
136 };
137};
138
139
140
141
142
143
144struct ceph_msg {
145 struct ceph_msg_header hdr;
146 union {
147 struct ceph_msg_footer footer;
148 struct ceph_msg_footer_old old_footer;
149 };
150 struct kvec front;
151 struct ceph_buffer *middle;
152
153 size_t data_length;
154 struct list_head data;
155 struct ceph_msg_data_cursor cursor;
156
157 struct ceph_connection *con;
158 struct list_head list_head;
159
160 struct kref kref;
161 bool more_to_follow;
162 bool needs_out_seq;
163 int front_alloc_len;
164 unsigned long ack_stamp;
165
166 struct ceph_msgpool *pool;
167};
168
169
170#define BASE_DELAY_INTERVAL (HZ/2)
171#define MAX_DELAY_INTERVAL (5 * 60 * HZ)
172
173
174
175
176
177
178
179
180struct ceph_connection {
181 void *private;
182
183 const struct ceph_connection_operations *ops;
184
185 struct ceph_messenger *msgr;
186
187 atomic_t sock_state;
188 struct socket *sock;
189 struct ceph_entity_addr peer_addr;
190 struct ceph_entity_addr peer_addr_for_me;
191
192 unsigned long flags;
193 unsigned long state;
194 const char *error_msg;
195
196 struct ceph_entity_name peer_name;
197
198 u64 peer_features;
199 u32 connect_seq;
200
201 u32 peer_global_seq;
202
203 int auth_retry;
204 void *auth_reply_buf;
205 int auth_reply_buf_len;
206
207 struct mutex mutex;
208
209
210 struct list_head out_queue;
211 struct list_head out_sent;
212 u64 out_seq;
213
214 u64 in_seq, in_seq_acked;
215
216
217 char in_banner[CEPH_BANNER_MAX_LEN];
218 struct ceph_msg_connect out_connect;
219 struct ceph_msg_connect_reply in_reply;
220 struct ceph_entity_addr actual_peer_addr;
221
222
223 struct ceph_msg_header out_hdr;
224 struct ceph_msg *out_msg;
225
226 bool out_msg_done;
227
228 struct kvec out_kvec[8],
229 *out_kvec_cur;
230 int out_kvec_left;
231 int out_skip;
232 int out_kvec_bytes;
233 int out_more;
234 __le64 out_temp_ack;
235 struct ceph_timespec out_temp_keepalive2;
236
237
238
239 struct ceph_msg_header in_hdr;
240 struct ceph_msg *in_msg;
241 u32 in_front_crc, in_middle_crc, in_data_crc;
242
243 char in_tag;
244 int in_base_pos;
245 __le64 in_temp_ack;
246
247 struct timespec last_keepalive_ack;
248
249 struct delayed_work work;
250 unsigned long delay;
251};
252
253
254extern const char *ceph_pr_addr(const struct sockaddr_storage *ss);
255extern int ceph_parse_ips(const char *c, const char *end,
256 struct ceph_entity_addr *addr,
257 int max_count, int *count);
258
259
260extern int ceph_msgr_init(void);
261extern void ceph_msgr_exit(void);
262extern void ceph_msgr_flush(void);
263
264extern void ceph_messenger_init(struct ceph_messenger *msgr,
265 struct ceph_entity_addr *myaddr);
266extern void ceph_messenger_fini(struct ceph_messenger *msgr);
267
268extern void ceph_con_init(struct ceph_connection *con, void *private,
269 const struct ceph_connection_operations *ops,
270 struct ceph_messenger *msgr);
271extern void ceph_con_open(struct ceph_connection *con,
272 __u8 entity_type, __u64 entity_num,
273 struct ceph_entity_addr *addr);
274extern bool ceph_con_opened(struct ceph_connection *con);
275extern void ceph_con_close(struct ceph_connection *con);
276extern void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg);
277
278extern void ceph_msg_revoke(struct ceph_msg *msg);
279extern void ceph_msg_revoke_incoming(struct ceph_msg *msg);
280
281extern void ceph_con_keepalive(struct ceph_connection *con);
282extern bool ceph_con_keepalive_expired(struct ceph_connection *con,
283 unsigned long interval);
284
285extern void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages,
286 size_t length, size_t alignment);
287extern void ceph_msg_data_add_pagelist(struct ceph_msg *msg,
288 struct ceph_pagelist *pagelist);
289#ifdef CONFIG_BLOCK
290extern void ceph_msg_data_add_bio(struct ceph_msg *msg, struct bio *bio,
291 size_t length);
292#endif
293
294extern struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
295 bool can_fail);
296
297extern struct ceph_msg *ceph_msg_get(struct ceph_msg *msg);
298extern void ceph_msg_put(struct ceph_msg *msg);
299
300extern void ceph_msg_dump(struct ceph_msg *msg);
301
302#endif
303