Commit 051e77e3 authored by Arseniy Krasnov's avatar Arseniy Krasnov Committed by Paolo Abeni

virtio/vsock: rework MSG_PEEK for SOCK_STREAM

This reworks current implementation of MSG_PEEK logic:
1) Replaces 'skb_queue_walk_safe()' with 'skb_queue_walk()'. There is
   no need in the first one, as there are no removes of skb in loop.
2) Removes nested while loop - MSG_PEEK logic could be implemented
   without it: just iterate over skbs without removing it and copy
   data from each until destination buffer is not full.
Signed-off-by: default avatarArseniy Krasnov <AVKrasnov@sberdevices.ru>
Reviewed-by: default avatarBobby Eshleman <bobby.eshleman@bytedance.com>
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 bc758ade
...@@ -348,37 +348,34 @@ virtio_transport_stream_do_peek(struct vsock_sock *vsk, ...@@ -348,37 +348,34 @@ virtio_transport_stream_do_peek(struct vsock_sock *vsk,
size_t len) size_t len)
{ {
struct virtio_vsock_sock *vvs = vsk->trans; struct virtio_vsock_sock *vvs = vsk->trans;
size_t bytes, total = 0, off; struct sk_buff *skb;
struct sk_buff *skb, *tmp; size_t total = 0;
int err = -EFAULT; int err;
spin_lock_bh(&vvs->rx_lock); spin_lock_bh(&vvs->rx_lock);
skb_queue_walk_safe(&vvs->rx_queue, skb, tmp) { skb_queue_walk(&vvs->rx_queue, skb) {
off = 0; size_t bytes;
if (total == len)
break;
while (total < len && off < skb->len) {
bytes = len - total; bytes = len - total;
if (bytes > skb->len - off) if (bytes > skb->len)
bytes = skb->len - off; bytes = skb->len;
spin_unlock_bh(&vvs->rx_lock);
/* sk_lock is held by caller so no one else can dequeue. /* sk_lock is held by caller so no one else can dequeue.
* Unlock rx_lock since memcpy_to_msg() may sleep. * Unlock rx_lock since memcpy_to_msg() may sleep.
*/ */
spin_unlock_bh(&vvs->rx_lock); err = memcpy_to_msg(msg, skb->data, bytes);
err = memcpy_to_msg(msg, skb->data + off, bytes);
if (err) if (err)
goto out; goto out;
total += bytes;
spin_lock_bh(&vvs->rx_lock); spin_lock_bh(&vvs->rx_lock);
total += bytes; if (total == len)
off += bytes; break;
}
} }
spin_unlock_bh(&vvs->rx_lock); spin_unlock_bh(&vvs->rx_lock);
......
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