2e18a0
From 29b9f5efd78ae0f9cc02dd169b6e80d2c404bade Mon Sep 17 00:00:00 2001
2e18a0
From: Jason Wang <jasowang@redhat.com>
2e18a0
Date: Fri, 25 Sep 2015 13:21:29 +0800
2e18a0
Subject: [PATCH] virtio: introduce virtqueue_discard()
2e18a0
2e18a0
This patch introduces virtqueue_discard() to discard a descriptor and
2e18a0
unmap the sgs. This will be used by the patch that will discard
2e18a0
descriptor when packet is truncated.
2e18a0
2e18a0
Cc: Michael S. Tsirkin <mst@redhat.com>
2e18a0
Signed-off-by: Jason Wang <jasowang@redhat.com>
2e18a0
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
2e18a0
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2e18a0
---
2e18a0
 hw/virtio/virtio.c         |    7 +++++++
2e18a0
 include/hw/gvirtio/virtio.h |    2 ++
2e18a0
 2 files changed, 9 insertions(+), 0 deletions(-)
2e18a0
2e18a0
diff --git a/tools/qemu-xen/hw/virtio/virtio.c b/tools/qemu-xen/hw/virtio/virtio.c
2e18a0
index 6f2b96c..d0bc72e 100644
2e18a0
--- a/tools/qemu-xen/hw/virtio/virtio.c
2e18a0
+++ b/tools/qemu-xen/hw/virtio/virtio.c
2e18a0
@@ -267,6 +267,13 @@ static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem,
2e18a0
                                   0, elem->out_sg[i].iov_len);
2e18a0
 }
2e18a0
 
2e18a0
+void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
2e18a0
+                       unsigned int len)
2e18a0
+{
2e18a0
+    vq->last_avail_idx--;
2e18a0
+    virtqueue_unmap_sg(vq, elem, len);
2e18a0
+}
2e18a0
+
2e18a0
 void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
2e18a0
                     unsigned int len, unsigned int idx)
2e18a0
 {
2e18a0
diff --git a/tools/qemu-xen/include/hw/virtio/virtio.h b/tools/qemu-xen/include/hw/virtio/virtio.h
2e18a0
index 6201ee8..9d09115 100644
2e18a0
--- a/tools/qemu-xen/include/hw/virtio/virtio.h
2e18a0
+++ b/tools/qemu-xen/include/hw/virtio/virtio.h
2e18a0
@@ -146,6 +146,8 @@ void virtio_del_queue(VirtIODevice *vdev, int n);
2e18a0
 void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
2e18a0
                     unsigned int len);
2e18a0
 void virtqueue_flush(VirtQueue *vq, unsigned int count);
2e18a0
+void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
2e18a0
+                       unsigned int len);
2e18a0
 void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
2e18a0
                     unsigned int len, unsigned int idx);
2e18a0
 
2e18a0
-- 
2e18a0
1.7.0.4
2e18a0