Skip to content

Commit 62699b3

Browse files
Alexander Aringteigland
authored andcommitted
fs: dlm: move receive loop into receive handler
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> Signed-off-by: David Teigland <teigland@redhat.com>
1 parent c51b022 commit 62699b3

1 file changed

Lines changed: 31 additions & 37 deletions

File tree

fs/dlm/lowcomms.c

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,6 @@ static int con_realloc_receive_buf(struct connection *con, int newlen)
895895
/* Data received from remote end */
896896
static int receive_from_sock(struct connection *con)
897897
{
898-
int call_again_soon = 0;
899898
struct msghdr msg;
900899
struct kvec iov;
901900
int ret, buflen;
@@ -915,41 +914,39 @@ static int receive_from_sock(struct connection *con)
915914
goto out_resched;
916915
}
917916

918-
/* calculate new buffer parameter regarding last receive and
919-
* possible leftover bytes
920-
*/
921-
iov.iov_base = con->rx_buf + con->rx_leftover;
922-
iov.iov_len = con->rx_buflen - con->rx_leftover;
923-
924-
memset(&msg, 0, sizeof(msg));
925-
msg.msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
926-
ret = kernel_recvmsg(con->sock, &msg, &iov, 1, iov.iov_len,
927-
msg.msg_flags);
928-
if (ret <= 0)
929-
goto out_close;
930-
else if (ret == iov.iov_len)
931-
call_again_soon = 1;
932-
933-
/* new buflen according readed bytes and leftover from last receive */
934-
buflen = ret + con->rx_leftover;
935-
ret = dlm_process_incoming_buffer(con->nodeid, con->rx_buf, buflen);
936-
if (ret < 0)
937-
goto out_close;
917+
for (;;) {
918+
/* calculate new buffer parameter regarding last receive and
919+
* possible leftover bytes
920+
*/
921+
iov.iov_base = con->rx_buf + con->rx_leftover;
922+
iov.iov_len = con->rx_buflen - con->rx_leftover;
923+
924+
memset(&msg, 0, sizeof(msg));
925+
msg.msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
926+
ret = kernel_recvmsg(con->sock, &msg, &iov, 1, iov.iov_len,
927+
msg.msg_flags);
928+
if (ret == -EAGAIN)
929+
break;
930+
else if (ret <= 0)
931+
goto out_close;
938932

939-
/* calculate leftover bytes from process and put it into begin of
940-
* the receive buffer, so next receive we have the full message
941-
* at the start address of the receive buffer.
942-
*/
943-
con->rx_leftover = buflen - ret;
944-
if (con->rx_leftover) {
945-
memmove(con->rx_buf, con->rx_buf + ret,
946-
con->rx_leftover);
947-
call_again_soon = true;
933+
/* new buflen according readed bytes and leftover from last receive */
934+
buflen = ret + con->rx_leftover;
935+
ret = dlm_process_incoming_buffer(con->nodeid, con->rx_buf, buflen);
936+
if (ret < 0)
937+
goto out_close;
938+
939+
/* calculate leftover bytes from process and put it into begin of
940+
* the receive buffer, so next receive we have the full message
941+
* at the start address of the receive buffer.
942+
*/
943+
con->rx_leftover = buflen - ret;
944+
if (con->rx_leftover) {
945+
memmove(con->rx_buf, con->rx_buf + ret,
946+
con->rx_leftover);
947+
}
948948
}
949949

950-
if (call_again_soon)
951-
goto out_resched;
952-
953950
mutex_unlock(&con->sock_mutex);
954951
return 0;
955952

@@ -1511,12 +1508,9 @@ int dlm_lowcomms_close(int nodeid)
15111508
static void process_recv_sockets(struct work_struct *work)
15121509
{
15131510
struct connection *con = container_of(work, struct connection, rwork);
1514-
int err;
15151511

15161512
clear_bit(CF_READ_PENDING, &con->flags);
1517-
do {
1518-
err = receive_from_sock(con);
1519-
} while (!err);
1513+
receive_from_sock(con);
15201514
}
15211515

15221516
static void process_listen_recv_socket(struct work_struct *work)

0 commit comments

Comments
 (0)