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

libceph: consolidate message prep code

In prepare_write_message_data(), various fields are initialized in
preparation for writing message data out.  Meanwhile, in
read_partial_message(), there is essentially the same block of code,
operating on message variables associated with an incoming message.

Generalize prepare_write_message_data() so it works for both
incoming and outcoming messages, and use it in both spots.  The
did_page_crc is not used for input (so it's harmless to initialize
it).
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
parent bae6acd9
...@@ -722,11 +722,9 @@ static void iter_bio_next(struct bio **bio_iter, unsigned int *seg) ...@@ -722,11 +722,9 @@ static void iter_bio_next(struct bio **bio_iter, unsigned int *seg)
} }
#endif #endif
static void prepare_write_message_data(struct ceph_connection *con) static void prepare_message_data(struct ceph_msg *msg,
struct ceph_msg_pos *msg_pos)
{ {
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);
...@@ -742,7 +740,6 @@ static void prepare_write_message_data(struct ceph_connection *con) ...@@ -742,7 +740,6 @@ static void prepare_write_message_data(struct ceph_connection *con)
#endif #endif
msg_pos->data_pos = 0; msg_pos->data_pos = 0;
msg_pos->did_page_crc = false; msg_pos->did_page_crc = false;
con->out_more = 1; /* data + footer will follow */
} }
/* /*
...@@ -840,11 +837,13 @@ static void prepare_write_message(struct ceph_connection *con) ...@@ -840,11 +837,13 @@ static void prepare_write_message(struct ceph_connection *con)
/* is there a data payload? */ /* is there a data payload? */
con->out_msg->footer.data_crc = 0; con->out_msg->footer.data_crc = 0;
if (m->hdr.data_len) if (m->hdr.data_len) {
prepare_write_message_data(con); prepare_message_data(con->out_msg, &con->out_msg_pos);
else con->out_more = 1; /* data + footer will follow */
} else {
/* no, queue up footer too and be done */ /* no, queue up footer too and be done */
prepare_write_message_footer(con); prepare_write_message_footer(con);
}
con_flag_set(con, CON_FLAG_WRITE_PENDING); con_flag_set(con, CON_FLAG_WRITE_PENDING);
} }
...@@ -1956,17 +1955,10 @@ static int read_partial_message(struct ceph_connection *con) ...@@ -1956,17 +1955,10 @@ 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;
msg_pos->page = 0; /* prepare for data payload, if any */
if (m->pages)
msg_pos->page_pos = m->page_alignment;
else
msg_pos->page_pos = 0;
msg_pos->data_pos = 0;
#ifdef CONFIG_BLOCK if (data_len)
if (m->bio) prepare_message_data(con->in_msg, &con->in_msg_pos);
init_bio_iter(m->bio, &m->bio_iter, &m->bio_seg);
#endif
} }
/* front */ /* front */
......
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