diff options
author | Alex Elder <elder@dreamhost.com> | 2012-02-15 08:43:54 -0500 |
---|---|---|
committer | Alex Elder <elder@dreamhost.com> | 2012-03-22 11:47:51 -0400 |
commit | fe3ad593e2c34457ffa6233014ab19f4d36f85f2 (patch) | |
tree | eed6ceddbca3021e7492a1baaf658922e2aa8a6c /net/ceph | |
parent | a9a0c51af4e7c825c014b40694571456a75ebbc4 (diff) |
libceph: do crc calculations outside loop
Move blocks of code out of loops in read_partial_message_section()
and read_partial_message(). They were only was getting called at
the end of the last iteration of the loop anyway.
Signed-off-by: Alex Elder <elder@dreamhost.com>
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'net/ceph')
-rw-r--r-- | net/ceph/messenger.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 7ec6a228b667..575511a29eb7 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c | |||
@@ -1544,10 +1544,9 @@ static int read_partial_message_section(struct ceph_connection *con, | |||
1544 | if (ret <= 0) | 1544 | if (ret <= 0) |
1545 | return ret; | 1545 | return ret; |
1546 | section->iov_len += ret; | 1546 | section->iov_len += ret; |
1547 | if (section->iov_len == sec_len) | ||
1548 | *crc = crc32c(0, section->iov_base, | ||
1549 | section->iov_len); | ||
1550 | } | 1547 | } |
1548 | if (section->iov_len == sec_len) | ||
1549 | *crc = crc32c(0, section->iov_base, section->iov_len); | ||
1551 | 1550 | ||
1552 | return 1; | 1551 | return 1; |
1553 | } | 1552 | } |
@@ -1638,6 +1637,7 @@ static int read_partial_message(struct ceph_connection *con) | |||
1638 | bool do_datacrc = con->msgr->nocrc; | 1637 | bool do_datacrc = con->msgr->nocrc; |
1639 | int skip; | 1638 | int skip; |
1640 | u64 seq; | 1639 | u64 seq; |
1640 | u32 crc; | ||
1641 | 1641 | ||
1642 | dout("read_partial_message con %p msg %p\n", con, m); | 1642 | dout("read_partial_message con %p msg %p\n", con, m); |
1643 | 1643 | ||
@@ -1650,18 +1650,16 @@ static int read_partial_message(struct ceph_connection *con) | |||
1650 | if (ret <= 0) | 1650 | if (ret <= 0) |
1651 | return ret; | 1651 | return ret; |
1652 | con->in_base_pos += ret; | 1652 | con->in_base_pos += ret; |
1653 | if (con->in_base_pos == sizeof(con->in_hdr)) { | ||
1654 | u32 crc = crc32c(0, &con->in_hdr, | ||
1655 | offsetof(struct ceph_msg_header, crc)); | ||
1656 | |||
1657 | if (cpu_to_le32(crc) != con->in_hdr.crc) { | ||
1658 | pr_err("read_partial_message bad hdr " | ||
1659 | " crc %u != expected %u\n", | ||
1660 | crc, con->in_hdr.crc); | ||
1661 | return -EBADMSG; | ||
1662 | } | ||
1663 | } | ||
1664 | } | 1653 | } |
1654 | |||
1655 | crc = crc32c(0, &con->in_hdr, offsetof(struct ceph_msg_header, crc)); | ||
1656 | if (cpu_to_le32(crc) != con->in_hdr.crc) { | ||
1657 | pr_err("read_partial_message bad hdr " | ||
1658 | " crc %u != expected %u\n", | ||
1659 | crc, con->in_hdr.crc); | ||
1660 | return -EBADMSG; | ||
1661 | } | ||
1662 | |||
1665 | front_len = le32_to_cpu(con->in_hdr.front_len); | 1663 | front_len = le32_to_cpu(con->in_hdr.front_len); |
1666 | if (front_len > CEPH_MSG_MAX_FRONT_LEN) | 1664 | if (front_len > CEPH_MSG_MAX_FRONT_LEN) |
1667 | return -EIO; | 1665 | return -EIO; |