Commit 62699b3f authored by Alexander Aring's avatar Alexander Aring Committed by David Teigland

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: default avatarAlexander Aring <aahringo@redhat.com>
Signed-off-by: default avatarDavid Teigland <teigland@redhat.com>
parent c51b0221
...@@ -895,7 +895,6 @@ static int con_realloc_receive_buf(struct connection *con, int newlen) ...@@ -895,7 +895,6 @@ static int con_realloc_receive_buf(struct connection *con, int newlen)
/* Data received from remote end */ /* Data received from remote end */
static int receive_from_sock(struct connection *con) static int receive_from_sock(struct connection *con)
{ {
int call_again_soon = 0;
struct msghdr msg; struct msghdr msg;
struct kvec iov; struct kvec iov;
int ret, buflen; int ret, buflen;
...@@ -915,41 +914,39 @@ static int receive_from_sock(struct connection *con) ...@@ -915,41 +914,39 @@ static int receive_from_sock(struct connection *con)
goto out_resched; goto out_resched;
} }
/* calculate new buffer parameter regarding last receive and for (;;) {
* possible leftover bytes /* 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; 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; memset(&msg, 0, sizeof(msg));
ret = kernel_recvmsg(con->sock, &msg, &iov, 1, iov.iov_len, msg.msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
msg.msg_flags); ret = kernel_recvmsg(con->sock, &msg, &iov, 1, iov.iov_len,
if (ret <= 0) msg.msg_flags);
goto out_close; if (ret == -EAGAIN)
else if (ret == iov.iov_len) break;
call_again_soon = 1; else if (ret <= 0)
goto out_close;
/* 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 /* new buflen according readed bytes and leftover from last receive */
* the receive buffer, so next receive we have the full message buflen = ret + con->rx_leftover;
* at the start address of the receive buffer. ret = dlm_process_incoming_buffer(con->nodeid, con->rx_buf, buflen);
*/ if (ret < 0)
con->rx_leftover = buflen - ret; goto out_close;
if (con->rx_leftover) {
memmove(con->rx_buf, con->rx_buf + ret, /* calculate leftover bytes from process and put it into begin of
con->rx_leftover); * the receive buffer, so next receive we have the full message
call_again_soon = true; * at 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); mutex_unlock(&con->sock_mutex);
return 0; return 0;
...@@ -1511,12 +1508,9 @@ int dlm_lowcomms_close(int nodeid) ...@@ -1511,12 +1508,9 @@ int dlm_lowcomms_close(int nodeid)
static void process_recv_sockets(struct work_struct *work) static void process_recv_sockets(struct work_struct *work)
{ {
struct connection *con = container_of(work, struct connection, rwork); struct connection *con = container_of(work, struct connection, rwork);
int err;
clear_bit(CF_READ_PENDING, &con->flags); clear_bit(CF_READ_PENDING, &con->flags);
do { receive_from_sock(con);
err = receive_from_sock(con);
} while (!err);
} }
static void process_listen_recv_socket(struct work_struct *work) static void process_listen_recv_socket(struct work_struct *work)
......
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