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

VSOCK: define VSOCK_SS_LISTEN once only

The SS_LISTEN socket state is defined by both af_vsock.c and
vmci_transport.c.  This is risky since the value could be changed in one
file and the other would be out of sync.

Rename from SS_LISTEN to VSOCK_SS_LISTEN since the constant is not part
of enum socket_state (SS_CONNECTED, ...).  This way it is clear that the
constant is vsock-specific.

The big text reflow in af_vsock.c was necessary to keep to the maximum
line length.  Text is unchanged except for s/SS_LISTEN/VSOCK_SS_LISTEN/.
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 24c39de0
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
#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_sk(__sk) ((struct vsock_sock *)__sk) #define vsock_sk(__sk) ((struct vsock_sock *)__sk)
......
...@@ -36,19 +36,20 @@ ...@@ -36,19 +36,20 @@
* 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 SS_LISTEN state. When a connection * implementation because they are in the VSOCK_SS_LISTEN state. When a
* request is received (the second kind of socket mentioned above), we create a * connection request is received (the second kind of socket mentioned above),
* new socket and refer to it as a pending socket. These pending sockets are * we create a new socket and refer to it as a pending socket. These pending
* placed on the pending connection list of the listener socket. When future * sockets are placed on the pending connection list of the listener socket.
* packets are received for the address the listener socket is bound to, we * When future packets are received for the address the listener socket is
* check if the source of the packet is from one that has an existing pending * bound to, we check if the source of the packet is from one that has an
* connection. If it does, we process the packet for the pending socket. When * existing pending connection. If it does, we process the packet for the
* that socket reaches the connected state, it is removed from the listener * pending socket. When that socket reaches the connected state, it is removed
* socket's pending list and enqueued in the listener socket's accept queue. * from the listener socket's pending list and enqueued in the listener
* Callers of accept(2) will accept connected sockets from the listener socket's * socket's accept queue. Callers of accept(2) will accept connected sockets
* accept queue. If the socket cannot be accepted for some reason then it is * from the listener socket's accept queue. If the socket cannot be accepted
* marked rejected. Once the connection is accepted, it is owned by the user * for some reason then it is marked rejected. Once the connection is
* process and the responsibility for cleanup falls with that user process. * accepted, it is owned by the user process and the responsibility for cleanup
* falls with that user process.
* *
* - It is possible that these pending sockets will never reach the connected * - It is possible that these pending sockets will never reach the connected
* state; in fact, we may never receive another packet after the connection * state; in fact, we may never receive another packet after the connection
...@@ -114,8 +115,6 @@ static struct proto vsock_proto = { ...@@ -114,8 +115,6 @@ static struct proto vsock_proto = {
*/ */
#define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ) #define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ)
#define SS_LISTEN 255
static const struct vsock_transport *transport; static const struct vsock_transport *transport;
static DEFINE_MUTEX(vsock_register_mutex); static DEFINE_MUTEX(vsock_register_mutex);
...@@ -887,7 +886,7 @@ static unsigned int vsock_poll(struct file *file, struct socket *sock, ...@@ -887,7 +886,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 == SS_LISTEN if (sk->sk_state == VSOCK_SS_LISTEN
&& !vsock_is_accept_queue_empty(sk)) && !vsock_is_accept_queue_empty(sk))
mask |= POLLIN | POLLRDNORM; mask |= POLLIN | POLLRDNORM;
...@@ -1144,7 +1143,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1144,7 +1143,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
err = -EALREADY; err = -EALREADY;
break; break;
default: default:
if ((sk->sk_state == SS_LISTEN) || if ((sk->sk_state == VSOCK_SS_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;
...@@ -1256,7 +1255,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags) ...@@ -1256,7 +1255,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags)
goto out; goto out;
} }
if (listener->sk_state != SS_LISTEN) { if (listener->sk_state != VSOCK_SS_LISTEN) {
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
...@@ -1348,7 +1347,7 @@ static int vsock_listen(struct socket *sock, int backlog) ...@@ -1348,7 +1347,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 = SS_LISTEN; sk->sk_state = VSOCK_SS_LISTEN;
err = 0; err = 0;
......
...@@ -92,8 +92,6 @@ static int PROTOCOL_OVERRIDE = -1; ...@@ -92,8 +92,6 @@ static int PROTOCOL_OVERRIDE = -1;
*/ */
#define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ) #define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ)
#define SS_LISTEN 255
/* Helper function to convert from a VMCI error code to a VSock error code. */ /* Helper function to convert from a VMCI error code to a VSock error code. */
static s32 vmci_transport_error_to_vsock_error(s32 vmci_error) static s32 vmci_transport_error_to_vsock_error(s32 vmci_error)
...@@ -893,7 +891,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work) ...@@ -893,7 +891,7 @@ 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 SS_LISTEN: case VSOCK_SS_LISTEN:
vmci_transport_recv_listen(sk, pkt); vmci_transport_recv_listen(sk, pkt);
break; break;
case SS_CONNECTING: case SS_CONNECTING:
......
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