1 #ifndef __FS_CEPH_MESSENGER_H
2 #define __FS_CEPH_MESSENGER_H
4 #include <linux/blk_types.h>
5 #include <linux/kref.h>
6 #include <linux/mutex.h>
8 #include <linux/radix-tree.h>
10 #include <linux/workqueue.h>
11 #include <net/net_namespace.h>
13 #include <linux/ceph/types.h>
14 #include <linux/ceph/buffer.h>
17 struct ceph_connection
;
20 * Ceph defines these callbacks for handling connection events.
22 struct ceph_connection_operations
{
23 struct ceph_connection
*(*get
)(struct ceph_connection
*);
24 void (*put
)(struct ceph_connection
*);
26 /* handle an incoming message. */
27 void (*dispatch
) (struct ceph_connection
*con
, struct ceph_msg
*m
);
29 /* authorize an outgoing connection */
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
);
36 /* there was some error on the socket (disconnect, whatever) */
37 void (*fault
) (struct ceph_connection
*con
);
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
);
43 struct ceph_msg
* (*alloc_msg
) (struct ceph_connection
*con
,
44 struct ceph_msg_header
*hdr
,
47 int (*sign_message
) (struct ceph_msg
*msg
);
48 int (*check_message_signature
) (struct ceph_msg
*msg
);
51 /* use format string %s%d */
52 #define ENTITY_NAME(n) ceph_entity_type_name((n).type), le64_to_cpu((n).num)
54 struct ceph_messenger
{
55 struct ceph_entity_inst inst
; /* my name+address */
56 struct ceph_entity_addr my_enc_addr
;
62 * the global_seq counts connections i (attempt to) initiate
63 * in order to disambiguate certain connect race conditions.
66 spinlock_t global_seq_lock
;
69 enum ceph_msg_data_type
{
70 CEPH_MSG_DATA_NONE
, /* message contains no data payload */
71 CEPH_MSG_DATA_PAGES
, /* data source/destination is a page array */
72 CEPH_MSG_DATA_PAGELIST
, /* data source/destination is a pagelist */
74 CEPH_MSG_DATA_BIO
, /* data source/destination is a bio list */
75 #endif /* CONFIG_BLOCK */
78 static __inline__
bool ceph_msg_data_type_valid(enum ceph_msg_data_type type
)
81 case CEPH_MSG_DATA_NONE
:
82 case CEPH_MSG_DATA_PAGES
:
83 case CEPH_MSG_DATA_PAGELIST
:
85 case CEPH_MSG_DATA_BIO
:
86 #endif /* CONFIG_BLOCK */
93 struct ceph_msg_data
{
94 struct list_head links
; /* ceph_msg->data */
95 enum ceph_msg_data_type type
;
102 #endif /* CONFIG_BLOCK */
104 struct page
**pages
; /* NOT OWNER. */
105 size_t length
; /* total # bytes */
106 unsigned int alignment
; /* first page */
108 struct ceph_pagelist
*pagelist
;
112 struct ceph_msg_data_cursor
{
113 size_t total_resid
; /* across all data items */
114 struct list_head
*data_head
; /* = &ceph_msg->data */
116 struct ceph_msg_data
*data
; /* current data item */
117 size_t resid
; /* bytes not yet consumed */
118 bool last_piece
; /* current is last piece */
119 bool need_crc
; /* crc update needed */
123 struct bio
*bio
; /* bio from list */
124 struct bvec_iter bvec_iter
;
126 #endif /* CONFIG_BLOCK */
128 unsigned int page_offset
; /* offset in page */
129 unsigned short page_index
; /* index in array */
130 unsigned short page_count
; /* pages in array */
132 struct { /* pagelist */
133 struct page
*page
; /* page from list */
134 size_t offset
; /* bytes from list */
140 * a single message. it contains a header (src, dest, message type, etc.),
141 * footer (crc values, mainly), a "front" message body, and possibly a
142 * data payload (stored in some number of pages).
145 struct ceph_msg_header hdr
; /* header */
147 struct ceph_msg_footer footer
; /* footer */
148 struct ceph_msg_footer_old old_footer
; /* old format footer */
150 struct kvec front
; /* unaligned blobs of message */
151 struct ceph_buffer
*middle
;
154 struct list_head data
;
155 struct ceph_msg_data_cursor cursor
;
157 struct ceph_connection
*con
;
158 struct list_head list_head
; /* links for connection lists */
164 unsigned long ack_stamp
; /* tx: when we were acked */
166 struct ceph_msgpool
*pool
;
169 /* ceph connection fault delay defaults, for exponential backoff */
170 #define BASE_DELAY_INTERVAL (HZ/2)
171 #define MAX_DELAY_INTERVAL (5 * 60 * HZ)
174 * A single connection with another host.
176 * We maintain a queue of outgoing messages, and some session state to
177 * ensure that we can preserve the lossless, ordered delivery of
178 * messages in the case of a TCP disconnect.
180 struct ceph_connection
{
183 const struct ceph_connection_operations
*ops
;
185 struct ceph_messenger
*msgr
;
189 struct ceph_entity_addr peer_addr
; /* peer address */
190 struct ceph_entity_addr peer_addr_for_me
;
194 const char *error_msg
; /* error message, if any */
196 struct ceph_entity_name peer_name
; /* peer name */
199 u32 connect_seq
; /* identify the most recent connection
200 attempt for this connection, client */
201 u32 peer_global_seq
; /* peer's global seq for this connection */
203 int auth_retry
; /* true if we need a newer authorizer */
204 void *auth_reply_buf
; /* where to put the authorizer reply */
205 int auth_reply_buf_len
;
210 struct list_head out_queue
;
211 struct list_head out_sent
; /* sending or sent but unacked */
212 u64 out_seq
; /* last message queued for send */
214 u64 in_seq
, in_seq_acked
; /* last message received, acked */
216 /* connection negotiation temps */
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
;
222 /* message out temps */
223 struct ceph_msg_header out_hdr
;
224 struct ceph_msg
*out_msg
; /* sending message (== tail of
228 struct kvec out_kvec
[8], /* sending header/footer data */
230 int out_kvec_left
; /* kvec's left in out_kvec */
231 int out_skip
; /* skip this many bytes */
232 int out_kvec_bytes
; /* total bytes left */
233 int out_more
; /* there is more data after the kvecs */
234 __le64 out_temp_ack
; /* for writing an ack */
235 struct ceph_timespec out_temp_keepalive2
; /* for writing keepalive2
238 /* message in temps */
239 struct ceph_msg_header in_hdr
;
240 struct ceph_msg
*in_msg
;
241 u32 in_front_crc
, in_middle_crc
, in_data_crc
; /* calculated crc */
243 char in_tag
; /* protocol control byte */
244 int in_base_pos
; /* bytes read */
245 __le64 in_temp_ack
; /* for reading an ack */
247 struct timespec last_keepalive_ack
; /* keepalive2 ack stamp */
249 struct delayed_work work
; /* send|recv work */
250 unsigned long delay
; /* current delay interval */
254 extern const char *ceph_pr_addr(const struct sockaddr_storage
*ss
);
255 extern int ceph_parse_ips(const char *c
, const char *end
,
256 struct ceph_entity_addr
*addr
,
257 int max_count
, int *count
);
260 extern int ceph_msgr_init(void);
261 extern void ceph_msgr_exit(void);
262 extern void ceph_msgr_flush(void);
264 extern void ceph_messenger_init(struct ceph_messenger
*msgr
,
265 struct ceph_entity_addr
*myaddr
);
266 extern void ceph_messenger_fini(struct ceph_messenger
*msgr
);
268 extern void ceph_con_init(struct ceph_connection
*con
, void *private,
269 const struct ceph_connection_operations
*ops
,
270 struct ceph_messenger
*msgr
);
271 extern void ceph_con_open(struct ceph_connection
*con
,
272 __u8 entity_type
, __u64 entity_num
,
273 struct ceph_entity_addr
*addr
);
274 extern bool ceph_con_opened(struct ceph_connection
*con
);
275 extern void ceph_con_close(struct ceph_connection
*con
);
276 extern void ceph_con_send(struct ceph_connection
*con
, struct ceph_msg
*msg
);
278 extern void ceph_msg_revoke(struct ceph_msg
*msg
);
279 extern void ceph_msg_revoke_incoming(struct ceph_msg
*msg
);
281 extern void ceph_con_keepalive(struct ceph_connection
*con
);
282 extern bool ceph_con_keepalive_expired(struct ceph_connection
*con
,
283 unsigned long interval
);
285 extern void ceph_msg_data_add_pages(struct ceph_msg
*msg
, struct page
**pages
,
286 size_t length
, size_t alignment
);
287 extern void ceph_msg_data_add_pagelist(struct ceph_msg
*msg
,
288 struct ceph_pagelist
*pagelist
);
290 extern void ceph_msg_data_add_bio(struct ceph_msg
*msg
, struct bio
*bio
,
292 #endif /* CONFIG_BLOCK */
294 extern struct ceph_msg
*ceph_msg_new(int type
, int front_len
, gfp_t flags
,
297 extern struct ceph_msg
*ceph_msg_get(struct ceph_msg
*msg
);
298 extern void ceph_msg_put(struct ceph_msg
*msg
);
300 extern void ceph_msg_dump(struct ceph_msg
*msg
);