Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

VSOCK: defer sock removal to transports

The virtio transport will implement graceful shutdown and the related
SO_LINGER socket option. This requires orphaning the sock but keeping
it in the table of connections after .release().

This patch adds the vsock_remove_sock() function and leaves it up to the
transport when to remove the sock.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Stefan Hajnoczi and committed by
Michael S. Tsirkin
6773b7dc 0b01aeb3

+13 -6
+1
include/net/af_vsock.h
··· 180 180 struct sock *vsock_find_bound_socket(struct sockaddr_vm *addr); 181 181 struct sock *vsock_find_connected_socket(struct sockaddr_vm *src, 182 182 struct sockaddr_vm *dst); 183 + void vsock_remove_sock(struct vsock_sock *vsk); 183 184 void vsock_for_each_connected_socket(void (*fn)(struct sock *sk)); 184 185 185 186 #endif /* __AF_VSOCK_H__ */
+10 -6
net/vmw_vsock/af_vsock.c
··· 344 344 return ret; 345 345 } 346 346 347 + void vsock_remove_sock(struct vsock_sock *vsk) 348 + { 349 + if (vsock_in_bound_table(vsk)) 350 + vsock_remove_bound(vsk); 351 + 352 + if (vsock_in_connected_table(vsk)) 353 + vsock_remove_connected(vsk); 354 + } 355 + EXPORT_SYMBOL_GPL(vsock_remove_sock); 356 + 347 357 void vsock_for_each_connected_socket(void (*fn)(struct sock *sk)) 348 358 { 349 359 int i; ··· 669 659 670 660 vsk = vsock_sk(sk); 671 661 pending = NULL; /* Compiler warning. */ 672 - 673 - if (vsock_in_bound_table(vsk)) 674 - vsock_remove_bound(vsk); 675 - 676 - if (vsock_in_connected_table(vsk)) 677 - vsock_remove_connected(vsk); 678 662 679 663 transport->release(vsk); 680 664
+2
net/vmw_vsock/vmci_transport.c
··· 1644 1644 1645 1645 static void vmci_transport_release(struct vsock_sock *vsk) 1646 1646 { 1647 + vsock_remove_sock(vsk); 1648 + 1647 1649 if (!vmci_handle_is_invalid(vmci_trans(vsk)->dg_handle)) { 1648 1650 vmci_datagram_destroy_handle(vmci_trans(vsk)->dg_handle); 1649 1651 vmci_trans(vsk)->dg_handle = VMCI_INVALID_HANDLE;