vsock: Add support for SIOCINQ ioctl

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>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
Link: https://patch.msgid.link/20250708-siocinq-v6-2-3775f9a9e359@antgroup.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Xuewei Niu 2025-07-08 14:36:12 +08:00 committed by Jakub Kicinski
parent f0c5827d07
commit f7c7226592

View file

@ -1389,6 +1389,28 @@ static int vsock_do_ioctl(struct socket *sock, unsigned int cmd,
vsk = vsock_sk(sk); vsk = vsock_sk(sk);
switch (cmd) { 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: { case SIOCOUTQ: {
ssize_t n_bytes; ssize_t n_bytes;