Skip to content

Commit 3e09a8c

Browse files
mmhalNipaLocal
authored andcommitted
vsock: 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 such lingering is limited to transports that actually implement vsock_transport::unsent_bytes() callback. This excludes Hyper-V and VMCI, under which 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. Signed-off-by: Michal Luczaj <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 5b5e1c2 commit 3e09a8c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

net/vmw_vsock/virtio_transport_common.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,21 @@ static void virtio_transport_wait_close(struct sock *sk, long timeout)
11961196
{
11971197
if (timeout) {
11981198
DEFINE_WAIT_FUNC(wait, woken_wake_function);
1199+
ssize_t (*unsent)(struct vsock_sock *vsk);
1200+
struct vsock_sock *vsk = vsock_sk(sk);
1201+
1202+
/* Some transports (Hyper-V, VMCI) do not implement
1203+
* unsent_bytes. For those, no lingering on close().
1204+
*/
1205+
unsent = vsk->transport->unsent_bytes;
1206+
if (!unsent)
1207+
return;
11991208

12001209
add_wait_queue(sk_sleep(sk), &wait);
12011210

12021211
do {
1203-
if (sk_wait_event(sk, &timeout,
1204-
sock_flag(sk, SOCK_DONE), &wait))
1212+
if (sk_wait_event(sk, &timeout, unsent(vsk) == 0,
1213+
&wait))
12051214
break;
12061215
} while (!signal_pending(current) && timeout);
12071216

0 commit comments

Comments
 (0)