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