aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-06-11 15:57:13 -0400
committerSage Weil <sage@inktank.com>2012-07-06 00:14:31 -0400
commit5821bd8ccdf5d17ab2c391c773756538603838c3 (patch)
tree7aa1a214e9bbc59ad96f71921ce7febc2bcc579d /net
parent7593af920baac37752190a0db703d2732bed4a3b (diff)
libceph: small changes to messenger.c
This patch gathers a few small changes in "net/ceph/messenger.c": out_msg_pos_next() - small logic change that mostly affects indentation write_partial_msg_pages(). - use a local variable trail_off to represent the offset into a message of the trail portion of the data (if present) - once we are in the trail portion we will always be there, so we don't always need to check against our data position - avoid computing len twice after we've reached the trail - get rid of the variable tmpcrc, which is not needed - trail_off and trail_len never change so mark them const - update some comments read_partial_message_bio() - bio_iovec_idx() will never return an error, so don't bother checking for it 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.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 32a3a2a72580..4578e99bbef1 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -907,21 +907,23 @@ static void out_msg_pos_next(struct ceph_connection *con, struct page *page,
907 907
908 con->out_msg_pos.data_pos += sent; 908 con->out_msg_pos.data_pos += sent;
909 con->out_msg_pos.page_pos += sent; 909 con->out_msg_pos.page_pos += sent;
910 if (sent == len) { 910 if (sent < len)
911 con->out_msg_pos.page_pos = 0; 911 return;
912 con->out_msg_pos.page++; 912
913 con->out_msg_pos.did_page_crc = false; 913 BUG_ON(sent != len);
914 if (in_trail) 914 con->out_msg_pos.page_pos = 0;
915 list_move_tail(&page->lru, 915 con->out_msg_pos.page++;
916 &msg->trail->head); 916 con->out_msg_pos.did_page_crc = false;
917 else if (msg->pagelist) 917 if (in_trail)
918 list_move_tail(&page->lru, 918 list_move_tail(&page->lru,
919 &msg->pagelist->head); 919 &msg->trail->head);
920 else if (msg->pagelist)
921 list_move_tail(&page->lru,
922 &msg->pagelist->head);
920#ifdef CONFIG_BLOCK 923#ifdef CONFIG_BLOCK
921 else if (msg->bio) 924 else if (msg->bio)
922 iter_bio_next(&msg->bio_iter, &msg->bio_seg); 925 iter_bio_next(&msg->bio_iter, &msg->bio_seg);
923#endif 926#endif
924 }
925} 927}
926 928
927/* 929/*
@@ -940,30 +942,31 @@ static int write_partial_msg_pages(struct ceph_connection *con)
940 int ret; 942 int ret;
941 int total_max_write; 943 int total_max_write;
942 bool in_trail = false; 944 bool in_trail = false;
943 size_t trail_len = (msg->trail ? msg->trail->length : 0); 945 const size_t trail_len = (msg->trail ? msg->trail->length : 0);
946 const size_t trail_off = data_len - trail_len;
944 947
945 dout("write_partial_msg_pages %p msg %p page %d/%d offset %d\n", 948 dout("write_partial_msg_pages %p msg %p page %d/%d offset %d\n",
946 con, msg, con->out_msg_pos.page, msg->nr_pages, 949 con, msg, con->out_msg_pos.page, msg->nr_pages,
947 con->out_msg_pos.page_pos); 950 con->out_msg_pos.page_pos);
948 951
952 /*
953 * Iterate through each page that contains data to be
954 * written, and send as much as possible for each.
955 *
956 * If we are calculating the data crc (the default), we will
957 * need to map the page. If we have no pages, they have
958 * been revoked, so use the zero page.
959 */
949 while (data_len > con->out_msg_pos.data_pos) { 960 while (data_len > con->out_msg_pos.data_pos) {
950 struct page *page = NULL; 961 struct page *page = NULL;
951 int max_write = PAGE_SIZE; 962 int max_write = PAGE_SIZE;
952 int bio_offset = 0; 963 int bio_offset = 0;
953 964
954 total_max_write = data_len - trail_len - 965 in_trail = in_trail || con->out_msg_pos.data_pos >= trail_off;
955 con->out_msg_pos.data_pos; 966 if (!in_trail)
956 967 total_max_write = trail_off - con->out_msg_pos.data_pos;
957 /*
958 * if we are calculating the data crc (the default), we need
959 * to map the page. if our pages[] has been revoked, use the
960 * zero page.
961 */
962
963 /* have we reached the trail part of the data? */
964 if (con->out_msg_pos.data_pos >= data_len - trail_len) {
965 in_trail = true;
966 968
969 if (in_trail) {
967 total_max_write = data_len - con->out_msg_pos.data_pos; 970 total_max_write = data_len - con->out_msg_pos.data_pos;
968 971
969 page = list_first_entry(&msg->trail->head, 972 page = list_first_entry(&msg->trail->head,
@@ -990,14 +993,13 @@ static int write_partial_msg_pages(struct ceph_connection *con)
990 993
991 if (do_datacrc && !con->out_msg_pos.did_page_crc) { 994 if (do_datacrc && !con->out_msg_pos.did_page_crc) {
992 void *base; 995 void *base;
993 u32 crc; 996 u32 crc = le32_to_cpu(msg->footer.data_crc);
994 u32 tmpcrc = le32_to_cpu(msg->footer.data_crc);
995 char *kaddr; 997 char *kaddr;
996 998
997 kaddr = kmap(page); 999 kaddr = kmap(page);
998 BUG_ON(kaddr == NULL); 1000 BUG_ON(kaddr == NULL);
999 base = kaddr + con->out_msg_pos.page_pos + bio_offset; 1001 base = kaddr + con->out_msg_pos.page_pos + bio_offset;
1000 crc = crc32c(tmpcrc, base, len); 1002 crc = crc32c(crc, base, len);
1001 msg->footer.data_crc = cpu_to_le32(crc); 1003 msg->footer.data_crc = cpu_to_le32(crc);
1002 con->out_msg_pos.did_page_crc = true; 1004 con->out_msg_pos.did_page_crc = true;
1003 } 1005 }
@@ -1702,9 +1704,6 @@ static int read_partial_message_bio(struct ceph_connection *con,
1702 void *p; 1704 void *p;
1703 int ret, left; 1705 int ret, left;
1704 1706
1705 if (IS_ERR(bv))
1706 return PTR_ERR(bv);
1707
1708 left = min((int)(data_len - con->in_msg_pos.data_pos), 1707 left = min((int)(data_len - con->in_msg_pos.data_pos),
1709 (int)(bv->bv_len - con->in_msg_pos.page_pos)); 1708 (int)(bv->bv_len - con->in_msg_pos.page_pos));
1710 1709