All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 2/6] libceph: consolidate message prep code
Date: Sat, 09 Mar 2013 10:42:51 -0600	[thread overview]
Message-ID: <513B668B.2090305@inktank.com> (raw)
In-Reply-To: <513B661F.4050203@inktank.com>

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: Alex Elder <elder@inktank.com>
---
 net/ceph/messenger.c |   28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 7788170..e8fa449 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -722,11 +722,9 @@ static void iter_bio_next(struct bio **bio_iter,
unsigned int *seg)
 }
 #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->hdr.data_len);

@@ -742,7 +740,6 @@ static void prepare_write_message_data(struct
ceph_connection *con)
 #endif
 	msg_pos->data_pos = 0;
 	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)

 	/* is there a data payload? */
 	con->out_msg->footer.data_crc = 0;
-	if (m->hdr.data_len)
-		prepare_write_message_data(con);
-	else
+	if (m->hdr.data_len) {
+		prepare_message_data(con->out_msg, &con->out_msg_pos);
+		con->out_more = 1;  /* data + footer will follow */
+	} else {
 		/* no, queue up footer too and be done */
 		prepare_write_message_footer(con);
+	}

 	con_flag_set(con, CON_FLAG_WRITE_PENDING);
 }
@@ -1956,17 +1955,10 @@ static int read_partial_message(struct
ceph_connection *con)
 		if (m->middle)
 			m->middle->vec.iov_len = 0;

-		msg_pos->page = 0;
-		if (m->pages)
-			msg_pos->page_pos = m->page_alignment;
-		else
-			msg_pos->page_pos = 0;
-		msg_pos->data_pos = 0;
+		/* prepare for data payload, if any */

-#ifdef CONFIG_BLOCK
-		if (m->bio)
-			init_bio_iter(m->bio, &m->bio_iter, &m->bio_seg);
-#endif
+		if (data_len)
+			prepare_message_data(con->in_msg, &con->in_msg_pos);
 	}

 	/* front */
-- 
1.7.9.5


  parent reply	other threads:[~2013-03-09 16:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-09 16:41 [PATCH 0/6] libceph: refactor messenger for multiple data sources Alex Elder
2013-03-09 16:42 ` [PATCH 1/6] libceph: use local variables for message positions Alex Elder
2013-03-09 16:42 ` Alex Elder [this message]
2013-03-09 16:43 ` [PATCH 3/6] libceph: small write_partial_msg_pages() refactor Alex Elder
2013-03-09 16:43 ` [PATCH 4/6] libceph: encapsulate reading message data Alex Elder
2013-03-10  0:38   ` [PATCH 4/6, v2] " Alex Elder
2013-03-10 16:33   ` [PATCH 4/6, v3] " Alex Elder
2013-03-09 16:43 ` [PATCH 5/6] libceph: define and use ceph_tcp_recvpage() Alex Elder
2013-03-09 16:43 ` [PATCH 6/6] libceph: define and use ceph_crc32c_page() Alex Elder
2013-03-11 21:01 ` [PATCH 0/6] libceph: refactor messenger for multiple data sources Josh Durgin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=513B668B.2090305@inktank.com \
    --to=elder@inktank.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.