CEPH filesystem development
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 2/3] ceph: messenger: update "to" in read_partial() caller
Date: Thu, 10 May 2012 20:18:47 -0500	[thread overview]
Message-ID: <4FAC68F7.1030508@inktank.com> (raw)
In-Reply-To: <4FAC4799.3010903@inktank.com>

read_partial() always increases whatever "to" value is supplied by
adding the requested size to it.  That's the only thing it does with
that pointed-to value.

Do that pointer advance in the caller (and then only when the
updated value will be subsequently used), and change the "to"
parameter to be an in-only and non-pointer value.

Signed-off-by: Alex Elder <elder@inktank.com>
---
  net/ceph/messenger.c |   31 ++++++++++++++++---------------
  1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 673133e..37fd2ae 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -992,11 +992,12 @@ static int prepare_read_message(struct 
ceph_connection *con)


  static int read_partial(struct ceph_connection *con,
-			int *to, int size, void *object)
+			int to, int size, void *object)
  {
-	*to += size;
-	while (con->in_base_pos < *to) {
-		int left = *to - con->in_base_pos;
+	int end = to + size;
+
+	while (con->in_base_pos < end) {
+		int left = end - con->in_base_pos;
  		int have = size - left;
  		int ret = ceph_tcp_recvmsg(con->sock, object + have, left);
  		if (ret <= 0)
@@ -1017,14 +1018,16 @@ static int read_partial_banner(struct 
ceph_connection *con)
  	dout("read_partial_banner %p at %d\n", con, con->in_base_pos);

  	/* peer's banner */
-	ret = read_partial(con, &to, strlen(CEPH_BANNER), con->in_banner);
+	ret = read_partial(con, to, strlen(CEPH_BANNER), con->in_banner);
  	if (ret <= 0)
  		goto out;
-	ret = read_partial(con, &to, sizeof(con->actual_peer_addr),
+	to += strlen(CEPH_BANNER);
+	ret = read_partial(con, to, sizeof(con->actual_peer_addr),
  			   &con->actual_peer_addr);
  	if (ret <= 0)
  		goto out;
-	ret = read_partial(con, &to, sizeof(con->peer_addr_for_me),
+	to += sizeof(con->actual_peer_addr);
+	ret = read_partial(con, to, sizeof(con->peer_addr_for_me),
  			   &con->peer_addr_for_me);
  	if (ret <= 0)
  		goto out;
@@ -1038,10 +1041,11 @@ static int read_partial_connect(struct 
ceph_connection *con)

  	dout("read_partial_connect %p at %d\n", con, con->in_base_pos);

-	ret = read_partial(con, &to, sizeof(con->in_reply), &con->in_reply);
+	ret = read_partial(con, to, sizeof(con->in_reply), &con->in_reply);
  	if (ret <= 0)
  		goto out;
-	ret = read_partial(con, &to, le32_to_cpu(con->in_reply.authorizer_len),
+	to += sizeof(con->in_reply);
+	ret = read_partial(con, to, le32_to_cpu(con->in_reply.authorizer_len),
  			   con->auth_reply_buf);
  	if (ret <= 0)
  		goto out;
@@ -1491,9 +1495,7 @@ static int process_connect(struct ceph_connection 
*con)
   */
  static int read_partial_ack(struct ceph_connection *con)
  {
-	int to = 0;
-
-	return read_partial(con, &to, sizeof(con->in_temp_ack),
+	return read_partial(con, 0, sizeof(con->in_temp_ack),
  			    &con->in_temp_ack);
  }

@@ -1638,8 +1640,7 @@ static int read_partial_message(struct 
ceph_connection *con)
  	dout("read_partial_message con %p msg %p\n", con, m);

  	/* header */
-	to = 0;
-	ret = read_partial(con, &to, sizeof (con->in_hdr), &con->in_hdr);
+	ret = read_partial(con, 0, sizeof (con->in_hdr), &con->in_hdr);
  	if (ret <= 0)
  		return ret;

@@ -1755,7 +1756,7 @@ static int read_partial_message(struct 
ceph_connection *con)

  	/* footer */
  	to = sizeof (m->hdr);
-	ret = read_partial(con, &to, sizeof (m->footer), &m->footer);
+	ret = read_partial(con, to, sizeof (m->footer), &m->footer);
  	if (ret <= 0)
  		return ret;

-- 
1.7.9.5


  parent reply	other threads:[~2012-05-11  1:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10 22:56 [PATCH 0/3] ceph: messenger: read_partial() cleanups Alex Elder
2012-05-11  1:18 ` [PATCH 1/3] ceph: messenger: use read_partial() in read_partial_message() Alex Elder
2012-05-12 23:54   ` Sage Weil
2012-05-11  1:18 ` Alex Elder [this message]
2012-05-12 23:55   ` [PATCH 2/3] ceph: messenger: update "to" in read_partial() caller Sage Weil
2012-05-11  1:18 ` [PATCH 3/3] ceph: messenger: change read_partial() to take "end" arg Alex Elder
2012-05-13  0:11   ` Sage Weil
2012-05-14 16:26     ` Alex Elder
2012-05-14 16:28     ` Alex Elder

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=4FAC68F7.1030508@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox