diff options
| author | Stefan Hajnoczi <stefanha@redhat.com> | 2015-10-29 07:57:42 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2015-11-01 12:14:47 -0500 |
| commit | ea3803c193df18d8353d6c8d77034066a08c19f5 (patch) | |
| tree | 9af9acb0d01bd0190ccb035b0c1a21508cbc0af6 | |
| parent | 24c39de0091197f4c1f1a18a7c31e540000dc3b8 (diff) | |
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: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | include/net/af_vsock.h | 3 | ||||
| -rw-r--r-- | net/vmw_vsock/af_vsock.c | 37 | ||||
| -rw-r--r-- | net/vmw_vsock/vmci_transport.c | 4 |
3 files changed, 22 insertions, 22 deletions
diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h index db639a4c5ab8..e9eb2d6791b3 100644 --- a/include/net/af_vsock.h +++ b/include/net/af_vsock.h | |||
| @@ -22,6 +22,9 @@ | |||
| 22 | 22 | ||
| 23 | #include "vsock_addr.h" | 23 | #include "vsock_addr.h" |
| 24 | 24 | ||
| 25 | /* vsock-specific sock->sk_state constants */ | ||
| 26 | #define VSOCK_SS_LISTEN 255 | ||
| 27 | |||
| 25 | #define LAST_RESERVED_PORT 1023 | 28 | #define LAST_RESERVED_PORT 1023 |
| 26 | 29 | ||
| 27 | #define vsock_sk(__sk) ((struct vsock_sock *)__sk) | 30 | #define vsock_sk(__sk) ((struct vsock_sock *)__sk) |
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index 00e8a349aabc..7fd1220fbfa0 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c | |||
| @@ -36,19 +36,20 @@ | |||
| 36 | * not support simultaneous connects (two "client" sockets connecting). | 36 | * not support simultaneous connects (two "client" sockets connecting). |
| 37 | * | 37 | * |
| 38 | * - "Server" sockets are referred to as listener sockets throughout this | 38 | * - "Server" sockets are referred to as listener sockets throughout this |
| 39 | * implementation because they are in the SS_LISTEN state. When a connection | 39 | * implementation because they are in the VSOCK_SS_LISTEN state. When a |
| 40 | * request is received (the second kind of socket mentioned above), we create a | 40 | * connection request is received (the second kind of socket mentioned above), |
| 41 | * new socket and refer to it as a pending socket. These pending sockets are | 41 | * we create a new socket and refer to it as a pending socket. These pending |
| 42 | * placed on the pending connection list of the listener socket. When future | 42 | * sockets are placed on the pending connection list of the listener socket. |
| 43 | * packets are received for the address the listener socket is bound to, we | 43 | * When future packets are received for the address the listener socket is |
| 44 | * check if the source of the packet is from one that has an existing pending | 44 | * bound to, we check if the source of the packet is from one that has an |
| 45 | * connection. If it does, we process the packet for the pending socket. When | 45 | * existing pending connection. If it does, we process the packet for the |
| 46 | * that socket reaches the connected state, it is removed from the listener | 46 | * pending socket. When that socket reaches the connected state, it is removed |
| 47 | * socket's pending list and enqueued in the listener socket's accept queue. | 47 | * from the listener socket's pending list and enqueued in the listener |
| 48 | * Callers of accept(2) will accept connected sockets from the listener socket's | 48 | * socket's accept queue. Callers of accept(2) will accept connected sockets |
| 49 | * accept queue. If the socket cannot be accepted for some reason then it is | 49 | * from the listener socket's accept queue. If the socket cannot be accepted |
| 50 | * marked rejected. Once the connection is accepted, it is owned by the user | 50 | * for some reason then it is marked rejected. Once the connection is |
| 51 | * process and the responsibility for cleanup falls with that user process. | 51 | * accepted, it is owned by the user process and the responsibility for cleanup |
| 52 | * falls with that user process. | ||
| 52 | * | 53 | * |
| 53 | * - It is possible that these pending sockets will never reach the connected | 54 | * - It is possible that these pending sockets will never reach the connected |
| 54 | * state; in fact, we may never receive another packet after the connection | 55 | * state; in fact, we may never receive another packet after the connection |
| @@ -114,8 +115,6 @@ static struct proto vsock_proto = { | |||
| 114 | */ | 115 | */ |
| 115 | #define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ) | 116 | #define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ) |
| 116 | 117 | ||
| 117 | #define SS_LISTEN 255 | ||
| 118 | |||
| 119 | static const struct vsock_transport *transport; | 118 | static const struct vsock_transport *transport; |
| 120 | static DEFINE_MUTEX(vsock_register_mutex); | 119 | static DEFINE_MUTEX(vsock_register_mutex); |
| 121 | 120 | ||
| @@ -887,7 +886,7 @@ static unsigned int vsock_poll(struct file *file, struct socket *sock, | |||
| 887 | /* Listening sockets that have connections in their accept | 886 | /* Listening sockets that have connections in their accept |
| 888 | * queue can be read. | 887 | * queue can be read. |
| 889 | */ | 888 | */ |
| 890 | if (sk->sk_state == SS_LISTEN | 889 | if (sk->sk_state == VSOCK_SS_LISTEN |
| 891 | && !vsock_is_accept_queue_empty(sk)) | 890 | && !vsock_is_accept_queue_empty(sk)) |
| 892 | mask |= POLLIN | POLLRDNORM; | 891 | mask |= POLLIN | POLLRDNORM; |
| 893 | 892 | ||
| @@ -1144,7 +1143,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, | |||
| 1144 | err = -EALREADY; | 1143 | err = -EALREADY; |
| 1145 | break; | 1144 | break; |
| 1146 | default: | 1145 | default: |
| 1147 | if ((sk->sk_state == SS_LISTEN) || | 1146 | if ((sk->sk_state == VSOCK_SS_LISTEN) || |
| 1148 | vsock_addr_cast(addr, addr_len, &remote_addr) != 0) { | 1147 | vsock_addr_cast(addr, addr_len, &remote_addr) != 0) { |
| 1149 | err = -EINVAL; | 1148 | err = -EINVAL; |
| 1150 | goto out; | 1149 | goto out; |
| @@ -1256,7 +1255,7 @@ static int vsock_accept(struct socket *sock, struct socket *newsock, int flags) | |||
| 1256 | goto out; | 1255 | goto out; |
| 1257 | } | 1256 | } |
| 1258 | 1257 | ||
| 1259 | if (listener->sk_state != SS_LISTEN) { | 1258 | if (listener->sk_state != VSOCK_SS_LISTEN) { |
| 1260 | err = -EINVAL; | 1259 | err = -EINVAL; |
| 1261 | goto out; | 1260 | goto out; |
| 1262 | } | 1261 | } |
| @@ -1348,7 +1347,7 @@ static int vsock_listen(struct socket *sock, int backlog) | |||
| 1348 | } | 1347 | } |
| 1349 | 1348 | ||
| 1350 | sk->sk_max_ack_backlog = backlog; | 1349 | sk->sk_max_ack_backlog = backlog; |
| 1351 | sk->sk_state = SS_LISTEN; | 1350 | sk->sk_state = VSOCK_SS_LISTEN; |
| 1352 | 1351 | ||
| 1353 | err = 0; | 1352 | err = 0; |
| 1354 | 1353 | ||
diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c index 7555cad83a75..400d87294de3 100644 --- a/net/vmw_vsock/vmci_transport.c +++ b/net/vmw_vsock/vmci_transport.c | |||
| @@ -92,8 +92,6 @@ static int PROTOCOL_OVERRIDE = -1; | |||
| 92 | */ | 92 | */ |
| 93 | #define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ) | 93 | #define VSOCK_DEFAULT_CONNECT_TIMEOUT (2 * HZ) |
| 94 | 94 | ||
| 95 | #define SS_LISTEN 255 | ||
| 96 | |||
| 97 | /* Helper function to convert from a VMCI error code to a VSock error code. */ | 95 | /* Helper function to convert from a VMCI error code to a VSock error code. */ |
| 98 | 96 | ||
| 99 | static s32 vmci_transport_error_to_vsock_error(s32 vmci_error) | 97 | 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 | vsock_sk(sk)->local_addr.svm_cid = pkt->dg.dst.context; | 891 | vsock_sk(sk)->local_addr.svm_cid = pkt->dg.dst.context; |
| 894 | 892 | ||
| 895 | switch (sk->sk_state) { | 893 | switch (sk->sk_state) { |
| 896 | case SS_LISTEN: | 894 | case VSOCK_SS_LISTEN: |
| 897 | vmci_transport_recv_listen(sk, pkt); | 895 | vmci_transport_recv_listen(sk, pkt); |
| 898 | break; | 896 | break; |
| 899 | case SS_CONNECTING: | 897 | case SS_CONNECTING: |
