Skip to content

Commit f0c5827

Browse files
dcuikuba-moo
authored andcommitted
hv_sock: Return the readable bytes in hvs_stream_has_data()
When hv_sock was originally added, __vsock_stream_recvmsg() and vsock_stream_has_data() actually only needed to know whether there is any readable data or not, so hvs_stream_has_data() was written to return 1 or 0 for simplicity. However, now hvs_stream_has_data() should return the readable bytes because vsock_data_ready() -> vsock_stream_has_data() needs to know the actual bytes rather than a boolean value of 1 or 0. The SIOCINQ ioctl support also needs hvs_stream_has_data() to return the readable bytes. Let hvs_stream_has_data() return the readable bytes of the payload in the next host-to-guest VMBus hv_sock packet. Note: there may be multiple incoming hv_sock packets pending in the VMBus channel's ringbuffer, but so far there is not a VMBus API that allows us to know all the readable bytes in total without reading and caching the payload of the multiple packets, so let's just return the readable bytes of the next single packet. In the future, we'll either add a VMBus API that allows us to know the total readable bytes without touching the data in the ringbuffer, or the hv_sock driver needs to understand the VMBus packet format and parse the packets directly. Signed-off-by: Dexuan Cui <decui@microsoft.com> Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com> Acked-by: Stefano Garzarella <sgarzare@redhat.com> Acked-by: Wei Liu <wei.liu@kernel.org> Link: https://patch.msgid.link/20250708-siocinq-v6-1-3775f9a9e359@antgroup.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 819802e commit f0c5827

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

net/vmw_vsock/hyperv_transport.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,15 +694,26 @@ static ssize_t hvs_stream_enqueue(struct vsock_sock *vsk, struct msghdr *msg,
694694
static s64 hvs_stream_has_data(struct vsock_sock *vsk)
695695
{
696696
struct hvsock *hvs = vsk->trans;
697+
bool need_refill;
697698
s64 ret;
698699

699700
if (hvs->recv_data_len > 0)
700-
return 1;
701+
return hvs->recv_data_len;
701702

702703
switch (hvs_channel_readable_payload(hvs->chan)) {
703704
case 1:
704-
ret = 1;
705-
break;
705+
need_refill = !hvs->recv_desc;
706+
if (!need_refill)
707+
return -EIO;
708+
709+
hvs->recv_desc = hv_pkt_iter_first(hvs->chan);
710+
if (!hvs->recv_desc)
711+
return -ENOBUFS;
712+
713+
ret = hvs_update_recv_data(hvs);
714+
if (ret)
715+
return ret;
716+
return hvs->recv_data_len;
706717
case 0:
707718
vsk->peer_shutdown |= SEND_SHUTDOWN;
708719
ret = 0;

0 commit comments

Comments
 (0)