netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: Arseny Krasnov <arseny.krasnov@kaspersky.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Colin Ian King <colin.king@canonical.com>,
	Andra Paraschiv <andraprs@amazon.com>,
	Jeff Vander Stoep <jeffv@google.com>,
	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: Re: [RFC PATCH v2 01/13] af_vsock: implement 'vsock_wait_data()'.
Date: Mon, 18 Jan 2021 15:51:58 +0100	[thread overview]
Message-ID: <20210118145158.ufakay5mbezjex4v@steredhat> (raw)
In-Reply-To: <20210115054028.1455574-1-arseny.krasnov@kaspersky.com>

On Fri, Jan 15, 2021 at 08:40:25AM +0300, Arseny Krasnov wrote:
>This adds 'vsock_wait_data()' function which is called from user's read
>syscall and waits until new socket data is arrived. It was based on code
>from stream dequeue logic and moved to separate function because it will
>be called both from SOCK_STREAM and SOCK_SEQPACKET receive loops.
>
>Signed-off-by: Arseny Krasnov <arseny.krasnov@kaspersky.com>
>---
> net/vmw_vsock/af_vsock.c | 47 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 47 insertions(+)
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index b12d3a322242..af716f5a93a4 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -1822,6 +1822,53 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
> 	return err;
> }
>
>+static int vsock_wait_data(struct sock *sk, struct wait_queue_entry *wait,
>+			   long timeout,
>+			   struct vsock_transport_recv_notify_data *recv_data,
>+			   size_t target)
>+{
>+	int err = 0;
>+	struct vsock_sock *vsk;
>+	const struct vsock_transport *transport;

Please be sure that here and in all of the next patches, you follow the 
"Reverse Christmas tree" rule followed in net/ for the local variable 
declarations (order variable declaration lines longest to shortest).

>+
>+	vsk = vsock_sk(sk);
>+	transport = vsk->transport;
>+
>+	if (sk->sk_err != 0 ||
>+	    (sk->sk_shutdown & RCV_SHUTDOWN) ||
>+	    (vsk->peer_shutdown & SEND_SHUTDOWN)) {
>+		finish_wait(sk_sleep(sk), wait);
>+		return -1;
>+	}
>+	/* Don't wait for non-blocking sockets. */
>+	if (timeout == 0) {
>+		err = -EAGAIN;
>+		finish_wait(sk_sleep(sk), wait);
>+		return err;
>+	}
>+
>+	if (recv_data) {
>+		err = transport->notify_recv_pre_block(vsk, target, recv_data);
>+		if (err < 0) {
>+			finish_wait(sk_sleep(sk), wait);
>+			return err;
>+		}
>+	}
>+
>+	release_sock(sk);
>+	timeout = schedule_timeout(timeout);
>+	lock_sock(sk);
>+
>+	if (signal_pending(current)) {
>+		err = sock_intr_errno(timeout);
>+		finish_wait(sk_sleep(sk), wait);
>+	} else if (timeout == 0) {
>+		err = -EAGAIN;
>+		finish_wait(sk_sleep(sk), wait);
>+	}
>+

Since we are calling finish_wait() before return in all path, why not 
doing somethig like this:

out:
	finish_wait(sk_sleep(sk), wait);
>+	return err;
>+}

Then in the error paths you can do:

	err = XXX;
	goto out;

Thanks,
Stefano

>
> static int
> vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
>-- 
>2.25.1
>


  reply	other threads:[~2021-01-18 15:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15  5:35 [RFC PATCH v2 00/13] virtio/vsock: introduce SOCK_SEQPACKET support Arseny Krasnov
2021-01-15  5:40 ` [RFC PATCH v2 01/13] af_vsock: implement 'vsock_wait_data()' Arseny Krasnov
2021-01-18 14:51   ` Stefano Garzarella [this message]
2021-01-15  5:40 ` [RFC PATCH v2 02/13] af_vsock: separate rx loops for STREAM/SEQPACKET Arseny Krasnov
2021-01-18 15:04   ` Stefano Garzarella
2021-01-15  5:41 ` [RFC PATCH v2 03/13] af_vsock: implement rx loops entry point Arseny Krasnov
2021-01-15  5:41 ` [RFC PATCH v2 04/13] af_vsock: replace previous stream rx loop Arseny Krasnov
2021-01-15  5:42 ` [RFC PATCH v2 05/13] af_vsock: implement send logic for SOCK_SEQPACKET Arseny Krasnov
2021-01-15  5:42 ` [RFC PATCH v2 06/13] af_vsock: general support of SOCK_SEQPACKET type Arseny Krasnov
2021-01-18 15:12   ` Stefano Garzarella
2021-01-15  5:42 ` [RFC PATCH v2 07/13] af_vsock: update comments for stream sockets Arseny Krasnov
2021-01-15  5:43 ` [RFC PATCH v2 08/13] virtio/vsock: dequeue callback for SOCK_SEQPACKET Arseny Krasnov
2021-01-18 15:14   ` Stefano Garzarella
2021-01-15  5:43 ` [RFC PATCH v2 09/13] virtio/vsock: implement fetch of record length Arseny Krasnov
2021-01-15  5:44 ` [RFC PATCH v2 10/13] virtio/vsock: update receive logic Arseny Krasnov
2021-01-18 15:15   ` Stefano Garzarella
2021-01-15  5:44 ` [RFC PATCH v2 11/13] virtio/vsock: rest of SOCK_SEQPACKET support Arseny Krasnov
2021-01-18 15:15   ` Stefano Garzarella
2021-01-15  5:45 ` [RFC PATCH v2 12/13] vhost/vsock: support for SOCK_SEQPACKET socket Arseny Krasnov
2021-01-15  5:45 ` [RFC PATCH v2 13/13] vsock_test: add SOCK_SEQPACKET tests Arseny Krasnov
2021-01-15  9:59 ` [RFC PATCH v2 00/13] virtio/vsock: introduce SOCK_SEQPACKET support stsp
2021-01-18 15:16   ` 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=20210118145158.ufakay5mbezjex4v@steredhat \
    --to=sgarzare@redhat.com \
    --cc=andraprs@amazon.com \
    --cc=arseny.krasnov@kaspersky.com \
    --cc=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --cc=jasowang@redhat.com \
    --cc=jeffv@google.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=oxffffaa@gmail.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).