cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Alexander Aring <aahringo@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH v5.14-rc1 12/12] fs: dlm: move receive loop into receive handler
Date: Fri, 16 Jul 2021 16:22:45 -0400	[thread overview]
Message-ID: <20210716202245.1262791-13-aahringo@redhat.com> (raw)
In-Reply-To: <20210716202245.1262791-1-aahringo@redhat.com>

This patch moves the kernel_recvmsg() loop call into the
receive_from_sock() function instead of doing the loop outside the
function and abort the loop over it's return value.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
 fs/dlm/lowcomms.c | 68 +++++++++++++++++++++--------------------------
 1 file changed, 31 insertions(+), 37 deletions(-)

diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 04d16ece2bcb..1a7f92dbdea7 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -895,7 +895,6 @@ static int con_realloc_receive_buf(struct connection *con, int newlen)
 /* Data received from remote end */
 static int receive_from_sock(struct connection *con)
 {
-	int call_again_soon = 0;
 	struct msghdr msg;
 	struct kvec iov;
 	int ret, buflen;
@@ -915,41 +914,39 @@ static int receive_from_sock(struct connection *con)
 			goto out_resched;
 	}
 
-	/* calculate new buffer parameter regarding last receive and
-	 * possible leftover bytes
-	 */
-	iov.iov_base = con->rx_buf + con->rx_leftover;
-	iov.iov_len = con->rx_buflen - con->rx_leftover;
-
-	memset(&msg, 0, sizeof(msg));
-	msg.msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
-	ret = kernel_recvmsg(con->sock, &msg, &iov, 1, iov.iov_len,
-			     msg.msg_flags);
-	if (ret <= 0)
-		goto out_close;
-	else if (ret == iov.iov_len)
-		call_again_soon = 1;
-
-	/* new buflen according readed bytes and leftover from last receive */
-	buflen = ret + con->rx_leftover;
-	ret = dlm_process_incoming_buffer(con->nodeid, con->rx_buf, buflen);
-	if (ret < 0)
-		goto out_close;
+	for (;;) {
+		/* calculate new buffer parameter regarding last receive and
+		 * possible leftover bytes
+		 */
+		iov.iov_base = con->rx_buf + con->rx_leftover;
+		iov.iov_len = con->rx_buflen - con->rx_leftover;
+
+		memset(&msg, 0, sizeof(msg));
+		msg.msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
+		ret = kernel_recvmsg(con->sock, &msg, &iov, 1, iov.iov_len,
+				     msg.msg_flags);
+		if (ret == -EAGAIN)
+			break;
+		else if (ret <= 0)
+			goto out_close;
 
-	/* calculate leftover bytes from process and put it into begin of
-	 * the receive buffer, so next receive we have the full message
-	 *@the start address of the receive buffer.
-	 */
-	con->rx_leftover = buflen - ret;
-	if (con->rx_leftover) {
-		memmove(con->rx_buf, con->rx_buf + ret,
-			con->rx_leftover);
-		call_again_soon = true;
+		/* new buflen according readed bytes and leftover from last receive */
+		buflen = ret + con->rx_leftover;
+		ret = dlm_process_incoming_buffer(con->nodeid, con->rx_buf, buflen);
+		if (ret < 0)
+			goto out_close;
+
+		/* calculate leftover bytes from process and put it into begin of
+		 * the receive buffer, so next receive we have the full message
+		 *@the start address of the receive buffer.
+		 */
+		con->rx_leftover = buflen - ret;
+		if (con->rx_leftover) {
+			memmove(con->rx_buf, con->rx_buf + ret,
+				con->rx_leftover);
+		}
 	}
 
-	if (call_again_soon)
-		goto out_resched;
-
 	mutex_unlock(&con->sock_mutex);
 	return 0;
 
@@ -1511,12 +1508,9 @@ int dlm_lowcomms_close(int nodeid)
 static void process_recv_sockets(struct work_struct *work)
 {
 	struct connection *con = container_of(work, struct connection, rwork);
-	int err;
 
 	clear_bit(CF_READ_PENDING, &con->flags);
-	do {
-		err = receive_from_sock(con);
-	} while (!err);
+	receive_from_sock(con);
 }
 
 static void process_listen_recv_socket(struct work_struct *work)
-- 
2.27.0



      parent reply	other threads:[~2021-07-16 20:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-16 20:22 [Cluster-devel] [PATCH v5.14-rc1 00/12] fs: dlm: combine similar functionaility Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 01/12] fs: dlm: use sk->sk_socket instead of con->sock Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 02/12] fs: dlm: use READ_ONCE for config var Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 03/12] fs: dlm: fix typo in tlv prefix Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 04/12] fs: dlm: clear CF_APP_LIMITED on close Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 05/12] fs: dlm: cleanup and remove _send_rcom Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 06/12] fs: dlm: introduce con_next_wq helper Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 07/12] fs: dlm: move to static proto ops Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 08/12] fs: dlm: introduce generic listen Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 09/12] fs: dlm: auto load sctp module Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 10/12] fs: dlm: generic connect func Alexander Aring
2021-07-16 20:22 ` [Cluster-devel] [PATCH v5.14-rc1 11/12] fs: dlm: fix multiple empty writequeue alloc Alexander Aring
2021-07-16 20:22 ` Alexander Aring [this message]

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=20210716202245.1262791-13-aahringo@redhat.com \
    --to=aahringo@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).