mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2024-12-29 17:22:07 +00:00
vsock/virtio: add SIOCOUTQ support for all virtio based transports
Introduce support for virtio_transport_unsent_bytes ioctl for virtio_transport, vhost_vsock and vsock_loopback. For all transports the unsent bytes counter is incremented in virtio_transport_get_credit. In virtio_transport (G2H) and in vhost-vsock (H2G) the counter is decremented when the skbuff is consumed. In vsock_loopback the same skbuff is passed from the transmitter to the receiver, so the counter is decremented before queuing the skbuff to the receiver. Signed-off-by: Luigi Leonardi <luigi.leonardi@outlook.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
744500d81f
commit
e6ab450057
@ -244,7 +244,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
|
||||
restart_tx = true;
|
||||
}
|
||||
|
||||
consume_skb(skb);
|
||||
virtio_transport_consume_skb_sent(skb, true);
|
||||
}
|
||||
} while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len)));
|
||||
if (added)
|
||||
@ -451,6 +451,8 @@ static struct virtio_transport vhost_transport = {
|
||||
.notify_buffer_size = virtio_transport_notify_buffer_size,
|
||||
.notify_set_rcvlowat = virtio_transport_notify_set_rcvlowat,
|
||||
|
||||
.unsent_bytes = virtio_transport_unsent_bytes,
|
||||
|
||||
.read_skb = virtio_transport_read_skb,
|
||||
},
|
||||
|
||||
|
@ -133,6 +133,7 @@ struct virtio_vsock_sock {
|
||||
u32 tx_cnt;
|
||||
u32 peer_fwd_cnt;
|
||||
u32 peer_buf_alloc;
|
||||
size_t bytes_unsent;
|
||||
|
||||
/* Protected by rx_lock */
|
||||
u32 fwd_cnt;
|
||||
@ -193,6 +194,11 @@ s64 virtio_transport_stream_has_data(struct vsock_sock *vsk);
|
||||
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);
|
||||
|
||||
void virtio_transport_consume_skb_sent(struct sk_buff *skb,
|
||||
bool consume);
|
||||
|
||||
int virtio_transport_do_socket_init(struct vsock_sock *vsk,
|
||||
struct vsock_sock *psk);
|
||||
int
|
||||
|
@ -311,7 +311,7 @@ static void virtio_transport_tx_work(struct work_struct *work)
|
||||
|
||||
virtqueue_disable_cb(vq);
|
||||
while ((skb = virtqueue_get_buf(vq, &len)) != NULL) {
|
||||
consume_skb(skb);
|
||||
virtio_transport_consume_skb_sent(skb, true);
|
||||
added = true;
|
||||
}
|
||||
} while (!virtqueue_enable_cb(vq));
|
||||
@ -540,6 +540,8 @@ static struct virtio_transport virtio_transport = {
|
||||
.notify_buffer_size = virtio_transport_notify_buffer_size,
|
||||
.notify_set_rcvlowat = virtio_transport_notify_set_rcvlowat,
|
||||
|
||||
.unsent_bytes = virtio_transport_unsent_bytes,
|
||||
|
||||
.read_skb = virtio_transport_read_skb,
|
||||
},
|
||||
|
||||
|
@ -463,6 +463,26 @@ void virtio_transport_inc_tx_pkt(struct virtio_vsock_sock *vvs, struct sk_buff *
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(virtio_transport_inc_tx_pkt);
|
||||
|
||||
void virtio_transport_consume_skb_sent(struct sk_buff *skb, bool consume)
|
||||
{
|
||||
struct sock *s = skb->sk;
|
||||
|
||||
if (s && skb->len) {
|
||||
struct vsock_sock *vs = vsock_sk(s);
|
||||
struct virtio_vsock_sock *vvs;
|
||||
|
||||
vvs = vs->trans;
|
||||
|
||||
spin_lock_bh(&vvs->tx_lock);
|
||||
vvs->bytes_unsent -= skb->len;
|
||||
spin_unlock_bh(&vvs->tx_lock);
|
||||
}
|
||||
|
||||
if (consume)
|
||||
consume_skb(skb);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(virtio_transport_consume_skb_sent);
|
||||
|
||||
u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 credit)
|
||||
{
|
||||
u32 ret;
|
||||
@ -475,6 +495,7 @@ u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 credit)
|
||||
if (ret > credit)
|
||||
ret = credit;
|
||||
vvs->tx_cnt += ret;
|
||||
vvs->bytes_unsent += ret;
|
||||
spin_unlock_bh(&vvs->tx_lock);
|
||||
|
||||
return ret;
|
||||
@ -488,6 +509,7 @@ void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit)
|
||||
|
||||
spin_lock_bh(&vvs->tx_lock);
|
||||
vvs->tx_cnt -= credit;
|
||||
vvs->bytes_unsent -= credit;
|
||||
spin_unlock_bh(&vvs->tx_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(virtio_transport_put_credit);
|
||||
@ -1090,6 +1112,19 @@ void virtio_transport_destruct(struct vsock_sock *vsk)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(virtio_transport_destruct);
|
||||
|
||||
ssize_t virtio_transport_unsent_bytes(struct vsock_sock *vsk)
|
||||
{
|
||||
struct virtio_vsock_sock *vvs = vsk->trans;
|
||||
size_t ret;
|
||||
|
||||
spin_lock_bh(&vvs->tx_lock);
|
||||
ret = vvs->bytes_unsent;
|
||||
spin_unlock_bh(&vvs->tx_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(virtio_transport_unsent_bytes);
|
||||
|
||||
static int virtio_transport_reset(struct vsock_sock *vsk,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
|
@ -98,6 +98,8 @@ static struct virtio_transport loopback_transport = {
|
||||
.notify_buffer_size = virtio_transport_notify_buffer_size,
|
||||
.notify_set_rcvlowat = virtio_transport_notify_set_rcvlowat,
|
||||
|
||||
.unsent_bytes = virtio_transport_unsent_bytes,
|
||||
|
||||
.read_skb = virtio_transport_read_skb,
|
||||
},
|
||||
|
||||
@ -123,6 +125,10 @@ static void vsock_loopback_work(struct work_struct *work)
|
||||
spin_unlock_bh(&vsock->pkt_queue.lock);
|
||||
|
||||
while ((skb = __skb_dequeue(&pkts))) {
|
||||
/* Decrement the bytes_unsent counter without deallocating skb
|
||||
* It is freed by the receiver.
|
||||
*/
|
||||
virtio_transport_consume_skb_sent(skb, false);
|
||||
virtio_transport_deliver_tap_pkt(skb);
|
||||
virtio_transport_recv_pkt(&loopback_transport, skb);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user