Skip to content

Commit

Permalink
af_vsock: implement send logic for SEQPACKET
Browse files Browse the repository at this point in the history
Update current stream enqueue function for SEQPACKET
support:
1) Call transport's seqpacket enqueue callback.
2) Return value from enqueue function is whole record length or error
   for SOCK_SEQPACKET.

Signed-off-by: Arseny Krasnov <arseny.krasnov@kaspersky.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Arseny Krasnov authored and davem330 committed Jun 11, 2021
1 parent 9942c19 commit fbe70c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/net/af_vsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ struct vsock_transport {
/* SEQ_PACKET. */
ssize_t (*seqpacket_dequeue)(struct vsock_sock *vsk, struct msghdr *msg,
int flags);
int (*seqpacket_enqueue)(struct vsock_sock *vsk, struct msghdr *msg,
size_t len);

/* Notification. */
int (*notify_poll_in)(struct vsock_sock *, size_t, bool *);
Expand Down
20 changes: 15 additions & 5 deletions net/vmw_vsock/af_vsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1808,9 +1808,13 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
* responsibility to check how many bytes we were able to send.
*/

written = transport->stream_enqueue(
vsk, msg,
len - total_written);
if (sk->sk_type == SOCK_SEQPACKET) {
written = transport->seqpacket_enqueue(vsk,
msg, len - total_written);
} else {
written = transport->stream_enqueue(vsk,
msg, len - total_written);
}
if (written < 0) {
err = -ENOMEM;
goto out_err;
Expand All @@ -1826,8 +1830,14 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
}

out_err:
if (total_written > 0)
err = total_written;
if (total_written > 0) {
/* Return number of written bytes only if:
* 1) SOCK_STREAM socket.
* 2) SOCK_SEQPACKET socket when whole buffer is sent.
*/
if (sk->sk_type == SOCK_STREAM || total_written == len)
err = total_written;
}
out:
release_sock(sk);
return err;
Expand Down

0 comments on commit fbe70c4

Please sign in to comment.