Commit a75f501d authored by Arseniy Krasnov's avatar Arseniy Krasnov Committed by Paolo Abeni

virtio/vsock: support MSG_PEEK for SOCK_SEQPACKET

This adds support of MSG_PEEK flag for SOCK_SEQPACKET type of socket.
Difference with SOCK_STREAM is that this callback returns either length
of the message or error.
Signed-off-by: default avatarArseniy Krasnov <AVKrasnov@sberdevices.ru>
Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 051e77e3
...@@ -460,6 +460,63 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, ...@@ -460,6 +460,63 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
return err; return err;
} }
static ssize_t
virtio_transport_seqpacket_do_peek(struct vsock_sock *vsk,
struct msghdr *msg)
{
struct virtio_vsock_sock *vvs = vsk->trans;
struct sk_buff *skb;
size_t total, len;
spin_lock_bh(&vvs->rx_lock);
if (!vvs->msg_count) {
spin_unlock_bh(&vvs->rx_lock);
return 0;
}
total = 0;
len = msg_data_left(msg);
skb_queue_walk(&vvs->rx_queue, skb) {
struct virtio_vsock_hdr *hdr;
if (total < len) {
size_t bytes;
int err;
bytes = len - total;
if (bytes > skb->len)
bytes = skb->len;
spin_unlock_bh(&vvs->rx_lock);
/* sk_lock is held by caller so no one else can dequeue.
* Unlock rx_lock since memcpy_to_msg() may sleep.
*/
err = memcpy_to_msg(msg, skb->data, bytes);
if (err)
return err;
spin_lock_bh(&vvs->rx_lock);
}
total += skb->len;
hdr = virtio_vsock_hdr(skb);
if (le32_to_cpu(hdr->flags) & VIRTIO_VSOCK_SEQ_EOM) {
if (le32_to_cpu(hdr->flags) & VIRTIO_VSOCK_SEQ_EOR)
msg->msg_flags |= MSG_EOR;
break;
}
}
spin_unlock_bh(&vvs->rx_lock);
return total;
}
static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk,
struct msghdr *msg, struct msghdr *msg,
int flags) int flags)
...@@ -554,8 +611,8 @@ virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk, ...@@ -554,8 +611,8 @@ virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk,
int flags) int flags)
{ {
if (flags & MSG_PEEK) if (flags & MSG_PEEK)
return -EOPNOTSUPP; return virtio_transport_seqpacket_do_peek(vsk, msg);
else
return virtio_transport_seqpacket_do_dequeue(vsk, msg, flags); return virtio_transport_seqpacket_do_dequeue(vsk, msg, flags);
} }
EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_dequeue); EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_dequeue);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment