Thread (14 messages) 14 messages, 5 authors, 2025-07-10

Re: [PATCH net-next v6 2/4] vsock: Add support for SIOCINQ ioctl

From: Luigi Leonardi <hidden>
Date: 2025-07-09 15:01:07
Also in: linux-hyperv, lkml, virtualization

On Tue, Jul 08, 2025 at 02:36:12PM +0800, Xuewei Niu wrote:
quoted hunk ↗ jump to hunk
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 <redacted>
---
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
LGTM!

Reviewed-by: Luigi Leonardi <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help