kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arseny Krasnov <arseny.krasnov@kaspersky.com>
To: Stefan Hajnoczi <stefanha@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Arseny Krasnov <arseny.krasnov@kaspersky.com>,
	Jorgen Hansen <jhansen@vmware.com>,
	Andra Paraschiv <andraprs@amazon.com>,
	Colin Ian King <colin.king@canonical.com>,
	Norbert Slusarek <nslusarek@gmx.net>
Cc: <kvm@vger.kernel.org>,
	<virtualization@lists.linux-foundation.org>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<stsp2@yandex.ru>, <oxffffaa@gmail.com>
Subject: [RFC PATCH v6 06/22] af_vsock: implement send logic for SEQPACKET
Date: Sun, 7 Mar 2021 21:00:26 +0300	[thread overview]
Message-ID: <20210307180030.3465161-1-arseny.krasnov@kaspersky.com> (raw)
In-Reply-To: <20210307175722.3464068-1-arseny.krasnov@kaspersky.com>

This adds some logic to current stream enqueue function for SEQPACKET
support:
1) Use 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>
---
 include/net/af_vsock.h   |  2 ++
 net/vmw_vsock/af_vsock.c | 22 ++++++++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
index a8c4039e40cf..aed306292ab3 100644
--- a/include/net/af_vsock.h
+++ b/include/net/af_vsock.h
@@ -139,6 +139,8 @@ struct vsock_transport {
 	size_t (*seqpacket_seq_get_len)(struct vsock_sock *vsk);
 	int (*seqpacket_dequeue)(struct vsock_sock *vsk, struct msghdr *msg,
 				 int flags, bool *msg_ready);
+	int (*seqpacket_enqueue)(struct vsock_sock *vsk, struct msghdr *msg,
+				 int flags, size_t len);
 
 	/* Notification. */
 	int (*notify_poll_in)(struct vsock_sock *, size_t, bool *);
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 5bf64a3e678a..a031f165494d 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1830,9 +1830,14 @@ 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, msg->msg_flags,
+						len - total_written);
+		} else {
+			written = transport->stream_enqueue(vsk,
+					msg, len - total_written);
+		}
 		if (written < 0) {
 			err = -ENOMEM;
 			goto out_err;
@@ -1844,12 +1849,17 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
 				vsk, written, &send_data);
 		if (err < 0)
 			goto out_err;
-
 	}
 
 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;
-- 
2.25.1


  parent reply	other threads:[~2021-03-07 18:01 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-07 17:57 [RFC PATCH v6 00/22] virtio/vsock: introduce SOCK_SEQPACKET support Arseny Krasnov
2021-03-07 17:58 ` [RFC PATCH v6 01/22] af_vsock: update functions for connectible socket Arseny Krasnov
2021-03-12 14:38   ` Stefano Garzarella
2021-03-07 17:59 ` [RFC PATCH v6 02/22] af_vsock: separate wait data loop Arseny Krasnov
2021-03-12 14:40   ` Stefano Garzarella
2021-03-07 17:59 ` [RFC PATCH v6 03/22] af_vsock: separate receive " Arseny Krasnov
2021-03-07 17:59 ` [RFC PATCH v6 04/22] af_vsock: implement SEQPACKET receive loop Arseny Krasnov
2021-03-12 15:01   ` Stefano Garzarella
2021-03-12 15:17   ` Stefano Garzarella
2021-03-15  7:49     ` Arseny Krasnov
2021-03-07 17:59 ` [RFC PATCH v6 05/22] af_vsock: separate wait space loop Arseny Krasnov
2021-03-07 18:00 ` Arseny Krasnov [this message]
2021-03-12 15:10   ` [RFC PATCH v6 06/22] af_vsock: implement send logic for SEQPACKET Stefano Garzarella
2021-03-15  7:49     ` Arseny Krasnov
2021-03-07 18:00 ` [RFC PATCH v6 07/22] af_vsock: rest of SEQPACKET support Arseny Krasnov
2021-03-12 15:28   ` Stefano Garzarella
2021-03-07 18:01 ` [RFC PATCH v6 08/22] af_vsock: update comments for stream sockets Arseny Krasnov
2021-03-12 15:29   ` Stefano Garzarella
2021-03-07 18:01 ` [RFC PATCH v6 09/22] virtio/vsock: set packet's type in virtio_transport_send_pkt_info() Arseny Krasnov
2021-03-12 15:31   ` Stefano Garzarella
2021-03-07 18:01 ` [RFC PATCH v6 10/22] virtio/vsock: simplify credit update function API Arseny Krasnov
2021-03-12 15:33   ` Stefano Garzarella
2021-03-07 18:02 ` [RFC PATCH v6 11/22] virtio/vsock: dequeue callback for SOCK_SEQPACKET Arseny Krasnov
2021-03-15 11:02   ` Stefano Garzarella
2021-03-07 18:02 ` [RFC PATCH v6 12/22] virtio/vsock: fetch length for SEQPACKET record Arseny Krasnov
2021-03-12 15:20   ` Stefano Garzarella
2021-03-15  7:49     ` Arseny Krasnov
2021-03-07 18:02 ` [RFC PATCH v6 13/22] virtio/vsock: add SEQPACKET receive logic Arseny Krasnov
2021-03-15 11:15   ` Stefano Garzarella
2021-03-07 18:03 ` [RFC PATCH v6 14/22] virtio/vsock: rest of SOCK_SEQPACKET support Arseny Krasnov
2021-03-15 11:25   ` Stefano Garzarella
2021-03-07 18:03 ` [RFC PATCH v6 15/22] virtio/vsock: SEQPACKET support feature bit Arseny Krasnov
2021-03-07 18:03 ` [RFC PATCH v6 16/22] vhost/vsock: SEQPACKET feature bit support Arseny Krasnov
2021-03-15 11:28   ` Stefano Garzarella
2021-03-07 18:04 ` [RFC PATCH v6 17/22] virtio/vsock: " Arseny Krasnov
2021-03-15 11:29   ` Stefano Garzarella
2021-03-07 18:04 ` [RFC PATCH v6 18/22] virtio/vsock: setup SEQPACKET ops for transport Arseny Krasnov
2021-03-07 18:04 ` [RFC PATCH v6 19/22] vhost/vsock: " Arseny Krasnov
2021-03-07 18:04 ` [RFC PATCH v6 20/22] vsock/loopback: " Arseny Krasnov
2021-03-07 18:05 ` [RFC PATCH v6 21/22] vsock_test: add SOCK_SEQPACKET tests Arseny Krasnov
2021-03-07 18:05 ` [RFC PATCH v6 22/22] virtio/vsock: update trace event for SEQPACKET Arseny Krasnov
2021-03-10 10:06 ` [RFC PATCH v6 00/22] virtio/vsock: introduce SOCK_SEQPACKET support Stefano Garzarella
2021-03-10 10:13   ` Arseny Krasnov
2021-03-15 11:40 ` Stefano Garzarella
2021-03-15 15:22   ` Arseny Krasnov
2021-03-16  3:37     ` Arseny Krasnov
2021-03-16  8:08       ` Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210307180030.3465161-1-arseny.krasnov@kaspersky.com \
    --to=arseny.krasnov@kaspersky.com \
    --cc=andraprs@amazon.com \
    --cc=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --cc=jasowang@redhat.com \
    --cc=jhansen@vmware.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nslusarek@gmx.net \
    --cc=oxffffaa@gmail.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=stsp2@yandex.ru \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).