Commit bae6acd9 authored by Alex Elder's avatar Alex Elder Committed by Sage Weil

libceph: use local variables for message positions

There are several places where a message's out_msg_pos or in_msg_pos
field is used repeatedly within a function.  Use a local pointer
variable for this purpose to unclutter the code.

This and the upcoming cleanup patches are related to:
    http://tracker.ceph.com/issues/4403Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent 98a03708
...@@ -725,22 +725,23 @@ static void iter_bio_next(struct bio **bio_iter, unsigned int *seg) ...@@ -725,22 +725,23 @@ static void iter_bio_next(struct bio **bio_iter, unsigned int *seg)
static void prepare_write_message_data(struct ceph_connection *con) static void prepare_write_message_data(struct ceph_connection *con)
{ {
struct ceph_msg *msg = con->out_msg; struct ceph_msg *msg = con->out_msg;
struct ceph_msg_pos *msg_pos = &con->out_msg_pos;
BUG_ON(!msg); BUG_ON(!msg);
BUG_ON(!msg->hdr.data_len); BUG_ON(!msg->hdr.data_len);
/* initialize page iterator */ /* initialize page iterator */
con->out_msg_pos.page = 0; msg_pos->page = 0;
if (msg->pages) if (msg->pages)
con->out_msg_pos.page_pos = msg->page_alignment; msg_pos->page_pos = msg->page_alignment;
else else
con->out_msg_pos.page_pos = 0; msg_pos->page_pos = 0;
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
if (msg->bio) if (msg->bio)
init_bio_iter(msg->bio, &msg->bio_iter, &msg->bio_seg); init_bio_iter(msg->bio, &msg->bio_iter, &msg->bio_seg);
#endif #endif
con->out_msg_pos.data_pos = 0; msg_pos->data_pos = 0;
con->out_msg_pos.did_page_crc = false; msg_pos->did_page_crc = false;
con->out_more = 1; /* data + footer will follow */ con->out_more = 1; /* data + footer will follow */
} }
...@@ -1022,19 +1023,20 @@ static void out_msg_pos_next(struct ceph_connection *con, struct page *page, ...@@ -1022,19 +1023,20 @@ static void out_msg_pos_next(struct ceph_connection *con, struct page *page,
size_t len, size_t sent, bool in_trail) size_t len, size_t sent, bool in_trail)
{ {
struct ceph_msg *msg = con->out_msg; struct ceph_msg *msg = con->out_msg;
struct ceph_msg_pos *msg_pos = &con->out_msg_pos;
BUG_ON(!msg); BUG_ON(!msg);
BUG_ON(!sent); BUG_ON(!sent);
con->out_msg_pos.data_pos += sent; msg_pos->data_pos += sent;
con->out_msg_pos.page_pos += sent; msg_pos->page_pos += sent;
if (sent < len) if (sent < len)
return; return;
BUG_ON(sent != len); BUG_ON(sent != len);
con->out_msg_pos.page_pos = 0; msg_pos->page_pos = 0;
con->out_msg_pos.page++; msg_pos->page++;
con->out_msg_pos.did_page_crc = false; msg_pos->did_page_crc = false;
if (in_trail) if (in_trail)
list_rotate_left(&msg->trail->head); list_rotate_left(&msg->trail->head);
else if (msg->pagelist) else if (msg->pagelist)
...@@ -1049,18 +1051,19 @@ static void in_msg_pos_next(struct ceph_connection *con, size_t len, ...@@ -1049,18 +1051,19 @@ static void in_msg_pos_next(struct ceph_connection *con, size_t len,
size_t received) size_t received)
{ {
struct ceph_msg *msg = con->in_msg; struct ceph_msg *msg = con->in_msg;
struct ceph_msg_pos *msg_pos = &con->in_msg_pos;
BUG_ON(!msg); BUG_ON(!msg);
BUG_ON(!received); BUG_ON(!received);
con->in_msg_pos.data_pos += received; msg_pos->data_pos += received;
con->in_msg_pos.page_pos += received; msg_pos->page_pos += received;
if (received < len) if (received < len)
return; return;
BUG_ON(received != len); BUG_ON(received != len);
con->in_msg_pos.page_pos = 0; msg_pos->page_pos = 0;
con->in_msg_pos.page++; msg_pos->page++;
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
if (msg->bio) if (msg->bio)
iter_bio_next(&msg->bio_iter, &msg->bio_seg); iter_bio_next(&msg->bio_iter, &msg->bio_seg);
...@@ -1077,6 +1080,7 @@ static void in_msg_pos_next(struct ceph_connection *con, size_t len, ...@@ -1077,6 +1080,7 @@ static void in_msg_pos_next(struct ceph_connection *con, size_t len,
static int write_partial_msg_pages(struct ceph_connection *con) static int write_partial_msg_pages(struct ceph_connection *con)
{ {
struct ceph_msg *msg = con->out_msg; struct ceph_msg *msg = con->out_msg;
struct ceph_msg_pos *msg_pos = &con->out_msg_pos;
unsigned int data_len = le32_to_cpu(msg->hdr.data_len); unsigned int data_len = le32_to_cpu(msg->hdr.data_len);
size_t len; size_t len;
bool do_datacrc = !con->msgr->nocrc; bool do_datacrc = !con->msgr->nocrc;
...@@ -1087,7 +1091,7 @@ static int write_partial_msg_pages(struct ceph_connection *con) ...@@ -1087,7 +1091,7 @@ static int write_partial_msg_pages(struct ceph_connection *con)
const size_t trail_off = data_len - trail_len; const size_t trail_off = data_len - trail_len;
dout("write_partial_msg_pages %p msg %p page %d offset %d\n", dout("write_partial_msg_pages %p msg %p page %d offset %d\n",
con, msg, con->out_msg_pos.page, con->out_msg_pos.page_pos); con, msg, msg_pos->page, msg_pos->page_pos);
/* /*
* Iterate through each page that contains data to be * Iterate through each page that contains data to be
...@@ -1097,22 +1101,22 @@ static int write_partial_msg_pages(struct ceph_connection *con) ...@@ -1097,22 +1101,22 @@ static int write_partial_msg_pages(struct ceph_connection *con)
* need to map the page. If we have no pages, they have * need to map the page. If we have no pages, they have
* been revoked, so use the zero page. * been revoked, so use the zero page.
*/ */
while (data_len > con->out_msg_pos.data_pos) { while (data_len > msg_pos->data_pos) {
struct page *page = NULL; struct page *page = NULL;
int max_write = PAGE_SIZE; int max_write = PAGE_SIZE;
int bio_offset = 0; int bio_offset = 0;
in_trail = in_trail || con->out_msg_pos.data_pos >= trail_off; in_trail = in_trail || msg_pos->data_pos >= trail_off;
if (!in_trail) if (!in_trail)
total_max_write = trail_off - con->out_msg_pos.data_pos; total_max_write = trail_off - msg_pos->data_pos;
if (in_trail) { if (in_trail) {
total_max_write = data_len - con->out_msg_pos.data_pos; total_max_write = data_len - msg_pos->data_pos;
page = list_first_entry(&msg->trail->head, page = list_first_entry(&msg->trail->head,
struct page, lru); struct page, lru);
} else if (msg->pages) { } else if (msg->pages) {
page = msg->pages[con->out_msg_pos.page]; page = msg->pages[msg_pos->page];
} else if (msg->pagelist) { } else if (msg->pagelist) {
page = list_first_entry(&msg->pagelist->head, page = list_first_entry(&msg->pagelist->head,
struct page, lru); struct page, lru);
...@@ -1128,24 +1132,24 @@ static int write_partial_msg_pages(struct ceph_connection *con) ...@@ -1128,24 +1132,24 @@ static int write_partial_msg_pages(struct ceph_connection *con)
} else { } else {
page = zero_page; page = zero_page;
} }
len = min_t(int, max_write - con->out_msg_pos.page_pos, len = min_t(int, max_write - msg_pos->page_pos,
total_max_write); total_max_write);
if (do_datacrc && !con->out_msg_pos.did_page_crc) { if (do_datacrc && !msg_pos->did_page_crc) {
void *base; void *base;
u32 crc = le32_to_cpu(msg->footer.data_crc); u32 crc = le32_to_cpu(msg->footer.data_crc);
char *kaddr; char *kaddr;
kaddr = kmap(page); kaddr = kmap(page);
BUG_ON(kaddr == NULL); BUG_ON(kaddr == NULL);
base = kaddr + con->out_msg_pos.page_pos + bio_offset; base = kaddr + msg_pos->page_pos + bio_offset;
crc = crc32c(crc, base, len); crc = crc32c(crc, base, len);
kunmap(page); kunmap(page);
msg->footer.data_crc = cpu_to_le32(crc); msg->footer.data_crc = cpu_to_le32(crc);
con->out_msg_pos.did_page_crc = true; msg_pos->did_page_crc = true;
} }
ret = ceph_tcp_sendpage(con->sock, page, ret = ceph_tcp_sendpage(con->sock, page,
con->out_msg_pos.page_pos + bio_offset, msg_pos->page_pos + bio_offset,
len, true); len, true);
if (ret <= 0) if (ret <= 0)
goto out; goto out;
...@@ -1803,22 +1807,23 @@ static int read_partial_message_pages(struct ceph_connection *con, ...@@ -1803,22 +1807,23 @@ static int read_partial_message_pages(struct ceph_connection *con,
struct page **pages, struct page **pages,
unsigned int data_len, bool do_datacrc) unsigned int data_len, bool do_datacrc)
{ {
struct ceph_msg_pos *msg_pos = &con->in_msg_pos;
struct page *page; struct page *page;
void *p; void *p;
int ret; int ret;
int left; int left;
left = min((int)(data_len - con->in_msg_pos.data_pos), left = min((int)(data_len - msg_pos->data_pos),
(int)(PAGE_SIZE - con->in_msg_pos.page_pos)); (int)(PAGE_SIZE - msg_pos->page_pos));
/* (page) data */ /* (page) data */
BUG_ON(pages == NULL); BUG_ON(pages == NULL);
page = pages[con->in_msg_pos.page]; page = pages[msg_pos->page];
p = kmap(page); p = kmap(page);
ret = ceph_tcp_recvmsg(con->sock, p + con->in_msg_pos.page_pos, left); ret = ceph_tcp_recvmsg(con->sock, p + msg_pos->page_pos, left);
if (ret > 0 && do_datacrc) if (ret > 0 && do_datacrc)
con->in_data_crc = con->in_data_crc =
crc32c(con->in_data_crc, crc32c(con->in_data_crc,
p + con->in_msg_pos.page_pos, ret); p + msg_pos->page_pos, ret);
kunmap(page); kunmap(page);
if (ret <= 0) if (ret <= 0)
return ret; return ret;
...@@ -1833,6 +1838,7 @@ static int read_partial_message_bio(struct ceph_connection *con, ...@@ -1833,6 +1838,7 @@ static int read_partial_message_bio(struct ceph_connection *con,
unsigned int data_len, bool do_datacrc) unsigned int data_len, bool do_datacrc)
{ {
struct ceph_msg *msg = con->in_msg; struct ceph_msg *msg = con->in_msg;
struct ceph_msg_pos *msg_pos = &con->in_msg_pos;
struct bio_vec *bv; struct bio_vec *bv;
struct page *page; struct page *page;
void *p; void *p;
...@@ -1842,17 +1848,17 @@ static int read_partial_message_bio(struct ceph_connection *con, ...@@ -1842,17 +1848,17 @@ static int read_partial_message_bio(struct ceph_connection *con,
BUG_ON(!msg->bio_iter); BUG_ON(!msg->bio_iter);
bv = bio_iovec_idx(msg->bio_iter, msg->bio_seg); bv = bio_iovec_idx(msg->bio_iter, msg->bio_seg);
left = min((int)(data_len - con->in_msg_pos.data_pos), left = min((int)(data_len - msg_pos->data_pos),
(int)(bv->bv_len - con->in_msg_pos.page_pos)); (int)(bv->bv_len - msg_pos->page_pos));
page = bv->bv_page; page = bv->bv_page;
p = kmap(page) + bv->bv_offset; p = kmap(page) + bv->bv_offset;
ret = ceph_tcp_recvmsg(con->sock, p + con->in_msg_pos.page_pos, left); ret = ceph_tcp_recvmsg(con->sock, p + msg_pos->page_pos, left);
if (ret > 0 && do_datacrc) if (ret > 0 && do_datacrc)
con->in_data_crc = con->in_data_crc =
crc32c(con->in_data_crc, crc32c(con->in_data_crc,
p + con->in_msg_pos.page_pos, ret); p + msg_pos->page_pos, ret);
kunmap(page); kunmap(page);
if (ret <= 0) if (ret <= 0)
return ret; return ret;
...@@ -1869,6 +1875,7 @@ static int read_partial_message_bio(struct ceph_connection *con, ...@@ -1869,6 +1875,7 @@ static int read_partial_message_bio(struct ceph_connection *con,
static int read_partial_message(struct ceph_connection *con) static int read_partial_message(struct ceph_connection *con)
{ {
struct ceph_msg *m = con->in_msg; struct ceph_msg *m = con->in_msg;
struct ceph_msg_pos *msg_pos = &con->in_msg_pos;
int size; int size;
int end; int end;
int ret; int ret;
...@@ -1949,12 +1956,12 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1949,12 +1956,12 @@ static int read_partial_message(struct ceph_connection *con)
if (m->middle) if (m->middle)
m->middle->vec.iov_len = 0; m->middle->vec.iov_len = 0;
con->in_msg_pos.page = 0; msg_pos->page = 0;
if (m->pages) if (m->pages)
con->in_msg_pos.page_pos = m->page_alignment; msg_pos->page_pos = m->page_alignment;
else else
con->in_msg_pos.page_pos = 0; msg_pos->page_pos = 0;
con->in_msg_pos.data_pos = 0; msg_pos->data_pos = 0;
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
if (m->bio) if (m->bio)
...@@ -1978,7 +1985,7 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1978,7 +1985,7 @@ static int read_partial_message(struct ceph_connection *con)
} }
/* (page) data */ /* (page) data */
while (con->in_msg_pos.data_pos < data_len) { while (msg_pos->data_pos < data_len) {
if (m->pages) { if (m->pages) {
ret = read_partial_message_pages(con, m->pages, ret = read_partial_message_pages(con, m->pages,
data_len, do_datacrc); data_len, do_datacrc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment