aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-03-08 21:59:00 -0500
committerSage Weil <sage@inktank.com>2013-05-02 00:16:52 -0400
commit35b6280899424a0faf5410ce1ee86f9682528e6c (patch)
treee139fb767345c9bb09a8ea884fc7bb3303c867bc /net
parentafb3d90e205140415477d501ff9e2a33ff0b197f (diff)
libceph: define and use ceph_crc32c_page()
Factor out a common block of code that updates a CRC calculation over a range of data in a page. This and the preceding patches are related to: http://tracker.ceph.com/issues/4403 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net')
-rw-r--r--net/ceph/messenger.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 3120a6c81a76..f70bc92348d9 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1085,6 +1085,19 @@ static void in_msg_pos_next(struct ceph_connection *con, size_t len,
1085#endif /* CONFIG_BLOCK */ 1085#endif /* CONFIG_BLOCK */
1086} 1086}
1087 1087
1088static u32 ceph_crc32c_page(u32 crc, struct page *page,
1089 unsigned int page_offset,
1090 unsigned int length)
1091{
1092 char *kaddr;
1093
1094 kaddr = kmap(page);
1095 BUG_ON(kaddr == NULL);
1096 crc = crc32c(crc, kaddr + page_offset, length);
1097 kunmap(page);
1098
1099 return crc;
1100}
1088/* 1101/*
1089 * Write as much message data payload as we can. If we finish, queue 1102 * Write as much message data payload as we can. If we finish, queue
1090 * up the footer. 1103 * up the footer.
@@ -1153,15 +1166,9 @@ static int write_partial_message_data(struct ceph_connection *con)
1153 1166
1154 page_offset = msg_pos->page_pos + bio_offset; 1167 page_offset = msg_pos->page_pos + bio_offset;
1155 if (do_datacrc && !msg_pos->did_page_crc) { 1168 if (do_datacrc && !msg_pos->did_page_crc) {
1156 void *base;
1157 u32 crc = le32_to_cpu(msg->footer.data_crc); 1169 u32 crc = le32_to_cpu(msg->footer.data_crc);
1158 char *kaddr;
1159 1170
1160 kaddr = kmap(page); 1171 crc = ceph_crc32c_page(crc, page, page_offset, length);
1161 BUG_ON(kaddr == NULL);
1162 base = kaddr + page_offset;
1163 crc = crc32c(crc, base, length);
1164 kunmap(page);
1165 msg->footer.data_crc = cpu_to_le32(crc); 1172 msg->footer.data_crc = cpu_to_le32(crc);
1166 msg_pos->did_page_crc = true; 1173 msg_pos->did_page_crc = true;
1167 } 1174 }
@@ -1843,16 +1850,9 @@ static int read_partial_message_pages(struct ceph_connection *con,
1843 if (ret <= 0) 1850 if (ret <= 0)
1844 return ret; 1851 return ret;
1845 1852
1846 if (do_datacrc) { 1853 if (do_datacrc)
1847 void *kaddr; 1854 con->in_data_crc = ceph_crc32c_page(con->in_data_crc, page,
1848 void *base; 1855 page_offset, ret);
1849
1850 kaddr = kmap(page);
1851 BUG_ON(!kaddr);
1852 base = kaddr + page_offset;
1853 con->in_data_crc = crc32c(con->in_data_crc, base, ret);
1854 kunmap(page);
1855 }
1856 1856
1857 in_msg_pos_next(con, length, ret); 1857 in_msg_pos_next(con, length, ret);
1858 1858
@@ -1886,16 +1886,9 @@ static int read_partial_message_bio(struct ceph_connection *con,
1886 if (ret <= 0) 1886 if (ret <= 0)
1887 return ret; 1887 return ret;
1888 1888
1889 if (do_datacrc) { 1889 if (do_datacrc)
1890 void *kaddr; 1890 con->in_data_crc = ceph_crc32c_page(con->in_data_crc, page,
1891 void *base; 1891 page_offset, ret);
1892
1893 kaddr = kmap(page);
1894 BUG_ON(!kaddr);
1895 base = kaddr + page_offset;
1896 con->in_data_crc = crc32c(con->in_data_crc, base, ret);
1897 kunmap(page);
1898 }
1899 1892
1900 in_msg_pos_next(con, length, ret); 1893 in_msg_pos_next(con, length, ret);
1901 1894