The value of the SIOCINQ is obtained by `virtio_transport_unread_bytes()`,
which is generic for all virtio transports. The function acquires the
`rx_lock` and returns the value of `rx_bytes`.

Signed-off-by: Xuewei Niu <niuxuewei....@antgroup.com>
---
 drivers/vhost/vsock.c                   |  1 +
 include/linux/virtio_vsock.h            |  1 +
 net/vmw_vsock/virtio_transport.c        |  1 +
 net/vmw_vsock/virtio_transport_common.c | 13 +++++++++++++
 net/vmw_vsock/vsock_loopback.c          |  1 +
 5 files changed, 17 insertions(+)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 802153e23073..0f20af6e5036 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -452,6 +452,7 @@ static struct virtio_transport vhost_transport = {
                .notify_set_rcvlowat      = 
virtio_transport_notify_set_rcvlowat,
 
                .unsent_bytes             = virtio_transport_unsent_bytes,
+               .unread_bytes             = virtio_transport_unread_bytes,
 
                .read_skb = virtio_transport_read_skb,
        },
diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index 36fb3edfa403..74c50224431e 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -196,6 +196,7 @@ s64 virtio_transport_stream_has_space(struct vsock_sock 
*vsk);
 u32 virtio_transport_seqpacket_has_data(struct vsock_sock *vsk);
 
 ssize_t virtio_transport_unsent_bytes(struct vsock_sock *vsk);
+ssize_t virtio_transport_unread_bytes(struct vsock_sock *vsk);
 
 void virtio_transport_consume_skb_sent(struct sk_buff *skb,
                                       bool consume);
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index f0e48e6911fc..917881537b63 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -585,6 +585,7 @@ static struct virtio_transport virtio_transport = {
                .notify_set_rcvlowat      = 
virtio_transport_notify_set_rcvlowat,
 
                .unsent_bytes             = virtio_transport_unsent_bytes,
+               .unread_bytes             = virtio_transport_unread_bytes,
 
                .read_skb = virtio_transport_read_skb,
        },
diff --git a/net/vmw_vsock/virtio_transport_common.c 
b/net/vmw_vsock/virtio_transport_common.c
index 1b5d9896edae..59e72d2dbd85 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1135,6 +1135,19 @@ ssize_t virtio_transport_unsent_bytes(struct vsock_sock 
*vsk)
 }
 EXPORT_SYMBOL_GPL(virtio_transport_unsent_bytes);
 
+ssize_t virtio_transport_unread_bytes(struct vsock_sock *vsk)
+{
+       struct virtio_vsock_sock *vvs = vsk->trans;
+       size_t ret;
+
+       spin_lock_bh(&vvs->rx_lock);
+       ret = vvs->rx_bytes;
+       spin_unlock_bh(&vvs->rx_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(virtio_transport_unread_bytes);
+
 static int virtio_transport_reset(struct vsock_sock *vsk,
                                  struct sk_buff *skb)
 {
diff --git a/net/vmw_vsock/vsock_loopback.c b/net/vmw_vsock/vsock_loopback.c
index 6e78927a598e..13a77db2a76f 100644
--- a/net/vmw_vsock/vsock_loopback.c
+++ b/net/vmw_vsock/vsock_loopback.c
@@ -99,6 +99,7 @@ static struct virtio_transport loopback_transport = {
                .notify_set_rcvlowat      = 
virtio_transport_notify_set_rcvlowat,
 
                .unsent_bytes             = virtio_transport_unsent_bytes,
+               .unread_bytes             = virtio_transport_unread_bytes,
 
                .read_skb = virtio_transport_read_skb,
        },
-- 
2.34.1


Reply via email to