libceph: encapsulate advancing msg page
In write_partial_msg_pages(), once all the data from a page has been sent we advance to the next one. Put the code that takes care of this into its own function. While modifying write_partial_msg_pages(), make its local variable "in_trail" be Boolean, and use the local variable "msg" (which is just the connection's current out_msg pointer) consistently. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Родитель
739c905baa
Коммит
84ca8fc87f
|
@ -891,6 +891,33 @@ static void iter_bio_next(struct bio **bio_iter, int *seg)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void out_msg_pos_next(struct ceph_connection *con, struct page *page,
|
||||||
|
size_t len, size_t sent, bool in_trail)
|
||||||
|
{
|
||||||
|
struct ceph_msg *msg = con->out_msg;
|
||||||
|
|
||||||
|
BUG_ON(!msg);
|
||||||
|
BUG_ON(!sent);
|
||||||
|
|
||||||
|
con->out_msg_pos.data_pos += sent;
|
||||||
|
con->out_msg_pos.page_pos += sent;
|
||||||
|
if (sent == len) {
|
||||||
|
con->out_msg_pos.page_pos = 0;
|
||||||
|
con->out_msg_pos.page++;
|
||||||
|
con->out_msg_pos.did_page_crc = false;
|
||||||
|
if (in_trail)
|
||||||
|
list_move_tail(&page->lru,
|
||||||
|
&msg->trail->head);
|
||||||
|
else if (msg->pagelist)
|
||||||
|
list_move_tail(&page->lru,
|
||||||
|
&msg->pagelist->head);
|
||||||
|
#ifdef CONFIG_BLOCK
|
||||||
|
else if (msg->bio)
|
||||||
|
iter_bio_next(&msg->bio_iter, &msg->bio_seg);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write as much message data payload as we can. If we finish, queue
|
* Write as much message data payload as we can. If we finish, queue
|
||||||
* up the footer.
|
* up the footer.
|
||||||
|
@ -906,11 +933,11 @@ static int write_partial_msg_pages(struct ceph_connection *con)
|
||||||
bool do_datacrc = !con->msgr->nocrc;
|
bool do_datacrc = !con->msgr->nocrc;
|
||||||
int ret;
|
int ret;
|
||||||
int total_max_write;
|
int total_max_write;
|
||||||
int in_trail = 0;
|
bool in_trail = false;
|
||||||
size_t trail_len = (msg->trail ? msg->trail->length : 0);
|
size_t trail_len = (msg->trail ? msg->trail->length : 0);
|
||||||
|
|
||||||
dout("write_partial_msg_pages %p msg %p page %d/%d offset %d\n",
|
dout("write_partial_msg_pages %p msg %p page %d/%d offset %d\n",
|
||||||
con, con->out_msg, con->out_msg_pos.page, con->out_msg->nr_pages,
|
con, msg, con->out_msg_pos.page, msg->nr_pages,
|
||||||
con->out_msg_pos.page_pos);
|
con->out_msg_pos.page_pos);
|
||||||
|
|
||||||
#ifdef CONFIG_BLOCK
|
#ifdef CONFIG_BLOCK
|
||||||
|
@ -934,13 +961,12 @@ static int write_partial_msg_pages(struct ceph_connection *con)
|
||||||
|
|
||||||
/* have we reached the trail part of the data? */
|
/* have we reached the trail part of the data? */
|
||||||
if (con->out_msg_pos.data_pos >= data_len - trail_len) {
|
if (con->out_msg_pos.data_pos >= data_len - trail_len) {
|
||||||
in_trail = 1;
|
in_trail = true;
|
||||||
|
|
||||||
total_max_write = data_len - con->out_msg_pos.data_pos;
|
total_max_write = data_len - con->out_msg_pos.data_pos;
|
||||||
|
|
||||||
page = list_first_entry(&msg->trail->head,
|
page = list_first_entry(&msg->trail->head,
|
||||||
struct page, lru);
|
struct page, lru);
|
||||||
max_write = PAGE_SIZE;
|
|
||||||
} else if (msg->pages) {
|
} else if (msg->pages) {
|
||||||
page = msg->pages[con->out_msg_pos.page];
|
page = msg->pages[con->out_msg_pos.page];
|
||||||
} else if (msg->pagelist) {
|
} else if (msg->pagelist) {
|
||||||
|
@ -964,14 +990,14 @@ static int write_partial_msg_pages(struct ceph_connection *con)
|
||||||
if (do_datacrc && !con->out_msg_pos.did_page_crc) {
|
if (do_datacrc && !con->out_msg_pos.did_page_crc) {
|
||||||
void *base;
|
void *base;
|
||||||
u32 crc;
|
u32 crc;
|
||||||
u32 tmpcrc = le32_to_cpu(con->out_msg->footer.data_crc);
|
u32 tmpcrc = 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 + con->out_msg_pos.page_pos + bio_offset;
|
||||||
crc = crc32c(tmpcrc, base, len);
|
crc = crc32c(tmpcrc, base, len);
|
||||||
con->out_msg->footer.data_crc = cpu_to_le32(crc);
|
msg->footer.data_crc = cpu_to_le32(crc);
|
||||||
con->out_msg_pos.did_page_crc = true;
|
con->out_msg_pos.did_page_crc = true;
|
||||||
}
|
}
|
||||||
ret = ceph_tcp_sendpage(con->sock, page,
|
ret = ceph_tcp_sendpage(con->sock, page,
|
||||||
|
@ -984,30 +1010,14 @@ static int write_partial_msg_pages(struct ceph_connection *con)
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
con->out_msg_pos.data_pos += ret;
|
out_msg_pos_next(con, page, len, (size_t) ret, in_trail);
|
||||||
con->out_msg_pos.page_pos += ret;
|
|
||||||
if (ret == len) {
|
|
||||||
con->out_msg_pos.page_pos = 0;
|
|
||||||
con->out_msg_pos.page++;
|
|
||||||
con->out_msg_pos.did_page_crc = false;
|
|
||||||
if (in_trail)
|
|
||||||
list_move_tail(&page->lru,
|
|
||||||
&msg->trail->head);
|
|
||||||
else if (msg->pagelist)
|
|
||||||
list_move_tail(&page->lru,
|
|
||||||
&msg->pagelist->head);
|
|
||||||
#ifdef CONFIG_BLOCK
|
|
||||||
else if (msg->bio)
|
|
||||||
iter_bio_next(&msg->bio_iter, &msg->bio_seg);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dout("write_partial_msg_pages %p msg %p done\n", con, msg);
|
dout("write_partial_msg_pages %p msg %p done\n", con, msg);
|
||||||
|
|
||||||
/* prepare and queue up footer, too */
|
/* prepare and queue up footer, too */
|
||||||
if (!do_datacrc)
|
if (!do_datacrc)
|
||||||
con->out_msg->footer.flags |= CEPH_MSG_FOOTER_NOCRC;
|
msg->footer.flags |= CEPH_MSG_FOOTER_NOCRC;
|
||||||
con_out_kvec_reset(con);
|
con_out_kvec_reset(con);
|
||||||
prepare_write_message_footer(con);
|
prepare_write_message_footer(con);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче