diff options
author | Alex Elder <elder@inktank.com> | 2012-06-11 15:57:13 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-07-06 00:14:12 -0400 |
commit | 84ca8fc87fcf4ab97bb8acdb59bf97bb4820cb14 (patch) | |
tree | e1d859e4e6742cb872b06d323a909f648af62c7f /net | |
parent | 739c905baa018c99003564ebc367d93aa44d4861 (diff) |
libceph: encapsulate advancing msg page
In write_partial_msg_pages(), once all the data from a page has been
sent we advance to the next one. Put the code that takes care of
this into its own function.
While modifying write_partial_msg_pages(), make its local variable
"in_trail" be Boolean, and use the local variable "msg" (which is
just the connection's current out_msg pointer) consistently.
Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/ceph/messenger.c | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 56448660883d..1b92e3b16c0d 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c | |||
@@ -891,6 +891,33 @@ static void iter_bio_next(struct bio **bio_iter, int *seg) | |||
891 | } | 891 | } |
892 | #endif | 892 | #endif |
893 | 893 | ||
894 | static void out_msg_pos_next(struct ceph_connection *con, struct page *page, | ||
895 | size_t len, size_t sent, bool in_trail) | ||
896 | { | ||
897 | struct ceph_msg *msg = con->out_msg; | ||
898 | |||
899 | BUG_ON(!msg); | ||
900 | BUG_ON(!sent); | ||
901 | |||
902 | con->out_msg_pos.data_pos += sent; | ||
903 | con->out_msg_pos.page_pos += sent; | ||
904 | if (sent == len) { | ||
905 | con->out_msg_pos.page_pos = 0; | ||
906 | con->out_msg_pos.page++; | ||
907 | con->out_msg_pos.did_page_crc = false; | ||
908 | if (in_trail) | ||
909 | list_move_tail(&page->lru, | ||
910 | &msg->trail->head); | ||
911 | else if (msg->pagelist) | ||
912 | list_move_tail(&page->lru, | ||
913 | &msg->pagelist->head); | ||
914 | #ifdef CONFIG_BLOCK | ||
915 | else if (msg->bio) | ||
916 | iter_bio_next(&msg->bio_iter, &msg->bio_seg); | ||
917 | #endif | ||
918 | } | ||
919 | } | ||
920 | |||
894 | /* | 921 | /* |
895 | * Write as much message data payload as we can. If we finish, queue | 922 | * Write as much message data payload as we can. If we finish, queue |
896 | * up the footer. | 923 | * up the footer. |
@@ -906,11 +933,11 @@ static int write_partial_msg_pages(struct ceph_connection *con) | |||
906 | bool do_datacrc = !con->msgr->nocrc; | 933 | bool do_datacrc = !con->msgr->nocrc; |
907 | int ret; | 934 | int ret; |
908 | int total_max_write; | 935 | int total_max_write; |
909 | int in_trail = 0; | 936 | bool in_trail = false; |
910 | size_t trail_len = (msg->trail ? msg->trail->length : 0); | 937 | size_t trail_len = (msg->trail ? msg->trail->length : 0); |
911 | 938 | ||
912 | dout("write_partial_msg_pages %p msg %p page %d/%d offset %d\n", | 939 | dout("write_partial_msg_pages %p msg %p page %d/%d offset %d\n", |
913 | con, con->out_msg, con->out_msg_pos.page, con->out_msg->nr_pages, | 940 | con, msg, con->out_msg_pos.page, msg->nr_pages, |
914 | con->out_msg_pos.page_pos); | 941 | con->out_msg_pos.page_pos); |
915 | 942 | ||
916 | #ifdef CONFIG_BLOCK | 943 | #ifdef CONFIG_BLOCK |
@@ -934,13 +961,12 @@ static int write_partial_msg_pages(struct ceph_connection *con) | |||
934 | 961 | ||
935 | /* have we reached the trail part of the data? */ | 962 | /* have we reached the trail part of the data? */ |
936 | if (con->out_msg_pos.data_pos >= data_len - trail_len) { | 963 | if (con->out_msg_pos.data_pos >= data_len - trail_len) { |
937 | in_trail = 1; | 964 | in_trail = true; |
938 | 965 | ||
939 | total_max_write = data_len - con->out_msg_pos.data_pos; | 966 | total_max_write = data_len - con->out_msg_pos.data_pos; |
940 | 967 | ||
941 | page = list_first_entry(&msg->trail->head, | 968 | page = list_first_entry(&msg->trail->head, |
942 | struct page, lru); | 969 | struct page, lru); |
943 | max_write = PAGE_SIZE; | ||
944 | } else if (msg->pages) { | 970 | } else if (msg->pages) { |
945 | page = msg->pages[con->out_msg_pos.page]; | 971 | page = msg->pages[con->out_msg_pos.page]; |
946 | } else if (msg->pagelist) { | 972 | } else if (msg->pagelist) { |
@@ -964,14 +990,14 @@ static int write_partial_msg_pages(struct ceph_connection *con) | |||
964 | if (do_datacrc && !con->out_msg_pos.did_page_crc) { | 990 | if (do_datacrc && !con->out_msg_pos.did_page_crc) { |
965 | void *base; | 991 | void *base; |
966 | u32 crc; | 992 | u32 crc; |
967 | u32 tmpcrc = le32_to_cpu(con->out_msg->footer.data_crc); | 993 | u32 tmpcrc = le32_to_cpu(msg->footer.data_crc); |
968 | char *kaddr; | 994 | char *kaddr; |
969 | 995 | ||
970 | kaddr = kmap(page); | 996 | kaddr = kmap(page); |
971 | BUG_ON(kaddr == NULL); | 997 | BUG_ON(kaddr == NULL); |
972 | base = kaddr + con->out_msg_pos.page_pos + bio_offset; | 998 | base = kaddr + con->out_msg_pos.page_pos + bio_offset; |
973 | crc = crc32c(tmpcrc, base, len); | 999 | crc = crc32c(tmpcrc, base, len); |
974 | con->out_msg->footer.data_crc = cpu_to_le32(crc); | 1000 | msg->footer.data_crc = cpu_to_le32(crc); |
975 | con->out_msg_pos.did_page_crc = true; | 1001 | con->out_msg_pos.did_page_crc = true; |
976 | } | 1002 | } |
977 | ret = ceph_tcp_sendpage(con->sock, page, | 1003 | ret = ceph_tcp_sendpage(con->sock, page, |
@@ -984,30 +1010,14 @@ static int write_partial_msg_pages(struct ceph_connection *con) | |||
984 | if (ret <= 0) | 1010 | if (ret <= 0) |
985 | goto out; | 1011 | goto out; |
986 | 1012 | ||
987 | con->out_msg_pos.data_pos += ret; | 1013 | out_msg_pos_next(con, page, len, (size_t) ret, in_trail); |
988 | con->out_msg_pos.page_pos += ret; | ||
989 | if (ret == len) { | ||
990 | con->out_msg_pos.page_pos = 0; | ||
991 | con->out_msg_pos.page++; | ||
992 | con->out_msg_pos.did_page_crc = false; | ||
993 | if (in_trail) | ||
994 | list_move_tail(&page->lru, | ||
995 | &msg->trail->head); | ||
996 | else if (msg->pagelist) | ||
997 | list_move_tail(&page->lru, | ||
998 | &msg->pagelist->head); | ||
999 | #ifdef CONFIG_BLOCK | ||
1000 | else if (msg->bio) | ||
1001 | iter_bio_next(&msg->bio_iter, &msg->bio_seg); | ||
1002 | #endif | ||
1003 | } | ||
1004 | } | 1014 | } |
1005 | 1015 | ||
1006 | dout("write_partial_msg_pages %p msg %p done\n", con, msg); | 1016 | dout("write_partial_msg_pages %p msg %p done\n", con, msg); |
1007 | 1017 | ||
1008 | /* prepare and queue up footer, too */ | 1018 | /* prepare and queue up footer, too */ |
1009 | if (!do_datacrc) | 1019 | if (!do_datacrc) |
1010 | con->out_msg->footer.flags |= CEPH_MSG_FOOTER_NOCRC; | 1020 | msg->footer.flags |= CEPH_MSG_FOOTER_NOCRC; |
1011 | con_out_kvec_reset(con); | 1021 | con_out_kvec_reset(con); |
1012 | prepare_write_message_footer(con); | 1022 | prepare_write_message_footer(con); |
1013 | ret = 1; | 1023 | ret = 1; |