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>
#endif /* CONFIG_BLOCK */
}
#endif /* CONFIG_BLOCK */
}
+static u32 ceph_crc32c_page(u32 crc, struct page *page,
+ unsigned int page_offset,
+ unsigned int length)
+{
+ char *kaddr;
+
+ kaddr = kmap(page);
+ BUG_ON(kaddr == NULL);
+ crc = crc32c(crc, kaddr + page_offset, length);
+ kunmap(page);
+
+ return crc;
+}
/*
* Write as much message data payload as we can. If we finish, queue
* up the footer.
/*
* Write as much message data payload as we can. If we finish, queue
* up the footer.
page_offset = msg_pos->page_pos + bio_offset;
if (do_datacrc && !msg_pos->did_page_crc) {
page_offset = msg_pos->page_pos + bio_offset;
if (do_datacrc && !msg_pos->did_page_crc) {
u32 crc = le32_to_cpu(msg->footer.data_crc);
u32 crc = le32_to_cpu(msg->footer.data_crc);
- kaddr = kmap(page);
- BUG_ON(kaddr == NULL);
- base = kaddr + page_offset;
- crc = crc32c(crc, base, length);
- kunmap(page);
+ crc = ceph_crc32c_page(crc, page, page_offset, length);
msg->footer.data_crc = cpu_to_le32(crc);
msg_pos->did_page_crc = true;
}
msg->footer.data_crc = cpu_to_le32(crc);
msg_pos->did_page_crc = true;
}
if (ret <= 0)
return ret;
if (ret <= 0)
return ret;
- if (do_datacrc) {
- void *kaddr;
- void *base;
-
- kaddr = kmap(page);
- BUG_ON(!kaddr);
- base = kaddr + page_offset;
- con->in_data_crc = crc32c(con->in_data_crc, base, ret);
- kunmap(page);
- }
+ if (do_datacrc)
+ con->in_data_crc = ceph_crc32c_page(con->in_data_crc, page,
+ page_offset, ret);
in_msg_pos_next(con, length, ret);
in_msg_pos_next(con, length, ret);
if (ret <= 0)
return ret;
if (ret <= 0)
return ret;
- if (do_datacrc) {
- void *kaddr;
- void *base;
-
- kaddr = kmap(page);
- BUG_ON(!kaddr);
- base = kaddr + page_offset;
- con->in_data_crc = crc32c(con->in_data_crc, base, ret);
- kunmap(page);
- }
+ if (do_datacrc)
+ con->in_data_crc = ceph_crc32c_page(con->in_data_crc, page,
+ page_offset, ret);
in_msg_pos_next(con, length, ret);
in_msg_pos_next(con, length, ret);