[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210128170426.522mpkocdd35bt2e@steredhat>
Date: Thu, 28 Jan 2021 18:04:26 +0100
From: Stefano Garzarella <sgarzare@...hat.com>
To: Arseny Krasnov <arseny.krasnov@...persky.com>
Cc: Stefan Hajnoczi <stefanha@...hat.com>,
"Michael S. Tsirkin" <mst@...hat.com>,
Jason Wang <jasowang@...hat.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Andra Paraschiv <andraprs@...zon.com>,
Colin Ian King <colin.king@...onical.com>,
Jeff Vander Stoep <jeffv@...gle.com>, kvm@...r.kernel.org,
virtualization@...ts.linux-foundation.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, stsp2@...dex.ru, oxffffaa@...il.com
Subject: Re: [RFC PATCH v3 05/13] af_vsock: rest of SEQPACKET support
On Mon, Jan 25, 2021 at 02:13:18PM +0300, Arseny Krasnov wrote:
>This does rest of SOCK_SEQPACKET support:
>1) Adds socket ops for SEQPACKET type.
>2) Allows to create socket with SEQPACKET type.
>
>Signed-off-by: Arseny Krasnov <arseny.krasnov@...persky.com>
>---
> net/vmw_vsock/af_vsock.c | 71 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 71 insertions(+)
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index 4600c1ec3bb3..bbc3c31085aa 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -452,6 +452,7 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
> new_transport = transport_dgram;
> break;
> case SOCK_STREAM:
>+ case SOCK_SEQPACKET:
> if (vsock_use_local_transport(remote_cid))
> new_transport = transport_local;
> else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g ||
>@@ -459,6 +460,13 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
> new_transport = transport_g2h;
> else
> new_transport = transport_h2g;
>+
>+ if (sk->sk_type == SOCK_SEQPACKET) {
I think you must also check that new_transport is not NULL.
>+ if (!new_transport->seqpacket_seq_send_len ||
>+ !new_transport->seqpacket_seq_get_len ||
>+ !new_transport->seqpacket_dequeue)
>+ return -ENODEV;
I'm not sure about ENODEV is the better choice in this case, since the
transport exists, but it doesn't support SOCK_SEQPACKET, so maybe is
better ESOCKTNOSUPPORT.
>+ }
> break;
> default:
> return -ESOCKTNOSUPPORT;
>@@ -684,6 +692,7 @@ static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr)
>
> switch (sk->sk_socket->type) {
> case SOCK_STREAM:
>+ case SOCK_SEQPACKET:
> spin_lock_bh(&vsock_table_lock);
> retval = __vsock_bind_connectible(vsk, addr);
> spin_unlock_bh(&vsock_table_lock);
>@@ -1406,6 +1415,12 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
> return vsock_connect(sock, addr, addr_len, flags);
> }
>
>+static int vsock_seqpacket_connect(struct socket *sock, struct sockaddr *addr,
>+ int addr_len, int flags)
>+{
>+ return vsock_connect(sock, addr, addr_len, flags);
>+}
>+
> static int vsock_accept(struct socket *sock, struct socket *newsock, int flags,
> bool kern)
> {
>@@ -1633,6 +1648,16 @@ static int vsock_stream_setsockopt(struct socket *sock,
> optlen);
> }
>
>+static int vsock_seqpacket_setsockopt(struct socket *sock,
>+ int level,
>+ int optname,
>+ sockptr_t optval,
>+ unsigned int optlen)
>+{
>+ return vsock_connectible_setsockopt(sock, level, optname, optval,
>+ optlen);
>+}
>+
> static int vsock_connectible_getsockopt(struct socket *sock,
> int level, int optname,
> char __user *optval,
>@@ -1713,6 +1738,15 @@ static int vsock_stream_getsockopt(struct socket *sock,
> optlen);
> }
>
>+static int vsock_seqpacket_getsockopt(struct socket *sock,
>+ int level, int optname,
>+ char __user *optval,
>+ int __user *optlen)
>+{
>+ return vsock_connectible_getsockopt(sock, level, optname, optval,
>+ optlen);
>+}
>+
> static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
> size_t len)
> {
>@@ -1870,6 +1904,12 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg,
> return vsock_connectible_sendmsg(sock, msg, len);
> }
>
>+static int vsock_seqpacket_sendmsg(struct socket *sock, struct msghdr *msg,
>+ size_t len)
>+{
>+ return vsock_connectible_sendmsg(sock, msg, len);
>+}
>+
> static int vsock_wait_data(struct sock *sk, struct wait_queue_entry *wait,
> long timeout,
> struct vsock_transport_recv_notify_data *recv_data,
>@@ -2184,6 +2224,13 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
> return vsock_connectible_recvmsg(sock, msg, len, flags);
> }
>
>+static int
>+vsock_seqpacket_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
>+ int flags)
>+{
>+ return vsock_connectible_recvmsg(sock, msg, len, flags);
>+}
>+
As I said, I think you don't need to implement all of this helpers and
you can directly assign the vsock_connectible_* functions in the
'vsock_seqpacket_ops'.
> static const struct proto_ops vsock_stream_ops = {
> .family = PF_VSOCK,
> .owner = THIS_MODULE,
>@@ -2205,6 +2252,27 @@ static const struct proto_ops vsock_stream_ops = {
> .sendpage = sock_no_sendpage,
> };
>
>+static const struct proto_ops vsock_seqpacket_ops = {
>+ .family = PF_VSOCK,
>+ .owner = THIS_MODULE,
>+ .release = vsock_release,
>+ .bind = vsock_bind,
>+ .connect = vsock_seqpacket_connect,
>+ .socketpair = sock_no_socketpair,
>+ .accept = vsock_accept,
>+ .getname = vsock_getname,
>+ .poll = vsock_poll,
>+ .ioctl = sock_no_ioctl,
>+ .listen = vsock_listen,
>+ .shutdown = vsock_shutdown,
>+ .setsockopt = vsock_seqpacket_setsockopt,
>+ .getsockopt = vsock_seqpacket_getsockopt,
>+ .sendmsg = vsock_seqpacket_sendmsg,
>+ .recvmsg = vsock_seqpacket_recvmsg,
>+ .mmap = sock_no_mmap,
>+ .sendpage = sock_no_sendpage,
>+};
>+
> static int vsock_create(struct net *net, struct socket *sock,
> int protocol, int kern)
> {
>@@ -2225,6 +2293,9 @@ static int vsock_create(struct net *net, struct socket *sock,
> case SOCK_STREAM:
> sock->ops = &vsock_stream_ops;
> break;
>+ case SOCK_SEQPACKET:
>+ sock->ops = &vsock_seqpacket_ops;
>+ break;
> default:
> return -ESOCKTNOSUPPORT;
> }
>--
>2.25.1
>
Powered by blists - more mailing lists