From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zcqbm-0001Zq-E6 for qemu-devel@nongnu.org; Fri, 18 Sep 2015 04:01:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zcqbg-00015B-Ie for qemu-devel@nongnu.org; Fri, 18 Sep 2015 04:01:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zcqbg-000155-DX for qemu-devel@nongnu.org; Fri, 18 Sep 2015 04:01:20 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 11344A35BF for ; Fri, 18 Sep 2015 08:01:20 +0000 (UTC) From: Jason Wang Date: Fri, 18 Sep 2015 16:01:09 +0800 Message-Id: <1442563270-11615-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1442563270-11615-1-git-send-email-jasowang@redhat.com> References: <1442563270-11615-1-git-send-email-jasowang@redhat.com> Subject: [Qemu-devel] [PATCH 2/3] virtio: introduce virtqueue_discard() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mst@redhat.com, qemu-devel@nongnu.org Cc: Jason Wang , ppandit@redhat.com This patch introduces virtqueue_discard() to discard a descriptor and unmap the sgs. This will be used by the patch that will discard descriptor when packet is truncated. Cc: Michael S. Tsirkin Signed-off-by: Jason Wang --- hw/virtio/virtio.c | 7 +++++++ include/hw/virtio/virtio.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index eb8d5ca..d24ee80 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -265,6 +265,13 @@ static void virtqueue_unmap_sg(VirtQueue *vq, const VirtQueueElement *elem, 0, elem->out_sg[i].iov_len); } +void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem, + unsigned int len) +{ + vq->last_avail_idx--; + virtqueue_unmap_sg(vq, elem, len); +} + void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx) { diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 6201ee8..9d09115 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -146,6 +146,8 @@ void virtio_del_queue(VirtIODevice *vdev, int n); void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len); void virtqueue_flush(VirtQueue *vq, unsigned int count); +void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem, + unsigned int len); void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx); -- 2.1.4