Commit 3b4477d2 authored by Stefan Hajnoczi's avatar Stefan Hajnoczi Committed by David S. Miller

VSOCK: use TCP state constants for sk_state

There are two state fields: socket->state and sock->sk_state.  The
socket->state field uses SS_UNCONNECTED, SS_CONNECTED, etc while the
sock->sk_state typically uses values that match TCP state constants
(TCP_CLOSE, TCP_ESTABLISHED).  AF_VSOCK does not follow this convention
and instead uses SS_* constants for both fields.

The sk_state field will be exposed to userspace through the vsock_diag
interface for ss(8), netstat(8), and other programs.

This patch switches sk_state to TCP state constants so that the meaning
of this field is consistent with other address families.  Not just
AF_INET and AF_INET6 use the TCP constants, AF_UNIX and others do too.

The following mapping was used to convert the code:

  SS_FREE -> TCP_CLOSE
  SS_UNCONNECTED -> TCP_CLOSE
  SS_CONNECTING -> TCP_SYN_SENT
  SS_CONNECTED -> TCP_ESTABLISHED
  SS_DISCONNECTING -> TCP_CLOSING
  VSOCK_SS_LISTEN -> TCP_LISTEN

In __vsock_create() the sk_state initialization was dropped because
sock_init_data() already initializes sk_state to TCP_CLOSE.
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bf359b81
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
#include "vsock_addr.h" #include "vsock_addr.h"
/* vsock-specific sock->sk_state constants */
#define VSOCK_SS_LISTEN 255
#define LAST_RESERVED_PORT 1023 #define LAST_RESERVED_PORT 1023
#define VSOCK_HASH_SIZE 251 #define VSOCK_HASH_SIZE 251
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
* not support simultaneous connects (two "client" sockets connecting). * not support simultaneous connects (two "client" sockets connecting).
* *
* - "Server" sockets are referred to as listener sockets throughout this * - "Server" sockets are referred to as listener sockets throughout this
* implementation because they are in the VSOCK_SS_LISTEN state. When a * implementation because they are in the TCP_LISTEN state. When a
* connection request is received (the second kind of socket mentioned above), * connection request is received (the second kind of socket mentioned above),
* we create a new socket and refer to it as a pending socket. These pending * we create a new socket and refer to it as a pending socket. These pending
* sockets are placed on the pending connection list of the listener socket. * sockets are placed on the pending connection list of the listener socket.
...@@ -82,6 +82,15 @@ ...@@ -82,6 +82,15 @@
* argument, we must ensure the reference count is increased to ensure the * argument, we must ensure the reference count is increased to ensure the
* socket isn't freed before the function is run; the deferred function will * socket isn't freed before the function is run; the deferred function will
* then drop the reference. * then drop the reference.
*
* - sk->sk_state uses the TCP state constants because they are widely used by
* other address families and exposed to userspace tools like ss(8):
*
* TCP_CLOSE - unconnected
* TCP_SYN_SENT - connecting
* TCP_ESTABLISHED - connected
* TCP_CLOSING - disconnecting
* TCP_LISTEN - listening
*/ */
#include <linux/types.h> #include <linux/types.h>
...@@ -477,7 +486,7 @@ void vsock_pending_work(struct work_struct *work) ...@@ -477,7 +486,7 @@ void vsock_pending_work(struct work_struct *work)
if (vsock_in_connected_table(vsk)) if (vsock_in_connected_table(vsk))
vsock_remove_connected(vsk); vsock_remove_connected(vsk);
sk->sk_state = SS_FREE; sk->sk_state = TCP_CLOSE;
out: out:
release_sock(sk); release_sock(sk);
...@@ -617,7 +626,6 @@ struct sock *__vsock_create(struct net *net, ...@@ -617,7 +626,6 @@ struct sock *__vsock_create(struct net *net,
sk->sk_destruct = vsock_sk_destruct; sk->sk_destruct = vsock_sk_destruct;
sk->sk_backlog_rcv = vsock_queue_rcv_skb; sk->sk_backlog_rcv = vsock_queue_rcv_skb;
sk->sk_state = 0;
sock_reset_flag(sk, SOCK_DONE); sock_reset_flag(sk, SOCK_DONE);
INIT_LIST_HEAD(&vsk->bound_table); INIT_LIST_HEAD(&vsk->bound_table);
...@@ -891,7 +899,7 @@ static unsigned int vsock_poll(struct file *file, struct socket *sock, ...@@ -891,7 +899,7 @@ static unsigned int vsock_poll(struct file *file, struct socket *sock,
/* Listening sockets that have connections in their accept /* Listening sockets that have connections in their accept
* queue can be read. * queue can be read.
*/ */
if (sk->sk_state == VSOCK_SS_LISTEN if (sk->sk_state == TCP_LISTEN
&& !vsock_is_accept_queue_empty(sk)) && !vsock_is_accept_queue_empty(sk))
mask |= POLLIN | POLLRDNORM; mask |= POLLIN | POLLRDNORM;
...@@ -920,7 +928,7 @@ static unsigned int vsock_poll(struct file *file, struct socket *sock, ...@@ -920,7 +928,7 @@ static unsigned int vsock_poll(struct file *file, struct socket *sock,
} }
/* Connected sockets that can produce data can be written. */ /* Connected sockets that can produce data can be written. */
if (sk->sk_state == SS_CONNECTED) { if (sk->sk_state == TCP_ESTABLISHED) {
if (!(sk->sk_shutdown & SEND_SHUTDOWN)) { if (!(sk->sk_shutdown & SEND_SHUTDOWN)) {
bool space_avail_now = false; bool space_avail_now = false;
int ret = transport->notify_poll_out( int ret = transport->notify_poll_out(
...@@ -942,7 +950,7 @@ static unsigned int vsock_poll(struct file *file, struct socket *sock, ...@@ -942,7 +950,7 @@ static unsigned int vsock_poll(struct file *file, struct socket *sock,
* POLLOUT|POLLWRNORM when peer is closed and nothing to read, * POLLOUT|POLLWRNORM when peer is closed and nothing to read,
* but local send is not shutdown. * but local send is not shutdown.
*/ */
if (sk->sk_state == SS_UNCONNECTED) { if (sk->sk_state == TCP_CLOSE) {
if (!(sk->sk_shutdown & SEND_SHUTDOWN)) if (!(sk->sk_shutdown & SEND_SHUTDOWN))
mask |= POLLOUT | POLLWRNORM; mask |= POLLOUT | POLLWRNORM;
...@@ -1112,9 +1120,9 @@ static void vsock_connect_timeout(struct work_struct *work) ...@@ -1112,9 +1120,9 @@ static void vsock_connect_timeout(struct work_struct *work)
sk = sk_vsock(vsk); sk = sk_vsock(vsk);
lock_sock(sk); lock_sock(sk);
if (sk->sk_state == SS_CONNECTING && if (sk->sk_state == TCP_SYN_SENT &&
(sk->sk_shutdown != SHUTDOWN_MASK)) { (sk->sk_shutdown != SHUTDOWN_MASK)) {
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
sk->sk_err = ETIMEDOUT; sk->sk_err = ETIMEDOUT;
sk->sk_error_report(sk); sk->sk_error_report(sk);
cancel = 1; cancel = 1;
...@@ -1160,7 +1168,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1160,7 +1168,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
err = -EALREADY; err = -EALREADY;
break; break;
default: default:
if ((sk->sk_state == VSOCK_SS_LISTEN) || if ((sk->sk_state == TCP_LISTEN) ||
vsock_addr_cast(addr, addr_len, &remote_addr) != 0) { vsock_addr_cast(addr, addr_len, &remote_addr) != 0) {
err = -EINVAL; err = -EINVAL;
goto out; goto out;
...@@ -1183,7 +1191,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1183,7 +1191,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
if (err) if (err)
goto out; goto out;
sk->sk_state = SS_CONNECTING; sk->sk_state = TCP_SYN_SENT;
err = transport->connect(vsk); err = transport->connect(vsk);
if (err < 0) if (err < 0)
...@@ -1203,7 +1211,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1203,7 +1211,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
timeout = vsk->connect_timeout; timeout = vsk->connect_timeout;
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
while (sk->sk_state != SS_CONNECTED && sk->sk_err == 0) { while (sk->sk_state != TCP_ESTABLISHED && sk->sk_err == 0) {
if (flags & O_NONBLOCK) { if (flags & O_NONBLOCK) {
/* If we're not going to block, we schedule a timeout /* If we're not going to block, we schedule a timeout
* function to generate a timeout on the connection * function to generate a timeout on the connection
...@@ -1226,13 +1234,13 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1226,13 +1234,13 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
if (signal_pending(current)) { if (signal_pending(current)) {
err = sock_intr_errno(timeout); err = sock_intr_errno(timeout);
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
vsock_transport_cancel_pkt(vsk); vsock_transport_cancel_pkt(vsk);
goto out_wait; goto out_wait;
} else if (timeout == 0) { } else if (timeout == 0) {
err = -ETIMEDOUT; err = -ETIMEDOUT;
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
vsock_transport_cancel_pkt(vsk); vsock_transport_cancel_pkt(vsk);
goto out_wait; goto out_wait;
...@@ -1243,7 +1251,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1243,7 +1251,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
if (sk->sk_err) { if (sk->sk_err) {
err = -sk->sk_err; err = -sk->sk_err;
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
} else { } else {
err = 0; err = 0;
...@@ -1276,7 +1284,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags, ...@@ -1276,7 +1284,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags,
goto out; goto out;
} }
if (listener->sk_state != VSOCK_SS_LISTEN) { if (listener->sk_state != TCP_LISTEN) {
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
...@@ -1366,7 +1374,7 @@ static int vsock_listen(struct socket *sock, int backlog) ...@@ -1366,7 +1374,7 @@ static int vsock_listen(struct socket *sock, int backlog)
} }
sk->sk_max_ack_backlog = backlog; sk->sk_max_ack_backlog = backlog;
sk->sk_state = VSOCK_SS_LISTEN; sk->sk_state = TCP_LISTEN;
err = 0; err = 0;
...@@ -1546,7 +1554,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -1546,7 +1554,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
/* Callers should not provide a destination with stream sockets. */ /* Callers should not provide a destination with stream sockets. */
if (msg->msg_namelen) { if (msg->msg_namelen) {
err = sk->sk_state == SS_CONNECTED ? -EISCONN : -EOPNOTSUPP; err = sk->sk_state == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;
goto out; goto out;
} }
...@@ -1557,7 +1565,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -1557,7 +1565,7 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
goto out; goto out;
} }
if (sk->sk_state != SS_CONNECTED || if (sk->sk_state != TCP_ESTABLISHED ||
!vsock_addr_bound(&vsk->local_addr)) { !vsock_addr_bound(&vsk->local_addr)) {
err = -ENOTCONN; err = -ENOTCONN;
goto out; goto out;
...@@ -1681,7 +1689,7 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, ...@@ -1681,7 +1689,7 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
lock_sock(sk); lock_sock(sk);
if (sk->sk_state != SS_CONNECTED) { if (sk->sk_state != TCP_ESTABLISHED) {
/* Recvmsg is supposed to return 0 if a peer performs an /* Recvmsg is supposed to return 0 if a peer performs an
* orderly shutdown. Differentiate between that case and when a * orderly shutdown. Differentiate between that case and when a
* peer has not connected or a local shutdown occured with the * peer has not connected or a local shutdown occured with the
......
...@@ -310,7 +310,7 @@ static void hvs_close_connection(struct vmbus_channel *chan) ...@@ -310,7 +310,7 @@ static void hvs_close_connection(struct vmbus_channel *chan)
struct sock *sk = get_per_channel_state(chan); struct sock *sk = get_per_channel_state(chan);
struct vsock_sock *vsk = vsock_sk(sk); struct vsock_sock *vsk = vsock_sk(sk);
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
sock_set_flag(sk, SOCK_DONE); sock_set_flag(sk, SOCK_DONE);
vsk->peer_shutdown |= SEND_SHUTDOWN | RCV_SHUTDOWN; vsk->peer_shutdown |= SEND_SHUTDOWN | RCV_SHUTDOWN;
...@@ -344,8 +344,8 @@ static void hvs_open_connection(struct vmbus_channel *chan) ...@@ -344,8 +344,8 @@ static void hvs_open_connection(struct vmbus_channel *chan)
if (!sk) if (!sk)
return; return;
if ((conn_from_host && sk->sk_state != VSOCK_SS_LISTEN) || if ((conn_from_host && sk->sk_state != TCP_LISTEN) ||
(!conn_from_host && sk->sk_state != SS_CONNECTING)) (!conn_from_host && sk->sk_state != TCP_SYN_SENT))
goto out; goto out;
if (conn_from_host) { if (conn_from_host) {
...@@ -357,7 +357,7 @@ static void hvs_open_connection(struct vmbus_channel *chan) ...@@ -357,7 +357,7 @@ static void hvs_open_connection(struct vmbus_channel *chan)
if (!new) if (!new)
goto out; goto out;
new->sk_state = SS_CONNECTING; new->sk_state = TCP_SYN_SENT;
vnew = vsock_sk(new); vnew = vsock_sk(new);
hvs_new = vnew->trans; hvs_new = vnew->trans;
hvs_new->chan = chan; hvs_new->chan = chan;
...@@ -384,7 +384,7 @@ static void hvs_open_connection(struct vmbus_channel *chan) ...@@ -384,7 +384,7 @@ static void hvs_open_connection(struct vmbus_channel *chan)
vmbus_set_chn_rescind_callback(chan, hvs_close_connection); vmbus_set_chn_rescind_callback(chan, hvs_close_connection);
if (conn_from_host) { if (conn_from_host) {
new->sk_state = SS_CONNECTED; new->sk_state = TCP_ESTABLISHED;
sk->sk_ack_backlog++; sk->sk_ack_backlog++;
hvs_addr_init(&vnew->local_addr, if_type); hvs_addr_init(&vnew->local_addr, if_type);
...@@ -399,7 +399,7 @@ static void hvs_open_connection(struct vmbus_channel *chan) ...@@ -399,7 +399,7 @@ static void hvs_open_connection(struct vmbus_channel *chan)
vsock_enqueue_accept(sk, new); vsock_enqueue_accept(sk, new);
release_sock(sk); release_sock(sk);
} else { } else {
sk->sk_state = SS_CONNECTED; sk->sk_state = TCP_ESTABLISHED;
sk->sk_socket->state = SS_CONNECTED; sk->sk_socket->state = SS_CONNECTED;
vsock_insert_connected(vsock_sk(sk)); vsock_insert_connected(vsock_sk(sk));
......
...@@ -414,7 +414,7 @@ static void virtio_vsock_event_fill(struct virtio_vsock *vsock) ...@@ -414,7 +414,7 @@ static void virtio_vsock_event_fill(struct virtio_vsock *vsock)
static void virtio_vsock_reset_sock(struct sock *sk) static void virtio_vsock_reset_sock(struct sock *sk)
{ {
lock_sock(sk); lock_sock(sk);
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
sk->sk_err = ECONNRESET; sk->sk_err = ECONNRESET;
sk->sk_error_report(sk); sk->sk_error_report(sk);
release_sock(sk); release_sock(sk);
......
...@@ -708,7 +708,7 @@ static void virtio_transport_do_close(struct vsock_sock *vsk, ...@@ -708,7 +708,7 @@ static void virtio_transport_do_close(struct vsock_sock *vsk,
sock_set_flag(sk, SOCK_DONE); sock_set_flag(sk, SOCK_DONE);
vsk->peer_shutdown = SHUTDOWN_MASK; vsk->peer_shutdown = SHUTDOWN_MASK;
if (vsock_stream_has_data(vsk) <= 0) if (vsock_stream_has_data(vsk) <= 0)
sk->sk_state = SS_DISCONNECTING; sk->sk_state = TCP_CLOSING;
sk->sk_state_change(sk); sk->sk_state_change(sk);
if (vsk->close_work_scheduled && if (vsk->close_work_scheduled &&
...@@ -748,8 +748,8 @@ static bool virtio_transport_close(struct vsock_sock *vsk) ...@@ -748,8 +748,8 @@ static bool virtio_transport_close(struct vsock_sock *vsk)
{ {
struct sock *sk = &vsk->sk; struct sock *sk = &vsk->sk;
if (!(sk->sk_state == SS_CONNECTED || if (!(sk->sk_state == TCP_ESTABLISHED ||
sk->sk_state == SS_DISCONNECTING)) sk->sk_state == TCP_CLOSING))
return true; return true;
/* Already received SHUTDOWN from peer, reply with RST */ /* Already received SHUTDOWN from peer, reply with RST */
...@@ -801,7 +801,7 @@ virtio_transport_recv_connecting(struct sock *sk, ...@@ -801,7 +801,7 @@ virtio_transport_recv_connecting(struct sock *sk,
switch (le16_to_cpu(pkt->hdr.op)) { switch (le16_to_cpu(pkt->hdr.op)) {
case VIRTIO_VSOCK_OP_RESPONSE: case VIRTIO_VSOCK_OP_RESPONSE:
sk->sk_state = SS_CONNECTED; sk->sk_state = TCP_ESTABLISHED;
sk->sk_socket->state = SS_CONNECTED; sk->sk_socket->state = SS_CONNECTED;
vsock_insert_connected(vsk); vsock_insert_connected(vsk);
sk->sk_state_change(sk); sk->sk_state_change(sk);
...@@ -821,7 +821,7 @@ virtio_transport_recv_connecting(struct sock *sk, ...@@ -821,7 +821,7 @@ virtio_transport_recv_connecting(struct sock *sk,
destroy: destroy:
virtio_transport_reset(vsk, pkt); virtio_transport_reset(vsk, pkt);
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
sk->sk_err = skerr; sk->sk_err = skerr;
sk->sk_error_report(sk); sk->sk_error_report(sk);
return err; return err;
...@@ -857,7 +857,7 @@ virtio_transport_recv_connected(struct sock *sk, ...@@ -857,7 +857,7 @@ virtio_transport_recv_connected(struct sock *sk,
vsk->peer_shutdown |= SEND_SHUTDOWN; vsk->peer_shutdown |= SEND_SHUTDOWN;
if (vsk->peer_shutdown == SHUTDOWN_MASK && if (vsk->peer_shutdown == SHUTDOWN_MASK &&
vsock_stream_has_data(vsk) <= 0) vsock_stream_has_data(vsk) <= 0)
sk->sk_state = SS_DISCONNECTING; sk->sk_state = TCP_CLOSING;
if (le32_to_cpu(pkt->hdr.flags)) if (le32_to_cpu(pkt->hdr.flags))
sk->sk_state_change(sk); sk->sk_state_change(sk);
break; break;
...@@ -928,7 +928,7 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt) ...@@ -928,7 +928,7 @@ virtio_transport_recv_listen(struct sock *sk, struct virtio_vsock_pkt *pkt)
lock_sock_nested(child, SINGLE_DEPTH_NESTING); lock_sock_nested(child, SINGLE_DEPTH_NESTING);
child->sk_state = SS_CONNECTED; child->sk_state = TCP_ESTABLISHED;
vchild = vsock_sk(child); vchild = vsock_sk(child);
vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid), vsock_addr_init(&vchild->local_addr, le64_to_cpu(pkt->hdr.dst_cid),
...@@ -1016,18 +1016,18 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt) ...@@ -1016,18 +1016,18 @@ void virtio_transport_recv_pkt(struct virtio_vsock_pkt *pkt)
sk->sk_write_space(sk); sk->sk_write_space(sk);
switch (sk->sk_state) { switch (sk->sk_state) {
case VSOCK_SS_LISTEN: case TCP_LISTEN:
virtio_transport_recv_listen(sk, pkt); virtio_transport_recv_listen(sk, pkt);
virtio_transport_free_pkt(pkt); virtio_transport_free_pkt(pkt);
break; break;
case SS_CONNECTING: case TCP_SYN_SENT:
virtio_transport_recv_connecting(sk, pkt); virtio_transport_recv_connecting(sk, pkt);
virtio_transport_free_pkt(pkt); virtio_transport_free_pkt(pkt);
break; break;
case SS_CONNECTED: case TCP_ESTABLISHED:
virtio_transport_recv_connected(sk, pkt); virtio_transport_recv_connected(sk, pkt);
break; break;
case SS_DISCONNECTING: case TCP_CLOSING:
virtio_transport_recv_disconnecting(sk, pkt); virtio_transport_recv_disconnecting(sk, pkt);
virtio_transport_free_pkt(pkt); virtio_transport_free_pkt(pkt);
break; break;
......
...@@ -742,7 +742,7 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg) ...@@ -742,7 +742,7 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)
/* The local context ID may be out of date, update it. */ /* The local context ID may be out of date, update it. */
vsk->local_addr.svm_cid = dst.svm_cid; vsk->local_addr.svm_cid = dst.svm_cid;
if (sk->sk_state == SS_CONNECTED) if (sk->sk_state == TCP_ESTABLISHED)
vmci_trans(vsk)->notify_ops->handle_notify_pkt( vmci_trans(vsk)->notify_ops->handle_notify_pkt(
sk, pkt, true, &dst, &src, sk, pkt, true, &dst, &src,
&bh_process_pkt); &bh_process_pkt);
...@@ -800,7 +800,9 @@ static void vmci_transport_handle_detach(struct sock *sk) ...@@ -800,7 +800,9 @@ static void vmci_transport_handle_detach(struct sock *sk)
* left in our consume queue. * left in our consume queue.
*/ */
if (vsock_stream_has_data(vsk) <= 0) { if (vsock_stream_has_data(vsk) <= 0) {
if (sk->sk_state == SS_CONNECTING) { sk->sk_state = TCP_CLOSE;
if (sk->sk_state == TCP_SYN_SENT) {
/* The peer may detach from a queue pair while /* The peer may detach from a queue pair while
* we are still in the connecting state, i.e., * we are still in the connecting state, i.e.,
* if the peer VM is killed after attaching to * if the peer VM is killed after attaching to
...@@ -809,12 +811,10 @@ static void vmci_transport_handle_detach(struct sock *sk) ...@@ -809,12 +811,10 @@ static void vmci_transport_handle_detach(struct sock *sk)
* event like a reset. * event like a reset.
*/ */
sk->sk_state = SS_UNCONNECTED;
sk->sk_err = ECONNRESET; sk->sk_err = ECONNRESET;
sk->sk_error_report(sk); sk->sk_error_report(sk);
return; return;
} }
sk->sk_state = SS_UNCONNECTED;
} }
sk->sk_state_change(sk); sk->sk_state_change(sk);
} }
...@@ -882,17 +882,17 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work) ...@@ -882,17 +882,17 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work)
vsock_sk(sk)->local_addr.svm_cid = pkt->dg.dst.context; vsock_sk(sk)->local_addr.svm_cid = pkt->dg.dst.context;
switch (sk->sk_state) { switch (sk->sk_state) {
case VSOCK_SS_LISTEN: case TCP_LISTEN:
vmci_transport_recv_listen(sk, pkt); vmci_transport_recv_listen(sk, pkt);
break; break;
case SS_CONNECTING: case TCP_SYN_SENT:
/* Processing of pending connections for servers goes through /* Processing of pending connections for servers goes through
* the listening socket, so see vmci_transport_recv_listen() * the listening socket, so see vmci_transport_recv_listen()
* for that path. * for that path.
*/ */
vmci_transport_recv_connecting_client(sk, pkt); vmci_transport_recv_connecting_client(sk, pkt);
break; break;
case SS_CONNECTED: case TCP_ESTABLISHED:
vmci_transport_recv_connected(sk, pkt); vmci_transport_recv_connected(sk, pkt);
break; break;
default: default:
...@@ -941,7 +941,7 @@ static int vmci_transport_recv_listen(struct sock *sk, ...@@ -941,7 +941,7 @@ static int vmci_transport_recv_listen(struct sock *sk,
vsock_sk(pending)->local_addr.svm_cid = pkt->dg.dst.context; vsock_sk(pending)->local_addr.svm_cid = pkt->dg.dst.context;
switch (pending->sk_state) { switch (pending->sk_state) {
case SS_CONNECTING: case TCP_SYN_SENT:
err = vmci_transport_recv_connecting_server(sk, err = vmci_transport_recv_connecting_server(sk,
pending, pending,
pkt); pkt);
...@@ -1071,7 +1071,7 @@ static int vmci_transport_recv_listen(struct sock *sk, ...@@ -1071,7 +1071,7 @@ static int vmci_transport_recv_listen(struct sock *sk,
vsock_add_pending(sk, pending); vsock_add_pending(sk, pending);
sk->sk_ack_backlog++; sk->sk_ack_backlog++;
pending->sk_state = SS_CONNECTING; pending->sk_state = TCP_SYN_SENT;
vmci_trans(vpending)->produce_size = vmci_trans(vpending)->produce_size =
vmci_trans(vpending)->consume_size = qp_size; vmci_trans(vpending)->consume_size = qp_size;
vmci_trans(vpending)->queue_pair_size = qp_size; vmci_trans(vpending)->queue_pair_size = qp_size;
...@@ -1196,11 +1196,11 @@ vmci_transport_recv_connecting_server(struct sock *listener, ...@@ -1196,11 +1196,11 @@ vmci_transport_recv_connecting_server(struct sock *listener,
* the socket will be valid until it is removed from the queue. * the socket will be valid until it is removed from the queue.
* *
* If we fail sending the attach below, we remove the socket from the * If we fail sending the attach below, we remove the socket from the
* connected list and move the socket to SS_UNCONNECTED before * connected list and move the socket to TCP_CLOSE before
* releasing the lock, so a pending slow path processing of an incoming * releasing the lock, so a pending slow path processing of an incoming
* packet will not see the socket in the connected state in that case. * packet will not see the socket in the connected state in that case.
*/ */
pending->sk_state = SS_CONNECTED; pending->sk_state = TCP_ESTABLISHED;
vsock_insert_connected(vpending); vsock_insert_connected(vpending);
...@@ -1231,7 +1231,7 @@ vmci_transport_recv_connecting_server(struct sock *listener, ...@@ -1231,7 +1231,7 @@ vmci_transport_recv_connecting_server(struct sock *listener,
destroy: destroy:
pending->sk_err = skerr; pending->sk_err = skerr;
pending->sk_state = SS_UNCONNECTED; pending->sk_state = TCP_CLOSE;
/* As long as we drop our reference, all necessary cleanup will handle /* As long as we drop our reference, all necessary cleanup will handle
* when the cleanup function drops its reference and our destruct * when the cleanup function drops its reference and our destruct
* implementation is called. Note that since the listen handler will * implementation is called. Note that since the listen handler will
...@@ -1269,7 +1269,7 @@ vmci_transport_recv_connecting_client(struct sock *sk, ...@@ -1269,7 +1269,7 @@ vmci_transport_recv_connecting_client(struct sock *sk,
* accounting (it can already be found since it's in the bound * accounting (it can already be found since it's in the bound
* table). * table).
*/ */
sk->sk_state = SS_CONNECTED; sk->sk_state = TCP_ESTABLISHED;
sk->sk_socket->state = SS_CONNECTED; sk->sk_socket->state = SS_CONNECTED;
vsock_insert_connected(vsk); vsock_insert_connected(vsk);
sk->sk_state_change(sk); sk->sk_state_change(sk);
...@@ -1337,7 +1337,7 @@ vmci_transport_recv_connecting_client(struct sock *sk, ...@@ -1337,7 +1337,7 @@ vmci_transport_recv_connecting_client(struct sock *sk,
destroy: destroy:
vmci_transport_send_reset(sk, pkt); vmci_transport_send_reset(sk, pkt);
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
sk->sk_err = skerr; sk->sk_err = skerr;
sk->sk_error_report(sk); sk->sk_error_report(sk);
return err; return err;
...@@ -1525,7 +1525,7 @@ static int vmci_transport_recv_connected(struct sock *sk, ...@@ -1525,7 +1525,7 @@ static int vmci_transport_recv_connected(struct sock *sk,
sock_set_flag(sk, SOCK_DONE); sock_set_flag(sk, SOCK_DONE);
vsk->peer_shutdown = SHUTDOWN_MASK; vsk->peer_shutdown = SHUTDOWN_MASK;
if (vsock_stream_has_data(vsk) <= 0) if (vsock_stream_has_data(vsk) <= 0)
sk->sk_state = SS_DISCONNECTING; sk->sk_state = TCP_CLOSING;
sk->sk_state_change(sk); sk->sk_state_change(sk);
break; break;
...@@ -1789,7 +1789,7 @@ static int vmci_transport_connect(struct vsock_sock *vsk) ...@@ -1789,7 +1789,7 @@ static int vmci_transport_connect(struct vsock_sock *vsk)
err = vmci_transport_send_conn_request( err = vmci_transport_send_conn_request(
sk, vmci_trans(vsk)->queue_pair_size); sk, vmci_trans(vsk)->queue_pair_size);
if (err < 0) { if (err < 0) {
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
return err; return err;
} }
} else { } else {
...@@ -1799,7 +1799,7 @@ static int vmci_transport_connect(struct vsock_sock *vsk) ...@@ -1799,7 +1799,7 @@ static int vmci_transport_connect(struct vsock_sock *vsk)
sk, vmci_trans(vsk)->queue_pair_size, sk, vmci_trans(vsk)->queue_pair_size,
supported_proto_versions); supported_proto_versions);
if (err < 0) { if (err < 0) {
sk->sk_state = SS_UNCONNECTED; sk->sk_state = TCP_CLOSE;
return err; return err;
} }
......
...@@ -355,7 +355,7 @@ vmci_transport_notify_pkt_poll_in(struct sock *sk, ...@@ -355,7 +355,7 @@ vmci_transport_notify_pkt_poll_in(struct sock *sk,
* queue. Ask for notifications when there is something to * queue. Ask for notifications when there is something to
* read. * read.
*/ */
if (sk->sk_state == SS_CONNECTED) { if (sk->sk_state == TCP_ESTABLISHED) {
if (!send_waiting_read(sk, 1)) if (!send_waiting_read(sk, 1))
return -1; return -1;
......
...@@ -176,7 +176,7 @@ vmci_transport_notify_pkt_poll_in(struct sock *sk, ...@@ -176,7 +176,7 @@ vmci_transport_notify_pkt_poll_in(struct sock *sk,
* queue. Ask for notifications when there is something to * queue. Ask for notifications when there is something to
* read. * read.
*/ */
if (sk->sk_state == SS_CONNECTED) if (sk->sk_state == TCP_ESTABLISHED)
vsock_block_update_write_window(sk); vsock_block_update_write_window(sk);
*data_ready_now = false; *data_ready_now = false;
} }
......
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