619821
From 06ca4cab12a4216d40c297d8a79c83a4df4dd80e Mon Sep 17 00:00:00 2001
4f5da8
From: Ladi Prosek <lprosek@redhat.com>
4f5da8
Date: Wed, 5 Oct 2016 17:22:24 +0200
4f5da8
Subject: [PATCH 2/8] virtio: introduce virtqueue_discard()
4f5da8
4f5da8
RH-Author: Ladi Prosek <lprosek@redhat.com>
4f5da8
Message-id: <1475666548-9186-3-git-send-email-lprosek@redhat.com>
4f5da8
Patchwork-id: 72481
4f5da8
O-Subject: [RHEL-7.4 qemu-kvm v2 PATCH 2/6] virtio: introduce virtqueue_discard()
619821
Bugzilla: 1377968
4f5da8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4f5da8
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
4f5da8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
4f5da8
4f5da8
From: Jason Wang <jasowang@redhat.com>
4f5da8
4f5da8
This patch introduces virtqueue_discard() to discard a descriptor and
4f5da8
unmap the sgs. This will be used by the patch that will discard
4f5da8
descriptor when packet is truncated.
4f5da8
4f5da8
Cc: Michael S. Tsirkin <mst@redhat.com>
4f5da8
Signed-off-by: Jason Wang <jasowang@redhat.com>
4f5da8
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
4f5da8
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
4f5da8
(cherry picked from commit 29b9f5efd78ae0f9cc02dd169b6e80d2c404bade)
4f5da8
Signed-off-by: Ladi Prosek <lprosek@redhat.com>
4f5da8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4f5da8
---
4f5da8
 hw/virtio/virtio.c         | 7 +++++++
4f5da8
 include/hw/virtio/virtio.h | 2 ++
4f5da8
 2 files changed, 9 insertions(+)
4f5da8
4f5da8
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
4f5da8
index 5ee899a..91c9642 100644
4f5da8
--- a/hw/virtio/virtio.c
4f5da8
+++ b/hw/virtio/virtio.c
4f5da8
@@ -251,6 +251,13 @@ static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem,
4f5da8
                                   0, elem->out_sg[i].iov_len);
4f5da8
 }
4f5da8
 
4f5da8
+void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
4f5da8
+                       unsigned int len)
4f5da8
+{
4f5da8
+    vq->last_avail_idx--;
4f5da8
+    virtqueue_unmap_sg(vq, elem, len);
4f5da8
+}
4f5da8
+
4f5da8
 void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
4f5da8
                     unsigned int len, unsigned int idx)
4f5da8
 {
4f5da8
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
4f5da8
index 9e22865..de32425 100644
4f5da8
--- a/include/hw/virtio/virtio.h
4f5da8
+++ b/include/hw/virtio/virtio.h
4f5da8
@@ -165,6 +165,8 @@ void virtio_del_queue(VirtIODevice *vdev, int n);
4f5da8
 void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
4f5da8
                     unsigned int len);
4f5da8
 void virtqueue_flush(VirtQueue *vq, unsigned int count);
4f5da8
+void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
4f5da8
+                       unsigned int len);
4f5da8
 void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
4f5da8
                     unsigned int len, unsigned int idx);
4f5da8
 
4f5da8
-- 
4f5da8
1.8.3.1
4f5da8