vsock: introduce vsock_pending_to_accept() helper

Add vsock_pending_to_accept() to move a socket directly from the
pending list to the accept queue in a single operation, avoiding
the sock_put/sock_hold dance and the sk_acceptq_removed()/
sk_acceptq_added() pair that would otherwise be needed when
calling vsock_remove_pending() followed by vsock_enqueue_accept().

Use it in vmci_transport_recv_connecting_server() where a completed
handshake transitions the socket from pending to accept queue.

Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Raf Dickson <rafdog35@gmail.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>
Link: https://patch.msgid.link/20260612045216.105796-2-rafdog35@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Raf Dickson
2026-06-12 04:52:13 +00:00
committed by Jakub Kicinski
parent 4ff2e84ff1
commit 77eee18939
3 changed files with 12 additions and 2 deletions
+1
View File
@@ -220,6 +220,7 @@ static inline bool __vsock_in_connected_table(struct vsock_sock *vsk)
void vsock_add_pending(struct sock *listener, struct sock *pending);
void vsock_remove_pending(struct sock *listener, struct sock *pending);
void vsock_enqueue_accept(struct sock *listener, struct sock *connected);
void vsock_pending_to_accept(struct sock *listener, struct sock *pending);
void vsock_insert_connected(struct vsock_sock *vsk);
void vsock_remove_bound(struct vsock_sock *vsk);
void vsock_remove_connected(struct vsock_sock *vsk);
+10
View File
@@ -497,6 +497,16 @@ void vsock_remove_pending(struct sock *listener, struct sock *pending)
}
EXPORT_SYMBOL_GPL(vsock_remove_pending);
void vsock_pending_to_accept(struct sock *listener, struct sock *pending)
{
struct vsock_sock *vpending = vsock_sk(pending);
struct vsock_sock *vlistener = vsock_sk(listener);
list_del_init(&vpending->pending_links);
list_add_tail(&vpending->accept_queue, &vlistener->accept_queue);
}
EXPORT_SYMBOL_GPL(vsock_pending_to_accept);
void vsock_enqueue_accept(struct sock *listener, struct sock *connected)
{
struct vsock_sock *vlistener;
+1 -2
View File
@@ -1258,8 +1258,7 @@ vmci_transport_recv_connecting_server(struct sock *listener,
* listener's pending list to the accept queue so callers of accept()
* can find it.
*/
vsock_remove_pending(listener, pending);
vsock_enqueue_accept(listener, pending);
vsock_pending_to_accept(listener, pending);
/* Callers of accept() will be waiting on the listening socket, not
* the pending socket.