1 #include <linux/ceph/ceph_debug.h>
3 #include <linux/crc32c.h>
4 #include <linux/ctype.h>
5 #include <linux/highmem.h>
6 #include <linux/inet.h>
7 #include <linux/kthread.h>
9 #include <linux/slab.h>
10 #include <linux/socket.h>
11 #include <linux/string.h>
12 #include <linux/bio.h>
13 #include <linux/blkdev.h>
14 #include <linux/dns_resolver.h>
17 #include <linux/ceph/libceph.h>
18 #include <linux/ceph/messenger.h>
19 #include <linux/ceph/decode.h>
20 #include <linux/ceph/pagelist.h>
21 #include <linux/export.h>
24 * Ceph uses the messenger to exchange ceph_msg messages with other
25 * hosts in the system. The messenger provides ordered and reliable
26 * delivery. We tolerate TCP disconnects by reconnecting (with
27 * exponential backoff) in the case of a fault (disconnection, bad
28 * crc, protocol error). Acks allow sent messages to be discarded by
32 /* State values for ceph_connection->sock_state; NEW is assumed to be 0 */
34 #define CON_SOCK_STATE_NEW 0 /* -> CLOSED */
35 #define CON_SOCK_STATE_CLOSED 1 /* -> CONNECTING */
36 #define CON_SOCK_STATE_CONNECTING 2 /* -> CONNECTED or -> CLOSING */
37 #define CON_SOCK_STATE_CONNECTED 3 /* -> CLOSING or -> CLOSED */
38 #define CON_SOCK_STATE_CLOSING 4 /* -> CLOSED */
40 /* static tag bytes (protocol control messages) */
41 static char tag_msg = CEPH_MSGR_TAG_MSG;
42 static char tag_ack = CEPH_MSGR_TAG_ACK;
43 static char tag_keepalive = CEPH_MSGR_TAG_KEEPALIVE;
46 static struct lock_class_key socket_class;
50 * When skipping (ignoring) a block of input we read it into a "skip
51 * buffer," which is this many bytes in size.
53 #define SKIP_BUF_SIZE 1024
55 static void queue_con(struct ceph_connection *con);
56 static void con_work(struct work_struct *);
57 static void ceph_fault(struct ceph_connection *con);
60 * Nicely render a sockaddr as a string. An array of formatted
61 * strings is used, to approximate reentrancy.
63 #define ADDR_STR_COUNT_LOG 5 /* log2(# address strings in array) */
64 #define ADDR_STR_COUNT (1 << ADDR_STR_COUNT_LOG)
65 #define ADDR_STR_COUNT_MASK (ADDR_STR_COUNT - 1)
66 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
68 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
69 static atomic_t addr_str_seq = ATOMIC_INIT(0);
71 static struct page *zero_page; /* used in certain error cases */
73 const char *ceph_pr_addr(const struct sockaddr_storage *ss)
77 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
78 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
80 i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
83 switch (ss->ss_family) {
85 snprintf(s, MAX_ADDR_STR_LEN, "%pI4:%hu", &in4->sin_addr,
86 ntohs(in4->sin_port));
90 snprintf(s, MAX_ADDR_STR_LEN, "[%pI6c]:%hu", &in6->sin6_addr,
91 ntohs(in6->sin6_port));
95 snprintf(s, MAX_ADDR_STR_LEN, "(unknown sockaddr family %hu)",
101 EXPORT_SYMBOL(ceph_pr_addr);
103 static void encode_my_addr(struct ceph_messenger *msgr)
105 memcpy(&msgr->my_enc_addr, &msgr->inst.addr, sizeof(msgr->my_enc_addr));
106 ceph_encode_addr(&msgr->my_enc_addr);
110 * work queue for all reading and writing to/from the socket.
112 static struct workqueue_struct *ceph_msgr_wq;
114 void _ceph_msgr_exit(void)
117 destroy_workqueue(ceph_msgr_wq);
121 BUG_ON(zero_page == NULL);
123 page_cache_release(zero_page);
127 int ceph_msgr_init(void)
129 BUG_ON(zero_page != NULL);
130 zero_page = ZERO_PAGE(0);
131 page_cache_get(zero_page);
133 ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0);
137 pr_err("msgr_init failed to create workqueue\n");
142 EXPORT_SYMBOL(ceph_msgr_init);
144 void ceph_msgr_exit(void)
146 BUG_ON(ceph_msgr_wq == NULL);
150 EXPORT_SYMBOL(ceph_msgr_exit);
152 void ceph_msgr_flush(void)
154 flush_workqueue(ceph_msgr_wq);
156 EXPORT_SYMBOL(ceph_msgr_flush);
158 /* Connection socket state transition functions */
160 static void con_sock_state_init(struct ceph_connection *con)
164 old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CLOSED);
165 if (WARN_ON(old_state != CON_SOCK_STATE_NEW))
166 printk("%s: unexpected old state %d\n", __func__, old_state);
169 static void con_sock_state_connecting(struct ceph_connection *con)
173 old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CONNECTING);
174 if (WARN_ON(old_state != CON_SOCK_STATE_CLOSED))
175 printk("%s: unexpected old state %d\n", __func__, old_state);
178 static void con_sock_state_connected(struct ceph_connection *con)
182 old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CONNECTED);
183 if (WARN_ON(old_state != CON_SOCK_STATE_CONNECTING))
184 printk("%s: unexpected old state %d\n", __func__, old_state);
187 static void con_sock_state_closing(struct ceph_connection *con)
191 old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CLOSING);
192 if (WARN_ON(old_state != CON_SOCK_STATE_CONNECTING &&
193 old_state != CON_SOCK_STATE_CONNECTED &&
194 old_state != CON_SOCK_STATE_CLOSING))
195 printk("%s: unexpected old state %d\n", __func__, old_state);
198 static void con_sock_state_closed(struct ceph_connection *con)
202 old_state = atomic_xchg(&con->sock_state, CON_SOCK_STATE_CLOSED);
203 if (WARN_ON(old_state != CON_SOCK_STATE_CONNECTED &&
204 old_state != CON_SOCK_STATE_CLOSING))
205 printk("%s: unexpected old state %d\n", __func__, old_state);
209 * socket callback functions
212 /* data available on socket, or listen socket received a connect */
213 static void ceph_sock_data_ready(struct sock *sk, int count_unused)
215 struct ceph_connection *con = sk->sk_user_data;
217 if (sk->sk_state != TCP_CLOSE_WAIT) {
218 dout("%s on %p state = %lu, queueing work\n", __func__,
224 /* socket has buffer space for writing */
225 static void ceph_sock_write_space(struct sock *sk)
227 struct ceph_connection *con = sk->sk_user_data;
229 /* only queue to workqueue if there is data we want to write,
230 * and there is sufficient space in the socket buffer to accept
231 * more data. clear SOCK_NOSPACE so that ceph_sock_write_space()
232 * doesn't get called again until try_write() fills the socket
233 * buffer. See net/ipv4/tcp_input.c:tcp_check_space()
234 * and net/core/stream.c:sk_stream_write_space().
236 if (test_bit(WRITE_PENDING, &con->flags)) {
237 if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) {
238 dout("%s %p queueing write work\n", __func__, con);
239 clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
243 dout("%s %p nothing to write\n", __func__, con);
247 /* socket's state has changed */
248 static void ceph_sock_state_change(struct sock *sk)
250 struct ceph_connection *con = sk->sk_user_data;
252 dout("%s %p state = %lu sk_state = %u\n", __func__,
253 con, con->state, sk->sk_state);
255 if (test_bit(CLOSED, &con->state))
258 switch (sk->sk_state) {
260 dout("%s TCP_CLOSE\n", __func__);
262 dout("%s TCP_CLOSE_WAIT\n", __func__);
263 con_sock_state_closing(con);
264 set_bit(SOCK_CLOSED, &con->flags);
267 case TCP_ESTABLISHED:
268 dout("%s TCP_ESTABLISHED\n", __func__);
269 con_sock_state_connected(con);
272 default: /* Everything else is uninteresting */
278 * set up socket callbacks
280 static void set_sock_callbacks(struct socket *sock,
281 struct ceph_connection *con)
283 struct sock *sk = sock->sk;
284 sk->sk_user_data = con;
285 sk->sk_data_ready = ceph_sock_data_ready;
286 sk->sk_write_space = ceph_sock_write_space;
287 sk->sk_state_change = ceph_sock_state_change;
296 * initiate connection to a remote socket.
298 static int ceph_tcp_connect(struct ceph_connection *con)
300 struct sockaddr_storage *paddr = &con->peer_addr.in_addr;
305 ret = sock_create_kern(con->peer_addr.in_addr.ss_family, SOCK_STREAM,
309 sock->sk->sk_allocation = GFP_NOFS;
311 #ifdef CONFIG_LOCKDEP
312 lockdep_set_class(&sock->sk->sk_lock, &socket_class);
315 set_sock_callbacks(sock, con);
317 dout("connect %s\n", ceph_pr_addr(&con->peer_addr.in_addr));
319 con_sock_state_connecting(con);
320 ret = sock->ops->connect(sock, (struct sockaddr *)paddr, sizeof(*paddr),
322 if (ret == -EINPROGRESS) {
323 dout("connect %s EINPROGRESS sk_state = %u\n",
324 ceph_pr_addr(&con->peer_addr.in_addr),
326 } else if (ret < 0) {
327 pr_err("connect %s error %d\n",
328 ceph_pr_addr(&con->peer_addr.in_addr), ret);
330 con->error_msg = "connect error";
338 static int ceph_tcp_recvmsg(struct socket *sock, void *buf, size_t len)
340 struct kvec iov = {buf, len};
341 struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL };
344 r = kernel_recvmsg(sock, &msg, &iov, 1, len, msg.msg_flags);
351 * write something. @more is true if caller will be sending more data
354 static int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov,
355 size_t kvlen, size_t len, int more)
357 struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL };
361 msg.msg_flags |= MSG_MORE;
363 msg.msg_flags |= MSG_EOR; /* superfluous, but what the hell */
365 r = kernel_sendmsg(sock, &msg, iov, kvlen, len);
371 static int ceph_tcp_sendpage(struct socket *sock, struct page *page,
372 int offset, size_t size, int more)
374 int flags = MSG_DONTWAIT | MSG_NOSIGNAL | (more ? MSG_MORE : MSG_EOR);
377 ret = kernel_sendpage(sock, page, offset, size, flags);
386 * Shutdown/close the socket for the given connection.
388 static int con_close_socket(struct ceph_connection *con)
392 dout("con_close_socket on %p sock %p\n", con, con->sock);
395 rc = con->sock->ops->shutdown(con->sock, SHUT_RDWR);
396 sock_release(con->sock);
400 * Forcibly clear the SOCK_CLOSE flag. It gets set
401 * independent of the connection mutex, and we could have
402 * received a socket close event before we had the chance to
403 * shut the socket down.
405 clear_bit(SOCK_CLOSED, &con->flags);
406 con_sock_state_closed(con);
411 * Reset a connection. Discard all incoming and outgoing messages
412 * and clear *_seq state.
414 static void ceph_msg_remove(struct ceph_msg *msg)
416 list_del_init(&msg->list_head);
417 BUG_ON(msg->con == NULL);
418 msg->con->ops->put(msg->con);
423 static void ceph_msg_remove_list(struct list_head *head)
425 while (!list_empty(head)) {
426 struct ceph_msg *msg = list_first_entry(head, struct ceph_msg,
428 ceph_msg_remove(msg);
432 static void reset_connection(struct ceph_connection *con)
434 /* reset connection, out_queue, msg_ and connect_seq */
435 /* discard existing out_queue and msg_seq */
436 ceph_msg_remove_list(&con->out_queue);
437 ceph_msg_remove_list(&con->out_sent);
440 BUG_ON(con->in_msg->con != con);
441 con->in_msg->con = NULL;
442 ceph_msg_put(con->in_msg);
447 con->connect_seq = 0;
450 ceph_msg_put(con->out_msg);
454 con->in_seq_acked = 0;
458 * mark a peer down. drop any open connections.
460 void ceph_con_close(struct ceph_connection *con)
462 dout("con_close %p peer %s\n", con,
463 ceph_pr_addr(&con->peer_addr.in_addr));
464 clear_bit(NEGOTIATING, &con->state);
465 clear_bit(STANDBY, &con->state); /* avoid connect_seq bump */
466 set_bit(CLOSED, &con->state);
468 clear_bit(LOSSYTX, &con->flags); /* so we retry next connect */
469 clear_bit(KEEPALIVE_PENDING, &con->flags);
470 clear_bit(WRITE_PENDING, &con->flags);
472 mutex_lock(&con->mutex);
473 reset_connection(con);
474 con->peer_global_seq = 0;
475 cancel_delayed_work(&con->work);
476 mutex_unlock(&con->mutex);
479 EXPORT_SYMBOL(ceph_con_close);
482 * Reopen a closed connection, with a new peer address.
484 void ceph_con_open(struct ceph_connection *con, struct ceph_entity_addr *addr)
486 dout("con_open %p %s\n", con, ceph_pr_addr(&addr->in_addr));
487 set_bit(OPENING, &con->state);
488 WARN_ON(!test_and_clear_bit(CLOSED, &con->state));
490 memcpy(&con->peer_addr, addr, sizeof(*addr));
491 con->delay = 0; /* reset backoff memory */
494 EXPORT_SYMBOL(ceph_con_open);
497 * return true if this connection ever successfully opened
499 bool ceph_con_opened(struct ceph_connection *con)
501 return con->connect_seq > 0;
505 * initialize a new connection.
507 void ceph_con_init(struct ceph_connection *con, void *private,
508 const struct ceph_connection_operations *ops,
509 struct ceph_messenger *msgr, __u8 entity_type, __u64 entity_num)
511 dout("con_init %p\n", con);
512 memset(con, 0, sizeof(*con));
513 con->private = private;
517 con_sock_state_init(con);
519 con->peer_name.type = (__u8) entity_type;
520 con->peer_name.num = cpu_to_le64(entity_num);
522 mutex_init(&con->mutex);
523 INIT_LIST_HEAD(&con->out_queue);
524 INIT_LIST_HEAD(&con->out_sent);
525 INIT_DELAYED_WORK(&con->work, con_work);
527 set_bit(CLOSED, &con->state);
529 EXPORT_SYMBOL(ceph_con_init);
533 * We maintain a global counter to order connection attempts. Get
534 * a unique seq greater than @gt.
536 static u32 get_global_seq(struct ceph_messenger *msgr, u32 gt)
540 spin_lock(&msgr->global_seq_lock);
541 if (msgr->global_seq < gt)
542 msgr->global_seq = gt;
543 ret = ++msgr->global_seq;
544 spin_unlock(&msgr->global_seq_lock);
548 static void con_out_kvec_reset(struct ceph_connection *con)
550 con->out_kvec_left = 0;
551 con->out_kvec_bytes = 0;
552 con->out_kvec_cur = &con->out_kvec[0];
555 static void con_out_kvec_add(struct ceph_connection *con,
556 size_t size, void *data)
560 index = con->out_kvec_left;
561 BUG_ON(index >= ARRAY_SIZE(con->out_kvec));
563 con->out_kvec[index].iov_len = size;
564 con->out_kvec[index].iov_base = data;
565 con->out_kvec_left++;
566 con->out_kvec_bytes += size;
570 static void init_bio_iter(struct bio *bio, struct bio **iter, int *seg)
581 static void iter_bio_next(struct bio **bio_iter, int *seg)
583 if (*bio_iter == NULL)
586 BUG_ON(*seg >= (*bio_iter)->bi_vcnt);
589 if (*seg == (*bio_iter)->bi_vcnt)
590 init_bio_iter((*bio_iter)->bi_next, bio_iter, seg);
594 static void prepare_write_message_data(struct ceph_connection *con)
596 struct ceph_msg *msg = con->out_msg;
599 BUG_ON(!msg->hdr.data_len);
601 /* initialize page iterator */
602 con->out_msg_pos.page = 0;
604 con->out_msg_pos.page_pos = msg->page_alignment;
606 con->out_msg_pos.page_pos = 0;
609 init_bio_iter(msg->bio, &msg->bio_iter, &msg->bio_seg);
611 con->out_msg_pos.data_pos = 0;
612 con->out_msg_pos.did_page_crc = false;
613 con->out_more = 1; /* data + footer will follow */
617 * Prepare footer for currently outgoing message, and finish things
618 * off. Assumes out_kvec* are already valid.. we just add on to the end.
620 static void prepare_write_message_footer(struct ceph_connection *con)
622 struct ceph_msg *m = con->out_msg;
623 int v = con->out_kvec_left;
625 m->footer.flags |= CEPH_MSG_FOOTER_COMPLETE;
627 dout("prepare_write_message_footer %p\n", con);
628 con->out_kvec_is_msg = true;
629 con->out_kvec[v].iov_base = &m->footer;
630 con->out_kvec[v].iov_len = sizeof(m->footer);
631 con->out_kvec_bytes += sizeof(m->footer);
632 con->out_kvec_left++;
633 con->out_more = m->more_to_follow;
634 con->out_msg_done = true;
638 * Prepare headers for the next outgoing message.
640 static void prepare_write_message(struct ceph_connection *con)
645 con_out_kvec_reset(con);
646 con->out_kvec_is_msg = true;
647 con->out_msg_done = false;
649 /* Sneak an ack in there first? If we can get it into the same
650 * TCP packet that's a good thing. */
651 if (con->in_seq > con->in_seq_acked) {
652 con->in_seq_acked = con->in_seq;
653 con_out_kvec_add(con, sizeof (tag_ack), &tag_ack);
654 con->out_temp_ack = cpu_to_le64(con->in_seq_acked);
655 con_out_kvec_add(con, sizeof (con->out_temp_ack),
659 BUG_ON(list_empty(&con->out_queue));
660 m = list_first_entry(&con->out_queue, struct ceph_msg, list_head);
662 BUG_ON(m->con != con);
664 /* put message on sent list */
666 list_move_tail(&m->list_head, &con->out_sent);
669 * only assign outgoing seq # if we haven't sent this message
670 * yet. if it is requeued, resend with it's original seq.
672 if (m->needs_out_seq) {
673 m->hdr.seq = cpu_to_le64(++con->out_seq);
674 m->needs_out_seq = false;
677 dout("prepare_write_message %p seq %lld type %d len %d+%d+%d %d pgs\n",
678 m, con->out_seq, le16_to_cpu(m->hdr.type),
679 le32_to_cpu(m->hdr.front_len), le32_to_cpu(m->hdr.middle_len),
680 le32_to_cpu(m->hdr.data_len),
682 BUG_ON(le32_to_cpu(m->hdr.front_len) != m->front.iov_len);
684 /* tag + hdr + front + middle */
685 con_out_kvec_add(con, sizeof (tag_msg), &tag_msg);
686 con_out_kvec_add(con, sizeof (m->hdr), &m->hdr);
687 con_out_kvec_add(con, m->front.iov_len, m->front.iov_base);
690 con_out_kvec_add(con, m->middle->vec.iov_len,
691 m->middle->vec.iov_base);
693 /* fill in crc (except data pages), footer */
694 crc = crc32c(0, &m->hdr, offsetof(struct ceph_msg_header, crc));
695 con->out_msg->hdr.crc = cpu_to_le32(crc);
696 con->out_msg->footer.flags = 0;
698 crc = crc32c(0, m->front.iov_base, m->front.iov_len);
699 con->out_msg->footer.front_crc = cpu_to_le32(crc);
701 crc = crc32c(0, m->middle->vec.iov_base,
702 m->middle->vec.iov_len);
703 con->out_msg->footer.middle_crc = cpu_to_le32(crc);
705 con->out_msg->footer.middle_crc = 0;
706 dout("%s front_crc %u middle_crc %u\n", __func__,
707 le32_to_cpu(con->out_msg->footer.front_crc),
708 le32_to_cpu(con->out_msg->footer.middle_crc));
710 /* is there a data payload? */
711 con->out_msg->footer.data_crc = 0;
713 prepare_write_message_data(con);
715 /* no, queue up footer too and be done */
716 prepare_write_message_footer(con);
718 set_bit(WRITE_PENDING, &con->flags);
724 static void prepare_write_ack(struct ceph_connection *con)
726 dout("prepare_write_ack %p %llu -> %llu\n", con,
727 con->in_seq_acked, con->in_seq);
728 con->in_seq_acked = con->in_seq;
730 con_out_kvec_reset(con);
732 con_out_kvec_add(con, sizeof (tag_ack), &tag_ack);
734 con->out_temp_ack = cpu_to_le64(con->in_seq_acked);
735 con_out_kvec_add(con, sizeof (con->out_temp_ack),
738 con->out_more = 1; /* more will follow.. eventually.. */
739 set_bit(WRITE_PENDING, &con->flags);
743 * Prepare to write keepalive byte.
745 static void prepare_write_keepalive(struct ceph_connection *con)
747 dout("prepare_write_keepalive %p\n", con);
748 con_out_kvec_reset(con);
749 con_out_kvec_add(con, sizeof (tag_keepalive), &tag_keepalive);
750 set_bit(WRITE_PENDING, &con->flags);
754 * Connection negotiation.
757 static struct ceph_auth_handshake *get_connect_authorizer(struct ceph_connection *con,
760 struct ceph_auth_handshake *auth;
762 if (!con->ops->get_authorizer) {
763 con->out_connect.authorizer_protocol = CEPH_AUTH_UNKNOWN;
764 con->out_connect.authorizer_len = 0;
769 /* Can't hold the mutex while getting authorizer */
771 mutex_unlock(&con->mutex);
773 auth = con->ops->get_authorizer(con, auth_proto, con->auth_retry);
775 mutex_lock(&con->mutex);
779 if (test_bit(CLOSED, &con->state) || test_bit(OPENING, &con->flags))
780 return ERR_PTR(-EAGAIN);
782 con->auth_reply_buf = auth->authorizer_reply_buf;
783 con->auth_reply_buf_len = auth->authorizer_reply_buf_len;
790 * We connected to a peer and are saying hello.
792 static void prepare_write_banner(struct ceph_connection *con)
794 con_out_kvec_add(con, strlen(CEPH_BANNER), CEPH_BANNER);
795 con_out_kvec_add(con, sizeof (con->msgr->my_enc_addr),
796 &con->msgr->my_enc_addr);
799 set_bit(WRITE_PENDING, &con->flags);
802 static int prepare_write_connect(struct ceph_connection *con)
804 unsigned int global_seq = get_global_seq(con->msgr, 0);
807 struct ceph_auth_handshake *auth;
809 switch (con->peer_name.type) {
810 case CEPH_ENTITY_TYPE_MON:
811 proto = CEPH_MONC_PROTOCOL;
813 case CEPH_ENTITY_TYPE_OSD:
814 proto = CEPH_OSDC_PROTOCOL;
816 case CEPH_ENTITY_TYPE_MDS:
817 proto = CEPH_MDSC_PROTOCOL;
823 dout("prepare_write_connect %p cseq=%d gseq=%d proto=%d\n", con,
824 con->connect_seq, global_seq, proto);
826 con->out_connect.features = cpu_to_le64(con->msgr->supported_features);
827 con->out_connect.host_type = cpu_to_le32(CEPH_ENTITY_TYPE_CLIENT);
828 con->out_connect.connect_seq = cpu_to_le32(con->connect_seq);
829 con->out_connect.global_seq = cpu_to_le32(global_seq);
830 con->out_connect.protocol_version = cpu_to_le32(proto);
831 con->out_connect.flags = 0;
833 auth_proto = CEPH_AUTH_UNKNOWN;
834 auth = get_connect_authorizer(con, &auth_proto);
836 return PTR_ERR(auth);
838 con->out_connect.authorizer_protocol = cpu_to_le32(auth_proto);
839 con->out_connect.authorizer_len = auth ?
840 cpu_to_le32(auth->authorizer_buf_len) : 0;
842 con_out_kvec_add(con, sizeof (con->out_connect),
844 if (auth && auth->authorizer_buf_len)
845 con_out_kvec_add(con, auth->authorizer_buf_len,
846 auth->authorizer_buf);
849 set_bit(WRITE_PENDING, &con->flags);
855 * write as much of pending kvecs to the socket as we can.
857 * 0 -> socket full, but more to do
860 static int write_partial_kvec(struct ceph_connection *con)
864 dout("write_partial_kvec %p %d left\n", con, con->out_kvec_bytes);
865 while (con->out_kvec_bytes > 0) {
866 ret = ceph_tcp_sendmsg(con->sock, con->out_kvec_cur,
867 con->out_kvec_left, con->out_kvec_bytes,
871 con->out_kvec_bytes -= ret;
872 if (con->out_kvec_bytes == 0)
875 /* account for full iov entries consumed */
876 while (ret >= con->out_kvec_cur->iov_len) {
877 BUG_ON(!con->out_kvec_left);
878 ret -= con->out_kvec_cur->iov_len;
880 con->out_kvec_left--;
882 /* and for a partially-consumed entry */
884 con->out_kvec_cur->iov_len -= ret;
885 con->out_kvec_cur->iov_base += ret;
888 con->out_kvec_left = 0;
889 con->out_kvec_is_msg = false;
892 dout("write_partial_kvec %p %d left in %d kvecs ret = %d\n", con,
893 con->out_kvec_bytes, con->out_kvec_left, ret);
894 return ret; /* done! */
897 static void out_msg_pos_next(struct ceph_connection *con, struct page *page,
898 size_t len, size_t sent, bool in_trail)
900 struct ceph_msg *msg = con->out_msg;
905 con->out_msg_pos.data_pos += sent;
906 con->out_msg_pos.page_pos += sent;
908 con->out_msg_pos.page_pos = 0;
909 con->out_msg_pos.page++;
910 con->out_msg_pos.did_page_crc = false;
912 list_move_tail(&page->lru,
914 else if (msg->pagelist)
915 list_move_tail(&page->lru,
916 &msg->pagelist->head);
919 iter_bio_next(&msg->bio_iter, &msg->bio_seg);
925 * Write as much message data payload as we can. If we finish, queue
927 * 1 -> done, footer is now queued in out_kvec[].
928 * 0 -> socket full, but more to do
931 static int write_partial_msg_pages(struct ceph_connection *con)
933 struct ceph_msg *msg = con->out_msg;
934 unsigned int data_len = le32_to_cpu(msg->hdr.data_len);
936 bool do_datacrc = !con->msgr->nocrc;
939 bool in_trail = false;
940 size_t trail_len = (msg->trail ? msg->trail->length : 0);
942 dout("write_partial_msg_pages %p msg %p page %d/%d offset %d\n",
943 con, msg, con->out_msg_pos.page, msg->nr_pages,
944 con->out_msg_pos.page_pos);
946 while (data_len > con->out_msg_pos.data_pos) {
947 struct page *page = NULL;
948 int max_write = PAGE_SIZE;
951 total_max_write = data_len - trail_len -
952 con->out_msg_pos.data_pos;
955 * if we are calculating the data crc (the default), we need
956 * to map the page. if our pages[] has been revoked, use the
960 /* have we reached the trail part of the data? */
961 if (con->out_msg_pos.data_pos >= data_len - trail_len) {
964 total_max_write = data_len - con->out_msg_pos.data_pos;
966 page = list_first_entry(&msg->trail->head,
968 } else if (msg->pages) {
969 page = msg->pages[con->out_msg_pos.page];
970 } else if (msg->pagelist) {
971 page = list_first_entry(&msg->pagelist->head,
974 } else if (msg->bio) {
977 bv = bio_iovec_idx(msg->bio_iter, msg->bio_seg);
979 bio_offset = bv->bv_offset;
980 max_write = bv->bv_len;
985 len = min_t(int, max_write - con->out_msg_pos.page_pos,
988 if (do_datacrc && !con->out_msg_pos.did_page_crc) {
991 u32 tmpcrc = le32_to_cpu(msg->footer.data_crc);
995 BUG_ON(kaddr == NULL);
996 base = kaddr + con->out_msg_pos.page_pos + bio_offset;
997 crc = crc32c(tmpcrc, base, len);
998 msg->footer.data_crc = cpu_to_le32(crc);
999 con->out_msg_pos.did_page_crc = true;
1001 ret = ceph_tcp_sendpage(con->sock, page,
1002 con->out_msg_pos.page_pos + bio_offset,
1011 out_msg_pos_next(con, page, len, (size_t) ret, in_trail);
1014 dout("write_partial_msg_pages %p msg %p done\n", con, msg);
1016 /* prepare and queue up footer, too */
1018 msg->footer.flags |= CEPH_MSG_FOOTER_NOCRC;
1019 con_out_kvec_reset(con);
1020 prepare_write_message_footer(con);
1029 static int write_partial_skip(struct ceph_connection *con)
1033 while (con->out_skip > 0) {
1034 size_t size = min(con->out_skip, (int) PAGE_CACHE_SIZE);
1036 ret = ceph_tcp_sendpage(con->sock, zero_page, 0, size, 1);
1039 con->out_skip -= ret;
1047 * Prepare to read connection handshake, or an ack.
1049 static void prepare_read_banner(struct ceph_connection *con)
1051 dout("prepare_read_banner %p\n", con);
1052 con->in_base_pos = 0;
1055 static void prepare_read_connect(struct ceph_connection *con)
1057 dout("prepare_read_connect %p\n", con);
1058 con->in_base_pos = 0;
1061 static void prepare_read_ack(struct ceph_connection *con)
1063 dout("prepare_read_ack %p\n", con);
1064 con->in_base_pos = 0;
1067 static void prepare_read_tag(struct ceph_connection *con)
1069 dout("prepare_read_tag %p\n", con);
1070 con->in_base_pos = 0;
1071 con->in_tag = CEPH_MSGR_TAG_READY;
1075 * Prepare to read a message.
1077 static int prepare_read_message(struct ceph_connection *con)
1079 dout("prepare_read_message %p\n", con);
1080 BUG_ON(con->in_msg != NULL);
1081 con->in_base_pos = 0;
1082 con->in_front_crc = con->in_middle_crc = con->in_data_crc = 0;
1087 static int read_partial(struct ceph_connection *con,
1088 int end, int size, void *object)
1090 while (con->in_base_pos < end) {
1091 int left = end - con->in_base_pos;
1092 int have = size - left;
1093 int ret = ceph_tcp_recvmsg(con->sock, object + have, left);
1096 con->in_base_pos += ret;
1103 * Read all or part of the connect-side handshake on a new connection
1105 static int read_partial_banner(struct ceph_connection *con)
1111 dout("read_partial_banner %p at %d\n", con, con->in_base_pos);
1114 size = strlen(CEPH_BANNER);
1116 ret = read_partial(con, end, size, con->in_banner);
1120 size = sizeof (con->actual_peer_addr);
1122 ret = read_partial(con, end, size, &con->actual_peer_addr);
1126 size = sizeof (con->peer_addr_for_me);
1128 ret = read_partial(con, end, size, &con->peer_addr_for_me);
1136 static int read_partial_connect(struct ceph_connection *con)
1142 dout("read_partial_connect %p at %d\n", con, con->in_base_pos);
1144 size = sizeof (con->in_reply);
1146 ret = read_partial(con, end, size, &con->in_reply);
1150 size = le32_to_cpu(con->in_reply.authorizer_len);
1152 ret = read_partial(con, end, size, con->auth_reply_buf);
1156 dout("read_partial_connect %p tag %d, con_seq = %u, g_seq = %u\n",
1157 con, (int)con->in_reply.tag,
1158 le32_to_cpu(con->in_reply.connect_seq),
1159 le32_to_cpu(con->in_reply.global_seq));
1166 * Verify the hello banner looks okay.
1168 static int verify_hello(struct ceph_connection *con)
1170 if (memcmp(con->in_banner, CEPH_BANNER, strlen(CEPH_BANNER))) {
1171 pr_err("connect to %s got bad banner\n",
1172 ceph_pr_addr(&con->peer_addr.in_addr));
1173 con->error_msg = "protocol error, bad banner";
1179 static bool addr_is_blank(struct sockaddr_storage *ss)
1181 switch (ss->ss_family) {
1183 return ((struct sockaddr_in *)ss)->sin_addr.s_addr == 0;
1186 ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[0] == 0 &&
1187 ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[1] == 0 &&
1188 ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[2] == 0 &&
1189 ((struct sockaddr_in6 *)ss)->sin6_addr.s6_addr32[3] == 0;
1194 static int addr_port(struct sockaddr_storage *ss)
1196 switch (ss->ss_family) {
1198 return ntohs(((struct sockaddr_in *)ss)->sin_port);
1200 return ntohs(((struct sockaddr_in6 *)ss)->sin6_port);
1205 static void addr_set_port(struct sockaddr_storage *ss, int p)
1207 switch (ss->ss_family) {
1209 ((struct sockaddr_in *)ss)->sin_port = htons(p);
1212 ((struct sockaddr_in6 *)ss)->sin6_port = htons(p);
1218 * Unlike other *_pton function semantics, zero indicates success.
1220 static int ceph_pton(const char *str, size_t len, struct sockaddr_storage *ss,
1221 char delim, const char **ipend)
1223 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
1224 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
1226 memset(ss, 0, sizeof(*ss));
1228 if (in4_pton(str, len, (u8 *)&in4->sin_addr.s_addr, delim, ipend)) {
1229 ss->ss_family = AF_INET;
1233 if (in6_pton(str, len, (u8 *)&in6->sin6_addr.s6_addr, delim, ipend)) {
1234 ss->ss_family = AF_INET6;
1242 * Extract hostname string and resolve using kernel DNS facility.
1244 #ifdef CONFIG_CEPH_LIB_USE_DNS_RESOLVER
1245 static int ceph_dns_resolve_name(const char *name, size_t namelen,
1246 struct sockaddr_storage *ss, char delim, const char **ipend)
1248 const char *end, *delim_p;
1249 char *colon_p, *ip_addr = NULL;
1253 * The end of the hostname occurs immediately preceding the delimiter or
1254 * the port marker (':') where the delimiter takes precedence.
1256 delim_p = memchr(name, delim, namelen);
1257 colon_p = memchr(name, ':', namelen);
1259 if (delim_p && colon_p)
1260 end = delim_p < colon_p ? delim_p : colon_p;
1261 else if (!delim_p && colon_p)
1265 if (!end) /* case: hostname:/ */
1266 end = name + namelen;
1272 /* do dns_resolve upcall */
1273 ip_len = dns_query(NULL, name, end - name, NULL, &ip_addr, NULL);
1275 ret = ceph_pton(ip_addr, ip_len, ss, -1, NULL);
1283 pr_info("resolve '%.*s' (ret=%d): %s\n", (int)(end - name), name,
1284 ret, ret ? "failed" : ceph_pr_addr(ss));
1289 static inline int ceph_dns_resolve_name(const char *name, size_t namelen,
1290 struct sockaddr_storage *ss, char delim, const char **ipend)
1297 * Parse a server name (IP or hostname). If a valid IP address is not found
1298 * then try to extract a hostname to resolve using userspace DNS upcall.
1300 static int ceph_parse_server_name(const char *name, size_t namelen,
1301 struct sockaddr_storage *ss, char delim, const char **ipend)
1305 ret = ceph_pton(name, namelen, ss, delim, ipend);
1307 ret = ceph_dns_resolve_name(name, namelen, ss, delim, ipend);
1313 * Parse an ip[:port] list into an addr array. Use the default
1314 * monitor port if a port isn't specified.
1316 int ceph_parse_ips(const char *c, const char *end,
1317 struct ceph_entity_addr *addr,
1318 int max_count, int *count)
1320 int i, ret = -EINVAL;
1323 dout("parse_ips on '%.*s'\n", (int)(end-c), c);
1324 for (i = 0; i < max_count; i++) {
1326 struct sockaddr_storage *ss = &addr[i].in_addr;
1335 ret = ceph_parse_server_name(p, end - p, ss, delim, &ipend);
1344 dout("missing matching ']'\n");
1351 if (p < end && *p == ':') {
1354 while (p < end && *p >= '0' && *p <= '9') {
1355 port = (port * 10) + (*p - '0');
1358 if (port > 65535 || port == 0)
1361 port = CEPH_MON_PORT;
1364 addr_set_port(ss, port);
1366 dout("parse_ips got %s\n", ceph_pr_addr(ss));
1383 pr_err("parse_ips bad ip '%.*s'\n", (int)(end - c), c);
1386 EXPORT_SYMBOL(ceph_parse_ips);
1388 static int process_banner(struct ceph_connection *con)
1390 dout("process_banner on %p\n", con);
1392 if (verify_hello(con) < 0)
1395 ceph_decode_addr(&con->actual_peer_addr);
1396 ceph_decode_addr(&con->peer_addr_for_me);
1399 * Make sure the other end is who we wanted. note that the other
1400 * end may not yet know their ip address, so if it's 0.0.0.0, give
1401 * them the benefit of the doubt.
1403 if (memcmp(&con->peer_addr, &con->actual_peer_addr,
1404 sizeof(con->peer_addr)) != 0 &&
1405 !(addr_is_blank(&con->actual_peer_addr.in_addr) &&
1406 con->actual_peer_addr.nonce == con->peer_addr.nonce)) {
1407 pr_warning("wrong peer, want %s/%d, got %s/%d\n",
1408 ceph_pr_addr(&con->peer_addr.in_addr),
1409 (int)le32_to_cpu(con->peer_addr.nonce),
1410 ceph_pr_addr(&con->actual_peer_addr.in_addr),
1411 (int)le32_to_cpu(con->actual_peer_addr.nonce));
1412 con->error_msg = "wrong peer at address";
1417 * did we learn our address?
1419 if (addr_is_blank(&con->msgr->inst.addr.in_addr)) {
1420 int port = addr_port(&con->msgr->inst.addr.in_addr);
1422 memcpy(&con->msgr->inst.addr.in_addr,
1423 &con->peer_addr_for_me.in_addr,
1424 sizeof(con->peer_addr_for_me.in_addr));
1425 addr_set_port(&con->msgr->inst.addr.in_addr, port);
1426 encode_my_addr(con->msgr);
1427 dout("process_banner learned my addr is %s\n",
1428 ceph_pr_addr(&con->msgr->inst.addr.in_addr));
1431 set_bit(NEGOTIATING, &con->state);
1432 prepare_read_connect(con);
1436 static void fail_protocol(struct ceph_connection *con)
1438 reset_connection(con);
1439 set_bit(CLOSED, &con->state); /* in case there's queued work */
1442 static int process_connect(struct ceph_connection *con)
1444 u64 sup_feat = con->msgr->supported_features;
1445 u64 req_feat = con->msgr->required_features;
1446 u64 server_feat = le64_to_cpu(con->in_reply.features);
1449 dout("process_connect on %p tag %d\n", con, (int)con->in_tag);
1451 switch (con->in_reply.tag) {
1452 case CEPH_MSGR_TAG_FEATURES:
1453 pr_err("%s%lld %s feature set mismatch,"
1454 " my %llx < server's %llx, missing %llx\n",
1455 ENTITY_NAME(con->peer_name),
1456 ceph_pr_addr(&con->peer_addr.in_addr),
1457 sup_feat, server_feat, server_feat & ~sup_feat);
1458 con->error_msg = "missing required protocol features";
1462 case CEPH_MSGR_TAG_BADPROTOVER:
1463 pr_err("%s%lld %s protocol version mismatch,"
1464 " my %d != server's %d\n",
1465 ENTITY_NAME(con->peer_name),
1466 ceph_pr_addr(&con->peer_addr.in_addr),
1467 le32_to_cpu(con->out_connect.protocol_version),
1468 le32_to_cpu(con->in_reply.protocol_version));
1469 con->error_msg = "protocol version mismatch";
1473 case CEPH_MSGR_TAG_BADAUTHORIZER:
1475 dout("process_connect %p got BADAUTHORIZER attempt %d\n", con,
1477 if (con->auth_retry == 2) {
1478 con->error_msg = "connect authorization failure";
1481 con->auth_retry = 1;
1482 con_out_kvec_reset(con);
1483 ret = prepare_write_connect(con);
1486 prepare_read_connect(con);
1489 case CEPH_MSGR_TAG_RESETSESSION:
1491 * If we connected with a large connect_seq but the peer
1492 * has no record of a session with us (no connection, or
1493 * connect_seq == 0), they will send RESETSESION to indicate
1494 * that they must have reset their session, and may have
1497 dout("process_connect got RESET peer seq %u\n",
1498 le32_to_cpu(con->in_connect.connect_seq));
1499 pr_err("%s%lld %s connection reset\n",
1500 ENTITY_NAME(con->peer_name),
1501 ceph_pr_addr(&con->peer_addr.in_addr));
1502 reset_connection(con);
1503 con_out_kvec_reset(con);
1504 ret = prepare_write_connect(con);
1507 prepare_read_connect(con);
1509 /* Tell ceph about it. */
1510 mutex_unlock(&con->mutex);
1511 pr_info("reset on %s%lld\n", ENTITY_NAME(con->peer_name));
1512 if (con->ops->peer_reset)
1513 con->ops->peer_reset(con);
1514 mutex_lock(&con->mutex);
1515 if (test_bit(CLOSED, &con->state) ||
1516 test_bit(OPENING, &con->state))
1520 case CEPH_MSGR_TAG_RETRY_SESSION:
1522 * If we sent a smaller connect_seq than the peer has, try
1523 * again with a larger value.
1525 dout("process_connect got RETRY my seq = %u, peer_seq = %u\n",
1526 le32_to_cpu(con->out_connect.connect_seq),
1527 le32_to_cpu(con->in_connect.connect_seq));
1528 con->connect_seq = le32_to_cpu(con->in_connect.connect_seq);
1529 con_out_kvec_reset(con);
1530 ret = prepare_write_connect(con);
1533 prepare_read_connect(con);
1536 case CEPH_MSGR_TAG_RETRY_GLOBAL:
1538 * If we sent a smaller global_seq than the peer has, try
1539 * again with a larger value.
1541 dout("process_connect got RETRY_GLOBAL my %u peer_gseq %u\n",
1542 con->peer_global_seq,
1543 le32_to_cpu(con->in_connect.global_seq));
1544 get_global_seq(con->msgr,
1545 le32_to_cpu(con->in_connect.global_seq));
1546 con_out_kvec_reset(con);
1547 ret = prepare_write_connect(con);
1550 prepare_read_connect(con);
1553 case CEPH_MSGR_TAG_READY:
1554 if (req_feat & ~server_feat) {
1555 pr_err("%s%lld %s protocol feature mismatch,"
1556 " my required %llx > server's %llx, need %llx\n",
1557 ENTITY_NAME(con->peer_name),
1558 ceph_pr_addr(&con->peer_addr.in_addr),
1559 req_feat, server_feat, req_feat & ~server_feat);
1560 con->error_msg = "missing required protocol features";
1564 clear_bit(CONNECTING, &con->state);
1565 con->peer_global_seq = le32_to_cpu(con->in_reply.global_seq);
1567 con->peer_features = server_feat;
1568 dout("process_connect got READY gseq %d cseq %d (%d)\n",
1569 con->peer_global_seq,
1570 le32_to_cpu(con->in_reply.connect_seq),
1572 WARN_ON(con->connect_seq !=
1573 le32_to_cpu(con->in_reply.connect_seq));
1575 if (con->in_reply.flags & CEPH_MSG_CONNECT_LOSSY)
1576 set_bit(LOSSYTX, &con->flags);
1578 prepare_read_tag(con);
1581 case CEPH_MSGR_TAG_WAIT:
1583 * If there is a connection race (we are opening
1584 * connections to each other), one of us may just have
1585 * to WAIT. This shouldn't happen if we are the
1588 pr_err("process_connect got WAIT as client\n");
1589 con->error_msg = "protocol error, got WAIT as client";
1593 pr_err("connect protocol error, will retry\n");
1594 con->error_msg = "protocol error, garbage tag during connect";
1602 * read (part of) an ack
1604 static int read_partial_ack(struct ceph_connection *con)
1606 int size = sizeof (con->in_temp_ack);
1609 return read_partial(con, end, size, &con->in_temp_ack);
1614 * We can finally discard anything that's been acked.
1616 static void process_ack(struct ceph_connection *con)
1619 u64 ack = le64_to_cpu(con->in_temp_ack);
1622 while (!list_empty(&con->out_sent)) {
1623 m = list_first_entry(&con->out_sent, struct ceph_msg,
1625 seq = le64_to_cpu(m->hdr.seq);
1628 dout("got ack for seq %llu type %d at %p\n", seq,
1629 le16_to_cpu(m->hdr.type), m);
1630 m->ack_stamp = jiffies;
1633 prepare_read_tag(con);
1639 static int read_partial_message_section(struct ceph_connection *con,
1640 struct kvec *section,
1641 unsigned int sec_len, u32 *crc)
1647 while (section->iov_len < sec_len) {
1648 BUG_ON(section->iov_base == NULL);
1649 left = sec_len - section->iov_len;
1650 ret = ceph_tcp_recvmsg(con->sock, (char *)section->iov_base +
1651 section->iov_len, left);
1654 section->iov_len += ret;
1656 if (section->iov_len == sec_len)
1657 *crc = crc32c(0, section->iov_base, section->iov_len);
1662 static bool ceph_con_in_msg_alloc(struct ceph_connection *con,
1663 struct ceph_msg_header *hdr);
1666 static int read_partial_message_pages(struct ceph_connection *con,
1667 struct page **pages,
1668 unsigned int data_len, bool do_datacrc)
1674 left = min((int)(data_len - con->in_msg_pos.data_pos),
1675 (int)(PAGE_SIZE - con->in_msg_pos.page_pos));
1677 BUG_ON(pages == NULL);
1678 p = kmap(pages[con->in_msg_pos.page]);
1679 ret = ceph_tcp_recvmsg(con->sock, p + con->in_msg_pos.page_pos,
1681 if (ret > 0 && do_datacrc)
1683 crc32c(con->in_data_crc,
1684 p + con->in_msg_pos.page_pos, ret);
1685 kunmap(pages[con->in_msg_pos.page]);
1688 con->in_msg_pos.data_pos += ret;
1689 con->in_msg_pos.page_pos += ret;
1690 if (con->in_msg_pos.page_pos == PAGE_SIZE) {
1691 con->in_msg_pos.page_pos = 0;
1692 con->in_msg_pos.page++;
1699 static int read_partial_message_bio(struct ceph_connection *con,
1700 struct bio **bio_iter, int *bio_seg,
1701 unsigned int data_len, bool do_datacrc)
1703 struct bio_vec *bv = bio_iovec_idx(*bio_iter, *bio_seg);
1710 left = min((int)(data_len - con->in_msg_pos.data_pos),
1711 (int)(bv->bv_len - con->in_msg_pos.page_pos));
1713 p = kmap(bv->bv_page) + bv->bv_offset;
1715 ret = ceph_tcp_recvmsg(con->sock, p + con->in_msg_pos.page_pos,
1717 if (ret > 0 && do_datacrc)
1719 crc32c(con->in_data_crc,
1720 p + con->in_msg_pos.page_pos, ret);
1721 kunmap(bv->bv_page);
1724 con->in_msg_pos.data_pos += ret;
1725 con->in_msg_pos.page_pos += ret;
1726 if (con->in_msg_pos.page_pos == bv->bv_len) {
1727 con->in_msg_pos.page_pos = 0;
1728 iter_bio_next(bio_iter, bio_seg);
1736 * read (part of) a message.
1738 static int read_partial_message(struct ceph_connection *con)
1740 struct ceph_msg *m = con->in_msg;
1744 unsigned int front_len, middle_len, data_len;
1745 bool do_datacrc = !con->msgr->nocrc;
1749 dout("read_partial_message con %p msg %p\n", con, m);
1752 size = sizeof (con->in_hdr);
1754 ret = read_partial(con, end, size, &con->in_hdr);
1758 crc = crc32c(0, &con->in_hdr, offsetof(struct ceph_msg_header, crc));
1759 if (cpu_to_le32(crc) != con->in_hdr.crc) {
1760 pr_err("read_partial_message bad hdr "
1761 " crc %u != expected %u\n",
1762 crc, con->in_hdr.crc);
1766 front_len = le32_to_cpu(con->in_hdr.front_len);
1767 if (front_len > CEPH_MSG_MAX_FRONT_LEN)
1769 middle_len = le32_to_cpu(con->in_hdr.middle_len);
1770 if (middle_len > CEPH_MSG_MAX_DATA_LEN)
1772 data_len = le32_to_cpu(con->in_hdr.data_len);
1773 if (data_len > CEPH_MSG_MAX_DATA_LEN)
1777 seq = le64_to_cpu(con->in_hdr.seq);
1778 if ((s64)seq - (s64)con->in_seq < 1) {
1779 pr_info("skipping %s%lld %s seq %lld expected %lld\n",
1780 ENTITY_NAME(con->peer_name),
1781 ceph_pr_addr(&con->peer_addr.in_addr),
1782 seq, con->in_seq + 1);
1783 con->in_base_pos = -front_len - middle_len - data_len -
1785 con->in_tag = CEPH_MSGR_TAG_READY;
1787 } else if ((s64)seq - (s64)con->in_seq > 1) {
1788 pr_err("read_partial_message bad seq %lld expected %lld\n",
1789 seq, con->in_seq + 1);
1790 con->error_msg = "bad message sequence # for incoming message";
1794 /* allocate message? */
1796 dout("got hdr type %d front %d data %d\n", con->in_hdr.type,
1797 con->in_hdr.front_len, con->in_hdr.data_len);
1798 if (ceph_con_in_msg_alloc(con, &con->in_hdr)) {
1799 /* skip this message */
1800 dout("alloc_msg said skip message\n");
1801 BUG_ON(con->in_msg);
1802 con->in_base_pos = -front_len - middle_len - data_len -
1804 con->in_tag = CEPH_MSGR_TAG_READY;
1810 "error allocating memory for incoming message";
1814 BUG_ON(con->in_msg->con != con);
1816 m->front.iov_len = 0; /* haven't read it yet */
1818 m->middle->vec.iov_len = 0;
1820 con->in_msg_pos.page = 0;
1822 con->in_msg_pos.page_pos = m->page_alignment;
1824 con->in_msg_pos.page_pos = 0;
1825 con->in_msg_pos.data_pos = 0;
1829 ret = read_partial_message_section(con, &m->front, front_len,
1830 &con->in_front_crc);
1836 ret = read_partial_message_section(con, &m->middle->vec,
1838 &con->in_middle_crc);
1843 if (m->bio && !m->bio_iter)
1844 init_bio_iter(m->bio, &m->bio_iter, &m->bio_seg);
1848 while (con->in_msg_pos.data_pos < data_len) {
1850 ret = read_partial_message_pages(con, m->pages,
1851 data_len, do_datacrc);
1855 } else if (m->bio) {
1857 ret = read_partial_message_bio(con,
1858 &m->bio_iter, &m->bio_seg,
1859 data_len, do_datacrc);
1869 size = sizeof (m->footer);
1871 ret = read_partial(con, end, size, &m->footer);
1875 dout("read_partial_message got msg %p %d (%u) + %d (%u) + %d (%u)\n",
1876 m, front_len, m->footer.front_crc, middle_len,
1877 m->footer.middle_crc, data_len, m->footer.data_crc);
1880 if (con->in_front_crc != le32_to_cpu(m->footer.front_crc)) {
1881 pr_err("read_partial_message %p front crc %u != exp. %u\n",
1882 m, con->in_front_crc, m->footer.front_crc);
1885 if (con->in_middle_crc != le32_to_cpu(m->footer.middle_crc)) {
1886 pr_err("read_partial_message %p middle crc %u != exp %u\n",
1887 m, con->in_middle_crc, m->footer.middle_crc);
1891 (m->footer.flags & CEPH_MSG_FOOTER_NOCRC) == 0 &&
1892 con->in_data_crc != le32_to_cpu(m->footer.data_crc)) {
1893 pr_err("read_partial_message %p data crc %u != exp. %u\n", m,
1894 con->in_data_crc, le32_to_cpu(m->footer.data_crc));
1898 return 1; /* done! */
1902 * Process message. This happens in the worker thread. The callback should
1903 * be careful not to do anything that waits on other incoming messages or it
1906 static void process_message(struct ceph_connection *con)
1908 struct ceph_msg *msg;
1910 BUG_ON(con->in_msg->con != con);
1911 con->in_msg->con = NULL;
1916 /* if first message, set peer_name */
1917 if (con->peer_name.type == 0)
1918 con->peer_name = msg->hdr.src;
1921 mutex_unlock(&con->mutex);
1923 dout("===== %p %llu from %s%lld %d=%s len %d+%d (%u %u %u) =====\n",
1924 msg, le64_to_cpu(msg->hdr.seq),
1925 ENTITY_NAME(msg->hdr.src),
1926 le16_to_cpu(msg->hdr.type),
1927 ceph_msg_type_name(le16_to_cpu(msg->hdr.type)),
1928 le32_to_cpu(msg->hdr.front_len),
1929 le32_to_cpu(msg->hdr.data_len),
1930 con->in_front_crc, con->in_middle_crc, con->in_data_crc);
1931 con->ops->dispatch(con, msg);
1933 mutex_lock(&con->mutex);
1934 prepare_read_tag(con);
1939 * Write something to the socket. Called in a worker thread when the
1940 * socket appears to be writeable and we have something ready to send.
1942 static int try_write(struct ceph_connection *con)
1946 dout("try_write start %p state %lu\n", con, con->state);
1949 dout("try_write out_kvec_bytes %d\n", con->out_kvec_bytes);
1951 /* open the socket first? */
1952 if (con->sock == NULL) {
1953 clear_bit(NEGOTIATING, &con->state);
1954 set_bit(CONNECTING, &con->state);
1956 con_out_kvec_reset(con);
1957 prepare_write_banner(con);
1958 ret = prepare_write_connect(con);
1961 prepare_read_banner(con);
1963 BUG_ON(con->in_msg);
1964 con->in_tag = CEPH_MSGR_TAG_READY;
1965 dout("try_write initiating connect on %p new state %lu\n",
1967 ret = ceph_tcp_connect(con);
1969 con->error_msg = "connect error";
1975 /* kvec data queued? */
1976 if (con->out_skip) {
1977 ret = write_partial_skip(con);
1981 if (con->out_kvec_left) {
1982 ret = write_partial_kvec(con);
1989 if (con->out_msg_done) {
1990 ceph_msg_put(con->out_msg);
1991 con->out_msg = NULL; /* we're done with this one */
1995 ret = write_partial_msg_pages(con);
1997 goto more_kvec; /* we need to send the footer, too! */
2001 dout("try_write write_partial_msg_pages err %d\n",
2008 if (!test_bit(CONNECTING, &con->state)) {
2009 /* is anything else pending? */
2010 if (!list_empty(&con->out_queue)) {
2011 prepare_write_message(con);
2014 if (con->in_seq > con->in_seq_acked) {
2015 prepare_write_ack(con);
2018 if (test_and_clear_bit(KEEPALIVE_PENDING, &con->flags)) {
2019 prepare_write_keepalive(con);
2024 /* Nothing to do! */
2025 clear_bit(WRITE_PENDING, &con->flags);
2026 dout("try_write nothing else to write.\n");
2029 dout("try_write done on %p ret %d\n", con, ret);
2036 * Read what we can from the socket.
2038 static int try_read(struct ceph_connection *con)
2045 if (test_bit(STANDBY, &con->state))
2048 dout("try_read start on %p\n", con);
2051 dout("try_read tag %d in_base_pos %d\n", (int)con->in_tag,
2055 * process_connect and process_message drop and re-take
2056 * con->mutex. make sure we handle a racing close or reopen.
2058 if (test_bit(CLOSED, &con->state) ||
2059 test_bit(OPENING, &con->state)) {
2064 if (test_bit(CONNECTING, &con->state)) {
2065 if (!test_bit(NEGOTIATING, &con->state)) {
2066 dout("try_read connecting\n");
2067 ret = read_partial_banner(con);
2070 ret = process_banner(con);
2074 ret = read_partial_connect(con);
2077 ret = process_connect(con);
2083 if (con->in_base_pos < 0) {
2085 * skipping + discarding content.
2087 * FIXME: there must be a better way to do this!
2089 static char buf[SKIP_BUF_SIZE];
2090 int skip = min((int) sizeof (buf), -con->in_base_pos);
2092 dout("skipping %d / %d bytes\n", skip, -con->in_base_pos);
2093 ret = ceph_tcp_recvmsg(con->sock, buf, skip);
2096 con->in_base_pos += ret;
2097 if (con->in_base_pos)
2100 if (con->in_tag == CEPH_MSGR_TAG_READY) {
2104 ret = ceph_tcp_recvmsg(con->sock, &con->in_tag, 1);
2107 dout("try_read got tag %d\n", (int)con->in_tag);
2108 switch (con->in_tag) {
2109 case CEPH_MSGR_TAG_MSG:
2110 prepare_read_message(con);
2112 case CEPH_MSGR_TAG_ACK:
2113 prepare_read_ack(con);
2115 case CEPH_MSGR_TAG_CLOSE:
2116 set_bit(CLOSED, &con->state); /* fixme */
2122 if (con->in_tag == CEPH_MSGR_TAG_MSG) {
2123 ret = read_partial_message(con);
2127 con->error_msg = "bad crc";
2131 con->error_msg = "io error";
2136 if (con->in_tag == CEPH_MSGR_TAG_READY)
2138 process_message(con);
2141 if (con->in_tag == CEPH_MSGR_TAG_ACK) {
2142 ret = read_partial_ack(con);
2150 dout("try_read done on %p ret %d\n", con, ret);
2154 pr_err("try_read bad con->in_tag = %d\n", (int)con->in_tag);
2155 con->error_msg = "protocol error, garbage tag";
2162 * Atomically queue work on a connection. Bump @con reference to
2163 * avoid races with connection teardown.
2165 static void queue_con(struct ceph_connection *con)
2167 if (!con->ops->get(con)) {
2168 dout("queue_con %p ref count 0\n", con);
2172 if (!queue_delayed_work(ceph_msgr_wq, &con->work, 0)) {
2173 dout("queue_con %p - already queued\n", con);
2176 dout("queue_con %p\n", con);
2181 * Do some work on a connection. Drop a connection ref when we're done.
2183 static void con_work(struct work_struct *work)
2185 struct ceph_connection *con = container_of(work, struct ceph_connection,
2189 mutex_lock(&con->mutex);
2191 if (test_and_clear_bit(SOCK_CLOSED, &con->flags)) {
2192 if (test_bit(CONNECTING, &con->state))
2193 con->error_msg = "connection failed";
2195 con->error_msg = "socket closed";
2199 if (test_and_clear_bit(BACKOFF, &con->flags)) {
2200 dout("con_work %p backing off\n", con);
2201 if (queue_delayed_work(ceph_msgr_wq, &con->work,
2202 round_jiffies_relative(con->delay))) {
2203 dout("con_work %p backoff %lu\n", con, con->delay);
2204 mutex_unlock(&con->mutex);
2208 dout("con_work %p FAILED to back off %lu\n", con,
2213 if (test_bit(STANDBY, &con->state)) {
2214 dout("con_work %p STANDBY\n", con);
2217 if (test_bit(CLOSED, &con->state)) { /* e.g. if we are replaced */
2218 dout("con_work CLOSED\n");
2219 con_close_socket(con);
2222 if (test_and_clear_bit(OPENING, &con->state)) {
2223 /* reopen w/ new peer */
2224 dout("con_work OPENING\n");
2225 con_close_socket(con);
2228 ret = try_read(con);
2234 ret = try_write(con);
2241 mutex_unlock(&con->mutex);
2247 mutex_unlock(&con->mutex);
2248 ceph_fault(con); /* error/fault path */
2254 * Generic error/fault handler. A retry mechanism is used with
2255 * exponential backoff
2257 static void ceph_fault(struct ceph_connection *con)
2259 pr_err("%s%lld %s %s\n", ENTITY_NAME(con->peer_name),
2260 ceph_pr_addr(&con->peer_addr.in_addr), con->error_msg);
2261 dout("fault %p state %lu to peer %s\n",
2262 con, con->state, ceph_pr_addr(&con->peer_addr.in_addr));
2264 if (test_bit(LOSSYTX, &con->flags)) {
2265 dout("fault on LOSSYTX channel\n");
2269 mutex_lock(&con->mutex);
2270 if (test_bit(CLOSED, &con->state))
2273 con_close_socket(con);
2276 BUG_ON(con->in_msg->con != con);
2277 con->in_msg->con = NULL;
2278 ceph_msg_put(con->in_msg);
2283 /* Requeue anything that hasn't been acked */
2284 list_splice_init(&con->out_sent, &con->out_queue);
2286 /* If there are no messages queued or keepalive pending, place
2287 * the connection in a STANDBY state */
2288 if (list_empty(&con->out_queue) &&
2289 !test_bit(KEEPALIVE_PENDING, &con->flags)) {
2290 dout("fault %p setting STANDBY clearing WRITE_PENDING\n", con);
2291 clear_bit(WRITE_PENDING, &con->flags);
2292 set_bit(STANDBY, &con->state);
2294 /* retry after a delay. */
2295 if (con->delay == 0)
2296 con->delay = BASE_DELAY_INTERVAL;
2297 else if (con->delay < MAX_DELAY_INTERVAL)
2300 if (queue_delayed_work(ceph_msgr_wq, &con->work,
2301 round_jiffies_relative(con->delay))) {
2302 dout("fault queued %p delay %lu\n", con, con->delay);
2305 dout("fault failed to queue %p delay %lu, backoff\n",
2308 * In many cases we see a socket state change
2309 * while con_work is running and end up
2310 * queuing (non-delayed) work, such that we
2311 * can't backoff with a delay. Set a flag so
2312 * that when con_work restarts we schedule the
2315 set_bit(BACKOFF, &con->flags);
2320 mutex_unlock(&con->mutex);
2323 * in case we faulted due to authentication, invalidate our
2324 * current tickets so that we can get new ones.
2326 if (con->auth_retry && con->ops->invalidate_authorizer) {
2327 dout("calling invalidate_authorizer()\n");
2328 con->ops->invalidate_authorizer(con);
2331 if (con->ops->fault)
2332 con->ops->fault(con);
2338 * initialize a new messenger instance
2340 void ceph_messenger_init(struct ceph_messenger *msgr,
2341 struct ceph_entity_addr *myaddr,
2342 u32 supported_features,
2343 u32 required_features,
2346 msgr->supported_features = supported_features;
2347 msgr->required_features = required_features;
2349 spin_lock_init(&msgr->global_seq_lock);
2352 msgr->inst.addr = *myaddr;
2354 /* select a random nonce */
2355 msgr->inst.addr.type = 0;
2356 get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce));
2357 encode_my_addr(msgr);
2358 msgr->nocrc = nocrc;
2360 dout("%s %p\n", __func__, msgr);
2362 EXPORT_SYMBOL(ceph_messenger_init);
2364 static void clear_standby(struct ceph_connection *con)
2366 /* come back from STANDBY? */
2367 if (test_and_clear_bit(STANDBY, &con->state)) {
2368 mutex_lock(&con->mutex);
2369 dout("clear_standby %p and ++connect_seq\n", con);
2371 WARN_ON(test_bit(WRITE_PENDING, &con->flags));
2372 WARN_ON(test_bit(KEEPALIVE_PENDING, &con->flags));
2373 mutex_unlock(&con->mutex);
2378 * Queue up an outgoing message on the given connection.
2380 void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg)
2382 if (test_bit(CLOSED, &con->state)) {
2383 dout("con_send %p closed, dropping %p\n", con, msg);
2389 msg->hdr.src = con->msgr->inst.name;
2391 BUG_ON(msg->front.iov_len != le32_to_cpu(msg->hdr.front_len));
2393 msg->needs_out_seq = true;
2396 mutex_lock(&con->mutex);
2398 BUG_ON(msg->con != NULL);
2399 msg->con = con->ops->get(con);
2400 BUG_ON(msg->con == NULL);
2402 BUG_ON(!list_empty(&msg->list_head));
2403 list_add_tail(&msg->list_head, &con->out_queue);
2404 dout("----- %p to %s%lld %d=%s len %d+%d+%d -----\n", msg,
2405 ENTITY_NAME(con->peer_name), le16_to_cpu(msg->hdr.type),
2406 ceph_msg_type_name(le16_to_cpu(msg->hdr.type)),
2407 le32_to_cpu(msg->hdr.front_len),
2408 le32_to_cpu(msg->hdr.middle_len),
2409 le32_to_cpu(msg->hdr.data_len));
2410 mutex_unlock(&con->mutex);
2412 /* if there wasn't anything waiting to send before, queue
2415 if (test_and_set_bit(WRITE_PENDING, &con->flags) == 0)
2418 EXPORT_SYMBOL(ceph_con_send);
2421 * Revoke a message that was previously queued for send
2423 void ceph_msg_revoke(struct ceph_msg *msg)
2425 struct ceph_connection *con = msg->con;
2428 return; /* Message not in our possession */
2430 mutex_lock(&con->mutex);
2431 if (!list_empty(&msg->list_head)) {
2432 dout("%s %p msg %p - was on queue\n", __func__, con, msg);
2433 list_del_init(&msg->list_head);
2434 BUG_ON(msg->con == NULL);
2435 msg->con->ops->put(msg->con);
2441 if (con->out_msg == msg) {
2442 dout("%s %p msg %p - was sending\n", __func__, con, msg);
2443 con->out_msg = NULL;
2444 if (con->out_kvec_is_msg) {
2445 con->out_skip = con->out_kvec_bytes;
2446 con->out_kvec_is_msg = false;
2452 mutex_unlock(&con->mutex);
2456 * Revoke a message that we may be reading data into
2458 void ceph_msg_revoke_incoming(struct ceph_msg *msg)
2460 struct ceph_connection *con;
2462 BUG_ON(msg == NULL);
2464 dout("%s msg %p null con\n", __func__, msg);
2466 return; /* Message not in our possession */
2470 mutex_lock(&con->mutex);
2471 if (con->in_msg == msg) {
2472 unsigned int front_len = le32_to_cpu(con->in_hdr.front_len);
2473 unsigned int middle_len = le32_to_cpu(con->in_hdr.middle_len);
2474 unsigned int data_len = le32_to_cpu(con->in_hdr.data_len);
2476 /* skip rest of message */
2477 dout("%s %p msg %p revoked\n", __func__, con, msg);
2478 con->in_base_pos = con->in_base_pos -
2479 sizeof(struct ceph_msg_header) -
2483 sizeof(struct ceph_msg_footer);
2484 ceph_msg_put(con->in_msg);
2486 con->in_tag = CEPH_MSGR_TAG_READY;
2489 dout("%s %p in_msg %p msg %p no-op\n",
2490 __func__, con, con->in_msg, msg);
2492 mutex_unlock(&con->mutex);
2496 * Queue a keepalive byte to ensure the tcp connection is alive.
2498 void ceph_con_keepalive(struct ceph_connection *con)
2500 dout("con_keepalive %p\n", con);
2502 if (test_and_set_bit(KEEPALIVE_PENDING, &con->flags) == 0 &&
2503 test_and_set_bit(WRITE_PENDING, &con->flags) == 0)
2506 EXPORT_SYMBOL(ceph_con_keepalive);
2510 * construct a new message with given type, size
2511 * the new msg has a ref count of 1.
2513 struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
2518 m = kmalloc(sizeof(*m), flags);
2521 kref_init(&m->kref);
2524 INIT_LIST_HEAD(&m->list_head);
2527 m->hdr.type = cpu_to_le16(type);
2528 m->hdr.priority = cpu_to_le16(CEPH_MSG_PRIO_DEFAULT);
2530 m->hdr.front_len = cpu_to_le32(front_len);
2531 m->hdr.middle_len = 0;
2532 m->hdr.data_len = 0;
2533 m->hdr.data_off = 0;
2534 m->hdr.reserved = 0;
2535 m->footer.front_crc = 0;
2536 m->footer.middle_crc = 0;
2537 m->footer.data_crc = 0;
2538 m->footer.flags = 0;
2539 m->front_max = front_len;
2540 m->front_is_vmalloc = false;
2541 m->more_to_follow = false;
2550 m->page_alignment = 0;
2560 if (front_len > PAGE_CACHE_SIZE) {
2561 m->front.iov_base = __vmalloc(front_len, flags,
2563 m->front_is_vmalloc = true;
2565 m->front.iov_base = kmalloc(front_len, flags);
2567 if (m->front.iov_base == NULL) {
2568 dout("ceph_msg_new can't allocate %d bytes\n",
2573 m->front.iov_base = NULL;
2575 m->front.iov_len = front_len;
2577 dout("ceph_msg_new %p front %d\n", m, front_len);
2584 pr_err("msg_new can't create type %d front %d\n", type,
2588 dout("msg_new can't create type %d front %d\n", type,
2593 EXPORT_SYMBOL(ceph_msg_new);
2596 * Allocate "middle" portion of a message, if it is needed and wasn't
2597 * allocated by alloc_msg. This allows us to read a small fixed-size
2598 * per-type header in the front and then gracefully fail (i.e.,
2599 * propagate the error to the caller based on info in the front) when
2600 * the middle is too large.
2602 static int ceph_alloc_middle(struct ceph_connection *con, struct ceph_msg *msg)
2604 int type = le16_to_cpu(msg->hdr.type);
2605 int middle_len = le32_to_cpu(msg->hdr.middle_len);
2607 dout("alloc_middle %p type %d %s middle_len %d\n", msg, type,
2608 ceph_msg_type_name(type), middle_len);
2609 BUG_ON(!middle_len);
2610 BUG_ON(msg->middle);
2612 msg->middle = ceph_buffer_new(middle_len, GFP_NOFS);
2619 * Allocate a message for receiving an incoming message on a
2620 * connection, and save the result in con->in_msg. Uses the
2621 * connection's private alloc_msg op if available.
2623 * Returns true if the message should be skipped, false otherwise.
2624 * If true is returned (skip message), con->in_msg will be NULL.
2625 * If false is returned, con->in_msg will contain a pointer to the
2626 * newly-allocated message, or NULL in case of memory exhaustion.
2628 static bool ceph_con_in_msg_alloc(struct ceph_connection *con,
2629 struct ceph_msg_header *hdr)
2631 int type = le16_to_cpu(hdr->type);
2632 int front_len = le32_to_cpu(hdr->front_len);
2633 int middle_len = le32_to_cpu(hdr->middle_len);
2636 BUG_ON(con->in_msg != NULL);
2638 if (con->ops->alloc_msg) {
2641 mutex_unlock(&con->mutex);
2642 con->in_msg = con->ops->alloc_msg(con, hdr, &skip);
2643 mutex_lock(&con->mutex);
2645 con->in_msg->con = con->ops->get(con);
2646 BUG_ON(con->in_msg->con == NULL);
2655 con->in_msg = ceph_msg_new(type, front_len, GFP_NOFS, false);
2657 pr_err("unable to allocate msg type %d len %d\n",
2661 con->in_msg->con = con->ops->get(con);
2662 BUG_ON(con->in_msg->con == NULL);
2663 con->in_msg->page_alignment = le16_to_cpu(hdr->data_off);
2665 memcpy(&con->in_msg->hdr, &con->in_hdr, sizeof(con->in_hdr));
2667 if (middle_len && !con->in_msg->middle) {
2668 ret = ceph_alloc_middle(con, con->in_msg);
2670 ceph_msg_put(con->in_msg);
2680 * Free a generically kmalloc'd message.
2682 void ceph_msg_kfree(struct ceph_msg *m)
2684 dout("msg_kfree %p\n", m);
2685 if (m->front_is_vmalloc)
2686 vfree(m->front.iov_base);
2688 kfree(m->front.iov_base);
2693 * Drop a msg ref. Destroy as needed.
2695 void ceph_msg_last_put(struct kref *kref)
2697 struct ceph_msg *m = container_of(kref, struct ceph_msg, kref);
2699 dout("ceph_msg_put last one on %p\n", m);
2700 WARN_ON(!list_empty(&m->list_head));
2702 /* drop middle, data, if any */
2704 ceph_buffer_put(m->middle);
2711 ceph_pagelist_release(m->pagelist);
2719 ceph_msgpool_put(m->pool, m);
2723 EXPORT_SYMBOL(ceph_msg_last_put);
2725 void ceph_msg_dump(struct ceph_msg *msg)
2727 pr_debug("msg_dump %p (front_max %d nr_pages %d)\n", msg,
2728 msg->front_max, msg->nr_pages);
2729 print_hex_dump(KERN_DEBUG, "header: ",
2730 DUMP_PREFIX_OFFSET, 16, 1,
2731 &msg->hdr, sizeof(msg->hdr), true);
2732 print_hex_dump(KERN_DEBUG, " front: ",
2733 DUMP_PREFIX_OFFSET, 16, 1,
2734 msg->front.iov_base, msg->front.iov_len, true);
2736 print_hex_dump(KERN_DEBUG, "middle: ",
2737 DUMP_PREFIX_OFFSET, 16, 1,
2738 msg->middle->vec.iov_base,
2739 msg->middle->vec.iov_len, true);
2740 print_hex_dump(KERN_DEBUG, "footer: ",
2741 DUMP_PREFIX_OFFSET, 16, 1,
2742 &msg->footer, sizeof(msg->footer), true);
2744 EXPORT_SYMBOL(ceph_msg_dump);