Skip to content

Commit 1c39f5d

Browse files
mmhalPaolo Abeni
authored andcommitted
vsock/virtio: Linger on unsent data
Currently vsock's lingering effectively boils down to waiting (or timing out) until packets are consumed or dropped by the peer; be it by receiving the data, closing or shutting down the connection. To align with the semantics described in the SO_LINGER section of man socket(7) and to mimic AF_INET's behaviour more closely, change the logic of a lingering close(): instead of waiting for all data to be handled, block until data is considered sent from the vsock's transport point of view. That is until worker picks the packets for processing and decrements virtio_vsock_sock::bytes_unsent down to 0. Note that (some interpretation of) lingering was always limited to transports that called virtio_transport_wait_close() on transport release. This does not change, i.e. under Hyper-V and VMCI no lingering would be observed. The implementation does not adhere strictly to man page's interpretation of SO_LINGER: shutdown() will not trigger the lingering. This follows AF_INET. Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Michal Luczaj <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent b2908a9 commit 1c39f5d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/vmw_vsock/virtio_transport_common.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,12 +1195,14 @@ static void virtio_transport_wait_close(struct sock *sk, long timeout)
11951195
{
11961196
if (timeout) {
11971197
DEFINE_WAIT_FUNC(wait, woken_wake_function);
1198+
struct vsock_sock *vsk = vsock_sk(sk);
11981199

11991200
add_wait_queue(sk_sleep(sk), &wait);
12001201

12011202
do {
12021203
if (sk_wait_event(sk, &timeout,
1203-
sock_flag(sk, SOCK_DONE), &wait))
1204+
virtio_transport_unsent_bytes(vsk) == 0,
1205+
&wait))
12041206
break;
12051207
} while (!signal_pending(current) && timeout);
12061208

0 commit comments

Comments
 (0)