From: Xuewei Niu <niuxuewei.nxw@antgroup.com>
To: "K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Stefano Garzarella <sgarzare@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>
Cc: linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Xuewei Niu <niuxuewei.nxw@antgroup.com>,
niuxuewei97@gmail.com
Subject: [PATCH net-next v6 2/4] vsock: Add support for SIOCINQ ioctl
Date: Tue, 08 Jul 2025 14:36:12 +0800 [thread overview]
Message-ID: <20250708-siocinq-v6-2-3775f9a9e359@antgroup.com> (raw)
In-Reply-To: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com>
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 2e7a3034e965db30b6ee295370d866e6d8b1c341..bae6b89bb5fb7dd7a3a378f92097561a98a0c814 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
next prev parent reply other threads:[~2025-07-08 6:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-08 6:36 [PATCH net-next v6 0/4] vsock: Introduce SIOCINQ ioctl support Xuewei Niu
2025-07-08 6:36 ` [PATCH net-next v6 1/4] hv_sock: Return the readable bytes in hvs_stream_has_data() Xuewei Niu
2025-07-08 10:49 ` Stefano Garzarella
2025-07-09 23:23 ` Wei Liu
2025-07-08 6:36 ` Xuewei Niu [this message]
2025-07-08 10:52 ` [PATCH net-next v6 2/4] vsock: Add support for SIOCINQ ioctl Stefano Garzarella
2025-07-09 15:00 ` Luigi Leonardi
2025-07-08 6:36 ` [PATCH net-next v6 3/4] test/vsock: Add retry mechanism to ioctl wrapper Xuewei Niu
2025-07-08 10:54 ` Stefano Garzarella
2025-07-09 15:02 ` Luigi Leonardi
2025-07-08 6:36 ` [PATCH net-next v6 4/4] test/vsock: Add ioctl SIOCINQ tests Xuewei Niu
2025-07-08 10:57 ` Stefano Garzarella
2025-07-09 15:05 ` Luigi Leonardi
2025-07-10 2:50 ` [PATCH net-next v6 0/4] vsock: Introduce SIOCINQ ioctl support patchwork-bot+netdevbpf
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=20250708-siocinq-v6-2-3775f9a9e359@antgroup.com \
--to=niuxuewei.nxw@antgroup.com \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=haiyangz@microsoft.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=niuxuewei97@gmail.com \
--cc=pabeni@redhat.com \
--cc=sgarzare@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=wei.liu@kernel.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).