Lines Matching refs:con

110 static void con_out_kvec_reset(struct ceph_connection *con)
112 BUG_ON(con->v1.out_skip);
114 con->v1.out_kvec_left = 0;
115 con->v1.out_kvec_bytes = 0;
116 con->v1.out_kvec_cur = &con->v1.out_kvec[0];
119 static void con_out_kvec_add(struct ceph_connection *con,
122 int index = con->v1.out_kvec_left;
124 BUG_ON(con->v1.out_skip);
125 BUG_ON(index >= ARRAY_SIZE(con->v1.out_kvec));
127 con->v1.out_kvec[index].iov_len = size;
128 con->v1.out_kvec[index].iov_base = data;
129 con->v1.out_kvec_left++;
130 con->v1.out_kvec_bytes += size;
138 static int con_out_kvec_skip(struct ceph_connection *con)
142 if (con->v1.out_kvec_bytes > 0) {
143 skip = con->v1.out_kvec_cur[con->v1.out_kvec_left - 1].iov_len;
144 BUG_ON(con->v1.out_kvec_bytes < skip);
145 BUG_ON(!con->v1.out_kvec_left);
146 con->v1.out_kvec_bytes -= skip;
147 con->v1.out_kvec_left--;
153 static size_t sizeof_footer(struct ceph_connection *con)
155 return (con->peer_features & CEPH_FEATURE_MSG_AUTH) ?
172 static void prepare_write_message_footer(struct ceph_connection *con)
174 struct ceph_msg *m = con->out_msg;
178 dout("prepare_write_message_footer %p\n", con);
179 con_out_kvec_add(con, sizeof_footer(con), &m->footer);
180 if (con->peer_features & CEPH_FEATURE_MSG_AUTH) {
181 if (con->ops->sign_message)
182 con->ops->sign_message(m);
188 con->v1.out_more = m->more_to_follow;
189 con->v1.out_msg_done = true;
195 static void prepare_write_message(struct ceph_connection *con)
200 con_out_kvec_reset(con);
201 con->v1.out_msg_done = false;
205 if (con->in_seq > con->in_seq_acked) {
206 con->in_seq_acked = con->in_seq;
207 con_out_kvec_add(con, sizeof (tag_ack), &tag_ack);
208 con->v1.out_temp_ack = cpu_to_le64(con->in_seq_acked);
209 con_out_kvec_add(con, sizeof(con->v1.out_temp_ack),
210 &con->v1.out_temp_ack);
213 ceph_con_get_out_msg(con);
214 m = con->out_msg;
217 m, con->out_seq, le16_to_cpu(m->hdr.type),
224 con_out_kvec_add(con, sizeof (tag_msg), &tag_msg);
225 con_out_kvec_add(con, sizeof(con->v1.out_hdr), &con->v1.out_hdr);
226 con_out_kvec_add(con, m->front.iov_len, m->front.iov_base);
229 con_out_kvec_add(con, m->middle->vec.iov_len,
234 con->out_msg->hdr.crc = cpu_to_le32(crc);
235 memcpy(&con->v1.out_hdr, &con->out_msg->hdr, sizeof(con->v1.out_hdr));
239 con->out_msg->footer.front_crc = cpu_to_le32(crc);
243 con->out_msg->footer.middle_crc = cpu_to_le32(crc);
245 con->out_msg->footer.middle_crc = 0;
247 le32_to_cpu(con->out_msg->footer.front_crc),
248 le32_to_cpu(con->out_msg->footer.middle_crc));
249 con->out_msg->footer.flags = 0;
252 con->out_msg->footer.data_crc = 0;
254 prepare_message_data(con->out_msg, m->data_length);
255 con->v1.out_more = 1; /* data + footer will follow */
258 prepare_write_message_footer(con);
261 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING);
267 static void prepare_write_ack(struct ceph_connection *con)
269 dout("prepare_write_ack %p %llu -> %llu\n", con,
270 con->in_seq_acked, con->in_seq);
271 con->in_seq_acked = con->in_seq;
273 con_out_kvec_reset(con);
275 con_out_kvec_add(con, sizeof (tag_ack), &tag_ack);
277 con->v1.out_temp_ack = cpu_to_le64(con->in_seq_acked);
278 con_out_kvec_add(con, sizeof(con->v1.out_temp_ack),
279 &con->v1.out_temp_ack);
281 con->v1.out_more = 1; /* more will follow.. eventually.. */
282 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING);
288 static void prepare_write_seq(struct ceph_connection *con)
290 dout("prepare_write_seq %p %llu -> %llu\n", con,
291 con->in_seq_acked, con->in_seq);
292 con->in_seq_acked = con->in_seq;
294 con_out_kvec_reset(con);
296 con->v1.out_temp_ack = cpu_to_le64(con->in_seq_acked);
297 con_out_kvec_add(con, sizeof(con->v1.out_temp_ack),
298 &con->v1.out_temp_ack);
300 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING);
306 static void prepare_write_keepalive(struct ceph_connection *con)
308 dout("prepare_write_keepalive %p\n", con);
309 con_out_kvec_reset(con);
310 if (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2) {
314 con_out_kvec_add(con, sizeof(tag_keepalive2), &tag_keepalive2);
315 ceph_encode_timespec64(&con->v1.out_temp_keepalive2, &now);
316 con_out_kvec_add(con, sizeof(con->v1.out_temp_keepalive2),
317 &con->v1.out_temp_keepalive2);
319 con_out_kvec_add(con, sizeof(tag_keepalive), &tag_keepalive);
321 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING);
328 static int get_connect_authorizer(struct ceph_connection *con)
333 if (!con->ops->get_authorizer) {
334 con->v1.auth = NULL;
335 con->v1.out_connect.authorizer_protocol = CEPH_AUTH_UNKNOWN;
336 con->v1.out_connect.authorizer_len = 0;
340 auth = con->ops->get_authorizer(con, &auth_proto, con->v1.auth_retry);
344 con->v1.auth = auth;
345 con->v1.out_connect.authorizer_protocol = cpu_to_le32(auth_proto);
346 con->v1.out_connect.authorizer_len =
354 static void prepare_write_banner(struct ceph_connection *con)
356 con_out_kvec_add(con, strlen(CEPH_BANNER), CEPH_BANNER);
357 con_out_kvec_add(con, sizeof (con->msgr->my_enc_addr),
358 &con->msgr->my_enc_addr);
360 con->v1.out_more = 0;
361 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING);
364 static void __prepare_write_connect(struct ceph_connection *con)
366 con_out_kvec_add(con, sizeof(con->v1.out_connect),
367 &con->v1.out_connect);
368 if (con->v1.auth)
369 con_out_kvec_add(con, con->v1.auth->authorizer_buf_len,
370 con->v1.auth->authorizer_buf);
372 con->v1.out_more = 0;
373 ceph_con_flag_set(con, CEPH_CON_F_WRITE_PENDING);
376 static int prepare_write_connect(struct ceph_connection *con)
378 unsigned int global_seq = ceph_get_global_seq(con->msgr, 0);
382 switch (con->peer_name.type) {
396 dout("prepare_write_connect %p cseq=%d gseq=%d proto=%d\n", con,
397 con->v1.connect_seq, global_seq, proto);
399 con->v1.out_connect.features =
400 cpu_to_le64(from_msgr(con->msgr)->supported_features);
401 con->v1.out_connect.host_type = cpu_to_le32(CEPH_ENTITY_TYPE_CLIENT);
402 con->v1.out_connect.connect_seq = cpu_to_le32(con->v1.connect_seq);
403 con->v1.out_connect.global_seq = cpu_to_le32(global_seq);
404 con->v1.out_connect.protocol_version = cpu_to_le32(proto);
405 con->v1.out_connect.flags = 0;
407 ret = get_connect_authorizer(con);
411 __prepare_write_connect(con);
421 static int write_partial_kvec(struct ceph_connection *con)
425 dout("write_partial_kvec %p %d left\n", con, con->v1.out_kvec_bytes);
426 while (con->v1.out_kvec_bytes > 0) {
427 ret = ceph_tcp_sendmsg(con->sock, con->v1.out_kvec_cur,
428 con->v1.out_kvec_left,
429 con->v1.out_kvec_bytes,
430 con->v1.out_more);
433 con->v1.out_kvec_bytes -= ret;
434 if (!con->v1.out_kvec_bytes)
438 while (ret >= con->v1.out_kvec_cur->iov_len) {
439 BUG_ON(!con->v1.out_kvec_left);
440 ret -= con->v1.out_kvec_cur->iov_len;
441 con->v1.out_kvec_cur++;
442 con->v1.out_kvec_left--;
446 con->v1.out_kvec_cur->iov_len -= ret;
447 con->v1.out_kvec_cur->iov_base += ret;
450 con->v1.out_kvec_left = 0;
453 dout("write_partial_kvec %p %d left in %d kvecs ret = %d\n", con,
454 con->v1.out_kvec_bytes, con->v1.out_kvec_left, ret);
465 static int write_partial_message_data(struct ceph_connection *con)
467 struct ceph_msg *msg = con->out_msg;
469 bool do_datacrc = !ceph_test_opt(from_msgr(con->msgr), NOCRC);
472 dout("%s %p msg %p\n", __func__, con, msg);
498 ret = ceph_tcp_sendpage(con->sock, page, page_offset, length,
511 dout("%s %p msg %p done\n", __func__, con, msg);
518 con_out_kvec_reset(con);
519 prepare_write_message_footer(con);
527 static int write_partial_skip(struct ceph_connection *con)
531 dout("%s %p %d left\n", __func__, con, con->v1.out_skip);
532 while (con->v1.out_skip > 0) {
533 size_t size = min(con->v1.out_skip, (int)PAGE_SIZE);
535 ret = ceph_tcp_sendpage(con->sock, ceph_zero_page, 0, size,
539 con->v1.out_skip -= ret;
549 static void prepare_read_banner(struct ceph_connection *con)
551 dout("prepare_read_banner %p\n", con);
552 con->v1.in_base_pos = 0;
555 static void prepare_read_connect(struct ceph_connection *con)
557 dout("prepare_read_connect %p\n", con);
558 con->v1.in_base_pos = 0;
561 static void prepare_read_ack(struct ceph_connection *con)
563 dout("prepare_read_ack %p\n", con);
564 con->v1.in_base_pos = 0;
567 static void prepare_read_seq(struct ceph_connection *con)
569 dout("prepare_read_seq %p\n", con);
570 con->v1.in_base_pos = 0;
571 con->v1.in_tag = CEPH_MSGR_TAG_SEQ;
574 static void prepare_read_tag(struct ceph_connection *con)
576 dout("prepare_read_tag %p\n", con);
577 con->v1.in_base_pos = 0;
578 con->v1.in_tag = CEPH_MSGR_TAG_READY;
581 static void prepare_read_keepalive_ack(struct ceph_connection *con)
583 dout("prepare_read_keepalive_ack %p\n", con);
584 con->v1.in_base_pos = 0;
590 static int prepare_read_message(struct ceph_connection *con)
592 dout("prepare_read_message %p\n", con);
593 BUG_ON(con->in_msg != NULL);
594 con->v1.in_base_pos = 0;
595 con->in_front_crc = con->in_middle_crc = con->in_data_crc = 0;
599 static int read_partial(struct ceph_connection *con,
602 while (con->v1.in_base_pos < end) {
603 int left = end - con->v1.in_base_pos;
605 int ret = ceph_tcp_recvmsg(con->sock, object + have, left);
608 con->v1.in_base_pos += ret;
616 static int read_partial_banner(struct ceph_connection *con)
622 dout("read_partial_banner %p at %d\n", con, con->v1.in_base_pos);
627 ret = read_partial(con, end, size, con->v1.in_banner);
631 size = sizeof(con->v1.actual_peer_addr);
633 ret = read_partial(con, end, size, &con->v1.actual_peer_addr);
636 ceph_decode_banner_addr(&con->v1.actual_peer_addr);
638 size = sizeof(con->v1.peer_addr_for_me);
640 ret = read_partial(con, end, size, &con->v1.peer_addr_for_me);
643 ceph_decode_banner_addr(&con->v1.peer_addr_for_me);
649 static int read_partial_connect(struct ceph_connection *con)
655 dout("read_partial_connect %p at %d\n", con, con->v1.in_base_pos);
657 size = sizeof(con->v1.in_reply);
659 ret = read_partial(con, end, size, &con->v1.in_reply);
663 if (con->v1.auth) {
664 size = le32_to_cpu(con->v1.in_reply.authorizer_len);
665 if (size > con->v1.auth->authorizer_reply_buf_len) {
667 con->v1.auth->authorizer_reply_buf_len);
673 ret = read_partial(con, end, size,
674 con->v1.auth->authorizer_reply_buf);
680 con, con->v1.in_reply.tag,
681 le32_to_cpu(con->v1.in_reply.connect_seq),
682 le32_to_cpu(con->v1.in_reply.global_seq));
690 static int verify_hello(struct ceph_connection *con)
692 if (memcmp(con->v1.in_banner, CEPH_BANNER, strlen(CEPH_BANNER))) {
694 ceph_pr_addr(&con->peer_addr));
695 con->error_msg = "protocol error, bad banner";
701 static int process_banner(struct ceph_connection *con)
703 struct ceph_entity_addr *my_addr = &con->msgr->inst.addr;
705 dout("process_banner on %p\n", con);
707 if (verify_hello(con) < 0)
715 if (memcmp(&con->peer_addr, &con->v1.actual_peer_addr,
716 sizeof(con->peer_addr)) != 0 &&
717 !(ceph_addr_is_blank(&con->v1.actual_peer_addr) &&
718 con->v1.actual_peer_addr.nonce == con->peer_addr.nonce)) {
720 ceph_pr_addr(&con->peer_addr),
721 le32_to_cpu(con->peer_addr.nonce),
722 ceph_pr_addr(&con->v1.actual_peer_addr),
723 le32_to_cpu(con->v1.actual_peer_addr.nonce));
724 con->error_msg = "wrong peer at address";
733 &con->v1.peer_addr_for_me.in_addr,
734 sizeof(con->v1.peer_addr_for_me.in_addr));
736 ceph_encode_my_addr(con->msgr);
744 static int process_connect(struct ceph_connection *con)
746 u64 sup_feat = from_msgr(con->msgr)->supported_features;
747 u64 req_feat = from_msgr(con->msgr)->required_features;
748 u64 server_feat = le64_to_cpu(con->v1.in_reply.features);
751 dout("process_connect on %p tag %d\n", con, con->v1.in_tag);
753 if (con->v1.auth) {
754 int len = le32_to_cpu(con->v1.in_reply.authorizer_len);
763 if (con->v1.in_reply.tag ==
765 ret = con->ops->add_authorizer_challenge(
766 con, con->v1.auth->authorizer_reply_buf, len);
770 con_out_kvec_reset(con);
771 __prepare_write_connect(con);
772 prepare_read_connect(con);
777 ret = con->ops->verify_authorizer_reply(con);
779 con->error_msg = "bad authorize reply";
785 switch (con->v1.in_reply.tag) {
789 ENTITY_NAME(con->peer_name),
790 ceph_pr_addr(&con->peer_addr),
792 con->error_msg = "missing required protocol features";
798 ENTITY_NAME(con->peer_name),
799 ceph_pr_addr(&con->peer_addr),
800 le32_to_cpu(con->v1.out_connect.protocol_version),
801 le32_to_cpu(con->v1.in_reply.protocol_version));
802 con->error_msg = "protocol version mismatch";
806 con->v1.auth_retry++;
807 dout("process_connect %p got BADAUTHORIZER attempt %d\n", con,
808 con->v1.auth_retry);
809 if (con->v1.auth_retry == 2) {
810 con->error_msg = "connect authorization failure";
813 con_out_kvec_reset(con);
814 ret = prepare_write_connect(con);
817 prepare_read_connect(con);
829 le32_to_cpu(con->v1.in_reply.connect_seq));
831 ENTITY_NAME(con->peer_name),
832 ceph_pr_addr(&con->peer_addr));
833 ceph_con_reset_session(con);
834 con_out_kvec_reset(con);
835 ret = prepare_write_connect(con);
838 prepare_read_connect(con);
841 mutex_unlock(&con->mutex);
842 if (con->ops->peer_reset)
843 con->ops->peer_reset(con);
844 mutex_lock(&con->mutex);
845 if (con->state != CEPH_CON_S_V1_CONNECT_MSG)
855 le32_to_cpu(con->v1.out_connect.connect_seq),
856 le32_to_cpu(con->v1.in_reply.connect_seq));
857 con->v1.connect_seq = le32_to_cpu(con->v1.in_reply.connect_seq);
858 con_out_kvec_reset(con);
859 ret = prepare_write_connect(con);
862 prepare_read_connect(con);
871 con->v1.peer_global_seq,
872 le32_to_cpu(con->v1.in_reply.global_seq));
873 ceph_get_global_seq(con->msgr,
874 le32_to_cpu(con->v1.in_reply.global_seq));
875 con_out_kvec_reset(con);
876 ret = prepare_write_connect(con);
879 prepare_read_connect(con);
887 ENTITY_NAME(con->peer_name),
888 ceph_pr_addr(&con->peer_addr),
890 con->error_msg = "missing required protocol features";
894 WARN_ON(con->state != CEPH_CON_S_V1_CONNECT_MSG);
895 con->state = CEPH_CON_S_OPEN;
896 con->v1.auth_retry = 0; /* we authenticated; clear flag */
897 con->v1.peer_global_seq =
898 le32_to_cpu(con->v1.in_reply.global_seq);
899 con->v1.connect_seq++;
900 con->peer_features = server_feat;
902 con->v1.peer_global_seq,
903 le32_to_cpu(con->v1.in_reply.connect_seq),
904 con->v1.connect_seq);
905 WARN_ON(con->v1.connect_seq !=
906 le32_to_cpu(con->v1.in_reply.connect_seq));
908 if (con->v1.in_reply.flags & CEPH_MSG_CONNECT_LOSSY)
909 ceph_con_flag_set(con, CEPH_CON_F_LOSSYTX);
911 con->delay = 0; /* reset backoff memory */
913 if (con->v1.in_reply.tag == CEPH_MSGR_TAG_SEQ) {
914 prepare_write_seq(con);
915 prepare_read_seq(con);
917 prepare_read_tag(con);
928 con->error_msg = "protocol error, got WAIT as client";
932 con->error_msg = "protocol error, garbage tag during connect";
941 static int read_partial_ack(struct ceph_connection *con)
943 int size = sizeof(con->v1.in_temp_ack);
946 return read_partial(con, end, size, &con->v1.in_temp_ack);
952 static void process_ack(struct ceph_connection *con)
954 u64 ack = le64_to_cpu(con->v1.in_temp_ack);
956 if (con->v1.in_tag == CEPH_MSGR_TAG_ACK)
957 ceph_con_discard_sent(con, ack);
959 ceph_con_discard_requeued(con, ack);
961 prepare_read_tag(con);
964 static int read_partial_message_chunk(struct ceph_connection *con,
975 ret = ceph_tcp_recvmsg(con->sock, (char *)section->iov_base +
987 static inline int read_partial_message_section(struct ceph_connection *con,
992 return read_partial_message_chunk(con, section, sec_len, crc);
995 static int read_partial_sparse_msg_extent(struct ceph_connection *con, u32 *crc)
997 struct ceph_msg_data_cursor *cursor = &con->in_msg->cursor;
998 bool do_bounce = ceph_test_opt(from_msgr(con->msgr), RXBOUNCE);
1000 if (do_bounce && unlikely(!con->bounce_page)) {
1001 con->bounce_page = alloc_page(GFP_NOIO);
1002 if (!con->bounce_page) {
1014 rpage = do_bounce ? con->bounce_page : page;
1018 ret = ceph_tcp_recvpage(con->sock, rpage, (int)off, len);
1030 static int read_partial_sparse_msg_data(struct ceph_connection *con)
1032 struct ceph_msg_data_cursor *cursor = &con->in_msg->cursor;
1033 bool do_datacrc = !ceph_test_opt(from_msgr(con->msgr), NOCRC);
1038 crc = con->in_data_crc;
1041 if (con->v1.in_sr_kvec.iov_base)
1042 ret = read_partial_message_chunk(con,
1043 &con->v1.in_sr_kvec,
1044 con->v1.in_sr_len,
1047 ret = read_partial_sparse_msg_extent(con, &crc);
1051 memset(&con->v1.in_sr_kvec, 0, sizeof(con->v1.in_sr_kvec));
1052 ret = con->ops->sparse_read(con, cursor,
1053 (char **)&con->v1.in_sr_kvec.iov_base);
1058 con->v1.in_sr_len = ret;
1062 con->in_data_crc = crc;
1067 static int read_partial_msg_data(struct ceph_connection *con)
1069 struct ceph_msg_data_cursor *cursor = &con->in_msg->cursor;
1070 bool do_datacrc = !ceph_test_opt(from_msgr(con->msgr), NOCRC);
1078 crc = con->in_data_crc;
1086 ret = ceph_tcp_recvpage(con->sock, page, page_offset, length);
1089 con->in_data_crc = crc;
1099 con->in_data_crc = crc;
1104 static int read_partial_msg_data_bounce(struct ceph_connection *con)
1106 struct ceph_msg_data_cursor *cursor = &con->in_msg->cursor;
1112 if (unlikely(!con->bounce_page)) {
1113 con->bounce_page = alloc_page(GFP_NOIO);
1114 if (!con->bounce_page) {
1120 crc = con->in_data_crc;
1128 ret = ceph_tcp_recvpage(con->sock, con->bounce_page, 0, len);
1130 con->in_data_crc = crc;
1134 crc = crc32c(crc, page_address(con->bounce_page), ret);
1135 memcpy_to_page(page, off, page_address(con->bounce_page), ret);
1139 con->in_data_crc = crc;
1147 static int read_partial_message(struct ceph_connection *con)
1149 struct ceph_msg *m = con->in_msg;
1154 bool do_datacrc = !ceph_test_opt(from_msgr(con->msgr), NOCRC);
1155 bool need_sign = (con->peer_features & CEPH_FEATURE_MSG_AUTH);
1159 dout("read_partial_message con %p msg %p\n", con, m);
1162 size = sizeof(con->v1.in_hdr);
1164 ret = read_partial(con, end, size, &con->v1.in_hdr);
1168 crc = crc32c(0, &con->v1.in_hdr, offsetof(struct ceph_msg_header, crc));
1169 if (cpu_to_le32(crc) != con->v1.in_hdr.crc) {
1171 crc, con->v1.in_hdr.crc);
1175 front_len = le32_to_cpu(con->v1.in_hdr.front_len);
1178 middle_len = le32_to_cpu(con->v1.in_hdr.middle_len);
1181 data_len = le32_to_cpu(con->v1.in_hdr.data_len);
1186 seq = le64_to_cpu(con->v1.in_hdr.seq);
1187 if ((s64)seq - (s64)con->in_seq < 1) {
1189 ENTITY_NAME(con->peer_name),
1190 ceph_pr_addr(&con->peer_addr),
1191 seq, con->in_seq + 1);
1192 con->v1.in_base_pos = -front_len - middle_len - data_len -
1193 sizeof_footer(con);
1194 con->v1.in_tag = CEPH_MSGR_TAG_READY;
1196 } else if ((s64)seq - (s64)con->in_seq > 1) {
1198 seq, con->in_seq + 1);
1199 con->error_msg = "bad message sequence # for incoming message";
1204 if (!con->in_msg) {
1207 dout("got hdr type %d front %d data %d\n", con->v1.in_hdr.type,
1209 ret = ceph_con_in_msg_alloc(con, &con->v1.in_hdr, &skip);
1213 BUG_ON((!con->in_msg) ^ skip);
1217 con->v1.in_base_pos = -front_len - middle_len -
1218 data_len - sizeof_footer(con);
1219 con->v1.in_tag = CEPH_MSGR_TAG_READY;
1220 con->in_seq++;
1224 BUG_ON(!con->in_msg);
1225 BUG_ON(con->in_msg->con != con);
1226 m = con->in_msg;
1234 prepare_message_data(con->in_msg, data_len);
1238 ret = read_partial_message_section(con, &m->front, front_len,
1239 &con->in_front_crc);
1245 ret = read_partial_message_section(con, &m->middle->vec,
1247 &con->in_middle_crc);
1258 ret = read_partial_sparse_msg_data(con);
1259 else if (ceph_test_opt(from_msgr(con->msgr), RXBOUNCE))
1260 ret = read_partial_msg_data_bounce(con);
1262 ret = read_partial_msg_data(con);
1268 size = sizeof_footer(con);
1270 ret = read_partial(con, end, size, &m->footer);
1284 if (con->in_front_crc != le32_to_cpu(m->footer.front_crc)) {
1286 m, con->in_front_crc, m->footer.front_crc);
1289 if (con->in_middle_crc != le32_to_cpu(m->footer.middle_crc)) {
1291 m, con->in_middle_crc, m->footer.middle_crc);
1296 con->in_data_crc != le32_to_cpu(m->footer.data_crc)) {
1298 con->in_data_crc, le32_to_cpu(m->footer.data_crc));
1302 if (need_sign && con->ops->check_message_signature &&
1303 con->ops->check_message_signature(m)) {
1311 static int read_keepalive_ack(struct ceph_connection *con)
1315 int ret = read_partial(con, size, size, &ceph_ts);
1318 ceph_decode_timespec64(&con->last_keepalive_ack, &ceph_ts);
1319 prepare_read_tag(con);
1326 int ceph_con_v1_try_read(struct ceph_connection *con)
1331 dout("try_read start %p state %d\n", con, con->state);
1332 if (con->state != CEPH_CON_S_V1_BANNER &&
1333 con->state != CEPH_CON_S_V1_CONNECT_MSG &&
1334 con->state != CEPH_CON_S_OPEN)
1337 BUG_ON(!con->sock);
1339 dout("try_read tag %d in_base_pos %d\n", con->v1.in_tag,
1340 con->v1.in_base_pos);
1342 if (con->state == CEPH_CON_S_V1_BANNER) {
1343 ret = read_partial_banner(con);
1346 ret = process_banner(con);
1350 con->state = CEPH_CON_S_V1_CONNECT_MSG;
1357 ret = prepare_write_connect(con);
1360 prepare_read_connect(con);
1366 if (con->state == CEPH_CON_S_V1_CONNECT_MSG) {
1367 ret = read_partial_connect(con);
1370 ret = process_connect(con);
1376 WARN_ON(con->state != CEPH_CON_S_OPEN);
1378 if (con->v1.in_base_pos < 0) {
1382 ret = ceph_tcp_recvmsg(con->sock, NULL, -con->v1.in_base_pos);
1385 dout("skipped %d / %d bytes\n", ret, -con->v1.in_base_pos);
1386 con->v1.in_base_pos += ret;
1387 if (con->v1.in_base_pos)
1390 if (con->v1.in_tag == CEPH_MSGR_TAG_READY) {
1394 ret = ceph_tcp_recvmsg(con->sock, &con->v1.in_tag, 1);
1397 dout("try_read got tag %d\n", con->v1.in_tag);
1398 switch (con->v1.in_tag) {
1400 prepare_read_message(con);
1403 prepare_read_ack(con);
1406 prepare_read_keepalive_ack(con);
1409 ceph_con_close_socket(con);
1410 con->state = CEPH_CON_S_CLOSED;
1416 if (con->v1.in_tag == CEPH_MSGR_TAG_MSG) {
1417 ret = read_partial_message(con);
1421 con->error_msg = "bad crc/signature";
1427 con->error_msg = "io error";
1432 if (con->v1.in_tag == CEPH_MSGR_TAG_READY)
1434 ceph_con_process_message(con);
1435 if (con->state == CEPH_CON_S_OPEN)
1436 prepare_read_tag(con);
1439 if (con->v1.in_tag == CEPH_MSGR_TAG_ACK ||
1440 con->v1.in_tag == CEPH_MSGR_TAG_SEQ) {
1445 ret = read_partial_ack(con);
1448 process_ack(con);
1451 if (con->v1.in_tag == CEPH_MSGR_TAG_KEEPALIVE2_ACK) {
1452 ret = read_keepalive_ack(con);
1459 dout("try_read done on %p ret %d\n", con, ret);
1463 pr_err("try_read bad tag %d\n", con->v1.in_tag);
1464 con->error_msg = "protocol error, garbage tag";
1473 int ceph_con_v1_try_write(struct ceph_connection *con)
1477 dout("try_write start %p state %d\n", con, con->state);
1478 if (con->state != CEPH_CON_S_PREOPEN &&
1479 con->state != CEPH_CON_S_V1_BANNER &&
1480 con->state != CEPH_CON_S_V1_CONNECT_MSG &&
1481 con->state != CEPH_CON_S_OPEN)
1485 if (con->state == CEPH_CON_S_PREOPEN) {
1486 BUG_ON(con->sock);
1487 con->state = CEPH_CON_S_V1_BANNER;
1489 con_out_kvec_reset(con);
1490 prepare_write_banner(con);
1491 prepare_read_banner(con);
1493 BUG_ON(con->in_msg);
1494 con->v1.in_tag = CEPH_MSGR_TAG_READY;
1496 con, con->state);
1497 ret = ceph_tcp_connect(con);
1499 con->error_msg = "connect error";
1505 dout("try_write out_kvec_bytes %d\n", con->v1.out_kvec_bytes);
1506 BUG_ON(!con->sock);
1509 if (con->v1.out_kvec_left) {
1510 ret = write_partial_kvec(con);
1514 if (con->v1.out_skip) {
1515 ret = write_partial_skip(con);
1521 if (con->out_msg) {
1522 if (con->v1.out_msg_done) {
1523 ceph_msg_put(con->out_msg);
1524 con->out_msg = NULL; /* we're done with this one */
1528 ret = write_partial_message_data(con);
1541 if (con->state == CEPH_CON_S_OPEN) {
1542 if (ceph_con_flag_test_and_clear(con,
1544 prepare_write_keepalive(con);
1548 if (!list_empty(&con->out_queue)) {
1549 prepare_write_message(con);
1552 if (con->in_seq > con->in_seq_acked) {
1553 prepare_write_ack(con);
1559 ceph_con_flag_clear(con, CEPH_CON_F_WRITE_PENDING);
1563 dout("try_write done on %p ret %d\n", con, ret);
1567 void ceph_con_v1_revoke(struct ceph_connection *con)
1569 struct ceph_msg *msg = con->out_msg;
1571 WARN_ON(con->v1.out_skip);
1573 if (con->v1.out_msg_done) {
1574 con->v1.out_skip += con_out_kvec_skip(con);
1577 con->v1.out_skip += sizeof_footer(con);
1581 con->v1.out_skip += msg->cursor.total_resid;
1583 con->v1.out_skip += con_out_kvec_skip(con);
1584 con->v1.out_skip += con_out_kvec_skip(con);
1586 dout("%s con %p out_kvec_bytes %d out_skip %d\n", __func__, con,
1587 con->v1.out_kvec_bytes, con->v1.out_skip);
1590 void ceph_con_v1_revoke_incoming(struct ceph_connection *con)
1592 unsigned int front_len = le32_to_cpu(con->v1.in_hdr.front_len);
1593 unsigned int middle_len = le32_to_cpu(con->v1.in_hdr.middle_len);
1594 unsigned int data_len = le32_to_cpu(con->v1.in_hdr.data_len);
1597 con->v1.in_base_pos = con->v1.in_base_pos -
1604 con->v1.in_tag = CEPH_MSGR_TAG_READY;
1605 con->in_seq++;
1607 dout("%s con %p in_base_pos %d\n", __func__, con, con->v1.in_base_pos);
1610 bool ceph_con_v1_opened(struct ceph_connection *con)
1612 return con->v1.connect_seq;
1615 void ceph_con_v1_reset_session(struct ceph_connection *con)
1617 con->v1.connect_seq = 0;
1618 con->v1.peer_global_seq = 0;
1621 void ceph_con_v1_reset_protocol(struct ceph_connection *con)
1623 con->v1.out_skip = 0;