Commit 3f40504f authored by Ying Xue's avatar Ying Xue Committed by David S. Miller

tipc: standardize sendmsg routine of connectionless socket

Comparing the behaviour of how to wait for events in TIPC sendmsg()
with other stacks, the TIPC implementation might be perceived as
different, and sometimes even incorrect. For instance, sk_sleep()
and tport->congested variables associated with socket are exposed
without socket lock protection while wait_event_interruptible_timeout()
accesses them. So standardizing it with similar implementation
in other stacks can help us correct these errors which the process
of calling sendmsg() cannot be woken up event if an expected event
arrive at socket or improperly woken up although the wake condition
doesn't match.
Signed-off-by: default avatarYing Xue <ying.xue@windriver.com>
Reviewed-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6398e23c
...@@ -567,6 +567,31 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) ...@@ -567,6 +567,31 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
return 0; return 0;
} }
static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
{
struct sock *sk = sock->sk;
struct tipc_port *tport = tipc_sk_port(sk);
DEFINE_WAIT(wait);
int done;
do {
int err = sock_error(sk);
if (err)
return err;
if (sock->state == SS_DISCONNECTING)
return -EPIPE;
if (!*timeo_p)
return -EAGAIN;
if (signal_pending(current))
return sock_intr_errno(*timeo_p);
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
done = sk_wait_event(sk, timeo_p, !tport->congested);
finish_wait(sk_sleep(sk), &wait);
} while (!done);
return 0;
}
/** /**
* send_msg - send message in connectionless manner * send_msg - send message in connectionless manner
* @iocb: if NULL, indicates that socket lock is already held * @iocb: if NULL, indicates that socket lock is already held
...@@ -588,7 +613,7 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, ...@@ -588,7 +613,7 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
struct tipc_port *tport = tipc_sk_port(sk); struct tipc_port *tport = tipc_sk_port(sk);
struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name;
int needs_conn; int needs_conn;
long timeout_val; long timeo;
int res = -EINVAL; int res = -EINVAL;
if (unlikely(!dest)) if (unlikely(!dest))
...@@ -625,8 +650,7 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, ...@@ -625,8 +650,7 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
reject_rx_queue(sk); reject_rx_queue(sk);
} }
timeout_val = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
do { do {
if (dest->addrtype == TIPC_ADDR_NAME) { if (dest->addrtype == TIPC_ADDR_NAME) {
res = dest_name_check(dest, m); res = dest_name_check(dest, m);
...@@ -660,14 +684,9 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, ...@@ -660,14 +684,9 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,
sock->state = SS_CONNECTING; sock->state = SS_CONNECTING;
break; break;
} }
if (timeout_val <= 0L) { res = tipc_wait_for_sndmsg(sock, &timeo);
res = timeout_val ? timeout_val : -EWOULDBLOCK; if (res)
break; break;
}
release_sock(sk);
timeout_val = wait_event_interruptible_timeout(*sk_sleep(sk),
!tport->congested, timeout_val);
lock_sock(sk);
} while (1); } while (1);
exit: exit:
......
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