Add support for SIOCINQ ioctl, indicating the length of bytes unread in the
socket. The value is obtained from `vsock_stream_has_data()`.
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
---
net/vmw_vsock/af_vsock.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 2e7a3034e965..bae6b89bb5fb 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1389,6 +1389,28 @@ static int vsock_do_ioctl(struct socket *sock, unsigned int cmd,
vsk = vsock_sk(sk);
switch (cmd) {
+ case SIOCINQ: {
+ ssize_t n_bytes;
+
+ if (!vsk->transport) {
+ ret = -EOPNOTSUPP;
+ break;
+ }
+
+ if (sock_type_connectible(sk->sk_type) &&
+ sk->sk_state == TCP_LISTEN) {
+ ret = -EINVAL;
+ break;
+ }
+
+ n_bytes = vsock_stream_has_data(vsk);
+ if (n_bytes < 0) {
+ ret = n_bytes;
+ break;
+ }
+ ret = put_user(n_bytes, arg);
+ break;
+ }
case SIOCOUTQ: {
ssize_t n_bytes;
--
2.34.1
CCin hyper-v maintainers and list since I have a question about hyperv transport. On Tue, Jun 17, 2025 at 12:53:44PM +0800, Xuewei Niu wrote: >Add support for SIOCINQ ioctl, indicating the length of bytes unread in the >socket. The value is obtained from `vsock_stream_has_data()`. > >Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com> >--- > net/vmw_vsock/af_vsock.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c >index 2e7a3034e965..bae6b89bb5fb 100644 >--- a/net/vmw_vsock/af_vsock.c >+++ b/net/vmw_vsock/af_vsock.c >@@ -1389,6 +1389,28 @@ static int vsock_do_ioctl(struct socket *sock, unsigned int cmd, > vsk = vsock_sk(sk); > > switch (cmd) { >+ case SIOCINQ: { >+ ssize_t n_bytes; >+ >+ if (!vsk->transport) { >+ ret = -EOPNOTSUPP; >+ break; >+ } >+ >+ if (sock_type_connectible(sk->sk_type) && >+ sk->sk_state == TCP_LISTEN) { >+ ret = -EINVAL; >+ break; >+ } >+ >+ n_bytes = vsock_stream_has_data(vsk); Now looks better to me, I just checked transports: vmci and virtio/vhost returns what we want, but for hyperv we have: static s64 hvs_stream_has_data(struct vsock_sock *vsk) { struct hvsock *hvs = vsk->trans; s64 ret; if (hvs->recv_data_len > 0) return 1; @Hyper-v maintainers: do you know why we don't return `recv_data_len`? Do you think we can do that to support this new feature? Thanks, Stefano >+ if (n_bytes < 0) { >+ ret = n_bytes; >+ break; >+ } >+ ret = put_user(n_bytes, arg); >+ break; >+ } > case SIOCOUTQ: { > ssize_t n_bytes; > >-- >2.34.1 >
> ACCin hyper-v maintainers and list since I have a question about hyperv > transport. > > On Tue, Jun 17, 2025 at 12:53:44PM +0800, Xuewei Niu wrote: > >Add support for SIOCINQ ioctl, indicating the length of bytes unread in the > >socket. The value is obtained from `vsock_stream_has_data()`. > > > >Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com> > >--- > > net/vmw_vsock/af_vsock.c | 22 ++++++++++++++++++++++ > > 1 file changed, 22 insertions(+) > > > >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c > >index 2e7a3034e965..bae6b89bb5fb 100644 > >--- a/net/vmw_vsock/af_vsock.c > >+++ b/net/vmw_vsock/af_vsock.c > >@@ -1389,6 +1389,28 @@ static int vsock_do_ioctl(struct socket *sock, unsigned int cmd, > > vsk = vsock_sk(sk); > > > > switch (cmd) { > >+ case SIOCINQ: { > >+ ssize_t n_bytes; > >+ > >+ if (!vsk->transport) { > >+ ret = -EOPNOTSUPP; > >+ break; > >+ } > >+ > >+ if (sock_type_connectible(sk->sk_type) && > >+ sk->sk_state == TCP_LISTEN) { > >+ ret = -EINVAL; > >+ break; > >+ } > >+ > >+ n_bytes = vsock_stream_has_data(vsk); > > Now looks better to me, I just checked transports: vmci and virtio/vhost > returns what we want, but for hyperv we have: > > static s64 hvs_stream_has_data(struct vsock_sock *vsk) > { > struct hvsock *hvs = vsk->trans; > s64 ret; > > if (hvs->recv_data_len > 0) > return 1; > > @Hyper-v maintainers: do you know why we don't return `recv_data_len`? > Do you think we can do that to support this new feature? Hi Hyper-v maintainers, could you please take a look at this? Hi Stefano, if no response, can I fix this issue in the next version? Thanks, Xuewei > Thanks, > Stefano > > >+ if (n_bytes < 0) { > >+ ret = n_bytes; > >+ break; > >+ } > >+ ret = put_user(n_bytes, arg); > >+ break; > >+ } > > case SIOCOUTQ: { > > ssize_t n_bytes; > > > >-- > >2.34.1 > >
On Sun, Jun 22, 2025 at 09:59:10PM +0800, Xuewei Niu wrote: >> ACCin hyper-v maintainers and list since I have a question about hyperv >> transport. >> >> On Tue, Jun 17, 2025 at 12:53:44PM +0800, Xuewei Niu wrote: >> >Add support for SIOCINQ ioctl, indicating the length of bytes unread in the >> >socket. The value is obtained from `vsock_stream_has_data()`. >> > >> >Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com> >> >--- >> > net/vmw_vsock/af_vsock.c | 22 ++++++++++++++++++++++ >> > 1 file changed, 22 insertions(+) >> > >> >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c >> >index 2e7a3034e965..bae6b89bb5fb 100644 >> >--- a/net/vmw_vsock/af_vsock.c >> >+++ b/net/vmw_vsock/af_vsock.c >> >@@ -1389,6 +1389,28 @@ static int vsock_do_ioctl(struct socket *sock, unsigned int cmd, >> > vsk = vsock_sk(sk); >> > >> > switch (cmd) { >> >+ case SIOCINQ: { >> >+ ssize_t n_bytes; >> >+ >> >+ if (!vsk->transport) { >> >+ ret = -EOPNOTSUPP; >> >+ break; >> >+ } >> >+ >> >+ if (sock_type_connectible(sk->sk_type) && >> >+ sk->sk_state == TCP_LISTEN) { >> >+ ret = -EINVAL; >> >+ break; >> >+ } >> >+ >> >+ n_bytes = vsock_stream_has_data(vsk); >> >> Now looks better to me, I just checked transports: vmci and virtio/vhost >> returns what we want, but for hyperv we have: >> >> static s64 hvs_stream_has_data(struct vsock_sock *vsk) >> { >> struct hvsock *hvs = vsk->trans; >> s64 ret; >> >> if (hvs->recv_data_len > 0) >> return 1; >> >> @Hyper-v maintainers: do you know why we don't return `recv_data_len`? >> Do you think we can do that to support this new feature? > >Hi Hyper-v maintainers, could you please take a look at this? > >Hi Stefano, if no response, can I fix this issue in the next version? Yep, but let's wait a little bit more. In that case, please do it in a separate patch (same series is fine) that we can easily revert/fix if they will find issues later. Thanks, Stefano > >Thanks, >Xuewei > >> Thanks, >> Stefano >> >> >+ if (n_bytes < 0) { >> >+ ret = n_bytes; >> >+ break; >> >+ } >> >+ ret = put_user(n_bytes, arg); >> >+ break; >> >+ } >> > case SIOCOUTQ: { >> > ssize_t n_bytes; >> > >> >-- >> >2.34.1 >> > >
© 2016 - 2025 Red Hat, Inc.