Skip to content

Commit

Permalink
vsock: cancel packets when failing to connect
Browse files Browse the repository at this point in the history
Otherwise we'll leave the packets queued until releasing vsock device.
E.g., if guest is slow to start up, resulting ETIMEDOUT on connect, guest
will get the connect requests from failed host sockets.

Reviewed-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Jorgen Hansen <[email protected]>
Signed-off-by: Peng Tao <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
bergwolf authored and davem330 committed Mar 21, 2017
1 parent 073b4f2 commit 380feae
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions net/vmw_vsock/af_vsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,19 @@ static const struct proto_ops vsock_dgram_ops = {
.sendpage = sock_no_sendpage,
};

static int vsock_transport_cancel_pkt(struct vsock_sock *vsk)
{
if (!transport->cancel_pkt)
return -EOPNOTSUPP;

return transport->cancel_pkt(vsk);
}

static void vsock_connect_timeout(struct work_struct *work)
{
struct sock *sk;
struct vsock_sock *vsk;
int cancel = 0;

vsk = container_of(work, struct vsock_sock, dwork.work);
sk = sk_vsock(vsk);
Expand All @@ -1116,8 +1125,11 @@ static void vsock_connect_timeout(struct work_struct *work)
sk->sk_state = SS_UNCONNECTED;
sk->sk_err = ETIMEDOUT;
sk->sk_error_report(sk);
cancel = 1;
}
release_sock(sk);
if (cancel)
vsock_transport_cancel_pkt(vsk);

sock_put(sk);
}
Expand Down Expand Up @@ -1224,11 +1236,13 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
err = sock_intr_errno(timeout);
sk->sk_state = SS_UNCONNECTED;
sock->state = SS_UNCONNECTED;
vsock_transport_cancel_pkt(vsk);
goto out_wait;
} else if (timeout == 0) {
err = -ETIMEDOUT;
sk->sk_state = SS_UNCONNECTED;
sock->state = SS_UNCONNECTED;
vsock_transport_cancel_pkt(vsk);
goto out_wait;
}

Expand Down

0 comments on commit 380feae

Please sign in to comment.